Remove prefix 'V' in struct names

This commit is contained in:
V2Ray committed 2015-09-12 22:11:54 +02:00
1 parent cc3fdb6ef4
commit 51670b223d
27 files changed
+201 -201

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
package core
import (
"encoding/base64"
)
type UserSet struct {
validUserIds []ID
userIdsAskHash map[string]int
}
func NewUserSet() *UserSet {
vuSet := new(UserSet)
vuSet.validUserIds = make([]ID, 0, 16)
vuSet.userIdsAskHash = make(map[string]int)
return vuSet
}
func hashBytesToString(hash []byte) string {
return base64.StdEncoding.EncodeToString(hash)
}
func (us *UserSet) AddUser(user User) 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 UserSet) IsValidUserId(askHash []byte) (*ID, bool) {
askBase64 := hashBytesToString(askHash)
idIndex, found := us.userIdsAskHash[askBase64]
if found {
return &us.validUserIds[idIndex], true
}
return nil, false
}