Hierarchy

  • PeerStore

Properties

all: ((query?: PeerQuery) => Promise<Peer[]>)

Type declaration

consumePeerRecord: ((buf: Uint8Array, expectedPeer?: PeerId) => Promise<boolean>)

Type declaration

    • (buf: Uint8Array, expectedPeer?: PeerId): Promise<boolean>
    • 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.

      Example

      await peerStore.consumePeerRecord(buf, expectedPeer)
      

      Parameters

      Returns Promise<boolean>

delete: ((peerId: PeerId) => Promise<void>)

Type declaration

    • (peerId: PeerId): Promise<void>
    • Delete all data stored for the passed peer

      Example

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

      await peerStore.delete(peerId)

      await peerStore.addressBook.get(peerId)
      // []

      Parameters

      Returns Promise<void>

forEach: ((fn: ((peer: Peer) => void), query?: PeerQuery) => Promise<void>)

Type declaration

    • (fn: ((peer: Peer) => void), query?: PeerQuery): Promise<void>
    • 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

      Example

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

      Parameters

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

            Returns void

      • Optional query: PeerQuery

      Returns Promise<void>

get: ((peerId: PeerId) => Promise<Peer>)

Type declaration

    • (peerId: PeerId): Promise<Peer>
    • Returns all data stored for the passed PeerId

      Example

      const peer = await peerStore.get(peerId)
      // { .. }

      Parameters

      Returns Promise<Peer>

has: ((peerId: PeerId) => Promise<boolean>)

Type declaration

    • (peerId: PeerId): Promise<boolean>
    • Returns true if the passed PeerId is in the peer store

      Example

      await peerStore.has(peerId)
      // false
      await peerStore.addressBook.add(peerId, multiaddrs)
      await peerStore.has(peerId)
      // true

      Parameters

      Returns Promise<boolean>

merge: ((id: PeerId, data: PeerData) => Promise<Peer>)

Type declaration

patch: ((id: PeerId, data: PeerData) => Promise<Peer>)

Type declaration

save: ((id: PeerId, data: PeerData) => Promise<Peer>)

Type declaration