mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 20:05:46 +08:00
configure proxy on node updates
This commit is contained in:
parent
104fe8824f
commit
474bd14e36
5 changed files with 29 additions and 5 deletions
6
go.mod
6
go.mod
|
@ -42,8 +42,11 @@ require (
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-oidc/v3 v3.4.0
|
github.com/coreos/go-oidc/v3 v3.4.0
|
||||||
github.com/gorilla/websocket v1.5.0
|
github.com/gorilla/websocket v1.5.0
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
|
github.com/sirupsen/logrus v1.9.0
|
||||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
|
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
|
||||||
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035
|
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035
|
||||||
|
gortc.io/stun v1.23.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -82,11 +85,9 @@ require (
|
||||||
github.com/mdlayher/socket v0.1.1 // indirect
|
github.com/mdlayher/socket v0.1.1 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/opencontainers/image-spec v1.0.2 // indirect
|
github.com/opencontainers/image-spec v1.0.2 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
|
||||||
github.com/spf13/afero v1.9.2 // indirect
|
github.com/spf13/afero v1.9.2 // indirect
|
||||||
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
|
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
|
||||||
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect
|
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect
|
||||||
|
@ -100,6 +101,5 @@ require (
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gortc.io/stun v1.23.0 // indirect
|
|
||||||
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
|
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,7 +36,7 @@ func GetPeersForProxy(node *models.Node) ([]wgtypes.PeerConfig, error) {
|
||||||
logger.Log(1, "failed to parse node pub key: ", peer.ID)
|
logger.Log(1, "failed to parse node pub key: ", peer.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
endpoint, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", node.Endpoint, node.ListenPort))
|
endpoint, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", peer.Endpoint, peer.LocalListenPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log(1, "failed to resolve udp addr for node: ", peer.ID, peer.Endpoint, err.Error())
|
logger.Log(1, "failed to resolve udp addr for node: ", peer.ID, peer.Endpoint, err.Error())
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -56,6 +56,7 @@ func IfaceDelta(currentNode *models.Node, newNode *models.Node) bool {
|
||||||
newNode.UDPHolePunch != currentNode.UDPHolePunch ||
|
newNode.UDPHolePunch != currentNode.UDPHolePunch ||
|
||||||
newNode.IsPending != currentNode.IsPending ||
|
newNode.IsPending != currentNode.IsPending ||
|
||||||
newNode.ListenPort != currentNode.ListenPort ||
|
newNode.ListenPort != currentNode.ListenPort ||
|
||||||
|
newNode.LocalListenPort != currentNode.LocalListenPort ||
|
||||||
newNode.MTU != currentNode.MTU ||
|
newNode.MTU != currentNode.MTU ||
|
||||||
newNode.PersistentKeepalive != currentNode.PersistentKeepalive ||
|
newNode.PersistentKeepalive != currentNode.PersistentKeepalive ||
|
||||||
newNode.DNSOn != currentNode.DNSOn ||
|
newNode.DNSOn != currentNode.DNSOn ||
|
||||||
|
|
|
@ -3,6 +3,7 @@ package mq
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
@ -11,7 +12,9 @@ import (
|
||||||
"github.com/gravitl/netmaker/logic"
|
"github.com/gravitl/netmaker/logic"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||||
|
"github.com/gravitl/netmaker/nm-proxy/manager"
|
||||||
"github.com/gravitl/netmaker/servercfg"
|
"github.com/gravitl/netmaker/servercfg"
|
||||||
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultHandler default message queue handler -- NOT USED
|
// DefaultHandler default message queue handler -- NOT USED
|
||||||
|
@ -101,6 +104,26 @@ func UpdateNode(client mqtt.Client, msg mqtt.Message) {
|
||||||
if err = PublishPeerUpdate(¤tNode, true); err != nil {
|
if err = PublishPeerUpdate(¤tNode, true); err != nil {
|
||||||
logger.Log(0, "error updating peers when node", currentNode.Name, currentNode.ID, "informed the server of an interface change", err.Error())
|
logger.Log(0, "error updating peers when node", currentNode.Name, currentNode.ID, "informed the server of an interface change", err.Error())
|
||||||
}
|
}
|
||||||
|
pubKey, err := wgtypes.ParseKey(newNode.PublicKey)
|
||||||
|
if err == nil {
|
||||||
|
endpoint, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", newNode.Endpoint, newNode.LocalListenPort))
|
||||||
|
if err == nil {
|
||||||
|
logic.ProxyMgmChan <- &manager.ManagerAction{
|
||||||
|
Action: manager.UpdatePeer,
|
||||||
|
Payload: manager.ManagerPayload{
|
||||||
|
InterfaceName: newNode.Interface,
|
||||||
|
Peers: []wgtypes.PeerConfig{
|
||||||
|
{
|
||||||
|
PublicKey: pubKey,
|
||||||
|
Endpoint: endpoint,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
logger.Log(1, "updated node", id, newNode.Name)
|
logger.Log(1, "updated node", id, newNode.Name)
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
2. Delete - remove close all conns for the interface,cleanup
|
2. Delete - remove close all conns for the interface,cleanup
|
||||||
|
|
||||||
*/
|
*/
|
||||||
func Start(mgmChan chan *manager.ManagerAction, isServer bool) {
|
func Start(mgmChan chan *manager.ManagerAction) {
|
||||||
log.Println("Starting Proxy...")
|
log.Println("Starting Proxy...")
|
||||||
go manager.StartProxyManager(mgmChan)
|
go manager.StartProxyManager(mgmChan)
|
||||||
hInfo := stun.GetHostInfo()
|
hInfo := stun.GetHostInfo()
|
||||||
|
|
Loading…
Add table
Reference in a new issue