1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 17:27:23 -05:00

unified release

This commit is contained in:
Darien Raymond 2016-12-27 21:33:34 +01:00
parent 5769df496b
commit c68da6a0e8
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 27 additions and 25 deletions

View File

@ -25,8 +25,10 @@ func NewReader(rawReader io.Reader) *BufferedReader {
// Release implements Releasable.Release().
func (v *BufferedReader) Release() {
v.buffer.Release()
v.buffer = nil
if v.buffer != nil {
v.buffer.Release()
v.buffer = nil
}
common.Release(v.reader)
}

View File

@ -31,8 +31,8 @@ func (v *CryptionReader) Read(data []byte) (int, error) {
}
func (v *CryptionReader) Release() {
v.reader = nil
v.stream = nil
common.Release(v.reader)
common.Release(v.stream)
}
type CryptionWriter struct {
@ -56,6 +56,6 @@ func (v *CryptionWriter) Write(data []byte) (int, error) {
}
func (v *CryptionWriter) Release() {
v.writer = nil
v.stream = nil
common.Release(v.writer)
common.Release(v.stream)
}

View File

@ -19,10 +19,9 @@ type ErrorLog struct {
}
func (v *ErrorLog) Release() {
for index := range v.Values {
v.Values[index] = nil
for _, val := range v.Values {
common.Release(val)
}
v.Values = nil
}
func (v *ErrorLog) String() string {
@ -37,9 +36,9 @@ type AccessLog struct {
}
func (v *AccessLog) Release() {
v.From = nil
v.To = nil
v.Reason = nil
common.Release(v.From)
common.Release(v.To)
common.Release(v.Reason)
}
func (v *AccessLog) String() string {

View File

@ -4,6 +4,8 @@ import (
"io"
"net"
"time"
"v2ray.com/core/common"
)
var (
@ -51,8 +53,8 @@ func (reader *TimeOutReader) SetTimeOut(value uint32) {
}
func (reader *TimeOutReader) Release() {
reader.connection = nil
reader.worker = nil
common.Release(reader.connection)
common.Release(reader.worker)
}
type timedReaderWorker struct {

View File

@ -6,6 +6,7 @@ import (
"crypto/sha1"
"io"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/serial"
@ -70,8 +71,8 @@ func NewChunkReader(reader io.Reader, auth *Authenticator) *ChunkReader {
}
func (v *ChunkReader) Release() {
v.reader = nil
v.auth = nil
common.Release(v.reader)
common.Release(v.auth)
}
func (v *ChunkReader) Read() (*buf.Buffer, error) {
@ -124,8 +125,8 @@ func NewChunkWriter(writer io.Writer, auth *Authenticator) *ChunkWriter {
}
func (v *ChunkWriter) Release() {
v.writer = nil
v.auth = nil
common.Release(v.writer)
common.Release(v.auth)
}
func (v *ChunkWriter) Write(payload *buf.Buffer) error {

View File

@ -69,11 +69,6 @@ func (v *TimedUserValidator) Release() {
}
v.running = false
v.validUsers = nil
v.userHash = nil
v.ids = nil
v.hasher = nil
v.cancel = nil
}
func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, idx int, entry *idEntry) {
@ -89,10 +84,8 @@ func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, idx in
idHash.Sum(hashValueRemoval[:0])
idHash.Reset()
v.Lock()
v.userHash[hashValue] = &indexTimePair{idx, entry.lastSec}
delete(v.userHash, hashValueRemoval)
v.Unlock()
entry.lastSec++
entry.lastSecRemoval++
@ -107,9 +100,11 @@ func (v *TimedUserValidator) updateUserHash(interval time.Duration) {
select {
case now := <-time.After(interval):
nowSec := protocol.Timestamp(now.Unix() + cacheDurationSec)
v.Lock()
for _, entry := range v.ids {
v.generateNewHashes(nowSec, entry.userIdx, entry)
}
v.Unlock()
case <-v.cancel.WaitForCancel():
return
}
@ -117,6 +112,9 @@ func (v *TimedUserValidator) updateUserHash(interval time.Duration) {
}
func (v *TimedUserValidator) Add(user *protocol.User) error {
v.Lock()
defer v.Unlock()
idx := len(v.validUsers)
v.validUsers = append(v.validUsers, user)
rawAccount, err := user.GetTypedAccount()