-
Notifications
You must be signed in to change notification settings - Fork 43
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: use the lowest latency peer for light protocols #1520
Closed
Closed
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
29cb6a8
set peer-exchange with default bootstrap
danisharora099 3646fdc
only initialise protocols with bootstrap peers
danisharora099 8d48380
Merge branch 'master' into feat/px-default
danisharora099 573fb8d
update package
danisharora099 4894091
Merge branch 'master' into feat/px-default
danisharora099 a5c1372
Merge branch 'master' of github.com:waku-org/js-waku into feat/px-def…
danisharora099 6c1ec84
update package-lock
danisharora099 a0f0668
refactor `getPeers` while setting up a protocol
danisharora099 f376334
move codecs to `@waku/interfaces`
danisharora099 f7f383b
lightpush: send messages to multiple peers
danisharora099 6807888
only use multiple peers for LP and Filter
danisharora099 f956f7f
fix: ts warnings
danisharora099 b43fe35
lightpush: tests pass
danisharora099 d712e8a
update breaking changes for new API
danisharora099 8bf969a
move codecs back into protocol files
danisharora099 3204267
refactor: `getPeers()`
danisharora099 645d7c1
rm: log as an arg
danisharora099 9d70d55
add tsdoc for getPeers
danisharora099 12cec4a
Merge branch 'master' into feat/px-default
danisharora099 773d1ef
add import
danisharora099 f345496
add prettier rule to eslint
danisharora099 f2c2fd0
Merge branch 'feat/fix-prettier-eslint' of github.com:waku-org/js-wak…
danisharora099 efef7a2
add: peer exchange to sdk as a dep
danisharora099 6a17cc3
fix eslint error
danisharora099 befbd37
add try catch
danisharora099 aa87190
Merge branch 'master' into feat/px-default
danisharora099 83d5103
revert unecessary diff
danisharora099 63796db
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 9583bda
revert unecessary diff
danisharora099 6082ffb
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 c63d146
fix imports
danisharora099 6fdcf61
convert relaycodecs to array
danisharora099 916af18
Merge branch 'master' into feat/px-default
danisharora099 5dff864
remove: peerId as an arg for protocol methods
danisharora099 f75b2d9
keep peerId as an arg for peer-exchange
danisharora099 7d14956
remove: peerId from getPeers()
danisharora099 1c93c12
lightpush: extract hardcoded numPeers as a constant
danisharora099 016965b
Merge branch 'master' of github.com:waku-org/js-waku into feat/px-def…
danisharora099 04b9bb5
return all peers if numPeers is 0 and increase readability for random…
danisharora099 1f81ae1
refactor considering more than 1 bootstrap peers can exist
danisharora099 dce7b3b
use `getPeers`
danisharora099 a376bdd
change arg for `getPeers` to object
danisharora099 ec8a1a1
store pings for peers & create getter
danisharora099 ec3bcc8
address comments
danisharora099 c697c15
Merge branch 'master' of github.com:waku-org/js-waku into feat/px-def…
danisharora099 1b0e1fe
refactor tests for new API
danisharora099 c7fca3e
lightpush: make constant the class variable
danisharora099 60c6e05
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 57fbfd2
make `KeepAliveManager` a singleton
danisharora099 3a50420
use the peer with the lowest latency for protocols
danisharora099 40e0b94
introduce tests for `selectPeerForProtocol`
danisharora099 97dff59
add more tests for util & install `chai-as-promised`
danisharora099 acf078d
update package-lock
danisharora099 e98e3c6
rm: only for utils test
danisharora099 191355b
use `maxBootstrapPeers` instead of `includeBootstrap`
danisharora099 6820ebe
refactor protocols for new API
danisharora099 e968d4d
add tests for `getPeers`
danisharora099 401265b
skip getPeers test
danisharora099 1b91278
rm: only from test
danisharora099 c421732
fix: breaking circular dep error
danisharora099 1a8d3a5
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 75ee463
Merge branch 'master' of github.com:waku-org/js-waku into feat/px-def…
danisharora099 56d8b84
move tests to `base_protocol.spec.ts`
danisharora099 dcb4fbf
break down `getPeers` into a `filter` method
danisharora099 2cd8fa0
return all bootstrap peers if arg is 0
danisharora099 ad518af
refactor test without stubbing
danisharora099 d29ecab
Merge branch 'master' of github.com:waku-org/js-waku into feat/select…
danisharora099 9097564
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 6847766
readd chai-as-promised
danisharora099 f24e8c0
address comments
danisharora099 7354b09
update test title
danisharora099 c1d2e1a
move `filterPeers` to a separate file
danisharora099 919f10b
address comments & add more test
danisharora099 e5f1331
Merge branch 'master' into feat/px-default
danisharora099 6a1a4ad
make test title more verbose
danisharora099 a6cad7a
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 0f629cb
address comments
danisharora099 9302a86
remove ProtocolOptions
danisharora099 50df227
Merge branch 'master' into feat/px-default
danisharora099 053c9da
chore: refactor tests for new API
danisharora099 5aa4fcb
add defaults for getPeers
danisharora099 afbcaae
address comments
danisharora099 78114c7
Merge branch 'master' of github.com:waku-org/js-waku into feat/px-def…
danisharora099 ee659cd
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 1002963
minor improvements
danisharora099 2dabefc
peer pings: pass the hashmap in args instead of the function
danisharora099 d28647a
update tests for the new API
danisharora099 d44670d
rm unneeded comment
danisharora099 2e907ea
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 9439bb3
address comment: add diversity of node tags to test
danisharora099 1e2a9d2
address comments
danisharora099 7e49625
Merge branch 'master' of github.com:waku-org/js-waku into feat/px-def…
danisharora099 c90f88b
fix: imports
danisharora099 518f9c6
Merge branch 'feat/px-default' of github.com:waku-org/js-waku into fe…
danisharora099 7840a78
merge
danisharora099 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,25 +4,59 @@ import type { KeepAliveOptions } from "@waku/interfaces"; | |
import debug from "debug"; | ||
import type { PingService } from "libp2p/ping"; | ||
|
||
import { createEncoder } from "../index.js"; | ||
import { createEncoder } from "./message/version_0.js"; | ||
|
||
export const RelayPingContentTopic = "/relay-ping/1/ping/null"; | ||
const log = debug("waku:keep-alive"); | ||
|
||
export class KeepAliveManager { | ||
private static instance: KeepAliveManager; | ||
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. converted this into a singleton for easier access (also consistent with |
||
|
||
private pingKeepAliveTimers: Map<string, ReturnType<typeof setInterval>>; | ||
private relayKeepAliveTimers: Map<PeerId, ReturnType<typeof setInterval>>; | ||
private options: KeepAliveOptions; | ||
private relay?: IRelay; | ||
private libp2pPing: PingService; | ||
public peerPings: Map<string, number>; | ||
|
||
constructor(options: KeepAliveOptions, relay?: IRelay) { | ||
private constructor( | ||
libp2pPing: PingService, | ||
options: KeepAliveOptions, | ||
relay?: IRelay | ||
) { | ||
this.pingKeepAliveTimers = new Map(); | ||
this.relayKeepAliveTimers = new Map(); | ||
this.options = options; | ||
this.relay = relay; | ||
this.peerPings = new Map(); | ||
this.libp2pPing = libp2pPing; | ||
} | ||
|
||
public static createInstance( | ||
libp2pPing: PingService, | ||
options: KeepAliveOptions, | ||
relay?: IRelay | ||
): KeepAliveManager { | ||
if (!KeepAliveManager.instance) { | ||
KeepAliveManager.instance = new KeepAliveManager( | ||
libp2pPing, | ||
options, | ||
relay | ||
); | ||
} | ||
return KeepAliveManager.instance; | ||
} | ||
|
||
public static getInstance(): KeepAliveManager { | ||
if (!KeepAliveManager.instance) { | ||
throw new Error( | ||
"KeepAliveManager not initialized - please use createInstance() first" | ||
); | ||
} | ||
return KeepAliveManager.instance; | ||
} | ||
|
||
public start(peerId: PeerId, libp2pPing: PingService): void { | ||
public start(peerId: PeerId): void { | ||
// Just in case a timer already exist for this peer | ||
this.stop(peerId); | ||
|
||
|
@@ -33,9 +67,15 @@ export class KeepAliveManager { | |
|
||
if (pingPeriodSecs !== 0) { | ||
const interval = setInterval(() => { | ||
libp2pPing.ping(peerId).catch((e) => { | ||
log(`Ping failed (${peerIdStr})`, e); | ||
}); | ||
this.libp2pPing | ||
.ping(peerId) | ||
.then((ping) => { | ||
log(`Ping succeeded (${peerIdStr})`, ping); | ||
this.peerPings.set(peerIdStr, ping); | ||
}) | ||
.catch((e) => { | ||
log(`Ping failed (${peerIdStr})`, e); | ||
}); | ||
}, pingPeriodSecs * 1000); | ||
this.pingKeepAliveTimers.set(peerIdStr, interval); | ||
} | ||
|
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
Oops, something went wrong.
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.
while unrelated to this PR, this was causing a cyclic dependency error that surfaced during this PR