forked from extern/smegmesh
main
- Preparing for demo
This commit is contained in:
parent
3f82ef9cd7
commit
41d41694a6
@ -141,7 +141,14 @@ func (m *ConnectionManagerImpl) HasConnection(endPoint string) bool {
|
||||
// RemoveConnection removes the given connection if it exists
|
||||
func (m *ConnectionManagerImpl) RemoveConnection(endPoint string) error {
|
||||
m.conLoc.Lock()
|
||||
err := m.clientConnections[endPoint].Close()
|
||||
connection, ok := m.clientConnections[endPoint]
|
||||
|
||||
if !ok {
|
||||
// nothing to do if no connection
|
||||
return nil
|
||||
}
|
||||
|
||||
err := connection.Close()
|
||||
|
||||
delete(m.clientConnections, endPoint)
|
||||
m.conLoc.Unlock()
|
||||
|
@ -17,7 +17,7 @@ func HashString(value string) int {
|
||||
}
|
||||
|
||||
// ConsistentHash implementation. Traverse the values until we find a key
|
||||
// less than ours.
|
||||
// greater than ours.
|
||||
func ConsistentHash[V any, K any](values []V, client K, bucketFunc func(V) int, keyFunc func(K) int) V {
|
||||
if len(values) == 0 {
|
||||
panic("values is empty")
|
||||
|
@ -36,7 +36,6 @@ type routeNode struct {
|
||||
|
||||
type convertMeshNodeParams struct {
|
||||
node MeshNode
|
||||
correspondingPeer MeshNode
|
||||
mesh MeshProvider
|
||||
device *wgtypes.Device
|
||||
peerToClients map[string][]net.IPNet
|
||||
@ -59,8 +58,7 @@ func (m *WgMeshConfigApplyer) convertMeshNode(params convertMeshNodeParams) (*wg
|
||||
allowedips = append(allowedips, clients...)
|
||||
}
|
||||
|
||||
for _, route := range params.node.GetRoutes() {
|
||||
bestRoutes := params.routes[route.GetDestination().String()]
|
||||
for _, bestRoutes := range lib.MapValues(params.routes) {
|
||||
var pickedRoute routeNode
|
||||
|
||||
if len(bestRoutes) == 1 {
|
||||
@ -70,8 +68,7 @@ func (m *WgMeshConfigApplyer) convertMeshNode(params convertMeshNodeParams) (*wg
|
||||
return lib.HashString(rn.gateway)
|
||||
}
|
||||
|
||||
// Else there is more than one candidate so consistently hash
|
||||
pickedRoute = lib.ConsistentHash(bestRoutes, params.correspondingPeer, bucketFunc, m.hashFunc)
|
||||
pickedRoute = lib.ConsistentHash(bestRoutes, params.node, bucketFunc, m.hashFunc)
|
||||
}
|
||||
|
||||
if pickedRoute.gateway == pubKey.String() {
|
||||
@ -347,7 +344,6 @@ func (m *WgMeshConfigApplyer) getPeerConfig(params *GetConfigParams) (*wgtypes.C
|
||||
|
||||
cfg, err := m.convertMeshNode(convertMeshNodeParams{
|
||||
node: n,
|
||||
correspondingPeer: peer,
|
||||
mesh: params.mesh,
|
||||
device: params.dev,
|
||||
peerToClients: peerToClients,
|
||||
@ -373,7 +369,6 @@ func (m *WgMeshConfigApplyer) getPeerConfig(params *GetConfigParams) (*wgtypes.C
|
||||
|
||||
peer, err := m.convertMeshNode(convertMeshNodeParams{
|
||||
node: n,
|
||||
correspondingPeer: self,
|
||||
mesh: params.mesh,
|
||||
peerToClients: peerToClients,
|
||||
routes: params.routes,
|
||||
|
Loading…
Reference in New Issue
Block a user