mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-15 08:46:34 -05:00
Merge branch 'master' of https://github.com/v2ray/v2ray-core
This commit is contained in:
commit
a3a772e1d0
@ -118,7 +118,7 @@ func getDefaultPoolSize() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var size uint32 = getDefaultPoolSize()
|
size := getDefaultPoolSize()
|
||||||
sizeStr := os.Getenv(poolSizeEnvKey)
|
sizeStr := os.Getenv(poolSizeEnvKey)
|
||||||
if len(sizeStr) > 0 {
|
if len(sizeStr) > 0 {
|
||||||
customSize, err := strconv.ParseUint(sizeStr, 10, 32)
|
customSize, err := strconv.ParseUint(sizeStr, 10, 32)
|
||||||
|
@ -11,7 +11,7 @@ type BufferedReader struct {
|
|||||||
buffered bool
|
buffered bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewReader creates a new BufferedReader based on an io.Reader.
|
// NewBufferedReader creates a new BufferedReader based on an io.Reader.
|
||||||
func NewBufferedReader(rawReader io.Reader) *BufferedReader {
|
func NewBufferedReader(rawReader io.Reader) *BufferedReader {
|
||||||
return &BufferedReader{
|
return &BufferedReader{
|
||||||
reader: rawReader,
|
reader: rawReader,
|
||||||
|
@ -14,7 +14,7 @@ type BufferedWriter struct {
|
|||||||
buffered bool
|
buffered bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWriter creates a new BufferedWriter.
|
// NewBufferedWriter creates a new BufferedWriter.
|
||||||
func NewBufferedWriter(rawWriter io.Writer) *BufferedWriter {
|
func NewBufferedWriter(rawWriter io.Writer) *BufferedWriter {
|
||||||
return &BufferedWriter{
|
return &BufferedWriter{
|
||||||
writer: rawWriter,
|
writer: rawWriter,
|
||||||
|
@ -24,7 +24,7 @@ func TestBufferedWriter(t *testing.T) {
|
|||||||
|
|
||||||
assert.Bool(content.IsEmpty()).IsTrue()
|
assert.Bool(content.IsEmpty()).IsTrue()
|
||||||
|
|
||||||
writer.SetBuffered(false)
|
assert.Error(writer.SetBuffered(false)).IsNil()
|
||||||
assert.Int(content.Len()).Equals(16)
|
assert.Int(content.Len()).Equals(16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ func NewReader(reader io.Reader) Reader {
|
|||||||
|
|
||||||
// ToBytesReader converts a Reaaer to io.Reader.
|
// ToBytesReader converts a Reaaer to io.Reader.
|
||||||
func ToBytesReader(stream Reader) io.Reader {
|
func ToBytesReader(stream Reader) io.Reader {
|
||||||
return &BufferToBytesReader{
|
return &bufferToBytesReader{
|
||||||
stream: stream,
|
stream: stream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ func NewWriter(writer io.Writer) Writer {
|
|||||||
|
|
||||||
// ToBytesWriter converts a Writer to io.Writer
|
// ToBytesWriter converts a Writer to io.Writer
|
||||||
func ToBytesWriter(writer Writer) io.Writer {
|
func ToBytesWriter(writer Writer) io.Writer {
|
||||||
return &BytesToBufferWriter{
|
return &bytesToBufferWriter{
|
||||||
writer: writer,
|
writer: writer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,14 @@ func (v *BytesToBufferReader) Read() (*Buffer, error) {
|
|||||||
return buffer, nil
|
return buffer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type BufferToBytesReader struct {
|
type bufferToBytesReader struct {
|
||||||
stream Reader
|
stream Reader
|
||||||
current *Buffer
|
current *Buffer
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill fills in the internal buffer.
|
// fill fills in the internal buffer.
|
||||||
// Private: Visible for testing.
|
func (v *bufferToBytesReader) fill() {
|
||||||
func (v *BufferToBytesReader) Fill() {
|
|
||||||
b, err := v.stream.Read()
|
b, err := v.stream.Read()
|
||||||
v.current = b
|
v.current = b
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -60,13 +59,13 @@ func (v *BufferToBytesReader) Fill() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *BufferToBytesReader) Read(b []byte) (int, error) {
|
func (v *bufferToBytesReader) Read(b []byte) (int, error) {
|
||||||
if v.err != nil {
|
if v.err != nil {
|
||||||
return 0, v.err
|
return 0, v.err
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.current == nil {
|
if v.current == nil {
|
||||||
v.Fill()
|
v.fill()
|
||||||
if v.err != nil {
|
if v.err != nil {
|
||||||
return 0, v.err
|
return 0, v.err
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ func (v *BufferToBytesWriter) Write(buffer *Buffer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type BytesToBufferWriter struct {
|
type bytesToBufferWriter struct {
|
||||||
writer Writer
|
writer Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *BytesToBufferWriter) Write(payload []byte) (int, error) {
|
func (v *bytesToBufferWriter) Write(payload []byte) (int, error) {
|
||||||
bytesWritten := 0
|
bytesWritten := 0
|
||||||
size := len(payload)
|
size := len(payload)
|
||||||
for size > 0 {
|
for size > 0 {
|
||||||
|
@ -21,11 +21,17 @@ var (
|
|||||||
LocalHostIPv6 = IPAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
|
LocalHostIPv6 = IPAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AddressFamily is the type of address.
|
||||||
type AddressFamily int
|
type AddressFamily int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AddressFamilyIPv4 = AddressFamily(0)
|
// AddressFamilyIPv4 represents address as IPv4
|
||||||
AddressFamilyIPv6 = AddressFamily(1)
|
AddressFamilyIPv4 = AddressFamily(0)
|
||||||
|
|
||||||
|
// AddressFamilyIPv6 represents address as IPv6
|
||||||
|
AddressFamilyIPv6 = AddressFamily(1)
|
||||||
|
|
||||||
|
// AddressFamilyDomain represents address as Domain
|
||||||
AddressFamilyDomain = AddressFamily(2)
|
AddressFamilyDomain = AddressFamily(2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ type Destination struct {
|
|||||||
Address Address
|
Address Address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DestinationFromAddr generates a Destination from a net address.
|
||||||
func DestinationFromAddr(addr net.Addr) Destination {
|
func DestinationFromAddr(addr net.Addr) Destination {
|
||||||
switch addr := addr.(type) {
|
switch addr := addr.(type) {
|
||||||
case *net.TCPAddr:
|
case *net.TCPAddr:
|
||||||
@ -52,6 +53,7 @@ func (v Destination) IsValid() bool {
|
|||||||
return v.Network != Network_Unknown
|
return v.Network != Network_Unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AsDestination converts current Enpoint into Destination.
|
||||||
func (v *Endpoint) AsDestination() Destination {
|
func (v *Endpoint) AsDestination() Destination {
|
||||||
return Destination{
|
return Destination{
|
||||||
Network: v.Network,
|
Network: v.Network,
|
||||||
|
@ -46,7 +46,7 @@ func (v Network) URLPrefix() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashNetwork returns true if the given network is in v NetworkList.
|
// HasNetwork returns true if the given network is in v NetworkList.
|
||||||
func (v NetworkList) HasNetwork(network Network) bool {
|
func (v NetworkList) HasNetwork(network Network) bool {
|
||||||
for _, value := range v.Network {
|
for _, value := range v.Network {
|
||||||
if string(value) == string(network) {
|
if string(value) == string(network) {
|
||||||
@ -60,6 +60,7 @@ func (v NetworkList) Get(idx int) Network {
|
|||||||
return v.Network[idx]
|
return v.Network[idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns the number of networks in this network list.
|
||||||
func (v NetworkList) Size() int {
|
func (v NetworkList) Size() int {
|
||||||
return len(v.Network)
|
return len(v.Network)
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ func (v PortRange) Contains(port Port) bool {
|
|||||||
return v.FromPort() <= port && port <= v.ToPort()
|
return v.FromPort() <= port && port <= v.ToPort()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SinglePortRange returns a PortRange contains a single port.
|
||||||
func SinglePortRange(v Port) *PortRange {
|
func SinglePortRange(v Port) *PortRange {
|
||||||
return &PortRange{
|
return &PortRange{
|
||||||
From: uint32(v),
|
From: uint32(v),
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"v2ray.com/core/common/uuid"
|
"v2ray.com/core/common/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RequestCommand is a custom command in a proxy request.
|
||||||
type RequestCommand byte
|
type RequestCommand byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user