mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 09:47:49 +02:00
another log and different approach for meta calc
This commit is contained in:
parent
9dc9402deb
commit
ebf3d26c91
@ -166,7 +166,8 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
|
|||||||
ctx = context.WithValue(ctx, nbContext.AccountIDKey, accountID)
|
ctx = context.WithValue(ctx, nbContext.AccountIDKey, accountID)
|
||||||
|
|
||||||
realIP := getRealIP(ctx)
|
realIP := getRealIP(ctx)
|
||||||
log.WithContext(ctx).Debugf("Sync request from peer [%s] [%s] [%s]", req.WgPubKey, realIP.String(), metaHash(extractPeerMeta(ctx, syncReq.GetMeta())))
|
sip := realIP.String()
|
||||||
|
log.WithContext(ctx).Debugf("Sync request from peer [%s] [%s] [%s]", req.WgPubKey, sip, metaHash(extractPeerMeta(ctx, syncReq.GetMeta()), sip))
|
||||||
|
|
||||||
if syncReq.GetMeta() == nil {
|
if syncReq.GetMeta() == nil {
|
||||||
log.WithContext(ctx).Tracef("peer system meta has to be provided on sync. Peer %s, remote addr %s", peerKey.String(), realIP)
|
log.WithContext(ctx).Tracef("peer system meta has to be provided on sync. Peer %s, remote addr %s", peerKey.String(), realIP)
|
||||||
|
@ -15,6 +15,9 @@ const (
|
|||||||
filterTimeout = 5 * time.Minute // Duration to secure the previous login information in the filter
|
filterTimeout = 5 * time.Minute // Duration to secure the previous login information in the filter
|
||||||
|
|
||||||
loggingLimit = 100
|
loggingLimit = 100
|
||||||
|
|
||||||
|
loggingLimitOnePeer = 30
|
||||||
|
loggingTresholdOnePeer = 5 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
type loginFilter struct {
|
type loginFilter struct {
|
||||||
@ -53,6 +56,13 @@ func (l *loginFilter) addLogin(wgPubKey, metaHash string) {
|
|||||||
"elapsed time for number of attempts": time.Since(mh.start),
|
"elapsed time for number of attempts": time.Since(mh.start),
|
||||||
"number of syncs": mh.counter,
|
"number of syncs": mh.counter,
|
||||||
}).Info(mh.prepareHashes())
|
}).Info(mh.prepareHashes())
|
||||||
|
} else if mh.counter%loggingLimitOnePeer == 0 && time.Since(mh.start) > loggingTresholdOnePeer && len(mh.hashes) == 1 {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"wgPubKey": wgPubKey,
|
||||||
|
"elapsed time for number of attempts": time.Since(mh.start),
|
||||||
|
"number of syncs": mh.counter,
|
||||||
|
}).Info(mh.prepareHashes())
|
||||||
|
mh.start = time.Now()
|
||||||
}
|
}
|
||||||
l.logged[wgPubKey] = mh
|
l.logged[wgPubKey] = mh
|
||||||
}
|
}
|
||||||
@ -66,8 +76,10 @@ func (m *metahash) prepareHashes() string {
|
|||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func metaHash(meta nbpeer.PeerSystemMeta) string {
|
func metaHash(meta nbpeer.PeerSystemMeta, pubip string) string {
|
||||||
estimatedSize := len(meta.WtVersion) + len(meta.OSVersion) + len(meta.KernelVersion) + len(meta.Hostname) + len(meta.SystemSerialNumber) + 4
|
mac := getMacAddress(meta.NetworkAddresses)
|
||||||
|
estimatedSize := len(meta.WtVersion) + len(meta.OSVersion) + len(meta.KernelVersion) + len(meta.Hostname) + len(meta.SystemSerialNumber) +
|
||||||
|
len(pubip) + len(mac) + 6
|
||||||
|
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.Grow(estimatedSize)
|
b.Grow(estimatedSize)
|
||||||
@ -81,6 +93,21 @@ func metaHash(meta nbpeer.PeerSystemMeta) string {
|
|||||||
b.WriteString(meta.Hostname)
|
b.WriteString(meta.Hostname)
|
||||||
b.WriteByte('|')
|
b.WriteByte('|')
|
||||||
b.WriteString(meta.SystemSerialNumber)
|
b.WriteString(meta.SystemSerialNumber)
|
||||||
|
b.WriteByte('|')
|
||||||
|
b.WriteString(pubip)
|
||||||
|
b.WriteByte('|')
|
||||||
|
b.WriteString(mac)
|
||||||
|
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMacAddress(nas []nbpeer.NetworkAddress) string {
|
||||||
|
if len(nas) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
macs := make([]string, 0, len(nas))
|
||||||
|
for _, na := range nas {
|
||||||
|
macs = append(macs, na.Mac)
|
||||||
|
}
|
||||||
|
return strings.Join(macs, "/")
|
||||||
|
}
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"hash/fnv"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/peer"
|
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
|
||||||
)
|
|
||||||
|
|
||||||
func BenchmarkMetaHash(b *testing.B) {
|
|
||||||
meta := peer.PeerSystemMeta{
|
|
||||||
WtVersion: "1.0.0",
|
|
||||||
OSVersion: "Linux 5.4.0",
|
|
||||||
KernelVersion: "5.4.0-42-generic",
|
|
||||||
Hostname: "test-host",
|
|
||||||
}
|
|
||||||
b.Run("fnv", func(b *testing.B) {
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
metaHashFnv(meta)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
b.Run("builder", func(b *testing.B) {
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
metaHash(meta)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
b.Run("strings", func(b *testing.B) {
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
metaHashStrings(meta)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func metaHashStrings(meta nbpeer.PeerSystemMeta) string {
|
|
||||||
return meta.WtVersion + meta.OSVersion + meta.KernelVersion + meta.Hostname
|
|
||||||
}
|
|
||||||
|
|
||||||
func metaHashFnv(meta nbpeer.PeerSystemMeta) string {
|
|
||||||
h := fnv.New64a()
|
|
||||||
h.Write([]byte(meta.WtVersion))
|
|
||||||
h.Write([]byte(meta.OSVersion))
|
|
||||||
h.Write([]byte(meta.KernelVersion))
|
|
||||||
h.Write([]byte(meta.Hostname))
|
|
||||||
return fmt.Sprintf("%x", h.Sum64())
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user