diff options
Diffstat (limited to 'src/p2p.h')
| -rw-r--r-- | src/p2p.h | 22 |
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); |
