net

package
v2.19.7+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package net contains common network utilities.

Index

Constants

View Source
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)
)

Variables

View Source
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})
)
View Source
var Network_name = map[int32]string{
	0: "Unknown",
	1: "RawTCP",
	2: "TCP",
	3: "UDP",
}
View Source
var Network_value = map[string]int32{
	"Unknown": 0,
	"RawTCP":  1,
	"TCP":     2,
	"UDP":     3,
}

Functions

This section is empty.

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

func DomainAddress(domain string) Address

DomainAddress creates an Address with given domain.

func IPAddress

func IPAddress(ip []byte) Address

IPAddress creates an Address with given IP.

func ParseAddress added in v1.0.0

func ParseAddress(addr string) Address

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 int

AddressFamily is the type of address.

func (AddressFamily) Either added in v1.24.4

func (v AddressFamily) Either(fs ...AddressFamily) bool

func (AddressFamily) IsDomain added in v1.0.0

func (v AddressFamily) IsDomain() bool

func (AddressFamily) IsIPv4 added in v1.0.0

func (v AddressFamily) IsIPv4() bool

func (AddressFamily) IsIPv6 added in v1.0.0

func (v AddressFamily) IsIPv6() bool

type Destination

type Destination struct {
	Network Network
	Port    Port
	Address Address
}

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 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 (Destination) IsValid added in v1.0.0

func (v Destination) IsValid() bool

func (Destination) NetAddr added in v1.0.0

func (v Destination) NetAddr() string

func (Destination) String

func (v Destination) String() string

type Endpoint added in v1.0.0

type Endpoint struct {
	Network Network     `protobuf:"varint,1,opt,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
	Address *IPOrDomain `protobuf:"bytes,2,opt,name=address" json:"address,omitempty"`
	Port    uint32      `protobuf:"varint,3,opt,name=port" json:"port,omitempty"`
}

func (*Endpoint) AsDestination added in v1.0.0

func (v *Endpoint) AsDestination() Destination

AsDestination converts current Enpoint into Destination.

func (*Endpoint) Descriptor added in v1.0.0

func (*Endpoint) Descriptor() ([]byte, []int)

func (*Endpoint) GetAddress added in v1.0.0

func (m *Endpoint) GetAddress() *IPOrDomain

func (*Endpoint) GetNetwork added in v1.0.0

func (m *Endpoint) GetNetwork() Network

func (*Endpoint) GetPort added in v1.0.0

func (m *Endpoint) GetPort() uint32

func (*Endpoint) ProtoMessage added in v1.0.0

func (*Endpoint) ProtoMessage()

func (*Endpoint) Reset added in v1.0.0

func (m *Endpoint) Reset()

func (*Endpoint) String added in v1.0.0

func (m *Endpoint) String() string

type IPNet added in v1.0.0

type IPNet struct {
	// contains filtered or unexported fields
}

func NewIPNet added in v1.13.1

func NewIPNet() *IPNet

func (*IPNet) Add added in v1.13.1

func (v *IPNet) Add(ipNet *net.IPNet)

func (*IPNet) AddIP

func (v *IPNet) AddIP(ip []byte, mask byte)

func (*IPNet) Contains added in v1.13.1

func (v *IPNet) Contains(ip net.IP) bool

func (*IPNet) IsEmpty

func (v *IPNet) IsEmpty() bool

type IPOrDomain added in v1.0.0

type IPOrDomain struct {
	// Types that are valid to be assigned to Address:
	//	*IPOrDomain_Ip
	//	*IPOrDomain_Domain
	Address isIPOrDomain_Address `protobuf_oneof:"address"`
}

func NewIPOrDomain added in v1.0.0

func NewIPOrDomain(addr Address) *IPOrDomain

func (*IPOrDomain) AsAddress added in v1.0.0

func (v *IPOrDomain) AsAddress() Address

func (*IPOrDomain) Descriptor added in v1.0.0

func (*IPOrDomain) Descriptor() ([]byte, []int)

func (*IPOrDomain) GetAddress added in v1.0.0

func (m *IPOrDomain) GetAddress() isIPOrDomain_Address

func (*IPOrDomain) GetDomain added in v1.0.0

func (m *IPOrDomain) GetDomain() string

func (*IPOrDomain) GetIp added in v1.0.0

func (m *IPOrDomain) GetIp() []byte

func (*IPOrDomain) ProtoMessage added in v1.0.0

func (*IPOrDomain) ProtoMessage()

func (*IPOrDomain) Reset added in v1.0.0

func (m *IPOrDomain) Reset()

func (*IPOrDomain) String added in v1.0.0

func (m *IPOrDomain) String() string

func (*IPOrDomain) XXX_OneofFuncs

func (*IPOrDomain) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type IPOrDomain_Domain added in v1.0.0

type IPOrDomain_Domain struct {
	Domain string `protobuf:"bytes,2,opt,name=domain,oneof"`
}

type IPOrDomain_Ip added in v1.0.0

type IPOrDomain_Ip struct {
	Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3,oneof"`
}

