public async Task Can_Dispose() { using (var node = new TempNode()) { await node.StartAsync(); } }
public async Task Can_Use_Private_Node() { using (var ipfs = new TempNode()) { ipfs.Options.Discovery.BootstrapPeers = new MultiAddress[0]; ipfs.Options.Swarm.PrivateNetworkKey = new PreSharedKey().Generate(); await ipfs.StartAsync(); } }
public async Task Read_From_OtherNode() { using (var a = new TempNode()) using (var b = new TempNode()) using (var c = new TempNode()) { var psk = new PeerTalk.Cryptography.PreSharedKey().Generate(); // Start bootstrap node. b.Options.Discovery.DisableMdns = true; b.Options.Swarm.MinConnections = 0; b.Options.Swarm.PrivateNetworkKey = psk; b.Options.Discovery.BootstrapPeers = new MultiAddress[0]; await b.StartAsync(); var bootstrapPeers = new MultiAddress[] { (await b.LocalPeer).Addresses.First() }; Console.WriteLine($"B is {await b.LocalPeer}"); // Node that has the content. c.Options.Discovery.DisableMdns = true; c.Options.Swarm.MinConnections = 0; c.Options.Swarm.PrivateNetworkKey = psk; c.Options.Discovery.BootstrapPeers = bootstrapPeers; await c.StartAsync(); await c.Swarm.ConnectAsync(bootstrapPeers[0]); Console.WriteLine($"C is {await c.LocalPeer}"); var fsn = await c.FileSystem.AddTextAsync("some content"); var cid = fsn.Id; // Node that reads the content. a.Options.Discovery.DisableMdns = true; a.Options.Swarm.MinConnections = 0; a.Options.Swarm.PrivateNetworkKey = psk; a.Options.Discovery.BootstrapPeers = bootstrapPeers; await a.StartAsync(); Console.WriteLine($"A is {await a.LocalPeer}"); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var content = await a.FileSystem.ReadAllTextAsync(cid, cts.Token); Assert.AreEqual("some content", content); } }