+ (p->length
* sizeof (struct GNUNET_PeerIdentity)),
&send_core_create_path_for_peer,
- peer_info
- );
+ peer_info);
return;
}
struct MeshClient *c, *next;
struct MESH_tunnel *t;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: client disconnected\n");
c = clients_head;
while (NULL != c) {
if (c->handle == client) {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: cleaning client structures\n");
GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
while (NULL != (t = c->tunnels_head)) {
destroy_tunnel(c, t);
struct MeshClient *c;
unsigned int payload_size;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: new client connected\n");
/* Check data sanity */
- payload_size = message->size - sizeof(struct GNUNET_MessageHeader);
+ payload_size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader);
if (0 != payload_size % sizeof(GNUNET_MESH_ApplicationType)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
c->messages_subscribed = NULL;
}
c->subscription_counter = payload_size/sizeof(GNUNET_MESH_ApplicationType);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: client has %u subscriptions\n", c->subscription_counter);
/* Insert new client in DLL */
GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
* sizeof(MESH_ApplicationType) * applications
*/
struct GNUNET_MessageHeader header;
- uint16_t types;
- uint16_t applications;
+ uint16_t types GNUNET_PACKED;
+ uint16_t applications GNUNET_PACKED;
};
* @return number of bytes written to buf
*/
static size_t
-send_connect_packet (void *cls, size_t size, void *buf) {
+send_connect_packet (void *cls, size_t size, void *buf)
+{
struct GNUNET_MESH_Handle *h = cls;
struct GNUNET_MESH_ClientConnect *msg;
uint16_t *types;
- int ntypes;
+ uint16_t ntypes;
GNUNET_MESH_ApplicationType *apps;
- int napps;
+ uint16_t napps;
h->th = NULL;
if (0 == size || buf == NULL) {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Send: buffer size 0 or buffer invalid\n");
+ "Send connect packet: buffer size 0 or buffer invalid\n");
// FIXME: disconnect, reconnect, retry!
return 0;
}
if (sizeof(struct GNUNET_MessageHeader) > size) {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Send: buffer size too small\n");
+ "Send connect packet: buffer size too small\n");
// FIXME: disconnect, reconnect, retry!
return 0;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending into %lu bytes buffer\n",
+ "Send connect packet: %lu bytes buffer\n",
size);
msg = (struct GNUNET_MESH_ClientConnect *) buf;
- msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
+ msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
- for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
+ for (ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
types[ntypes] = h->message_handlers[ntypes].type;
}
apps[napps] = h->applications[napps];
}
- msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
- sizeof(uint16_t) * ntypes +
- sizeof(GNUNET_MESH_ApplicationType) * napps;
- if(msg->header.size > size) {
- /* TODO treat error / retry */
- return 0;
- }
+ msg->header.size = htons(sizeof(struct GNUNET_MESH_ClientConnect) +
+ sizeof(uint16_t) * ntypes +
+ sizeof(GNUNET_MESH_ApplicationType) * napps);
memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
apps,
sizeof(GNUNET_MESH_ApplicationType) * napps);
-
- return msg->header.size;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sent %lu bytes long message %d types and %d apps\n",
+ ntohs(msg->header.size),
+ ntypes,
+ napps
+ );
+ msg->applications = htons(napps);
+ msg->types = htons(ntypes);
+
+ return ntohs(msg->header.size);
}
* Global id of the tunnel this path belongs to,
* unique in conjunction with the origin.
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* Information about speed requirements. If the tunnel cannot sustain the
* minimum bandwidth, packets are to be dropped.
*/
- uint32_t speed_min GNUNET_PACKED;
+ uint32_t speed_min GNUNET_PACKED;
/**
* 64-bit alignment.
*/
- uint32_t reserved GNUNET_PACKED;
+ uint32_t reserved GNUNET_PACKED;
/**
* path_length structs defining the *whole* path from the origin [0] to the
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Payload follows
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Destination.
*/
- struct GNUNET_PeerIdentity destination;
+ struct GNUNET_PeerIdentity destination;
/**
* Payload follows
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Sender of the message.
*/
- struct GNUNET_PeerIdentity sender;
+ struct GNUNET_PeerIdentity sender;
/**
* Payload follows
/**
* TID of the tunnel
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t tid GNUNET_PACKED;
/**
* OID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_PeerIdentity oid;
/**
* Slowest link down the path (above minimum speed requirement).
*/
- uint32_t speed_min;
+ uint32_t speed_min;
};
static struct GNUNET_MESH_Handle *mesh;
-static struct GNUNET_DHT_Handle *dht;
-
static void
- do_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if (NULL != mesh)
- GNUNET_MESH_disconnect (mesh);
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
+ if (NULL != mesh) {
+ GNUNET_MESH_disconnect (mesh);
+ }
+ if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ }
GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
GNUNET_OS_process_close (arm_pid);
}
+static void
+error_shutdown (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (NULL != mesh) {
+ GNUNET_MESH_disconnect (mesh);
+ }
+ if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ }
+ GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
+ GNUNET_OS_process_close (arm_pid);
+}
+
static void
run (void *cls,
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
GNUNET_MESH_ApplicationType app;
- // char buffer[2048];
-
arm_pid = GNUNET_OS_start_process (NULL, NULL,
"gnunet-service-arm",
"-L", "DEBUG",
"-c", "test_mesh.conf",
NULL);
- dht = GNUNET_DHT_connect(cfg, 100);
- if(NULL == dht) {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
- } else {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
- }
-
app = 0;
mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
if(NULL == mesh) {
}
/* do real test work here */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
+ GNUNET_TIME_UNIT_SECONDS, 5),
+ &do_shutdown,
+ NULL);
}
-
-
-
int main (int argc, char *argv[]) {
int ret;
char *const argv2[] = {"test-mesh-api",
argv2, "test-mesh-api", "nohelp",
options, &run, NULL);
if (ret != GNUNET_OK) {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+ "test-mesh-api': Failed with error code %d\n", ret);
+ return 1;
}
return 0;
}