Use pointer for UserInfo in User struct

This commit is contained in:
Qian Wang 2018-12-08 15:30:46 +00:00
parent 7919834dfe
commit 3abef6dbad
3 changed files with 5 additions and 6 deletions

View File

@ -47,7 +47,8 @@ func (c *controller) HandleRequest(req []byte) ([]byte, error) {
if err == ErrInvalidMac { if err == ErrInvalidMac {
log.Printf("!!!CONTROL MESSAGE AND HMAC MISMATCH!!!\n raw request:\n%x\ndecrypted msg:\n%x", req, plain) log.Printf("!!!CONTROL MESSAGE AND HMAC MISMATCH!!!\n raw request:\n%x\ndecrypted msg:\n%x", req, plain)
return nil, err return nil, err
} else { } else if err != nil {
log.Println(err)
return c.respond([]byte(err.Error())), nil return c.respond([]byte(err.Error())), nil
} }

View File

@ -26,9 +26,7 @@ type User struct {
arrUID [32]byte arrUID [32]byte
// TODO: use pointer here instead because we don't want to accidentally read *UserInfo
// UserInfo's Credits?
UserInfo
valve *mux.Valve valve *mux.Valve
@ -36,7 +34,7 @@ type User struct {
sessions map[uint32]*mux.Session sessions map[uint32]*mux.Session
} }
func MakeUser(up *Userpanel, uinfo UserInfo) *User { func MakeUser(up *Userpanel, uinfo *UserInfo) *User {
// this instance of valve is shared across ALL sessions of a user // this instance of valve is shared across ALL sessions of a user
valve := mux.MakeValve(uinfo.UpRate, uinfo.DownRate, &uinfo.UpCredit, &uinfo.DownCredit) valve := mux.MakeValve(uinfo.UpRate, uinfo.DownRate, &uinfo.UpCredit, &uinfo.DownCredit)
u := &User{ u := &User{

View File

@ -124,7 +124,7 @@ func (up *Userpanel) GetAndActivateUser(UID []byte) (*User, error) {
up.activeUsersM.Unlock() up.activeUsersM.Unlock()
return nil, err return nil, err
} }
u := MakeUser(up, uinfo) u := MakeUser(up, &uinfo)
up.activeUsers[arrUID] = u up.activeUsers[arrUID] = u
up.activeUsersM.Unlock() up.activeUsersM.Unlock()
return u, nil return u, nil