mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 09:47:49 +02:00
added logging for blocked peers, removed map size
This commit is contained in:
parent
7890cb4f32
commit
2f73b7a35f
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -48,6 +49,8 @@ type GRPCServer struct {
|
|||||||
ephemeralManager *EphemeralManager
|
ephemeralManager *EphemeralManager
|
||||||
peerLocks sync.Map
|
peerLocks sync.Map
|
||||||
authManager auth.Manager
|
authManager auth.Manager
|
||||||
|
|
||||||
|
logBlockedPeers bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new Management server
|
// NewServer creates a new Management server
|
||||||
@ -77,6 +80,8 @@ func NewServer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logBlockedPeers := os.Getenv("NB_LOG_BLOCKED_PEERS") == "true"
|
||||||
|
|
||||||
return &GRPCServer{
|
return &GRPCServer{
|
||||||
wgKey: key,
|
wgKey: key,
|
||||||
// peerKey -> event channel
|
// peerKey -> event channel
|
||||||
@ -88,6 +93,7 @@ func NewServer(
|
|||||||
authManager: authManager,
|
authManager: authManager,
|
||||||
appMetrics: appMetrics,
|
appMetrics: appMetrics,
|
||||||
ephemeralManager: ephemeralManager,
|
ephemeralManager: ephemeralManager,
|
||||||
|
logBlockedPeers: logBlockedPeers,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +152,9 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
|
|||||||
if s.appMetrics != nil {
|
if s.appMetrics != nil {
|
||||||
s.appMetrics.GRPCMetrics().CountSyncRequestBlocked()
|
s.appMetrics.GRPCMetrics().CountSyncRequestBlocked()
|
||||||
}
|
}
|
||||||
|
if s.logBlockedPeers {
|
||||||
|
log.WithContext(ctx).Warnf("peer %s with meta hash %d is blocked from syncing", peerKey.String(), metahashed)
|
||||||
|
}
|
||||||
return internalStatus.ErrPeerAlreadyLoggedIn
|
return internalStatus.ErrPeerAlreadyLoggedIn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
loginFilterSize = 100_000 // Size of the login filter map, making it large enough for a future
|
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
|
|
||||||
|
|
||||||
reconnTreshold = 5 * time.Minute
|
reconnTreshold = 5 * time.Minute
|
||||||
blockDuration = 10 * time.Minute // Duration for which a user is banned after exceeding the reconnection limit
|
blockDuration = 10 * time.Minute // Duration for which a user is banned after exceeding the reconnection limit
|
||||||
@ -18,7 +17,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
loginFilterSize int
|
|
||||||
filterTimeout time.Duration
|
filterTimeout time.Duration
|
||||||
reconnTreshold time.Duration
|
reconnTreshold time.Duration
|
||||||
blockDuration time.Duration
|
blockDuration time.Duration
|
||||||
@ -41,7 +39,6 @@ type metahash struct {
|
|||||||
|
|
||||||
func initCfg() *config {
|
func initCfg() *config {
|
||||||
return &config{
|
return &config{
|
||||||
loginFilterSize: loginFilterSize,
|
|
||||||
filterTimeout: filterTimeout,
|
filterTimeout: filterTimeout,
|
||||||
reconnTreshold: reconnTreshold,
|
reconnTreshold: reconnTreshold,
|
||||||
blockDuration: blockDuration,
|
blockDuration: blockDuration,
|
||||||
@ -55,7 +52,7 @@ func newLoginFilter() *loginFilter {
|
|||||||
|
|
||||||
func newLoginFilterWithCfg(cfg *config) *loginFilter {
|
func newLoginFilterWithCfg(cfg *config) *loginFilter {
|
||||||
return &loginFilter{
|
return &loginFilter{
|
||||||
logged: make(map[string]metahash, cfg.loginFilterSize),
|
logged: make(map[string]metahash),
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,5 +115,4 @@ func metaHash(meta nbpeer.PeerSystemMeta, pubip string) uint64 {
|
|||||||
h.Write([]byte(pubip))
|
h.Write([]byte(pubip))
|
||||||
|
|
||||||
return h.Sum64()
|
return h.Sum64()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user