conn

package
v0.34.8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: GPL-3.0 Imports: 33 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const HandshakeTimeout = 10 * time.Second

HandshakeTimeout bounds how long an accepted transport may take to present its first stream or protocol upgrade before it is dropped.

Variables

View Source
var LocalTCPAddr = &net.TCPAddr{IP: net.ParseIP("127.0.0.1")}

Functions

func Accept

func Accept(l net.Listener, f func(c net.Conn))

Accept serves l until it is closed, backing off on transient errors.

func CheckFlowLimits added in v0.29.25

func CheckFlowLimits(f *file.Flow, label string) error

CheckFlowLimits returns an error naming label if f is over its traffic limit or past its time limit.

func CopyWaitGroup

func CopyWaitGroup(conn1, conn2 net.Conn, crypt bool, snappy bool, rate *rate.Rate,
	flows []*file.Flow, isServer bool, proxyProtocol int, rb []byte, task *file.Tunnel, isLocal, isFramed bool)

CopyWaitGroup conn1 mux conn

func DescribeNetError added in v0.34.8

func DescribeNetError(err error, c net.Conn) string

func DialKCPWithLocalIP added in v0.34.6

func DialKCPWithLocalIP(raddr string, localIP string) (*kcp.UDPSession, error)

DialKCPWithLocalIP creates a KCP connection with optional local IP binding.

func DialQuicWithLocalIP added in v0.34.7

func DialQuicWithLocalIP(ctx context.Context, server string, tlsCfg *tls.Config, quicCfg *quic.Config, localIP string) (*quic.Conn, error)

func DialVirtual added in v0.34.8

func DialVirtual(ctx context.Context, l *netx.ChanListener, remote string) (net.Conn, error)

DialVirtual connects to l through an in-memory pipe, with remote, a host:port address, as the address of the dialing side. It waits for queue space until ctx is done or l is closed.

func DialWS added in v0.27.0

func DialWS(rawConn net.Conn, urlStr, host string, timeout time.Duration) (*websocket.Conn, *http.Response, error)

func DialWSS added in v0.27.0

func DialWSS(rawConn net.Conn, urlStr, host, sni string, timeout time.Duration) (*websocket.Conn, *http.Response, error)

func GetConn

func GetConn(conn net.Conn, cpt, snappy bool, rt *rate.Rate, isServer, isLocal bool) io.ReadWriteCloser

GetConn get crypt or snappy conn

func GetLenBytes

func GetLenBytes(buf []byte) (b []byte, err error)

GetLenBytes get the assembled amount data(len 4 and content)

func GetRealIP added in v0.33.3

func GetRealIP(r *http.Request, header string) string

func GetTlsConn added in v0.29.31

func GetTlsConn(c net.Conn, sni string) (net.Conn, error)

func HandleUdp5 added in v0.30.6

func HandleUdp5(ctx context.Context, serverConn net.Conn, timeout time.Duration, localIP string)

HandleUdp5 relays the SOCKS5 UDP datagrams of serverConn, one per frame, through a local UDP socket: each datagram's payload goes to its destination, and each datagram received goes back with its source as the address.

func IsBrokenPipe added in v0.34.8

func IsBrokenPipe(err error) bool

func IsConnAborted added in v0.34.8

func IsConnAborted(err error) bool

func IsConnReset added in v0.34.8

func IsConnReset(err error) bool

func IsTimeout added in v0.34.6

func IsTimeout(err error) bool

func Join added in v0.34.8

func Join(c1, c2 net.Conn, flows []*file.Flow, task *file.Tunnel, remote string)

Join relays between c1 and c2 until either direction ends, then closes both. Every byte written either way is added as both inlet and export traffic to each of flows, and the relay stops once one of them is over its limits; the first bytes of each direction set task.IsHttp.

func NetErrorKind added in v0.34.8

func NetErrorKind(err error) string

func NewKCPSessionWithConn added in v0.34.6

func NewKCPSessionWithConn(raddr *net.UDPAddr, pc net.PacketConn) (*kcp.UDPSession, error)

NewKCPSessionWithConn creates a KCP session based on an existing PacketConn.

func NewKcpListenerAndProcess

