mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-26 15:39:08 -04:00
Drain Connection Based on Uuid based Behavior seed
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
package vmess
|
||||
|
||||
import (
|
||||
"hash/crc64"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"v2ray.com/core/common/dice"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/protocol"
|
||||
@@ -26,11 +28,13 @@ type user struct {
|
||||
// TimedUserValidator is a user Validator based on time.
|
||||
type TimedUserValidator struct {
|
||||
sync.RWMutex
|
||||
users []*user
|
||||
userHash map[[16]byte]indexTimePair
|
||||
hasher protocol.IDHash
|
||||
baseTime protocol.Timestamp
|
||||
task *task.Periodic
|
||||
users []*user
|
||||
userHash map[[16]byte]indexTimePair
|
||||
hasher protocol.IDHash
|
||||
baseTime protocol.Timestamp
|
||||
task *task.Periodic
|
||||
behaviorSeed uint64
|
||||
behaviorFused bool
|
||||
}
|
||||
|
||||
type indexTimePair struct {
|
||||
@@ -124,6 +128,11 @@ func (v *TimedUserValidator) Add(u *protocol.MemoryUser) error {
|
||||
v.users = append(v.users, uu)
|
||||
v.generateNewHashes(protocol.Timestamp(nowSec), uu)
|
||||
|
||||
if v.behaviorFused == false {
|
||||
account := uu.user.Account.(*MemoryAccount)
|
||||
crc64.Update(v.behaviorSeed, crc64.MakeTable(crc64.ECMA), account.ID.Bytes())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -131,6 +140,8 @@ func (v *TimedUserValidator) Get(userHash []byte) (*protocol.MemoryUser, protoco
|
||||
defer v.RUnlock()
|
||||
v.RLock()
|
||||
|
||||
v.behaviorFused = true
|
||||
|
||||
var fixedSizeHash [16]byte
|
||||
copy(fixedSizeHash[:], userHash)
|
||||
pair, found := v.userHash[fixedSizeHash]
|
||||
@@ -170,3 +181,13 @@ func (v *TimedUserValidator) Remove(email string) bool {
|
||||
func (v *TimedUserValidator) Close() error {
|
||||
return v.task.Close()
|
||||
}
|
||||
|
||||
func (v *TimedUserValidator) GetBehaviorSeed() uint64 {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
v.behaviorFused = true
|
||||
if v.behaviorSeed == 0 {
|
||||
v.behaviorSeed = dice.RollUint64()
|
||||
}
|
||||
return v.behaviorSeed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user