smux

package module
v0.0.0-...-44432f3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 15 Imported by: 0

README

SMUX

  • 说明
  1. go 标准库net套接字编程
  2. 只做了简单的粘包处理
  3. 添加了tls双向认证
  4. 修改certfile.sh脚本中[ alt_names ]块设置服务端地址为服务的端地址
  5. 如果要动态扩容server节点, 则需要保证所有server节点和client节点基于相同的ca证书来进行证书签发

Documentation

Index

Constants

View Source
const (
	MsgHeadLen  = 4
	MaxBodySize = 10 * 1024 * 1024

	MsgReadTimeout  = 60 * time.Second
	MsgWriteTimeout = 60 * time.Second
)
View Source
const (
	KeyLength   = 32
	NonceLength = 16
	HMACLength  = 32
	PBKDF2Iter  = 100000
	MagicHeader = "ENC"
)

Variables

View Source
var SigKey = ""

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(address string, coder coder) *Client

func (*Client) Clean

func (c *Client) Clean()

func (*Client) RecvMessage

func (c *Client) RecvMessage() (Message, error)

func (*Client) SendMessage

func (c *Client) SendMessage(msg *Message) error

type Conn

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

func NewConn

func NewConn(conn net.Conn, coder coder) *Conn

func (*Conn) GetRemoteAddr

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

func (*Conn) RecvMessage

func (c *Conn) RecvMessage() (Message, error)

func (*Conn) SendMessage

func (c *Conn) SendMessage(msg *Message) error

type Handler

type Handler interface {
	Handle(conn *Conn) error
}

Handler 消息处理器接口

type HandlerFunc

type HandlerFunc func(conn *Conn) error

HandlerFunc 是一个适配器,允许普通函数作为Handler使用

func (HandlerFunc) Handle

func (fun HandlerFunc) Handle(conn *Conn) error

Handle 实现Handler接口

type JsonCode

type JsonCode struct{}

func (*JsonCode) Decode

func (c *JsonCode) Decode(data []byte) (Message, error)

func (*JsonCode) Encode

func (c *JsonCode) Encode(msg *Message) ([]byte, error)

type Message

type Message map[string]any

type Server

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

func NewServer

func NewServer(address string, coder coder) *Server

func (*Server) SetHandler

func (s *Server) SetHandler(handler Handler)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop()

Stop 停止服务器

type Signature

type Signature struct{}

func (Signature) Decrypt

func (s Signature) Decrypt(data []byte) ([]byte, error)

Decrypt 解密数据

func (Signature) Encrypt

func (s Signature) Encrypt(data []byte) ([]byte, error)

Encrypt 加密数据

Directories

Path Synopsis
example
client command
server command

Jump to

Keyboard shortcuts

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