mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-16 10:20:09 +01: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
|
||||
for _, remotePeer := range networkMap.Peers {
|
||||
// todo update this once we have store v2 to avoid lock/peer
|
||||
remotePeerNetworkMap, err := s.accountManager.GetNetworkMap(remotePeer.Key)
|
||||
if err != nil {
|
||||
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 {
|
||||
if config == nil {
|
||||
return nil
|
||||
}
|
||||
var stuns []*proto.HostConfig
|
||||
for _, stun := range config.Stuns {
|
||||
stuns = append(stuns, &proto.HostConfig{
|
||||
|
@ -281,9 +281,6 @@ func (am *DefaultAccountManager) GetNetworkMap(peerPubKey string) (*NetworkMap,
|
||||
aclPeers := am.getPeersByACL(account, 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
|
||||
peersCustomZone := getPeersCustomZone(account, am.dnsDomain)
|
||||
if peersCustomZone.Domain != "" {
|
||||
@ -584,43 +581,18 @@ func (am *DefaultAccountManager) getPeersByACL(account *Account, peerPubKey stri
|
||||
// updateAccountPeers updates all peers that belong to an account.
|
||||
// Should be called when changes have to be synced to peers.
|
||||
func (am *DefaultAccountManager) updateAccountPeers(account *Account) error {
|
||||
// notify other peers of the change
|
||||
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 {
|
||||
aclPeers := am.getPeersByACL(account, 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,
|
||||
},
|
||||
},
|
||||
})
|
||||
remotePeerNetworkMap, err := am.GetNetworkMap(peer.Key)
|
||||
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…
Reference in New Issue
Block a user