aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-06-27 10:35:35 +0000
committerBart Polot <bart@net.in.tum.de>2011-06-27 10:35:35 +0000
commit7641f95f5043db6051054e377f03a4bca158fc75 (patch)
tree8df56a550fed7e87e50ff7ced8d7973a23d2f860 /src
parent1791f39fa6dc0bc37d14af98a0684fe1a23fc697 (diff)
downloadgnunet-7641f95f5043db6051054e377f03a4bca158fc75.tar.gz
gnunet-7641f95f5043db6051054e377f03a4bca158fc75.zip
Multicast and back-to-origin P2P traffic handling
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh.c151
1 files changed, 138 insertions, 13 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 88c10140c..68e542385 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -312,12 +312,12 @@ static struct MeshClient *clients_tail;
312/** 312/**
313 * Tunnels known, indexed by MESH_TunnelID (MeshTunnel) 313 * Tunnels known, indexed by MESH_TunnelID (MeshTunnel)
314 */ 314 */
315struct GNUNET_CONTAINER_MultiHashMap *tunnels; 315static struct GNUNET_CONTAINER_MultiHashMap *tunnels;
316 316
317/** 317/**
318 * Peers known, indexed by PeerIdentity (MeshPeerInfo) 318 * Peers known, indexed by PeerIdentity (MeshPeerInfo)
319 */ 319 */
320struct GNUNET_CONTAINER_MultiHashMap *peers; 320static struct GNUNET_CONTAINER_MultiHashMap *peers;
321 321
322/** 322/**
323 * Handle to communicate with core 323 * Handle to communicate with core
@@ -717,7 +717,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
717 * - # memcpy = 1 (in callback, cls->buf) 717 * - # memcpy = 1 (in callback, cls->buf)
718 * - Noise: extra containers defined per type of message 718 * - Noise: extra containers defined per type of message
719 */ 719 */
720 struct info_for_data_to_origin 720struct info_for_data_to_origin
721{ 721{
722 struct MESH_TunnelID *origin; 722 struct MESH_TunnelID *origin;
723 void *data; 723 void *data;
@@ -774,7 +774,38 @@ send_core_data_to_origin (void *cls, size_t size, void *buf)
774 * @return number of bytes written to buf 774 * @return number of bytes written to buf
775 */ 775 */
776static size_t 776static size_t
777send_core_data_from_origin (void *cls, size_t size, void *buf) 777send_core_data_raw (void *cls, size_t size, void *buf)
778{
779 struct GNUNET_MessageHeader *msg = cls;
780 size_t total_size;
781
782 GNUNET_assert(NULL != msg);
783 total_size = ntohs(msg->size);
784
785 if (total_size > size) {
786 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
787 "not enough buffer to send data futher\n");
788 return 0;
789 }
790 memcpy(msg, buf, total_size);
791 return total_size;
792}
793
794
795#if LATER
796/**
797 * Function called to notify a client about the socket
798 * being ready to queue more data. "buf" will be
799 * NULL and "size" zero if the socket was closed for
800 * writing in the meantime.
801 *
802 * @param cls closure (data itself)
803 * @param size number of bytes available in buf
804 * @param buf where the callee should write the message
805 * @return number of bytes written to buf
806 */
807static size_t
808send_core_data_multicast (void *cls, size_t size, void *buf)
778{ 809{
779 struct GNUNET_MESH_DataMessageFromOrigin *msg = cls; 810 struct GNUNET_MESH_DataMessageFromOrigin *msg = cls;
780 size_t total_size; 811 size_t total_size;
@@ -792,7 +823,6 @@ send_core_data_from_origin (void *cls, size_t size, void *buf)
792} 823}
793 824
794 825
795#if LATER
796/** 826/**
797 * Function called to notify a client about the socket 827 * Function called to notify a client about the socket
798 * being ready to queue more data. "buf" will be 828 * being ready to queue more data. "buf" will be
@@ -858,6 +888,39 @@ send_p2p_tunnel_destroy(void *cls, size_t size, void *buf)
858} 888}
859#endif 889#endif
860 890
891/**
892 * Iterator over hash map peer entries to resend a data packet to all peers
893 * down the tunnel.
894 *
895 * @param cls closure (original message)
896 * @param key current key code (peer id hash)
897 * @param value value in the hash map (peer_info)
898 * @return GNUNET_YES if we should continue to iterate, GNUNET_NO if not.
899 */
900static int iterate_resend_multicast (void *cls,
901 const GNUNET_HashCode * key,
902 void *value)
903{
904 struct GNUNET_MESH_DataMessageMulticast *msg = cls;
905 struct GNUNET_PeerIdentity id;
906 struct MeshPeerInfo *peer_info = value;
907
908 if (peer_info->id == myid) {
909// TODO retransmit to interested clients
910 return GNUNET_YES;
911 }
912 GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id);
913 GNUNET_CORE_notify_transmit_ready(core_handle,
914 0,
915 0,
916 GNUNET_TIME_UNIT_FOREVER_REL,
917 &id,
918 ntohs(msg->header.size),
919 &send_core_data_raw,
920 msg);
921 return GNUNET_YES;
922}
923
861 924
862/******************************************************************************/ 925/******************************************************************************/
863/******************** MESH NETWORK HANDLERS **************************/ 926/******************** MESH NETWORK HANDLERS **************************/
@@ -986,7 +1049,7 @@ handle_mesh_path_create (void *cls,
986 GNUNET_PEER_resolve(get_first_hop(path), &id); /* path is inverted :) */ 1049 GNUNET_PEER_resolve(get_first_hop(path), &id); /* path is inverted :) */
987 /* FIXME / COMMENT 1050 /* FIXME / COMMENT
988 * is it allowed/desired to declare variables this way? 1051 * is it allowed/desired to declare variables this way?
989 * (style, best bractices, etc) 1052 * (style, best practices, etc)
990 * This variable is short lived and completely irrelevant for the rest 1053 * This variable is short lived and completely irrelevant for the rest
991 * of the function 1054 * of the function
992 */ 1055 */
@@ -1042,7 +1105,7 @@ handle_mesh_data_unicast (void *cls,
1042 struct MeshPeerInfo *pi; 1105 struct MeshPeerInfo *pi;
1043 size_t size; 1106 size_t size;
1044 1107
1045 size = ntohs(message->size); 1108 size = ntohs(message->size);
1046 if (size < sizeof(struct GNUNET_MESH_DataMessageFromOrigin)) { 1109 if (size < sizeof(struct GNUNET_MESH_DataMessageFromOrigin)) {
1047 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1110 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1048 "got data from origin packet: too short\n"); 1111 "got data from origin packet: too short\n");
@@ -1056,10 +1119,10 @@ handle_mesh_data_unicast (void *cls,
1056 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1119 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1057 "got invalid data from origin packet: wrong destination\n"); 1120 "got invalid data from origin packet: wrong destination\n");
1058 /* TODO are we so nice to try to deliver it anyway? maybe we missed 1121 /* TODO are we so nice to try to deliver it anyway? maybe we missed
1059 * a Create_path packed that added the peer but we have it in the global 1122 * a Create_Path packet that added the peer but we have it in the
1060 * peer pool anyway... 1123 * _global_ peer pool anyway...
1061 */ 1124 */
1062 return GNUNET_OK; // FIXME maybe SYSERR? peer misbehaving? 1125 return GNUNET_OK;
1063 } 1126 }
1064 GNUNET_PEER_resolve(get_first_hop(pi->path), &id); 1127 GNUNET_PEER_resolve(get_first_hop(pi->path), &id);
1065 GNUNET_CORE_notify_transmit_ready(core_handle, 1128 GNUNET_CORE_notify_transmit_ready(core_handle,
@@ -1068,7 +1131,7 @@ handle_mesh_data_unicast (void *cls,
1068 GNUNET_TIME_UNIT_FOREVER_REL, 1131 GNUNET_TIME_UNIT_FOREVER_REL,
1069 &id, 1132 &id,
1070 size, 1133 size,
1071 &send_core_data_from_origin, 1134 &send_core_data_raw,
1072 msg); 1135 msg);
1073 return GNUNET_OK; 1136 return GNUNET_OK;
1074} 1137}
@@ -1091,7 +1154,23 @@ handle_mesh_data_multicast (void *cls,
1091 const struct GNUNET_TRANSPORT_ATS_Information 1154 const struct GNUNET_TRANSPORT_ATS_Information
1092 *atsi) 1155 *atsi)
1093{ 1156{
1094// struct GNUNET_MESH_DataMessageMulticast *msg = message; 1157 struct GNUNET_MESH_DataMessageMulticast *msg;
1158 struct MeshTunnel *t;
1159 size_t size;
1160
1161 size = ntohs(message->size);
1162 if (size < sizeof(struct GNUNET_MESH_DataMessageMulticast)) {
1163 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1164 "got multicast packet: too short\n");
1165 return GNUNET_OK; // FIXME maybe SYSERR? peer misbehaving?
1166 }
1167 msg = (struct GNUNET_MESH_DataMessageMulticast *) message;
1168 t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
1169
1170 GNUNET_CONTAINER_multihashmap_iterate(t->peers,
1171 &iterate_resend_multicast,
1172 msg);
1173
1095 return GNUNET_OK; 1174 return GNUNET_OK;
1096} 1175}
1097 1176
@@ -1113,7 +1192,53 @@ handle_mesh_data_to_orig (void *cls,
1113 const struct GNUNET_TRANSPORT_ATS_Information 1192 const struct GNUNET_TRANSPORT_ATS_Information
1114 *atsi) 1193 *atsi)
1115{ 1194{
1116// struct GNUNET_MESH_DataMessageToOrigin *msg = message; 1195 struct GNUNET_MESH_DataMessageToOrigin *msg;
1196 struct GNUNET_PeerIdentity id;
1197 struct MeshTunnel *t;
1198 struct MeshPeerInfo *peer_info;
1199 size_t size;
1200
1201 size = ntohs(message->size);
1202 if (size < sizeof(struct GNUNET_MESH_DataMessageToOrigin)) {
1203 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1204 "got invalid data to origin packet: too short\n");
1205 return GNUNET_OK; // FIXME maybe SYSERR? peer misbehaving?
1206 }
1207 msg = (struct GNUNET_MESH_DataMessageToOrigin *) message;
1208 t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
1209
1210 if (NULL == t) { /* don't know tunnel */
1211 /* 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
1213 */
1214 return GNUNET_OK;
1215 }
1216
1217 if (t->id.oid == myid) {
1218 if (NULL == t->client) {
1219 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1220 "got data packet for ownerless tunnel\n");
1221 return GNUNET_OK;
1222 }
1223 // TODO retransmit to client owner
1224 return GNUNET_OK;
1225 }
1226 peer_info = get_peer_info(&msg->oid);
1227 if (NULL == peer_info) {
1228 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1229 "unknown origin of tunnel\n");
1230 return GNUNET_OK;
1231 }
1232 GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id);
1233 GNUNET_CORE_notify_transmit_ready(core_handle,
1234 0,
1235 0,
1236 GNUNET_TIME_UNIT_FOREVER_REL,
1237 &id,
1238 size,
1239 &send_core_data_raw,
1240 msg);
1241
1117 return GNUNET_OK; 1242 return GNUNET_OK;
1118} 1243}
1119 1244