protocol

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

core/protocol/protocol.go

Index

Constants

View Source
const (
	// AuthAHeaderSize 定义了我们自定义头部的大小:CRC32 (4 字节) + 原始数据长度 (4 字节)
	AuthAHeaderSize = 8
)

Variables

This section is empty.

Functions

func RegisterProtocol

func RegisterProtocol(name string, factory ProtocolFactory)

RegisterProtocol registers a Protocol plugin.

Types

type AuthAProtocol added in v0.4.1

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

AuthAProtocol 实现了 protocol_ext.Protocol 接口

func (*AuthAProtocol) Deobfuscate added in v0.4.1

func (p *AuthAProtocol) Deobfuscate(data ProtocolData, ctx ProtocolContext) (ProtocolData, error)

Deobfuscate 反转混淆逻辑。

func (*AuthAProtocol) Init added in v0.4.1

func (p *AuthAProtocol) Init(param string) error

Init 初始化插件。

func (*AuthAProtocol) Name added in v0.4.1

func (p *AuthAProtocol) Name() string

Name 返回插件的名称。

func (*AuthAProtocol) Obfuscate added in v0.4.1

func (p *AuthAProtocol) Obfuscate(data ProtocolData, ctx ProtocolContext) (ProtocolData, error)

Obfuscate 施加混淆逻辑。

func (*AuthAProtocol) ParamName added in v0.4.1

func (p *AuthAProtocol) ParamName() string

ParamName 返回插件参数的名称。

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