> ## Documentation Index
> Fetch the complete documentation index at: https://docs.parallaxprotocol.org/llms.txt
> Use this file to discover all available pages before exploring further.

# TCP Peer Discovery

Parallax discovers peers with a Bitcoin-style TCP gossip model, which
replaced the UDP-based `discv4` discovery of v1.x releases. Each node
runs:

* a **Bitcoin Core-style address manager** (`addrman`) that stores up
  to \~65k peer records in stochastic "new" and "tried" bucket tables,
  keyed by a per-node secret `nKey`;
* the **`parallax-disc/1`** RLPx subprotocol, carrying a mandatory
  session-opening `Hello` followed by `GetPeers` / `Peers` /
  `YourAddr` gossip messages on top of existing TCP sessions —
  `Hello` must be each side's first disc message, and anything else
  first ends the session;
* a **BIP324-style v2 handshake** that lets two nodes authenticate a
  TCP connection knowing only each other's `ip:port` — no persistent
  secp256k1 identity, no enode URL, no ENR.

These three pieces are **always on** in v2.0+ builds. Operators
choose their compatibility posture with a single flag.

Addresses travel in BIP155 form, so the same gossip carries IPv4,
IPv6 and Tor v3 onion addresses — see
[Tor Integration](./tor) for how onion peers behave.

## The `--legacy-discovery` flag

`--legacy-discovery` controls how much of the v1.x transport surface
the node exposes. UDP discovery and legacy RLPx handshake acceptance
are coupled: they share the same v1.x identity model (persistent
secp256k1 key, enode URL, ENR record), so the flag drives both in
lockstep.

| Value                | UDP discv4               | Legacy RLPx                          | v2 handshake | addrman   |
| -------------------- | ------------------------ | ------------------------------------ | ------------ | --------- |
| **`auto`** (default) | responder-only           | accepted + dialed for `KeyType=0x01` | always on    | always on |
| **`on`**             | full (drives dialing)    | accepted + dialed                    | always on    | always on |
| **`off`**            | disabled (no UDP socket) | **refused** (listener & dialer)      | always on    | always on |

`auto` is the transitional posture: the node answers inbound discv4
PING/FINDNODE so v1.x peers can still contact it, but the addrman is
the primary dial source. Most mainnet operators will never need to
change it.

`on` matches pre-2.0 behaviour — `discv4.RandomNodes()` is plumbed
into the dial scheduler, useful when debugging against a pure v1.x
network.

`off` is the v3.0 posture available as an early opt-in: no UDP
socket, the listener rejects anything that isn't the v2 magic byte
`0xA0`, and the dialer refuses addrman entries that carry a legacy
`NodeID`. The enode URL logged at startup becomes diagnostic-only —
no peer handshake consumes the persistent secp256k1 key in this mode.

## Topology examples

The canonical three-role mainnet setup:

```
Node A (v1.x simulated)   : no v2 discovery flags                     → legacy RLPx, discv4
Node B (bridge)           : --legacy-discovery=auto (or on)           → speaks both, addrman on
Node C (v2-only)          : --legacy-discovery=off                    → v2 handshake only, no UDP
```

Under this topology, B connects to both A (legacy RLPx) and C (v2
handshake) simultaneously on the same listener. C never peers with A
directly; all A-discovered addresses reach C via `parallax-disc/1`
gossip through B.

## Addrbook persistence

The addrman persists to `<datadir>/addrbook.rlp` on clean shutdown
and reloads it on next startup. The on-disk format is versioned
(v1 today); upgrades introduce a new version byte plus a migration
function rather than appending fields in place.

Unknown newer file versions are refused without truncation — a
downgrade-then-upgrade never loses the original file.

## Operator RPC

The admin namespace exposes the addrbook and dial controls:

* `admin_addnode <ip:port | <addr>.onion:port | enode://…>` — pin a
  peer as `source=manual`; persists across restarts and is heavily
  weighted in dial selection (a 4x chance multiplier, not a strict
  front-of-queue guarantee).
* `admin_removenode <ip:port | <addr>.onion:port | enode://…>` —
  inverse of addnode.
* `admin_addrbookStatus` — read-only addrbook snapshot
  (total/new/tried, per-source counts).
* `admin_addrbookResetKey` — regenerate `nKey` and clear the tried
  table. Operator-only; use after a credible `nKey` leak.
* `admin_dialV2 <ip:port | <addr>.onion:port>` — directly dial a
  remote over the v2 handshake. Operator-testing entry point.

Three more manage the persistent ban list (see
[Peer management](./peer-management) for behaviour):

* `admin_setban <subnet> <add|remove> [bantime] [absolute]`
* `admin_listbanned`
* `admin_clearbanned`

Corresponding `parallax-cli` subcommands are `addnode`, `removenode`,
`addrbook-status`, `addrbook-resetkey`, `dialv2`, `setban`,
`listbanned`, `clearbanned`.

## Deprecation timeline

| Release  | Default `--legacy-discovery` | What changes                                                                                                                                                                                                                                     |
| -------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **v2.0** | `auto`                       | TCP discovery ships as shown above.                                                                                                                                                                                                              |
| **v2.2** | `off`                        | Once telemetry confirms v1.x peers are \<5% of the network, the default flips.                                                                                                                                                                   |
| **v3.0** | n/a — flag removed           | Legacy RLPx, ENR, enode, and `p2p/discover/v4*.go` are deleted. `parallax-disc/2` replaces the v1-schema `PeerEntry`, dropping the legacy `KeyType`/`NodeID` fields while retaining BIP155 addressing so [Tor peers](./tor) survive the removal. |
