Skip to content

Ad-hoc Discovery

The Discovery Service keeps track of neighbor nodes, as reported from the mesh. Events notify a specific node about changes regarding its neighbors, i.e., nodes that have come in sight, or have left sight.

Discovery is used whenever you need to be aware about your peers locally near to you.

The Discovery Service

from hyveos_sdk import Connection
import asyncio
async with Connection() as connection:
discovery = connection.get_discovery_service()
# continue with usage of discovery
# TODO

Example 1. Obtain the Discovery service handler. Note the async environment.

Discover Neighbors

Subscribe to neighbor events in order to get notified when new neighbors are discovered or lost as adjacent nodes in the mesh.

The discovery methods return a stream of neighbour events which will emit an event whenever the local runtime detects a change in the set of neighbors. The stream is guaranteed to emit an Init neighbor event directly after subscribing and only Discovered and Lost events afterwards.

discover_neighbor_nodes.py
from hyveos_sdk import Connection
import asyncio
async with Connection() as connection:
discovery = connection.get_discovery_service()
neighbor_events_stream = discovery.discovery_events()
for neighbor_event in neighbor_events_stream:
print("{neighbor_event}")
asyncio.run(main())

Example 2. Receive a stream of neighbor events. The method is not asnyc.

Own Identification

A connected node has an hyve id, the peer_id.

The async method get_own_id() returns the peer ID of the local runtime.

own_id.py
peer_id = await discovery.get_own_id()
print(f"My peer id: {peer_id}")

Example 3. Obtaining your own ID in the hyve. Error Handling is emitted for brevity.


© 2025 P2P Industries. This documentation is licensed under the MIT License.
Cookie Policy    Privacy Policy