This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
feat: add content and peer routing progress events #355
Draft
achingbrain
wants to merge
1
commit into
master
Choose a base branch
from
feat/add-content-and-peer-routing-progress-events
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,6 +29,7 @@ import type { StreamHandler, StreamHandlerOptions, Topology } from '@libp2p/inte | |||||
import type { Metrics } from '@libp2p/interface-metrics' | ||||||
import type { PeerInfo } from '@libp2p/interface-peer-info' | ||||||
import type { KeyChain } from '@libp2p/interface-keychain' | ||||||
import type { ProgressEvent } from 'progress-events' | ||||||
|
||||||
/** | ||||||
* Once you have a libp2p instance, you can listen to several events it emits, so that you can be notified of relevant network events. | ||||||
|
@@ -87,7 +88,14 @@ export interface LookupFunction { | |||||
/** | ||||||
* Libp2p nodes implement this interface. | ||||||
*/ | ||||||
export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> { | ||||||
export interface Libp2p< | ||||||
FindPeerProgressEvents extends ProgressEvent = ProgressEvent, | ||||||
GetClosestPeersProgressEvents extends ProgressEvent = ProgressEvent, | ||||||
ProvideProgressEvents extends ProgressEvent = ProgressEvent, | ||||||
FindProvidersProgressEvents extends ProgressEvent = ProgressEvent, | ||||||
PutProgressEvents extends ProgressEvent = ProgressEvent, | ||||||
GetProgressEvents extends ProgressEvent = ProgressEvent | ||||||
> extends Startable, EventEmitter<Libp2pEvents> { | ||||||
/** | ||||||
* The PeerId is a unique identifier for a node on the network. | ||||||
* | ||||||
|
@@ -138,7 +146,7 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> { | |||||
* } | ||||||
* ``` | ||||||
*/ | ||||||
peerRouting: PeerRouting | ||||||
peerRouting: PeerRouting<FindPeerProgressEvents, GetClosestPeersProgressEvents> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/** | ||||||
* The content routing subsystem allows the user to find providers for content, | ||||||
|
@@ -154,7 +162,7 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> { | |||||
* } | ||||||
* ``` | ||||||
*/ | ||||||
contentRouting: ContentRouting | ||||||
contentRouting: ContentRouting<ProvideProgressEvents, FindProvidersProgressEvents, PutProgressEvents, GetProgressEvents> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/** | ||||||
* The keychain contains the keys used by the current node, and can create new | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import type { PeerId } from '@libp2p/interface-peer-id' | ||
import type { PeerInfo } from '@libp2p/interface-peer-info' | ||
import type { AbortOptions } from '@libp2p/interfaces' | ||
import type { ProgressEvent, ProgressOptions } from 'progress-events' | ||
|
||
export interface PeerRouting { | ||
export interface PeerRouting< | ||
FindPeerProgressEvents extends ProgressEvent = ProgressEvent, | ||
GetClosestPeersProgressEvents extends ProgressEvent = ProgressEvent, | ||
> { | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
/** | ||
* Searches the network for peer info corresponding to the passed peer id. | ||
* | ||
|
@@ -13,7 +17,7 @@ export interface PeerRouting { | |
* const peer = await peerRouting.findPeer(peerId, options) | ||
* ``` | ||
*/ | ||
findPeer: (peerId: PeerId, options?: AbortOptions) => Promise<PeerInfo> | ||
findPeer: (peerId: PeerId, options?: AbortOptions & ProgressOptions<FindPeerProgressEvents>) => Promise<PeerInfo> | ||
|
||
/** | ||
* Search the network for peers that are closer to the passed key. Peer | ||
|
@@ -28,5 +32,5 @@ export interface PeerRouting { | |
* } | ||
* ``` | ||
*/ | ||
getClosestPeers: (key: Uint8Array, options?: AbortOptions) => AsyncIterable<PeerInfo> | ||
getClosestPeers: (key: Uint8Array, options?: AbortOptions & ProgressOptions<GetClosestPeersProgressEvents>) => AsyncIterable<PeerInfo> | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add generics to the
extends ProgressEvent
in order to appropriately populate progressEvent or else users won't be able to customize their data since it's always going to be set toProgressEvent<any, unknown>
e.g.
this can obviously be improved, but without piping the generics through, you will lock types to any and unknown, and aren't getting much benefit