connection

package
v0.0.0-...-7a23388 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_CONN = iota
	TYPE_CONN_OPENSSL
	TYPE_CONN_TLS
)
View Source
const (
	CMD_NOP = iota
	CMD_DATA
	CMD_CLOSE
)

Variables

View Source
var KTLSClientPostHandshakeReadMaxBytes = 64 * 1024

KTLSClientPostHandshakeReadMaxBytes caps buffered app data during ticket drain.

View Source
var KTLSClientPostHandshakeTimeout = 10 * time.Millisecond

KTLSClientPostHandshakeTimeout is the max time to wait for TLS1.3 tickets.

View Source
var KTLSDisableSessionTickets = false

KTLSDisableSessionTickets disables TLS session tickets when kTLS is enabled.

View Source
var KTLSEnableRX = false

KTLSEnableRX controls whether kTLS RX is enabled.

View Source
var KTLSForceTLS13AESGCM = true

KTLSForceTLS13AESGCM restricts TLS1.3 cipher suites to AES-GCM.

View Source
var KTLSPreferTLS12IfNoAESGCM = true

KTLSPreferTLS12IfNoAESGCM forces TLS1.2 when client doesn't advertise TLS1.3 AES-GCM.

View Source
var TlsHandshakeTimeout = 1 * time.Second

Functions

func SetTLSEngine

func SetTLSEngine(engine TLSEngine)

Types

type ATLSConn

type ATLSConn struct {
	Base

	Conn *tls.Conn
	// contains filtered or unexported fields
}

ATLSConn is a non-blocking async TLS connection integrated with the event loop. The TLS handshake is completed before the connection is added to the loop.

func NewATLSConnClient

func NewATLSConnClient(ctx context.Context, fd int, cfg *tls.Config) (*ATLSConn, error)

func NewATLSConnServer

func NewATLSConnServer(ctx context.Context, fd int, cfg *tls.Config) (*ATLSConn, error)

func NewPendingTLSServerConn

func NewPendingTLSServerConn(fd int, cfg *tls.Config, local, remote net.Addr) (*ATLSConn, error)

func NewTLSConnClient

func NewTLSConnClient(ctx context.Context, fd int, cfg *tls.Config) (*ATLSConn, error)

func NewTLSConnServer

func NewTLSConnServer(ctx context.Context, fd int, cfg *tls.Config) (*ATLSConn, error)

func (*ATLSConn) AcceptLoopID

func (c *ATLSConn) AcceptLoopID() int

func (*ATLSConn) BufferedPlaintextLen

func (c *ATLSConn) BufferedPlaintextLen() int

func (*ATLSConn) Close

func (c *ATLSConn) Close() error

func (*ATLSConn) CompleteServerHandshake

func (c *ATLSConn) CompleteServerHandshake() error

func (*ATLSConn) ConnectionState

func (c *ATLSConn) ConnectionState() tls.ConnectionState

func (*ATLSConn) Destroy

func (c *ATLSConn) Destroy()

func (*ATLSConn) FlushN

func (c *ATLSConn) FlushN(maxBytes int) (int, error)

func (*ATLSConn) GetLocalAddr

func (c *ATLSConn) GetLocalAddr() string

func (*ATLSConn) GetRemoteAddr

func (c *ATLSConn) GetRemoteAddr() string

func (*ATLSConn) GetType

func (c *ATLSConn) GetType() int

func (*ATLSConn) HandshakeAt

func (c *ATLSConn) HandshakeAt() time.Time

func (*ATLSConn) IsKTLS

func (c *ATLSConn) IsKTLS() bool

func (*ATLSConn) IsKTLSRX

func (c *ATLSConn) IsKTLSRX() bool

func (*ATLSConn) LocalAddr

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

func (*ATLSConn) OnData

func (c *ATLSConn) OnData(in *[]byte) (out []byte, close bool)

func (*ATLSConn) Open

func (c *ATLSConn) Open()

func (*ATLSConn) ParsePacket

func (c *ATLSConn) ParsePacket(in *[]byte) (length, expect int)

