mirror of https://github.com/v2ray/v2ray-core
refactor
parent
a4d66be9fa
commit
bae5639dfd
|
@ -21,33 +21,33 @@ func NewBufferedReader(rawReader io.Reader) *BufferedReader {
|
|||
}
|
||||
|
||||
// IsBuffered returns true if the internal cache is effective.
|
||||
func (v *BufferedReader) IsBuffered() bool {
|
||||
return v.buffered
|
||||
func (r *BufferedReader) IsBuffered() bool {
|
||||
return r.buffered
|
||||
}
|
||||
|
||||
// SetBuffered is to enable or disable internal cache. If cache is disabled,
|
||||
// Read() calls will be delegated to the underlying io.Reader directly.
|
||||
func (v *BufferedReader) SetBuffered(cached bool) {
|
||||
v.buffered = cached
|
||||
func (r *BufferedReader) SetBuffered(cached bool) {
|
||||
r.buffered = cached
|
||||
}
|
||||
|
||||
// Read implements io.Reader.Read().
|
||||
func (v *BufferedReader) Read(b []byte) (int, error) {
|
||||
if !v.buffered || v.buffer == nil {
|
||||
if !v.buffer.IsEmpty() {
|
||||
return v.buffer.Read(b)
|
||||
func (r *BufferedReader) Read(b []byte) (int, error) {
|
||||
if !r.buffered || r.buffer == nil {
|
||||
if !r.buffer.IsEmpty() {
|
||||
return r.buffer.Read(b)
|
||||
}
|
||||
return v.reader.Read(b)
|
||||
return r.reader.Read(b)
|
||||
}
|
||||
if v.buffer.IsEmpty() {
|
||||
if err := v.buffer.Reset(ReadFrom(v.reader)); err != nil {
|
||||
if r.buffer.IsEmpty() {
|
||||
if err := r.buffer.Reset(ReadFrom(r.reader)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
if v.buffer.IsEmpty() {
|
||||
if r.buffer.IsEmpty() {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return v.buffer.Read(b)
|
||||
return r.buffer.Read(b)
|
||||
}
|
||||
|
|
|
@ -37,22 +37,22 @@ const (
|
|||
RequestOptionChunkMasking = RequestOption(0x04)
|
||||
)
|
||||
|
||||
func (v RequestOption) Has(option RequestOption) bool {
|
||||
return (v & option) == option
|
||||
func (o RequestOption) Has(option RequestOption) bool {
|
||||
return (o & option) == option
|
||||
}
|
||||
|
||||
func (v *RequestOption) Set(option RequestOption) {
|
||||
*v = (*v | option)
|
||||
func (o *RequestOption) Set(option RequestOption) {
|
||||
*o = (*o | option)
|
||||
}
|
||||
|
||||
func (v *RequestOption) Clear(option RequestOption) {
|
||||
*v = (*v & (^option))
|
||||
func (o *RequestOption) Clear(option RequestOption) {
|
||||
*o = (*o & (^option))
|
||||
}
|
||||
|
||||
type Security byte
|
||||
|
||||
func (v Security) Is(t SecurityType) bool {
|
||||
return v == Security(t)
|
||||
func (s Security) Is(t SecurityType) bool {
|
||||
return s == Security(t)
|
||||
}
|
||||
|
||||
func NormSecurity(s Security) Security {
|
||||
|
@ -72,11 +72,11 @@ type RequestHeader struct {
|
|||
User *User
|
||||
}
|
||||
|
||||
func (v *RequestHeader) Destination() net.Destination {
|
||||
if v.Command == RequestCommandUDP {
|
||||
return net.UDPDestination(v.Address, v.Port)
|
||||
func (h *RequestHeader) Destination() net.Destination {
|
||||
if h.Command == RequestCommandUDP {
|
||||
return net.UDPDestination(h.Address, h.Port)
|
||||
}
|
||||
return net.TCPDestination(v.Address, v.Port)
|
||||
return net.TCPDestination(h.Address, h.Port)
|
||||
}
|
||||
|
||||
type ResponseOption byte
|
||||
|
@ -85,16 +85,16 @@ const (
|
|||
ResponseOptionConnectionReuse = ResponseOption(0x01)
|
||||
)
|
||||
|
||||
func (v *ResponseOption) Set(option ResponseOption) {
|
||||
*v = (*v | option)
|
||||
func (o *ResponseOption) Set(option ResponseOption) {
|
||||
*o = (*o | option)
|
||||
}
|
||||
|
||||
func (v ResponseOption) Has(option ResponseOption) bool {
|
||||
return (v & option) == option
|
||||
func (o ResponseOption) Has(option ResponseOption) bool {
|
||||
return (o & option) == option
|
||||
}
|
||||
|
||||
func (v *ResponseOption) Clear(option ResponseOption) {
|
||||
*v = (*v & (^option))
|
||||
func (o *ResponseOption) Clear(option ResponseOption) {
|
||||
*o = (*o & (^option))
|
||||
}
|
||||
|
||||
type ResponseCommand interface{}
|
||||
|
@ -113,15 +113,15 @@ type CommandSwitchAccount struct {
|
|||
ValidMin byte
|
||||
}
|
||||
|
||||
func (v *SecurityConfig) AsSecurity() Security {
|
||||
if v == nil {
|
||||
func (sc *SecurityConfig) AsSecurity() Security {
|
||||
if sc == nil {
|
||||
return Security(SecurityType_LEGACY)
|
||||
}
|
||||
if v.Type == SecurityType_AUTO {
|
||||
if sc.Type == SecurityType_AUTO {
|
||||
if runtime.GOARCH == "amd64" || runtime.GOARCH == "s390x" {
|
||||
return Security(SecurityType_AES128_GCM)
|
||||
}
|
||||
return Security(SecurityType_CHACHA20_POLY1305)
|
||||
}
|
||||
return NormSecurity(Security(v.Type))
|
||||
return NormSecurity(Security(sc.Type))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue