-
Notifications
You must be signed in to change notification settings - Fork 55
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
Circuit relay v1 #670
Circuit relay v1 #670
Conversation
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.
Hey @lchenut! Thank you so much for taking the time to work on this! Great job and appologies for taking this long to respond from my side!
So far everything looks pretty good sans a few minor things I've already commented on. In any case I'll give it another pass soon.
One crussial thing that is missing are interop tests. We have examples of how we do this in the testinterop.nim
file, we run them against a go libp2p daemon instance. It's very usefull in catching any inconsistencies and validate how well supported the protocol. Let me know if you need any help navigating it.
Cheers!
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.
Some nitpicks
@dryajov @Menduist, I corrected all the errors / nitpicks and I added the interop tests. The only thing I left open is the dirty buffers in the bridge part of the relay as I wanted your advice on this point. proc main() {.async, gcsafe.} =
let
CustomProtoCodec = "/customProto"
rng = newRng()
src = SwitchBuilder.new()
.withRng(rng)
.withAddresses(@[ MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet() ])
.withTcpTransport()
.withMplex()
.withNoise()
.withRelayTransport(canHop=false)
.build()
rel = SwitchBuilder.new()
.withRng(rng)
.withAddresses(@[ MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet() ])
.withTcpTransport()
.withMplex()
.withNoise()
.withRelayTransport(canHop=true)
.build()
dst = SwitchBuilder.new()
.withRng(rng)
.withAddresses(@[ MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet() ])
.withTcpTransport()
.withMplex()
.withNoise()
.withRelayTransport(canHop=false)
.build()
# Create a custom protocol
var proto = new LPProtocol
proto.handler = proc (conn: Connection, customProto: string) {.async.} =
echo "Destination Read From Source: ", string.fromBytes(await conn.readLP(1024))
await conn.writeLp("I'm out")
await conn.close()
proto.codec = CustomProtoCodec
dst.mount(proto)
await src.start()
await rel.start()
await dst.start()
let ma = MultiAddress.init($rel.peerInfo.addrs[0] & "/p2p/" & $rel.peerInfo.peerId & "/p2p-circuit/p2p/" & $dst.peerInfo.peerId).tryGet()
# /ip4/.../tcp/.../p2p/QmRelay/p2p-circuit/p2p/QmDestination
await src.connect(rel.peerInfo.peerId, rel.peerInfo.addrs)
await rel.connect(dst.peerInfo.peerId, dst.peerInfo.addrs)
let conn = await src.dial(dst.peerInfo.peerId, @[ ma ], CustomProtoCodec)
await conn.writeLp("Hello")
echo "Source Read From Destination: ", string.fromBytes(await conn.readLp(1024))
await allFutures(src.stop(), rel.stop(), dst.stop())
waitFor(main()) Few more points:
|
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.
Getting close!
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.
Great job @lchenut! LGTM!
A simple way to make it work at the moment:
Few notes: