Object.DistributedRegistry (object v0.1.2)

Distributed registry for Objects using Kademlia DHT algorithm.

Provides a decentralized, fault-tolerant registry for object discovery across network boundaries. Implements Kademlia's XOR-based routing with k-buckets for efficient O(log n) lookups.

Features

  • Kademlia DHT with 160-bit node IDs
  • K-bucket routing table management
  • Iterative lookup procedures
  • Node liveness checking via PING/PONG
  • Automatic republishing of values
  • Byzantine fault tolerance mechanisms
  • NAT-aware node addressing

Summary

Functions

Adds a peer to the routing table.

Bootstraps the node into the DHT network.

Returns a specification to start this module under a supervisor.

Finds nodes close to a given ID.

Gets the current node's ID.

Looks up an object by ID in the distributed registry.

Registers a local object in the distributed registry.

Starts the distributed registry.

Types

node_id()

@type node_id() :: <<_::160>>

node_info()

@type node_info() :: %{
  id: node_id(),
  address: String.t(),
  port: non_neg_integer(),
  last_seen: DateTime.t(),
  rtt: non_neg_integer() | nil,
  reputation: float()
}

query_state()

@type query_state() :: %{
  type: :find_node | :find_value | :store,
  target: binary(),
  visited: MapSet.t(),
  active: MapSet.t(),
  best_nodes: [node_info()],
  from: GenServer.from() | nil,
  start_time: DateTime.t()
}

routing_table()

@type routing_table() :: %{
  buckets: %{required(non_neg_integer()) => [node_info()]},
  self_id: node_id()
}

state()

@type state() :: %{
  node_id: node_id(),
  routing_table: routing_table(),
  storage: %{required(binary()) => stored_value()},
  pending_queries: %{required(reference()) => query_state()},
  transport: pid(),
  config: map()
}

stored_value()

@type stored_value() :: %{
  key: binary(),
  value: term(),
  publisher: node_id(),
  timestamp: DateTime.t(),
  ttl: non_neg_integer()
}

Functions

add_peer(peer_id, address, port)

@spec add_peer(node_id(), String.t(), non_neg_integer()) :: :ok | {:error, term()}

Adds a peer to the routing table.

Parameters

  • peer_id: Node ID of the peer
  • address: IP address of the peer
  • port: Port number of the peer

bootstrap(bootstrap_nodes)

@spec bootstrap([{String.t(), non_neg_integer()}]) :: :ok | {:error, term()}

Bootstraps the node into the DHT network.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

find_node(target_id)

@spec find_node(binary()) :: {:ok, [node_info()]} | {:error, term()}

Finds nodes close to a given ID.

get_node_id()

@spec get_node_id() :: node_id()

Gets the current node's ID.

lookup_object(object_id)

@spec lookup_object(String.t()) :: {:ok, Object.t()} | {:error, :not_found}

Looks up an object by ID in the distributed registry.

register_object(object_id, object)

@spec register_object(String.t(), Object.t()) :: :ok | {:error, term()}

Registers a local object in the distributed registry.

start_link(opts \\ [])

Starts the distributed registry.