Repository navigation
refactor(gossipsub): convert ping pong to extensions #2144
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
89d0d69
ping pong ext
vladopajic 3d3178a
nph
vladopajic 39bc368
config budge
vladopajic cbda2ec
add test
vladopajic 88ff692
nph fix
vladopajic ca51dc2
update
vladopajic 6d4f20d
nph
vladopajic 483f243
fix
vladopajic f67483e
update
vladopajic b0acb6f
remove comment
vladopajic 684c707
update
vladopajic 4218fd4
update
vladopajic ab6c642
update
vladopajic 0299999
nph
vladopajic f28da0e
fix filed num
vladopajic a79ee7e
Apply suggestion from @Copilot
vladopajic efaae3a
Apply suggestion from @Copilot
vladopajic b95eae0
update
vladopajic 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| # Copyright (c) Status Research & Development GmbH | ||
|
|
||
| import tables | ||
| import ../../../[peerid] | ||
| import ../rpc/messages | ||
| import ./[extensions_types] | ||
|
|
||
| type | ||
| PingPongExtensionConfig* = object | ||
| sendPong*: proc(peerID: PeerId, pong: seq[byte]) {.gcsafe, raises: [].} | ||
| peerBudgetBytes*: int = 6400 # bytes per heartbeat per peer | ||
|
|
||
| PingPongExtension* = ref object of Extension | ||
| config: PingPongExtensionConfig | ||
| usedBudget: Table[PeerId, int] | ||
|
|
||
| proc doAssert(config: PingPongExtensionConfig) = | ||
| doAssert(config.sendPong != nil, "PingPongExtensionConfig.sendPong must be set") | ||
| doAssert( | ||
| config.peerBudgetBytes > 0, | ||
| "PingPongExtensionConfig.peerBudgetBytes must be positive (> 0)", | ||
| ) | ||
|
|
||
| proc new*( | ||
| T: typedesc[PingPongExtension], config: PingPongExtensionConfig | ||
| ): PingPongExtension = | ||
| config.doAssert() | ||
| PingPongExtension(config: config) | ||
|
|
||
| method isSupported*( | ||
| ext: PingPongExtension, pe: PeerExtensions | ||
| ): bool {.gcsafe, raises: [].} = | ||
| return pe.pingpongExtension | ||
|
vladopajic marked this conversation as resolved.
Resolved
|
||
|
|
||
| method onHeartbeat*(ext: PingPongExtension) {.gcsafe, raises: [].} = | ||
| ext.usedBudget.clear() | ||
|
|
||
| method onNegotiated*(ext: PingPongExtension, peerId: PeerId) {.gcsafe, raises: [].} = | ||
| discard # NOOP | ||
|
|
||
| method onRemovePeer*(ext: PingPongExtension, peerId: PeerId) {.gcsafe, raises: [].} = | ||
| discard # NOOP | ||
|
vladopajic marked this conversation as resolved.
Resolved
|
||
|
|
||
| method onHandleRPC*( | ||
| ext: PingPongExtension, peerId: PeerId, rpc: RPCMsg | ||
| ) {.gcsafe, raises: [].} = | ||
| rpc.pingpongExtension.withValue(ppe): | ||
| if ppe.ping.len > 0 and | ||
| ext.usedBudget.getOrDefault(peerId) + ppe.ping.len <= ext.config.peerBudgetBytes: | ||
| ext.usedBudget[peerId] = ext.usedBudget.getOrDefault(peerId) + ppe.ping.len | ||
| ext.config.sendPong(peerId, ppe.ping) | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.