From 5781d6a312db5389a089abac127339a9ff5de696 Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Sat, 13 Jun 2026 14:47:53 +0200 Subject: 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. --- src/p2p.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/p2p.h (limited to 'src/p2p.h') 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 +#include + +// +// 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); -- cgit v1.3.1