mirror of https://github.com/v2ray/v2ray-core
more docs
parent
e4b6d5e0f0
commit
313aec4097
|
@ -7,7 +7,8 @@ import (
|
||||||
"github.com/v2ray/v2ray-core/common/log"
|
"github.com/v2ray/v2ray-core/common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Address represents a network address to be communicated with. It may be an IP address or domain address, not both. This interface doesn't resolve IP address for a given domain.
|
// Address represents a network address to be communicated with. It may be an IP address or domain
|
||||||
|
// address, not both. This interface doesn't resolve IP address for a given domain.
|
||||||
type Address interface {
|
type Address interface {
|
||||||
IP() net.IP // IP of this Address
|
IP() net.IP // IP of this Address
|
||||||
Domain() string // Domain of this Address
|
Domain() string // Domain of this Address
|
||||||
|
@ -32,10 +33,12 @@ func IPAddress(ip []byte, port uint16) Address {
|
||||||
case net.IPv6len:
|
case net.IPv6len:
|
||||||
return IPv6Address{
|
return IPv6Address{
|
||||||
PortAddress: PortAddress{port: port},
|
PortAddress: PortAddress{port: port},
|
||||||
ip: [16]byte{ip[0], ip[1], ip[2], ip[3],
|
ip: [16]byte{
|
||||||
|
ip[0], ip[1], ip[2], ip[3],
|
||||||
ip[4], ip[5], ip[6], ip[7],
|
ip[4], ip[5], ip[6], ip[7],
|
||||||
ip[8], ip[9], ip[10], ip[11],
|
ip[8], ip[9], ip[10], ip[11],
|
||||||
ip[12], ip[13], ip[14], ip[15]},
|
ip[12], ip[13], ip[14], ip[15],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic(log.Error("Unknown IP format: %v", ip))
|
panic(log.Error("Unknown IP format: %v", ip))
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
package net
|
package net
|
||||||
|
|
||||||
|
// Destination represents a network destination including address and protocol (tcp / udp).
|
||||||
type Destination interface {
|
type Destination interface {
|
||||||
Network() string
|
Network() string // Protocol of communication (tcp / udp)
|
||||||
Address() Address
|
Address() Address // Address of destination
|
||||||
String() string
|
String() string // String representation of the destination
|
||||||
|
|
||||||
IsTCP() bool
|
IsTCP() bool // True if destination is reachable via TCP
|
||||||
IsUDP() bool
|
IsUDP() bool // True if destination is reachable via UDP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTCPDestination creates a TCP destination with given address
|
||||||
func NewTCPDestination(address Address) Destination {
|
func NewTCPDestination(address Address) Destination {
|
||||||
return TCPDestination{address: address}
|
return TCPDestination{address: address}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewUDPDestination creates a UDP destination with given address
|
||||||
func NewUDPDestination(address Address) Destination {
|
func NewUDPDestination(address Address) Destination {
|
||||||
return UDPDestination{address: address}
|
return UDPDestination{address: address}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ const (
|
||||||
bufferSize = 32 * 1024
|
bufferSize = 32 * 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ReaderToChan dumps all content from a given reader to a chan by constantly reading it until EOF.
|
||||||
func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
|
func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
|
||||||
for {
|
for {
|
||||||
buffer := make([]byte, bufferSize)
|
buffer := make([]byte, bufferSize)
|
||||||
|
@ -21,6 +22,7 @@ func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChanToWriter dumps all content from a given chan to a writer until the chan is closed.
|
||||||
func ChanToWriter(writer io.Writer, stream <-chan []byte) error {
|
func ChanToWriter(writer io.Writer, stream <-chan []byte) error {
|
||||||
for buffer := range stream {
|
for buffer := range stream {
|
||||||
_, err := writer.Write(buffer)
|
_, err := writer.Write(buffer)
|
||||||
|
|
Loading…
Reference in New Issue