mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-02-10 14:29:22 +01:00
main
- Fixed problem where connection not removed on error
This commit is contained in:
parent
2d5df25b1d
commit
352648b7cb
@ -42,25 +42,8 @@ func NewWgCtrlConnection(clientConfig *tls.Config, server string) (PeerConnectio
|
|||||||
|
|
||||||
// ConnectWithToken: Connects to a new gRPC peer given the address of the other server.
|
// ConnectWithToken: Connects to a new gRPC peer given the address of the other server.
|
||||||
func (c *WgCtrlConnection) CreateGrpcConnection() error {
|
func (c *WgCtrlConnection) CreateGrpcConnection() error {
|
||||||
retryPolicy := `{
|
|
||||||
"methodConfig": [{
|
|
||||||
"name": [
|
|
||||||
{"service": "syncservice.SyncService"},
|
|
||||||
{"service": "ctrlserver.MeshCtrlServer"}
|
|
||||||
],
|
|
||||||
"waitForReady": true,
|
|
||||||
"retryPolicy": {
|
|
||||||
"MaxAttempts": 2,
|
|
||||||
"InitialBackoff": ".1s",
|
|
||||||
"MaxBackoff": ".1s",
|
|
||||||
"BackoffMultiplier": 1.0,
|
|
||||||
"RetryableStatusCodes": [ "UNAVAILABLE", "DEADLINE_EXCEEDED", "UNKNOWN" ]
|
|
||||||
}
|
|
||||||
}]}`
|
|
||||||
|
|
||||||
conn, err := grpc.Dial(c.endpoint,
|
conn, err := grpc.Dial(c.endpoint,
|
||||||
grpc.WithTransportCredentials(credentials.NewTLS(c.clientConfig)),
|
grpc.WithTransportCredentials(credentials.NewTLS(c.clientConfig)))
|
||||||
grpc.WithDefaultServiceConfig(retryPolicy))
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Log.WriteErrorf("Could not connect: %s\n", err.Error())
|
logging.Log.WriteErrorf("Could not connect: %s\n", err.Error())
|
||||||
|
@ -66,12 +66,14 @@ func (s *SyncerImpl) Sync(meshId string) error {
|
|||||||
|
|
||||||
// Clients always pings its peer for configuration
|
// Clients always pings its peer for configuration
|
||||||
if self != nil && self.GetType() == conf.CLIENT_ROLE && len(nodeNames) > 1 {
|
if self != nil && self.GetType() == conf.CLIENT_ROLE && len(nodeNames) > 1 {
|
||||||
keyFunc := lib.HashString
|
neighbours := s.cluster.GetNeighbours(nodeNames, publicKey.String())
|
||||||
bucketFunc := lib.HashString
|
|
||||||
|
|
||||||
neighbour := lib.ConsistentHash(nodeNames, publicKey.String(), keyFunc, bucketFunc)
|
if len(neighbours) == 0 {
|
||||||
gossipNodes = make([]string, 1)
|
return nil
|
||||||
gossipNodes[0] = neighbour
|
}
|
||||||
|
|
||||||
|
redundancyLength := min(len(neighbours), 3)
|
||||||
|
gossipNodes = neighbours[:redundancyLength]
|
||||||
} else {
|
} else {
|
||||||
neighbours := s.cluster.GetNeighbours(nodeNames, publicKey.String())
|
neighbours := s.cluster.GetNeighbours(nodeNames, publicKey.String())
|
||||||
gossipNodes = lib.RandomSubsetOfLength(neighbours, s.conf.BranchRate)
|
gossipNodes = lib.RandomSubsetOfLength(neighbours, s.conf.BranchRate)
|
||||||
|
@ -22,11 +22,16 @@ type SyncErrorHandlerImpl struct {
|
|||||||
func (s *SyncErrorHandlerImpl) handleFailed(meshId string, nodeId string) bool {
|
func (s *SyncErrorHandlerImpl) handleFailed(meshId string, nodeId string) bool {
|
||||||
mesh := s.meshManager.GetMesh(meshId)
|
mesh := s.meshManager.GetMesh(meshId)
|
||||||
mesh.Mark(nodeId)
|
mesh.Mark(nodeId)
|
||||||
|
node, err := mesh.GetNode(nodeId)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
s.connManager.RemoveConnection(node.GetHostEndpoint())
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SyncErrorHandlerImpl) handleDeadlineExceeded(meshId string, nodeId string) bool {
|
func (s *SyncErrorHandlerImpl) handleDeadlineExceeded(meshId string, nodeId string) bool {
|
||||||
mesh := s.meshManager.GetMesh(nodeId)
|
mesh := s.meshManager.GetMesh(meshId)
|
||||||
|
|
||||||
if mesh == nil {
|
if mesh == nil {
|
||||||
return true
|
return true
|
||||||
@ -57,6 +62,6 @@ func (s *SyncErrorHandlerImpl) Handle(meshId string, nodeId string, err error) b
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSyncErrorHandler(m mesh.MeshManager) SyncErrorHandler {
|
func NewSyncErrorHandler(m mesh.MeshManager, conn conn.ConnectionManager) SyncErrorHandler {
|
||||||
return &SyncErrorHandlerImpl{meshManager: m}
|
return &SyncErrorHandlerImpl{meshManager: m, connManager: conn}
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,6 @@ func (s *SyncRequesterImpl) syncMesh(mesh mesh.MeshProvider, ctx context.Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewSyncRequester(s *ctrlserver.MeshCtrlServer) SyncRequester {
|
func NewSyncRequester(s *ctrlserver.MeshCtrlServer) SyncRequester {
|
||||||
errorHdlr := NewSyncErrorHandler(s.MeshManager)
|
errorHdlr := NewSyncErrorHandler(s.MeshManager, s.ConnectionManager)
|
||||||
return &SyncRequesterImpl{server: s, errorHdlr: errorHdlr}
|
return &SyncRequesterImpl{server: s, errorHdlr: errorHdlr}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user