From ed33f4e1c82fb2c21e0b60f457d1e3404be34980 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 25 Feb 2025 20:17:13 -0500 Subject: spec: Add initial P2P sources Signed-off-by: Ian Moffett --- lib/include/defs.h | 3 +++ lib/include/net/stpsession.h | 50 +++++++++++++++++++++++++++++++++++++++++++- lib/include/otconfig.h | 1 + lib/include/server.h | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) (limited to 'lib/include') diff --git a/lib/include/defs.h b/lib/include/defs.h index a15a2fd..d4a57a9 100644 --- a/lib/include/defs.h +++ b/lib/include/defs.h @@ -58,4 +58,7 @@ /* Fixed paths */ #define OSMORA_TRUST "/etc/ostp/trusted_users.osmt" +/* Maximum length of an IP */ +#define IP_LEN_MAX 46 + #endif 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 { @@ -76,6 +88,42 @@ struct session_request { uint8_t pad[8]; } 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. diff --git a/lib/include/otconfig.h b/lib/include/otconfig.h index 96cac38..e8400b1 100644 --- a/lib/include/otconfig.h +++ b/lib/include/otconfig.h @@ -34,6 +34,7 @@ #define DIAGNOSTIC 0 /* 1 for verbosity */ #define CONNECTION_TIMEOUT 60 /* In seconds */ #define ENABLE_MOTD 1 /* Enable message of the day */ +#define ENABLE_P2P 1 /* Enable peer-to-peer sessions */ #define ARBITRATION_MAX 5 /* Maximum number of arbitration attempts */ #define REQUIRE_USER_AUTH 1 /* 1: true, 0: false */ #define OSTP_PORT 5352 diff --git a/lib/include/server.h b/lib/include/server.h index c8eff9c..33d2b7e 100644 --- a/lib/include/server.h +++ b/lib/include/server.h @@ -40,6 +40,7 @@ struct ostp_client { struct ostp_session session; + char host[IP_LEN_MAX]; int sockfd; pthread_t td; volatile uint8_t authed : 1; -- cgit v1.2.3