|
@@ -3,13 +3,33 @@
|
|
|
#include "storage.hpp"
|
|
|
#include "ORExpand.hpp"
|
|
|
|
|
|
-// Handle the messages received by a storage node
|
|
|
-void storage_received(const uint8_t *msgs, uint32_t num_msgs)
|
|
|
+static struct {
|
|
|
+ // A local storage buffer, used when we need to do non-in-place
|
|
|
+ // sorts of the messages that have arrived
|
|
|
+ MsgBuffer stg_buf;
|
|
|
+} storage_state;
|
|
|
+
|
|
|
+// route_init will call this function; no one else should call it
|
|
|
+// explicitly. The parameter is the number of messages that can fit in
|
|
|
+// the storage-side MsgBuffer. Returns true on success, false on
|
|
|
+// failure.
|
|
|
+bool storage_init(uint32_t msg_buf_size)
|
|
|
+{
|
|
|
+ storage_state.stg_buf.alloc(msg_buf_size);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+// Handle the messages received by a storage node. Pass a _locked_
|
|
|
+// MsgBuffer. This function will itself reset and unlock it when it's
|
|
|
+// done with it.
|
|
|
+void storage_received(MsgBuffer &storage_buf)
|
|
|
{
|
|
|
// A dummy function for now that just counts how many real and
|
|
|
// padding messages arrived
|
|
|
uint16_t msg_size = g_teems_config.msg_size;
|
|
|
nodenum_t my_node_num = g_teems_config.my_node_num;
|
|
|
+ const uint8_t *msgs = storage_buf.buf;
|
|
|
+ uint32_t num_msgs = storage_buf.inserted;
|
|
|
uint32_t real = 0, padding = 0;
|
|
|
uint32_t uid_mask = (1 << DEST_UID_BITS) - 1;
|
|
|
|
|
@@ -32,4 +52,7 @@ void storage_received(const uint8_t *msgs, uint32_t num_msgs)
|
|
|
msgs += msg_size;
|
|
|
}
|
|
|
printf("%u real, %u padding\n", real, padding);
|
|
|
+
|
|
|
+ storage_buf.reset();
|
|
|
+ pthread_mutex_unlock(&storage_buf.mutex);
|
|
|
}
|