protocol

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

core/protocol/protocol.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProtocol

func RegisterProtocol(name string, factory ProtocolFactory)

RegisterProtocol registers a Protocol plugin.

Types

type Protocol

type Protocol interface {
	// Name returns the name of the plugin.
	Name() string

	// ParamName returns the name of the plugin's parameter, used for configuration.
	ParamName() string

	// Init initializes the protocol plugin. param is the ProtocolParam string configured by the user.
	// Returns an error if initialization fails.
	Init(param string) error

	// Obfuscate modifies internal protocol fields before data is sent (encrypted/encapsulated).
	// data is ProtocolData, context provides context information.
	// Returns the modified data. If an error is returned, the operation should be aborted.
	Obfuscate(data ProtocolData, context ProtocolContext) (ProtocolData, error)

	// Deobfuscate restores internal protocol fields after data is received (decrypted/de-encapsulated).
	// data is ProtocolData, context provides context information.
	// Returns the restored data. If an error is returned, the operation should be aborted.
	Deobfuscate(data ProtocolData, context ProtocolContext) (ProtocolData, error)
}

Protocol is the interface that protocol plugins must implement. It provides methods to modify data before encryption/encapsulation and to restore data after decryption.

func NewProtocol

func NewProtocol(name string, param string) (Protocol, error)

NewProtocol creates a Protocol instance based on its name and parameters.

type ProtocolContext

type ProtocolContext struct {
	// Type indicates the type of data being operated on, e.g., "tcp_request", "udp_message", "auth_request", "auth_response"
	// Plugins can use this field for type assertion.
	Type string

	// IsClient indicates whether the current operation is happening on the client side (true for client, false for server).
	IsClient bool

	// PeerAddr is the network address of the peer.
	PeerAddr net.Addr

	// SessionID is only valid for UDP messages.
	SessionID uint32

	// StreamID is only valid for TCP Streams (QUIC Streams).
	StreamID uquic.StreamID
}

ProtocolContext provides information about the current operation context.

type ProtocolData

type ProtocolData interface{}

ProtocolData is a generic abstraction for data that protocol plugins can operate on. The specific type is asserted by the plugin based on the Context's Type field.

type ProtocolFactory

type ProtocolFactory func() Protocol

ProtocolFactory is a function type for creating Protocol instances.

Jump to

Keyboard shortcuts

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