interface PeerStore {
    all(query?): Promise<Peer[]>;
    consumePeerRecord(buf, expectedPeer?): Promise<boolean>;
    delete(peerId): Promise<void>;
    forEach(fn, query?): Promise<void>;
    get(peerId): Promise<Peer>;
    has(peerId): Promise<boolean>;
    merge(id, data): Promise<Peer>;
    patch(id, data): Promise<Peer>;
    save(id, data): Promise<Peer>;
}

Methods

  • Unmarshal and verify a signed peer record, extract the multiaddrs and overwrite the stored addresses for the peer.

    Optionally pass an expected PeerId to verify that the peer record was signed by that peer.

    Parameters

    Returns Promise<boolean>

    Example

    await peerStore.consumePeerRecord(buf, expectedPeer)
    
  • Delete all data stored for the passed peer

    Parameters

    Returns Promise<void>

    Example

    await peerStore.addressBook.set(peerId, multiaddrs)
    await peerStore.addressBook.get(peerId)
    // multiaddrs[]

    await peerStore.delete(peerId)

    await peerStore.addressBook.get(peerId)
    // []
  • Loop over every peer - the looping is async because we read from a datastore but the peer operation is sync, this is to prevent long-lived peer operations causing deadlocks over the datastore which can happen if they try to access the peer store during the loop

    Parameters

    • fn: ((peer) => void)
        • (peer): void
        • Parameters

          Returns void

    • Optional query: PeerQuery

    Returns Promise<void>

    Example

    await peerStore.forEach(peer => {
    // ...
    })