net.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. #include <iostream>
  2. #include "Enclave_u.h"
  3. #include "Untrusted.hpp"
  4. #include "net.hpp"
  5. // The command type byte values
  6. #define COMMAND_EPOCH 0x00
  7. #define COMMAND_MESSAGE 0x01
  8. #define COMMAND_CHUNK 0x02
  9. #define VERBOSE_NET
  10. // #define DEBUG_NET_CLIENTS
  11. #define CEILDIV(x,y) (((x)+(y)-1)/(y))
  12. NetIO *g_netio = NULL;
  13. size_t client_count = 0;
  14. NodeIO::NodeIO(tcp::socket &&socket, nodenum_t nodenum) :
  15. sock(std::move(socket)), node_num(nodenum), msgsize_inflight(0),
  16. chunksize_inflight(0), recv_msgsize_inflight(0),
  17. recv_chunksize_inflight(0), bytes_sent(0)
  18. {
  19. }
  20. uint8_t *NodeIO::request_frame()
  21. {
  22. if (frames_available.empty()) {
  23. // Allocate a new frame. Note that this memory will (at this
  24. // time) never get deallocated. In theory, we could deallocate
  25. // it in return_frame, but if a certain number of frames were
  26. // allocated here, it means we had that much data in flight
  27. // (queued but not accepted for sending by the OS), and we're
  28. // likely to need that much again. Subsequent messages will
  29. // _reuse_ the allocated data, though, so the used memory won't
  30. // grow forever, and will be limited to the amount of in-flight
  31. // data needed.
  32. return new uint8_t[FRAME_SIZE];
  33. }
  34. // Copy the pointer to the frame out of the deque and remove it from
  35. // the deque. Note this is _not_ taking the address of the element
  36. // *in* the deque (and then popping it, which would invalidate that
  37. // pointer).
  38. frame_deque_lock.lock();
  39. uint8_t *frame = frames_available.back();
  40. frames_available.pop_back();
  41. frame_deque_lock.unlock();
  42. return frame;
  43. }
  44. void NodeIO::return_frame(uint8_t *frame)
  45. {
  46. if (!frame) return;
  47. // We push the frame back on to the end of the deque so that it will
  48. // be the next one used. This may lead to better cache behaviour?
  49. frame_deque_lock.lock();
  50. frames_available.push_back(frame);
  51. frame_deque_lock.unlock();
  52. }
  53. void NodeIO::send_header_data(uint64_t header, uint8_t *data, size_t len)
  54. {
  55. commands_deque_lock.lock();
  56. commands_inflight.push_back({header, data, len});
  57. if (commands_inflight.size() == 1) {
  58. async_send_commands();
  59. }
  60. commands_deque_lock.unlock();
  61. }
  62. void NodeIO::async_send_commands()
  63. {
  64. std::vector<boost::asio::const_buffer> tosend;
  65. CommandTuple *commandp = &(commands_inflight.front());
  66. tosend.push_back(boost::asio::buffer(&(std::get<0>(*commandp)), 5));
  67. if (std::get<1>(*commandp) != NULL && std::get<2>(*commandp) > 0) {
  68. tosend.push_back(boost::asio::buffer(std::get<1>(*commandp),
  69. std::get<2>(*commandp)));
  70. }
  71. boost::asio::async_write(sock, tosend,
  72. [this, commandp](boost::system::error_code, std::size_t){
  73. // When the write completes, pop the command from the deque
  74. // (which should now be in the front)
  75. commands_deque_lock.lock();
  76. assert(!commands_inflight.empty() &&
  77. &(commands_inflight.front()) == commandp);
  78. bytes_sent = bytes_sent + 5 + std::get<2>(*commandp);
  79. uint8_t *data = std::get<1>(*commandp);
  80. commands_inflight.pop_front();
  81. if (commands_inflight.size() > 0) {
  82. async_send_commands();
  83. }
  84. // And return the frame
  85. return_frame(data);
  86. commands_deque_lock.unlock();
  87. });
  88. }
  89. void NodeIO::send_epoch(uint32_t epoch_num)
  90. {
  91. uint64_t header = (uint64_t(epoch_num) << 8) + COMMAND_EPOCH;
  92. send_header_data(header, NULL, 0);
  93. }
  94. void NodeIO::send_message_header(uint32_t tot_message_len)
  95. {
  96. uint64_t header = (uint64_t(tot_message_len) << 8) + COMMAND_MESSAGE;
  97. send_header_data(header, NULL, 0);
  98. // If we're sending a new message header, we have to have finished
  99. // sending the previous message.
  100. assert(chunksize_inflight == msgsize_inflight);
  101. msgsize_inflight = tot_message_len;
  102. chunksize_inflight = 0;
  103. }
  104. bool NodeIO::send_chunk(uint8_t *data, uint32_t chunk_len)
  105. {
  106. assert(chunk_len <= FRAME_SIZE);
  107. uint64_t header = (uint64_t(chunk_len) << 8) + COMMAND_CHUNK;
  108. send_header_data(header, data, chunk_len);
  109. chunksize_inflight += chunk_len;
  110. assert(chunksize_inflight <= msgsize_inflight);
  111. return (chunksize_inflight < msgsize_inflight);
  112. }
  113. void NodeIO::recv_commands(
  114. std::function<void(boost::system::error_code)> error_cb,
  115. std::function<void(uint32_t)> epoch_cb)
  116. {
  117. // Asynchronously read the header
  118. receive_header = 0;
  119. boost::asio::async_read(sock, boost::asio::buffer(&receive_header, 5),
  120. [this, error_cb, epoch_cb]
  121. (boost::system::error_code ec, std::size_t) {
  122. if (ec) {
  123. error_cb(ec);
  124. return;
  125. }
  126. if ((receive_header & 0xff) == COMMAND_EPOCH) {
  127. epoch_cb(uint32_t(receive_header >> 8));
  128. recv_commands(error_cb, epoch_cb);
  129. } else if ((receive_header & 0xff) == COMMAND_MESSAGE) {
  130. assert(recv_msgsize_inflight == recv_chunksize_inflight);
  131. recv_msgsize_inflight = uint32_t(receive_header >> 8);
  132. recv_chunksize_inflight = 0;
  133. if (ecall_message(node_num, recv_msgsize_inflight)) {
  134. recv_commands(error_cb, epoch_cb);
  135. } else {
  136. printf("ecall_message failed\n");
  137. }
  138. } else if ((receive_header & 0xff) == COMMAND_CHUNK) {
  139. uint32_t this_chunk_size = uint32_t(receive_header >> 8);
  140. assert(recv_chunksize_inflight + this_chunk_size <=
  141. recv_msgsize_inflight);
  142. recv_chunksize_inflight += this_chunk_size;
  143. boost::asio::async_read(sock, boost::asio::buffer(
  144. receive_frame, this_chunk_size),
  145. [this, error_cb, epoch_cb, this_chunk_size]
  146. (boost::system::error_code ecc, std::size_t) {
  147. if (ecc) {
  148. error_cb(ecc);
  149. return;
  150. }
  151. if (ecall_chunk(node_num, receive_frame,
  152. this_chunk_size)) {
  153. recv_commands(error_cb, epoch_cb);
  154. } else {
  155. printf("ecall_chunk failed\n");
  156. }
  157. });
  158. } else {
  159. error_cb(boost::system::errc::make_error_code(
  160. boost::system::errc::errc_t::invalid_argument));
  161. }
  162. });
  163. }
  164. uint64_t NodeIO::reset_bytes_sent()
  165. {
  166. uint64_t b_sent = bytes_sent;
  167. bytes_sent = 0;
  168. return b_sent;
  169. }
  170. uint64_t NetIO::reset_bytes_sent()
  171. {
  172. uint64_t total=0;
  173. for(size_t i = 0; i<nodeios.size(); i++) {
  174. if(nodeios[i].has_value()) {
  175. total+=((nodeios[i].value()).reset_bytes_sent());
  176. }
  177. }
  178. return total;
  179. }
  180. /*
  181. Receive clients dropped off messages, i.e. a CLIENT_MESSAGE_BUNDLE
  182. */
  183. void NetIO::ing_receive_msgbundle(tcp::socket* csocket, clientid_t c_simid)
  184. {
  185. unsigned char *msgbundle = (unsigned char*) malloc(msgbundle_size);
  186. boost::asio::async_read(*csocket, boost::asio::buffer(msgbundle, msgbundle_size),
  187. [this, csocket, msgbundle, c_simid]
  188. (boost::system::error_code ec, std::size_t) {
  189. if (ec) {
  190. if(ec == boost::asio::error::eof) {
  191. // Client connection terminated so we delete this socket
  192. delete(csocket);
  193. }
  194. else {
  195. printf("Error ing_receive_msgbundle : %s\n", ec.message().c_str());
  196. }
  197. return;
  198. }
  199. bool ret;
  200. //Ingest the message_bundle
  201. if(conf.private_routing) {
  202. ret = ecall_ingest_msgbundle(c_simid, msgbundle, conf.m_priv_out);
  203. } else {
  204. ret = ecall_ingest_msgbundle(c_simid, msgbundle, conf.m_pub_out);
  205. }
  206. free(msgbundle);
  207. // Continue to async receive client message bundles
  208. if(ret) {
  209. ing_receive_msgbundle(csocket, c_simid);
  210. }
  211. });
  212. }
  213. /*
  214. Handle new client connections.
  215. New clients always send an authentication message.
  216. For ingestion this is then followed by their msg_bundles every epoch.
  217. */
  218. void NetIO::ing_authenticate_new_client(tcp::socket* csocket,
  219. const boost::system::error_code& error)
  220. {
  221. if(error) {
  222. printf("Accept handler failed\n");
  223. return;
  224. }
  225. #ifdef DEBUG_NET_CLIENTS
  226. printf("Accept handler success\n");
  227. #endif
  228. unsigned char* auth_message = (unsigned char*) malloc(auth_size);
  229. boost::asio::async_read(*csocket, boost::asio::buffer(auth_message, auth_size),
  230. [this, csocket, auth_message]
  231. (boost::system::error_code ec, std::size_t) {
  232. if (ec) {
  233. if(ec == boost::asio::error::eof) {
  234. // Client connection terminated so we delete this socket
  235. delete(csocket);
  236. } else {
  237. printf("Error ing_auth_new_client : %s\n", ec.message().c_str());
  238. }
  239. return;
  240. }
  241. else {
  242. clientid_t c_simid = *((clientid_t *)(auth_message));
  243. // Read the authentication token
  244. unsigned char *auth_ptr = auth_message + sizeof(clientid_t);
  245. bool ret = ecall_authenticate(c_simid, auth_ptr);
  246. free(auth_message);
  247. // Receive client message bundles on this socket
  248. // for client sim_id c_simid
  249. if(ret) {
  250. client_count++;
  251. ing_receive_msgbundle(csocket, c_simid);
  252. } else{
  253. printf("Client <-> Ingestion authentication failed\n");
  254. delete(csocket);
  255. }
  256. }
  257. });
  258. ing_start_accept();
  259. }
  260. /*
  261. Handle new client connections.
  262. New clients always send an authentication message.
  263. For storage this is then followed by the storage servers sending them
  264. their mailbox every epoch.
  265. */
  266. void NetIO::stg_authenticate_new_client(tcp::socket* csocket,
  267. const boost::system::error_code& error)
  268. {
  269. if(error) {
  270. printf("Accept handler failed\n");
  271. return;
  272. }
  273. #ifdef DEBUG_NET_CLIENTS
  274. printf("Accept handler success\n");
  275. #endif
  276. unsigned char* auth_message = (unsigned char*) malloc(auth_size);
  277. boost::asio::async_read(*csocket, boost::asio::buffer(auth_message, auth_size),
  278. [this, csocket, auth_message]
  279. (boost::system::error_code ec, std::size_t) {
  280. if (ec) {
  281. if(ec == boost::asio::error::eof) {
  282. // Client connection terminated so we delete this socket
  283. delete(csocket);
  284. } else {
  285. printf("Error stg_auth_new_client: %s\n", ec.message().c_str());
  286. }
  287. return;
  288. }
  289. else {
  290. clientid_t c_simid = *((clientid_t *)(auth_message));
  291. // Read the authentication token
  292. unsigned char *auth_ptr = auth_message + sizeof(clientid_t);
  293. bool ret = ecall_storage_authenticate(c_simid, auth_ptr);
  294. free(auth_message);
  295. // If the auth is successful, store this socket into
  296. // a client socket array at the local_c_simid index
  297. // for storage servers to send clients their mailbox periodically.
  298. if(ret) {
  299. uint32_t lcid = c_simid / num_stg_nodes;
  300. client_sockets[lcid] = csocket;
  301. }
  302. else{
  303. printf("Client <-> Storage authentication failed\n");
  304. delete (csocket);
  305. }
  306. }
  307. });
  308. stg_start_accept();
  309. }
  310. /*
  311. Asynchronously accept new client connections
  312. */
  313. void NetIO::ing_start_accept()
  314. {
  315. tcp::socket *csocket = new tcp::socket(io_context());
  316. #ifdef DEBUG_NET_CLIENTS
  317. std::cout << "Accepting on " << myconf.clistenhost << ":" << myconf.clistenport << "\n";
  318. #endif
  319. ingestion_acceptor->async_accept(*csocket,
  320. boost::bind(&NetIO::ing_authenticate_new_client, this, csocket,
  321. boost::asio::placeholders::error));
  322. }
  323. void NetIO::stg_start_accept()
  324. {
  325. tcp::socket *csocket = new tcp::socket(io_context());
  326. #ifdef DEBUG_NET_CLIENTS
  327. std::cout << "Accepting on " << myconf.slistenhost << ":" << myconf.slistenport << "\n";
  328. #endif
  329. storage_acceptor->async_accept(*csocket,
  330. boost::bind(&NetIO::stg_authenticate_new_client, this, csocket,
  331. boost::asio::placeholders::error));
  332. }
  333. void NetIO::send_client_mailbox()
  334. {
  335. #ifdef PROFILE_NET_CLIENTS
  336. struct timespec tp;
  337. clock_gettime(CLOCK_REALTIME_COARSE, &tp);
  338. unsigned long start = tp.tv_sec * 1000000 + tp.tv_nsec/1000;
  339. #endif
  340. // Send each client their tokens for the next epoch
  341. for(uint32_t lcid = 0; lcid < num_clients_per_stg; lcid++)
  342. {
  343. unsigned char *tkn_ptr = epoch_tokens + lcid * token_bundle_size;
  344. unsigned char *buf_ptr = epoch_mailboxes + lcid * mailbox_size;
  345. if(client_sockets[lcid]!=nullptr) {
  346. boost::asio::async_write(*(client_sockets[lcid]),
  347. boost::asio::buffer(tkn_ptr, token_bundle_size),
  348. [this, lcid, buf_ptr](boost::system::error_code ec, std::size_t){
  349. if (ec) {
  350. if(ec == boost::asio::error::eof) {
  351. // Client connection terminated so we delete this socket
  352. delete(client_sockets[lcid]);
  353. printf("Client socket terminated!\n");
  354. } else {
  355. printf("Error send_client_mailbox tokens: %s\n", ec.message().c_str());
  356. }
  357. return;
  358. }
  359. boost::asio::async_write(*(client_sockets[lcid]),
  360. boost::asio::buffer(buf_ptr, mailbox_size),
  361. [this, lcid](boost::system::error_code ecc, std::size_t){
  362. //printf("NetIO::send_client_mailbox, Client %d messages was sent\n", lcid);
  363. if (ecc) {
  364. if(ecc == boost::asio::error::eof) {
  365. // Client connection terminated so we delete this socket
  366. delete(client_sockets[lcid]);
  367. printf("Client socket terminated!\n");
  368. } else {
  369. printf("Error send_client_mailbox mailbox (lcid = %d): %s\n",
  370. lcid, ecc.message().c_str());
  371. }
  372. return;
  373. }
  374. });
  375. });
  376. }
  377. /*
  378. else {
  379. printf("Client did not have a socket!\n");
  380. }
  381. */
  382. }
  383. #ifdef PROFILE_NET_CLIENTS
  384. clock_gettime(CLOCK_REALTIME_COARSE, &tp);
  385. unsigned long end = tp.tv_sec * 1000000 + tp.tv_nsec/1000;
  386. unsigned long diff = end - start;
  387. printf("send_client_mailbox time: %lu.%06lu s\n", diff/1000000, diff%1000000);
  388. #endif
  389. }
  390. NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
  391. : context(io_context), conf(config),
  392. myconf(config.nodes[config.my_node_num])
  393. {
  394. num_nodes = nodenum_t(conf.nodes.size());
  395. nodeios.resize(num_nodes);
  396. me = conf.my_node_num;
  397. // Node number n will accept connections from nodes 0, ..., n-1 and
  398. // make connections to nodes n+1, ..., num_nodes-1. This is all
  399. // single threaded, but it doesn't deadlock because node 0 isn't
  400. // waiting for any incoming connections, so it immediately makes
  401. // outgoing connections. When it connects to node 1, that node
  402. // accepts its (only) incoming connection, and then starts making
  403. // its outgoing connections, etc.
  404. tcp::resolver resolver(io_context);
  405. tcp::acceptor acceptor(io_context,
  406. resolver.resolve(myconf.listenhost, myconf.listenport)->endpoint());
  407. for(size_t i=0; i<me; ++i) {
  408. #ifdef VERBOSE_NET
  409. std::cerr << "Accepting number " << i << "\n";
  410. #endif
  411. tcp::socket nodesock = acceptor.accept();
  412. #ifdef VERBOSE_NET
  413. std::cerr << "Accepted number " << i << "\n";
  414. #endif
  415. // Read 2 bytes from the socket, which will be the
  416. // connecting node's node number
  417. unsigned short node_num;
  418. boost::asio::read(nodesock,
  419. boost::asio::buffer(&node_num, sizeof(node_num)));
  420. if (node_num >= num_nodes) {
  421. std::cerr << "Received bad node number\n";
  422. } else {
  423. nodeios[node_num].emplace(std::move(nodesock), node_num);
  424. #ifdef VERBOSE_NET
  425. std::cerr << "Received connection from " <<
  426. config.nodes[node_num].name << "\n";
  427. #endif
  428. }
  429. }
  430. for(size_t i=me+1; i<num_nodes; ++i) {
  431. boost::system::error_code err;
  432. tcp::socket nodesock(io_context);
  433. while(1) {
  434. #ifdef VERBOSE_NET
  435. std::cerr << "Connecting to " << config.nodes[i].name << "...\n";
  436. #endif
  437. boost::asio::connect(nodesock,
  438. resolver.resolve(config.nodes[i].listenhost,
  439. config.nodes[i].listenport), err);
  440. if (!err) break;
  441. std::cerr << "Connection to " << config.nodes[i].name <<
  442. " refused, will retry.\n";
  443. sleep(1);
  444. }
  445. // Write 2 bytes to the socket to tell the peer node our node
  446. // number
  447. nodenum_t node_num = (nodenum_t)me;
  448. boost::asio::write(nodesock,
  449. boost::asio::buffer(&node_num, sizeof(node_num)));
  450. nodeios[i].emplace(std::move(nodesock), i);
  451. #ifdef VERBOSE_NET
  452. std::cerr << "Connected to " << config.nodes[i].name << "\n";
  453. #endif
  454. }
  455. auth_size = sizeof(clientid_t) + sizeof(unsigned long) + SGX_AESGCM_KEY_SIZE;
  456. uint16_t priv_out, priv_in, pub_in;
  457. if(config.private_routing) {
  458. priv_out = conf.m_priv_out;
  459. priv_in = conf.m_priv_in;
  460. msgbundle_size = SGX_AESGCM_IV_SIZE
  461. + (conf.m_priv_out * (conf.msg_size + TOKEN_SIZE))
  462. + SGX_AESGCM_MAC_SIZE;
  463. token_bundle_size = ((priv_out * TOKEN_SIZE)
  464. + SGX_AESGCM_IV_SIZE + SGX_AESGCM_MAC_SIZE);
  465. mailbox_size = (priv_in * conf.msg_size) + SGX_AESGCM_IV_SIZE
  466. + SGX_AESGCM_MAC_SIZE;
  467. } else {
  468. pub_in = conf.m_pub_in;
  469. msgbundle_size = SGX_AESGCM_IV_SIZE
  470. + (conf.m_pub_out * conf.msg_size)
  471. + SGX_AESGCM_MAC_SIZE;
  472. mailbox_size = (pub_in * conf.msg_size) + SGX_AESGCM_IV_SIZE
  473. + SGX_AESGCM_MAC_SIZE;
  474. }
  475. if(myconf.roles & ROLE_STORAGE) {
  476. // Setup the client sockets
  477. // Compute no_of_clients per storage_server
  478. uint32_t num_users = config.user_count;
  479. NodeConfig nc;
  480. num_stg_nodes = 0;
  481. for (nodenum_t i=0; i<num_nodes; ++i) {
  482. nc = conf.nodes[i];
  483. if(nc.roles & ROLE_STORAGE) {
  484. num_stg_nodes++;
  485. }
  486. }
  487. num_clients_per_stg = CEILDIV(num_users, num_stg_nodes);
  488. for(uint32_t i = 0; i<num_clients_per_stg; i++) {
  489. client_sockets.emplace_back(nullptr);
  490. }
  491. uint32_t epoch_mailboxes_size = num_clients_per_stg * mailbox_size;
  492. uint32_t epoch_tokens_size = num_clients_per_stg * token_bundle_size;
  493. epoch_mailboxes = (unsigned char *) malloc(epoch_mailboxes_size);
  494. epoch_tokens = (unsigned char *) malloc (epoch_tokens_size);
  495. ecall_supply_storage_buffers(epoch_mailboxes, epoch_mailboxes_size,
  496. epoch_tokens, epoch_tokens_size);
  497. storage_acceptor = std::shared_ptr<tcp::acceptor>(
  498. new tcp::acceptor(io_context,
  499. resolver.resolve(this->myconf.slistenhost,
  500. this->myconf.slistenport)->endpoint()));
  501. stg_start_accept();
  502. }
  503. if(myconf.roles & ROLE_INGESTION) {
  504. ingestion_acceptor = std::shared_ptr<tcp::acceptor>(
  505. new tcp::acceptor(io_context,
  506. resolver.resolve(this->myconf.clistenhost,
  507. this->myconf.clistenport)->endpoint()));
  508. ing_start_accept();
  509. }
  510. }
  511. void NetIO::recv_commands(
  512. std::function<void(boost::system::error_code)> error_cb,
  513. std::function<void(uint32_t)> epoch_cb)
  514. {
  515. for (nodenum_t node_num = 0; node_num < num_nodes; ++node_num) {
  516. if (node_num == me) continue;
  517. NodeIO &n = node(node_num);
  518. n.recv_commands(error_cb, epoch_cb);
  519. }
  520. }
  521. void NetIO::close()
  522. {
  523. for (nodenum_t node_num = 0; node_num < num_nodes; ++node_num) {
  524. if (node_num == me) continue;
  525. NodeIO &n = node(node_num);
  526. n.close();
  527. }
  528. }
  529. /* The enclave calls this to inform the untrusted app that there's a new
  530. * messaage to send. The return value is the frame the enclave should
  531. * use to store the first (encrypted) chunk of this message. */
  532. uint8_t *ocall_message(nodenum_t node_num, uint32_t message_len)
  533. {
  534. assert(g_netio != NULL);
  535. NodeIO &node = g_netio->node(node_num);
  536. node.send_message_header(message_len);
  537. return node.request_frame();
  538. }
  539. /* The enclave calls this to inform the untrusted app that there's a new
  540. * chunk to send. The return value is the frame the enclave should use
  541. * to store the next (encrypted) chunk of this message, or NULL if this
  542. * was the last chunk. */
  543. uint8_t *ocall_chunk(nodenum_t node_num, uint8_t *chunkdata,
  544. uint32_t chunklen)
  545. {
  546. assert(g_netio != NULL);
  547. NodeIO &node = g_netio->node(node_num);
  548. bool morechunks = node.send_chunk(chunkdata, chunklen);
  549. if (morechunks) {
  550. return node.request_frame();
  551. }
  552. return NULL;
  553. }