Browse Source

Actually send outgoing data from the enclave

Ian Goldberg 1 year ago
parent
commit
dd2f2be3d0
3 changed files with 21 additions and 6 deletions
  1. 13 3
      App/net.cpp
  2. 7 2
      App/net.hpp
  3. 1 1
      Enclave/Enclave.edl

+ 13 - 3
App/net.cpp

@@ -106,13 +106,14 @@ void NodeIO::send_message_header(uint32_t tot_message_len)
     chunksize_inflight = 0;
 }
 
-void NodeIO::send_chunk(uint8_t *data, uint32_t chunk_len)
+bool NodeIO::send_chunk(uint8_t *data, uint32_t chunk_len)
 {
     assert(chunk_len <= MAXCHUNKSIZE);
     uint64_t header = (uint64_t(chunk_len) << 8) + COMMAND_CHUNK;
     send_header_data(header, data, chunk_len);
     chunksize_inflight += chunk_len;
     assert(chunksize_inflight <= msgsize_inflight);
+    return (chunksize_inflight < msgsize_inflight);
 }
 
 void NodeIO::recv_commands(
@@ -239,15 +240,24 @@ NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
  * use to store the first (encrypted) chunk of this message. */
 uint8_t *ocall_message(nodenum_t node_num, uint32_t message_len)
 {
-    return NULL;
+    assert(g_netio != NULL);
+    NodeIO &node = g_netio->node(node_num);
+    node.send_message_header(message_len);
+    return node.request_frame();
 }
 
 /* The enclave calls this to inform the untrusted app that there's a new
  * chunk to send.  The return value is the frame the enclave should use
  * to store the next (encrypted) chunk of this message, or NULL if this
  * was the last chunk. */
-uint8_t *ocall_chunk(nodenum_t node_num, const uint8_t *chunkdata,
+uint8_t *ocall_chunk(nodenum_t node_num, uint8_t *chunkdata,
     uint32_t chunklen)
 {
+    assert(g_netio != NULL);
+    NodeIO &node = g_netio->node(node_num);
+    bool morechunks = node.send_chunk(chunkdata, chunklen);
+    if (morechunks) {
+        return node.request_frame();
+    }
     return NULL;
 }

+ 7 - 2
App/net.hpp

@@ -106,7 +106,9 @@ public:
 
     void send_epoch(uint32_t epoch_num);
     void send_message_header(uint32_t tot_message_len);
-    void send_chunk(uint8_t *data, uint32_t chunk_len);
+    // Returns true if there are more chunks to send in this message,
+    // false if not.
+    bool send_chunk(uint8_t *data, uint32_t chunk_len);
 
     // Asynchronously receive commands from this socket.  Depending on
     // what they are, one of the three callbacks will be called.  The
@@ -132,7 +134,10 @@ public:
 
     size_t num_nodes;
     size_t me;
-    NodeIO &node(size_t node_num) { return nodeios[node_num].value(); }
+    NodeIO &node(size_t node_num) {
+        assert(node_num < num_nodes);
+        return nodeios[node_num].value();
+    }
 };
 
 extern NetIO *g_netio;

+ 1 - 1
Enclave/Enclave.edl

@@ -40,7 +40,7 @@ enclave {
 
         uint8_t *ocall_chunk(
             nodenum_t node_num,
-            [user_check] const uint8_t *chunkdata,
+            [user_check] uint8_t *chunkdata,
             uint32_t chunklen);
     };
 };