func NewKcpListenerAndProcess(addr string, f func(c net.Conn)) error

func NewQuicListenerAndProcess added in v0.29.26

func NewQuicListenerAndProcess(addr string, tlsConfig *tls.Config, quicConfig *quic.Config, f func(c net.Conn)) error

func NewUdpConnByAddr added in v0.30.4

func NewUdpConnByAddr(addr string) (net.PacketConn, error)

func NewVirtualListener added in v0.30.6

func NewVirtualListener(addr net.Addr) *netx.ChanListener

NewVirtualListener returns an in-memory listener that reports addr, or LocalTCPAddr when addr is nil.

func NewWSListener added in v0.27.0

func NewWSListener(base net.Listener, path, trustedIps, realIpHeader string) net.Listener

func NewWSSListener added in v0.27.0

func NewWSSListener(base net.Listener, path string, cert tls.Certificate, trustedIps, realIpHeader string) net.Listener

func ParseAddr added in v0.30.6

func ParseAddr(addr string) net.Addr

func ParseTCPAddr added in v0.34.8

func ParseTCPAddr(s string) (net.Addr, error)

ParseTCPAddr resolves s, a host:port address. An empty s yields a nil address and no error.

func ProxyProtocolHeader added in v0.34.8

func ProxyProtocolHeader(version int, client, target net.Addr) *proxyproto.Header

ProxyProtocolHeader returns the PROXY protocol header of version 1 or 2 for a connection from client to target, or nil for any other version. The addresses are taken as proxyproto.NewHeader takes them: an unknown or unspecified target becomes the zero address of the client's family, and an IPv4 and an IPv6 address are both sent as IPv6. A pair that it rejects, such as a nil client, an address without an IP or addresses of other types, gives a header without addresses ("PROXY UNKNOWN" for version 1, a PROXY command of the AF_UNSPEC family for version 2), so that the backend uses the connection's own addresses.

func ReadACK added in v0.30.4

func ReadACK(c net.Conn, timeout time.Duration) error

func ServeVirtual added in v0.34.8

func ServeVirtual(l *netx.ChanListener, c net.Conn)

ServeVirtual hands c to l, closing c if l is closed or its queue is full.

func SetUdpSession

func SetUdpSession(sess *kcp.UDPSession)

SetUdpSession udp connection setting

func WriteACK added in v0.30.4

func WriteACK(c net.Conn, timeout time.Duration) error

Types

type Conn

type Conn struct {
	Conn net.Conn
	// contains filtered or unexported fields
}

func NewConn

func NewConn(conn net.Conn) *Conn

NewConn new conn

func (*Conn) BufferWrite added in v0.29.38

func (s *Conn) BufferWrite(b []byte) (int, error)

func (*Conn) Close

func (s *Conn) Close() error

func (*Conn) FlushBuf added in v0.29.38

func (s *Conn) FlushBuf() error

func (*Conn) GetAddStatus

func (s *Conn) GetAddStatus() (b bool)

GetAddStatus get task or host result of add

func (*Conn) GetConfigInfo

func (s *Conn) GetConfigInfo() (*file.Client, error)

GetConfigInfo get client config info

func (*Conn) GetHealthInfo

func (s *Conn) GetHealthInfo() (info string, status bool, err error)

GetHealthInfo get health info from conn

func (*Conn) GetHost

func (s *Conn) GetHost() (address string, r *http.Request, head, rest []byte, err error)

GetHost reads one HTTP proxy request header from the connection and resolves the target address. head holds the raw header bytes and rest holds everything read past the header (request body, pipelined requests or early tunnel data) followed by any data still queued on the connection, so nothing stays queued on return. On error head holds every byte consumed so far.

func (*Conn) GetHostInfo

func (s *Conn) GetHostInfo() (*file.Host, error)

GetHostInfo get host info

func (*Conn) GetLen

func (s *Conn) GetLen() (int, error)

func (*Conn) GetLinkInfo

func (s *Conn) GetLinkInfo() (lk *Link, err error)

GetLinkInfo get link info from conn

func (*Conn) GetShortContent

func (s *Conn) GetShortContent(l int) (b []byte, err error)

