aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-05-07 12:14:11 +0000
committerBart Polot <bart@net.in.tum.de>2013-05-07 12:14:11 +0000
commitb3e54688ae46b901bdbf6aa3020d93a04deda9e8 (patch)
treee6268ea98eff90a5d6012397a10fec9eb24e5ea6 /src
parent5128f85f632d1803ab3827b62a535b89e27f53ac (diff)
downloadgnunet-b3e54688ae46b901bdbf6aa3020d93a04deda9e8.tar.gz
gnunet-b3e54688ae46b901bdbf6aa3020d93a04deda9e8.zip
- remove regex integration from mesh2
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh-new.c444
1 files changed, 0 insertions, 444 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c
index 72295b0bb..e42be9142 100644
--- a/src/mesh/gnunet-service-mesh-new.c
+++ b/src/mesh/gnunet-service-mesh-new.c
@@ -1247,187 +1247,6 @@ queue_get_next (const struct MeshPeerInfo *peer);
1247static size_t 1247static size_t
1248queue_send (void *cls, size_t size, void *buf); 1248queue_send (void *cls, size_t size, void *buf);
1249 1249
1250/******************************************************************************/
1251/************************ REGEX INTEGRATION ****************************/
1252/******************************************************************************/
1253
1254/**
1255 * Cancel a mesh regex search and free resources.
1256 */
1257static void
1258regex_cancel_search (struct MeshRegexSearchInfo *regex_search)
1259{
1260 DEBUG_REGEX ("Search for %s canelled.\n", regex_search->description);
1261 GNUNET_REGEX_search_cancel (regex_search->search_handle);
1262 if (0 < regex_search->n_peers)
1263 GNUNET_free (regex_search->peers);
1264 if (GNUNET_SCHEDULER_NO_TASK != regex_search->timeout)
1265 {
1266 GNUNET_SCHEDULER_cancel(regex_search->timeout);
1267 }
1268 GNUNET_free (regex_search);
1269}
1270
1271
1272/**
1273 * Function called if the connect attempt to a peer found via
1274 * connect_by_string times out. Try to connect to another peer, if any.
1275 * Otherwise try to reconnect to the same peer.
1276 *
1277 * @param cls Closure (info about regex search).
1278 * @param tc TaskContext.
1279 */
1280static void
1281regex_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1282{
1283 struct MeshRegexSearchInfo *info = cls;
1284 struct MeshPeerInfo *peer_info;
1285 GNUNET_PEER_Id id;
1286 GNUNET_PEER_Id old;
1287
1288 DEBUG_REGEX ("Regex connect timeout\n");
1289 info->timeout = GNUNET_SCHEDULER_NO_TASK;
1290 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1291 {
1292 DEBUG_REGEX (" due to shutdown\n");
1293 return;
1294 }
1295
1296 old = info->peer;
1297 DEBUG_REGEX (" timed out: %u\n", old);
1298
1299 if (0 < info->n_peers)
1300 {
1301 // Select next peer, put current in that spot.
1302 id = info->peers[info->i_peer];
1303 info->peers[info->i_peer] = info->peer;
1304 info->i_peer = (info->i_peer + 1) % info->n_peers;
1305 }
1306 else
1307 {
1308 // Try to connect to same peer again.
1309 id = info->peer;
1310 }
1311 DEBUG_REGEX (" trying: %u\n", id);
1312
1313 peer_info = peer_info_get_short(id);
1314 tunnel_add_peer (info->t, peer_info);
1315 if (old != id)
1316 tunnel_delete_peer (info->t, old);
1317 peer_info_connect (peer_info, info->t);
1318 info->timeout = GNUNET_SCHEDULER_add_delayed (connect_timeout,
1319 &regex_connect_timeout,
1320 info);
1321 DEBUG_REGEX ("Regex connect timeout END\n");
1322}
1323
1324
1325/**
1326 * Function to process DHT string to regex matching.
1327 * Called on each result obtained for the DHT search.
1328 *
1329 * @param cls Closure provided in GNUNET_REGEX_search.
1330 * @param id Peer providing a regex that matches the string.
1331 * @param get_path Path of the get request.
1332 * @param get_path_length Lenght of get_path.
1333 * @param put_path Path of the put request.
1334 * @param put_path_length Length of the put_path.
1335 */
1336static void
1337regex_found_handler (void *cls,
1338 const struct GNUNET_PeerIdentity *id,
1339 const struct GNUNET_PeerIdentity *get_path,
1340 unsigned int get_path_length,
1341 const struct GNUNET_PeerIdentity *put_path,
1342 unsigned int put_path_length)
1343{
1344 struct MeshRegexSearchInfo *info = cls;
1345 struct MeshPeerPath *p;
1346 struct MeshPeerInfo *peer_info;
1347
1348 DEBUG_REGEX ("Got regex results from DHT!\n");
1349 DEBUG_REGEX (" for %s\n", info->description);
1350
1351 peer_info = peer_info_get (id);
1352 p = path_build_from_dht (get_path, get_path_length,
1353 put_path, put_path_length);
1354 path_add_to_peers (p, GNUNET_NO);
1355 path_destroy(p);
1356
1357 tunnel_add_peer (info->t, peer_info);
1358 peer_info_connect (peer_info, info->t);
1359 if (0 == info->peer)
1360 {
1361 info->peer = peer_info->id;
1362 }
1363 else
1364 {
1365 GNUNET_array_append (info->peers, info->n_peers, peer_info->id);
1366 }
1367
1368 if (GNUNET_SCHEDULER_NO_TASK != info->timeout)
1369 return;
1370
1371 info->timeout = GNUNET_SCHEDULER_add_delayed (connect_timeout,
1372 &regex_connect_timeout,
1373 info);
1374
1375 return;
1376}
1377
1378
1379/**
1380 * Store the regular expression describing a local service into the DHT.
1381 *
1382 * @param regex The regular expresion.
1383 */
1384static void
1385regex_put (struct MeshRegexDescriptor *regex)
1386{
1387 DEBUG_REGEX (" regex_put (%s) start\n", regex->regex);
1388 if (NULL == regex->h)
1389 {
1390 DEBUG_REGEX (" first put, creating DFA\n");
1391 regex->h = GNUNET_REGEX_announce (dht_handle,
1392 &my_full_id,
1393 regex->regex,
1394 regex->compression,
1395 stats);
1396 }
1397 else
1398 {
1399 DEBUG_REGEX (" not first put, using cached data\n");
1400 GNUNET_REGEX_reannounce (regex->h);
1401 }
1402 DEBUG_REGEX (" regex_put (%s) end\n", regex->regex);
1403}
1404
1405
1406/**
1407 * Periodically announce what applications are provided by local clients
1408 * (by regex)
1409 *
1410 * @param cls closure
1411 * @param tc task context
1412 */
1413static void
1414regex_announce (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1415{
1416 struct MeshClient *c = cls;
1417 unsigned int i;
1418
1419 c->regex_announce_task = GNUNET_SCHEDULER_NO_TASK;
1420 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1421 return;
1422 DEBUG_REGEX ("Starting announce for regex\n");
1423 for (i = 0; i < c->n_regex; i++)
1424 regex_put (&c->regexes[i]);
1425 c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time,
1426 &regex_announce,
1427 cls);
1428 DEBUG_REGEX ("Finished announce for regex\n");
1429}
1430
1431 1250
1432/******************************************************************************/ 1251/******************************************************************************/
1433/************************ PERIODIC FUNCTIONS ****************************/ 1252/************************ PERIODIC FUNCTIONS ****************************/
@@ -6178,63 +5997,6 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
6178} 5997}
6179 5998
6180 5999
6181/**
6182 * Function to process paths received for a new peer addition. The recorded
6183 * paths form the initial tunnel, which can be optimized later.
6184 * Called on each result obtained for the DHT search.
6185 *
6186 * @param cls closure
6187 * @param exp when will this value expire
6188 * @param key key of the result
6189 * @param get_path path of the get request
6190 * @param get_path_length lenght of get_path
6191 * @param put_path path of the put request
6192 * @param put_path_length length of the put_path
6193 * @param type type of the result
6194 * @param size number of bytes in data
6195 * @param data pointer to the result data
6196 */
6197static void
6198dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
6199 const struct GNUNET_HashCode * key,
6200 const struct GNUNET_PeerIdentity *get_path,
6201 unsigned int get_path_length,
6202 const struct GNUNET_PeerIdentity *put_path,
6203 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
6204 size_t size, const void *data)
6205{
6206 const struct PBlock *pb = data;
6207 const struct GNUNET_PeerIdentity *pi = &pb->id;
6208 struct MeshTunnel *t = cls;
6209 struct MeshPeerInfo *peer_info;
6210 struct MeshPeerPath *p;
6211
6212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got type DHT result!\n");
6213 if (size != sizeof (struct PBlock))
6214 {
6215 GNUNET_break_op (0);
6216 return;
6217 }
6218 if (ntohl(pb->type) != t->type)
6219 {
6220 GNUNET_break_op (0);
6221 return;
6222 }
6223 GNUNET_assert (NULL != t->owner);
6224 peer_info = peer_info_get (pi);
6225 (void) GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey,
6226 peer_info,
6227 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
6228
6229 p = path_build_from_dht (get_path, get_path_length, put_path,
6230 put_path_length);
6231 path_add_to_peers (p, GNUNET_NO);
6232 path_destroy(p);
6233 tunnel_add_peer (t, peer_info);
6234 peer_info_connect (peer_info, t);
6235}
6236
6237
6238/******************************************************************************/ 6000/******************************************************************************/
6239/********************* MESH LOCAL HANDLES **************************/ 6001/********************* MESH LOCAL HANDLES **************************/
6240/******************************************************************************/ 6002/******************************************************************************/
@@ -7027,209 +6789,6 @@ handle_local_unblacklist (void *cls, struct GNUNET_SERVER_Client *client,
7027 6789
7028 6790
7029/** 6791/**
7030 * Handler for connection requests to new peers by type
7031 *
7032 * @param cls closure
7033 * @param client identification of the client
7034 * @param message the actual message (ConnectPeerByType)
7035 */
7036static void
7037handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
7038 const struct GNUNET_MessageHeader *message)
7039{
7040 struct GNUNET_MESH_ConnectPeerByType *connect_msg;
7041 struct MeshClient *c;
7042 struct MeshTunnel *t;
7043 struct GNUNET_HashCode hash;
7044 MESH_TunnelNumber tid;
7045
7046 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got connect by type request\n");
7047 /* Sanity check for client registration */
7048 if (NULL == (c = client_get (client)))
7049 {
7050 GNUNET_break (0);
7051 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7052 return;
7053 }
7054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
7055
7056 connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message;
7057
7058 /* Sanity check for message size */
7059 if (sizeof (struct GNUNET_MESH_ConnectPeerByType) !=
7060 ntohs (connect_msg->header.size))
7061 {
7062 GNUNET_break (0);
7063 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7064 return;
7065 }
7066
7067 /* Tunnel exists? */
7068 tid = ntohl (connect_msg->tunnel_id);
7069 t = tunnel_get_by_local_id (c, tid);
7070 if (NULL == t)
7071 {
7072 GNUNET_break (0);
7073 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7074 return;
7075 }
7076
7077 /* Does client own tunnel? */
7078 if (t->owner->handle != client)
7079 {
7080 GNUNET_break (0);
7081 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7082 return;
7083 }
7084
7085 /* Do WE have the service? */
7086 t->type = ntohl (connect_msg->type);
7087 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type requested: %u\n", t->type);
7088 GNUNET_CRYPTO_hash (&t->type, sizeof (GNUNET_MESH_ApplicationType), &hash);
7089 if (GNUNET_CONTAINER_multihashmap_contains (applications, &hash) ==
7090 GNUNET_YES)
7091 {
7092 /* Yes! Fast forward, add ourselves to the tunnel and send the
7093 * good news to the client, and alert the destination client of
7094 * an incoming tunnel.
7095 *
7096 * FIXME send a path create to self, avoid code duplication
7097 */
7098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " available locally\n");
7099 GNUNET_CONTAINER_multihashmap_put (t->peers, &my_full_id.hashPubKey,
7100 peer_info_get (&my_full_id),
7101 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
7102
7103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " notifying client\n");
7104 send_client_peer_connected (t, myid);
7105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Done\n");
7106 GNUNET_SERVER_receive_done (client, GNUNET_OK);
7107
7108 t->local_tid_dest = next_local_tid++;
7109 GNUNET_CRYPTO_hash (&t->local_tid_dest, sizeof (MESH_TunnelNumber), &hash);
7110 GNUNET_CONTAINER_multihashmap_put (incoming_tunnels, &hash, t,
7111 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
7112
7113 return;
7114 }
7115 /* Ok, lets find a peer offering the service */
7116 if (NULL != t->dht_get_type)
7117 {
7118 GNUNET_DHT_get_stop (t->dht_get_type);
7119 }
7120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " looking in DHT for %s\n",
7121 GNUNET_h2s (&hash));
7122 t->dht_get_type =
7123 GNUNET_DHT_get_start (dht_handle,
7124 GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE,
7125 &hash,
7126 dht_replication_level,
7127 GNUNET_DHT_RO_RECORD_ROUTE |
7128 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
7129 NULL, 0,
7130 &dht_get_type_handler, t);
7131
7132 GNUNET_SERVER_receive_done (client, GNUNET_OK);
7133 return;
7134}
7135
7136
7137/**
7138 * Handler for connection requests to new peers by a string service description.
7139 *
7140 * @param cls closure
7141 * @param client identification of the client
7142 * @param message the actual message, which includes messages the client wants
7143 */
7144static void
7145handle_local_connect_by_string (void *cls, struct GNUNET_SERVER_Client *client,
7146 const struct GNUNET_MessageHeader *message)
7147{
7148 struct GNUNET_MESH_ConnectPeerByString *msg;
7149 struct MeshRegexSearchInfo *info;
7150 struct MeshTunnel *t;
7151 struct MeshClient *c;
7152 MESH_TunnelNumber tid;
7153 const char *string;
7154 size_t size;
7155 size_t len;
7156
7157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7158 "Connect by string started\n");
7159 msg = (struct GNUNET_MESH_ConnectPeerByString *) message;
7160 size = htons (message->size);
7161
7162 /* Sanity check for client registration */
7163 if (NULL == (c = client_get (client)))
7164 {
7165 GNUNET_break (0);
7166 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7167 return;
7168 }
7169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
7170
7171 /* Message size sanity check */
7172 if (sizeof(struct GNUNET_MESH_ConnectPeerByString) >= size)
7173 {
7174 GNUNET_break (0);
7175 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7176 return;
7177 }
7178
7179 /* Tunnel exists? */
7180 tid = ntohl (msg->tunnel_id);
7181 t = tunnel_get_by_local_id (c, tid);
7182 if (NULL == t)
7183 {
7184 GNUNET_break (0);
7185 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7186 return;
7187 }
7188
7189 /* Does client own tunnel? */
7190 if (t->owner->handle != client)
7191 {
7192 GNUNET_break (0);
7193 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7194 return;
7195 }
7196
7197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7198 " on tunnel %s [%u]\n",
7199 GNUNET_i2s(&my_full_id),
7200 t->id.tid);
7201
7202 /* Only one connect_by_string allowed at the same time! */
7203 /* FIXME: allow more, return handle at api level to cancel, document */
7204 if (NULL != t->regex_search)
7205 {
7206 GNUNET_break (0);
7207 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7208 return;
7209 }
7210
7211 /* Find string itself */
7212 len = size - sizeof(struct GNUNET_MESH_ConnectPeerByString);
7213 string = (const char *) &msg[1];
7214
7215 info = GNUNET_malloc (sizeof (struct MeshRegexSearchInfo));
7216 info->t = t;
7217 info->description = GNUNET_strndup (string, len);
7218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " string: %s\n", info->description);
7219
7220 t->regex_search = info;
7221
7222 info->search_handle = GNUNET_REGEX_search (dht_handle,
7223 info->description,
7224 &regex_found_handler, info,
7225 stats);
7226
7227 GNUNET_SERVER_receive_done (client, GNUNET_OK);
7228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connect by string processed\n");
7229}
7230
7231
7232/**
7233 * Handler for client traffic directed to one peer 6792 * Handler for client traffic directed to one peer
7234 * 6793 *
7235 * @param cls closure 6794 * @param cls closure
@@ -7922,9 +7481,6 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
7922 {&handle_local_unblacklist, NULL, 7481 {&handle_local_unblacklist, NULL,
7923 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST, 7482 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST,
7924 sizeof (struct GNUNET_MESH_PeerControl)}, 7483 sizeof (struct GNUNET_MESH_PeerControl)},
7925 {&handle_local_connect_by_type, NULL,
7926 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE,
7927 sizeof (struct GNUNET_MESH_ConnectPeerByType)},
7928 {&handle_local_connect_by_string, NULL, 7484 {&handle_local_connect_by_string, NULL,
7929 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING, 0}, 7485 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING, 0},
7930 {&handle_local_unicast, NULL, 7486 {&handle_local_unicast, NULL,