diff --git a/controller/handler_ctrl/bind.go b/controller/handler_ctrl/bind.go index b8687f7f2..25fca9fe3 100644 --- a/controller/handler_ctrl/bind.go +++ b/controller/handler_ctrl/bind.go @@ -41,7 +41,7 @@ func (self *bindHandler) BindChannel(ch channel2.Channel) error { ch.SetLogicalName(self.router.Id) ch.AddReceiveHandler(newSessionRequestHandler(self.router, self.network)) ch.AddReceiveHandler(newRouteResultHandler(self.network, self.router)) - ch.AddReceiveHandler(newSessionConfirmationHandler()) + ch.AddReceiveHandler(newSessionConfirmationHandler(self.network, self.router)) ch.AddReceiveHandler(newCreateTerminatorHandler(self.network, self.router)) ch.AddReceiveHandler(newRemoveTerminatorHandler(self.network)) ch.AddReceiveHandler(newUpdateTerminatorHandler(self.network)) diff --git a/controller/handler_ctrl/session_confirmation.go b/controller/handler_ctrl/session_confirmation.go index db6529c91..9e5fd0eea 100644 --- a/controller/handler_ctrl/session_confirmation.go +++ b/controller/handler_ctrl/session_confirmation.go @@ -17,15 +17,22 @@ package handler_ctrl import ( + "github.com/golang/protobuf/proto" + "github.com/openziti/fabric/controller/network" "github.com/openziti/fabric/ctrl_msg" + "github.com/openziti/fabric/pb/ctrl_pb" "github.com/openziti/foundation/channel2" + "github.com/openziti/foundation/identity/identity" "github.com/sirupsen/logrus" ) -type sessionConfirmationHandler struct{} +type sessionConfirmationHandler struct { + n *network.Network + r *network.Router +} -func newSessionConfirmationHandler() *sessionConfirmationHandler { - return &sessionConfirmationHandler{} +func newSessionConfirmationHandler(n *network.Network, r *network.Router) *sessionConfirmationHandler { + return &sessionConfirmationHandler{n, r} } func (self *sessionConfirmationHandler) ContentType() int32 { @@ -33,5 +40,29 @@ func (self *sessionConfirmationHandler) ContentType() int32 { } func (self *sessionConfirmationHandler) HandleReceive(msg *channel2.Message, ch channel2.Channel) { - logrus.Infof("this controller does not process session confirmation broadcasts. consider upgrading to a newer controller") -} \ No newline at end of file + logrus.Infof("received session confirmation request from [r/%s]", self.r.Id) + confirm := &ctrl_pb.SessionConfirmation{} + if err := proto.Unmarshal(msg.Body, confirm); err == nil { + for _, sessionId := range confirm.SessionIds { + if _, found := self.n.GetSession(&identity.TokenId{Token: sessionId}); !found { + unroute := &ctrl_pb.Unroute{} + unroute.SessionId = sessionId + unroute.Now = true + if body, err := proto.Marshal(unroute); err == nil { + msg := channel2.NewMessage(int32(ctrl_pb.ContentType_UnrouteType), body) + if err := self.r.Control.Send(msg); err == nil { + logrus.Infof("sent unroute to [r/%s] for [s/%s]", self.r.Id, sessionId) + } else { + logrus.Errorf("error sending unroute to [r/%s] for [s/%s] (%v)", self.r.Id, sessionId, err) + } + } else { + logrus.Errorf("error marshalling unroute to [r/%s] for [s/%s] (%v)", self.r.Id, sessionId, err) + } + } else { + logrus.Debugf("[s/%s] found, ignoring") + } + } + } else { + logrus.Errorf("error unmarshaling session confirmation from [r/%s] (%v)", self.r.Id, err) + } +}