aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2018-11-18 21:52:35 -0500
committerDeterminant <[email protected]>2018-11-18 21:52:35 -0500
commit35ffa2c1e5c7fba06c52e2c20aff2aac910921d5 (patch)
tree7adcea80aac36059811df618901ca38e656e282c
parentcff8386147356176228b8c56573005bca2b65d0a (diff)
...
-rw-r--r--README.rst12
-rw-r--r--include/salticidae/network.h15
-rw-r--r--include/salticidae/util.h1
-rw-r--r--src/util.cpp2
-rw-r--r--test/test_p2p_stress.cpp10
5 files changed, 30 insertions, 10 deletions
diff --git a/README.rst b/README.rst
index 23158e2..54932bb 100644
--- a/README.rst
+++ b/README.rst
@@ -1,4 +1,4 @@
-Salticidae: Minimal C++ asynchronous network library.
+Salticidae: minimal C++ asynchronous network library.
=======================================================
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
@@ -9,7 +9,7 @@ Features
--------
- Simplicity. The library is self-contained, small in code base, and only
- relies on libevent and libcrypo (OpenSSL, for SHA256 purpose).
+ relies on libuv and libcrypo (OpenSSL, for SHA256 purpose).
- Clarity. With moderate use of C++ template and new features, the vast
majority of the code is self-documenting.
@@ -17,11 +17,13 @@ Features
- Layered design. You can use network abstraction from the lowest socket
connection level to the highest P2P network level.
-- Performance. The implementation strives to incur very little overhead in processing
+- Performance. Based on a hybrid solution that combines both thread-based and
+ event-driven concurrency paradigms, it gets the best of both worlds.
+ The implementation strives to incur very little overhead in processing
network I/O, and avoid unnecessary memory copies thanks to the move semantics.
- Utilities. The library also provides with some useful gadgets, such as
- command-line parser, libevent abstraction, etc.
+ command-line parser, libuv abstraction, etc.
Functionalities
---------------
@@ -60,7 +62,7 @@ Dependencies
- CMake >= 3.9
- C++14
-- libevent
+- libuv
- libcrypto
Example (MsgNetwork layer)
diff --git a/include/salticidae/network.h b/include/salticidae/network.h
index a71c5dd..1e63efa 100644
--- a/include/salticidae/network.h
+++ b/include/salticidae/network.h
@@ -601,8 +601,19 @@ bool PeerNetwork<O, _, __>::check_new_conn(const conn_t &conn, uint16_t port) {
p->reset_ping_timer();
p->send_ping();
if (p->connected)
- SALTICIDAE_LOG_INFO("PeerNetwork: established connection with %s via %s",
- std::string(conn->peer_id).c_str(), std::string(*conn).c_str());
+ {
+ auto color_begin = "";
+ auto color_end = "";
+ if (logger.is_tty())
+ {
+ color_begin = TTY_COLOR_BLUE;
+ color_end = TTY_COLOR_RESET;
+ }
+ SALTICIDAE_LOG_INFO("%sPeerNetwork: established connection with %s via %s%s",
+ color_begin,
+ std::string(conn->peer_id).c_str(), std::string(*conn).c_str(),
+ color_end);
+ }
return false;
}
diff --git a/include/salticidae/util.h b/include/salticidae/util.h
index ed7d980..c640de7 100644
--- a/include/salticidae/util.h
+++ b/include/salticidae/util.h
@@ -101,6 +101,7 @@ class Logger {
void debug(const char *fmt, ...);
void warning(const char *fmt, ...);
void error(const char *fmt, ...);
+ bool is_tty() { return isatty(output); }
};
extern Logger logger;
diff --git a/src/util.cpp b/src/util.cpp
index d764ad5..c51e191 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -91,7 +91,7 @@ const std::string get_current_datetime() {
SalticidaeError::SalticidaeError() : msg("unknown") {}
void Logger::set_color() {
- if (isatty(output))
+ if (is_tty())
{
color_info = TTY_COLOR_GREEN;
color_debug = TTY_COLOR_BLUE;
diff --git a/test/test_p2p_stress.cpp b/test/test_p2p_stress.cpp
index e4120b9..cc61948 100644
--- a/test/test_p2p_stress.cpp
+++ b/test/test_p2p_stress.cpp
@@ -147,11 +147,15 @@ int main(int argc, char **argv) {
auto opt_npeers = Config::OptValInt::create(5);
auto opt_seg_buff_size = Config::OptValInt::create(4096);
auto opt_nworker = Config::OptValInt::create(2);
+ auto opt_conn_timeout = Config::OptValDouble::create(5);
+ auto opt_ping_peroid = Config::OptValDouble::create(5);
auto opt_help = Config::OptValFlag::create(false);
config.add_opt("no-msg", opt_no_msg, Config::SWITCH_ON);
config.add_opt("npeers", opt_npeers, Config::SET_VAL);
config.add_opt("seg-buff-size", opt_seg_buff_size, Config::SET_VAL);
config.add_opt("nworker", opt_nworker, Config::SET_VAL);
+ config.add_opt("conn-timeout", opt_conn_timeout, Config::SET_VAL);
+ config.add_opt("ping-period", opt_ping_peroid, Config::SET_VAL);
config.add_opt("help", opt_help, Config::SWITCH_ON, 'h', "show this help info");
config.parse(argc, argv);
if (opt_help->get())
@@ -171,8 +175,10 @@ int main(int argc, char **argv) {
a.addr = addrs[i];
a.net = new MyNet(a.ec, MyNet::Config(
salticidae::ConnPool::Config()
- .nworker(opt_nworker->get()).seg_buff_size(seg_buff_size))
- .conn_timeout(5).ping_period(2));
+ .nworker(opt_nworker->get())
+ .seg_buff_size(seg_buff_size))
+ .conn_timeout(opt_conn_timeout->get())
+ .ping_period(opt_ping_peroid->get()));
a.tcall = new ThreadCall(a.ec);
if (!opt_no_msg->get())
install_proto(a.ec, *a.net, a.tc, seg_buff_size);