net

package
v1.24.4 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package net contains common network utilities.

Index

Constants

View Source
const (
	AddressFamilyIPv4   = AddressFamily(0)
	AddressFamilyIPv6   = AddressFamily(1)
	AddressFamilyDomain = AddressFamily(2)
)
View Source
const (
	// TCPNetwork represents the TCP network.
	TCPNetwork = Network("tcp")

	// UDPNetwork represents the UDP network.
	UDPNetwork = Network("udp")

	// KCPNetwork represents the KCP network.
	KCPNetwork = Network("kcp")

	// WSNetwork represents the Websocket over HTTP network.
	WSNetwork = Network("ws")
)

Variables

View Source
var (
	LocalHostIP = IPAddress([]byte{127, 0, 0, 1})
	AnyIP       = IPAddress([]byte{0, 0, 0, 0})
)
View Source
var (
	// ErrInvalidPortRage indicates an error during port range parsing.
	ErrInvalidPortRange = errors.New("Invalid port range.")
)

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
	Equals(Address) bool
}

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

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

type AddressFamily int

func (AddressFamily) Either

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

func (AddressFamily) IsDomain

func (this AddressFamily) IsDomain() bool

func (AddressFamily) IsIPv4

func (this AddressFamily) IsIPv4() bool

func (AddressFamily) IsIPv6

func (this AddressFamily) IsIPv6() bool

type Destination

type Destination interface {
	Network() Network // Protocol of communication (tcp / udp)
	Address() Address // Address of destination
	Port() Port
	String() string // String representation of the destination
	NetAddr() string
	Equals(Destination) bool

	IsTCP() bool // True if destination is reachable via TCP
	IsUDP() bool // True if destination is reachable via UDP
}

Destination represents a network destination including address and protocol (tcp / udp).

func DestinationFromAddr

func DestinationFromAddr(addr net.Addr) Destination

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

type IPNet

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

func NewIPNet

func NewIPNet() *IPNet

func NewIPNetInitialValue

func NewIPNetInitialValue(data map[uint32]byte) *IPNet

func (*IPNet) Add

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

func (*IPNet) Contains

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

func (*IPNet) Serialize

func (this *IPNet) Serialize() []uint32

type Network

type Network string

Network represents a communication network on internet.

func (Network) AsList

func (this Network) AsList() *NetworkList

func (Network) String

func (this Network) String() string

type NetworkList

type NetworkList []Network

NetworkList is a list of Networks.

func NewNetworkList

func NewNetworkList(networks collect.StringList) NetworkList

NewNetworkList construsts a NetWorklist from the given StringListeralList.

func (*NetworkList) HasNetwork

func (this *NetworkList) HasNetwork(network Network) bool

HashNetwork returns true if the given network is in this NetworkList.

type Port

type Port uint16

Port represents a network port in TCP and UDP protocol.

func PortFromBytes

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

func PortFromInt(v int) (Port, error)

PortFromInt converts an integer to a Port. @error when the integer is not positive or larger then 65535

func PortFromString

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

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

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

func (Port) String

func (this Port) String() string

String returns the string presentation of this Port.

func (Port) Value

func (this Port) Value() uint16

Value return the correspoding uint16 value of this Port.

type PortRange

type PortRange struct {
	From Port
	To   Port
}

PortRange represents a range of ports.

func (PortRange) Contains

func (this PortRange) Contains(port Port) bool

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

type TimeOutReader

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

func NewTimeOutReader

func NewTimeOutReader(timeout int, connection net.Conn) *TimeOutReader

func (*TimeOutReader) GetTimeOut

func (reader *TimeOutReader) GetTimeOut() int

func (*TimeOutReader) Read

func (reader *TimeOutReader) Read(p []byte) (int, error)

func (*TimeOutReader) Release

func (reader *TimeOutReader) Release()

func (*TimeOutReader) SetTimeOut

func (reader *TimeOutReader) SetTimeOut(value int)

Jump to

Keyboard shortcuts

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