added logging for blocked peers, removed map size

This commit is contained in:
crn4 2025-06-19 16:45:49 +02:00
parent 7890cb4f32
commit 2f73b7a35f
2 changed files with 11 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/netip"
"os"
"strings"
"sync"
"time"
@ -48,6 +49,8 @@ type GRPCServer struct {
ephemeralManager *EphemeralManager
peerLocks sync.Map
authManager auth.Manager
logBlockedPeers bool
}
// NewServer creates a new Management server
@ -77,6 +80,8 @@ func NewServer(
}
}
logBlockedPeers := os.Getenv("NB_LOG_BLOCKED_PEERS") == "true"
return &GRPCServer{
wgKey: key,
// peerKey -> event channel
@ -88,6 +93,7 @@ func NewServer(
authManager: authManager,
appMetrics: appMetrics,
ephemeralManager: ephemeralManager,
logBlockedPeers: logBlockedPeers,
}, nil
}
@ -146,6 +152,9 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
if s.appMetrics != nil {
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
}

View File

@ -9,8 +9,7 @@ import (
)
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
blockDuration = 10 * time.Minute // Duration for which a user is banned after exceeding the reconnection limit
@ -18,7 +17,6 @@ const (
)
type config struct {
loginFilterSize int
filterTimeout time.Duration
reconnTreshold time.Duration
blockDuration time.Duration
@ -41,7 +39,6 @@ type metahash struct {
func initCfg() *config {
return &config{
loginFilterSize: loginFilterSize,
filterTimeout: filterTimeout,
reconnTreshold: reconnTreshold,
blockDuration: blockDuration,
@ -55,7 +52,7 @@ func newLoginFilter() *loginFilter {
func newLoginFilterWithCfg(cfg *config) *loginFilter {
return &loginFilter{
logged: make(map[string]metahash, cfg.loginFilterSize),
logged: make(map[string]metahash),
cfg: cfg,
}
}
@ -118,5 +115,4 @@ func metaHash(meta nbpeer.PeerSystemMeta, pubip string) uint64 {
h.Write([]byte(pubip))
return h.Sum64()
}