summaryrefslogtreecommitdiff
path: root/src/p2p.h
diff options
context:
space:
mode:
authorPancakeTAS <pancake@mgnet.work>2026-06-13 14:47:53 +0200
committerPancakeTAS <pancake@mgnet.work>2026-06-14 16:26:34 +0200
commit5781d6a312db5389a089abac127339a9ff5de696 (patch)
tree327366db23026636ba9b81700fb6e90eab432228 /src/p2p.h
parent(initial commit) (diff)
feat: Implement peer-to-peer(ish) socket handshake
This isn't entirely "peer-to-peer", because one side requires a publicly accessible port. The primary usecase for this is to establish connections to an endpoint, when there are several non-deterministic paths available on the client side.
Diffstat (limited to '')
-rw-r--r--src/p2p.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/p2p.h b/src/p2p.h
new file mode 100644
index 0000000..20fee9b
--- /dev/null
+++ b/src/p2p.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+
+#pragma once
+
+#include <netinet/in.h>
+#include <stdint.h>
+
+//
+// This module implements a peer-to-peer(ish) UDP connection where one side binds
+// a port and waits for the other side to connect from a specific IP address.
+//
+// Both sockets have IP_PMTUDISC_DO set, meaning packets larger than the
+// path MTU will be dropped or fail with EMSGSIZE.
+//
+
+/// Bind to a UDP port and wait for handshake from the specified ip.
+/// Returns sockfd on success, -1 on failure (errno is set).
+int p2p_bind(uint16_t port, in_addr_t ip);
+
+/// Connect to a peer-to-peer UDP socket. Timeout is in milliseconds.
+/// Returns sockfd on success, -1 on failure (errno is set).
+int p2p_connect(uint16_t port, in_addr_t ip, int timeout);