-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(store): allow using a specific node #2192
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,13 @@ export type ProtocolCreateOptions = { | |
* List of peers to use to bootstrap the node. Ignored if defaultBootstrap is set to true. | ||
*/ | ||
bootstrapPeers?: string[]; | ||
/** | ||
* List of nodes' multiaddrs as strings to use for each protocol. If not specified, random nodes will be used. | ||
* This should be used only if you know what you are doing. | ||
*/ | ||
nodeToUse?: { | ||
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. can you create and type StoreProtocolOptions = {
peers: [],
}; example for Filter in one of open PRs - 09127df |
||
store?: string; | ||
}; | ||
}; | ||
|
||
export type Callback<T extends IDecodedMessage> = ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import type { Stream } from "@libp2p/interface"; | ||
import { isPeerId, PeerId } from "@libp2p/interface"; | ||
import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; | ||
import { ConnectionManager, getHealthManager } from "@waku/core"; | ||
import { ConnectionManager, getHealthManager, StoreCodec } from "@waku/core"; | ||
import type { | ||
IFilter, | ||
IHealthManager, | ||
|
@@ -10,6 +10,7 @@ import type { | |
IStore, | ||
IWaku, | ||
Libp2p, | ||
PeerIdStr, | ||
ProtocolCreateOptions, | ||
PubsubTopic | ||
} from "@waku/interfaces"; | ||
|
@@ -106,7 +107,14 @@ export class WakuNode implements IWaku { | |
this.health = getHealthManager(); | ||
|
||
if (protocolsEnabled.store) { | ||
const store = wakuStore(this.connectionManager); | ||
let peerIdStr: PeerIdStr | undefined; | ||
if (options.nodeToUse?.store) { | ||
this.dialMultiaddr(options.nodeToUse.store, StoreCodec).catch((e) => { | ||
log.error("Failed to dial store peer", e); | ||
}); | ||
} | ||
|
||
const store = wakuStore(this.connectionManager, peerIdStr); | ||
this.store = store(libp2p); | ||
} | ||
|
||
|
@@ -224,6 +232,18 @@ export class WakuNode implements IWaku { | |
return this.connectionManager.isConnected(); | ||
} | ||
|
||
private async dialMultiaddr( | ||
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. let's not introduce this operation and use |
||
multiaddrStr: string, | ||
protocol: string | ||
): Promise<PeerIdStr> { | ||
const ma = multiaddr(multiaddrStr); | ||
if (!ma.getPeerId()) { | ||
throw new Error("Failed to dial multiaddr: missing peer ID"); | ||
} | ||
await this.libp2p.dialProtocol(ma, [protocol]); | ||
return ma.getPeerId()!; | ||
} | ||
|
||
private mapToPeerIdOrMultiaddr( | ||
peerId: PeerId | MultiaddrInput | ||
): PeerId | Multiaddr { | ||
|
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.
please, let's not introduce changes into this file and instead prefer peer in
store.ts
with something like