extnet

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Overview

Package extnet extend network

Index

Constants

View Source
const (
	IPv4Uint32Cnt = 1
	IPv6Uint32Cnt = 4
)

IP uint32 count const defined

Variables

View Source
var ErrInvalidBitPosition = fmt.Errorf("bit position not valid")

ErrInvalidBitPosition is returned when bits requested is not valid.

Functions

func DialContext

func DialContext(ctx context.Context, d Dialer, network, address string) (net.Conn, error)

DialContext dial context with dialer WARNING: this can leak a goroutine for as long as the underlying Dialer implementation takes to timeout A Conn returned from a successful Dial after the context has been canceled will be immediately closed.

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func GetFreePorts

func GetFreePorts(count int) ([]int, error)

GetFreePorts asks the kernel for free open ports that are ready to use.

func IsDomain

func IsDomain(host string) bool

IsDomain 是否是域名,只检查host或ip,不可带port,否则会误判

func IsErrClosed

func IsErrClosed(err error) bool

IsErrClosed is error closed

func IsErrDeadline

func IsErrDeadline(err error) bool

IsErrDeadline is error i/o deadline reached

func IsErrRefused

func IsErrRefused(err error) bool

IsErrRefused is error connection refused

func IsErrSocketNotConnected

func IsErrSocketNotConnected(err error) bool

IsErrSocketNotConnected is error socket is not connected

func IsErrTemporary

func IsErrTemporary(err error) bool

IsErrTemporary is net error timeout

func IsErrTimeout

func IsErrTimeout(err error) bool

IsErrTimeout is net error timeout

func IsIntranet

func IsIntranet(host string) bool

IsIntranet is intranet network,if host is domain,it will looks up host using the local resolver. net.LookupIP may cause deadlock in windows see https://github.com/golang/go/issues/24178 局域网IP段:

A类: 10.0.0.0~10.255.255.255
B类: 172.16.0.0~172.31.255.255
C类: 192.168.0.0~192.168.255.255

func IsIntranetIP

func IsIntranetIP(ip net.IP) bool

IsIntranetIP is intranet network or not. 局域网IP段:

A类: 10.0.0.0~10.255.255.255
B类: 172.16.0.0~172.31.255.255
C类: 192.168.0.0~192.168.255.255

func JoinHostPort

func JoinHostPort(host string, port uint16) string

JoinHostPort combines host and port into a network address of the form "host:port". If host contains a colon, as found in literal IPv6 addresses, then JoinHostPort returns "[host]:port".

See func Dial for a description of the host and port parameters.

func Listen

func Listen(network, addr string, chains ...AdornConn) (net.Listener, error)

Listen announces on the local network address and afterChains

func MustGetFreePort

func MustGetFreePort() int

MustGetFreePort calls GetFreePort and panics on error

func NewListener

func NewListener(inner net.Listener, chains ...AdornConn) net.Listener

NewListener new listener

func NextIP

func NextIP(ip net.IP) net.IP

NextIP returns the next sequential ip.

func PreviousIP

func PreviousIP(ip net.IP) net.IP

PreviousIP returns the previous sequential ip.

func SplitHostPort

func SplitHostPort(addr string) (string, uint16, error)

SplitHostPort splits a network address of the form "host:port", "host%zone:port", "[host]:port" or "[host%zone]:port" into host or host%zone and port.

A literal IPv6 address in hostport must be enclosed in square brackets, as in "[::1]:80", "[::1%lo0]:80".

See func Dial for a description of the hostport parameter, and host and port results.

func ToIP

func ToIP(v uint32) net.IP

ToIP 数值转换为net.ToIP

Types

type AdornConn

type AdornConn func(conn net.Conn) net.Conn

AdornConn defines the conn decorate.

func AdornFlow

func AdornFlow(wc, rc, tc *atomic.Uint64) AdornConn

AdornFlow cflow chain

func AdornGzip

func AdornGzip(compress bool) AdornConn

AdornGzip gzip chain

func AdornGzipLevel

func AdornGzipLevel(compress bool, level int) AdornConn

AdornGzipLevel gzip chain with level level see gzip package

func AdornIol

func AdornIol(opts ...ciol.Options) AdornConn

AdornIol ciol chain

func AdornSnappy

func AdornSnappy(compress bool) AdornConn

AdornSnappy snappy chain

func AdornZlib

func AdornZlib(compress bool) AdornConn

AdornZlib zlib chain

func AdornZlibLevel

func AdornZlibLevel(compress bool, level int) AdornConn

AdornZlibLevel zlib chain with the level level see zlib package

func AdornZlibLevelDict

func AdornZlibLevelDict(compress bool, level int, dict []byte) AdornConn

AdornZlibLevelDict zlib chain with the level and dict level see zlib package

func BaseAdornStcp

func BaseAdornStcp(method, password string) AdornConn

BaseAdornStcp base adorn encrypt with method and password

func BaseAdornTLSClient

func BaseAdornTLSClient(conf *tls.Config) AdornConn

BaseAdornTLSClient base adorn tls client

func BaseAdornTLSServer

func BaseAdornTLSServer(conf *tls.Config) AdornConn

BaseAdornTLSServer base adorn tls server

