Skip to content

Commit 0d2845e

Browse files
[management] optimize proxy network map (#4324)
1 parent f425870 commit 0d2845e

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ require (
6363
github.com/miekg/dns v1.1.59
6464
github.com/mitchellh/hashstructure/v2 v2.0.2
6565
github.com/nadoo/ipset v0.5.0
66-
github.com/netbirdio/management-integrations/integrations v0.0.0-20250812185008-dfc66fa49a2e
66+
github.com/netbirdio/management-integrations/integrations v0.0.0-20250820151658-9ee1b34f4190
6767
github.com/netbirdio/signal-dispatcher/dispatcher v0.0.0-20250805121659-6b4ac470ca45
6868
github.com/okta/okta-sdk-golang/v2 v2.18.0
6969
github.com/oschwald/maxminddb-golang v1.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944 h1:TDtJKmM6S
503503
github.com/netbirdio/go-netroute v0.0.0-20240611143515-f59b0e1d3944/go.mod h1:sHA6TRxjQ6RLbnI+3R4DZo2Eseg/iKiPRfNmcuNySVQ=
504504
github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e h1:PURA50S8u4mF6RrkYYCAvvPCixhqqEiEy3Ej6avh04c=
505505
github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e/go.mod h1:YMLU7qbKfVjmEv7EoZPIVEI+kNYxWCdPK3VS0BU+U4Q=
506-
github.com/netbirdio/management-integrations/integrations v0.0.0-20250812185008-dfc66fa49a2e h1:S85laGfx1UP+nmRF9smP6/TY965kLWz41PbBK1TX8g0=
507-
github.com/netbirdio/management-integrations/integrations v0.0.0-20250812185008-dfc66fa49a2e/go.mod h1:Jjve0+eUjOLKL3PJtAhjfM2iJ0SxWio5elHqlV1ymP8=
506+
github.com/netbirdio/management-integrations/integrations v0.0.0-20250820151658-9ee1b34f4190 h1:/ZbExdcDwRq6XgTpTf5I1DPqnC3eInEf0fcmkqR8eSg=
507+
github.com/netbirdio/management-integrations/integrations v0.0.0-20250820151658-9ee1b34f4190/go.mod h1:v0nUbbHbuQnqR7yKIYnKzsLBCswLtp2JctmKYmGgVhc=
508508
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502 h1:3tHlFmhTdX9axERMVN63dqyFqnvuD+EMJHzM7mNGON8=
509509
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
510510
github.com/netbirdio/signal-dispatcher/dispatcher v0.0.0-20250805121659-6b4ac470ca45 h1:ujgviVYmx243Ksy7NdSwrdGPSRNE3pb8kEDSpH0QuAQ=

management/server/integrations/port_forwarding/controller.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package port_forwarding
33
import (
44
"context"
55

6+
"github.com/netbirdio/netbird/management/server/peer"
67
nbtypes "github.com/netbirdio/netbird/management/server/types"
78
)
89

910
type Controller interface {
10-
SendUpdate(ctx context.Context, accountID string, affectedProxyID string, affectedPeerIDs []string)
11-
GetProxyNetworkMaps(ctx context.Context, accountID string) (map[string]*nbtypes.NetworkMap, error)
11+
SendUpdate(ctx context.Context, accountID string, affectedProxyID string, affectedPeerIDs []string, accountPeers map[string]*peer.Peer)
12+
GetProxyNetworkMaps(ctx context.Context, accountID, peerID string, accountPeers map[string]*peer.Peer) (map[string]*nbtypes.NetworkMap, error)
13+
GetProxyNetworkMapsAll(ctx context.Context, accountID string, accountPeers map[string]*peer.Peer) (map[string]*nbtypes.NetworkMap, error)
1214
IsPeerInIngressPorts(ctx context.Context, accountID, peerID string) (bool, error)
1315
}
1416

@@ -19,11 +21,15 @@ func NewControllerMock() *ControllerMock {
1921
return &ControllerMock{}
2022
}
2123

22-
func (c *ControllerMock) SendUpdate(ctx context.Context, accountID string, affectedProxyID string, affectedPeerIDs []string) {
24+
func (c *ControllerMock) SendUpdate(ctx context.Context, accountID string, affectedProxyID string, affectedPeerIDs []string, accountPeers map[string]*peer.Peer) {
2325
// noop
2426
}
2527

26-
func (c *ControllerMock) GetProxyNetworkMaps(ctx context.Context, accountID string) (map[string]*nbtypes.NetworkMap, error) {
28+
func (c *ControllerMock) GetProxyNetworkMaps(ctx context.Context, accountID, peerID string, accountPeers map[string]*peer.Peer) (map[string]*nbtypes.NetworkMap, error) {
29+
return make(map[string]*nbtypes.NetworkMap), nil
30+
}
31+
32+
func (c *ControllerMock) GetProxyNetworkMapsAll(ctx context.Context, accountID string, accountPeers map[string]*peer.Peer) (map[string]*nbtypes.NetworkMap, error) {
2733
return make(map[string]*nbtypes.NetworkMap), nil
2834
}
2935

management/server/peer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (am *DefaultAccountManager) GetNetworkMap(ctx context.Context, peerID strin
427427
}
428428
customZone := account.GetPeersCustomZone(ctx, am.GetDNSDomain(account.Settings))
429429

430-
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMaps(ctx, account.Id)
430+
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMaps(ctx, account.Id, peerID, account.Peers)
431431
if err != nil {
432432
log.WithContext(ctx).Errorf("failed to get proxy network maps: %v", err)
433433
return nil, err
@@ -1033,7 +1033,7 @@ func (am *DefaultAccountManager) getValidatedPeerWithMap(ctx context.Context, is
10331033

10341034
customZone := account.GetPeersCustomZone(ctx, am.GetDNSDomain(account.Settings))
10351035

1036-
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMaps(ctx, account.Id)
1036+
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMaps(ctx, account.Id, peer.ID, account.Peers)
10371037
if err != nil {
10381038
log.WithContext(ctx).Errorf("failed to get proxy network maps: %v", err)
10391039
return nil, nil, nil, err
@@ -1206,7 +1206,7 @@ func (am *DefaultAccountManager) UpdateAccountPeers(ctx context.Context, account
12061206
resourcePolicies := account.GetResourcePoliciesMap()
12071207
routers := account.GetResourceRoutersMap()
12081208

1209-
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMaps(ctx, accountID)
1209+
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMapsAll(ctx, accountID, account.Peers)
12101210
if err != nil {
12111211
log.WithContext(ctx).Errorf("failed to get proxy network maps: %v", err)
12121212
return
@@ -1345,7 +1345,7 @@ func (am *DefaultAccountManager) UpdateAccountPeer(ctx context.Context, accountI
13451345
return
13461346
}
13471347

1348-
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMaps(ctx, accountId)
1348+
proxyNetworkMaps, err := am.proxyController.GetProxyNetworkMaps(ctx, accountId, peerId, account.Peers)
13491349
if err != nil {
13501350
log.WithContext(ctx).Errorf("failed to get proxy network maps: %v", err)
13511351
return

management/server/peer/peer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Peer struct {
2424
// Meta is a Peer system meta data
2525
Meta PeerSystemMeta `gorm:"embedded;embeddedPrefix:meta_"`
2626
// Name is peer's name (machine name)
27-
Name string
27+
Name string `gorm:"index"`
2828
// DNSLabel is the parsed peer name for domain resolution. It is used to form an FQDN by appending the account's
2929
// domain to the peer label. e.g. peer-dns-label.netbird.cloud
3030
DNSLabel string // uniqueness index per accountID (check migrations)

0 commit comments

Comments
 (0)