diff options
Diffstat (limited to 'lib/include/net/stpsession.h')
-rw-r--r-- | lib/include/net/stpsession.h | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/include/net/stpsession.h b/lib/include/net/stpsession.h index 731b8ce..9735678 100644 --- a/lib/include/net/stpsession.h +++ b/lib/include/net/stpsession.h @@ -46,6 +46,17 @@ /* Session Request option bits */ #define SESSION_REQ_USER BIT(0) +#define SESSION_REQ_P2P BIT(1) + +/* + * For ACKing/TRUNCing packets e.g., + * peer blocks + */ +#define ACK_WORD 0xAC7E +#define TRUNC_WORD 0x782C + +#define PB_N_PEERS 16 +#define PB_N_BLOCKS 16 /* * The Session Request is sent from the client to the @@ -63,11 +74,12 @@ * / * 0 1 2 3 4 5 6 * ~ ~ ~ ~ ~ ~ ~ - * U R R R R R R + * U P R R R R R * \ * Purpose * * U: User auth. + * P: Peer-to-peer. * R: Reserved, keep zero. */ struct session_request { @@ -77,6 +89,42 @@ struct session_request { } PACKED; /* + * The `peer' structure describes a peer on + * an OSTP server running in peer-to-peer mode. + * + * @pad: Must be all 1s, treat invalid otherwise + * @port: Port peer accepts connections on + * @host: Host peer is at + */ +struct peer { + uint8_t pad[1]; + uint16_t port; + char host[IP_LEN_MAX]; +}; + +/* + * If P2P is enabled and supported, the OCS + * sends one or more peer blocks in a consecutive + * manner. Each peer block can list up to 16 peers + * max. If the `seq' field is greater than zero and + * the list of peers within the current block is full, + * the client may either request the next peer block by + * sending an ACK packet or terminating the connection + * by sending a TRUNC packet. + * + * @peers: List of available peers within this block + * @seq: Descending one-based block sequence number (0=invalid) + */ +struct peer_block { + struct peer peers[PB_N_PEERS]; + uint8_t seq; +} PACKED; + +/* Peer/block counts must be powers of two */ +CTASSERT((PB_N_PEERS & 1) == 0, "PB_N_PEERS not power-of-two!"); +CTASSERT((PB_N_BLOCKS & 1) == 0, "PB_N_BLOCKS not power-of-two!"); + +/* * Structure containing user information * for password protected channels. */ |