void fullnode::start() { // Subscribe to new connections. protocol_.subscribe_channel( std::bind(&fullnode::connection_started, this, _1, _2)); // Start blockchain. Must finish before any operations // are performed on the database (or they will fail). std::promise<std::error_code> ec_promise; auto blockchain_started = [&ec_promise](const std::error_code& ec) { ec_promise.set_value(ec); }; chain_.start("blockchain", blockchain_started); std::error_code ec = ec_promise.get_future().get(); if (ec) { log_error() << "Problem starting blockchain: " << ec.message(); return; } // Start transaction pool txpool_.start(); // Fire off app. auto handle_start = std::bind(&fullnode::handle_start, this, _1); session_.start(handle_start); }
void connection_started(const std::error_code& ec, channel_ptr node, protocol& prot) { if (ec) { log_warning() << "Couldn't start connection: " << ec.message(); return; } log_info() << "Connection established."; // Resubscribe to new nodes. prot.subscribe_channel( std::bind(connection_started, _1, _2, std::ref(prot))); }
void fullnode::connection_started(const std::error_code& ec, channel_ptr node) { if (ec) { log_warning() << "Couldn't start connection: " << ec.message(); return; } // Subscribe to transaction messages from this node. node->subscribe_transaction( std::bind(&fullnode::recv_tx, this, _1, _2, node)); // Stay subscribed to new connections. protocol_.subscribe_channel( std::bind(&fullnode::connection_started, this, _1, _2)); }
void connection_started(const std::error_code& ec, channel_ptr node, protocol& prot, tx_watch& watch) { if (ec) { log_warning() << "Couldn't start connection: " << ec.message(); return; } log_info() << "Connection established."; // Subscribe to inventory packets. node->subscribe_inventory( std::bind(inventory_received, _1, _2, node, std::ref(watch))); // Resubscribe to new nodes. prot.subscribe_channel( std::bind(connection_started, _1, _2, std::ref(prot), std::ref(watch))); }
void send_tx(const std::error_code& ec, channel_ptr node, protocol& prot, transaction_type& tx) { check_error(ec); std::cout << "sendtx-p2p: Sending " << hash_transaction(tx) << std::endl; auto handle_send = [](const std::error_code& ec) { if (ec) log_warning() << "Send failed: " << ec.message(); else std::cout << "sendtx-p2p: Sent " << time(nullptr) << std::endl; }; node->send(tx, handle_send); prot.subscribe_channel( std::bind(send_tx, _1, _2, std::ref(prot), std::ref(tx))); }