Skip to content

Commit 37e260f

Browse files
feat: ignore unknown multiaddress protocol #38
1 parent 97c4ab7 commit 37e260f

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/CoreApi/BootstrapApi.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ internal BootstrapApi(IpfsClient ipfs)
3737
var json = await ipfs.DoCommandAsync("bootstrap/add/default", cancel);
3838
var addrs = (JArray)(JObject.Parse(json)["Peers"]);
3939
return addrs
40-
.Select(a => new MultiAddress((string)a));
40+
.Select(a => MultiAddress.TryCreate((string)a))
41+
.Where(ma => ma != null);
4142
}
4243

4344
public async Task<IEnumerable<MultiAddress>> ListAsync(CancellationToken cancel = default(CancellationToken))
4445
{
4546
var json = await ipfs.DoCommandAsync("bootstrap/list", cancel);
4647
var addrs = (JArray)(JObject.Parse(json)["Peers"]);
4748
return addrs
48-
.Select(a => new MultiAddress((string)a));
49+
.Select(a => MultiAddress.TryCreate((string)a))
50+
.Where(ma => ma != null);
4951
}
5052

5153
public Task RemoveAllAsync(CancellationToken cancel = default(CancellationToken))

src/CoreApi/SwarmApi.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ internal SwarmApi(IpfsClient ipfs)
3030
.Select(p => new Peer {
3131
Id = p.Name,
3232
Addresses = ((JArray)p.Value)
33-
.Where(v => !string.IsNullOrWhiteSpace((string)v))
34-
.Select(v => new MultiAddress((string)v))
35-
});
33+
.Select(a => MultiAddress.TryCreate((string)a))
34+
.Where(ma => ma != null)
35+
});
3636
}
3737

3838
public async Task<IEnumerable<Peer>> PeersAsync(CancellationToken cancel = default(CancellationToken))
@@ -110,7 +110,9 @@ internal SwarmApi(IpfsClient ipfs)
110110

111111
if (addrs == null)
112112
return new MultiAddress[0];
113-
return addrs.Select(a => new MultiAddress((string)a));
113+
return addrs
114+
.Select(a => MultiAddress.TryCreate((string)a))
115+
.Where(ma => ma != null);
114116
}
115117

116118
public async Task<MultiAddress> RemoveAddressFilterAsync(MultiAddress address, bool persist = false, CancellationToken cancel = default(CancellationToken))

src/IpfsApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Ipfs.Core" Version="0.29.1" />
30+
<PackageReference Include="Ipfs.Core" Version="0.30.0" />
3131
<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'" />

0 commit comments

Comments
 (0)