WiP (in-tunnel data forwarding)
authorBart Polot <bart@net.in.tum.de>
Fri, 24 Jun 2011 22:00:28 +0000 (22:00 +0000)
committerBart Polot <bart@net.in.tum.de>
Fri, 24 Jun 2011 22:00:28 +0000 (22:00 +0000)
src/mesh/gnunet-service-mesh.c

index 78550b2a10e6602b6f59942d2913277f3d32bec7..88c10140cb1e9f77f65a54b5067a79e8db72a681 100644 (file)
@@ -730,7 +730,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
  * NULL and "size" zero if the socket was closed for
  * writing in the meantime.
  *
- * @param cls closure (data itself)
+ * @param cls closure (info_for_data_to_origin with all info to build packet)
  * @param size number of bytes available in buf
  * @param buf where the callee should write the message
  * @return number of bytes written to buf
@@ -762,6 +762,35 @@ send_core_data_to_origin (void *cls, size_t size, void *buf)
     return total_size;
 }
 
+/**
+ * Function called to notify a client about the socket
+ * being ready to queue more data.  "buf" will be
+ * NULL and "size" zero if the socket was closed for
+ * writing in the meantime.
+ *
+ * @param cls closure (data itself)
+ * @param size number of bytes available in buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to buf
+ */
+static size_t
+send_core_data_from_origin (void *cls, size_t size, void *buf)
+{
+    struct GNUNET_MESH_DataMessageFromOrigin    *msg = cls;
+    size_t                                      total_size;
+
+    GNUNET_assert(NULL != msg);
+    total_size = ntohs(msg->header.size);
+
+    if (total_size > size) {
+        GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                   "not enough buffer to send data futher\n");
+        return 0;
+    }
+    memcpy(msg, buf, total_size);
+    return total_size;
+}
+
 
 #if LATER
 /**
@@ -1039,7 +1068,7 @@ handle_mesh_data_unicast (void *cls,
         GNUNET_TIME_UNIT_FOREVER_REL,
         &id,
         size,
-        &send_core_data_to_origin,
+        &send_core_data_from_origin,
         msg);
     return GNUNET_OK;
 }