Run the index
Start a small TCP coordination service reachable by both peers.
A small C library and CLI for exposing local TCP and UDP services through direct peer-to-peer tunnels.
A temporary TCP index coordinates registration, lookup, candidate exchange, and UDP hole punching. Application traffic travels directly between peers.
The shortest path from zero to a working TCP tunnel uses three processes: an index, a publisher, and a consumer.
Start a small TCP coordination service reachable by both peers.
Register a local service and wait for incoming peer sessions.
Expose the remote service through a local port on the consumer.
# index
redp2p idx 9876
# publisher: expose local TCP port 8080
redp2p pub web@idx.example.com:9876 --tcp 8080
# consumer: expose it locally on TCP port 9000
redp2p con web@idx.example.com:9876 --tcp 9000
Now a local connection to 127.0.0.1:9000 is bridged to the publisher's local TCP service on port 8080.
The index is coordination infrastructure, not a data plane. It helps two peers discover enough information to establish a direct UDP path, then application traffic stays between those peers.
The index uses TCP and stores only temporary coordination state.
redp2p idx 9876
redp2p idx 9876 --seats 128
redp2p idx 9876 --pow 20
TCP:
redp2p pub web@idx.example.com:9876 --tcp 8080
UDP:
redp2p pub game@idx.example.com:9876 --udp 7777
The identifier before @ is an arbitrary service label registered in the selected index. IDs may contain ASCII letters and digits.
Expose a remote TCP service on a local port:
redp2p con web@idx.example.com:9876 --tcp 9000
Expose a remote UDP service:
redp2p con game@idx.example.com:9876 --udp 9000
redp2p pub web@idx.example.com:9876 --tcp 8080 \
--stun stun:stun.cloudflare.com:3478
STUN discovers an externally visible endpoint. It does not relay application traffic and is not part of an established tunnel.
| Command / flag | Description |
|---|---|
idx <port> | Start an index server. |
idx <port> --seats <N> | Set total publisher seats. |
idx <port> --pow <N> | Set publisher registration proof-of-work cost. |
idx <port> --list | List active publisher IDs from the local index. |
idx <port> -l | Alias for --list. |
pub <id>@<index[:port]> --tcp <port> | Publish a local TCP service. |
pub <id>@<index[:port]> --udp <port> | Publish a local UDP service. |
con <id>@<index[:port]> --tcp <port> | Expose a remote TCP service locally. |
con <id>@<index[:port]> --udp <port> | Expose a remote UDP service locally. |
del <id>@<index[:port]> | Remove a published service. |
--sweep <N> | Set the bounded UDP port sweep range. |
--stun <url> | Enable optional STUN endpoint discovery. |
-h, --help | Show help and usage. |
-v, --version | Show build version. |
The public C API lives in libredp2p.h. Reusable behavior is implemented in the single src/libredp2p.c compilation unit.
#include "libredp2p.h"
redp2p_t *ctx = NULL;
if (redp2p_open(&ctx) == REDP2P_OK) {
redp2p_set_protocol(ctx, REDP2P_PROTO_TCP);
redp2p_set_port(ctx, 8080);
redp2p_wait(ctx, "idx.example.com", 9876, "web", 0);
redp2p_close(ctx);
}
Allocate a caller-owned context.
Run an index server.
Publish a local service and accept peer sessions.
Expose a remote service through a local bridge.
Remove one published service.
List active publisher IDs.
Request termination of a blocking operation.
Release the context and associated resources.
redp2p_options_default() returns initialized runtime options.redp2p_options_load_env() loads supported environment values.redp2p_options_free() releases option-owned allocations.redp2p_open() creates the context.serve_index, wait, or connect.redp2p_stop() requests termination.redp2p_close() releases the context.CLI flags override environment variables, which override built-in defaults.
REDP2P_PASS
REDP2P_VIP
REDP2P_POW
REDP2P_SEATS
REDP2P_SWEEP
REDP2P_STUN
REDP2P_PASS, REDP2P_VIP, and proof-of-work protect publisher registration and index capacity. They are not application authentication or peer identity.
RedP2P separates coordination from application transport.
Registration, lookup, listing, candidates, punching, temporary state.
Application traffic travels directly between peers through UDP.
Authentication, authorization, encryption, persistence and business rules stay outside.
The local application talks TCP to redp2p.c. The peer-to-peer path uses vendored KCP over UDP for ordering, acknowledgements, retransmission, congestion/window state and stream reconstruction.
UDP datagrams are transported directly and datagram boundaries are preserved. redp2p.c does not add ordering, retransmission, duplication suppression guarantees, or fragmentation of oversized application datagrams.
redp2p.c transports application traffic without defining the application's security model.
RedP2P is deliberately small. It is not an enterprise network platform or a universal NAT traversal system.
| Inside redp2p.c | Outside redp2p.c |
|---|---|
| Peer coordination | User accounts |
| Direct TCP/UDP tunneling | Application authorization |
| Candidate exchange | Application encryption |
| UDP hole punching | Permanent network database |
| Optional STUN discovery | TURN-style traffic relay |
| Temporary index state | Telemetry, billing, fleet management |
# current host
make
# tests
make test
# clean rebuild
make clean && make
Build artifacts are generated under bin/{arch}/{platform}/. Tests link dynamically against the generated shared library and run through CTest.
The implementation targets portable C11. Supported build targets include Linux, Windows, macOS, iOS, Android, and multiple CPU architectures. Cross-compilation does not imply equal runtime validation on every target.
make all
make x86_64/linux
make x86_64/windows
make x86_64/macos
make aarch64/linux
make aarch64/android
make armv7/linux
make riscv64/linux
make powerpc64le/linux
make s390x/linux