Example #1
0
        public async Task Provide()
        {
            Cid cid   = "zBunRGrmCGokA1oMESGGTfrtcMFsVA8aEtcNzM54akPWXF97uXCqTjF3GZ9v8YzxHrG66J8QhtPFWwZebRZ2zeUEELu67";
            var swarm = new SwarmService {
                LocalPeer = self
            };
            var dht = new DhtService {
                SwarmService = swarm
            };
            await dht.StartAsync();

            try
            {
                await swarm.StartAsync();

                await swarm.StartListeningAsync("/ip4/127.0.0.1/tcp/0");

                await dht.ProvideAsync(cid);

                var peers = (await dht.FindProvidersAsync(cid, 1)).ToArray();
                Assert.AreEqual(1, peers.Length);
                Assert.AreEqual(self, peers[0]);
            }
            finally
            {
                await dht.StopAsync();

                await swarm.StopAsync();
            }
        }