Skip to content

Commit 7bff3d0

Browse files
feat(BitswapApi): UnwantAsync
1 parent b32dcb0 commit 7bff3d0

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ More information, including the Class Reference, is on the [Project](https://ric
1616
- Targets .NET Framework 4.5, .NET Standard 1.4 and .NET Standard 2.0
1717
- [Asynchronous I/O](https://richardschneider.github.io/net-ipfs-api/articles/async.html) to an IPFS server
1818
- Supports [cancellation](https://richardschneider.github.io/net-ipfs-api/articles/cancellation.html) of all requests to the IPFS Server
19+
- Requests that all responses are compressed
1920
- Comprehensive [documentation](https://richardschneider.github.io/net-ipfs-api)
2021
- C# style access to the [ipfs core interface](https://richardschneider.github.io/net-ipfs-core/api/Ipfs.CoreApi.html)
2122
- [Bitswap API](https://richardschneider.github.io/net-ipfs-core/api/Ipfs.CoreApi.IBitswapApi.html)

src/CoreApi/BitswapApi.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ internal BitswapApi(IpfsClient ipfs)
4040
var obj = (JObject)k;
4141
return Cid.Decode(obj["/"].ToString());
4242
});
43-
43+
}
44+
45+
public async Task UnwantAsync(Cid id, CancellationToken cancel = default(CancellationToken))
46+
{
47+
await ipfs.DoCommandAsync("bitswap/unwant", cancel, id);
4448
}
4549
}
4650

src/IpfsApi.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Ipfs.Core" Version="0.27.4" />
31-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
30+
<PackageReference Include="Ipfs.Core" Version="0.28.1" />
31+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
3232
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'netstandard14'" />
3333
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'net45'" />
3434
</ItemGroup>

test/CoreApi/BitswapApiTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,28 @@ public async Task Wants()
3232
Assert.Fail("wanted block is missing");
3333
}
3434

35+
[TestMethod]
36+
[Ignore("doesn't work on go ipfs")]
37+
public async Task Unwant()
38+
{
39+
var block = new DagNode(Encoding.UTF8.GetBytes("BitswapApiTest unknown block 2"));
40+
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
41+
Task.Run(() => ipfs.Bitswap.GetAsync(block.Id).Wait());
42+
43+
var endTime = DateTime.Now.AddSeconds(10);
44+
while (true)
45+
{
46+
if (DateTime.Now > endTime)
47+
Assert.Fail("wanted block is missing");
48+
await Task.Delay(100);
49+
var w = await ipfs.Bitswap.WantsAsync();
50+
if (w.Contains(block.Id))
51+
break;
52+
}
53+
54+
await ipfs.Bitswap.UnwantAsync(block.Id);
55+
var wants = await ipfs.Bitswap.WantsAsync();
56+
CollectionAssert.DoesNotContain(wants.ToArray(), block.Id);
57+
}
3558
}
3659
}

0 commit comments

Comments
 (0)