|
@@ -170,6 +170,45 @@ void NodeIO::recv_commands(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+void accept_handler(const boost::system::error_code& error) {
|
|
|
+ if(!error) {
|
|
|
+ printf("Accept handler success\n");
|
|
|
+ // Read 2 bytes from the socket, which will be the
|
|
|
+ // connecting node's node number
|
|
|
+ //unsigned short node_num;
|
|
|
+ //boost::asio::read(acc_sock,
|
|
|
+ // boost::asio::buffer(&node_num, sizeof(node_num)));
|
|
|
+ //printf("node_num received = %d\n", node_num);
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+void start_accept(boost::asio::io_context& io_context, const NodeConfig& myconf);
|
|
|
+
|
|
|
+void handle_accept(boost::asio::io_context& io_context, const NodeConfig &myconf, tcp_connection::pointer new_connection,
|
|
|
+ const boost::system::error_code& error)
|
|
|
+ {
|
|
|
+ if (!error)
|
|
|
+ {
|
|
|
+ new_connection->start();
|
|
|
+ }
|
|
|
+
|
|
|
+ start_accept(io_context, myconf);
|
|
|
+ }
|
|
|
+
|
|
|
+void start_accept(boost::asio::io_context& io_context, const NodeConfig& myconf) {
|
|
|
+ tcp::resolver resolver(io_context);
|
|
|
+ tcp::acceptor async_acceptor(io_context,
|
|
|
+ resolver.resolve(myconf.clistenhost, myconf.clistenport)->endpoint());
|
|
|
+ tcp_connection::pointer new_connection =
|
|
|
+ tcp_connection::create(io_context);
|
|
|
+ async_acceptor.async_accept(new_connection->socket(),
|
|
|
+ boost::bind(&handle_accept, io_context, myconf, new_connection,
|
|
|
+ boost::asio::placeholders::error));
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
|
|
|
: conf(config), myconf(config.nodes[config.my_node_num])
|
|
|
{
|
|
@@ -238,8 +277,26 @@ NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
|
|
|
std::cerr << "Connected to " << config.nodes[i].name << "\n";
|
|
|
#endif
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(me==0) {
|
|
|
+ tcp::acceptor async_acceptor(io_context,
|
|
|
+ resolver.resolve(myconf.clistenhost, myconf.clistenport)->endpoint());
|
|
|
+ std::shared_ptr<tcp::socket> new_socket(new tcp::socket(io_context));
|
|
|
+ std::cout << myconf.clistenhost << ":" << myconf.clistenport;
|
|
|
+ async_acceptor.async_accept(*new_socket, accept_handler);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ if(me==0) {
|
|
|
+ start_accept(io_context, myconf);
|
|
|
+ }
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
+
|
|
|
void NetIO::recv_commands(
|
|
|
std::function<void(boost::system::error_code)> error_cb,
|
|
|
std::function<void(uint32_t)> epoch_cb)
|