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 Connectionimport asyncio
async with Connection() as connection: discovery = connection.get_discovery_service()
# continue with usage of discovery # TODO
use hyveos_sdk::Connection;
#[tokio::main]async fn main() { let connection = Connection::new().await.unwrap(); let mut discovery = connection.discovery()
// continue with usage of req_resp // todo!()}
import { Client } from 'hyveos-sdk'import { Connection } from 'hyveos-web'
async function main() { const transport = new Connection('http://localhost:8080') const client = new Client(transport) const discoveryService = client.discovery
// continue with usage of discoveryService // 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.
from hyveos_sdk import Connectionimport 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())
use futures::TryStreamExt as _;use hyveos_sdk::Connection;
#[tokio::main]async fn main() { let connection = Connection::new().await.unwrap(); let mut discovery = connection.discovery();
let mut events = discovery.subscribe_events().await.unwrap();
while let Some(event) = events.try_next().await.unwrap() { println!("{event:?}"); }}
import { Client } from 'hyveos-sdk'import { Connection } from 'hyveos-web'
async function main() { const transport = new Connection('http://localhost:8080') const client = new Client(transport) const discoveryService = client.discovery
const discoverySubscription = discoveryService.subscribe()
for await (const neighborEvent of discoverySubscription) { console.log('Received event:', neighborEvent) }}
main().catch(console.error)
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.
peer_id = await discovery.get_own_id()
print(f"My peer id: {peer_id}")
let peer_id = discovery.get_own_id().await.unwrap();
println!("My peer id: {peer_id}")
const peerId = await discovery.getOwnId();
console.log(`My peer id: ${peerId}`);
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