func (*Conn) GetShortLenContent

func (s *Conn) GetShortLenContent() (b []byte, err error)

func (*Conn) GetTaskInfo

func (s *Conn) GetTaskInfo() (*file.Tunnel, error)

GetTaskInfo get task info

func (*Conn) IsClosed added in v0.30.3

func (s *Conn) IsClosed() bool

func (*Conn) LocalAddr

func (s *Conn) LocalAddr() net.Addr

func (*Conn) OnClose added in v0.32.0

func (s *Conn) OnClose(fn func(*Conn)) *Conn

func (*Conn) Read

func (s *Conn) Read(b []byte) (n int, err error)

read

func (*Conn) ReadFlag

func (s *Conn) ReadFlag() (string, error)

ReadFlag read flag

func (*Conn) ReadLen

func (s *Conn) ReadLen(cLen int, buf []byte) (int, error)

func (*Conn) RemoteAddr

func (s *Conn) RemoteAddr() net.Addr

func (*Conn) SendHealthInfo

func (s *Conn) SendHealthInfo(info, status string) (int, error)

SendHealthInfo send info for link

func (*Conn) SendInfo

func (s *Conn) SendInfo(t interface{}, flag string) (int, error)

SendInfo send info

func (*Conn) SetAlive

func (s *Conn) SetAlive()

SetAlive set alive

func (*Conn) SetDeadline

func (s *Conn) SetDeadline(t time.Time) error

func (*Conn) SetRb added in v0.32.0

func (s *Conn) SetRb(rbs ...[]byte) *Conn

func (*Conn) SetReadDeadline

