mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-01 20:52:57 +08:00
move peers to host level
This commit is contained in:
@@ -455,7 +455,6 @@ func getNode(w http.ResponseWriter, r *http.Request) {
|
|||||||
Node: *legacy,
|
Node: *legacy,
|
||||||
Peers: peerUpdate.Peers,
|
Peers: peerUpdate.Peers,
|
||||||
ServerConfig: server,
|
ServerConfig: server,
|
||||||
PeerIDs: peerUpdate.PeerIDs,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if servercfg.Is_EE && nodeRequest {
|
if servercfg.Is_EE && nodeRequest {
|
||||||
@@ -637,19 +636,18 @@ func createNode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peerUpdate, err := logic.GetPeerUpdate(&data.Node, &data.Host)
|
peerUpdate, err := logic.GetPeerUpdateForHost(&data.Host)
|
||||||
if err != nil && !database.IsEmptyRecord(err) {
|
if err != nil && !database.IsEmptyRecord(err) {
|
||||||
logger.Log(0, r.Header.Get("user"),
|
logger.Log(0, r.Header.Get("user"),
|
||||||
fmt.Sprintf("error fetching wg peers config for node [ %s ]: %v", data.Node.ID.String(), err))
|
fmt.Sprintf("error fetching wg peers config for node [ %s ]: %v", data.Node.ID.String(), err))
|
||||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data.Node.Peers = peerUpdate.Peers
|
data.Host.Peers = peerUpdate.Peers
|
||||||
|
|
||||||
response := models.NodeJoinResponse{
|
response := models.NodeJoinResponse{
|
||||||
Node: data.Node,
|
Node: data.Node,
|
||||||
ServerConfig: server,
|
ServerConfig: server,
|
||||||
PeerIDs: peerUpdate.PeerIDs,
|
Host: data.Host,
|
||||||
}
|
}
|
||||||
logger.Log(1, r.Header.Get("user"), "created new node", data.Host.Name, "on network", networkName)
|
logger.Log(1, r.Header.Get("user"), "created new node", data.Host.Name, "on network", networkName)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (a *ApiNode) ConvertToServerNode(currentNode *Node) *Node {
|
|||||||
convertedNode.IsRelay = a.IsRelay
|
convertedNode.IsRelay = a.IsRelay
|
||||||
convertedNode.IsRelayed = a.IsRelayed
|
convertedNode.IsRelayed = a.IsRelayed
|
||||||
convertedNode.PendingDelete = a.PendingDelete
|
convertedNode.PendingDelete = a.PendingDelete
|
||||||
convertedNode.Peers = currentNode.Peers
|
//convertedNode.Peers = currentNode.Peers
|
||||||
convertedNode.Failover = a.Failover
|
convertedNode.Failover = a.Failover
|
||||||
convertedNode.IsEgressGateway = a.IsEgressGateway
|
convertedNode.IsEgressGateway = a.IsEgressGateway
|
||||||
convertedNode.IsIngressGateway = a.IsIngressGateway
|
convertedNode.IsIngressGateway = a.IsIngressGateway
|
||||||
|
|||||||
@@ -12,35 +12,36 @@ const WIREGUARD_INTERFACE = "netmaker"
|
|||||||
|
|
||||||
// Host - represents a host on the network
|
// Host - represents a host on the network
|
||||||
type Host struct {
|
type Host struct {
|
||||||
ID uuid.UUID `json:"id" yaml:"id"`
|
ID uuid.UUID `json:"id" yaml:"id"`
|
||||||
Verbosity int `json:"verbosity" yaml:"verbosity"`
|
Verbosity int `json:"verbosity" yaml:"verbosity"`
|
||||||
FirewallInUse string `json:"firewallinuse" yaml:"firewallinuse"`
|
FirewallInUse string `json:"firewallinuse" yaml:"firewallinuse"`
|
||||||
Version string `json:"version" yaml:"version"`
|
Version string `json:"version" yaml:"version"`
|
||||||
IPForwarding bool `json:"ipforwarding" yaml:"ipforwarding"`
|
IPForwarding bool `json:"ipforwarding" yaml:"ipforwarding"`
|
||||||
DaemonInstalled bool `json:"daemoninstalled" yaml:"daemoninstalled"`
|
DaemonInstalled bool `json:"daemoninstalled" yaml:"daemoninstalled"`
|
||||||
HostPass string `json:"hostpass" yaml:"hostpass"`
|
HostPass string `json:"hostpass" yaml:"hostpass"`
|
||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
OS string `json:"os" yaml:"os"`
|
OS string `json:"os" yaml:"os"`
|
||||||
Interface string `json:"interface" yaml:"interface"`
|
Interface string `json:"interface" yaml:"interface"`
|
||||||
Debug bool `json:"debug" yaml:"debug"`
|
Debug bool `json:"debug" yaml:"debug"`
|
||||||
ListenPort int `json:"listenport" yaml:"listenport"`
|
ListenPort int `json:"listenport" yaml:"listenport"`
|
||||||
LocalAddress net.IPNet `json:"localaddress" yaml:"localaddress"`
|
LocalAddress net.IPNet `json:"localaddress" yaml:"localaddress"`
|
||||||
LocalRange net.IPNet `json:"localrange" yaml:"localrange"`
|
LocalRange net.IPNet `json:"localrange" yaml:"localrange"`
|
||||||
LocalListenPort int `json:"locallistenport" yaml:"locallistenport"`
|
LocalListenPort int `json:"locallistenport" yaml:"locallistenport"`
|
||||||
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
|
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
|
||||||
MTU int `json:"mtu" yaml:"mtu"`
|
MTU int `json:"mtu" yaml:"mtu"`
|
||||||
PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
|
PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
|
||||||
MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
|
MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
|
||||||
TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"trafficekeypublic"`
|
TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"trafficekeypublic"`
|
||||||
InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
|
InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
|
||||||
Nodes []string `json:"nodes" yaml:"nodes"`
|
Nodes []string `json:"nodes" yaml:"nodes"`
|
||||||
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
||||||
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
|
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
|
||||||
ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
|
ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
|
||||||
IsDocker bool `json:"isdocker" yaml:"isdocker"`
|
IsDocker bool `json:"isdocker" yaml:"isdocker"`
|
||||||
IsK8S bool `json:"isk8s" yaml:"isk8s"`
|
IsK8S bool `json:"isk8s" yaml:"isk8s"`
|
||||||
IsStatic bool `json:"isstatic" yaml:"isstatic"`
|
IsStatic bool `json:"isstatic" yaml:"isstatic"`
|
||||||
IsDefault bool `json:"isdefault" yaml:"isdefault"`
|
IsDefault bool `json:"isdefault" yaml:"isdefault"`
|
||||||
|
Peers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatBool converts a boolean to a [yes|no] string
|
// FormatBool converts a boolean to a [yes|no] string
|
||||||
|
|||||||
@@ -56,27 +56,26 @@ type Iface struct {
|
|||||||
|
|
||||||
// CommonNode - represents a commonn node data elements shared by netmaker and netclient
|
// CommonNode - represents a commonn node data elements shared by netmaker and netclient
|
||||||
type CommonNode struct {
|
type CommonNode struct {
|
||||||
ID uuid.UUID `json:"id" yaml:"id"`
|
ID uuid.UUID `json:"id" yaml:"id"`
|
||||||
HostID uuid.UUID `json:"hostid" yaml:"hostid"`
|
HostID uuid.UUID `json:"hostid" yaml:"hostid"`
|
||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
Network string `json:"network" yaml:"network"`
|
Network string `json:"network" yaml:"network"`
|
||||||
NetworkRange net.IPNet `json:"networkrange" yaml:"networkrange"`
|
NetworkRange net.IPNet `json:"networkrange" yaml:"networkrange"`
|
||||||
NetworkRange6 net.IPNet `json:"networkrange6" yaml:"networkrange6"`
|
NetworkRange6 net.IPNet `json:"networkrange6" yaml:"networkrange6"`
|
||||||
InternetGateway *net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
|
InternetGateway *net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
|
||||||
Server string `json:"server" yaml:"server"`
|
Server string `json:"server" yaml:"server"`
|
||||||
Connected bool `json:"connected" yaml:"connected"`
|
Connected bool `json:"connected" yaml:"connected"`
|
||||||
Address net.IPNet `json:"address" yaml:"address"`
|
Address net.IPNet `json:"address" yaml:"address"`
|
||||||
Address6 net.IPNet `json:"address6" yaml:"address6"`
|
Address6 net.IPNet `json:"address6" yaml:"address6"`
|
||||||
PostUp string `json:"postup" yaml:"postup"`
|
PostUp string `json:"postup" yaml:"postup"`
|
||||||
PostDown string `json:"postdown" yaml:"postdown"`
|
PostDown string `json:"postdown" yaml:"postdown"`
|
||||||
Action string `json:"action" yaml:"action"`
|
Action string `json:"action" yaml:"action"`
|
||||||
LocalAddress net.IPNet `json:"localaddress" yaml:"localaddress"`
|
LocalAddress net.IPNet `json:"localaddress" yaml:"localaddress"`
|
||||||
IsLocal bool `json:"islocal" yaml:"islocal"`
|
IsLocal bool `json:"islocal" yaml:"islocal"`
|
||||||
IsEgressGateway bool `json:"isegressgateway" yaml:"isegressgateway"`
|
IsEgressGateway bool `json:"isegressgateway" yaml:"isegressgateway"`
|
||||||
IsIngressGateway bool `json:"isingressgateway" yaml:"isingressgateway"`
|
IsIngressGateway bool `json:"isingressgateway" yaml:"isingressgateway"`
|
||||||
DNSOn bool `json:"dnson" yaml:"dnson"`
|
DNSOn bool `json:"dnson" yaml:"dnson"`
|
||||||
PersistentKeepalive time.Duration `json:"persistentkeepalive" yaml:"persistentkeepalive"`
|
PersistentKeepalive time.Duration `json:"persistentkeepalive" yaml:"persistentkeepalive"`
|
||||||
Peers []wgtypes.PeerConfig `json:"peers" yaml:"peers"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node - a model of a network node
|
// Node - a model of a network node
|
||||||
|
|||||||
@@ -206,7 +206,6 @@ type NodeGet struct {
|
|||||||
Host Host `json:"host" yaml:"host"`
|
Host Host `json:"host" yaml:"host"`
|
||||||
Peers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
|
Peers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
|
||||||
ServerConfig ServerConfig `json:"serverconfig" bson:"serverconfig" yaml:"serverconfig"`
|
ServerConfig ServerConfig `json:"serverconfig" bson:"serverconfig" yaml:"serverconfig"`
|
||||||
PeerIDs PeerMap `json:"peerids,omitempty" bson:"peerids,omitempty" yaml:"peerids,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeJoinResponse data returned to node in response to join
|
// NodeJoinResponse data returned to node in response to join
|
||||||
@@ -214,7 +213,6 @@ type NodeJoinResponse struct {
|
|||||||
Node Node `json:"node" bson:"node" yaml:"node"`
|
Node Node `json:"node" bson:"node" yaml:"node"`
|
||||||
Host Host `json:"host" yaml:"host"`
|
Host Host `json:"host" yaml:"host"`
|
||||||
ServerConfig ServerConfig `json:"serverconfig" bson:"serverconfig" yaml:"serverconfig"`
|
ServerConfig ServerConfig `json:"serverconfig" bson:"serverconfig" yaml:"serverconfig"`
|
||||||
PeerIDs PeerMap `json:"peerids,omitempty" bson:"peerids,omitempty" yaml:"peerids,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfig - struct for dealing with the server information for a netclient
|
// ServerConfig - struct for dealing with the server information for a netclient
|
||||||
|
|||||||
@@ -74,31 +74,7 @@ func PublishSingleHostUpdate(host *models.Host) error {
|
|||||||
|
|
||||||
// PublishPeerUpdate --- publishes a peer update to all the peers of a node
|
// PublishPeerUpdate --- publishes a peer update to all the peers of a node
|
||||||
func PublishExtPeerUpdate(node *models.Node) error {
|
func PublishExtPeerUpdate(node *models.Node) error {
|
||||||
host, err := logic.GetHost(node.HostID.String())
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if !servercfg.IsMessageQueueBackend() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
peerUpdate, err := logic.GetPeerUpdate(node, host)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
data, err := json.Marshal(&peerUpdate)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if host.ProxyEnabled {
|
|
||||||
proxyUpdate, err := logic.GetPeersForProxy(node, false)
|
|
||||||
if err == nil {
|
|
||||||
peerUpdate.ProxyUpdate = proxyUpdate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = publish(host, fmt.Sprintf("peers/%s/%s", node.Network, node.ID), data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
go PublishPeerUpdate(node.Network, false)
|
go PublishPeerUpdate(node.Network, false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user