Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: add routing symbols #388

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/interface-content-routing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ import type { CID } from 'multiformats/cid'
import type { AbortOptions } from '@libp2p/interfaces'
import type { PeerInfo } from '@libp2p/interface-peer-info'

/**
* Any object that implements this Symbol as a property should return a
* ContentRouting instance as the property value, similar to how
* `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
*
* @example
*
* ```js
* import { contentRouting, ContentRouting } from '@libp2p/content-routing'
*
* class MyContentRouter implements ContentRouting {
* get [contentRouting] () {
* return this
* }
*
* // ...other methods
* }
* ```
*/
export const contentRouting = Symbol.for('@libp2p/content-routing')

export interface ContentRouting {
/**
* The implementation of this method should ensure that network peers know the
Expand Down
21 changes: 21 additions & 0 deletions packages/interface-peer-discovery/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import type { PeerInfo } from '@libp2p/interface-peer-info'
import type { EventEmitter } from '@libp2p/interfaces/events'

/**
* Any object that implements this Symbol as a property should return a
* PeerDiscovery instance as the property value, similar to how
* `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
*
* @example
*
* ```js
* import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery'
*
* class MyPeerDiscoverer implements PeerDiscovery {
* get [peerDiscovery] () {
* return this
* }
*
* // ...other methods
* }
* ```
*/
export const peerDiscovery = Symbol.for('@libp2p/peer-discovery')

export const symbol = Symbol.for('@libp2p/peer-discovery')

export interface PeerDiscoveryEvents {
Expand Down
21 changes: 21 additions & 0 deletions packages/interface-peer-routing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerInfo } from '@libp2p/interface-peer-info'
import type { AbortOptions } from '@libp2p/interfaces'

/**
* Any object that implements this Symbol as a property should return a
* PeerRouting instance as the property value, similar to how
* `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
*
* @example
*
* ```js
* import { peerRouting, PeerRouting } from '@libp2p/peer-routing'
*
* class MyPeerRouter implements PeerRouting {
* get [peerRouting] () {
* return this
* }
*
* // ...other methods
* }
* ```
*/
export const peerRouting = Symbol.for('@libp2p/peer-routing')

export interface PeerRouting {
/**
* Searches the network for peer info corresponding to the passed peer id.
Expand Down