func (s *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetReadDeadlineBySecond

func (s *Conn) SetReadDeadlineBySecond(t time.Duration)

SetReadDeadlineBySecond set read deadline

func (*Conn) SetWriteDeadline

func (s *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (s *Conn) Write(b []byte) (n int, err error)

write

func (*Conn) WriteAddFail

func (s *Conn) WriteAddFail() error

func (*Conn) WriteAddOk

func (s *Conn) WriteAddOk() error

func (*Conn) WriteChan

func (s *Conn) WriteChan() (int, error)

WriteChan write chan

func (*Conn) WriteClose

func (s *Conn) WriteClose() (int, error)

WriteClose write sign flag

func (*Conn) WriteConfig

func (s *Conn) WriteConfig() (int, error)

WriteConfig write config

func (*Conn) WriteLenContent

func (s *Conn) WriteLenContent(buf []byte) (err error)

func (*Conn) WriteMain

func (s *Conn) WriteMain() (int, error)

WriteMain write main

type FlowConn added in v0.28.3

type FlowConn struct {
	*RWConn
	// contains filtered or unexported fields
}

func NewFlowConn added in v0.28.3

func NewFlowConn(conn io.ReadWriteCloser, task, client *file.Flow) *FlowConn

func (*FlowConn) Read added in v0.28.3

func (c *FlowConn) Read(p []byte) (int, error)

func (*FlowConn) Write added in v0.28.3

func (c *FlowConn) Write(p []byte) (int, error)
type Link struct {
	ConnType   string //连接类型
	Host       string //目标
	Crypt      bool   //加密
	Compress   bool
	LocalProxy bool
	RemoteAddr string
	Option     Options
}
func NewLink(connType string, host string, crypt bool, compress bool, remoteAddr string, localProxy bool, opts ...Option) *Link

type Option

type Option func(*Options)

type Options

type Options struct {
	Timeout time.Duration
	NeedAck bool
}

type QuicAutoCloseConn added in v0.30.4

type QuicAutoCloseConn struct{ *QuicStreamConn }

func NewQuicAutoCloseConn added in v0.30.4

func NewQuicAutoCloseConn(stream *quic.Stream, sess *quic.Conn) *QuicAutoCloseConn

func (*QuicAutoCloseConn) Close added in v0.30.4

func (q *QuicAutoCloseConn) Close() error

type QuicStreamConn added in v0.30.4

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

func NewQuicStreamConn added in v0.30.4

func NewQuicStreamConn(stream *quic.Stream, sess *quic.Conn) *QuicStreamConn

func (*QuicStreamConn) Close added in v0.30.4

func (q *QuicStreamConn) Close() error

func (*QuicStreamConn) GetSession added in v0.31.0

func (q *QuicStreamConn) GetSession() *quic.Conn

func (*QuicStreamConn) LocalAddr added in v0.30.4

func (q *QuicStreamConn) LocalAddr() net.Addr

func (*QuicStreamConn) Read added in v0.30.4

func (q *QuicStreamConn) Read(p []byte) (int, error)

func (*QuicStreamConn) RemoteAddr added in v0.30.4

func (q *QuicStreamConn) RemoteAddr() net.Addr

func (*QuicStreamConn) SetDeadline added in v0.30.4

func (q *QuicStreamConn) SetDeadline(t time.Time) error

func (*QuicStreamConn) SetReadDeadline added in v0.30.4

func (q *QuicStreamConn) SetReadDeadline(t time.Time) error

func (*QuicStreamConn) SetWriteDeadline added in v0.30.4

func (q *QuicStreamConn) SetWriteDeadline(t time.Time) error

func (*QuicStreamConn) Write added in v0.30.4

func (q *QuicStreamConn) Write(p []byte) (int, error)

type RWConn added in v0.28.3

type RWConn struct {
	io.ReadWriteCloser
	FakeAddr net.Addr
}

func NewRWConn added in v0.28.3

func NewRWConn(conn io.ReadWriteCloser) *RWConn

func (*RWConn) LocalAddr added in v0.28.3

func (c *RWConn) LocalAddr() net.Addr

func (*RWConn) RemoteAddr added in v0.28.3

func (c *RWConn) RemoteAddr() net.Addr

func (*RWConn) SetDeadline added in v0.28.3

func (c *RWConn) SetDeadline(_ time.Time) error

func (*RWConn) SetReadDeadline added in v0.28.3

func (c *RWConn) SetReadDeadline(_ time.Time) error

func (*RWConn) SetWriteDeadline added in v0.28.3

func (c *RWConn) SetWriteDeadline(_ time.Time) error

type Secret

type Secret struct {
	//Type     string // tcp/udp
	Password string
	Conn     *Conn
}

func NewSecret

func NewSecret(p string, conn *Conn) *Secret

type SmartUdpConn added in v0.30.4

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

func NewSmartUdpConn added in v0.30.4

func NewSmartUdpConn(conns []net.PacketConn, addr *net.UDPAddr) *SmartUdpConn

func (*SmartUdpConn) Close added in v0.30.4

func (s *SmartUdpConn) Close() error

func (*SmartUdpConn) LocalAddr added in v0.30.4

func (s *SmartUdpConn) LocalAddr() net.Addr

func (*SmartUdpConn) ReadFrom added in v0.30.4

func (s *SmartUdpConn) ReadFrom(p []byte) (int, net.Addr, error)

func (*SmartUdpConn) SetDeadline added in v0.30.4

func (s *SmartUdpConn) SetDeadline(t time.Time) error

func (*SmartUdpConn) SetReadDeadline added in v0.30.4

func (s *SmartUdpConn) SetReadDeadline(t time.Time) error

func (*SmartUdpConn) SetWriteDeadline added in v0.30.4

func (s *SmartUdpConn) SetWriteDeadline(t time.Time) error

func (*SmartUdpConn) UDPConns added in v0.34.8

func (s *SmartUdpConn) UDPConns() []*net.UDPConn

func (*SmartUdpConn) WriteTo added in v0.30.4

func (s *SmartUdpConn) WriteTo(p []byte, addr net.Addr) (int, error)

type SnappyConn

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

func NewSnappyConn

func NewSnappyConn(conn io.ReadWriteCloser) *SnappyConn

func (*SnappyConn) Close

func (s *SnappyConn) Close() error

func (*SnappyConn) Read

func (s *SnappyConn) Read(b []byte) (n int, err error)

snappy压缩读

func (*SnappyConn) Write

func (s *SnappyConn) Write(b []byte) (n int, err error)

snappy压缩写

type TeeConn added in v0.30.4

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

func NewTeeConn added in v0.30.4

func NewTeeConn(conn net.Conn, maxBufBytes ...int) *TeeConn

func (*TeeConn) Buffered added in v0.30.4

func (t *TeeConn) Buffered() []byte

func (*TeeConn) Close added in v0.30.4

func (t *TeeConn) Close() error

func (*TeeConn) ExtractAndReset added in v0.30.4

func (t *TeeConn) ExtractAndReset() []byte

func (*TeeConn) LocalAddr added in v0.30.4

func (t *TeeConn) LocalAddr() net.Addr

func (*TeeConn) Read added in v0.30.4

func (t *TeeConn) Read(p []byte) (n int, err error)

func (*TeeConn) Release added in v0.30.4

func (t *TeeConn) Release() (net.Conn, []byte)

func (*TeeConn) RemoteAddr added in v0.30.4

func (t *TeeConn) RemoteAddr() net.Addr

func (*TeeConn) ResetBuffer added in v0.30.4

func (t *TeeConn) ResetBuffer()

func (*TeeConn) SetDeadline added in v0.30.4

func (t *TeeConn) SetDeadline(deadline time.Time) error

func (*TeeConn) SetReadDeadline added in v0.30.4

func (t *TeeConn) SetReadDeadline(deadline time.Time) error

func (*TeeConn) SetWriteDeadline added in v0.30.4

func (t *TeeConn) SetWriteDeadline(deadline time.Time) error

func (*TeeConn) StopAndClean added in v0.30.4

func (t *TeeConn) StopAndClean()

func (*TeeConn) StopBuffering added in v0.30.4

func (t *TeeConn) StopBuffering()

func (*TeeConn) Write added in v0.30.4

func (t *TeeConn) Write(p []byte) (n int, err error)

type TlsConn added in v0.26.48

type TlsConn struct {
	*tls.Conn
	// contains filtered or unexported fields
}

func NewTlsConn added in v0.26.48

func NewTlsConn(rawConn net.Conn, timeout time.Duration, tlsConfig *tls.Config) (*TlsConn, error)

func (*TlsConn) Close added in v0.26.48

func (c *TlsConn) Close() error

func (*TlsConn) GetRawConn added in v0.26.48

func (c *TlsConn) GetRawConn() net.Conn

func (*TlsConn) LocalAddr added in v0.26.48

func (c *TlsConn) LocalAddr() net.Addr

func (*TlsConn) Read added in v0.26.48

func (c *TlsConn) Read(b []byte) (n int, err error)

func (*TlsConn) RemoteAddr added in v0.26.48

func (c *TlsConn) RemoteAddr() net.Addr

func (*TlsConn) SetDeadline added in v0.26.48

func (c *TlsConn) SetDeadline(t time.Time) error

func (*TlsConn) SetReadDeadline added in v0.26.48

func (c *TlsConn) SetReadDeadline(t time.Time) error

func (*TlsConn) SetWriteDeadline added in v0.26.48

func (c *TlsConn) SetWriteDeadline(t time.Time) error

func (*TlsConn) Write added in v0.26.48

func (c *TlsConn) Write(b []byte) (n int, err error)

type WsConn added in v0.28.3

type WsConn struct {
	*websocket.Conn
	RealIP string
	// contains filtered or unexported fields
}

func NewWsConn added in v0.28.3

func NewWsConn(ws *websocket.Conn) *WsConn

func (*WsConn) Close added in v0.28.3

func (c *WsConn) Close() error

func (*WsConn) LocalAddr added in v0.28.3

func (c *WsConn) LocalAddr() net.Addr

func (*WsConn) Read added in v0.28.3

func (c *WsConn) Read(p []byte) (int, error)

func (*WsConn) RemoteAddr added in v0.28.3

func (c *WsConn) RemoteAddr() net.Addr

func (*WsConn) SetDeadline added in v0.28.3

func (c *WsConn) SetDeadline(t time.Time) error

func (*WsConn) SetReadDeadline added in v0.28.3

func (c *WsConn) SetReadDeadline(t time.Time) error

func (*WsConn) SetWriteDeadline added in v0.28.3

func (c *WsConn) SetWriteDeadline(t time.Time) error

func (*WsConn) Write added in v0.28.3

func (c *WsConn) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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