1
0
forked from extern/smegmesh

Fixed routing issue

This commit is contained in:
Tim Beatham 2023-11-24 17:49:06 +00:00
parent 73db65660b
commit 4030d17b41
6 changed files with 18 additions and 21 deletions

View File

@ -29,7 +29,7 @@ func (d *DNSHandler) queryMesh(meshId, alias string) net.IP {
err := d.client.Call("IpcHandler.Query", &ipc.QueryMesh{ err := d.client.Call("IpcHandler.Query", &ipc.QueryMesh{
MeshId: meshId, MeshId: meshId,
Query: "[?alias == 'tim'] | [0]", Query: fmt.Sprintf("[?alias == '%s'] | [0]", alias),
}, &reply) }, &reply)
if err != nil { if err != nil {

View File

@ -61,7 +61,7 @@ func (c *MeshDOTConverter) graphNode(g *graph.Graph, node MeshNode, meshId strin
self, _ := c.manager.GetSelf(meshId) self, _ := c.manager.GetSelf(meshId)
if node.GetHostEndpoint() == self.GetHostEndpoint() { if NodeEquals(self, node) {
return return
} }

View File

@ -266,20 +266,16 @@ func (s *MeshManagerImpl) AddSelf(params *AddSelfParams) error {
params.WgPort = device.ListenPort params.WgPort = device.ListenPort
} }
pubKey, err := s.GetPublicKey(params.MeshId) pubKey := s.HostParameters.PrivateKey.PublicKey()
if err != nil { nodeIP, err := s.ipAllocator.GetIP(pubKey, params.MeshId)
return err
}
nodeIP, err := s.ipAllocator.GetIP(*pubKey, params.MeshId)
if err != nil { if err != nil {
return err return err
} }
node := s.nodeFactory.Build(&MeshNodeFactoryParams{ node := s.nodeFactory.Build(&MeshNodeFactoryParams{
PublicKey: pubKey, PublicKey: &pubKey,
NodeIP: nodeIP, NodeIP: nodeIP,
WgPort: params.WgPort, WgPort: params.WgPort,
Endpoint: params.Endpoint, Endpoint: params.Endpoint,

View File

@ -45,7 +45,7 @@ func (r *RouteManagerImpl) UpdateRoutes() error {
return err return err
} }
err = mesh1.AddRoutes(self.GetHostEndpoint(), ipNet.String()) err = mesh1.AddRoutes(NodeID(self), ipNet.String())
if err != nil { if err != nil {
return err return err
@ -74,7 +74,7 @@ func (r *RouteManagerImpl) RemoveRoutes(meshId string) error {
return err return err
} }
mesh1.RemoveRoutes(self.GetHostEndpoint(), ipNet.String()) mesh1.RemoveRoutes(NodeID(self), ipNet.String())
} }
return nil return nil
} }
@ -152,7 +152,7 @@ func (m *RouteManagerImpl) installRoutes(meshProvider MeshProvider) error {
} }
for _, node := range mesh.GetNodes() { for _, node := range mesh.GetNodes() {
if self.GetHostEndpoint() == node.GetHostEndpoint() { if NodeEquals(self, node) {
continue continue
} }

View File

@ -23,7 +23,7 @@ type MeshNodeStub struct {
// GetType implements MeshNode. // GetType implements MeshNode.
func (*MeshNodeStub) GetType() conf.NodeType { func (*MeshNodeStub) GetType() conf.NodeType {
return PEER return conf.PEER_ROLE
} }
// GetServices implements MeshNode. // GetServices implements MeshNode.

View File

@ -10,13 +10,6 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
) )
const (
// Data Exchanged Between Peers
PEER conf.NodeType = "peer"
// Data Exchanged Between Clients
CLIENT conf.NodeType = "client"
)
// MeshNode represents an implementation of a node in a mesh // MeshNode represents an implementation of a node in a mesh
type MeshNode interface { type MeshNode interface {
// GetHostEndpoint: gets the gRPC endpoint of the node // GetHostEndpoint: gets the gRPC endpoint of the node
@ -45,7 +38,15 @@ type MeshNode interface {
// NodeEquals: determines if two mesh nodes are equivalent to one another // NodeEquals: determines if two mesh nodes are equivalent to one another
func NodeEquals(node1, node2 MeshNode) bool { func NodeEquals(node1, node2 MeshNode) bool {
return node1.GetHostEndpoint() == node2.GetHostEndpoint() key1, _ := node1.GetPublicKey()
key2, _ := node2.GetPublicKey()
return key1.String() == key2.String()
}
func NodeID(node MeshNode) string {
key, _ := node.GetPublicKey()
return key.String()
} }
type MeshSnapshot interface { type MeshSnapshot interface {