Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ logos_module(
src/callbacks.cpp
src/kademlia.cpp
src/stream.cpp
src/mix.cpp
# src/mix.cpp # temporarily disabled — extracted to separate repo, no cbindings yet
src/gossipsub.cpp
src/service_discovery.cpp
Comment thread
rlve marked this conversation as resolved.
EXTERNAL_LIBS
Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
file(GLOB EXAMPLE_SOURCES CONFIGURE_DEPENDS *.cpp)
# mix.cpp temporarily disabled — extracted to separate repo, no cbindings yet
list(FILTER EXAMPLE_SOURCES EXCLUDE REGEX "/mix\\.cpp$")

foreach(example_src ${EXAMPLE_SOURCES})
get_filename_component(example_name ${example_src} NAME_WE)
Expand Down
10 changes: 5 additions & 5 deletions examples/service_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ int main()
return 1;
}

printf("Node B: starting discovering %s\n", serviceId.c_str());
if (!nodeB.discoStartDiscovering(serviceId).success) {
fprintf(stderr, "Node B: discoStartDiscovering failed\n");
printf("Node B: registering interest in %s\n", serviceId.c_str());
if (!nodeB.discoRegisterInterest(serviceId).success) {
fprintf(stderr, "Node B: discoRegisterInterest failed\n");
return 1;
}

Expand Down Expand Up @@ -79,8 +79,8 @@ int main()
printf("Random lookup returned %zu peer(s)\n", randRes.value.size());
}

printf("Node B: stopping discovering %s\n", serviceId.c_str());
nodeB.discoStopDiscovering(serviceId);
printf("Node B: unregistering interest in %s\n", serviceId.c_str());
nodeB.discoUnregisterInterest(serviceId);

printf("Node A: stopping advertising %s\n", serviceId.c_str());
nodeA.discoStopAdvertising(serviceId);
Expand Down
12 changes: 4 additions & 8 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ Libp2pModuleImpl::Libp2pModuleImpl(const Libp2pModuleOptions& options)

m_libp2pConfig.mount_kad = options.mountKad ? 1 : 0;
m_libp2pConfig.mount_service_discovery = options.mountServiceDiscovery ? 1 : 0;
m_libp2pConfig.mount_mix = options.mountMix ? 1 : 0;
// m_libp2pConfig.mount_mix = options.mountMix ? 1 : 0; # temporarily disabled — extracted to separate repo, no cbindings yet


