aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-01-20 09:58:33 +0000
committerJulius Bünger <buenger@mytum.de>2015-01-20 09:58:33 +0000
commit6fd7ca6a91ddf9a0c67ea661a7686a358a0e262e (patch)
tree232e1979559155b93a38e7b19a5dd3bcad302ed0
parent9b640e19853156059fe8e1a614aadd1d6d48f63e (diff)
downloadgnunet-6fd7ca6a91ddf9a0c67ea661a7686a358a0e262e.tar.gz
gnunet-6fd7ca6a91ddf9a0c67ea661a7686a358a0e262e.zip
optical changes, small fix, draft for notification
-rw-r--r--src/rps/gnunet-service-rps.c72
1 files changed, 54 insertions, 18 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index a8f36b14c..6caa77c40 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -56,7 +56,7 @@
56 56
57// TODO check that every id we get is valid - is it reachable? 57// TODO check that every id we get is valid - is it reachable?
58 58
59// TODO ignore list 59// TODO ignore list?
60 60
61// hist_size_init, hist_size_max 61// hist_size_init, hist_size_max
62 62
@@ -382,7 +382,8 @@ get_rand_peer (const struct GNUNET_PeerIdentity *peer_list, unsigned int list_si
382 * Get the context of a peer. If not existing, create. 382 * Get the context of a peer. If not existing, create.
383 */ 383 */
384 struct PeerContext * 384 struct PeerContext *
385get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) 385get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
386 const struct GNUNET_PeerIdentity *peer)
386{ 387{
387 struct PeerContext *ctx; 388 struct PeerContext *ctx;
388 389
@@ -397,29 +398,63 @@ get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNE
397 ctx->mq = NULL; 398 ctx->mq = NULL;
398 ctx->send_channel = NULL; 399 ctx->send_channel = NULL;
399 ctx->recv_channel = NULL; 400 ctx->recv_channel = NULL;
400 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 401 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx,
402 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
401 } 403 }
402 return ctx; 404 return ctx;
403} 405}
404 406
405 407
406/** 408/**
409 * Callback that is called when a channel was effectively established.
410 * This is given to ntfy_tmt_rdy and called when the channel was
411 * successfully established.
412 */
413 size_t
414peer_is_live (void *cls, size_t size, void *buf)
415{
416 struct GNUNET_PeerIdentity *peer;
417 struct PeerContext *peer_ctx;
418
419 peer = (struct GNUNET_PeerIdentity *) cls;
420 peer_ctx = get_peer_ctx (peer_map, peer);
421 peer_ctx->peer_flags |= LIVING;
422
423 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %s is live\n", GNUNET_i2s (peer));
424
425 GNUNET_free (peer);
426
427 buf = NULL;
428 return 0;
429}
430
431
432/**
407 * Get the channel of a peer. If not existing, create. 433 * Get the channel of a peer. If not existing, create.
408 */ 434 */
409 struct GNUNET_CADET_Channel * 435 struct GNUNET_CADET_Channel *
410get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer) 436get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
437 const struct GNUNET_PeerIdentity *peer)
411{ 438{
412 struct PeerContext *ctx; 439 struct PeerContext *ctx;
440 //struct GNUNET_PeerIdentity *tmp_peer;
413 441
414 ctx = get_peer_ctx (peer_map, peer); 442 ctx = get_peer_ctx (peer_map, peer);
415 if (NULL == ctx->send_channel) 443 if (NULL == ctx->send_channel)
416 { 444 {
417 ctx->send_channel = GNUNET_CADET_channel_create (cadet_handle, NULL, peer, 445 ctx->send_channel = GNUNET_CADET_channel_create (cadet_handle, NULL, peer,
418 GNUNET_RPS_CADET_PORT, 446 GNUNET_RPS_CADET_PORT,
419 GNUNET_CADET_OPTION_RELIABLE); 447 GNUNET_CADET_OPTION_RELIABLE);
448
449 //tmp_peer = GNUNET_new (struct GNUNET_PeerIdentity);
450 //*tmp_peer = *peer;
451 //(void) GNUNET_CADET_notify_transmit_ready (ctx->send_channel, GNUNET_NO,
452 // GNUNET_TIME_UNIT_FOREVER_REL,
453 // 0, peer_is_live, tmp_peer);
454
420 // do I have to explicitly put it in the peer_map? 455 // do I have to explicitly put it in the peer_map?
421 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, 456 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx,
422 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 457 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
423 } 458 }
424 return ctx->send_channel; 459 return ctx->send_channel;
425} 460}
@@ -432,7 +467,8 @@ get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET
432 * simply return it, otherways create one. 467 * simply return it, otherways create one.
433 */ 468 */
434 struct GNUNET_MQ_Handle * 469 struct GNUNET_MQ_Handle *
435get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer_id) 470get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
471 const struct GNUNET_PeerIdentity *peer_id)
436{ 472{
437 struct PeerContext *ctx; 473 struct PeerContext *ctx;
438 474
@@ -654,7 +690,7 @@ handle_client_seed (void *cls,
654 GNUNET_SYSERR); 690 GNUNET_SYSERR);
655 } 691 }
656 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message; 692 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message;
657 if (ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage) / 693 if ((ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
658 sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers)) 694 sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
659 { 695 {
660 GNUNET_break_op (0); 696 GNUNET_break_op (0);
@@ -1179,7 +1215,7 @@ handle_inbound_channel (void *cls,
1179 * @param channel The channel being closed 1215 * @param channel The channel being closed
1180 * @param channel_ctx The context associated with this channel 1216 * @param channel_ctx The context associated with this channel
1181 */ 1217 */
1182static void 1218 static void
1183cleanup_channel (void *cls, 1219cleanup_channel (void *cls,
1184 const struct GNUNET_CADET_Channel *channel, 1220 const struct GNUNET_CADET_Channel *channel,
1185 void *channel_ctx) 1221 void *channel_ctx)
@@ -1203,7 +1239,7 @@ cleanup_channel (void *cls,
1203/** 1239/**
1204 * Actually start the service. 1240 * Actually start the service.
1205 */ 1241 */
1206static void 1242 static void
1207rps_start (struct GNUNET_SERVER_Handle *server) 1243rps_start (struct GNUNET_SERVER_Handle *server)
1208{ 1244{
1209 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1245 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -1236,7 +1272,7 @@ rps_start (struct GNUNET_SERVER_Handle *server)
1236 * @param server the initialized server 1272 * @param server the initialized server
1237 * @param c configuration to use 1273 * @param c configuration to use
1238 */ 1274 */
1239static void 1275 static void
1240run (void *cls, 1276run (void *cls,
1241 struct GNUNET_SERVER_Handle *server, 1277 struct GNUNET_SERVER_Handle *server,
1242 const struct GNUNET_CONFIGURATION_Handle *c) 1278 const struct GNUNET_CONFIGURATION_Handle *c)
@@ -1332,11 +1368,11 @@ run (void *cls,
1332 1368
1333 const uint32_t ports[] = {GNUNET_RPS_CADET_PORT, 0}; // _PORT specified in src/rps/rps.h 1369 const uint32_t ports[] = {GNUNET_RPS_CADET_PORT, 0}; // _PORT specified in src/rps/rps.h
1334 cadet_handle = GNUNET_CADET_connect (cfg, 1370 cadet_handle = GNUNET_CADET_connect (cfg,
1335 cls, 1371 cls,
1336 &handle_inbound_channel, 1372 &handle_inbound_channel,
1337 &cleanup_channel, 1373 &cleanup_channel,
1338 cadet_handlers, 1374 cadet_handlers,
1339 ports); 1375 ports);
1340 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to CADET\n"); 1376 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to CADET\n");
1341 1377
1342 1378
@@ -1375,7 +1411,7 @@ run (void *cls,
1375 * @param argv command line arguments 1411 * @param argv command line arguments
1376 * @return 0 ok, 1 on error 1412 * @return 0 ok, 1 on error
1377 */ 1413 */
1378int 1414 int
1379main (int argc, char *const *argv) 1415main (int argc, char *const *argv)
1380{ 1416{
1381 return (GNUNET_OK == 1417 return (GNUNET_OK ==