aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-08-04 11:52:10 +0000
committerBart Polot <bart@net.in.tum.de>2011-08-04 11:52:10 +0000
commit76691a8f1f0a595e96716e8a267ad088931ea401 (patch)
treeb526ffbc409bb2936ee08c1e716b1ab032dbcb58 /src
parent81c9af90cbc58f7052e268f0d03997b3c63ef7d5 (diff)
downloadgnunet-76691a8f1f0a595e96716e8a267ad088931ea401.tar.gz
gnunet-76691a8f1f0a595e96716e8a267ad088931ea401.zip
fixes
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh.c119
1 files changed, 70 insertions, 49 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 1d2994585..7a159f3bd 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -121,6 +121,40 @@ enum MeshPeerState
121}; 121};
122 122
123 123
124/** FWD declaration */
125struct MeshPeerInfo;
126
127/**
128 * Struct containing all info possibly needed to build a package when called
129 * back by core.
130 */
131struct MeshDataDescriptor
132{
133 /** ID of the tunnel this packet travels in */
134 struct MESH_TunnelID *origin;
135
136 /** Ultimate destination of the packet */
137 GNUNET_PEER_Id destination;
138
139 /** Number of identical messages sent to different hops (multicast) */
140 unsigned int copies;
141
142 /** Size of the data */
143 size_t size;
144
145 /** Client that asked for the transmission, if any */
146 struct GNUNET_SERVER_Client *client;
147
148 /** Who was is message being sent to */
149 struct MeshPeerInfo *peer;
150
151 /** Which handler was used to request the transmission */
152 unsigned int handler_n;
153
154 /* Data at the end */
155};
156
157
124/** 158/**
125 * Struct containing all information regarding a given peer 159 * Struct containing all information regarding a given peer
126 */ 160 */
@@ -156,11 +190,16 @@ struct MeshPeerInfo
156 * Handle to stop the DHT search for a path to this peer 190 * Handle to stop the DHT search for a path to this peer
157 */ 191 */
158 struct GNUNET_DHT_GetHandle *dhtget; 192 struct GNUNET_DHT_GetHandle *dhtget;
159 193
160 /** 194 /**
161 * Handles to stop queued transmissions for this peer 195 * Handles to stop queued transmissions for this peer
162 */ 196 */
163 struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; 197 struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE];
198
199 /**
200 * Pointer to info stuctures used as cls for queued transmissions
201 */
202 struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE];
164}; 203};
165 204
166 205
@@ -529,7 +568,7 @@ retrieve_client (struct GNUNET_SERVER_Client *client)
529 * @param c Client to check 568 * @param c Client to check
530 * @return GNUNET_YES or GNUNET_NO, depending on subscription status 569 * @return GNUNET_YES or GNUNET_NO, depending on subscription status
531 */ 570 */
532static int 571static int /* FIXME inline? */
533is_client_subscribed(uint16_t message_type, struct MeshClient *c) 572is_client_subscribed(uint16_t message_type, struct MeshClient *c)
534{ 573{
535 unsigned int i; 574 unsigned int i;
@@ -733,35 +772,6 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
733} 772}
734 773
735 774
736/**
737 * TODO: build msg and use raw?
738 */
739struct MeshDataDescriptor
740{
741 /** ID of the tunnel this packet travels in */
742 struct MESH_TunnelID *origin;
743
744 /** Ultimate destination of the packet */
745 GNUNET_PEER_Id destination;
746
747 /** Number of identical messages sent to different hops (multicast) */
748 unsigned int copies;
749
750 /** Size of the data */
751 size_t size;
752
753 /** Client that asked for the transmission, if any */
754 struct GNUNET_SERVER_Client *client;
755
756 /** Who was this message directed to */
757 struct MeshPeerInfo *peer;
758
759 /** Which handler was used to request the transmission */
760 unsigned int handler_n;
761
762 /* Data at the end */
763};
764
765#if LATER 775#if LATER
766/** 776/**
767 * Function called to notify a client about the socket 777 * Function called to notify a client about the socket
@@ -1234,31 +1244,26 @@ handle_mesh_data_unicast (void *cls,
1234 1244
1235 size = ntohs(message->size); 1245 size = ntohs(message->size);
1236 if (size < sizeof(struct GNUNET_MESH_DataMessageFromOrigin)) { 1246 if (size < sizeof(struct GNUNET_MESH_DataMessageFromOrigin)) {
1237 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1247 GNUNET_break(0);
1238 "got data from origin packet: too short\n"); 1248 return GNUNET_OK;
1239 return GNUNET_OK; // FIXME maybe SYSERR? peer misbehaving?
1240 } 1249 }
1241 msg = (struct GNUNET_MESH_DataMessageFromOrigin *) message; 1250 msg = (struct GNUNET_MESH_DataMessageFromOrigin *) message;
1242 t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); 1251 t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
1243 if (NULL == t) { 1252 if (NULL == t) {
1244 /* TODO: are we so nice that we try to send it to OID anyway? We *could* 1253 /* TODO notify back: we don't know this tunnel */
1245 * know how to reach it, from the global peer hashmap
1246 */
1247 return GNUNET_OK; 1254 return GNUNET_OK;
1248 } 1255 }
1249 pi = GNUNET_CONTAINER_multihashmap_get(t->peers, 1256 pi = GNUNET_CONTAINER_multihashmap_get(t->peers,
1250 &msg->destination.hashPubKey); 1257 &msg->destination.hashPubKey);
1251 if (NULL == pi) { 1258 if (NULL == pi) {
1252 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1259 /* TODO maybe feedback, log to statistics */
1253 "got invalid data from origin packet: wrong destination\n");
1254 /* TODO maybe feedback, log to statistics
1255 */
1256 return GNUNET_OK; 1260 return GNUNET_OK;
1257 } 1261 }
1258 if (pi->id == myid) { 1262 if (pi->id == myid) {
1259 payload_type = ntohs(msg[1].header.type); 1263 payload_type = ntohs(msg[1].header.type);
1260 for (c = clients; NULL != c; c = c->next) { 1264 for (c = clients; NULL != c; c = c->next) {
1261 if (is_client_subscribed(payload_type, c)) { 1265 if (is_client_subscribed(payload_type, c)) {
1266 /* FIXME copy data to buffer (info), msg will expire */
1262 GNUNET_SERVER_notify_transmit_ready(c->handle, 1267 GNUNET_SERVER_notify_transmit_ready(c->handle,
1263 size - sizeof(struct GNUNET_MESH_DataMessageFromOrigin), 1268 size - sizeof(struct GNUNET_MESH_DataMessageFromOrigin),
1264 GNUNET_TIME_UNIT_FOREVER_REL, 1269 GNUNET_TIME_UNIT_FOREVER_REL,
@@ -1327,14 +1332,16 @@ handle_mesh_data_multicast (void *cls,
1327 GNUNET_PEER_resolve(myid, &id); 1332 GNUNET_PEER_resolve(myid, &id);
1328 if (GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) { 1333 if (GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) {
1329 type = ntohs(msg[1].header.type); 1334 type = ntohs(msg[1].header.type);
1330 nc = GNUNET_SERVER_notification_context_create(server_handle, 10U); 1335 nc = GNUNET_SERVER_notification_context_create(server_handle,
1336 CORE_QUEUE_SIZE);
1331 for (c = clients; c != NULL; c = c->next) { 1337 for (c = clients; c != NULL; c = c->next) {
1332 for (i = 0; i < c->type_counter; i++) { 1338 if (is_client_subscribed(type, c)) {
1333 if (c->types[i] == type) { 1339 GNUNET_SERVER_notification_context_add(nc, c->handle);
1334 GNUNET_SERVER_notification_context_add(nc, c->handle);
1335 }
1336 } 1340 }
1337 } 1341 }
1342 GNUNET_SERVER_notification_context_broadcast(nc, message, GNUNET_NO);
1343 GNUNET_SERVER_notification_context_destroy(nc);
1344 /* FIXME is this right? better to do like in core retransmissions? */
1338 } 1345 }
1339 1346
1340 /* Retransmit to other peers */ 1347 /* Retransmit to other peers */
@@ -1363,6 +1370,7 @@ handle_mesh_data_multicast (void *cls,
1363 } 1370 }
1364 } 1371 }
1365 dd->handler_n = j; 1372 dd->handler_n = j;
1373 dd->peer->infos[j] = dd;
1366 dd->peer->core_transmit[j] = GNUNET_CORE_notify_transmit_ready( 1374 dd->peer->core_transmit[j] = GNUNET_CORE_notify_transmit_ready(
1367 core_handle, 1375 core_handle,
1368 0, 1376 0,
@@ -2288,11 +2296,24 @@ core_disconnect (void *cls,
2288 const struct 2296 const struct
2289 GNUNET_PeerIdentity *peer) 2297 GNUNET_PeerIdentity *peer)
2290{ 2298{
2291 GNUNET_PEER_Id pid; 2299 struct MeshPeerInfo *pi;
2300 unsigned int i;
2301
2292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2293 "Peer disconnected\n"); 2303 "Peer disconnected\n");
2294 pid = GNUNET_PEER_search(peer); 2304 pi = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
2295 if (myid == pid) { 2305 if (!pi) {
2306 GNUNET_break(0);
2307 return;
2308 }
2309 for (i = 0; i < CORE_QUEUE_SIZE; i++) {
2310 if (pi->core_transmit[i]) {
2311 GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit[i]);
2312 /* TODO: notify that tranmission has failed */
2313 GNUNET_free(pi->infos[i]);
2314 }
2315 }
2316 if (myid == pi->id) {
2296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2297 " (self)\n"); 2318 " (self)\n");
2298 } 2319 }