Skip to content

Commit

Permalink
kademlia multiple protocols (#219)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <[email protected]>
  • Loading branch information
turuslan authored Oct 12, 2023
1 parent 28f3bf0 commit ac2eec9
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 13 deletions.
4 changes: 1 addition & 3 deletions include/libp2p/protocol/kademlia/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

#include <chrono>

#include <libp2p/basic/scheduler.hpp>
#include <libp2p/peer/peer_id.hpp>
#include <libp2p/peer/peer_info.hpp>
#include <libp2p/peer/protocol.hpp>
#include <libp2p/basic/scheduler.hpp>
#include <libp2p/protocol/kademlia/content_id.hpp>
#include <libp2p/protocol/kademlia/content_value.hpp>

Expand All @@ -21,7 +20,6 @@ namespace libp2p::protocol::kademlia {

using peer::PeerId;
using peer::PeerInfo;
using peer::ProtocolName;

using Key = ContentId;
using Value = ContentValue;
Expand Down
5 changes: 3 additions & 2 deletions include/libp2p/protocol/kademlia/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define LIBP2P_PROTOCOL_KADEMLIA_CONFIG

#include <libp2p/outcome/outcome.hpp>
#include <libp2p/peer/stream_protocols.hpp>
#include <libp2p/protocol/kademlia/common.hpp>

namespace libp2p::protocol::kademlia {
Expand Down Expand Up @@ -51,10 +52,10 @@ namespace libp2p::protocol::kademlia {
Config() = default;

/**
* @returns kademlia protocol id
* @returns kademlia protocol ids
* @note Default: "ipfs/kad/1.0"
*/
peer::ProtocolName protocolId = "/ipfs/kad/1.0.0";
StreamProtocols protocols = {"/ipfs/kad/1.0.0"};

/**
* True if application is not announce himself
Expand Down
1 change: 0 additions & 1 deletion include/libp2p/protocol/kademlia/impl/kademlia_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ namespace libp2p::protocol::kademlia {

// --- Secondary ---

const ProtocolName &protocol_;
const PeerId self_id_;

// --- Auxiliary ---
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/kademlia/impl/add_provider_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace libp2p::protocol::kademlia {
config_.connectionTimeout);

host_->newStream(
peer_info, {config_.protocolId},
peer_info, config_.protocols,
[holder](auto &&stream_res) {
if (holder->first) {
holder->second.cancel();
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/kademlia/impl/find_peer_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace libp2p::protocol::kademlia {
config_.connectionTimeout);

host_->newStream(
peer_info, {config_.protocolId},
peer_info, config_.protocols,
[holder](auto &&stream_res) {
if (holder->first) {
holder->second.cancel();
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/kademlia/impl/find_providers_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace libp2p::protocol::kademlia {
config_.connectionTimeout);

host_->newStream(
peer_info, {config_.protocolId},
peer_info, config_.protocols,
[holder](auto &&stream_res) {
if (holder->first) {
holder->second.cancel();
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/kademlia/impl/get_value_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace libp2p::protocol::kademlia {
config_.connectionTimeout);

host_->newStream(
peer_info, {config_.protocolId},
peer_info, config_.protocols,
[holder](auto &&stream_res) {
if (holder->first) {
holder->second.cancel();
Expand Down
3 changes: 1 addition & 2 deletions src/protocol/kademlia/impl/kademlia_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace libp2p::protocol::kademlia {
scheduler_(std::move(scheduler)),
bus_(std::move(bus)),
random_generator_(std::move(random_generator)),
protocol_(config_.protocolId),
self_id_(host_->getId()),
log_("Kademlia", "kademlia") {
BOOST_ASSERT(host_ != nullptr);
Expand All @@ -68,7 +67,7 @@ namespace libp2p::protocol::kademlia {

// handle streams for observed protocol
host_->setProtocolHandler(
{protocol_}, [wp = weak_from_this()](StreamAndProtocol stream) {
config_.protocols, [wp = weak_from_this()](StreamAndProtocol stream) {
if (auto self = wp.lock()) {
self->handleProtocol(std::move(stream));
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/kademlia/impl/put_value_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace libp2p::protocol::kademlia {
config_.connectionTimeout);

host_->newStream(
peer_info, {config_.protocolId},
peer_info, config_.protocols,
[holder](auto &&stream_res) {
if (holder->first) {
holder->second.cancel();
Expand Down

0 comments on commit ac2eec9

Please sign in to comment.