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")
|
||||
|
@ -35,12 +35,11 @@ type routeNode struct {
|
||||
}
|
||||
|
||||
type convertMeshNodeParams struct {
|
||||
node MeshNode
|
||||
correspondingPeer MeshNode
|
||||
mesh MeshProvider
|
||||
device *wgtypes.Device
|
||||
peerToClients map[string][]net.IPNet
|
||||
routes map[string][]routeNode
|
||||
node MeshNode
|
||||
mesh MeshProvider
|
||||
device *wgtypes.Device
|
||||
peerToClients map[string][]net.IPNet
|
||||
routes map[string][]routeNode
|
||||
}
|
||||
|
||||
func (m *WgMeshConfigApplyer) convertMeshNode(params convertMeshNodeParams) (*wgtypes.PeerConfig, error) {
|
||||
@ -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() {
|
||||
@ -346,12 +343,11 @@ func (m *WgMeshConfigApplyer) getPeerConfig(params *GetConfigParams) (*wgtypes.C
|
||||
peerToClients[pubKey.String()] = append(clients, *n.GetWgHost())
|
||||
|
||||
cfg, err := m.convertMeshNode(convertMeshNodeParams{
|
||||
node: n,
|
||||
correspondingPeer: peer,
|
||||
mesh: params.mesh,
|
||||
device: params.dev,
|
||||
peerToClients: peerToClients,
|
||||
routes: params.routes,
|
||||
node: n,
|
||||
mesh: params.mesh,
|
||||
device: params.dev,
|
||||
peerToClients: peerToClients,
|
||||
routes: params.routes,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -372,12 +368,11 @@ 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,
|
||||
device: params.dev,
|
||||
node: n,
|
||||
mesh: params.mesh,
|
||||
peerToClients: peerToClients,
|
||||
routes: params.routes,
|
||||
device: params.dev,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user