mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 07:41:17 +00:00
1a6fb53271
* progress on controller communication * added yaml encoding/decoding * move dispatch callbacks to be more consistent * update unit tests * small cleaups * Add new datadir to unit tests * fix linter * Was able to use FSM hooks to get configuration updates to show raft state * Send index to prevent older versions from being applied and added leader override * pr comments and added/removed ctrl connections * added error logging * pr comments * spelling and bad log newlines * added delete from the toconnect map and added end case to the background connect * reordered removal from map * added mtx around access. Forgot that was changed to be unsopported.
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package handler_ctrl
|
|
|
|
import (
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/channel/v2"
|
|
"github.com/openziti/fabric/pb/ctrl_pb"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
var updateCtrlAddressesHandlerInstance *updateCtrlAddressesHandler
|
|
|
|
type CtrlAddressUpdater interface {
|
|
UpdateCtrlEndpoints(endpoints []string) error
|
|
}
|
|
|
|
type updateCtrlAddressesHandler struct {
|
|
callback CtrlAddressUpdater
|
|
|
|
currentVersion uint64
|
|
}
|
|
|
|
func (handler *updateCtrlAddressesHandler) ContentType() int32 {
|
|
return int32(ctrl_pb.ContentType_UpdateCtrlAddressesType)
|
|
}
|
|
|
|
func (handler *updateCtrlAddressesHandler) HandleReceive(msg *channel.Message, ch channel.Channel) {
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
upd := &ctrl_pb.UpdateCtrlAddresses{}
|
|
if err := proto.Unmarshal(msg.Body, upd); err != nil {
|
|
log.WithError(err).Error("error unmarshalling")
|
|
return
|
|
}
|
|
|
|
if upd.IsLeader || handler.currentVersion == 0 || handler.currentVersion < upd.Index {
|
|
if err := handler.callback.UpdateCtrlEndpoints(upd.Addresses); err != nil {
|
|
log.WithError(err).Error("Unable to update ctrl addresses")
|
|
}
|
|
handler.currentVersion = upd.Index
|
|
log.Infof("updated to version %v", handler.currentVersion)
|
|
}
|
|
}
|
|
|
|
func newUpdateCtrlAddressesHandler(callback CtrlAddressUpdater) channel.TypedReceiveHandler {
|
|
if updateCtrlAddressesHandlerInstance == nil {
|
|
updateCtrlAddressesHandlerInstance = &updateCtrlAddressesHandler{
|
|
callback: callback,
|
|
}
|
|
}
|
|
return updateCtrlAddressesHandlerInstance
|
|
}
|