Documentation
¶
Index ¶
- Variables
- func WrapTLS(conn net.Conn, cfg *tls.Config) (net.Conn, error)
- type Action
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Connect() error
- func (c *Conn) GenLogMsg() *log.LogMessage
- func (c *Conn) IsOpen() bool
- func (c *Conn) Listen()
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) Reconnect() error
- func (c *Conn) ReconnectOrClose() error
- func (c *Conn) Register(action Action, fn HandlerFunc)
- func (c *Conn) RegisterLogger(l *log.Logger)
- func (c *Conn) SafeWrite(b []byte) error
- func (c *Conn) String() string
- func (c *Conn) Write(b []byte) (int, error)
- type ConnConfig
- type ConnState
- type HandlerFunc
- type Header
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidHeader = errors.New("invalid packet header") ErrPayloadTooLarge = errors.New("payload too large") ErrInvalidAction = errors.New("invalid action") ErrConnectionClosed = errors.New("connection closed") ErrConnectionNotEstablished = errors.New("connection not established") ErrConnectionAlreadyReconnecting = errors.New("connection already reconnecting") ErrConnectionTLSUpgradeFailed = errors.New("tls upgrade failed") ErrExhaustedReconnectAttempts = errors.New("exhausted reconnect attempts") )
View Source
var DefaultConnHandlers = map[Action]HandlerFunc{ ActionPing: func(c *Conn, header Header, r io.Reader) { if err := c.sendPong(); err != nil { c.GenLogMsg().Error().Msgf("failed to send pong: %v", err).Send() } }, ActionPong: func(c *Conn, header Header, r io.Reader) { select { case c.pongCh <- struct{}{}: default: } }, }
View Source
var ErrAddressRequired = errors.New("address is required")
View Source
var ErrTLSMissingConfig = errors.New("tls config is required")
Functions ¶
Types ¶
type Action ¶
type Action uint8
The header byte denoting the type of the message
const ( ActionInvalid Action = iota ActionAck // Generic ACK ActionError // Error message // Control & lifecycle ActionPing // Keepalive & healthcheck ActionPong // Response to ping ActionHello // Initial handshake (agent info) ActionGoodbye // Disconnect notification // Config management ActionRequestConfig // Agent asking for config ActionPushConfig // Daemon pushing config // File transfers ActionSendFile // Agent uploads file (e.g., flag, log) ActionRequestLogs // Daemon requests logs from agent ActionSendFileChunk // (Optional) Chunked file part // Status and logs ActionPushStatus // Agent pushes status update ActionRequestStatus // Server requests current status )
type Conn ¶
type Conn struct {
Config *ConnConfig
ReadDone chan struct{} // closes when reading is done
// contains filtered or unexported fields
}
func DailWithRetry ¶
func DailWithRetry(cfg *ConnConfig) (*Conn, error)
func NewConn ¶
func NewConn(cfg *ConnConfig) *Conn
func NewConnWithRaw ¶
func NewConnWithRaw(raw net.Conn, cfg *ConnConfig) *Conn
func (*Conn) GenLogMsg ¶
func (c *Conn) GenLogMsg() *log.LogMessage
func (*Conn) ReconnectOrClose ¶
func (*Conn) Register ¶
func (c *Conn) Register(action Action, fn HandlerFunc)
func (*Conn) RegisterLogger ¶
Otherwise uses the default logger
type ConnConfig ¶
type ConnConfig struct {
Address string // The address to connect to
Name string // The name of the connection. This only really holds significance in logs.
UseTLS bool
TLSConfig *tls.Config
AutoReconnect bool
MaxReconnectionAttempts int
ReconnectionDelay time.Duration // The amount of time to wait between reconnection attempts
HeartbeatInterval time.Duration // The interval at which to send pings. Set to 0 to disable.
MessageSendTimeout time.Duration // The maximum amount of time to wait for a message to be sent
MessageRecvTimeout time.Duration // The maximum amount of time to wait for a message to be received
MaxHeaderSize uint
MaxMessageSize uint
Handlers map[Action]HandlerFunc // The handlers to use for each action
}
func DefaultConnConfig ¶
func DefaultConnConfig(address, name string, tlsCfg *tls.Config) *ConnConfig
func (*ConnConfig) Validate ¶
func (c *ConnConfig) Validate() error
type Header ¶
The packet header
func UnmarshalHeader ¶
func (*Header) MarshalBytes ¶
func (*Header) UnmarshalBytes ¶
Click to show internal directories.
Click to hide internal directories.