+static void
+disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: disconnecting mesh service of peers\n");
+ disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_MESH_disconnect (h1);
+ GNUNET_MESH_disconnect (h2);
+ if (test == MULTICAST)
+ GNUNET_MESH_disconnect (h3);
+ if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
+ {
+ GNUNET_SCHEDULER_cancel (shutdown_handle);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ }
+}
+
+
+/**
+ * Transmit ready callback
+ */
+size_t
+tmt_rdy (void *cls, size_t size, void *buf)
+{
+ struct GNUNET_MessageHeader *msg = buf;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: tmt_rdy called\n");
+ if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf)
+ return 0;
+ msg->size = htons (sizeof (struct GNUNET_MessageHeader));
+ msg->type = htons ((long) cls);
+ return sizeof (struct GNUNET_MessageHeader);
+}
+
+
+/**
+ * Function is called whenever a message is received.
+ *
+ * @param cls closure (set from GNUNET_MESH_connect)
+ * @param tunnel connection to the other end
+ * @param tunnel_ctx place to store local state associated with the tunnel
+ * @param sender who sent the message
+ * @param message the actual message
+ * @param atsi performance data for the connection
+ * @return GNUNET_OK to keep the connection open,
+ * GNUNET_SYSERR to close it (signal serious error)
+ */
+int
+data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi)
+{
+ long client = (long) cls;
+
+ switch (client)
+ {
+ case 1L:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Origin client got a response!\n");
+ ok++;
+ peers_responded++;
+ if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
+ NULL);
+ }
+ if (test == MULTICAST && peers_responded < 2)
+ return GNUNET_OK;
+ GNUNET_MESH_tunnel_destroy (tunnel);
+ break;
+ case 2L:
+ case 3L:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Destination client %u got a message.\n",
+ client);
+ ok++;
+ GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL, sender,
+ sizeof (struct GNUNET_MessageHeader),
+ &tmt_rdy, (void *) 1L);
+ if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
+ NULL);
+ }
+ break;
+ default:
+ break;
+ }
+ return GNUNET_OK;
+}
+
+