1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 09:17:32 -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(). // Release implements Releasable.Release().
func (v *BufferedReader) Release() { func (v *BufferedReader) Release() {
v.buffer.Release() if v.buffer != nil {
v.buffer = nil v.buffer.Release()
v.buffer = nil
}
common.Release(v.reader) common.Release(v.reader)
} }

View File

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

View File

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

View File

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

View File

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

View File

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