2 # PEX - Peer Endpoint eXchange protocol
13 - version: always 0 for now
14 - opcode: message type
18 All multi-byte integer fields are in big-endian byte order.
19 Peer identifiers contain the first 8 bytes of the public key
23 ### opcode=0: PEX_MSG_HELLO
25 Payload (single item):
29 uint8_t local_addr[16];
32 - local_addr: Local IPv4 or IPv6 address used for connecting to the remote endpoint
34 Bit 0: local_addr is an IPv6 address
36 Sent after any successful handshake.
38 ### opcode=1: PEX_MSG_NOTIFY_PEERS
40 Used to send information about one or more peers, either proactively, or as a response to PEX_MSG_QUERY
44 struct pex_peer_endpoint {
47 uint8_t peer_id[PEX_ID_LEN];
52 - addr: IPv4 or IPv6 endpoint address
55 Bit 0: addr is an IPv6 address
56 Bit 1: addr refers to the local network address of the peer
58 ### opcode=2: PEX_MSG_QUERY
60 Used to ask for the endpoint address of one or more peers. Expects a PEX_MSG_NOTIFY_PEERS response, but only if there is known data about any of the queried peers.
66 For any peer in the payload list that has a known endpoint address, compare the IP address against the endpoint address of the sender of this message.
67 If the IP address matches, send back the local address of the peer (from the PEX_MSG_HELLO message) instead of the discovered wireguard endpoint address. This helps with establishing a direct connection through double-NAT.
69 ### opcode=3: PEX_MSG_PING
71 Used to ping a peer (to keep the connection alive).
74 ### opcode=4: PEX_MSG_PONG
76 Response to PEX_MSG_PING.