aboutsummaryrefslogtreecommitdiff
path: root/lib/include
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-02-25 20:17:13 -0500
committerIan Moffett <ian@osmora.org>2025-02-25 20:21:27 -0500
commited33f4e1c82fb2c21e0b60f457d1e3404be34980 (patch)
treef75f14efdf654f81dfe566fc49295e340c486a78 /lib/include
parent833f064b8f4ee30b9f46bba654a99411cd6866d3 (diff)
spec: Add initial P2P sourcesp2p
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/include')
-rw-r--r--lib/include/defs.h3
-rw-r--r--lib/include/net/stpsession.h50
-rw-r--r--lib/include/otconfig.h1
-rw-r--r--lib/include/server.h1
4 files changed, 54 insertions, 1 deletions
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 {
@@ -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.
*/
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;