Object.P2PBootstrap (object v0.1.2)

P2P bootstrap and discovery service for the Object network.

Provides multiple discovery mechanisms to find and join the P2P network including hardcoded bootstrap nodes, DNS seeds, mDNS/Bonjour local discovery, BitTorrent DHT integration, and gossip-based peer exchange.

Features

  • Multiple bootstrap strategies
  • DNS seed resolution
  • mDNS/Bonjour local network discovery
  • BitTorrent mainline DHT integration
  • Gossip-based peer exchange protocol
  • Bootstrap node reputation tracking
  • Network partition detection and healing

Summary

Functions

Adds a known peer to the peer list.

Announces this node to the network.

Returns a specification to start this module under a supervisor.

Initiates network discovery using all available methods.

Gets the current list of known peers.

Gets bootstrap statistics.

Starts the P2P bootstrap service.

Types

bootstrap_method()

@type bootstrap_method() :: :hardcoded | :dns | :mdns | :dht | :peer_exchange

bootstrap_stats()

@type bootstrap_stats() :: %{
  total_peers_discovered: non_neg_integer(),
  successful_connections: non_neg_integer(),
  failed_connections: non_neg_integer(),
  discovery_methods_used: %{required(bootstrap_method()) => non_neg_integer()}
}

peer_info()

@type peer_info() :: %{
  node_id: binary(),
  address: String.t(),
  port: non_neg_integer(),
  last_seen: DateTime.t(),
  reputation: float(),
  capabilities: MapSet.t(),
  latency_ms: non_neg_integer() | nil
}

state()

@type state() :: %{
  node_id: binary(),
  peers: %{required(binary()) => peer_info()},
  bootstrap_nodes: [peer_info()],
  dns_seeds: [String.t()],
  active_discoveries: MapSet.t(),
  peer_exchange_enabled: boolean(),
  mdns_ref: reference() | nil,
  dht_port: non_neg_integer() | nil,
  stats: bootstrap_stats()
}

Functions

add_peer(node_id, address, port)

@spec add_peer(binary(), String.t(), non_neg_integer()) :: :ok

Adds a known peer to the peer list.

announce(listen_port)

@spec announce(non_neg_integer()) :: :ok

Announces this node to the network.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

discover_peers()

@spec discover_peers() :: {:ok, [peer_info()]} | {:error, term()}

Initiates network discovery using all available methods.

get_peers()

@spec get_peers() :: [peer_info()]

Gets the current list of known peers.

get_stats()

@spec get_stats() :: bootstrap_stats()

Gets bootstrap statistics.

start_link(opts \\ [])

Starts the P2P bootstrap service.