Browse Source

Fix examples (#119)

Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
pull/120/head
Dmitriy Khaustov 4 years ago
committed by GitHub
parent
commit
8732a78525
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      example/01-echo/libp2p_echo_client.cpp
  2. 37
      example/01-echo/libp2p_echo_server.cpp
  3. 2
      example/03-gossip/gossip_chat_example.cpp
  4. 2
      example/04-dnstxt/ares_resolver.cpp

2
example/01-echo/libp2p_echo_client.cpp

@ -25,7 +25,7 @@ groups:
- name: main
sink: console
level: info
children
children:
- name: libp2p
# ----------------
)");

37
example/01-echo/libp2p_echo_server.cpp

@ -11,10 +11,29 @@
#include <libp2p/common/literals.hpp>
#include <libp2p/host/basic_host.hpp>
#include <libp2p/injector/host_injector.hpp>
#include <libp2p/log/configurator.hpp>
#include <libp2p/log/logger.hpp>
#include <libp2p/protocol/echo.hpp>
#include <libp2p/security/noise.hpp>
#include <libp2p/security/plaintext.hpp>
namespace {
const std::string logger_config(R"(
# ----------------
sinks:
- name: console
type: console
color: true
groups:
- name: main
sink: console
level: info
children:
- name: libp2p
# ----------------
)");
} // namespace
bool isInsecure(int argc, char **argv) {
if (2 == argc) {
const std::string insecure{"-insecure"};
@ -56,6 +75,24 @@ int main(int argc, char **argv) {
using libp2p::crypto::PublicKey;
using libp2p::common::operator""_unhex;
// prepare log system
auto logging_system = std::make_shared<soralog::LoggingSystem>(
std::make_shared<libp2p::log::Configurator>(logger_config));
auto r = logging_system->configure();
if (not r.message.empty()) {
(r.has_error ? std::cerr : std::cout) << r.message << std::endl;
}
if (r.has_error) {
exit(EXIT_FAILURE);
}
libp2p::log::setLoggingSystem(logging_system);
if (std::getenv("TRACE_DEBUG") != nullptr) {
libp2p::log::setLevelOfGroup("*", soralog::Level::TRACE);
} else {
libp2p::log::setLevelOfGroup("*", soralog::Level::ERROR);
}
// resulting PeerId should be
// 12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV
KeyPair keypair{PublicKey{{Key::Type::Ed25519,

2
example/03-gossip/gossip_chat_example.cpp

@ -43,7 +43,7 @@ groups:
- name: main
sink: console
level: info
children
children:
- name: libp2p
# ----------------
)");

2
example/04-dnstxt/ares_resolver.cpp

@ -23,7 +23,7 @@ groups:
- name: main
sink: console
level: info
children
children:
- name: libp2p
# ----------------
)");

Loading…
Cancel
Save