Documentation
¶
Index ¶
Constants ¶
const ( FlagSYN uint8 = 0x1 FlagACK uint8 = 0x2 FlagFIN uint8 = 0x4 FlagRST uint8 = 0x8 )
Flags (4 bits, stored in lower nibble of first byte alongside version)
const ( ProtoStream uint8 = 0x01 // Reliable, ordered (TCP-like) ProtoDatagram uint8 = 0x02 // Unreliable, unordered (UDP-like) ProtoControl uint8 = 0x03 // Internal control )
Protocol types
const ( PortPing uint16 = 0 PortControl uint16 = 1 PortEcho uint16 = 7 PortNameserver uint16 = 53 PortHTTP uint16 = 80 PortSecure uint16 = 443 PortStdIO uint16 = 1000 PortDataExchange uint16 = 1001 PortEventStream uint16 = 1002 )
Well-known ports
const ( PortReservedMax uint16 = 1023 PortRegisteredMax uint16 = 49151 PortEphemeralMin uint16 = 49152 PortEphemeralMax uint16 = 65535 )
Port ranges
const ( BeaconMsgDiscover byte = 0x01 BeaconMsgDiscoverReply byte = 0x02 BeaconMsgPunchRequest byte = 0x03 BeaconMsgPunchCommand byte = 0x04 BeaconMsgRelay byte = 0x05 BeaconMsgRelayDeliver byte = 0x06 BeaconMsgSync byte = 0x07 // gossip: beacon-to-beacon node list exchange )
Beacon message types (single-byte codes, all < 0x10 to avoid collision with tunnel magic)
const AddrSize = 6 // 48 bits: 2 bytes network + 4 bytes node
const PortHandshake uint16 = 444
Well-known port for handshake requests
const Version uint8 = 1
Protocol version
Variables ¶
var ( AddrZero = Addr{0, 0} AddrRegistry = Addr{0, 1} AddrBeacon = Addr{0, 2} AddrNameserver = Addr{0, 3} )
var ( ErrNodeNotFound = errors.New("node not found") ErrNetworkNotFound = errors.New("network not found") ErrConnClosed = errors.New("connection closed") ErrConnRefused = errors.New("connection refused") ErrDialTimeout = errors.New("dial timeout") ErrChecksumMismatch = errors.New("checksum mismatch") )
Sentinel errors shared across packages.
var TunnelMagic = [4]byte{0x50, 0x49, 0x4C, 0x54}
Tunnel magic bytes: "PILT" (0x50494C54)
var TunnelMagicAuthEx = [4]byte{0x50, 0x49, 0x4C, 0x41}
Tunnel magic bytes for authenticated key exchange: "PILA" (0x50494C41)
var TunnelMagicKeyEx = [4]byte{0x50, 0x49, 0x4C, 0x4B}
Tunnel magic bytes for key exchange: "PILK" (0x50494C4B)
var TunnelMagicPunch = [4]byte{0x50, 0x49, 0x4C, 0x50}
Tunnel magic bytes for NAT punch packet: "PILP" (0x50494C50)
var TunnelMagicSecure = [4]byte{0x50, 0x49, 0x4C, 0x53}
Tunnel magic bytes for encrypted packets: "PILS" (0x50494C53)
Functions ¶
func PacketHeaderSize ¶
func PacketHeaderSize() int
Types ¶
type Addr ¶
Addr is a 48-bit Pilot Protocol virtual address. Layout: [16-bit Network ID][32-bit Node ID] Text format: N:NNNN.HHHH.LLLL
N = network ID in decimal NNNN = network ID in hex (redundant, for readability) HHHH = node ID high 16 bits in hex LLLL = node ID low 16 bits in hex
func BroadcastAddr ¶
BroadcastAddr returns the broadcast address for a given network.
func UnmarshalAddr ¶
UnmarshalAddr reads a 6-byte address from buf.
func (Addr) IsBroadcast ¶
type Packet ¶
type Packet struct {
Version uint8
Flags uint8
Protocol uint8
Src Addr
Dst Addr
SrcPort uint16
DstPort uint16
Seq uint32
Ack uint32
Window uint16 // advertised receive window (in segments; 0 = no limit)
Payload []byte
}
type SocketAddr ¶
SocketAddr is a full endpoint: virtual address + port.
func ParseSocketAddr ¶
func ParseSocketAddr(s string) (SocketAddr, error)
ParseSocketAddr parses "N:XXXX.YYYY.YYYY:PORT".
func (SocketAddr) String ¶
func (sa SocketAddr) String() string