diff --git a/tutorial/tutorial_10_peerstore.cpp b/tutorial/tutorial_10_peerstore.cpp index 330b4c9..99a9848 100644 --- a/tutorial/tutorial_10_peerstore.cpp +++ b/tutorial/tutorial_10_peerstore.cpp @@ -40,12 +40,16 @@ int main() Libp2pModuleImpl node(opts); Libp2pModuleImpl remote(remoteOpts); - if (!node.start().success) { - fprintf(stderr, "Node failed to start\n"); + StdLogosResult startRes = node.start(); + if (!startRes.success) { + fprintf(stderr, "Node failed to start: %s\n", + startRes.error.c_str()); return 1; } - if (!remote.start().success) { - fprintf(stderr, "Remote node failed to start\n"); + StdLogosResult remoteStartRes = remote.start(); + if (!remoteStartRes.success) { + fprintf(stderr, "Remote node failed to start: %s\n", + remoteStartRes.error.c_str()); return 1; } @@ -95,8 +99,10 @@ int main() /// `peerstoreGetPeerInfo()` returns a rich JSON object with addresses, /// protocols, and the public key. printf("\nConnecting to remote peer...\n"); - if (!node.connectPeer(remotePeerId, remoteAddrs, 5000).success) { - fprintf(stderr, "Failed to connect to remote peer\n"); + StdLogosResult connectRes = node.connectPeer(remotePeerId, remoteAddrs, 5000); + if (!connectRes.success) { + fprintf(stderr, "Failed to connect to remote peer: %s\n", + connectRes.error.c_str()); return 1; } printf("Connected to remote peer\n"); @@ -142,9 +148,11 @@ int main() "/examples/echo/1.0.0", }; - if (!node.peerstoreAddPeer(manualPeerId, manualAddrs, manualProtos) - .success) { - fprintf(stderr, "Failed to add peer\n"); + StdLogosResult addPeerRes = + node.peerstoreAddPeer(manualPeerId, manualAddrs, manualProtos); + if (!addPeerRes.success) { + fprintf(stderr, "Failed to add peer: %s\n", + addPeerRes.error.c_str()); return 1; } printf("Peer added: %s\n", manualPeerId.c_str()); @@ -171,9 +179,11 @@ int main() "/ip4/192.168.1.100/tcp/9002", "/dns4/peer.example.com/tcp/9000", }; - if (!node.peerstoreSetPeerAddresses(manualPeerId, updatedAddrs) - .success) { - fprintf(stderr, "Failed to update addresses\n"); + StdLogosResult updateAddrsRes = + node.peerstoreSetPeerAddresses(manualPeerId, updatedAddrs); + if (!updateAddrsRes.success) { + fprintf(stderr, "Failed to update addresses: %s\n", + updateAddrsRes.error.c_str()); return 1; } printf("Addresses updated\n"); @@ -194,8 +204,10 @@ int main() /// /// `peerstoreDeletePeer()` removes a peer and all its metadata. printf("\nDeleting peer from store...\n"); - if (!node.peerstoreDeletePeer(manualPeerId).success) { - fprintf(stderr, "Failed to delete peer\n"); + StdLogosResult deletePeerRes = node.peerstoreDeletePeer(manualPeerId); + if (!deletePeerRes.success) { + fprintf(stderr, "Failed to delete peer: %s\n", + deletePeerRes.error.c_str()); return 1; } printf("Peer deleted\n"); diff --git a/tutorial/tutorial_11_circuit_relay.cpp b/tutorial/tutorial_11_circuit_relay.cpp index e2e20cb..436d4ca 100644 --- a/tutorial/tutorial_11_circuit_relay.cpp +++ b/tutorial/tutorial_11_circuit_relay.cpp @@ -74,18 +74,23 @@ int main() printf("Starting nodes...\n"); - if (!relay.start().success) { - fprintf(stderr, "Relay failed\n"); + StdLogosResult relayStartRes = relay.start(); + if (!relayStartRes.success) { + fprintf(stderr, "Relay failed: %s\n", relayStartRes.error.c_str()); return 1; } - if (!dest.start().success) { - fprintf(stderr, "Destination failed\n"); + StdLogosResult destStartRes = dest.start(); + if (!destStartRes.success) { + fprintf(stderr, "Destination failed: %s\n", + destStartRes.error.c_str()); return 1; } - if (!client.start().success) { - fprintf(stderr, "Client failed\n"); + StdLogosResult clientStartRes = client.start(); + if (!clientStartRes.success) { + fprintf(stderr, "Client failed: %s\n", + clientStartRes.error.c_str()); return 1; } printf("All three nodes started\n"); @@ -121,8 +126,11 @@ int main() /// `circuitRelayReserve()` to request a reservation. The relay /// returns the addresses the Destination can be reached at (via relay). printf("\nDestination connecting to relay...\n"); - if (!dest.connectPeer(relayPeerId, relayAddrs, 5000).success) { - fprintf(stderr, "Destination failed to connect to relay\n"); + StdLogosResult destConnectRes = + dest.connectPeer(relayPeerId, relayAddrs, 5000); + if (!destConnectRes.success) { + fprintf(stderr, "Destination failed to connect to relay: %s\n", + destConnectRes.error.c_str()); return 1; } printf("Destination connected to relay\n"); @@ -150,8 +158,11 @@ int main() /// The Client connects to the Relay (same as any other peer), then /// uses `dialCircuitRelay()` to reach the Destination through the Relay. printf("\nClient connecting to relay...\n"); - if (!client.connectPeer(relayPeerId, relayAddrs, 5000).success) { - fprintf(stderr, "Client failed to connect to relay\n"); + StdLogosResult clientConnectRes = + client.connectPeer(relayPeerId, relayAddrs, 5000); + if (!clientConnectRes.success) { + fprintf(stderr, "Client failed to connect to relay: %s\n", + clientConnectRes.error.c_str()); return 1; } printf("Client connected to relay\n"); @@ -187,8 +198,9 @@ int main() std::string payload(32, '\0'); for (int i = 0; i < 32; ++i) payload[i] = static_cast(i); - if (!client.streamWrite(streamId, payload).success) { - fprintf(stderr, "Write failed\n"); + StdLogosResult writeRes = client.streamWrite(streamId, payload); + if (!writeRes.success) { + fprintf(stderr, "Write failed: %s\n", writeRes.error.c_str()); return 1; } printf("Sent %zu bytes through relay\n", payload.size()); diff --git a/tutorial/tutorial_1_node_lifecycle.cpp b/tutorial/tutorial_1_node_lifecycle.cpp index 6585838..4381096 100644 --- a/tutorial/tutorial_1_node_lifecycle.cpp +++ b/tutorial/tutorial_1_node_lifecycle.cpp @@ -42,8 +42,10 @@ int main() /// Calling `start()` creates the libp2p context, binds the configured /// address, and begins accepting connections. - if (!node.start().success) { - fprintf(stderr, "Failed to start node\n"); + StdLogosResult startRes = node.start(); + if (!startRes.success) { + fprintf(stderr, "Failed to start node: %s\n", + startRes.error.c_str()); return 1; } diff --git a/tutorial/tutorial_2_custom_config.cpp b/tutorial/tutorial_2_custom_config.cpp index 345aa29..e2407b9 100644 --- a/tutorial/tutorial_2_custom_config.cpp +++ b/tutorial/tutorial_2_custom_config.cpp @@ -61,8 +61,10 @@ int main() Libp2pModuleImpl node(options); - if (!node.start().success) { - fprintf(stderr, "Failed to start node\n"); + StdLogosResult startRes = node.start(); + if (!startRes.success) { + fprintf(stderr, "Failed to start node: %s\n", + startRes.error.c_str()); return 1; } @@ -115,8 +117,10 @@ int main() Libp2pModuleImpl nodeFromJson(jsonOpts); - if (!nodeFromJson.start().success) { - fprintf(stderr, "Failed to start JSON-configured node\n"); + StdLogosResult jsonStartRes = nodeFromJson.start(); + if (!jsonStartRes.success) { + fprintf(stderr, "Failed to start JSON-configured node: %s\n", + jsonStartRes.error.c_str()); return 1; } diff --git a/tutorial/tutorial_3_connecting_peers.cpp b/tutorial/tutorial_3_connecting_peers.cpp index 2c15fd2..1822ba6 100644 --- a/tutorial/tutorial_3_connecting_peers.cpp +++ b/tutorial/tutorial_3_connecting_peers.cpp @@ -59,14 +59,18 @@ int main() Libp2pModuleImpl nodeA(optsA); Libp2pModuleImpl nodeB(optsB); - if (!nodeA.start().success) { - fprintf(stderr, "Node A failed to start\n"); + StdLogosResult startARes = nodeA.start(); + if (!startARes.success) { + fprintf(stderr, "Node A failed to start: %s\n", + startARes.error.c_str()); return 1; } printf("Node A started\n"); - if (!nodeB.start().success) { - fprintf(stderr, "Node B failed to start\n"); + StdLogosResult startBRes = nodeB.start(); + if (!startBRes.success) { + fprintf(stderr, "Node B failed to start: %s\n", + startBRes.error.c_str()); return 1; } printf("Node B started\n"); @@ -99,8 +103,10 @@ int main() /// `connectPeer()` establishes the transport connection. The timeout /// parameter is in milliseconds. printf("\nConnecting Node B to Node A...\n"); - if (!nodeB.connectPeer(peerIdA, addrsA, 5000).success) { - fprintf(stderr, "Failed to connect\n"); + StdLogosResult connectRes = nodeB.connectPeer(peerIdA, addrsA, 5000); + if (!connectRes.success) { + fprintf(stderr, "Failed to connect: %s\n", + connectRes.error.c_str()); return 1; } printf("Connected!\n"); @@ -158,8 +164,9 @@ int main() } printf("Sending %zu bytes...\n", payload.size()); - if (!nodeB.streamWrite(streamId, payload).success) { - fprintf(stderr, "Write failed\n"); + StdLogosResult writeRes = nodeB.streamWrite(streamId, payload); + if (!writeRes.success) { + fprintf(stderr, "Write failed: %s\n", writeRes.error.c_str()); return 1; } diff --git a/tutorial/tutorial_4_custom_protocol.cpp b/tutorial/tutorial_4_custom_protocol.cpp index cf1afa7..d14fe2f 100644 --- a/tutorial/tutorial_4_custom_protocol.cpp +++ b/tutorial/tutorial_4_custom_protocol.cpp @@ -62,8 +62,16 @@ int main() Libp2pModuleImpl nodeA(optsA); Libp2pModuleImpl nodeB(optsB); - if (!nodeA.start().success) { fprintf(stderr, "Node A failed\n"); return 1; } - if (!nodeB.start().success) { fprintf(stderr, "Node B failed\n"); return 1; } + StdLogosResult startARes = nodeA.start(); + if (!startARes.success) { + fprintf(stderr, "Node A failed: %s\n", startARes.error.c_str()); + return 1; + } + StdLogosResult startBRes = nodeB.start(); + if (!startBRes.success) { + fprintf(stderr, "Node B failed: %s\n", startBRes.error.c_str()); + return 1; + } printf("Both nodes started\n"); /// ## Step 2: Set up the protocol handler on Node A @@ -99,8 +107,10 @@ int main() /// Register the echo protocol on Node A: printf("Mounting protocol '%s' on Node A...\n", kEchoProtocol.c_str()); - if (!nodeA.mountProtocol(kEchoProtocol).success) { - fprintf(stderr, "Failed to mount protocol\n"); + StdLogosResult mountRes = nodeA.mountProtocol(kEchoProtocol); + if (!mountRes.success) { + fprintf(stderr, "Failed to mount protocol: %s\n", + mountRes.error.c_str()); return 1; } @@ -118,8 +128,10 @@ int main() addrsA.push_back(a.get()); printf("Connecting Node B to Node A...\n"); - if (!nodeB.connectPeer(peerIdA, addrsA, 5000).success) { - fprintf(stderr, "Failed to connect\n"); + StdLogosResult connectRes = nodeB.connectPeer(peerIdA, addrsA, 5000); + if (!connectRes.success) { + fprintf(stderr, "Failed to connect: %s\n", + connectRes.error.c_str()); return 1; } printf("Connected\n"); @@ -155,8 +167,9 @@ int main() /// ## Step 6: Node B sends a message std::string message = "Hello from Node B!"; printf("Node B sending: \"%s\"\n", message.c_str()); - if (!nodeB.streamWriteLp(clientStreamId, message).success) { - fprintf(stderr, "Write failed\n"); + StdLogosResult writeRes = nodeB.streamWriteLp(clientStreamId, message); + if (!writeRes.success) { + fprintf(stderr, "Write failed: %s\n", writeRes.error.c_str()); return 1; } @@ -171,8 +184,10 @@ int main() printf("Node A received: \"%s\"\n", received.c_str()); /// Echo it back: - if (!nodeA.streamWriteLp(serverStreamId, received).success) { - fprintf(stderr, "Node A echo write failed\n"); + StdLogosResult echoWriteRes = nodeA.streamWriteLp(serverStreamId, received); + if (!echoWriteRes.success) { + fprintf(stderr, "Node A echo write failed: %s\n", + echoWriteRes.error.c_str()); return 1; } diff --git a/tutorial/tutorial_5_kademlia_basics.cpp b/tutorial/tutorial_5_kademlia_basics.cpp index 58e6dd5..f50297a 100644 --- a/tutorial/tutorial_5_kademlia_basics.cpp +++ b/tutorial/tutorial_5_kademlia_basics.cpp @@ -53,8 +53,10 @@ int main() Libp2pModuleImpl nodeA(optsA); printf("Starting Node A (bootstrap)...\n"); - if (!nodeA.start().success) { - fprintf(stderr, "Node A failed to start\n"); + StdLogosResult startARes = nodeA.start(); + if (!startARes.success) { + fprintf(stderr, "Node A failed to start: %s\n", + startARes.error.c_str()); return 1; } @@ -80,15 +82,19 @@ int main() Libp2pModuleImpl nodeB(optsB); printf("Starting Node B (with Node A as bootstrap)...\n"); - if (!nodeB.start().success) { - fprintf(stderr, "Node B failed to start\n"); + StdLogosResult startBRes = nodeB.start(); + if (!startBRes.success) { + fprintf(stderr, "Node B failed to start: %s\n", + startBRes.error.c_str()); return 1; } // Connect Node B to Node A so they can participate in the DHT printf("Connecting Node B to Node A...\n"); - if (!nodeB.connectPeer(peerIdA, addrsA, 5000).success) { - fprintf(stderr, "Failed to connect\n"); + StdLogosResult connectRes = nodeB.connectPeer(peerIdA, addrsA, 5000); + if (!connectRes.success) { + fprintf(stderr, "Failed to connect: %s\n", + connectRes.error.c_str()); return 1; } printf("Nodes connected\n"); @@ -104,8 +110,9 @@ int main() printf(" Key: \"%s\"\n", key.c_str()); printf(" Value: \"%s\"\n", value.c_str()); - if (!nodeA.kadPutValue(key, value).success) { - fprintf(stderr, "PutValue failed\n"); + StdLogosResult putRes = nodeA.kadPutValue(key, value); + if (!putRes.success) { + fprintf(stderr, "PutValue failed: %s\n", putRes.error.c_str()); return 1; } printf("Value stored!\n"); diff --git a/tutorial/tutorial_6_kademlia_providers.cpp b/tutorial/tutorial_6_kademlia_providers.cpp index f359cd0..c73fc5e 100644 --- a/tutorial/tutorial_6_kademlia_providers.cpp +++ b/tutorial/tutorial_6_kademlia_providers.cpp @@ -42,8 +42,9 @@ int main() Libp2pModuleImpl nodeA(optsA); - if (!nodeA.start().success) { - fprintf(stderr, "Node A failed\n"); + StdLogosResult startARes = nodeA.start(); + if (!startARes.success) { + fprintf(stderr, "Node A failed: %s\n", startARes.error.c_str()); return 1; } @@ -64,13 +65,16 @@ int main() optsB.mountKad = true; optsB.bootstrapNodes = {{peerIdA, addrsA}}; Libp2pModuleImpl nodeB(optsB); - if (!nodeB.start().success) { - fprintf(stderr, "Node B failed\n"); + StdLogosResult startBRes = nodeB.start(); + if (!startBRes.success) { + fprintf(stderr, "Node B failed: %s\n", startBRes.error.c_str()); return 1; } - if (!nodeB.connectPeer(peerIdA, addrsA, 5000).success) { - fprintf(stderr, "Failed to connect\n"); + StdLogosResult connectRes = nodeB.connectPeer(peerIdA, addrsA, 5000); + if (!connectRes.success) { + fprintf(stderr, "Failed to connect: %s\n", + connectRes.error.c_str()); return 1; } printf("Nodes connected\n"); @@ -94,8 +98,10 @@ int main() /// /// This advertises to the DHT that Node A has this content. printf("\nNode A starting to provide CID...\n"); - if (!nodeA.kadStartProviding(cid).success) { - fprintf(stderr, "kadStartProviding failed\n"); + StdLogosResult startProvidingRes = nodeA.kadStartProviding(cid); + if (!startProvidingRes.success) { + fprintf(stderr, "kadStartProviding failed: %s\n", + startProvidingRes.error.c_str()); return 1; } printf("Node A is now a provider for: %s\n", cid.c_str()); diff --git a/tutorial/tutorial_7_gossipsub_polling.cpp b/tutorial/tutorial_7_gossipsub_polling.cpp index 76dccaa..a44a6cf 100644 --- a/tutorial/tutorial_7_gossipsub_polling.cpp +++ b/tutorial/tutorial_7_gossipsub_polling.cpp @@ -50,12 +50,14 @@ int main() Libp2pModuleImpl nodeA(optsA); Libp2pModuleImpl nodeB(optsB); - if (!nodeA.start().success) { - fprintf(stderr, "Node A failed\n"); + StdLogosResult startARes = nodeA.start(); + if (!startARes.success) { + fprintf(stderr, "Node A failed: %s\n", startARes.error.c_str()); return 1; } - if (!nodeB.start().success) { - fprintf(stderr, "Node B failed\n"); + StdLogosResult startBRes = nodeB.start(); + if (!startBRes.success) { + fprintf(stderr, "Node B failed: %s\n", startBRes.error.c_str()); return 1; } printf("Both nodes started\n"); @@ -76,8 +78,10 @@ int main() addrsA.push_back(a.get()); printf("Connecting Node B to Node A...\n"); - if (!nodeB.connectPeer(peerIdA, addrsA, 5000).success) { - fprintf(stderr, "Failed to connect\n"); + StdLogosResult connectRes = nodeB.connectPeer(peerIdA, addrsA, 5000); + if (!connectRes.success) { + fprintf(stderr, "Failed to connect: %s\n", + connectRes.error.c_str()); return 1; } printf("Connected\n"); @@ -88,14 +92,18 @@ int main() /// same topic will receive each other's messages. std::string topic = "chat-room-1"; printf("Node B subscribing to topic: \"%s\"\n", topic.c_str()); - if (!nodeB.gossipsubSubscribe(topic).success) { - fprintf(stderr, "Node B subscribe failed\n"); + StdLogosResult subscribeBRes = nodeB.gossipsubSubscribe(topic); + if (!subscribeBRes.success) { + fprintf(stderr, "Node B subscribe failed: %s\n", + subscribeBRes.error.c_str()); return 1; } printf("Node A subscribing to topic: \"%s\"\n", topic.c_str()); - if (!nodeA.gossipsubSubscribe(topic).success) { - fprintf(stderr, "Node A subscribe failed\n"); + StdLogosResult subscribeARes = nodeA.gossipsubSubscribe(topic); + if (!subscribeARes.success) { + fprintf(stderr, "Node A subscribe failed: %s\n", + subscribeARes.error.c_str()); return 1; } @@ -114,8 +122,9 @@ int main() printf("\nNode A publishing: \"%s\"\n", payload.c_str()); printf(" Topic: \"%s\"\n", topic.c_str()); - if (!nodeA.gossipsubPublish(topic, payload).success) { - fprintf(stderr, "Publish failed\n"); + StdLogosResult publishRes = nodeA.gossipsubPublish(topic, payload); + if (!publishRes.success) { + fprintf(stderr, "Publish failed: %s\n", publishRes.error.c_str()); return 1; } printf("Message published!\n"); diff --git a/tutorial/tutorial_8_gossipsub_event_callback.cpp b/tutorial/tutorial_8_gossipsub_event_callback.cpp index e8b994d..679471e 100644 --- a/tutorial/tutorial_8_gossipsub_event_callback.cpp +++ b/tutorial/tutorial_8_gossipsub_event_callback.cpp @@ -46,12 +46,14 @@ int main() Libp2pModuleImpl nodeA(optsA); Libp2pModuleImpl nodeB(optsB); - if (!nodeA.start().success) { - fprintf(stderr, "Node A failed\n"); + StdLogosResult startARes = nodeA.start(); + if (!startARes.success) { + fprintf(stderr, "Node A failed: %s\n", startARes.error.c_str()); return 1; } - if (!nodeB.start().success) { - fprintf(stderr, "Node B failed\n"); + StdLogosResult startBRes = nodeB.start(); + if (!startBRes.success) { + fprintf(stderr, "Node B failed: %s\n", startBRes.error.c_str()); return 1; } printf("Both nodes started\n"); @@ -70,8 +72,10 @@ int main() addrsA.push_back(a.get()); printf("Connecting Node B to Node A...\n"); - if (!nodeB.connectPeer(peerIdA, addrsA, 5000).success) { - fprintf(stderr, "Failed to connect\n"); + StdLogosResult connectRes = nodeB.connectPeer(peerIdA, addrsA, 5000); + if (!connectRes.success) { + fprintf(stderr, "Failed to connect: %s\n", + connectRes.error.c_str()); return 1; } printf("Connected\n"); @@ -107,14 +111,18 @@ int main() /// ## Step 4: Both nodes subscribe to a topic std::string topic = "chat-room-1"; printf("Node A subscribing to topic: \"%s\"\n", topic.c_str()); - if (!nodeA.gossipsubSubscribe(topic).success) { - fprintf(stderr, "Node A subscribe failed\n"); + StdLogosResult subscribeARes = nodeA.gossipsubSubscribe(topic); + if (!subscribeARes.success) { + fprintf(stderr, "Node A subscribe failed: %s\n", + subscribeARes.error.c_str()); return 1; } printf("Node B subscribing to topic: \"%s\"\n", topic.c_str()); - if (!nodeB.gossipsubSubscribe(topic).success) { - fprintf(stderr, "Node B subscribe failed\n"); + StdLogosResult subscribeBRes = nodeB.gossipsubSubscribe(topic); + if (!subscribeBRes.success) { + fprintf(stderr, "Node B subscribe failed: %s\n", + subscribeBRes.error.c_str()); return 1; } @@ -130,8 +138,9 @@ int main() printf("\nNode B publishing: \"%s\"\n", payload.c_str()); printf(" Topic: \"%s\"\n", topic.c_str()); - if (!nodeB.gossipsubPublish(topic, payload).success) { - fprintf(stderr, "Publish failed\n"); + StdLogosResult publishRes = nodeB.gossipsubPublish(topic, payload); + if (!publishRes.success) { + fprintf(stderr, "Publish failed: %s\n", publishRes.error.c_str()); return 1; } printf("Message published!\n"); diff --git a/tutorial/tutorial_9_service_discovery.cpp b/tutorial/tutorial_9_service_discovery.cpp index 3f5e079..f506fb8 100644 --- a/tutorial/tutorial_9_service_discovery.cpp +++ b/tutorial/tutorial_9_service_discovery.cpp @@ -44,12 +44,16 @@ int main() optsBootstrap.mountServiceDiscovery = true; Libp2pModuleImpl bootstrap(optsBootstrap); - if (!bootstrap.start().success) { - fprintf(stderr, "Bootstrap failed\n"); + StdLogosResult bootstrapStartRes = bootstrap.start(); + if (!bootstrapStartRes.success) { + fprintf(stderr, "Bootstrap failed: %s\n", + bootstrapStartRes.error.c_str()); return 1; } - if (!bootstrap.discoStart().success) { - fprintf(stderr, "Bootstrap discoStart failed\n"); + StdLogosResult bootstrapDiscoStartRes = bootstrap.discoStart(); + if (!bootstrapDiscoStartRes.success) { + fprintf(stderr, "Bootstrap discoStart failed: %s\n", + bootstrapDiscoStartRes.error.c_str()); return 1; } @@ -76,18 +80,25 @@ int main() optsAdvertiser.mountServiceDiscovery = true; Libp2pModuleImpl advertiser(optsAdvertiser); - if (!advertiser.start().success) { - fprintf(stderr, "Advertiser failed\n"); + StdLogosResult advertiserStartRes = advertiser.start(); + if (!advertiserStartRes.success) { + fprintf(stderr, "Advertiser failed: %s\n", + advertiserStartRes.error.c_str()); return 1; } - if (!advertiser.discoStart().success) { - fprintf(stderr, "Advertiser discoStart failed\n"); + StdLogosResult advertiserDiscoStartRes = advertiser.discoStart(); + if (!advertiserDiscoStartRes.success) { + fprintf(stderr, "Advertiser discoStart failed: %s\n", + advertiserDiscoStartRes.error.c_str()); return 1; } // Connect to bootstrap - if (!advertiser.connectPeer(bootstrapId, bootstrapAddrs, 5000).success) { - fprintf(stderr, "Advertiser failed to connect to bootstrap\n"); + StdLogosResult advertiserConnectRes = + advertiser.connectPeer(bootstrapId, bootstrapAddrs, 5000); + if (!advertiserConnectRes.success) { + fprintf(stderr, "Advertiser failed to connect to bootstrap: %s\n", + advertiserConnectRes.error.c_str()); return 1; } printf("Advertiser connected to bootstrap\n"); @@ -99,17 +110,24 @@ int main() optsDiscoverer.mountServiceDiscovery = true; Libp2pModuleImpl discoverer(optsDiscoverer); - if (!discoverer.start().success) { - fprintf(stderr, "Discoverer failed\n"); + StdLogosResult discovererStartRes = discoverer.start(); + if (!discovererStartRes.success) { + fprintf(stderr, "Discoverer failed: %s\n", + discovererStartRes.error.c_str()); return 1; } - if (!discoverer.discoStart().success) { - fprintf(stderr, "Discoverer discoStart failed\n"); + StdLogosResult discovererDiscoStartRes = discoverer.discoStart(); + if (!discovererDiscoStartRes.success) { + fprintf(stderr, "Discoverer discoStart failed: %s\n", + discovererDiscoStartRes.error.c_str()); return 1; } - if (!discoverer.connectPeer(bootstrapId, bootstrapAddrs, 5000).success) { - fprintf(stderr, "Discoverer failed to connect to bootstrap\n"); + StdLogosResult discovererConnectRes = + discoverer.connectPeer(bootstrapId, bootstrapAddrs, 5000); + if (!discovererConnectRes.success) { + fprintf(stderr, "Discoverer failed to connect to bootstrap: %s\n", + discovererConnectRes.error.c_str()); return 1; } printf("Discoverer connected to bootstrap\n"); @@ -122,8 +140,11 @@ int main() std::string serviceData = "version=1.0;capacity=100"; printf("\nAdvertiser advertising: \"%s\"\n", serviceId.c_str()); - if (!advertiser.discoStartAdvertising(serviceId, serviceData).success) { - fprintf(stderr, "discoStartAdvertising failed\n"); + StdLogosResult advertiseRes = + advertiser.discoStartAdvertising(serviceId, serviceData); + if (!advertiseRes.success) { + fprintf(stderr, "discoStartAdvertising failed: %s\n", + advertiseRes.error.c_str()); return 1; } printf("Advertising started\n"); @@ -133,8 +154,11 @@ int main() /// Registering interest tells the service discovery system that /// this peer wants to know about providers of this service. printf("Discoverer registering interest in \"%s\"\n", serviceId.c_str()); - if (!discoverer.discoRegisterInterest(serviceId).success) { - fprintf(stderr, "discoRegisterInterest failed\n"); + StdLogosResult registerInterestRes = + discoverer.discoRegisterInterest(serviceId); + if (!registerInterestRes.success) { + fprintf(stderr, "discoRegisterInterest failed: %s\n", + registerInterestRes.error.c_str()); return 1; }