// Given a key (as a Uint8Array) returns a value (as a Uint8Array), or // undefined if the key isn't found. // // All keys must be prefixed by the same prefix, which will be used to find // the appropriate key lookup function. asyncfunctionmy_subsystem_key_lookup (key: Uint8Array): Promise<Uint8Array | undefined> { // app specific callback to lookup key-value pairs. returnUint8Array.from([0, 1, 2, 3, 4]) }
// Enable this peer to respond to fetch requests for keys that begin with // '/my_subsystem_key_prefix/' libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
// Load the value from the remote peer, timing out after 10s constvalue = awaitlibp2p.services.fetch.fetch(peerDst, key, { signal:AbortSignal.timeout(10_000) })
An implementation of the Fetch protocol as described here: https://github.com/libp2p/specs/tree/master/fetch
The fetch protocol is a simple protocol for requesting a value corresponding to a key from a peer.
Example