protocol

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthMethod         protocol.ID = basePath + "/auth/"
	GetStatusMethod    protocol.ID = basePath + "/status/"
	TunnelPacketMethod protocol.ID = basePath + "/tunnel/"
	Socks5PacketMethod protocol.ID = basePath + "/socks5/"
	Socks5NoAuthMethod protocol.ID = basePath + "/socks5-noauth/"
)
View Source
const (
	// MaxAuthMessageSize limits AuthPeer and AuthPeerResponse. An auth request
	// comes from any node before we trust it, so the limit is kept small; the
	// messages are well under 1 KiB today.
	MaxAuthMessageSize = 64 << 10
	// MaxStatusMessageSize limits PeerStatusInfo, accepted from known peers only.
	MaxStatusMessageSize = 512 << 10
)

Size limits for a single message, checked on receive. A message that outgrows its limit needs a new protocol: older peers would reject it.

View Source
const MaxNameLength = 100

MaxNameLength is the longest name a peer can give itself, in characters, as the API allows it.

Variables

View Source
var ErrMessageTooLarge = errors.New("message too large")

ErrMessageTooLarge is returned when an incoming message exceeds its size limit.

Functions

func AppendPacketToBuf added in v0.15.0

func AppendPacketToBuf(buf, packet []byte, dir vpn.GatewayDir) []byte

AppendPacketToBuf appends a length-prefixed tunnel packet to buf. The high bits of the length prefix encode dir; see ReadPacketHeader.

func IsUnsafeNameRune added in v0.20.0

func IsUnsafeNameRune(r rune) bool

IsUnsafeNameRune reports whether r must not be part of a name shown to the user: a control character, or one that changes the direction of the text around it (U+202A–U+202E, U+2066–U+2069) and so can make a name read as another one. The rest of the format characters are fine: U+200D, for one, joins emoji.

func NormalizeName added in v0.20.0

func NormalizeName(name string) string

NormalizeName makes a name that came from a peer safe to show: it drops unsafe characters, trims spaces and cuts the name to MaxNameLength.

func ReadPacketHeader added in v0.18.0

func ReadPacketHeader(stream io.Reader) (size uint64, dir vpn.GatewayDir, err error)

ReadPacketHeader reads an 8-byte tunnel packet header from the stream and returns the body size and the gateway direction encoded in the high bits. Both direction bits set is rejected as a protocol error.

func SendAuth

func SendAuth(stream io.Writer, authPeer AuthPeer) error

func SendAuthResponse

func SendAuthResponse(stream io.Writer, response AuthPeerResponse) error

func SendStatus

func SendStatus(stream io.Writer, statusInfo PeerStatusInfo) error

Types

type AuthPeer

type AuthPeer struct {
	Name string
	// Token is the secret from an invite link, presented by the peer that
	// redeems it. A valid token means the request is accepted automatically.
	//
	// Additive and backwards compatible: ReceiveAuth decodes without
	// DisallowUnknownFields, so an older awl ignores the field and falls back to
	// a manual accept, and a request from an older awl simply has none.
	//
	// The token must not leak outside this handshake: it travels over the
	// encrypted libp2p transport and AuthStreamHandler clears it before the
	// request is stored or emitted. entity.AuthRequest embeds this struct, so
	// the field is always empty there and swagger does not advertise it —
	// json:"-" is not an option, it would drop the token from the wire too.
	Token string `json:",omitempty" swaggerignore:"true"`
}

func ReceiveAuth

func ReceiveAuth(stream io.Reader) (AuthPeer, error)

type AuthPeerResponse

type AuthPeerResponse struct {
	// Confirmed means the sender is in our KnownPeers. The sender takes it as a
	// confirmation and stops retrying.
	Confirmed bool
	// Declined means we have blocked the sender. It outranks Confirmed: a peer
	// can be in KnownPeers and BlockedPeers at once.
	Declined bool
}

AuthPeerResponse is the answer to an auth request: where the sender stands with us. Both false means the request is waiting for a manual accept.

func ReceiveAuthResponse

func ReceiveAuthResponse(stream io.Reader) (AuthPeerResponse, error)

type PeerStatusInfo

type PeerStatusInfo struct {
	Name                 string
	Declined             bool
	AllowUsingAsExitNode bool
	// VPNGatewayServerEnabled mirrors VPNGatewayConfig.ServerEnabled on the
	// sender. The receiver stores it in KnownPeer.RemoteVPNGatewayServerEnabled
	// and uses KnownPeer.CanUseAsVPNGateway() to decide whether the
	// peer is a valid VPN gateway target.
	VPNGatewayServerEnabled bool
	IPv6Addr                string `json:"ipv6Addr,omitempty"`
}

func ReceiveStatus

func ReceiveStatus(stream io.Reader) (PeerStatusInfo, error)

Jump to

Keyboard shortcuts

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