// Generate private key
auto keyResult = newPrivateKey();
Expand Down
6 changes: 4 additions & 2 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Libp2pModuleImpl {
StdLogosResult kadGetProviders(const std::string& cid);
StdLogosResult kadGetRandomRecords();

#if 0 // mix temporarily disabled — extracted to separate repo, no cbindings yet
/* ----------- Mix Network ----------- */

StdLogosResult mixGeneratePrivKey();
Expand All @@ -147,6 +148,7 @@ class Libp2pModuleImpl {
const std::string& multiaddr,
const std::string& mixPubKey,
const std::string& libp2pPubKey);
#endif
Comment thread
rlve marked this conversation as resolved.

/* ----------- Service Discovery ----------- */

Expand All @@ -155,8 +157,8 @@ class Libp2pModuleImpl {
StdLogosResult discoStartAdvertising(const std::string& serviceId,
const std::string& serviceData = {});
StdLogosResult discoStopAdvertising(const std::string& serviceId);
StdLogosResult discoStartDiscovering(const std::string& serviceId);
StdLogosResult discoStopDiscovering(const std::string& serviceId);
StdLogosResult discoRegisterInterest(const std::string& serviceId);
StdLogosResult discoUnregisterInterest(const std::string& serviceId);
Comment thread
rlve marked this conversation as resolved.
StdLogosResult discoLookup(const std::string& serviceId,
const std::string& serviceData = {});
StdLogosResult discoRandomLookup();
Expand Down
16 changes: 8 additions & 8 deletions src/service_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,28 @@ StdLogosResult Libp2pModuleImpl::discoStopAdvertising(const std::string& service
return {true, {}, ""};
}

StdLogosResult Libp2pModuleImpl::discoStartDiscovering(const std::string& serviceId) {
StdLogosResult Libp2pModuleImpl::discoRegisterInterest(const std::string& serviceId) {
if (!ctx) return {false, {}, "No libp2p context"};

auto* p = new SyncPromise();
auto f = p->get_future();
int ret = libp2p_service_disco_start_discovering(ctx, serviceId.c_str(),
&Libp2pModuleImpl::promiseCallback, p);
if (ret != RET_OK) { delete p; return {false, {}, "Failed to start discovering"}; }
int ret = libp2p_service_disco_register_interest(ctx, serviceId.c_str(),
&Libp2pModuleImpl::promiseCallback, p);
if (ret != RET_OK) { delete p; return {false, {}, "Failed to register interest"}; }

auto r = awaitResult(f);
if (!r.ok) return {false, {}, r.message};
return {true, {}, ""};
}

StdLogosResult Libp2pModuleImpl::discoStopDiscovering(const std::string& serviceId) {
StdLogosResult Libp2pModuleImpl::discoUnregisterInterest(const std::string& serviceId) {
if (!ctx) return {false, {}, "No libp2p context"};

auto* p = new SyncPromise();
auto f = p->get_future();
int ret = libp2p_service_disco_stop_discovering(ctx, serviceId.c_str(),
&Libp2pModuleImpl::promiseCallback, p);
if (ret != RET_OK) { delete p; return {false, {}, "Failed to stop discovering"}; }
int ret = libp2p_service_disco_unregister_interest(ctx, serviceId.c_str(),
&Libp2pModuleImpl::promiseCallback, p);
if (ret != RET_OK) { delete p; return {false, {}, "Failed to unregister interest"}; }

auto r = awaitResult(f);
if (!r.ok) return {false, {}, r.message};
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if(LIBP2P_PATH)
../src/callbacks.cpp
../src/kademlia.cpp
../src/stream.cpp
../src/mix.cpp
# ../src/mix.cpp # temporarily disabled — extracted to separate repo, no cbindings yet
../src/gossipsub.cpp
../src/service_discovery.cpp
TEST_SOURCES
Expand All @@ -30,7 +30,7 @@ if(LIBP2P_PATH)
integration.cpp
integration_gossipsub.cpp
integration_kad.cpp
integration_mix.cpp
# integration_mix.cpp # temporarily disabled — extracted to separate repo, no cbindings yet
integration_service_discovery.cpp
EXTRA_INCLUDES
../lib
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_service_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LOGOS_TEST(disco_advertise_and_lookup) {

std::string serviceId = "test-service";
LOGOS_ASSERT_TRUE(nodeA.discoStartAdvertising(serviceId).success);
LOGOS_ASSERT_TRUE(nodeB.discoStartDiscovering(serviceId).success);
LOGOS_ASSERT_TRUE(nodeB.discoRegisterInterest(serviceId).success);

std::this_thread::sleep_for(std::chrono::milliseconds(2000));

Expand Down Expand Up @@ -96,7 +96,7 @@ LOGOS_TEST(disco_advertise_with_data) {
std::string serviceData = "version=2;proto=test";

LOGOS_ASSERT_TRUE(nodeA.discoStartAdvertising(serviceId, serviceData).success);
LOGOS_ASSERT_TRUE(nodeB.discoStartDiscovering(serviceId).success);
LOGOS_ASSERT_TRUE(nodeB.discoRegisterInterest(serviceId).success);

std::this_thread::sleep_for(std::chrono::milliseconds(2000));

Expand Down
2 changes: 2 additions & 0 deletions tests/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ LOGOS_TEST(sync_kad_random_records) {
LOGOS_ASSERT_TRUE(plugin.stop().success);
}

#if 0 // mix temporarily disabled — extracted to separate repo, no cbindings yet
Comment thread
rlve marked this conversation as resolved.
LOGOS_TEST(sync_mix_dial) {
Libp2pModuleImpl plugin;
LOGOS_ASSERT_TRUE(plugin.start().success);
Expand Down Expand Up @@ -315,3 +316,4 @@ LOGOS_TEST(sync_mix_nodepool_add) {

LOGOS_ASSERT_TRUE(plugin.stop().success);
}
#endif
Loading