DHT & Peer Discovery

KayakNet uses a Kademlia-based Distributed Hash Table (DHT) for peer discovery and decentralized data storage.

What is a DHT?

A DHT is a decentralized key-value store distributed across all nodes:

  • No central server

  • Data is replicated

  • Lookups are efficient (O(log n))

  • Survives node failures

Kademlia Protocol

KayakNet uses Kademlia, the same DHT protocol used by BitTorrent.

XOR Distance

Nodes are assigned IDs, and "distance" is calculated using XOR:

Distance(A, B) = A XOR B

This creates a metric space where:

  • Each node knows about nodes "close" to it

  • Lookups get exponentially closer with each hop

Routing Table

Each node maintains a routing table of k-buckets:

Each bucket holds up to K nodes (K=20 in KayakNet).

Operations

PING

Check if a node is alive:

STORE

Store a key-value pair:

FIND_NODE

Find nodes close to a target ID:

FIND_VALUE

Retrieve a stored value:

Peer Discovery Process

Joining the Network

Iterative Lookup

To find a node or value:

Parameters:

  • α (alpha) = 3 (parallel queries)

  • K = 20 (nodes per bucket)

Data Storage

What's Stored in DHT

Key Type
Value
TTL

peer:<id>

Node address

1 hour

room:<name>

Room metadata

24 hours

domain:<name>

Domain record

Permanent

listing:<id>

Marketplace listing

7 days

msg:<hash>

Message (store-forward)

1 hour

Replication

Data is stored on the K closest nodes:

  • Provides redundancy

  • Survives node failures

  • Automatic re-replication

TTL and Refresh

  • Records have TTL

  • Publishers refresh before expiry

  • Expired records are deleted

  • Popular content stays available

Configuration

Performance

Lookup Efficiency

For N nodes in network:

  • Average hops: O(log N)

  • With 1M nodes: ~20 hops

  • With caching: Often 1-3 hops

Bandwidth Usage

  • PING: ~100 bytes

  • FIND_NODE: ~500 bytes

  • STORE: Variable (depends on value)

Security Considerations

Sybil Protection

Without protection, attacker could:

  • Create many nodes

  • Control routing

  • Censor lookups

KayakNet mitigation:

  • Proof-of-Work for new nodes

  • Peer scoring

  • Diverse peer selection

Eclipse Protection

Without protection, attacker could:

  • Surround victim node

  • Control all their peers

  • Censor or manipulate

KayakNet mitigation:

  • Require peers from different subnets

  • Maintain bootstrap connections

  • Periodic peer refresh

Data Integrity

All DHT records are signed:

Unsigned or invalid records are rejected.

Comparison with Other DHTs

DHT
Used By
Differences

Kademlia

BitTorrent, KayakNet

XOR distance, k-buckets

Chord

Academic

Ring topology

Pastry

Academic

Prefix routing

Coral

CDN

Hierarchical clusters

Troubleshooting

Few Peers

Slow Lookups

  • Check network connectivity

  • Verify bootstrap is reachable

  • Increase alpha for more parallelism

Data Not Found

  • Publisher may be offline

  • TTL may have expired

  • Try again after network refresh

Last updated