-
Notifications
You must be signed in to change notification settings - Fork 66
chore(kad): interop tests #1902
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
base: master
Are you sure you want to change the base?
Changes from all commits
2526221
539d365
1b54f46
dc9fadf
eb6da80
9414d6c
cdaac23
0934d79
394f147
f629da4
e01b8fa
fa53d3a
57cc870
aa68c2a
72bd14c
879fbec
e030255
eec1dd0
58c99d9
4561174
eda1b96
4663da1
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 |
|---|---|---|
|
|
@@ -17,6 +17,10 @@ examples/*.md | |
| nimble.develop | ||
| nimble.paths | ||
| go-libp2p-daemon/ | ||
| *.id | ||
| *.key | ||
| interop/kad/rust-peer/target/* | ||
| interop/kad/nim-peer/src/nim_peer | ||
|
Comment on lines
+22
to
+23
Member
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. consider having .gitignore file in |
||
|
|
||
| # Ignore all test build files in tests folder (auto generated when running tests). | ||
| # First rule (`tests/**/test*[^.]*`) will ignore all binaries: has prefix test + does not have dot in name. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # begin Nimble config (version 2) | ||
| when withDir(thisDir(), system.fileExists("nimble.paths")): | ||
| include "nimble.paths" | ||
| # end Nimble config |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| version = "0.1.0" | ||
| author = "Status Research & Development Gmb" | ||
| description = "AutoNATv2 peer for interop testing" | ||
|
Member
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. description ? |
||
| license = "MIT" | ||
| srcDir = "src" | ||
| bin = @["nim_peer"] | ||
|
|
||
| # Dependencies | ||
|
|
||
| requires "nim >= 2.3.1", "libp2p" | ||
|
Member
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. does |
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||||||||
| # Nim-LibP2P | ||||||||||||
| # Copyright (c) 2023-2025 Status Research & Development GmbH | ||||||||||||
| # Licensed under either of | ||||||||||||
| # * Apache License, version 2.0 ([LICENSE-APACHE](LICENSE-APACHE)) | ||||||||||||
| # * MIT license ([LICENSE-MIT](LICENSE-MIT)) | ||||||||||||
| # at your option. | ||||||||||||
| # This file may not be copied, modified, or distributed except according to | ||||||||||||
| # those terms. | ||||||||||||
|
|
||||||||||||
| import net, chronos, libp2p, sequtils | ||||||||||||
| import libp2p/protocols/kademlia | ||||||||||||
|
|
||||||||||||
| proc waitForService( | ||||||||||||
| host: string, port: Port, retries: int = 20, delay: Duration = 500.milliseconds | ||||||||||||
| ): Future[bool] {.async.} = | ||||||||||||
| for i in 0 ..< retries: | ||||||||||||
| try: | ||||||||||||
| var s = newSocket() | ||||||||||||
| s.connect(host, port) | ||||||||||||
| s.close() | ||||||||||||
| return true | ||||||||||||
| except OSError: | ||||||||||||
| discard | ||||||||||||
| await sleepAsync(delay) | ||||||||||||
| return false | ||||||||||||
|
Comment on lines
+13
to
+25
Member
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. this code keeps repeating. please have it as shared utility. |
||||||||||||
|
|
||||||||||||
| proc main() {.async.} = | ||||||||||||
| var switch = SwitchBuilder | ||||||||||||
| .new() | ||||||||||||
| .withRng(newRng()) | ||||||||||||
| .withAddresses(@[MultiAddress.init("/ip4/127.0.0.1/tcp/3131").tryGet()]) | ||||||||||||
| .withTcpTransport() | ||||||||||||
| .withYamux() | ||||||||||||
|
Member
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. if rust has mplex can we use that?
Member
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. we should try to reduce yamux usage in codebase becasue #1635 might be around the corner |
||||||||||||
| .withNoise() | ||||||||||||
| .build() | ||||||||||||
|
|
||||||||||||
| let | ||||||||||||
| peerId = PeerId.init(readFile("../rust-peer/peer.id")).get() | ||||||||||||
| peerMa = MultiAddress.init("/ip4/127.0.0.1/tcp/4141").get() | ||||||||||||
|
Member
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. seems bit mixed decisions... peer id is not hardcoded but address is. why not have both in file? or hardcode both? |
||||||||||||
| kad = KadDHT.new( | ||||||||||||
| switch, | ||||||||||||
| bootstrapNodes = @[(peerId, @[peerMa])], | ||||||||||||
| config = KadDHTConfig.new(quorum = 1), | ||||||||||||
|
Member
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.
|
||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| switch.mount(kad) | ||||||||||||
| await sleepAsync(5.seconds) | ||||||||||||
|
|
||||||||||||
| await switch.start() | ||||||||||||
| defer: | ||||||||||||
| await switch.stop() | ||||||||||||
|
|
||||||||||||
| let key: Key = "key".mapIt(byte(it)) | ||||||||||||
|
|
||||||||||||
| let value = @[1.byte, 2, 3, 4, 5] | ||||||||||||
|
Comment on lines
+53
to
+55
Member
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
|
||||||||||||
|
|
||||||||||||
| let res = await kad.putValue(key, value) | ||||||||||||
| if res.isErr(): | ||||||||||||
| echo "putValue failed: ", res.error | ||||||||||||
| quit(1) | ||||||||||||
|
|
||||||||||||
| await sleepAsync(2.seconds) | ||||||||||||
|
|
||||||||||||
| # try to get the inserted value from peer | ||||||||||||
| if (await kad.getValue(key)).get().value != value: | ||||||||||||
| echo "Get value did not return correct value" | ||||||||||||
| quit(1) | ||||||||||||
|
|
||||||||||||
|
Member
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 we get value that this node does not have but rust node does have? |
||||||||||||
| when isMainModule: | ||||||||||||
| if waitFor(waitForService("127.0.0.1", Port(4141))): | ||||||||||||
|
Member
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.
|
||||||||||||
| waitFor(main()) | ||||||||||||
| else: | ||||||||||||
| quit("timeout waiting for service", 1) | ||||||||||||
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.
why
$(cat ../rust-peer/peer.id)?