mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-31 15:16:58 +02:00
Use a single way to generate network map (#550)
This commit is contained in:
parent
7d7e576775
commit
157137e4ad
@ -254,7 +254,6 @@ func (s *GRPCServer) registerPeer(peerKey wgtypes.Key, req *proto.LoginRequest)
|
|||||||
}
|
}
|
||||||
// notify other peers of our registration
|
// notify other peers of our registration
|
||||||
for _, remotePeer := range networkMap.Peers {
|
for _, remotePeer := range networkMap.Peers {
|
||||||
// todo update this once we have store v2 to avoid lock/peer
|
|
||||||
remotePeerNetworkMap, err := s.accountManager.GetNetworkMap(remotePeer.Key)
|
remotePeerNetworkMap, err := s.accountManager.GetNetworkMap(remotePeer.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "unable to fetch network map after registering peer, error: %v", err)
|
return nil, status.Errorf(codes.Internal, "unable to fetch network map after registering peer, error: %v", err)
|
||||||
@ -390,6 +389,9 @@ func ToResponseProto(configProto Protocol) proto.HostConfig_Protocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func toWiretrusteeConfig(config *Config, turnCredentials *TURNCredentials) *proto.WiretrusteeConfig {
|
func toWiretrusteeConfig(config *Config, turnCredentials *TURNCredentials) *proto.WiretrusteeConfig {
|
||||||
|
if config == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
var stuns []*proto.HostConfig
|
var stuns []*proto.HostConfig
|
||||||
for _, stun := range config.Stuns {
|
for _, stun := range config.Stuns {
|
||||||
stuns = append(stuns, &proto.HostConfig{
|
stuns = append(stuns, &proto.HostConfig{
|
||||||
|
@ -281,9 +281,6 @@ func (am *DefaultAccountManager) GetNetworkMap(peerPubKey string) (*NetworkMap,
|
|||||||
aclPeers := am.getPeersByACL(account, peerPubKey)
|
aclPeers := am.getPeersByACL(account, peerPubKey)
|
||||||
routesUpdate := account.GetPeersRoutes(append(aclPeers, account.Peers[peerPubKey]))
|
routesUpdate := account.GetPeersRoutes(append(aclPeers, account.Peers[peerPubKey]))
|
||||||
|
|
||||||
// todo extract this with the store v2
|
|
||||||
// this should become part of the method parameters
|
|
||||||
// to prevent slow performance when called in a parent loop
|
|
||||||
var zones []nbdns.CustomZone
|
var zones []nbdns.CustomZone
|
||||||
peersCustomZone := getPeersCustomZone(account, am.dnsDomain)
|
peersCustomZone := getPeersCustomZone(account, am.dnsDomain)
|
||||||
if peersCustomZone.Domain != "" {
|
if peersCustomZone.Domain != "" {
|
||||||
@ -584,43 +581,18 @@ func (am *DefaultAccountManager) getPeersByACL(account *Account, peerPubKey stri
|
|||||||
// updateAccountPeers updates all peers that belong to an account.
|
// updateAccountPeers updates all peers that belong to an account.
|
||||||
// Should be called when changes have to be synced to peers.
|
// Should be called when changes have to be synced to peers.
|
||||||
func (am *DefaultAccountManager) updateAccountPeers(account *Account) error {
|
func (am *DefaultAccountManager) updateAccountPeers(account *Account) error {
|
||||||
// notify other peers of the change
|
|
||||||
peers := account.GetPeers()
|
peers := account.GetPeers()
|
||||||
network := account.Network.Copy()
|
|
||||||
var zones []nbdns.CustomZone
|
|
||||||
peersCustomZone := getPeersCustomZone(account, am.dnsDomain)
|
|
||||||
if peersCustomZone.Domain != "" {
|
|
||||||
zones = append(zones, peersCustomZone)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
aclPeers := am.getPeersByACL(account, peer.Key)
|
remotePeerNetworkMap, err := am.GetNetworkMap(peer.Key)
|
||||||
peersUpdate := toRemotePeerConfig(aclPeers)
|
|
||||||
routesUpdate := toProtocolRoutes(account.GetPeersRoutes(append(aclPeers, peer)))
|
|
||||||
dnsUpdate := toProtocolDNSConfig(nbdns.Config{
|
|
||||||
ServiceEnable: true,
|
|
||||||
CustomZones: zones,
|
|
||||||
NameServerGroups: getPeerNSGroups(account, peer.Key),
|
|
||||||
})
|
|
||||||
err := am.peersUpdateManager.SendUpdate(peer.Key,
|
|
||||||
&UpdateMessage{
|
|
||||||
Update: &proto.SyncResponse{
|
|
||||||
// fill deprecated fields for backward compatibility
|
|
||||||
RemotePeers: peersUpdate,
|
|
||||||
RemotePeersIsEmpty: len(peersUpdate) == 0,
|
|
||||||
// new field
|
|
||||||
NetworkMap: &proto.NetworkMap{
|
|
||||||
Serial: account.Network.CurrentSerial(),
|
|
||||||
RemotePeers: peersUpdate,
|
|
||||||
RemotePeersIsEmpty: len(peersUpdate) == 0,
|
|
||||||
PeerConfig: toPeerConfig(peer, network),
|
|
||||||
Routes: routesUpdate,
|
|
||||||
DNSConfig: dnsUpdate,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return status.Errorf(codes.Internal, "unable to fetch network map for peer %s, error: %v", peer.Key, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
update := toSyncResponse(nil, peer, nil, remotePeerNetworkMap)
|
||||||
|
err = am.peersUpdateManager.SendUpdate(peer.Key, &UpdateMessage{Update: update})
|
||||||
|
if err != nil {
|
||||||
|
return status.Errorf(codes.Internal, "unable to send update for peer %s, error: %v", peer.Key, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user