|
@@ -182,6 +182,84 @@ void start(NetIO &netio, char **args)
|
|
|
if (*args && !strcmp(*args, "route")) {
|
|
|
++args;
|
|
|
route_test(netio, args);
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/*
|
|
|
+ Handler for received client messages.
|
|
|
+*/
|
|
|
+void handle_async_clients(NetIO &netio, std::shared_ptr<tcp::socket> csocket,
|
|
|
+ const boost::system::error_code& error, size_t auth_size,
|
|
|
+ size_t msgbundle_size)
|
|
|
+{
|
|
|
+ if(!error) {
|
|
|
+#ifdef VERBOSE_NET
|
|
|
+ printf("Accept handler success\n");
|
|
|
+#endif
|
|
|
+ // Read header (1 uint64_t) from the socket and extract the client ID
|
|
|
+ size_t header;
|
|
|
+ clientid_t cid;
|
|
|
+ boost::asio::read(*csocket,
|
|
|
+ boost::asio::buffer(&header, sizeof(uint64_t)));
|
|
|
+
|
|
|
+ if((header & 0xff) == CLIENT_AUTHENTICATE) {
|
|
|
+ // Read the authentication token
|
|
|
+ boost::asio::read(*csocket,
|
|
|
+ boost::asio::buffer(&header, auth_size));
|
|
|
+
|
|
|
+ } else if ((header & 0xff) == CLIENT_MESSAGE_BUNDLE) {
|
|
|
+ unsigned char *msgbundle = (unsigned char*) malloc(msgbundle_size);
|
|
|
+ cid = (clientid_t)(header >> 8);
|
|
|
+
|
|
|
+ // Read the message_bundle
|
|
|
+ boost::asio::read(*csocket,
|
|
|
+ boost::asio::buffer(msgbundle, msgbundle_size));
|
|
|
+
|
|
|
+ //Ingest the message_bundle
|
|
|
+ bool ret = ecall_ingest_msgbundle(cid, msgbundle, apiparams.m_priv_out);
|
|
|
+ free(msgbundle);
|
|
|
+ }
|
|
|
+
|
|
|
+ start_accept(netio, auth_size, msgbundle_size);
|
|
|
+ } else {
|
|
|
+ printf("Accept handler failed\n");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ Asynchronously accept client connections
|
|
|
+*/
|
|
|
+void start_accept(NetIO &netio, size_t auth_size, size_t msgbundle_size)
|
|
|
+{
|
|
|
+ boost::asio::io_context &io_context = netio.io_context();
|
|
|
+ const NodeConfig &myconf = netio.myconfig();
|
|
|
+ std::shared_ptr<tcp::socket> csocket(new tcp::socket(netio.io_context()));
|
|
|
+ tcp::resolver resolver(io_context);
|
|
|
+ std::shared_ptr<tcp::acceptor> client_acceptor;
|
|
|
+ client_acceptor = std::shared_ptr<tcp::acceptor>(
|
|
|
+ new tcp::acceptor(io_context,
|
|
|
+ resolver.resolve(myconf.clistenhost,
|
|
|
+ myconf.clistenport)->endpoint()));
|
|
|
+#ifdef VERBOSE_NET
|
|
|
+ std::cout << "Accepting on " << myconf.clistenhost << ":"
|
|
|
+ << myconf.clistenport << "\n";
|
|
|
+#endif
|
|
|
+ client_acceptor->async_accept(*csocket,
|
|
|
+ boost::bind(&handle_async_clients, netio, csocket,
|
|
|
+ boost::asio::placeholders::error, auth_size, msgbundle_size));
|
|
|
+}
|
|
|
+
|
|
|
+void runAsyncListeners(NetIO &netio)
|
|
|
+{
|
|
|
+ const Config &conf = netio.config();
|
|
|
+ const NodeConfig &myconf = netio.myconfig();
|
|
|
+ if(myconf.roles & ROLE_INGESTION) {
|
|
|
+ size_t auth_size, msgbundle_size;
|
|
|
+ auth_size = SGX_AESGCM_MAC_SIZE;
|
|
|
+ msgbundle_size = SGX_AESGCM_IV_SIZE +
|
|
|
+ (conf.m_priv_out * conf.msg_size) + SGX_AESGCM_MAC_SIZE;
|
|
|
+ start_accept(netio, auth_size, msgbundle_size);
|
|
|
+ }
|
|
|
+}
|