import type { Metadata } from 'next'; import UDPHolePunchingDiagram from '@/components/diagrams/UDPHolePunchingDiagram'; import NATTraversalDiagram from '@/components/diagrams/NATTraversalDiagram'; import PeerDiscoveryDiagram from '@/components/diagrams/PeerDiscoveryDiagram'; export const metadata: Metadata = { title: 'How P2P Works - Understanding Peer-to-Peer Networking', description: 'Learn about peer-to-peer networking, UDP hole-punching, NAT traversal, and how P2NS uses these technologies.', keywords: ['P2P networking', 'peer-to-peer', 'UDP hole-punching', 'NAT traversal', 'Hyperswarm', 'DHT', 'Corestore', 'P2P explained'], authors: [{ name: 'Raven Scott' }], openGraph: { title: 'How P2P Works - Understanding Peer-to-Peer Networking', description: 'Learn about peer-to-peer networking, UDP hole-punching, NAT traversal, and how P2NS uses these technologies.', url: 'https://p2ns.space/learn/p2p', siteName: 'P2NS', type: 'website', }, twitter: { card: 'summary_large_image', title: 'How P2P Works - Understanding Peer-to-Peer Networking', description: 'Learn about peer-to-peer networking, UDP hole-punching, NAT traversal, and how P2NS uses these technologies.', }, alternates: { canonical: 'https://p2ns.space/learn/p2p', }, }; export default function P2PPage() { return (
Peer-to-peer (P2P) networking is a distributed architecture where participants (peers) share resources and communicate directly without relying on a central server. P2NS leverages P2P technology to create a resilient, decentralized DNS system.
Key Concept: In a P2P network, each node can act as both a client and a server, enabling direct communication and resource sharing between peers.
UDP hole-punching lets two peers behind NAT establish a direct path. In the Holepunch stack (used by Hyperswarm and Holesail), peers coordinate through HyperDHT—a distributed hash table—not a single central rendezvous server. When both sides use predictable NAT ports, most sessions connect directly; symmetric NAT or blocked UDP may fall back to encrypted relays.
Network Address Translation (NAT) is used by routers to share a single public IP address among multiple devices. NAT traversal techniques allow P2P connections to work through these devices.
Carrier-Grade NAT (CGNAT) adds an additional layer of NAT, making traversal even more complex. P2NS uses Holesail, which is specifically designed to handle these challenging scenarios.
Holesail implements advanced techniques including:
Hyperswarm is a high-level API on top of HyperDHT (Kademlia-style DHT). Peers announce and discover each other by 32-byte topics without a central directory server.
Topic-based discovery: P2NS hashes TOPIC_SEED (default p2ns-dns) with SHA-256 to form a 32-byte topic. Every node interested in the network joins that topic.
DHT lookup: HyperDHT returns peers that have announced on the topic. DHT results are candidates only—each connection still completes a Noise XX handshake so the remote party must prove key ownership.
Connection establishment: Hyperswarm coordinates UDP hole punching (and relay fallback when needed), then runs encrypted streams for Core RPC and plugin traffic.
Automatic Reconnection: Hyperswarm automatically handles peer churn, reconnecting when peers go offline and come back online.
P2NS uses the Holepunch stack in layers: raw UDP paths, then encryption, then application protocols.
Domain tunnels use Holesail (separate hashes on the DHT) for reaching services behind NAT; the P2NS swarm topic is only for DNS peer sync.
Corestore manages Hypercore append-only logs. Each block is Merkle-linked and signed with Ed25519, so peers verify data by proof—not by trusting who delivered it. P2NS stores domain claims and votes in this replicated log.
Autopass manages secure writer additions to the Corestore. It ensures only authorized peers can write to the ledger, preventing spam and attacks.
networkId per network (manifest)