func (*ATLSConn) PendingWrite

func (c *ATLSConn) PendingWrite() int

func (*ATLSConn) Read

func (c *ATLSConn) Read(b []byte) (int, error)

func (*ATLSConn) RemoteAddr

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

func (*ATLSConn) SetAcceptLoopID

func (c *ATLSConn) SetAcceptLoopID(loopID int)

func (*ATLSConn) SetCloseCB

func (c *ATLSConn) SetCloseCB(cb CloseCb)

func (*ATLSConn) SetDeadline

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

func (*ATLSConn) SetLocal

func (c *ATLSConn) SetLocal(addr net.Addr)

func (*ATLSConn) SetOpenCB

func (c *ATLSConn) SetOpenCB(cb OpenCb)

func (*ATLSConn) SetReadDeadline

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

func (*ATLSConn) SetRemote

func (c *ATLSConn) SetRemote(addr net.Addr)

func (*ATLSConn) SetWriteDeadline

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

func (*ATLSConn) Write

func (c *ATLSConn) Write(b []byte) (int, error)

type AppConn

type AppConn interface {
	ID() uint64
	Context() interface{}
	SetContext(interface{})

	Close() error
	AddCmd(cmd int, data []byte) error

	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	GetLocalAddr() string
	GetRemoteAddr() string
	IsClient() bool
}

AppConn is the application-facing connection surface. Keep this interface narrow for handlers/business code.

type Base

type Base struct {
	Client bool
	// contains filtered or unexported fields
}

Conn ...

func (*Base) AcceptAddr

func (c *Base) AcceptAddr() string

func (*Base) AddCmd

func (c *Base) AddCmd(cmd int, data []byte) error

func (*Base) Context

func (c *Base) Context() interface{}

func (*Base) EnqueueWrite

func (c *Base) EnqueueWrite(buf []byte, size int)

EnqueueWrite enqueues a buffer for writev flush.

func (*Base) Fd

func (c *Base) Fd() int

func (*Base) GetLastRecv

func (c *Base) GetLastRecv() int64

func (*Base) GetListenerEndpoint

func (c *Base) GetListenerEndpoint() interface{}

func (*Base) GetPktHandler

func (c *Base) GetPktHandler() IPktHandler

func (*Base) GetRecv

func (c *Base) GetRecv(reset bool) int32

func (*Base) GetSend

func (c *Base) GetSend(reset bool) int32

func (*Base) ID

func (c *Base) ID() uint64

func (*Base) IsClient

func (c *Base) IsClient() bool

func (*Base) LoopID

func (c *Base) LoopID() int

func (*Base) PendingWrite

func (c *Base) PendingWrite() int

PendingWrite returns total pending bytes in the write queue.

func (*Base) Recvbuf

func (c *Base) Recvbuf() *ringbuffer.RingBuffer

func (*Base) SetAcceptAddr

func (c *Base) SetAcceptAddr(addr string)

func (*Base) SetContext

func (c *Base) SetContext(itf interface{})

func (*Base) SetFd

func (c *Base) SetFd(fd int)

func (*Base) SetID

func (c *Base) SetID(id uint64)

func (*Base) SetLastRecv

func (c *Base) SetLastRecv(ts int64)

func (*Base) SetListenerEndpoint

func (c *Base) SetListenerEndpoint(ep interface{})

func (*Base) SetLoopID

func (c *Base) SetLoopID(loopID int)

func (*Base) SetPktHandler

func (c *Base) SetPktHandler(h IPktHandler)

func (*Base) SetReceiver

func (c *Base) SetReceiver(recv ICmdRecv)

func (*Base) SetRecvbuf

func (c *Base) SetRecvbuf(buf *ringbuffer.RingBuffer)

func (*Base) UpdatePktHandler

func (c *Base) UpdatePktHandler(h IPktHandler)

type CloseCb

type CloseCb interface {
	OnClose(interface{})
}

type Conn

type Conn struct {
	Base
	// contains filtered or unexported fields
}

Conn ...

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Destroy

