minor fixes

This commit is contained in:
crn4 2025-06-19 17:20:03 +02:00
parent 0ed6555b91
commit 58478b57af
3 changed files with 9 additions and 6 deletions

View File

@ -11,14 +11,14 @@ import (
const ( 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
reconnTreshold = 5 * time.Minute reconnThreshold = 5 * time.Minute
blockDuration = 10 * time.Minute // Duration for which a peer is banned after exceeding the reconnection limit blockDuration = 10 * time.Minute // Duration for which a peer is banned after exceeding the reconnection limit
reconnLimitForBan = 30 // Number of reconnections within the reconnTreshold that triggers a ban reconnLimitForBan = 30 // Number of reconnections within the reconnTreshold that triggers a ban
) )
type config struct { type config struct {
filterTimeout time.Duration filterTimeout time.Duration
reconnTreshold time.Duration reconnThreshold time.Duration
blockDuration time.Duration blockDuration time.Duration
reconnLimitForBan int reconnLimitForBan int
} }
@ -40,7 +40,7 @@ type metahash struct {
func initCfg() *config { func initCfg() *config {
return &config{ return &config{
filterTimeout: filterTimeout, filterTimeout: filterTimeout,
reconnTreshold: reconnTreshold, reconnThreshold: reconnThreshold,
blockDuration: blockDuration, blockDuration: blockDuration,
reconnLimitForBan: reconnLimitForBan, reconnLimitForBan: reconnLimitForBan,
} }
@ -70,7 +70,7 @@ func (l *loginFilter) addLogin(wgPubKey string, metaHash uint64) {
mh.counter++ mh.counter++
mh.hash = metaHash mh.hash = metaHash
mh.lastSeen = time.Now() mh.lastSeen = time.Now()
if mh.counter > l.cfg.reconnLimitForBan && mh.lastSeen.Sub(mh.firstLogin) < l.cfg.reconnTreshold { if mh.counter > l.cfg.reconnLimitForBan && mh.lastSeen.Sub(mh.firstLogin) < l.cfg.reconnThreshold {
mh.banned = true mh.banned = true
} }
l.logged[wgPubKey] = mh l.logged[wgPubKey] = mh

View File

@ -15,7 +15,7 @@ import (
func testCfg() *config { func testCfg() *config {
return &config{ return &config{
filterTimeout: 20 * time.Millisecond, filterTimeout: 20 * time.Millisecond,
reconnTreshold: 50 * time.Millisecond, reconnThreshold: 50 * time.Millisecond,
blockDuration: 100 * time.Millisecond, blockDuration: 100 * time.Millisecond,
reconnLimitForBan: 3, reconnLimitForBan: 3,
} }

View File

@ -893,6 +893,9 @@ func (am *MockAccountManager) GetCurrentUserInfo(ctx context.Context, userAuth n
return nil, status.Errorf(codes.Unimplemented, "method GetCurrentUserInfo is not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetCurrentUserInfo is not implemented")
} }
func (am *MockAccountManager) AllowSync(_ string, _ uint64) bool { func (am *MockAccountManager) AllowSync(key string, hash uint64) bool {
if am.AllowSyncFunc != nil {
return am.AllowSyncFunc(key, hash)
}
return true return true
} }