type Network

type Network int32
const (
	Network_Unknown Network = 0
	// Native TCP provided by system.
	Network_RawTCP Network = 1
	// V2Ray specific TCP.
	Network_TCP Network = 2
	Network_UDP Network = 3
)

func ParseNetwork added in v1.0.0

func ParseNetwork(nwStr string) Network

func (Network) AsList added in v1.13.1

func (v Network) AsList() *NetworkList

func (Network) EnumDescriptor added in v1.0.0

func (Network) EnumDescriptor() ([]byte, []int)

func (Network) String added in v1.0.0

func (x Network) String() string

func (Network) SystemString added in v1.0.0

func (v Network) SystemString() string

func (Network) URLPrefix

func (v Network) URLPrefix() string

type NetworkList

type NetworkList struct {
	Network []Network `protobuf:"varint,1,rep,packed,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
}

func (*NetworkList) Descriptor added in v1.0.0

func (*NetworkList) Descriptor() ([]byte, []int)

func (NetworkList) Get

func (v NetworkList) Get(idx int) Network

func (*NetworkList) GetNetwork added in v1.0.0

func (m *NetworkList) GetNetwork() []Network

func (NetworkList) HasNetwork

func (v NetworkList) HasNetwork(network Network) bool

HasNetwork returns true if the given network is in v NetworkList.

func (*NetworkList) ProtoMessage added in v1.0.0

func (*NetworkList) ProtoMessage()

func (*NetworkList) Reset added in v1.0.0

func (m *NetworkList) Reset()

func (NetworkList) Size

func (v NetworkList) Size() int

Size returns the number of networks in this network list.

func (*NetworkList) String added in v1.0.0

func (m *NetworkList) String() string

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

func PortFromBytes(port []byte) Port

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

func PortFromInt(val uint32) (Port, error)

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

func PortFromString(s string) (Port, error)

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.

func (Port) Bytes added in v1.13.1

func (v Port) Bytes(b []byte) []byte

Bytes returns the correspoding bytes of v Port, in big endian order.

func (Port) String added in v1.0.0

func (v Port) String() string

String returns the string presentation of v Port.

func (Port) Value added in v1.0.0

func (v Port) Value() uint16

Value return the correspoding uint16 value of v Port.

type PortRange

type PortRange struct {
	From uint32 `protobuf:"varint,1,opt,name=From" json:"From,omitempty"`
	To   uint32 `protobuf:"varint,2,opt,name=To" json:"To,omitempty"`
}

PortRange represents a range of ports.

func SinglePortRange added in v1.0.0

func SinglePortRange(v Port) *PortRange

SinglePortRange returns a PortRange contains a single port.

func (PortRange) Contains added in v1.0.0

func (v PortRange) Contains(port Port) bool

Contains returns true if the given port is within the range of v PortRange.

func (*PortRange) Descriptor added in v1.0.0

func (*PortRange) Descriptor() ([]byte, []int)

func (PortRange) FromPort added in v1.0.0

func (v PortRange) FromPort() Port

func (*PortRange) GetFrom added in v1.0.0

func (m *PortRange) GetFrom() uint32

func (*PortRange) GetTo added in v1.0.0

func (m *PortRange) GetTo() uint32

func (*PortRange) ProtoMessage added in v1.0.0

func (*PortRange) ProtoMessage()

func (*PortRange) Reset added in v1.0.0

func (m *PortRange) Reset()

func (*PortRange) String added in v1.0.0

func (m *PortRange) String() string

func (PortRange) ToPort added in v1.0.0

func (v PortRange) ToPort() Port

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL