extnet

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

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 AdornFlow added in v0.0.4

func AdornFlow(wc, rc, tc *atomic.Uint64) func(conn net.Conn) net.Conn

AdornFlow cflow chain

func AdornGzip added in v0.0.4

func AdornGzip(compress bool) func(conn net.Conn) net.Conn

AdornGzip gzip chain

func AdornGzipLevel added in v0.0.4

func AdornGzipLevel(compress bool, level int) func(conn net.Conn) net.Conn

AdornGzipLevel gzip chain with level level see gzip package

func AdornIol added in v0.0.4

func AdornIol(opts ...ciol.Options) func(conn net.Conn) net.Conn

AdornIol ciol chain

func AdornSnappy added in v0.0.4

func AdornSnappy(compress bool) func(conn net.Conn) net.Conn

AdornSnappy snappy chain

func AdornZlib added in v0.0.4

func AdornZlib(compress bool) func(net.Conn) net.Conn

AdornZlib zlib chain

func AdornZlibLevel added in v0.0.4

func AdornZlibLevel(compress bool, level int) func(net.Conn) net.Conn

AdornZlibLevel zlib chain with the level level see zlib package

func AdornZlibLevelDict added in v0.0.4

func AdornZlibLevelDict(compress bool, level int, dict []byte) func(net.Conn) net.Conn

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

func BaseAdornStcp added in v0.0.6

func BaseAdornStcp(method, password string) func(conn net.Conn) net.Conn

BaseAdornStcp base adorn encrypt with method and password

func BaseAdornTLSClient added in v0.0.5

func BaseAdornTLSClient(conf *tls.Config) func(conn net.Conn) net.Conn

BaseAdornTLSClient base adorn tls client

func BaseAdornTLSServer added in v0.0.5

func BaseAdornTLSServer(conf *tls.Config) func(conn net.Conn) net.Conn

BaseAdornTLSServer base adorn tls server

func DialContext added in v0.0.4

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 IsDomain

func IsDomain(host string) bool

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

func IsErrClosed added in v0.0.7

func IsErrClosed(err error) bool

IsErrClosed is error closed

func IsErrDeadline added in v0.0.7

func IsErrDeadline(err error) bool

IsErrDeadline is error i/o deadline reached

func IsErrRefused added in v0.0.7

func IsErrRefused(err error) bool

IsErrRefused is error connection refused

func IsErrSocketNotConnected added in v0.0.7

func IsErrSocketNotConnected(err error) bool

IsErrSocketNotConnected is error socket is not connected

func IsErrTemporary added in v0.0.7

func IsErrTemporary(err error) bool

IsErrTemporary is net error timeout

func IsErrTimeout added in v0.0.7

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 added in v0.1.6

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 added in v0.0.4

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 added in v0.0.4

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

Listen announces on the local network address and afterChains

func ListenWith added in v0.0.4

func ListenWith(network, addr string, base AdornConn, afterChains ...AdornConn) (net.Listener, error)

ListenWith announces on the local network address , base afterChains

func NewListener added in v0.0.4

func NewListener(inner net.Listener, base AdornConn, afterChains ...AdornConn) net.Listener

NewListener new listener

func NextIP added in v0.1.2

func NextIP(ip net.IP) net.IP

NextIP returns the next sequential ip.

func PreviousIP added in v0.1.2

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 added in v0.1.2

func ToIP(v uint32) net.IP

ToIP 数值转换为net.ToIP

Types

type AdornConn added in v0.0.4

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

AdornConn defines the conn decorate.

type AdornConnsChain added in v0.0.4

type AdornConnsChain []AdornConn

AdornConnsChain defines a adornConn array. NOTE: 在conn read或write调用过程是在链上从后往前执行的,(类似栈,先进后执行,后进先执行),

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

type Client added in v0.0.5

type Client struct {
	Timeout          time.Duration   // timeout for dial
	BaseAdorn        AdornConn       // base adorn conn
	AfterAdornChains AdornConnsChain // chains after base
	Forward          Dialer          // if set it will use forward.
}

Client tcp dialer

func (*Client) Dial added in v0.0.5

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

Dial connects to the address on the named network.

func (*Client) DialContext added in v0.0.5

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 added in v0.0.4

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

ContextDialer A ContextDialer dials using a context.

type Dialer added in v0.0.4

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

Dialer A Dialer is a means to establish a connection.

type IPNet added in v0.1.2

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

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

func NewIPNet added in v0.1.2

func NewIPNet(ipNet *net.IPNet) *IPNet

NewIPNet returns Network built using given net.IPNet.

func (*IPNet) ContainsIPNet added in v0.1.2

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

ContainsIPNet returns true if Network covers o, false otherwise

func (*IPNet) ContainsNumeric added in v0.1.2

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

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

func (*IPNet) Equal added in v0.1.2

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

Equal is the equality test for 2 networks.

func (*IPNet) Masked added in v0.1.2

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

Masked returns a new network conforming to new mask.

type Numeric added in v0.1.2

type Numeric []uint32

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

func IP added in v0.1.2

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 added in v0.0.4

func IPv4(a uint32) Numeric

IPv4 returns a equivalent Numeric to given uint32 number,

func IPv6 added in v0.1.2

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

IPv6 returns a equivalent Numeric to given uint32 number,

func (Numeric) Bit added in v0.1.2

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 added in v0.1.2

func (n Numeric) Equal(n1 Numeric) bool

Equal is the equality test for 2 network numbers.

func (Numeric) Mask added in v0.1.2

func (n Numeric) Mask(m NumericMask) Numeric

Mask returns a new masked Numeric from given Numeric.

func (Numeric) Next added in v0.1.2

func (n Numeric) Next() Numeric

Next returns the next logical network number.

func (Numeric) Previous added in v0.1.2

func (n Numeric) Previous() Numeric

Previous returns the previous logical network number.

func (Numeric) String added in v0.1.2

func (n Numeric) String() string

String returns the string form of the IP address ip.

func (Numeric) To16 added in v0.1.2

func (n Numeric) To16() Numeric

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

func (Numeric) To4 added in v0.1.2

func (n Numeric) To4() Numeric

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

func (Numeric) ToIP added in v0.1.2

func (n Numeric) ToIP() net.IP

ToIP returns equivalent net.IP.

type NumericMask added in v0.1.2

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