diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-06-27 17:01:39 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-06-27 17:01:39 +0000 |
commit | a3982a7b6723b8adb052f8c446a662258f34a4d4 (patch) | |
tree | d8b50d83dd0d36328522c423016413c225702834 | |
parent | c7a1c4045e54c5c7ac360007a33a5fa46ee74687 (diff) | |
download | gnunet-a3982a7b6723b8adb052f8c446a662258f34a4d4.tar.gz gnunet-a3982a7b6723b8adb052f8c446a662258f34a4d4.zip |
WiP (deliver packets to client)
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 68e542385..fe497f1a1 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -510,6 +510,24 @@ retrieve_client (struct GNUNET_SERVER_Client *client) | |||
510 | 510 | ||
511 | 511 | ||
512 | /** | 512 | /** |
513 | * Checks if a given client has subscribed to certain message type | ||
514 | * @param message_type Type of message to check | ||
515 | * @param c Client to check | ||
516 | * @return GNUNET_YES or GNUNET_NO, depending on subscription status | ||
517 | */ | ||
518 | static int | ||
519 | is_client_subscribed(uint16_t message_type, struct MeshClient *c) | ||
520 | { | ||
521 | unsigned int i; | ||
522 | |||
523 | for (i = 0; i < c->type_counter; i++) { | ||
524 | if (c->types[i] == message_type) return GNUNET_YES; | ||
525 | } | ||
526 | return GNUNET_NO; | ||
527 | } | ||
528 | |||
529 | |||
530 | /** | ||
513 | * Search for a tunnel among the tunnels for a client | 531 | * Search for a tunnel among the tunnels for a client |
514 | * @param client the client whose tunnels to search in | 532 | * @param client the client whose tunnels to search in |
515 | * @param tid the local id of the tunnel | 533 | * @param tid the local id of the tunnel |
@@ -888,6 +906,35 @@ send_p2p_tunnel_destroy(void *cls, size_t size, void *buf) | |||
888 | } | 906 | } |
889 | #endif | 907 | #endif |
890 | 908 | ||
909 | |||
910 | /** | ||
911 | * Function called to notify a client about the socket | ||
912 | * begin ready to queue more data. "buf" will be | ||
913 | * NULL and "size" zero if the socket was closed for | ||
914 | * writing in the meantime. | ||
915 | * | ||
916 | * @param cls closure | ||
917 | * @param size number of bytes available in buf | ||
918 | * @param buf where the callee should write the message | ||
919 | * @return number of bytes written to buf | ||
920 | */ | ||
921 | size_t | ||
922 | send_client_raw (void *cls, size_t size, void *buf) | ||
923 | { | ||
924 | GNUNET_MessageHeader *msg = cls; | ||
925 | size_t msg_size; | ||
926 | |||
927 | msg_size = ntohs(msg->size); | ||
928 | if (msg_size > size) { | ||
929 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
930 | "deliver to client failed: buffer too small\n"); | ||
931 | return 0; | ||
932 | } | ||
933 | memcpy(buf, cls, msg_size); | ||
934 | return msg_size; | ||
935 | } | ||
936 | |||
937 | |||
891 | /** | 938 | /** |
892 | * Iterator over hash map peer entries to resend a data packet to all peers | 939 | * Iterator over hash map peer entries to resend a data packet to all peers |
893 | * down the tunnel. | 940 | * down the tunnel. |
@@ -1103,7 +1150,9 @@ handle_mesh_data_unicast (void *cls, | |||
1103 | struct GNUNET_PeerIdentity id; | 1150 | struct GNUNET_PeerIdentity id; |
1104 | struct MeshTunnel *t; | 1151 | struct MeshTunnel *t; |
1105 | struct MeshPeerInfo *pi; | 1152 | struct MeshPeerInfo *pi; |
1153 | struct MeshClient *c; | ||
1106 | size_t size; | 1154 | size_t size; |
1155 | uint16_t payload_type; | ||
1107 | 1156 | ||
1108 | size = ntohs(message->size); | 1157 | size = ntohs(message->size); |
1109 | if (size < sizeof(struct GNUNET_MESH_DataMessageFromOrigin)) { | 1158 | if (size < sizeof(struct GNUNET_MESH_DataMessageFromOrigin)) { |
@@ -1113,6 +1162,12 @@ handle_mesh_data_unicast (void *cls, | |||
1113 | } | 1162 | } |
1114 | msg = (struct GNUNET_MESH_DataMessageFromOrigin *) message; | 1163 | msg = (struct GNUNET_MESH_DataMessageFromOrigin *) message; |
1115 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); | 1164 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); |
1165 | if (NULL == t) { | ||
1166 | /* TODO: are we so nice that we try to send it to OID anyway? We *could* | ||
1167 | * know how to reach it, from the global peer hashmap | ||
1168 | */ | ||
1169 | return GNUNET_OK; | ||
1170 | } | ||
1116 | pi = GNUNET_CONTAINER_multihashmap_get(t->peers, | 1171 | pi = GNUNET_CONTAINER_multihashmap_get(t->peers, |
1117 | &msg->destination.hashPubKey); | 1172 | &msg->destination.hashPubKey); |
1118 | if (NULL == pi) { | 1173 | if (NULL == pi) { |
@@ -1124,6 +1179,19 @@ handle_mesh_data_unicast (void *cls, | |||
1124 | */ | 1179 | */ |
1125 | return GNUNET_OK; | 1180 | return GNUNET_OK; |
1126 | } | 1181 | } |
1182 | if (pi->id == myid) { | ||
1183 | payload_type = ntohs(msg[1].header.type); | ||
1184 | for (c = clients; NULL != c; c = c->next) { | ||
1185 | if (is_client_subscribed(payload_type, c)) { | ||
1186 | GNUNET_SERVER_notify_transmit_ready(c, | ||
1187 | size - sizeof(struct GNUNET_MESH_DataMessageFromOrigin), | ||
1188 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1189 | send_client_raw, | ||
1190 | &msg[1]); | ||
1191 | } | ||
1192 | } | ||
1193 | return GNUNET_OK; | ||
1194 | } | ||
1127 | GNUNET_PEER_resolve(get_first_hop(pi->path), &id); | 1195 | GNUNET_PEER_resolve(get_first_hop(pi->path), &id); |
1128 | GNUNET_CORE_notify_transmit_ready(core_handle, | 1196 | GNUNET_CORE_notify_transmit_ready(core_handle, |
1129 | 0, | 1197 | 0, |
@@ -1167,6 +1235,10 @@ handle_mesh_data_multicast (void *cls, | |||
1167 | msg = (struct GNUNET_MESH_DataMessageMulticast *) message; | 1235 | msg = (struct GNUNET_MESH_DataMessageMulticast *) message; |
1168 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); | 1236 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); |
1169 | 1237 | ||
1238 | if (NULL == t) { | ||
1239 | return GNUNET_OK; | ||
1240 | } | ||
1241 | |||
1170 | GNUNET_CONTAINER_multihashmap_iterate(t->peers, | 1242 | GNUNET_CONTAINER_multihashmap_iterate(t->peers, |
1171 | &iterate_resend_multicast, | 1243 | &iterate_resend_multicast, |
1172 | msg); | 1244 | msg); |
@@ -1207,7 +1279,7 @@ handle_mesh_data_to_orig (void *cls, | |||
1207 | msg = (struct GNUNET_MESH_DataMessageToOrigin *) message; | 1279 | msg = (struct GNUNET_MESH_DataMessageToOrigin *) message; |
1208 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); | 1280 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); |
1209 | 1281 | ||
1210 | if (NULL == t) { /* don't know tunnel */ | 1282 | if (NULL == t) { |
1211 | /* TODO: are we so nice that we try to send it to OID anyway? We *could* | 1283 | /* TODO: are we so nice that we try to send it to OID anyway? We *could* |
1212 | * know how to reach it, from the global peer hashmap | 1284 | * know how to reach it, from the global peer hashmap |
1213 | */ | 1285 | */ |