- Preparing for demo
This commit is contained in:
Tim Beatham 2024-01-17 13:50:18 +00:00
parent 3f82ef9cd7
commit 41d41694a6
3 changed files with 26 additions and 24 deletions

View File

@ -141,7 +141,14 @@ func (m *ConnectionManagerImpl) HasConnection(endPoint string) bool {
// RemoveConnection removes the given connection if it exists // RemoveConnection removes the given connection if it exists
func (m *ConnectionManagerImpl) RemoveConnection(endPoint string) error { func (m *ConnectionManagerImpl) RemoveConnection(endPoint string) error {
m.conLoc.Lock() 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) delete(m.clientConnections, endPoint)
m.conLoc.Unlock() m.conLoc.Unlock()

View File

@ -17,7 +17,7 @@ func HashString(value string) int {
} }
// ConsistentHash implementation. Traverse the values until we find a key // 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 { func ConsistentHash[V any, K any](values []V, client K, bucketFunc func(V) int, keyFunc func(K) int) V {
if len(values) == 0 { if len(values) == 0 {
panic("values is empty") panic("values is empty")

View File

@ -36,7 +36,6 @@ type routeNode struct {
type convertMeshNodeParams struct { type convertMeshNodeParams struct {
node MeshNode node MeshNode
correspondingPeer MeshNode
mesh MeshProvider mesh MeshProvider
device *wgtypes.Device device *wgtypes.Device
peerToClients map[string][]net.IPNet peerToClients map[string][]net.IPNet
@ -59,8 +58,7 @@ func (m *WgMeshConfigApplyer) convertMeshNode(params convertMeshNodeParams) (*wg
allowedips = append(allowedips, clients...) allowedips = append(allowedips, clients...)
} }
for _, route := range params.node.GetRoutes() { for _, bestRoutes := range lib.MapValues(params.routes) {
bestRoutes := params.routes[route.GetDestination().String()]
var pickedRoute routeNode var pickedRoute routeNode
if len(bestRoutes) == 1 { if len(bestRoutes) == 1 {
@ -70,8 +68,7 @@ func (m *WgMeshConfigApplyer) convertMeshNode(params convertMeshNodeParams) (*wg
return lib.HashString(rn.gateway) return lib.HashString(rn.gateway)
} }
// Else there is more than one candidate so consistently hash pickedRoute = lib.ConsistentHash(bestRoutes, params.node, bucketFunc, m.hashFunc)
pickedRoute = lib.ConsistentHash(bestRoutes, params.correspondingPeer, bucketFunc, m.hashFunc)
} }
if pickedRoute.gateway == pubKey.String() { if pickedRoute.gateway == pubKey.String() {
@ -347,7 +344,6 @@ func (m *WgMeshConfigApplyer) getPeerConfig(params *GetConfigParams) (*wgtypes.C
cfg, err := m.convertMeshNode(convertMeshNodeParams{ cfg, err := m.convertMeshNode(convertMeshNodeParams{
node: n, node: n,
correspondingPeer: peer,
mesh: params.mesh, mesh: params.mesh,
device: params.dev, device: params.dev,
peerToClients: peerToClients, peerToClients: peerToClients,
@ -373,7 +369,6 @@ func (m *WgMeshConfigApplyer) getPeerConfig(params *GetConfigParams) (*wgtypes.C
peer, err := m.convertMeshNode(convertMeshNodeParams{ peer, err := m.convertMeshNode(convertMeshNodeParams{
node: n, node: n,
correspondingPeer: self,
mesh: params.mesh, mesh: params.mesh,
peerToClients: peerToClients, peerToClients: peerToClients,
routes: params.routes, routes: params.routes,