From de54568423775bda2a3afcadba05fb4226be36ae Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Tue, 10 Aug 2021 13:18:24 -0400 Subject: [PATCH] More session -> circuit fixes. Fix patch on service edge router policy when semantic isn't set --- controller/handler_edge_ctrl/create_circuit.go | 2 +- .../service_edge_router_policy_store.go | 10 ++-------- pb/edge_ctrl_pb/decoder.go | 2 +- pb/edge_ctrl_pb/edge_ctrl.pb.go | 10 +++++----- pb/edge_ctrl_pb/edge_ctrl.proto | 2 +- router/xgress_edge/dialer.go | 14 +++++++------- router/xgress_edge/listener.go | 2 +- router/xgress_edge_transport/dialer.go | 10 +++++----- router/xgress_edge_tunnel/dialer.go | 8 ++++---- 9 files changed, 27 insertions(+), 33 deletions(-) diff --git a/controller/handler_edge_ctrl/create_circuit.go b/controller/handler_edge_ctrl/create_circuit.go index 94068751f..ca4f85178 100644 --- a/controller/handler_edge_ctrl/create_circuit.go +++ b/controller/handler_edge_ctrl/create_circuit.go @@ -96,7 +96,7 @@ func (self *createCircuitHandler) CreateCircuit(ctx *CreateCircuitRequestContext log := pfxlog.ContextLogger(self.ch.Label()).WithField("token", ctx.req.SessionToken) response := &edge_ctrl_pb.CreateCircuitResponse{ - SessionId: circuitInfo.Id, + CircuitId: circuitInfo.Id, Address: circuitInfo.Path.IngressId, PeerData: peerData, } diff --git a/controller/persistence/service_edge_router_policy_store.go b/controller/persistence/service_edge_router_policy_store.go index 64783bf85..90946ec16 100644 --- a/controller/persistence/service_edge_router_policy_store.go +++ b/controller/persistence/service_edge_router_policy_store.go @@ -53,20 +53,14 @@ func (entity *ServiceEdgeRouterPolicy) SetValues(ctx *boltz.PersistContext) { ctx.Bucket.SetError(err) } - if !isSemanticValid(entity.Semantic) { + if ctx.ProceedWithSet(FieldSemantic) && !isSemanticValid(entity.Semantic) { ctx.Bucket.SetError(errorz.NewFieldError("invalid semantic", FieldSemantic, entity.Semantic)) return } entity.SetBaseValues(ctx) ctx.SetRequiredString(FieldName, entity.Name) - if ctx.ProceedWithSet(FieldSemantic) { - if !isSemanticValid(entity.Semantic) { - ctx.Bucket.SetError(errorz.NewFieldError("invalid semantic", FieldSemantic, entity.Semantic)) - return - } - ctx.SetRequiredString(FieldSemantic, entity.Semantic) - } + ctx.SetRequiredString(FieldSemantic, entity.Semantic) serviceEdgeRouterPolicyStore := ctx.Store.(*serviceEdgeRouterPolicyStoreImpl) diff --git a/pb/edge_ctrl_pb/decoder.go b/pb/edge_ctrl_pb/decoder.go index da980e92b..80ec235bf 100644 --- a/pb/edge_ctrl_pb/decoder.go +++ b/pb/edge_ctrl_pb/decoder.go @@ -99,7 +99,7 @@ func (d Decoder) Decode(msg *channel2.Message) ([]byte, bool) { request := &CreateCircuitResponse{} if err := proto.Unmarshal(msg.Body, request); err == nil { meta := channel2.NewTraceMessageDecode(DECODER, "Create Circuit Response") - meta["sessionId"] = request.SessionId + meta["circuitId"] = request.CircuitId meta["address"] = request.Address return meta.MarshalResult() } else { diff --git a/pb/edge_ctrl_pb/edge_ctrl.pb.go b/pb/edge_ctrl_pb/edge_ctrl.pb.go index 1cf801cd3..21d5a50c1 100644 --- a/pb/edge_ctrl_pb/edge_ctrl.pb.go +++ b/pb/edge_ctrl_pb/edge_ctrl.pb.go @@ -1114,7 +1114,7 @@ type CreateCircuitResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - SessionId string `protobuf:"bytes,1,opt,name=sessionId,proto3" json:"sessionId,omitempty"` + CircuitId string `protobuf:"bytes,1,opt,name=circuitId,proto3" json:"circuitId,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` PeerData map[uint32][]byte `protobuf:"bytes,3,rep,name=peerData,proto3" json:"peerData,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } @@ -1151,9 +1151,9 @@ func (*CreateCircuitResponse) Descriptor() ([]byte, []int) { return file_edge_ctrl_proto_rawDescGZIP(), []int{13} } -func (x *CreateCircuitResponse) GetSessionId() string { +func (x *CreateCircuitResponse) GetCircuitId() string { if x != nil { - return x.SessionId + return x.CircuitId } return "" } @@ -2687,8 +2687,8 @@ var file_edge_ctrl_proto_rawDesc = []byte{ 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xe0, 0x01, 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, + 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x52, 0x0a, 0x08, 0x70, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x36, 0x2e, 0x7a, diff --git a/pb/edge_ctrl_pb/edge_ctrl.proto b/pb/edge_ctrl_pb/edge_ctrl.proto index 3a359183c..90daef3e9 100644 --- a/pb/edge_ctrl_pb/edge_ctrl.proto +++ b/pb/edge_ctrl_pb/edge_ctrl.proto @@ -137,7 +137,7 @@ message CreateCircuitRequest { } message CreateCircuitResponse { - string sessionId = 1; + string circuitId = 1; string address = 2; map peerData = 3; } diff --git a/router/xgress_edge/dialer.go b/router/xgress_edge/dialer.go index eb864b355..bf846434f 100644 --- a/router/xgress_edge/dialer.go +++ b/router/xgress_edge/dialer.go @@ -60,7 +60,7 @@ func newDialer(factory *Factory, options *Options) xgress.Dialer { return txd } -func (dialer *dialer) Dial(destination string, sessionId *identity.TokenId, address xgress.Address, bindHandler xgress.BindHandler, ctx logcontext.Context) (xt.PeerData, error) { +func (dialer *dialer) Dial(destination string, circuitId *identity.TokenId, address xgress.Address, bindHandler xgress.BindHandler, ctx logcontext.Context) (xt.PeerData, error) { log := pfxlog.ChannelLogger(logcontext.EstablishPath).Wire(ctx). WithField("binding", "edge"). WithField("destination", destination) @@ -84,19 +84,19 @@ func (dialer *dialer) Dial(destination string, sessionId *identity.TokenId, addr log = log.WithField("bindConnId", listenConn.Id()) callerId := "" - if sessionId.Data != nil { - if callerIdBytes, found := sessionId.Data[edge.CallerIdHeader]; found { + if circuitId.Data != nil { + if callerIdBytes, found := circuitId.Data[edge.CallerIdHeader]; found { callerId = string(callerIdBytes) } } log.Debug("dialing sdk client hosting service") dialRequest := edge.NewDialMsg(listenConn.Id(), token, callerId) - if pk, ok := sessionId.Data[edge.PublicKeyHeader]; ok { + if pk, ok := circuitId.Data[edge.PublicKeyHeader]; ok { dialRequest.Headers[edge.PublicKeyHeader] = pk } - appData, hasAppData := sessionId.Data[edge.AppDataHeader] + appData, hasAppData := circuitId.Data[edge.AppDataHeader] if hasAppData { dialRequest.Headers[edge.AppDataHeader] = appData } @@ -114,7 +114,7 @@ func (dialer *dialer) Dial(destination string, sessionId *identity.TokenId, addr // On the terminator, which this is, this only starts the txer, which pulls data from the link // Since the opposing xgress doesn't start until this call returns, nothing should be coming this way yet - x := xgress.NewXgress(sessionId, address, conn, xgress.Terminator, &dialer.options.Options) + x := xgress.NewXgress(circuitId, address, conn, xgress.Terminator, &dialer.options.Options) bindHandler.HandleXgressBind(x) x.Start() @@ -170,7 +170,7 @@ func (dialer *dialer) Dial(destination string, sessionId *identity.TokenId, addr return nil, errors.Wrapf(err, "failed to create edge xgress conn for token %v", token) } - x := xgress.NewXgress(sessionId, address, conn, xgress.Terminator, &dialer.options.Options) + x := xgress.NewXgress(circuitId, address, conn, xgress.Terminator, &dialer.options.Options) bindHandler.HandleXgressBind(x) x.Start() diff --git a/router/xgress_edge/listener.go b/router/xgress_edge/listener.go index 7d7119db1..85745149e 100644 --- a/router/xgress_edge/listener.go +++ b/router/xgress_edge/listener.go @@ -163,7 +163,7 @@ func (self *edgeClientConn) processConnect(req *channel2.Message, ch channel2.Ch return } - x := xgress.NewXgress(&identity.TokenId{Token: response.SessionId}, xgress.Address(response.Address), conn, xgress.Initiator, &self.listener.options.Options) + x := xgress.NewXgress(&identity.TokenId{Token: response.CircuitId}, xgress.Address(response.Address), conn, xgress.Initiator, &self.listener.options.Options) self.listener.bindHandler.HandleXgressBind(x) // send the state_connected before starting the xgress. That way we can't get a state_closed before we get state_connected diff --git a/router/xgress_edge_transport/dialer.go b/router/xgress_edge_transport/dialer.go index 6bfe26457..1ec92d561 100644 --- a/router/xgress_edge_transport/dialer.go +++ b/router/xgress_edge_transport/dialer.go @@ -45,7 +45,7 @@ func newDialer(ctrl xgress.CtrlChannel, options *xgress.Options) (xgress.Dialer, return txd, nil } -func (txd *dialer) Dial(destination string, sessionId *identity.TokenId, address xgress.Address, bindHandler xgress.BindHandler, ctx logcontext.Context) (xt.PeerData, error) { +func (txd *dialer) Dial(destination string, circuitId *identity.TokenId, address xgress.Address, bindHandler xgress.BindHandler, ctx logcontext.Context) (xt.PeerData, error) { log := pfxlog.ChannelLogger(logcontext.EstablishPath).Wire(ctx). WithField("binding", "edge_transport"). WithField("destination", destination) @@ -56,16 +56,16 @@ func (txd *dialer) Dial(destination string, sessionId *identity.TokenId, address } log.Debug("dialing") - peer, err := txDestination.Dial("x/"+sessionId.Token, sessionId, txd.options.ConnectTimeout, nil) + peer, err := txDestination.Dial("x/"+circuitId.Token, circuitId, txd.options.ConnectTimeout, nil) if err != nil { return nil, err } - log.Infof("successful connection to %v from %v (s/%v)", destination, peer.Conn().LocalAddr(), sessionId.Token) + log.Infof("successful connection to %v from %v (s/%v)", destination, peer.Conn().LocalAddr(), circuitId.Token) xgConn := xgress_common.NewXgressConn(peer.Conn(), true) peerData := make(xt.PeerData, 1) - if peerKey, ok := sessionId.Data[edge.PublicKeyHeader]; ok { + if peerKey, ok := circuitId.Data[edge.PublicKeyHeader]; ok { if publicKey, err := xgConn.SetupServerCrypto(peerKey); err != nil { return nil, err } else { @@ -73,7 +73,7 @@ func (txd *dialer) Dial(destination string, sessionId *identity.TokenId, address } } - x := xgress.NewXgress(sessionId, address, xgConn, xgress.Terminator, txd.options) + x := xgress.NewXgress(circuitId, address, xgConn, xgress.Terminator, txd.options) bindHandler.HandleXgressBind(x) x.Start() diff --git a/router/xgress_edge_tunnel/dialer.go b/router/xgress_edge_tunnel/dialer.go index 65ff22a76..051c667f7 100644 --- a/router/xgress_edge_tunnel/dialer.go +++ b/router/xgress_edge_tunnel/dialer.go @@ -33,7 +33,7 @@ func (self *tunneler) IsTerminatorValid(_ string, destination string) bool { return found } -func (self *tunneler) Dial(destination string, sessionId *identity.TokenId, address xgress.Address, bindHandler xgress.BindHandler, ctx logcontext.Context) (xt.PeerData, error) { +func (self *tunneler) Dial(destination string, circuitId *identity.TokenId, address xgress.Address, bindHandler xgress.BindHandler, ctx logcontext.Context) (xt.PeerData, error) { log := pfxlog.ChannelLogger(logcontext.EstablishPath).Wire(ctx). WithField("binding", "edge"). WithField("destination", destination) @@ -44,7 +44,7 @@ func (self *tunneler) Dial(destination string, sessionId *identity.TokenId, addr } terminator := val.(*tunnelTerminator) - options, err := tunnel.AppDataToMap(sessionId.Data[edge.AppDataHeader]) + options, err := tunnel.AppDataToMap(circuitId.Data[edge.AppDataHeader]) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func (self *tunneler) Dial(destination string, sessionId *identity.TokenId, addr xgConn := xgress_common.NewXgressConn(conn, halfClose) peerData := make(xt.PeerData, 1) - if peerKey, ok := sessionId.Data[edge.PublicKeyHeader]; ok { + if peerKey, ok := circuitId.Data[edge.PublicKeyHeader]; ok { if publicKey, err := xgConn.SetupServerCrypto(peerKey); err != nil { return nil, err } else { @@ -66,7 +66,7 @@ func (self *tunneler) Dial(destination string, sessionId *identity.TokenId, addr } } - x := xgress.NewXgress(sessionId, address, xgConn, xgress.Terminator, self.dialOptions.Options) + x := xgress.NewXgress(circuitId, address, xgConn, xgress.Terminator, self.dialOptions.Options) bindHandler.HandleXgressBind(x) x.Start()