{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"nim-libp2p documentation","text":"<p>Welcome to the nim-libp2p documentation!</p> <p>Here, you'll find tutorials to help you get started, as well as the full reference.</p>"},{"location":"circuitrelay/","title":"Circuit Relay example","text":"<p>Circuit Relay can be used when a node cannot reach another node directly, but can reach it through another node (the Relay).</p> <p>That may happen because of NAT, Firewalls, or incompatible transports.</p> <p>More informations here.</p> <pre><code>import chronos, stew/byteutils\nimport libp2p, libp2p/protocols/connectivity/relay/[relay, client]\n\n# Helper to create a circuit relay node\nproc createCircuitRelaySwitch(r: Relay): Switch =\n SwitchBuilder\n .new()\n .withRng(newRng())\n .withAddresses(@[MultiAddress.init(\"/ip4/0.0.0.0/tcp/0\").tryGet()])\n .withTcpTransport()\n .withMplex()\n .withNoise()\n .withCircuitRelay(r)\n .build()\n\nproc main() {.async.} =\n # Create a custom protocol\n let customProtoCodec = \"/test\"\n var proto = new LPProtocol\n proto.codec = customProtoCodec\n proto.handler = proc(conn: Connection, proto: string) {.async.} =\n var msg = string.fromBytes(await conn.readLp(1024))\n echo \"1 - Dst Received: \", msg\n assert \"test1\" == msg\n await conn.writeLp(\"test2\")\n msg = string.fromBytes(await conn.readLp(1024))\n echo \"2 - Dst Received: \", msg\n assert \"test3\" == msg\n await conn.writeLp(\"test4\")\n\n let\n relay = Relay.new()\n clSrc = RelayClient.new()\n clDst = RelayClient.new()\n\n # Create three hosts, enable relay client on two of them.\n # The third one can relay connections for other peers.\n # RelayClient can use a relay, Relay is a relay.\n swRel = createCircuitRelaySwitch(relay)\n swSrc = createCircuitRelaySwitch(clSrc)\n swDst = createCircuitRelaySwitch(clDst)\n\n swDst.mount(proto)\n\n await swRel.start()\n await swSrc.start()\n await swDst.start()\n\n let\n # Create a relay address to swDst using swRel as the relay\n addrs = MultiAddress\n .init(\n $swRel.peerInfo.addrs[0] & \"/p2p/\" & $swRel.peerInfo.peerId & \"/p2p-circuit\"\n )\n .get()\n\n # Connect Dst to the relay\n await swDst.connect(swRel.peerInfo.peerId, swRel.peerInfo.addrs)\n\n # Dst reserve a slot on the relay.\n let rsvp = await clDst.reserve(swRel.peerInfo.peerId, swRel.peerInfo.addrs)\n\n # Src dial Dst using the relay\n let conn = await swSrc.dial(swDst.peerInfo.peerId, @[addrs], customProtoCodec)\n\n await conn.writeLp(\"test1\")\n var msg = string.fromBytes(await conn.readLp(1024))\n echo \"1 - Src Received: \", msg\n assert \"test2\" == msg\n await conn.writeLp(\"test3\")\n msg = string.fromBytes(await conn.readLp(1024))\n echo \"2 - Src Received: \", msg\n assert \"test4\" == msg\n\n await relay.stop()\n await allFutures(swSrc.stop(), swDst.stop(), swRel.stop())\n\nwaitFor(main())\n</code></pre>"},{"location":"tutorial_1_connect/","title":"Simple ping tutorial","text":"<p>Hi all, welcome to the first nim-libp2p tutorial!</p> <p>This tutorial is for everyone who is interested in building peer-to-peer applications. No Nim programming experience is needed.</p> <p>To give you a quick overview, Nim is the programming language we are using and nim-libp2p is the Nim implementation of libp2p, a modular library that enables the development of peer-to-peer network applications.</p> <p>Hope you'll find it helpful in your journey of learning. Happy coding! ;)</p>"},{"location":"tutorial_1_connect/#before-you-start","title":"Before you start","text":"<p>TheonlyprerequisitehereisNim,theprogramminglanguagewithaPython-likesyntaxandaperformancesimilartoC.Detailedinformationcanbefoundhere.</p><p>InstallNimviatheirofficialwebsite.CheckNim'sinstallationvia<code>nim--version</code>anditspackagemanagerNimblevia<code>nimble--version</code>.</p><p>Youcannowinstallthelatestversionof<code>n