upgrade diff package

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-10-09 17:01:40 +03:00
parent 2a751645f9
commit 271bed5f73
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547
4 changed files with 128 additions and 126 deletions

3
go.mod
View File

@ -71,6 +71,7 @@ require (
github.com/pion/turn/v3 v3.0.1 github.com/pion/turn/v3 v3.0.1
github.com/prometheus/client_golang v1.19.1 github.com/prometheus/client_golang v1.19.1
github.com/r3labs/diff v1.1.0 github.com/r3labs/diff v1.1.0
github.com/r3labs/diff/v3 v3.0.1
github.com/rs/xid v1.3.0 github.com/rs/xid v1.3.0
github.com/shirou/gopsutil/v3 v3.24.4 github.com/shirou/gopsutil/v3 v3.24.4
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
@ -211,6 +212,8 @@ require (
github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect github.com/tklauser/numcpus v0.8.0 // indirect
github.com/vishvananda/netns v0.0.4 // indirect github.com/vishvananda/netns v0.0.4 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.1 // indirect github.com/yuin/goldmark v1.7.1 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect github.com/zeebo/blake3 v0.2.3 // indirect
go.opencensus.io v0.24.0 // indirect go.opencensus.io v0.24.0 // indirect

6
go.sum
View File

@ -607,6 +607,8 @@ github.com/prometheus/procfs v0.15.0 h1:A82kmvXJq2jTu5YUhSGNlYoxh85zLnKgPz4bMZgI
github.com/prometheus/procfs v0.15.0/go.mod h1:Y0RJ/Y5g5wJpkTisOtqwDSo4HwhGmLB4VQSw2sQJLHk= github.com/prometheus/procfs v0.15.0/go.mod h1:Y0RJ/Y5g5wJpkTisOtqwDSo4HwhGmLB4VQSw2sQJLHk=
github.com/r3labs/diff v1.1.0 h1:V53xhrbTHrWFWq3gI4b94AjgEJOerO1+1l0xyHOBi8M= github.com/r3labs/diff v1.1.0 h1:V53xhrbTHrWFWq3gI4b94AjgEJOerO1+1l0xyHOBi8M=
github.com/r3labs/diff v1.1.0/go.mod h1:7WjXasNzi0vJetRcB/RqNl5dlIsmXcTTLmF5IoH6Xig= github.com/r3labs/diff v1.1.0/go.mod h1:7WjXasNzi0vJetRcB/RqNl5dlIsmXcTTLmF5IoH6Xig=
github.com/r3labs/diff/v3 v3.0.1 h1:CBKqf3XmNRHXKmdU7mZP1w7TV0pDyVCis1AUHtA4Xtg=
github.com/r3labs/diff/v3 v3.0.1/go.mod h1:f1S9bourRbiM66NskseyUdo0fTmEE0qKrikYJX63dgo=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
@ -699,6 +701,10 @@ github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhg
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View File

@ -6,9 +6,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/netbirdio/netbird/management/server/differs"
"github.com/netbirdio/netbird/management/server/posture" "github.com/netbirdio/netbird/management/server/posture"
"github.com/r3labs/diff" "github.com/r3labs/diff/v3"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/netbirdio/netbird/management/proto" "github.com/netbirdio/netbird/management/proto"
@ -237,14 +236,7 @@ func isNewPeerUpdateMessage(lastSentUpdate, currUpdateToSend *UpdateMessage) (bo
return true, nil return true, nil
} }
differ, err := diff.NewDiffer( changelog, err = diff.Diff(lastSentUpdate.NetworkMap, currUpdateToSend.NetworkMap)
diff.CustomValueDiffers(differs.NewNameServerComparator(), differs.NewRouteComparator()),
)
if err != nil {
return false, err
}
changelog, err = differ.Diff(lastSentUpdate.NetworkMap, currUpdateToSend.NetworkMap)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to diff network map: %v", err) return false, fmt.Errorf("failed to diff network map: %v", err)
} }

View File

@ -8,11 +8,9 @@ import (
"time" "time"
nbdns "github.com/netbirdio/netbird/dns" nbdns "github.com/netbirdio/netbird/dns"
"github.com/netbirdio/netbird/management/domain"
"github.com/netbirdio/netbird/management/proto" "github.com/netbirdio/netbird/management/proto"
nbpeer "github.com/netbirdio/netbird/management/server/peer" nbpeer "github.com/netbirdio/netbird/management/server/peer"
"github.com/netbirdio/netbird/management/server/posture" "github.com/netbirdio/netbird/management/server/posture"
nbroute "github.com/netbirdio/netbird/route"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -370,118 +368,121 @@ func TestIsNewPeerUpdateMessage(t *testing.T) {
func createMockUpdateMessage(t *testing.T) *UpdateMessage { func createMockUpdateMessage(t *testing.T) *UpdateMessage {
t.Helper() t.Helper()
//_, ipNet, err := net.ParseCIDR("192.168.1.0/24")
_, ipNet, err := net.ParseCIDR("192.168.1.0/24") //if err != nil {
if err != nil { // t.Fatal(err)
t.Fatal(err) //}
} //domainList, err := domain.FromStringList([]string{"example.com"})
domainList, err := domain.FromStringList([]string{"example.com"}) //if err != nil {
if err != nil { // t.Fatal(err)
t.Fatal(err) //}
} //
//config := &Config{
config := &Config{ // Signal: &Host{
Signal: &Host{ // Proto: "https",
Proto: "https", // URI: "signal.uri",
URI: "signal.uri", // Username: "",
Username: "", // Password: "",
Password: "", // },
}, // Stuns: []*Host{{URI: "stun.uri", Proto: UDP}},
Stuns: []*Host{{URI: "stun.uri", Proto: UDP}}, // TURNConfig: &TURNConfig{
TURNConfig: &TURNConfig{ // Turns: []*Host{{URI: "turn.uri", Proto: UDP, Username: "turn-user", Password: "turn-pass"}},
Turns: []*Host{{URI: "turn.uri", Proto: UDP, Username: "turn-user", Password: "turn-pass"}}, // },
}, //}
} //peer := &nbpeer.Peer{
peer := &nbpeer.Peer{ // IP: net.ParseIP("192.168.1.1"),
IP: net.ParseIP("192.168.1.1"), // SSHEnabled: true,
SSHEnabled: true, // Key: "peer-key",
Key: "peer-key", // DNSLabel: "peer1",
DNSLabel: "peer1", // SSHKey: "peer1-ssh-key",
SSHKey: "peer1-ssh-key", //}
} //
turnCredentials := &TURNCredentials{ ////NewTimeBasedAuthSecretsManager(updateManager *PeersUpdateManager, turnCfg *TURNConfig, relayCfg *Relay)
Username: "turn-user", ////turnCredentials := &TURNCredentials{
Password: "turn-pass", //// Username: "turn-user",
} //// Password: "turn-pass",
networkMap := &NetworkMap{ ////}
Network: &Network{Net: *ipNet, Serial: 1000}, //
Peers: []*nbpeer.Peer{{IP: net.ParseIP("192.168.1.2"), Key: "peer2-key", DNSLabel: "peer2", SSHEnabled: true, SSHKey: "peer2-ssh-key"}}, //networkMap := &NetworkMap{
OfflinePeers: []*nbpeer.Peer{{IP: net.ParseIP("192.168.1.3"), Key: "peer3-key", DNSLabel: "peer3", SSHEnabled: true, SSHKey: "peer3-ssh-key"}}, // Network: &Network{Net: *ipNet, Serial: 1000},
Routes: []*nbroute.Route{ // Peers: []*nbpeer.Peer{{IP: net.ParseIP("192.168.1.2"), Key: "peer2-key", DNSLabel: "peer2", SSHEnabled: true, SSHKey: "peer2-ssh-key"}},
{ // OfflinePeers: []*nbpeer.Peer{{IP: net.ParseIP("192.168.1.3"), Key: "peer3-key", DNSLabel: "peer3", SSHEnabled: true, SSHKey: "peer3-ssh-key"}},
ID: "route1", // Routes: []*nbroute.Route{
Network: netip.MustParsePrefix("10.0.0.0/24"), // {
KeepRoute: true, // ID: "route1",
NetID: "route1", // Network: netip.MustParsePrefix("10.0.0.0/24"),
Peer: "peer1", // KeepRoute: true,
NetworkType: 1, // NetID: "route1",
Masquerade: true, // Peer: "peer1",
Metric: 9999, // NetworkType: 1,
Enabled: true, // Masquerade: true,
Groups: []string{"test1", "test2"}, // Metric: 9999,
}, // Enabled: true,
{ // Groups: []string{"test1", "test2"},
ID: "route2", // },
Domains: domainList, // {
KeepRoute: true, // ID: "route2",
NetID: "route2", // Domains: domainList,
Peer: "peer1", // KeepRoute: true,
NetworkType: 1, // NetID: "route2",
Masquerade: true, // Peer: "peer1",
Metric: 9999, // NetworkType: 1,
Enabled: true, // Masquerade: true,
Groups: []string{"test1", "test2"}, // Metric: 9999,
}, // Enabled: true,
}, // Groups: []string{"test1", "test2"},
DNSConfig: nbdns.Config{ // },
ServiceEnable: true, // },
NameServerGroups: []*nbdns.NameServerGroup{ // DNSConfig: nbdns.Config{
{ // ServiceEnable: true,
NameServers: []nbdns.NameServer{{ // NameServerGroups: []*nbdns.NameServerGroup{
IP: netip.MustParseAddr("8.8.8.8"), // {
NSType: nbdns.UDPNameServerType, // NameServers: []nbdns.NameServer{{
Port: nbdns.DefaultDNSPort, // IP: netip.MustParseAddr("8.8.8.8"),
}}, // NSType: nbdns.UDPNameServerType,
Primary: true, // Port: nbdns.DefaultDNSPort,
Domains: []string{"example.com"}, // }},
Enabled: true, // Primary: true,
SearchDomainsEnabled: true, // Domains: []string{"example.com"},
}, // Enabled: true,
{ // SearchDomainsEnabled: true,
ID: "ns1", // },
NameServers: []nbdns.NameServer{{ // {
IP: netip.MustParseAddr("1.1.1.1"), // ID: "ns1",
NSType: nbdns.UDPNameServerType, // NameServers: []nbdns.NameServer{{
Port: nbdns.DefaultDNSPort, // IP: netip.MustParseAddr("1.1.1.1"),
}}, // NSType: nbdns.UDPNameServerType,
Groups: []string{"group1"}, // Port: nbdns.DefaultDNSPort,
Primary: true, // }},
Domains: []string{"example.com"}, // Groups: []string{"group1"},
Enabled: true, // Primary: true,
SearchDomainsEnabled: true, // Domains: []string{"example.com"},
}, // Enabled: true,
}, // SearchDomainsEnabled: true,
CustomZones: []nbdns.CustomZone{{Domain: "example.com", Records: []nbdns.SimpleRecord{{Name: "example.com", Type: 1, Class: "IN", TTL: 60, RData: "100.64.0.1"}}}}, // },
}, // },
FirewallRules: []*FirewallRule{ // CustomZones: []nbdns.CustomZone{{Domain: "example.com", Records: []nbdns.SimpleRecord{{Name: "example.com", Type: 1, Class: "IN", TTL: 60, RData: "100.64.0.1"}}}},
{PeerIP: "192.168.1.2", Direction: firewallRuleDirectionIN, Action: string(PolicyTrafficActionAccept), Protocol: string(PolicyRuleProtocolTCP), Port: "80"}, // },
}, // FirewallRules: []*FirewallRule{
} // {PeerIP: "192.168.1.2", Direction: firewallRuleDirectionIN, Action: string(PolicyTrafficActionAccept), Protocol: string(PolicyRuleProtocolTCP), Port: "80"},
dnsName := "example.com" // },
checks := []*posture.Checks{ //}
{ //dnsName := "example.com"
Checks: posture.ChecksDefinition{ //checks := []*posture.Checks{
ProcessCheck: &posture.ProcessCheck{ // {
Processes: []posture.Process{{LinuxPath: "/usr/bin/netbird"}}, // Checks: posture.ChecksDefinition{
}, // ProcessCheck: &posture.ProcessCheck{
}, // Processes: []posture.Process{{LinuxPath: "/usr/bin/netbird"}},
}, // },
} // },
dnsCache := &DNSConfigCache{} // },
//}
return &UpdateMessage{ //dnsCache := &DNSConfigCache{}
Update: toSyncResponse(context.Background(), config, peer, turnCredentials, networkMap, dnsName, checks, dnsCache), //
NetworkMap: networkMap, //return &UpdateMessage{
Checks: checks, // //Update: toSyncResponse(context.Background(), config, peer, turnCredentials, networkMap, dnsName, checks, dnsCache),
} // NetworkMap: networkMap,
// Checks: checks,
//}
return nil
} }