aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-05-12 22:21:16 +0000
committerBart Polot <bart@net.in.tum.de>2011-05-12 22:21:16 +0000
commitbb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5 (patch)
tree091423fbd715fc8c8ed0bd8107ae6b9cde4bf8c9 /src/mesh
parent33b69c82ed1aed813b58aa076fbbed72a8e834b4 (diff)
downloadgnunet-bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5.tar.gz
gnunet-bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5.zip
WiP
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c13
-rw-r--r--src/mesh/mesh.h4
-rw-r--r--src/mesh/mesh_api_new.c39
-rw-r--r--src/mesh/mesh_protocol.h28
-rw-r--r--src/mesh/test_mesh_api.c51
5 files changed, 76 insertions, 59 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index d3b857c6a..2080a375f 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -657,8 +657,7 @@ dht_get_response_handler(void *cls,
657 + (p->length 657 + (p->length
658 * sizeof (struct GNUNET_PeerIdentity)), 658 * sizeof (struct GNUNET_PeerIdentity)),
659 &send_core_create_path_for_peer, 659 &send_core_create_path_for_peer,
660 peer_info 660 peer_info);
661 );
662 return; 661 return;
663} 662}
664 663
@@ -676,9 +675,13 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
676 struct MeshClient *c, *next; 675 struct MeshClient *c, *next;
677 struct MESH_tunnel *t; 676 struct MESH_tunnel *t;
678 677
678 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
679 "MESH: client disconnected\n");
679 c = clients_head; 680 c = clients_head;
680 while (NULL != c) { 681 while (NULL != c) {
681 if (c->handle == client) { 682 if (c->handle == client) {
683 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
684 "MESH: cleaning client structures\n");
682 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); 685 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
683 while (NULL != (t = c->tunnels_head)) { 686 while (NULL != (t = c->tunnels_head)) {
684 destroy_tunnel(c, t); 687 destroy_tunnel(c, t);
@@ -710,8 +713,10 @@ handle_local_new_client (void *cls,
710 struct MeshClient *c; 713 struct MeshClient *c;
711 unsigned int payload_size; 714 unsigned int payload_size;
712 715
716 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
717 "MESH: new client connected\n");
713 /* Check data sanity */ 718 /* Check data sanity */
714 payload_size = message->size - sizeof(struct GNUNET_MessageHeader); 719 payload_size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader);
715 if (0 != payload_size % sizeof(GNUNET_MESH_ApplicationType)) { 720 if (0 != payload_size % sizeof(GNUNET_MESH_ApplicationType)) {
716 GNUNET_break(0); 721 GNUNET_break(0);
717 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 722 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
@@ -728,6 +733,8 @@ handle_local_new_client (void *cls,
728 c->messages_subscribed = NULL; 733 c->messages_subscribed = NULL;
729 } 734 }
730 c->subscription_counter = payload_size/sizeof(GNUNET_MESH_ApplicationType); 735 c->subscription_counter = payload_size/sizeof(GNUNET_MESH_ApplicationType);
736 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
737 "MESH: client has %u subscriptions\n", c->subscription_counter);
731 738
732 /* Insert new client in DLL */ 739 /* Insert new client in DLL */
733 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); 740 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index dc90f781a..d317e8054 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -76,8 +76,8 @@ struct GNUNET_MESH_ClientConnect {
76 * sizeof(MESH_ApplicationType) * applications 76 * sizeof(MESH_ApplicationType) * applications
77 */ 77 */
78 struct GNUNET_MessageHeader header; 78 struct GNUNET_MessageHeader header;
79 uint16_t types; 79 uint16_t types GNUNET_PACKED;
80 uint16_t applications; 80 uint16_t applications GNUNET_PACKED;
81}; 81};
82 82
83 83
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index 11376681a..1fe9714e5 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -133,34 +133,35 @@ struct GNUNET_MESH_TransmitHandle {
133 * @return number of bytes written to buf 133 * @return number of bytes written to buf
134 */ 134 */
135static size_t 135static size_t
136send_connect_packet (void *cls, size_t size, void *buf) { 136send_connect_packet (void *cls, size_t size, void *buf)
137{
137 struct GNUNET_MESH_Handle *h = cls; 138 struct GNUNET_MESH_Handle *h = cls;
138 struct GNUNET_MESH_ClientConnect *msg; 139 struct GNUNET_MESH_ClientConnect *msg;
139 uint16_t *types; 140 uint16_t *types;
140 int ntypes; 141 uint16_t ntypes;
141 GNUNET_MESH_ApplicationType *apps; 142 GNUNET_MESH_ApplicationType *apps;
142 int napps; 143 uint16_t napps;
143 144
144 h->th = NULL; 145 h->th = NULL;
145 if (0 == size || buf == NULL) { 146 if (0 == size || buf == NULL) {
146 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 147 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
147 "Send: buffer size 0 or buffer invalid\n"); 148 "Send connect packet: buffer size 0 or buffer invalid\n");
148 // FIXME: disconnect, reconnect, retry! 149 // FIXME: disconnect, reconnect, retry!
149 return 0; 150 return 0;
150 } 151 }
151 if (sizeof(struct GNUNET_MessageHeader) > size) { 152 if (sizeof(struct GNUNET_MessageHeader) > size) {
152 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 153 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
153 "Send: buffer size too small\n"); 154 "Send connect packet: buffer size too small\n");
154 // FIXME: disconnect, reconnect, retry! 155 // FIXME: disconnect, reconnect, retry!
155 return 0; 156 return 0;
156 } 157 }
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Sending into %lu bytes buffer\n", 159 "Send connect packet: %lu bytes buffer\n",
159 size); 160 size);
160 msg = (struct GNUNET_MESH_ClientConnect *) buf; 161 msg = (struct GNUNET_MESH_ClientConnect *) buf;
161 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; 162 msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
162 163
163 for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) { 164 for (ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
164 types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1)); 165 types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
165 types[ntypes] = h->message_handlers[ntypes].type; 166 types[ntypes] = h->message_handlers[ntypes].type;
166 } 167 }
@@ -172,20 +173,24 @@ send_connect_packet (void *cls, size_t size, void *buf) {
172 apps[napps] = h->applications[napps]; 173 apps[napps] = h->applications[napps];
173 } 174 }
174 175
175 msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) + 176 msg->header.size = htons(sizeof(struct GNUNET_MESH_ClientConnect) +
176 sizeof(uint16_t) * ntypes + 177 sizeof(uint16_t) * ntypes +
177 sizeof(GNUNET_MESH_ApplicationType) * napps; 178 sizeof(GNUNET_MESH_ApplicationType) * napps);
178 if(msg->header.size > size) {
179 /* TODO treat error / retry */
180 return 0;
181 }
182 179
183 memcpy(&msg[1], types, sizeof(uint16_t) * ntypes); 180 memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
184 memcpy(&msg[1] + sizeof(uint16_t) * ntypes, 181 memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
185 apps, 182 apps,
186 sizeof(GNUNET_MESH_ApplicationType) * napps); 183 sizeof(GNUNET_MESH_ApplicationType) * napps);
187 184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 return msg->header.size; 185 "Sent %lu bytes long message %d types and %d apps\n",
186 ntohs(msg->header.size),
187 ntypes,
188 napps
189 );
190 msg->applications = htons(napps);
191 msg->types = htons(ntypes);
192
193 return ntohs(msg->header.size);
189} 194}
190 195
191 196
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h
index 50bb50b02..01a44b58b 100644
--- a/src/mesh/mesh_protocol.h
+++ b/src/mesh/mesh_protocol.h
@@ -55,18 +55,18 @@ struct GNUNET_MESH_ManipulatePath
55 * Global id of the tunnel this path belongs to, 55 * Global id of the tunnel this path belongs to,
56 * unique in conjunction with the origin. 56 * unique in conjunction with the origin.
57 */ 57 */
58 uint32_t tid GNUNET_PACKED; 58 uint32_t tid GNUNET_PACKED;
59 59
60 /** 60 /**
61 * Information about speed requirements. If the tunnel cannot sustain the 61 * Information about speed requirements. If the tunnel cannot sustain the
62 * minimum bandwidth, packets are to be dropped. 62 * minimum bandwidth, packets are to be dropped.
63 */ 63 */
64 uint32_t speed_min GNUNET_PACKED; 64 uint32_t speed_min GNUNET_PACKED;
65 65
66 /** 66 /**
67 * 64-bit alignment. 67 * 64-bit alignment.
68 */ 68 */
69 uint32_t reserved GNUNET_PACKED; 69 uint32_t reserved GNUNET_PACKED;
70 70
71 /** 71 /**
72 * path_length structs defining the *whole* path from the origin [0] to the 72 * path_length structs defining the *whole* path from the origin [0] to the
@@ -88,12 +88,12 @@ struct GNUNET_MESH_OriginMulticast
88 /** 88 /**
89 * TID of the tunnel 89 * TID of the tunnel
90 */ 90 */
91 uint32_t tid GNUNET_PACKED; 91 uint32_t tid GNUNET_PACKED;
92 92
93 /** 93 /**
94 * OID of the tunnel 94 * OID of the tunnel
95 */ 95 */
96 struct GNUNET_PeerIdentity oid; 96 struct GNUNET_PeerIdentity oid;
97 97
98 /** 98 /**
99 * Payload follows 99 * Payload follows
@@ -114,17 +114,17 @@ struct GNUNET_MESH_DataMessageFromOrigin
114 /** 114 /**
115 * TID of the tunnel 115 * TID of the tunnel
116 */ 116 */
117 uint32_t tid GNUNET_PACKED; 117 uint32_t tid GNUNET_PACKED;
118 118
119 /** 119 /**
120 * OID of the tunnel 120 * OID of the tunnel
121 */ 121 */
122 struct GNUNET_PeerIdentity oid; 122 struct GNUNET_PeerIdentity oid;
123 123
124 /** 124 /**
125 * Destination. 125 * Destination.
126 */ 126 */
127 struct GNUNET_PeerIdentity destination; 127 struct GNUNET_PeerIdentity destination;
128 128
129 /** 129 /**
130 * Payload follows 130 * Payload follows
@@ -145,17 +145,17 @@ struct GNUNET_MESH_DataMessageToOrigin
145 /** 145 /**
146 * TID of the tunnel 146 * TID of the tunnel
147 */ 147 */
148 uint32_t tid GNUNET_PACKED; 148 uint32_t tid GNUNET_PACKED;
149 149
150 /** 150 /**
151 * OID of the tunnel 151 * OID of the tunnel
152 */ 152 */
153 struct GNUNET_PeerIdentity oid; 153 struct GNUNET_PeerIdentity oid;
154 154
155 /** 155 /**
156 * Sender of the message. 156 * Sender of the message.
157 */ 157 */
158 struct GNUNET_PeerIdentity sender; 158 struct GNUNET_PeerIdentity sender;
159 159
160 /** 160 /**
161 * Payload follows 161 * Payload follows
@@ -175,17 +175,17 @@ struct GNUNET_MESH_SpeedNotify
175 /** 175 /**
176 * TID of the tunnel 176 * TID of the tunnel
177 */ 177 */
178 uint32_t tid GNUNET_PACKED; 178 uint32_t tid GNUNET_PACKED;
179 179
180 /** 180 /**
181 * OID of the tunnel 181 * OID of the tunnel
182 */ 182 */
183 struct GNUNET_PeerIdentity oid; 183 struct GNUNET_PeerIdentity oid;
184 184
185 /** 185 /**
186 * Slowest link down the path (above minimum speed requirement). 186 * Slowest link down the path (above minimum speed requirement).
187 */ 187 */
188 uint32_t speed_min; 188 uint32_t speed_min;
189 189
190}; 190};
191 191
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index 5f988f555..6c3bd60a9 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -11,28 +11,40 @@ static struct GNUNET_OS_Process *arm_pid;
11 11
12static struct GNUNET_MESH_Handle *mesh; 12static struct GNUNET_MESH_Handle *mesh;
13 13
14static struct GNUNET_DHT_Handle *dht;
15
16static void 14static void
17 do_shutdown (void *cls, 15do_shutdown (void *cls,
18 const struct GNUNET_SCHEDULER_TaskContext *tc) 16 const struct GNUNET_SCHEDULER_TaskContext *tc)
19{ 17{
20 if (NULL != mesh) 18 if (NULL != mesh) {
21 GNUNET_MESH_disconnect (mesh); 19 GNUNET_MESH_disconnect (mesh);
22 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) 20 }
21 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
23 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 22 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
23 }
24 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); 24 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
25 GNUNET_OS_process_close (arm_pid); 25 GNUNET_OS_process_close (arm_pid);
26} 26}
27 27
28 28
29static void 29static void
30error_shutdown (void *cls,
31 const struct GNUNET_SCHEDULER_TaskContext *tc)
32{
33 if (NULL != mesh) {
34 GNUNET_MESH_disconnect (mesh);
35 }
36 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
37 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
38 }
39 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
40 GNUNET_OS_process_close (arm_pid);
41}
42
43static void
30run (void *cls, 44run (void *cls,
31 char *const *args, 45 char *const *args,
32 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { 46 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
33 GNUNET_MESH_ApplicationType app; 47 GNUNET_MESH_ApplicationType app;
34 // char buffer[2048];
35
36 48
37 arm_pid = GNUNET_OS_start_process (NULL, NULL, 49 arm_pid = GNUNET_OS_start_process (NULL, NULL,
38 "gnunet-service-arm", 50 "gnunet-service-arm",
@@ -40,13 +52,6 @@ run (void *cls,
40 "-L", "DEBUG", 52 "-L", "DEBUG",
41 "-c", "test_mesh.conf", 53 "-c", "test_mesh.conf",
42 NULL); 54 NULL);
43 dht = GNUNET_DHT_connect(cfg, 100);
44 if(NULL == dht) {
45 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
46 } else {
47 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
48 }
49
50 app = 0; 55 app = 0;
51 mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); 56 mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
52 if(NULL == mesh) { 57 if(NULL == mesh) {
@@ -56,15 +61,13 @@ run (void *cls,
56 } 61 }
57 62
58 /* do real test work here */ 63 /* do real test work here */
59 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 64 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
60 &do_shutdown, 65 GNUNET_TIME_UNIT_SECONDS, 5),
61 NULL); 66 &do_shutdown,
67 NULL);
62} 68}
63 69
64 70
65
66
67
68int main (int argc, char *argv[]) { 71int main (int argc, char *argv[]) {
69 int ret; 72 int ret;
70 char *const argv2[] = {"test-mesh-api", 73 char *const argv2[] = {"test-mesh-api",
@@ -80,7 +83,9 @@ int main (int argc, char *argv[]) {
80 argv2, "test-mesh-api", "nohelp", 83 argv2, "test-mesh-api", "nohelp",
81 options, &run, NULL); 84 options, &run, NULL);
82 if (ret != GNUNET_OK) { 85 if (ret != GNUNET_OK) {
83 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret); 86 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
87 "test-mesh-api': Failed with error code %d\n", ret);
88 return 1;
84 } 89 }
85 return 0; 90 return 0;
86} 91}