Controller cleanup side. (#173)

This commit is contained in:
Michael Quigley
2021-03-05 14:14:26 -05:00
parent 152da46d01
commit eb904f8b4c
2 changed files with 37 additions and 6 deletions
+1 -1
View File
@@ -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))
@@ -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")
}
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)
}
}