From 41da4102ab4c69dfa9b8f6e71a6b4ef4622a3f22 Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Sun, 13 Jan 2019 21:43:50 +0000 Subject: [PATCH] Syntax cleanups --- internal/multiplex/frame.go | 2 -- internal/multiplex/qos.go | 19 ++++++------------- internal/multiplex/session.go | 2 -- internal/server/state.go | 5 ----- internal/server/usermanager/userpanel.go | 2 +- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/internal/multiplex/frame.go b/internal/multiplex/frame.go index 2faeb78..56c62f3 100644 --- a/internal/multiplex/frame.go +++ b/internal/multiplex/frame.go @@ -1,7 +1,5 @@ package multiplex -import () - type Frame struct { StreamID uint32 Seq uint32 diff --git a/internal/multiplex/qos.go b/internal/multiplex/qos.go index 4c5ebfe..9f70957 100644 --- a/internal/multiplex/qos.go +++ b/internal/multiplex/qos.go @@ -32,20 +32,13 @@ func MakeValve(rxRate, txRate int64, rxCredit, txCredit *int64) *Valve { } func (v *Valve) SetRxRate(rate int64) { v.rxtb.Store(ratelimit.NewBucketWithRate(float64(rate), rate)) } - func (v *Valve) SetTxRate(rate int64) { v.txtb.Store(ratelimit.NewBucketWithRate(float64(rate), rate)) } - -func (v *Valve) rxWait(n int) { v.rxtb.Load().(*ratelimit.Bucket).Wait(int64(n)) } - -func (v *Valve) txWait(n int) { v.txtb.Load().(*ratelimit.Bucket).Wait(int64(n)) } - -func (v *Valve) SetRxCredit(n int64) { atomic.StoreInt64(v.rxCredit, n) } - -func (v *Valve) SetTxCredit(n int64) { atomic.StoreInt64(v.txCredit, n) } - -func (v *Valve) GetRxCredit() int64 { return atomic.LoadInt64(v.rxCredit) } - -func (v *Valve) GetTxCredit() int64 { return atomic.LoadInt64(v.txCredit) } +func (v *Valve) rxWait(n int) { v.rxtb.Load().(*ratelimit.Bucket).Wait(int64(n)) } +func (v *Valve) txWait(n int) { v.txtb.Load().(*ratelimit.Bucket).Wait(int64(n)) } +func (v *Valve) SetRxCredit(n int64) { atomic.StoreInt64(v.rxCredit, n) } +func (v *Valve) SetTxCredit(n int64) { atomic.StoreInt64(v.txCredit, n) } +func (v *Valve) GetRxCredit() int64 { return atomic.LoadInt64(v.rxCredit) } +func (v *Valve) GetTxCredit() int64 { return atomic.LoadInt64(v.txCredit) } // n can be negative func (v *Valve) AddRxCredit(n int64) int64 { return atomic.AddInt64(v.rxCredit, n) } diff --git a/internal/multiplex/session.go b/internal/multiplex/session.go index c7a2409..8b3052e 100644 --- a/internal/multiplex/session.go +++ b/internal/multiplex/session.go @@ -9,7 +9,6 @@ import ( ) const ( - // Copied from smux acceptBacklog = 1024 ) @@ -42,7 +41,6 @@ type Session struct { suicide sync.Once } -// 1 conn is needed to make a session func MakeSession(id uint32, valve *Valve, obfs Obfser, deobfs Deobfser, obfsedRead func(net.Conn, []byte) (int, error)) *Session { sesh := &Session{ id: id, diff --git a/internal/server/state.go b/internal/server/state.go index 1bffa60..c84be76 100644 --- a/internal/server/state.go +++ b/internal/server/state.go @@ -20,11 +20,6 @@ type rawConfig struct { DatabasePath string BackupDirPath string } -type stateManager interface { - ParseConfig(string) error - SetAESKey(string) - PutUsedRandom([32]byte) -} // State type stores the global state of the program type State struct { diff --git a/internal/server/usermanager/userpanel.go b/internal/server/usermanager/userpanel.go index 9747dbc..d03c2bf 100644 --- a/internal/server/usermanager/userpanel.go +++ b/internal/server/usermanager/userpanel.go @@ -125,7 +125,7 @@ func (up *Userpanel) GetAndActivateAdminUser(AdminUID []byte) (*User, error) { return user, nil } -// GetUser is used to retrieve a user if s/he is active, or to retrieve the user's infor +// GetUser is used to retrieve a user if s/he is active, or to retrieve the user's info // from the db and mark it as an active user func (up *Userpanel) GetAndActivateUser(UID []byte) (*User, error) { up.activeUsersM.Lock()