<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Blog on Kévin Brault</title>
    <link>https://braultkevin.fr/blog/</link>
    <description>Recent content in Blog on Kévin Brault</description>
    <generator>Hugo</generator>
    <language>en</language>
    <managingEditor>contact@braultkevin.fr (BRAULT Kévin)</managingEditor>
    <webMaster>contact@braultkevin.fr (BRAULT Kévin)</webMaster>
    <lastBuildDate>Mon, 29 Dec 2025 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://braultkevin.fr/blog/index.xml" rel="self" type="application/rss+xml" />
    <image>
      <url>https://braultkevin.fr/favicon/favicon-512.png</url>
      <title>Kévin Brault</title>
      <link>https://braultkevin.fr/</link>
    </image>
    <item>
      <title>Why bootstrapping a peer-to-peer network without a directory is a mathematical utopia</title>
      <link>https://braultkevin.fr/blog/2025-12-29-why-bootstrapping-a-peer-to-peer-network-without-a-directory-is-a-mathematical-utopia/</link>
      <pubDate>Mon, 29 Dec 2025 00:00:00 +0000</pubDate><author>contact@braultkevin.fr (BRAULT Kévin)</author>
      <guid>https://braultkevin.fr/blog/2025-12-29-why-bootstrapping-a-peer-to-peer-network-without-a-directory-is-a-mathematical-utopia/</guid>
      <description><![CDATA[<p>I&rsquo;ve spent the last few weeks testing mesh LoRa hardware (Meshtastic nodes mostly).</p>
<p>On a Meshtastic mesh, discovery is almost free. Radio is a broadcast medium : a node transmits once and every other node within range hears it. There&rsquo;s nothing to guess, no address space to search. The only constraint is the proximity of each node.</p>
<p>At the same time, I&rsquo;m interested in peer-to-peer networks over the Internet and the transposition does impose quite a few constraints. There&rsquo;s no &ldquo;radio range&rdquo; on IP : two hosts a few meters apart and two hosts on opposite sides of the planet are equally reachable (or equally invisible actually) to each other. Reachability over the Internet is not a physical proximity constraint, it&rsquo;s a function of knowing an address that could be almost anything. Discovery becomes more about random guessing than a search within the area.</p>]]></description>
      <content:encoded><![CDATA[<p>I&rsquo;ve spent the last few weeks testing mesh LoRa hardware (Meshtastic nodes mostly).</p>
<p>On a Meshtastic mesh, discovery is almost free. Radio is a broadcast medium : a node transmits once and every other node within range hears it. There&rsquo;s nothing to guess, no address space to search. The only constraint is the proximity of each node.</p>
<p>At the same time, I&rsquo;m interested in peer-to-peer networks over the Internet and the transposition does impose quite a few constraints. There&rsquo;s no &ldquo;radio range&rdquo; on IP : two hosts a few meters apart and two hosts on opposite sides of the planet are equally reachable (or equally invisible actually) to each other. Reachability over the Internet is not a physical proximity constraint, it&rsquo;s a function of knowing an address that could be almost anything. Discovery becomes more about random guessing than a search within the area.</p>
<p>In a centralized network, peer discovery is easy : a directory, a tracker or a central authority tells where the network nodes are. But that comes at a cost : a single point of failure. For a network whose purpose is to resist censorship, a central server is an obvious target : block the directory&rsquo;s IP address and the entire network disappears. The promise of total decentralization is that peer discovery becomes as resilient as the network itself. A fully decentralized network has no central authority and delegates peer discovery to the peers themselves. But a node&rsquo;s ability to find another node with no intermediary is limited by two basic constraints : the size of the address space (the IP adress space) and how long nodes stay reachable. On the Internet, none of these constraints can be guaranteed.</p>
<p>Let&rsquo;s dig into it.</p>
<h2 id="the-address-space">
    <a class="heading-anchor" href="#the-address-space" aria-label="Link to this section">#</a>The address space
</h2>
<p>For an IPv4 network, the global address space is the set of all 32-bit binary vectors :</p>
$$A = \{0, 1\}^{32}$$<p>The total number of addressable addresses is:</p>
$$\lvert A \rvert = 2^{32} = 4\,294\,967\,296$$<p>Let $n$ be the number of active nodes belonging to the peer-to-peer network at a given time $t$. Define the network&rsquo;s density $\delta$ as the probability that a uniformly randomly sampled address belongs to the set of active peers:</p>
$$\delta = \frac{n}{\lvert A \rvert}$$<p>This is a simplified model : it assumes that peers are uniformly distributed across the IPv4 address space and that any address belonging to a peer is directly reachable. In practice, NAT, firewalls, ports, routing and service availability make the real situation even more complex.</p>
<p>Searching for a peer by random sampling can be modeled as a geometric distribution, where each query is an independent Bernoulli trial with success probability $p = \delta$. The expected number $E[X]$ of queries needed to make first contact is :</p>
$$E[X] = \frac{1}{\delta} = \frac{\lvert A \rvert}{n}$$<p>For a network starting up with $n = 100$ peers :</p>
$$E[X] = \frac{4\,294\,967\,296}{100} \approx 4.29 \times 10^{7} \text{ requests}$$<p>Now let $v$ be the scan rate (queries on the address space per second). The average discovery time $T$ is:</p>
$$T = \frac{E[X]}{v} = \frac{\lvert A \rvert}{n \cdot v}$$<p>Assuming a (very) optimistic scan rate of $v = 10^3$ requests per second :</p>
$$T = \frac{4\,294\,967\,296}{1000 \cdot 100} \approx 42\,950 \text{ seconds} \approx 11.93 \text{ hours}$$<p>So, brute-force discovery of a single node on an authority-free network takes close to 12 hours. For a network that already has 100 peers running.</p>
<p>For a very new network of just $n = 2$ peers, the theoretical discovery time increases to roughly &hellip; 24.9 days ! And on a IPv6 adress space, it completely stops being a practical number at all : $\approx 5.4 \times 10^{27}$ years (390 quadrillion times the current age of the universe).</p>
<h2 id="the-problem--addresses-change">
    <a class="heading-anchor" href="#the-problem--addresses-change" aria-label="Link to this section">#</a>The problem : addresses change
</h2>
<p>The scale of the address space alone would be a solvable engineering problem (well, you could, in principle, scan forever). But peers can&rsquo;t scan forever, because the addresses they&rsquo;re scanning for don&rsquo;t stay put. DHCP lease duration isn&rsquo;t fixed : it varies by router vendor, ISP and network type, but a reasonable working approximation would be between 7 to 14 days.</p>
<p>Take $T = 14$ days (1,209,600 seconds) as an upper bound. The total number of scan attempts a peer can realistically make in that window is :</p>
$$S = v \times T = 10^3 \times 1\,209\,600 = 1.2096 \times 10^{9} \text{ attempts}$$<p>Each discovery attempt is a Bernoulli trial with two outcomes : hit or miss. The probability of exactly $k$ hits is :</p>
$$P(X = k) = \binom{S}{k} p^{k} (1-p)^{S-k}$$<p>with :</p>
<ul>
<li>$S = 1.2096 \times 10^{9}$ trials,</li>
<li>$p = \dfrac{1}{4\,294\,967\,296} \approx 2.33 \times 10^{-10}$, the probability of a hit on any given attempt.
<br><br></li>
</ul>
<p>By the Poisson limit theorem ($S \to \infty$, $p \to 0$), the binomial distribution $B(S,p)$ converges to a Poisson distribution $P(\lambda)$ with $\lambda = Sp$ :</p>
$$\lambda = S \times p = 1.2096 \times 10^{9} \times 2.33 \times 10^{-10} \approx 0.2816$$<p>The probability of finding at least one peer ($X \ge 1$) over the whole lease window is :</p>
$$P(X \ge 1) = 1 - e^{-\lambda} = 1 - e^{-0.2816} \approx 0.245 \text{ (i.e. } 24.5\%\text{)}$$<p>A peer has roughly a 1-in-4 chance of ever finding another peer on IPv4 over an entire DHCP lease and that&rsquo;s the very best case, assuming :</p>
<ul>
<li>the searching peer dedicates 100% of its time and bandwidth to scanning, continuously, for the full 14 days, at $v = 10^3$ requests/second</li>
<li>nodes being searched for keep their IP for at least 14 days.</li>
</ul>
<p>None of these assumptions are realistic.</p>
<p>That&rsquo;s why fully decentralized networks aren&rsquo;t really fully decentralized. Bitcoin comes with hardcoded seed nodes and DNS seeds. BitTorrent leans on trackers. Tor has directory authorities. I2P has reseed servers. Pure peer-to-peer discovery is almost impossible when the address space is so large and constantly changing. These authorities, trackers and hardcoded nodes are needed for decentralization to work at all.</p>
<p>So, a fully peer-to-peer network with no authority, as sexy as it is, would be almost utopian over the Internet.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>