Skip to content

Commit 0670f24

Browse files
committed
fix build issues
1 parent 5f09f7c commit 0670f24

File tree

10 files changed

+466
-98
lines changed

10 files changed

+466
-98
lines changed

src/libp2p/Libp2p.Core.TestsBase/LocalPeerStub.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public Task<ISession> DialAsync(PeerId peerId, CancellationToken token = default
3737
throw new NotImplementedException();
3838
}
3939

40+
public T? GetProtocol<T>() where T : class, IProtocol
41+
{
42+
return default(T);
43+
}
44+
4045
public ValueTask DisposeAsync()
4146
{
4247
return ValueTask.CompletedTask;

src/libp2p/Libp2p.Core/ILocalPeer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public interface ILocalPeer : IAsyncDisposable
2020

2121
Task StartListenAsync(Multiaddress[]? addrs = default, CancellationToken token = default);
2222

23+
/// <summary>
24+
/// Get a protocol instance by type.
25+
/// </summary>
26+
/// <typeparam name="T">The protocol type to retrieve.</typeparam>
27+
/// <returns>The protocol instance, or null if not found.</returns>
28+
T? GetProtocol<T>() where T : class, IProtocol;
2329

2430
ObservableCollection<Multiaddress> ListenAddresses { get; }
2531

src/libp2p/Libp2p.Core/Peer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ internal IEnumerable<IProtocol> GetProtocolsFor(ProtocolRef protocol)
210210
return _protocolStackSettings.Protocols?.Keys.FirstOrDefault(p => p.Protocol.GetType() == typeof(TProtocol))?.Protocol;
211211
}
212212

213+
/// <summary>
214+
/// Get a protocol instance by type.
215+
/// </summary>
216+
/// <typeparam name="T">The protocol type to retrieve.</typeparam>
217+
/// <returns>The protocol instance, or null if not found.</returns>
218+
public T? GetProtocol<T>() where T : class, IProtocol
219+
{
220+
return GetProtocolInstance<T>() as T;
221+
}
222+
213223
public async Task<ISession> DialAsync(Multiaddress[] addrs, CancellationToken token)
214224
{
215225
PeerId? remotePeerId = addrs.FirstOrDefault()?.GetPeerId();

src/libp2p/Libp2p.Protocols.KadDht/Integration/KadDhtIntegrationExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ public static IPeerFactoryBuilder AddKadDht(
8383
/// <returns>A DhtNode instance.</returns>
8484
// Conversion retained for potential future usage with full integration
8585
public static DhtNode ToDhtNode(this PeerId peerId, IEnumerable<string>? multiaddrs = null)
86-
=> new DhtNode(peerId, new Kademlia.PublicKey(peerId.Bytes.ToArray()), multiaddrs);
86+
=> new DhtNode
87+
{
88+
PeerId = peerId,
89+
PublicKey = new Kademlia.PublicKey(peerId.Bytes.ToArray()),
90+
Multiaddrs = multiaddrs?.ToArray() ?? Array.Empty<string>()
91+
};
8792

8893
/// <summary>
8994
/// Bootstrap and run the DHT in the background.

src/libp2p/Libp2p.Protocols.KadDht/Integration/TypeAdapters.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static DhtNode ToDhtNode(this PeerId peerId)
4545
/// </summary>
4646
public static TestNode ToTestNode(this DhtNode dhtNode)
4747
{
48-
return new TestNode { Id = dhtNode.PublicKey };
48+
return new TestNode(dhtNode.PeerId);
4949
}
5050

5151
/// <summary>
@@ -55,8 +55,8 @@ public static DhtNode ToDhtNode(this TestNode testNode)
5555
{
5656
return new DhtNode
5757
{
58-
PeerId = testNode.Id.ToPeerId(),
59-
PublicKey = testNode.Id
58+
PeerId = testNode.Id,
59+
PublicKey = testNode.Id.ToKademliaKey()
6060
};
6161
}
6262
}

src/libp2p/Libp2p.Protocols.KadDht/Kademlia/PublicKeyKeyOperator.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
22
// SPDX-License-Identifier: LGPL-3.0-only
33

4+
using Libp2p.Protocols.KadDht.Integration;
5+
using Nethermind.Libp2p.Core;
6+
47
namespace Libp2p.Protocols.KadDht.Kademlia;
58

6-
public class PublicKeyKeyOperator : IKeyOperator<PublicKey, ValueHash256, TestNode>
9+
public class PublicKeyKeyOperator : IKeyOperator<PublicKey, ValueHash256, global::Libp2p.Protocols.KadDht.TestNode>
710
{
8-
public PublicKey GetKey(TestNode node) => node.Id;
11+
public PublicKey GetKey(global::Libp2p.Protocols.KadDht.TestNode node)
12+
{
13+
var peerId = node.Id;
14+
return TypeAdapters.ToKademliaKey(peerId);
15+
}
916

1017
public ValueHash256 GetKeyHash(PublicKey key) => key.Hash;
1118

src/libp2p/Libp2p.Protocols.KadDht/Session/KademliaSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public async Task<TNode[]> DiscoverAsync<TNode>(object targetKey, CancellationTo
7575
_config.KSize,
7676
async (nextNode, token) =>
7777
{
78-
if (_keyOperator.GetKeyHash(nextNode.Id).Equals(currentNodeIdAsHash))
78+
if (_keyOperator.GetNodeHash(nextNode).Equals(currentNodeIdAsHash))
7979
{
8080
ValueHash256 keyHash = _keyOperator.GetKeyHash(key);
8181
return _routingTable.GetKNearestNeighbour(keyHash);

src/samples/kad-dht-demo/KadDhtDemo.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
12-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<ProjectReference Include="..\..\libp2p\Libp2p.Protocols.KadDht\Kademlia\Libp2p.Protocols.KadDht.Kademlia.csproj" />
16+
<ProjectReference Include="..\..\libp2p\Libp2p.Protocols.KadDht\Libp2p.Protocols.KadDht.csproj" />
1717
</ItemGroup>
1818

1919
</Project>

0 commit comments

Comments
 (0)