libp2p/peerstore

Search:
Group by:
Source   Edit  

Stores generic informations about peers.

Example:

# Will keep info of all connected peers +
# last 50 disconnected peers
let peerStore = PeerStore.new(capacity = 50)

# Create a custom book type
type MoodBook = ref object of PeerBook[string]

var somePeerId = PeerId.random().expect("get random key")

peerStore[MoodBook][somePeerId] = "Happy"
doAssert peerStore[MoodBook][somePeerId] == "Happy"
##############################################################################

Types

AddressBook {.public.} = ref object of SeqPeerBook[MultiAddress]
Source   Edit  
AgentBook {.public.} = ref object of PeerBook[string]
Source   Edit  
KeyBook {.public.} = ref object of PeerBook[PublicKey]
Source   Edit  
PeerBook[T] {.public.} = ref object of BasePeerBook
  book*: Table[PeerId, T]
Source   Edit  
PeerBookChangeHandler = proc (peerId: PeerId) {....gcsafe, raises: [].}
Source   Edit  
PeerStore {.public.} = ref object
  capacity*: int
  toClean*: seq[PeerId]
Source   Edit  
ProtoBook {.public.} = ref object of SeqPeerBook[string]
Source   Edit  
ProtoVersionBook {.public.} = ref object of PeerBook[string]
Source   Edit  
SeqPeerBook[T] = ref object of PeerBook[seq[T]]
Source   Edit  
SPRBook {.public.} = ref object of PeerBook[Envelope]
Source   Edit  

Procs

proc `[]`[T](p: PeerStore; typ: type[T]): T {.public, ...raises: [].}
Get a book from the PeerStore (ex: peerStoreAddressBook) Source   Edit  
proc `[]`[T](peerBook: PeerBook[T]; peerId: PeerId): T {.public, ...raises: [].}
Get all known metadata of a provided peer, or default(T) if missing Source   Edit  
proc `[]=`[T](peerBook: PeerBook[T]; peerId: PeerId; entry: T) {.public,
    ...raises: [].}
Set metadata for a given peerId. Source   Edit  
proc addHandler[T](peerBook: PeerBook[T]; handler: PeerBookChangeHandler) {.
    public, ...raises: [].}
Adds a callback that will be called everytime the book changes Source   Edit  
proc cleanup(peerStore: PeerStore; peerId: PeerId) {....raises: [],
    tags: [RootEffect], forbids: [].}
Source   Edit  
proc contains[T](peerBook: PeerBook[T]; peerId: PeerId): bool {.public,
    ...raises: [].}
Source   Edit  
proc del(peerStore: PeerStore; peerId: PeerId) {.public, ...raises: [],
    tags: [RootEffect], forbids: [].}
Delete the provided peer from every book. Source   Edit  
proc del[T](peerBook: PeerBook[T]; peerId: PeerId): bool {.public, ...raises: [].}
Delete the provided peer from the book. Returns whether the peer was in the book Source   Edit  
proc getMostObservedProtosAndPorts(self: PeerStore): seq[MultiAddress] {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc guessDialableAddr(self: PeerStore; ma: MultiAddress): MultiAddress {.
    ...raises: [], tags: [RootEffect], forbids: [].}
Source   Edit  
proc identify(peerStore: PeerStore; muxer: Muxer) {.async, ...raises: [],
    tags: [RootEffect], forbids: [].}
Source   Edit  
proc len[T](peerBook: PeerBook[T]): int {.public, ...raises: [].}
Source   Edit  
proc new(T: type PeerStore; identify: Identify; capacity = 1000): PeerStore {.
    public, ...raises: [].}
Source   Edit  
proc updatePeerInfo(peerStore: PeerStore; info: IdentifyInfo) {....raises: [],
    tags: [RootEffect], forbids: [].}
Source   Edit