type AdornConnsChain

type AdornConnsChain []AdornConn

AdornConnsChain defines a adornConn array. NOTE: 在conn read或write调用过程是在链上从后往前执行的,(类似洋葱,包在最外面的选执行),

所以基础链,统计链的应放在链头,也就是chains的第一个,最靠近出口

type Client

type Client struct {
	Timeout     time.Duration   // timeout for dial
	AdornChains AdornConnsChain // adorn chains
	Forward     Dialer          // if set it will use forward.
}

Client tcp dialer

func (*Client) Dial

func (sf *Client) Dial(network, addr string) (net.Conn, error)

Dial connects to the address on the named network.

func (*Client) DialContext

func (sf *Client) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext connects to the address on the named network using the provided context.

type ContextDialer

type ContextDialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

ContextDialer A ContextDialer dials using a context.

type Dialer

type Dialer interface {
	Dial(network, address string) (net.Conn, error)
}

Dialer A Dialer is a means to establish a connection.

type IPNet

type IPNet struct {
	*net.IPNet
	Number Numeric
	Mask   NumericMask
}

IPNet represents a block of network numbers, also known as CIDR.

func NewIPNet

func NewIPNet(ipNet *net.IPNet) *IPNet

NewIPNet returns Network built using given net.IPNet.

func (*IPNet) ContainsIPNet

func (n *IPNet) ContainsIPNet(o *IPNet) bool

ContainsIPNet returns true if Network covers o, false otherwise

func (*IPNet) ContainsNumeric

func (n *IPNet) ContainsNumeric(nn Numeric) bool

ContainsNumeric returns true if Numeric is in range of IPNet, false otherwise.

func (*IPNet) Equal

func (n *IPNet) Equal(n1 *IPNet) bool

Equal is the equality test for 2 networks.

func (*IPNet) Masked

func (n *IPNet) Masked(ones int) *IPNet

Masked returns a new network conforming to new mask.

type Numeric

type Numeric []uint32

Numeric represents an ToIP address using uint32 as internal storage. IPv4 uses 1 uint32 IPv6 uses 4 uint32.

func IP

func IP(ip net.IP) Numeric

IP returns a equivalent Numeric to given IP address, return nil if ip is neither IPv4 nor IPv6.

func IPv4

func IPv4(a uint32) Numeric

IPv4 returns a equivalent Numeric to given uint32 number,

func IPv6

func IPv6(a, b, c, d uint32) Numeric

IPv6 returns a equivalent Numeric to given uint32 number,

func (Numeric) Bit

func (n Numeric) Bit(position uint) (bool, error)

Bit returns uint32 representing the bit value at given position, e.g., "128.0.0.0" has bit value of 1 at position 31, and 0 for positions 30 to 0.

func (Numeric) Equal

func (n Numeric) Equal(n1 Numeric) bool

Equal is the equality test for 2 network numbers.

func (Numeric) Mask

func (n Numeric) Mask(m NumericMask) Numeric

Mask returns a new masked Numeric from given Numeric.

func (Numeric) Next

func (n Numeric) Next() Numeric

Next returns the next logical network number.

func (Numeric) Previous

func (n Numeric) Previous() Numeric

Previous returns the previous logical network number.

func (Numeric) String

func (n Numeric) String() string

String returns the string form of the IP address ip.

func (Numeric) To16

func (n Numeric) To16() Numeric

To16 returns ip address if ip is IPv6, returns nil otherwise.

func (Numeric) To4

func (n Numeric) To4() Numeric

To4 returns ip address if ip is IPv4, returns nil otherwise.

func (Numeric) ToIP

func (n Numeric) ToIP() net.IP

ToIP returns equivalent net.IP.

type NumericMask

type NumericMask []uint32

NumericMask represents an IP address using uint32 as internal storage. IPv4 uses 1 uint32, while IPv6 uses 4 uint32.

Directories

Path Synopsis
connection
cbuffered
Package cbuffered 实现读缓冲的net.conn接口
Package cbuffered 实现读缓冲的net.conn接口
ccrypt
Package ccrypt 实现net.conn的加密conn接口 aes cfb加密码的连接,通过提供的配置使用pbkdf2生成key, 依靠key和hash生成iv
Package ccrypt 实现net.conn的加密conn接口 aes cfb加密码的连接,通过提供的配置使用pbkdf2生成key, 依靠key和hash生成iv
cencrypt
Package cencrypt 实现加密的net.conn接口
Package cencrypt 实现加密的net.conn接口
cflow
Package cflow 实现字节统计,读,写,读写统计,以字节为准.
Package cflow 实现字节统计,读,写,读写统计,以字节为准.
cgzip
Package cgzip 采用gzip压缩实现的net.conn接口
Package cgzip 采用gzip压缩实现的net.conn接口
ciol
Package ciol 实现 net.conn 网络io限速器接口
Package ciol 实现 net.conn 网络io限速器接口
csnappy
Package csnappy 采用snappy压缩实现的net.conn接口
Package csnappy 采用snappy压缩实现的net.conn接口
czlib
Package czlib 采用zlib压缩实现的net.conn接口
Package czlib 采用zlib压缩实现的net.conn接口

Jump to

Keyboard shortcuts

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