protocol

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handshake

func Handshake(conn net.Conn, authenticator *auth.Authentication, enableAuth bool) (cipher crypto.SymmetricCipher, authKey auth.AES192Key, err error)

nil authenticator means no authentication,return nil authKey

func ReadReq

func ReadReq[T any](conn net.Conn, dataLen int, cipher ...crypto.SymmetricCipher) (T, error)

func SendHandshakeResp

func SendHandshakeResp(conn net.Conn, resp HandshakeResp) error

func SendHeartbeat

func SendHeartbeat(conn net.Conn, id string, cipher ...crypto.SymmetricCipher) error

func SendHeartbeatNoResp

func SendHeartbeatNoResp(conn net.Conn, cipher ...crypto.SymmetricCipher) error

func SendRelayStart

func SendRelayStart(conn net.Conn, cipher ...crypto.SymmetricCipher) error

func SendRespHeadError

func SendRespHeadError(conn net.Conn, action Action, msg string, cipher ...crypto.SymmetricCipher) error

func SendRespHeadOKWithMsg

func SendRespHeadOKWithMsg(conn net.Conn, action Action, msg string, cipher ...crypto.SymmetricCipher) error

func SendRespHeadOk

func SendRespHeadOk(conn net.Conn, action Action, cipher ...crypto.SymmetricCipher) error

Types

type Action

type Action string
const (
	ActionConnect Action = "connect"
	ActionPing    Action = "ping"
	ActionRelay   Action = "relay"
	// ActionClose is used to close the long connection
	ActionClose     Action = "close"
	ActionHeartbeat Action = "heartbeat"
)

type CommonReq

type CommonReq struct {
	ID string `json:"id"`
}

type ConnectionReq

type ConnectionReq struct {
	CommonReq
}

type HandshakeReq

type HandshakeReq struct {
	// SecretKeySelector is the selector of the secret key, 4 bytes use hex string(8 bytes in total)
	SecretKeySelector string `json:"secretKeySelector"`
	// AuthFieldB64 is encrypted with secret key,["AUTH"+RANDOM_STRING(16)]
	AuthFieldB64 string `json:"authFieldB64"`
	// AuthAAD is the additional authentication data
	AuthAAD string `json:"authAAD"`
	// EcdhPublicKey is the public key of the ECDH X25519 key exchange
	EcdhPublicKeyB64 string `json:"ecdhPublicKeyB64"`
}

func ReadHandshakeReq

func ReadHandshakeReq(conn net.Conn) (HandshakeReq, error)

type HandshakeResp

type HandshakeResp struct {
	// RandomSharedKeyB64 string `json:"randomSharedKey"`
	Code StatusCode `json:"code"`
	Msg  string     `json:"msg"`
	// EcdhPublicKey is the public key of the ECDH X25519 key exchange
	EcdhPublicKeyB64 string `json:"ecdhPublicKeyB64"`
}

type HeartbeatReq

type HeartbeatReq struct {
	CommonReq
	NeedResp bool `json:"needResp"`
}

type RelayReq

type RelayReq struct {
	CommonReq
}

type ReqHead

type ReqHead struct {
	Action  Action `json:"action"`
	DataLen int    `json:"dataLen"`
}

func ReadReqHead

func ReadReqHead(conn net.Conn, cipher crypto.SymmetricCipher) (ReqHead, error)

type RespHead

type RespHead struct {
	Code    StatusCode `json:"code"`
	Msg     string     `json:"msg"`
	Action  Action     `json:"action"`
	DataLen int        `json:"dataLen"`
}

type StatusCode

type StatusCode int32
const (
	StatusError      StatusCode = 0
	StatusSuccess    StatusCode = -1
	StatusAuthFailed StatusCode = 1
)

Jump to

Keyboard shortcuts

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