Documentation ¶
Overview ¶
Package net is a drop-in replacement to Golang's net package, with some more functionalities.
Index ¶
- Constants
- Variables
- func HasNetwork(list []Network, network Network) bool
- func NewConnection(opts ...ConnectionOption) net.Conn
- type Addr
- type AddrError
- type Address
- type AddressFamily
- type Conn
- type ConnectionOption
- func ConnectionInput(writer io.Writer) ConnectionOption
- func ConnectionInputMulti(writer buf.Writer) ConnectionOption
- func ConnectionLocalAddr(a net.Addr) ConnectionOption
- func ConnectionOnClose(n io.Closer) ConnectionOption
- func ConnectionOutput(reader io.Reader) ConnectionOption
- func ConnectionOutputMulti(reader buf.Reader) ConnectionOption
- func ConnectionOutputMultiUDP(reader buf.Reader) ConnectionOption
- func ConnectionRemoteAddr(a net.Addr) ConnectionOption
- type Destination
- type Dialer
- type Endpoint
- func (p *Endpoint) AsDestination() Destination
- func (*Endpoint) Descriptor() ([]byte, []int)deprecated
- func (x *Endpoint) GetAddress() *IPOrDomain
- func (x *Endpoint) GetNetwork() Network
- func (x *Endpoint) GetPort() uint32
- func (*Endpoint) ProtoMessage()
- func (x *Endpoint) ProtoReflect() protoreflect.Message
- func (x *Endpoint) Reset()
- func (x *Endpoint) String() string
- type Error
- type IP
- type IPMask
- type IPNet
- type IPOrDomain
- func (d *IPOrDomain) AsAddress() Address
- func (*IPOrDomain) Descriptor() ([]byte, []int)deprecated
- func (m *IPOrDomain) GetAddress() isIPOrDomain_Address
- func (x *IPOrDomain) GetDomain() string
- func (x *IPOrDomain) GetIp() []byte
- func (*IPOrDomain) ProtoMessage()
- func (x *IPOrDomain) ProtoReflect() protoreflect.Message
- func (x *IPOrDomain) Reset()
- func (x *IPOrDomain) String() string
- func (d *IPOrDomain) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []byte) error
- type IPOrDomain_Domain
- type IPOrDomain_Ip
- type ListenConfig
- type Listener
- type MemoryPortList
- type MemoryPortRange
- type Network
- func (Network) Descriptor() protoreflect.EnumDescriptor
- func (x Network) Enum() *Network
- func (Network) EnumDescriptor() ([]byte, []int)deprecated
- func (x Network) Number() protoreflect.EnumNumber
- func (x Network) String() string
- func (n Network) SystemString() string
- func (Network) Type() protoreflect.EnumType
- type NetworkList
- func (*NetworkList) Descriptor() ([]byte, []int)deprecated
- func (x *NetworkList) GetNetwork() []Network
- func (*NetworkList) ProtoMessage()
- func (x *NetworkList) ProtoReflect() protoreflect.Message
- func (x *NetworkList) Reset()
- func (x *NetworkList) String() string
- func (nl *NetworkList) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []byte) error
- type PacketConn
- type Port
- type PortList
- type PortRange
- func (p *PortRange) Contains(port Port) bool
- func (*PortRange) Descriptor() ([]byte, []int)deprecated
- func (p *PortRange) FromPort() Port
- func (x *PortRange) GetFrom() uint32
- func (x *PortRange) GetTo() uint32
- func (*PortRange) ProtoMessage()
- func (x *PortRange) ProtoReflect() protoreflect.Message
- func (x *PortRange) Reset()
- func (x *PortRange) String() string
- func (p *PortRange) ToPort() Port
- type Resolver
- type TCPAddr
- type TCPConn
- type TCPListener
- type UDPAddr
- type UDPConn
- type UnixAddr
- type UnixConn
- type UnixListener
Constants ¶
const ( // AddressFamilyIPv4 represents address as IPv4 AddressFamilyIPv4 = AddressFamily(0) // AddressFamilyIPv6 represents address as IPv6 AddressFamilyIPv6 = AddressFamily(1) // AddressFamilyDomain represents address as Domain AddressFamilyDomain = AddressFamily(2) )
const ( IPv4len = net.IPv4len IPv6len = net.IPv6len )
Variables ¶
var ( // LocalHostIP is a constant value for localhost IP in IPv4. LocalHostIP = IPAddress([]byte{127, 0, 0, 1}) // AnyIP is a constant value for any IP in IPv4. AnyIP = IPAddress([]byte{0, 0, 0, 0}) // LocalHostDomain is a constant value for localhost domain. LocalHostDomain = DomainAddress("localhost") // LocalHostIPv6 is a constant value for localhost IP in IPv6. LocalHostIPv6 = IPAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}) // AnyIPv6 is a constant value for any IP in IPv6. AnyIPv6 = IPAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) )
var ( Network_name = map[int32]string{ 0: "Unknown", 1: "RawTCP", 2: "TCP", 3: "UDP", 4: "UNIX", } Network_value = map[string]int32{ "Unknown": 0, "RawTCP": 1, "TCP": 2, "UDP": 3, "UNIX": 4, } )
Enum value maps for Network.
var ( CIDRMask = net.CIDRMask Dial = net.Dial DialTCP = net.DialTCP DialUDP = net.DialUDP DialUnix = net.DialUnix FileConn = net.FileConn Listen = net.Listen ListenTCP = net.ListenTCP ListenUDP = net.ListenUDP ListenUnix = net.ListenUnix LookupIP = net.LookupIP ParseIP = net.ParseIP ResolveUDPAddr = net.ResolveUDPAddr ResolveUnixAddr = net.ResolveUnixAddr SplitHostPort = net.SplitHostPort )
var File_common_net_address_proto protoreflect.FileDescriptor
var File_common_net_destination_proto protoreflect.FileDescriptor
var File_common_net_network_proto protoreflect.FileDescriptor
var File_common_net_port_proto protoreflect.FileDescriptor
Functions ¶
func HasNetwork ¶ added in v1.0.0
HasNetwork returns true if the network list has a certain network.
func NewConnection ¶ added in v1.0.0
func NewConnection(opts ...ConnectionOption) net.Conn
Types ¶
type Address ¶
type Address interface { IP() net.IP // IP of this Address Domain() string // Domain of this Address Family() AddressFamily String() string // String representation of this Address }
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.
func DomainAddress ¶
DomainAddress creates an Address with given domain.
func ParseAddress ¶ added in v1.0.0
ParseAddress parses a string into an Address. The return value will be an IPAddress when the string is in the form of IPv4 or IPv6 address, or a DomainAddress otherwise.
type AddressFamily ¶ added in v1.0.0
type AddressFamily byte
AddressFamily is the type of address.
func (AddressFamily) IsDomain ¶ added in v1.0.0
func (af AddressFamily) IsDomain() bool
IsDomain returns true if current AddressFamily is Domain.
func (AddressFamily) IsIP ¶ added in v1.0.0
func (af AddressFamily) IsIP() bool
IsIP returns true if current AddressFamily is IPv6 or IPv4.
func (AddressFamily) IsIPv4 ¶ added in v1.0.0
func (af AddressFamily) IsIPv4() bool
IsIPv4 returns true if current AddressFamily is IPv4.
func (AddressFamily) IsIPv6 ¶ added in v1.0.0
func (af AddressFamily) IsIPv6() bool
IsIPv6 returns true if current AddressFamily is IPv6.
type ConnectionOption ¶ added in v1.0.0
type ConnectionOption func(*connection)
func ConnectionInput ¶ added in v1.0.0
func ConnectionInput(writer io.Writer) ConnectionOption
func ConnectionInputMulti ¶ added in v1.0.0
func ConnectionInputMulti(writer buf.Writer) ConnectionOption
func ConnectionLocalAddr ¶ added in v1.0.0
func ConnectionLocalAddr(a net.Addr) ConnectionOption
func ConnectionOnClose ¶ added in v1.0.0
func ConnectionOnClose(n io.Closer) ConnectionOption
func ConnectionOutput ¶ added in v1.0.0
func ConnectionOutput(reader io.Reader) ConnectionOption
func ConnectionOutputMulti ¶ added in v1.0.0
func ConnectionOutputMulti(reader buf.Reader) ConnectionOption
func ConnectionOutputMultiUDP ¶ added in v1.0.0
func ConnectionOutputMultiUDP(reader buf.Reader) ConnectionOption
func ConnectionRemoteAddr ¶ added in v1.0.0
func ConnectionRemoteAddr(a net.Addr) ConnectionOption
type Destination ¶
Destination represents a network destination including address and protocol (tcp / udp).
func DestinationFromAddr ¶ added in v1.0.0
func DestinationFromAddr(addr net.Addr) Destination
DestinationFromAddr generates a Destination from a net address.
func ParseDestination ¶ added in v1.0.0
func ParseDestination(dest string) (Destination, error)
ParseDestination converts a destination from its string presentation.
func TCPDestination ¶
func TCPDestination(address Address, port Port) Destination
TCPDestination creates a TCP destination with given address
func UDPDestination ¶
func UDPDestination(address Address, port Port) Destination
UDPDestination creates a UDP destination with given address
func UnixDestination ¶ added in v1.0.0
func UnixDestination(address Address) Destination
UnixDestination creates a Unix destination with given address
func (Destination) IsValid ¶ added in v1.0.0
func (d Destination) IsValid() bool
IsValid returns true if this Destination is valid.
func (Destination) NetAddr ¶ added in v1.0.0
func (d Destination) NetAddr() string
NetAddr returns the network address in this Destination in string form.
func (Destination) String ¶
func (d Destination) String() string
String returns the strings form of this Destination.
type Endpoint ¶ added in v1.0.0
type Endpoint struct { Network Network `protobuf:"varint,1,opt,name=network,proto3,enum=v2ray.core.common.net.Network" json:"network,omitempty"` Address *IPOrDomain `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` Port uint32 `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"` // contains filtered or unexported fields }
Endpoint of a network connection.
func (*Endpoint) AsDestination ¶ added in v1.0.0
func (p *Endpoint) AsDestination() Destination
AsDestination converts current Endpoint into Destination.
func (*Endpoint) Descriptor
deprecated
added in
v1.0.0
func (*Endpoint) GetAddress ¶ added in v1.0.0
func (x *Endpoint) GetAddress() *IPOrDomain
func (*Endpoint) GetNetwork ¶ added in v1.0.0
func (*Endpoint) ProtoMessage ¶ added in v1.0.0
func (*Endpoint) ProtoMessage()
func (*Endpoint) ProtoReflect ¶ added in v1.0.0
func (x *Endpoint) ProtoReflect() protoreflect.Message
type IPOrDomain ¶ added in v1.0.0
type IPOrDomain struct { // Types that are assignable to Address: // // *IPOrDomain_Ip // *IPOrDomain_Domain Address isIPOrDomain_Address `protobuf_oneof:"address"` // contains filtered or unexported fields }
Address of a network host. It may be either an IP address or a domain address.
func NewIPOrDomain ¶ added in v1.0.0
func NewIPOrDomain(addr Address) *IPOrDomain
NewIPOrDomain translates Address to IPOrDomain
func (*IPOrDomain) AsAddress ¶ added in v1.0.0
func (d *IPOrDomain) AsAddress() Address
AsAddress translates IPOrDomain to Address.
func (*IPOrDomain) Descriptor
deprecated
added in
v1.0.0
func (*IPOrDomain) Descriptor() ([]byte, []int)
Deprecated: Use IPOrDomain.ProtoReflect.Descriptor instead.
func (*IPOrDomain) GetAddress ¶ added in v1.0.0
func (m *IPOrDomain) GetAddress() isIPOrDomain_Address
func (*IPOrDomain) GetDomain ¶ added in v1.0.0
func (x *IPOrDomain) GetDomain() string
func (*IPOrDomain) GetIp ¶ added in v1.0.0
func (x *IPOrDomain) GetIp() []byte
func (*IPOrDomain) ProtoMessage ¶ added in v1.0.0
func (*IPOrDomain) ProtoMessage()
func (*IPOrDomain) ProtoReflect ¶ added in v1.0.0
func (x *IPOrDomain) ProtoReflect() protoreflect.Message
func (*IPOrDomain) Reset ¶ added in v1.0.0
func (x *IPOrDomain) Reset()
func (*IPOrDomain) String ¶ added in v1.0.0
func (x *IPOrDomain) String() string
func (*IPOrDomain) UnmarshalJSONPB ¶ added in v1.0.0
func (d *IPOrDomain) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []byte) error
type IPOrDomain_Domain ¶ added in v1.0.0
type IPOrDomain_Domain struct { // Domain address. Domain string `protobuf:"bytes,2,opt,name=domain,proto3,oneof"` }
type IPOrDomain_Ip ¶ added in v1.0.0
type IPOrDomain_Ip struct { // IP address. Must by either 4 or 16 bytes. Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3,oneof"` }
type ListenConfig ¶ added in v1.0.0
type ListenConfig = net.ListenConfig
type MemoryPortList ¶ added in v1.0.0
type MemoryPortList []MemoryPortRange
func PortListFromProto ¶ added in v1.0.0
func PortListFromProto(l *PortList) MemoryPortList
func (MemoryPortList) Contains ¶ added in v1.0.0
func (mpl MemoryPortList) Contains(port Port) bool
type MemoryPortRange ¶ added in v1.0.0
func (MemoryPortRange) Contains ¶ added in v1.0.0
func (r MemoryPortRange) Contains(port Port) bool
type Network ¶
type Network int32
func ParseNetwork ¶ added in v1.0.0
func ParseNetworkStringList ¶ added in v1.0.0
func (Network) Descriptor ¶ added in v1.0.0
func (Network) Descriptor() protoreflect.EnumDescriptor
func (Network) EnumDescriptor
deprecated
added in
v1.0.0
func (Network) Number ¶ added in v1.0.0
func (x Network) Number() protoreflect.EnumNumber
func (Network) SystemString ¶ added in v1.0.0
func (Network) Type ¶ added in v1.0.0
func (Network) Type() protoreflect.EnumType
type NetworkList ¶
type NetworkList struct { Network []Network `protobuf:"varint,1,rep,packed,name=network,proto3,enum=v2ray.core.common.net.Network" json:"network,omitempty"` // contains filtered or unexported fields }
NetworkList is a list of Networks.
func (*NetworkList) Descriptor
deprecated
added in
v1.0.0
func (*NetworkList) Descriptor() ([]byte, []int)
Deprecated: Use NetworkList.ProtoReflect.Descriptor instead.
func (*NetworkList) GetNetwork ¶ added in v1.0.0
func (x *NetworkList) GetNetwork() []Network
func (*NetworkList) ProtoMessage ¶ added in v1.0.0
func (*NetworkList) ProtoMessage()
func (*NetworkList) ProtoReflect ¶ added in v1.0.0
func (x *NetworkList) ProtoReflect() protoreflect.Message
func (*NetworkList) Reset ¶ added in v1.0.0
func (x *NetworkList) Reset()
func (*NetworkList) String ¶ added in v1.0.0
func (x *NetworkList) String() string
func (*NetworkList) UnmarshalJSONPB ¶ added in v1.0.0
func (nl *NetworkList) UnmarshalJSONPB(unmarshaler *jsonpb.Unmarshaler, bytes []byte) error
type PacketConn ¶ added in v1.0.0
type PacketConn = net.PacketConn
type Port ¶ added in v1.0.0
type Port uint16
Port represents a network port in TCP and UDP protocol.
func PortFromBytes ¶ added in v1.0.0
PortFromBytes converts a byte array to a Port, assuming bytes are in big endian order. @unsafe Caller must ensure that the byte array has at least 2 elements.
func PortFromInt ¶ added in v1.0.0
PortFromInt converts an integer to a Port. @error when the integer is not positive or larger then 65535
func PortFromString ¶ added in v1.0.0
PortFromString converts a string to a Port. @error when the string is not an integer or the integral value is a not a valid Port.
type PortList ¶ added in v1.0.0
type PortList struct { Range []*PortRange `protobuf:"bytes,1,rep,name=range,proto3" json:"range,omitempty"` // contains filtered or unexported fields }
PortList is a list of ports.
func (*PortList) Descriptor
deprecated
added in
v1.0.0
func (*PortList) ProtoMessage ¶ added in v1.0.0
func (*PortList) ProtoMessage()
func (*PortList) ProtoReflect ¶ added in v1.0.0
func (x *PortList) ProtoReflect() protoreflect.Message
type PortRange ¶
type PortRange struct { // The port that this range starts from. From uint32 `protobuf:"varint,1,opt,name=From,proto3" json:"From,omitempty"` // The port that this range ends with (inclusive). To uint32 `protobuf:"varint,2,opt,name=To,proto3" json:"To,omitempty"` // contains filtered or unexported fields }
PortRange represents a range of ports.
func SinglePortRange ¶ added in v1.0.0
SinglePortRange returns a PortRange contains a single port.
func (*PortRange) Contains ¶ added in v1.0.0
Contains returns true if the given port is within the range of a PortRange.
func (*PortRange) Descriptor
deprecated
added in
v1.0.0
func (*PortRange) ProtoMessage ¶ added in v1.0.0
func (*PortRange) ProtoMessage()
func (*PortRange) ProtoReflect ¶ added in v1.0.0
func (x *PortRange) ProtoReflect() protoreflect.Message
type TCPListener ¶ added in v1.0.0
type TCPListener = net.TCPListener
type UnixListener ¶ added in v1.0.0
type UnixListener = net.UnixListener