func (c *Conn) Destroy()

func (*Conn) FlushN

func (c *Conn) FlushN(maxBytes int) (int, error)

func (*Conn) GetLocalAddr

func (c *Conn) GetLocalAddr() string

func (*Conn) GetRemoteAddr

func (c *Conn) GetRemoteAddr() string

func (*Conn) GetType

func (c *Conn) GetType() int

func (*Conn) LocalAddr

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

func (*Conn) OnData

func (c *Conn) OnData(in *[]byte) (out []byte, close bool)

func (*Conn) Open

func (c *Conn) Open()

func (*Conn) ParsePacket

func (c *Conn) ParsePacket(in *[]byte) (length, expect int)

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) RemoteAddr

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

func (*Conn) SetCloseCB

func (c *Conn) SetCloseCB(cb CloseCb)

func (*Conn) SetDeadline

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

func (*Conn) SetLocal

func (c *Conn) SetLocal(addr net.Addr)

func (*Conn) SetOpenCB

func (c *Conn) SetOpenCB(cb OpenCb)

func (*Conn) SetReadDeadline

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

func (*Conn) SetRemote

func (c *Conn) SetRemote(addr net.Addr)

func (*Conn) SetWriteDeadline

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

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

type EngineConn

type EngineConn interface {
	ProtoConn
	Fd() int
	LoopID() int
	Recvbuf() *ringbuffer.RingBuffer
	GetType() int
	FlushN(maxBytes int) (int, error)
	PendingWrite() int
	SetID(id uint64)
	SetLoopID(loopID int)
	SetReceiver(recv ICmdRecv)
	Destroy()

	SetAcceptAddr(string)

	Open()
	Read(b []byte) (int, error)
	Write(b []byte) (int, error)
	AcceptAddr() string
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
	SetRemote(addr net.Addr)
	SetLocal(addr net.Addr)

	ParsePacket(in *[]byte) (length, expect int)
	OnData(in *[]byte) (out []byte, close bool)

	EnqueueWrite(buf []byte, size int)
	GetSend(reset bool) int32
	GetRecv(reset bool) int32

	SetLastRecv(ts int64)
	GetLastRecv() int64

	SetListenerEndpoint(interface{})
	GetListenerEndpoint() interface{}
}

EngineConn is the full engine/internal connection surface. It should only be consumed by eventloop/engine internals.

type ICmdRecv

type ICmdRecv interface {
	AddCmd(cmd, fd int, dial bool, id uint64, data []byte) error
}

type IPktHandler

type IPktHandler interface {
	// ParsePacket returns:
	//   - length > 0: a complete packet of "length" bytes is available at (*in)[:length]
	//   - length == 0: need more data (partial packet)
	//   - length < 0: fatal parse error (connection will be closed)
	// expect is a hint of the expected total packet size (or -1 if unknown).
	ParsePacket(c ProtoConn, in *[]byte) (length, expect int)
	OnData(c ProtoConn, in *[]byte) (out []byte, close bool)
	Stat(bool)
}

type ITimerWatcher

type ITimerWatcher interface {
	AddTimer(t timer.ITimer) bool
	DelTimer(t timer.ITimer)
	RefreshTimer(t timer.ITimer) bool
}

type OpenCb

type OpenCb interface {
	OnOpen(interface{})
}

type ProtoConn

type ProtoConn interface {
	AppConn
	SetPktHandler(h IPktHandler)
	UpdatePktHandler(h IPktHandler)
	GetPktHandler() IPktHandler
}

ProtoConn is the protocol-facing connection surface. It extends AppConn with packet-handler routing APIs.

type TLSEngine

type TLSEngine int
const (
	TLSEngineATLS TLSEngine = iota
	TLSEngineKTLS
)

func GetTLSEngine

func GetTLSEngine() TLSEngine

func ResolveTLSEngine

func ResolveTLSEngine(requested string) TLSEngine

ResolveTLSEngine selects the effective TLS engine. requested values: "atls" (default) and "ktls".

Jump to

Keyboard shortcuts

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