mirror of https://github.com/v2ray/v2ray-core
V2Ray
9 years ago
7 changed files with 121 additions and 10 deletions
@ -1,4 +1,4 @@
|
||||
package net |
||||
package socks |
||||
|
||||
import ( |
||||
"net" |
@ -1,5 +1,39 @@
|
||||
package core |
||||
|
||||
import ( |
||||
"encoding/base64" |
||||
) |
||||
|
||||
type VUserSet struct { |
||||
validUserIds [][]byte |
||||
validUserIds []VID |
||||
userIdsAskHash map[string]int |
||||
} |
||||
|
||||
func NewVUserSet() *VUserSet { |
||||
vuSet := new(VUserSet) |
||||
vuSet.validUserIds = make([]VID, 0, 16) |
||||
return vuSet |
||||
} |
||||
|
||||
func hashBytesToString(hash []byte) string { |
||||
return base64.StdEncoding.EncodeToString(hash) |
||||
} |
||||
|
||||
func (us *VUserSet) AddUser(user VUser) error { |
||||
id := user.Id |
||||
us.validUserIds = append(us.validUserIds, id) |
||||
|
||||
idBase64 := hashBytesToString(id.Hash([]byte("ASK"))) |
||||
us.userIdsAskHash[idBase64] = len(us.validUserIds) - 1 |
||||
|
||||
return nil |
||||
} |
||||
|
||||
func (us VUserSet) IsValidUserId(askHash []byte) (*VID, bool) { |
||||
askBase64 := hashBytesToString(askHash) |
||||
idIndex, found := us.userIdsAskHash[askBase64] |
||||
if found { |
||||
return &us.validUserIds[idIndex], true |
||||
} |
||||
return nil, false |
||||
} |
||||
|
Loading…
Reference in new issue