aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-14 09:58:55 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-14 09:58:55 +0000
commit0d61985b574cf5ba0e807200c5a8612e6b88a357 (patch)
treea7cbe6f154db88e78bfa461fc0f569e52d476ea6 /src/rps
parentae0700a8b5d905db4403a52dbf4a5eda5315e3ec (diff)
downloadgnunet-0d61985b574cf5ba0e807200c5a8612e6b88a357.tar.gz
gnunet-0d61985b574cf5ba0e807200c5a8612e6b88a357.zip
-slightly better port setup, for RPS I don't quite see a better way yet
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c27
-rw-r--r--src/rps/gnunet-service-rps_peers.c43
2 files changed, 59 insertions, 11 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 00c541d1f..eb538e9b5 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -24,6 +24,7 @@
24 * @author Julius Bünger 24 * @author Julius Bünger
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_applications.h"
27#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
28#include "gnunet_cadet_service.h" 29#include "gnunet_cadet_service.h"
29#include "gnunet_peerinfo_service.h" 30#include "gnunet_peerinfo_service.h"
@@ -2233,14 +2234,24 @@ rps_start (struct GNUNET_SERVER_Handle *server)
2233 * @param server the initialized server 2234 * @param server the initialized server
2234 * @param c configuration to use 2235 * @param c configuration to use
2235 */ 2236 */
2236 static void 2237static void
2237run (void *cls, 2238run (void *cls,
2238 struct GNUNET_SERVER_Handle *server, 2239 struct GNUNET_SERVER_Handle *server,
2239 const struct GNUNET_CONFIGURATION_Handle *c) 2240 const struct GNUNET_CONFIGURATION_Handle *c)
2240{ 2241{
2242 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
2243 {&handle_peer_push , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH ,
2244 sizeof (struct GNUNET_MessageHeader)},
2245 {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
2246 sizeof (struct GNUNET_MessageHeader)},
2247 {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0},
2248 {NULL, 0, 0}
2249 };
2250
2241 int size; 2251 int size;
2242 int out_size; 2252 int out_size;
2243 char* fn_valid_peers; 2253 char* fn_valid_peers;
2254 struct GNUNET_HashCode port;
2244 2255
2245 GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL); 2256 GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL);
2246 cfg = c; 2257 cfg = c;
@@ -2326,20 +2337,16 @@ run (void *cls,
2326 2337
2327 2338
2328 /* Initialise cadet */ 2339 /* Initialise cadet */
2329 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
2330 {&handle_peer_push , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH ,
2331 sizeof (struct GNUNET_MessageHeader)},
2332 {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
2333 sizeof (struct GNUNET_MessageHeader)},
2334 {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0},
2335 {NULL, 0, 0}
2336 };
2337 cadet_handle = GNUNET_CADET_connect (cfg, 2340 cadet_handle = GNUNET_CADET_connect (cfg,
2338 cls, 2341 cls,
2339 &cleanup_destroyed_channel, 2342 &cleanup_destroyed_channel,
2340 cadet_handlers); 2343 cadet_handlers);
2341 GNUNET_assert (NULL != cadet_handle); 2344 GNUNET_assert (NULL != cadet_handle);
2342 GNUNET_CADET_open_port (cadet_handle, GC_u2h (GNUNET_RPS_CADET_PORT), 2345 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
2346 strlen (GNUNET_APPLICATION_PORT_RPS),
2347 &port);
2348 GNUNET_CADET_open_port (cadet_handle,
2349 &port,
2343 &Peers_handle_inbound_channel, cls); 2350 &Peers_handle_inbound_channel, cls);
2344 2351
2345 2352
diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c
index 7c9f5ecd9..665061dc0 100644
--- a/src/rps/gnunet-service-rps_peers.c
+++ b/src/rps/gnunet-service-rps_peers.c
@@ -24,6 +24,7 @@
24 * @author Julius Bünger 24 * @author Julius Bünger
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_applications.h"
27#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
28#include "gnunet_cadet_service.h" 29#include "gnunet_cadet_service.h"
29#include <inttypes.h> 30#include <inttypes.h>
@@ -271,6 +272,7 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
271 return ctx; 272 return ctx;
272} 273}
273 274
275
274/** 276/**
275 * @brief Create a new #PeerContext and insert it into the peer map 277 * @brief Create a new #PeerContext and insert it into the peer map
276 * 278 *
@@ -296,6 +298,7 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
296 return ctx; 298 return ctx;
297} 299}
298 300
301
299/** 302/**
300 * @brief Create or get a #PeerContext 303 * @brief Create or get a #PeerContext
301 * 304 *
@@ -313,6 +316,7 @@ create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
313 return get_peer_ctx (peer); 316 return get_peer_ctx (peer);
314} 317}
315 318
319
316/** 320/**
317 * @brief Check whether we have a connection to this @a peer 321 * @brief Check whether we have a connection to this @a peer
318 * 322 *
@@ -347,6 +351,7 @@ Peers_check_connected (const struct GNUNET_PeerIdentity *peer)
347 return GNUNET_YES; 351 return GNUNET_YES;
348} 352}
349 353
354
350/** 355/**
351 * @brief The closure to #get_rand_peer_iterator. 356 * @brief The closure to #get_rand_peer_iterator.
352 */ 357 */
@@ -365,6 +370,7 @@ struct GetRandPeerIteratorCls
365 const struct GNUNET_PeerIdentity *peer; 370 const struct GNUNET_PeerIdentity *peer;
366}; 371};
367 372
373
368/** 374/**
369 * @brief Iterator function for #get_random_peer_from_peermap. 375 * @brief Iterator function for #get_random_peer_from_peermap.
370 * 376 *
@@ -395,6 +401,7 @@ get_rand_peer_iterator (void *cls,
395 return GNUNET_YES; 401 return GNUNET_YES;
396} 402}
397 403
404
398/** 405/**
399 * @brief Get a random peer from @a peer_map 406 * @brief Get a random peer from @a peer_map
400 * 407 *
@@ -420,6 +427,7 @@ get_random_peer_from_peermap (const struct
420 return ret; 427 return ret;
421} 428}
422 429
430
423/** 431/**
424 * @brief Add a given @a peer to valid peers. 432 * @brief Add a given @a peer to valid peers.
425 * 433 *
@@ -448,6 +456,7 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer)
448 return ret; 456 return ret;
449} 457}
450 458
459
451/** 460/**
452 * @brief Set the peer flag to living and 461 * @brief Set the peer flag to living and
453 * call the pending operations on this peer. 462 * call the pending operations on this peer.
@@ -485,6 +494,7 @@ set_peer_live (struct PeerContext *peer_ctx)
485 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); 494 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
486} 495}
487 496
497
488/** 498/**
489 * @brief Get the channel of a peer. If not existing, create. 499 * @brief Get the channel of a peer. If not existing, create.
490 * 500 *
@@ -495,6 +505,7 @@ struct GNUNET_CADET_Channel *
495get_channel (const struct GNUNET_PeerIdentity *peer) 505get_channel (const struct GNUNET_PeerIdentity *peer)
496{ 506{
497 struct PeerContext *peer_ctx; 507 struct PeerContext *peer_ctx;
508 struct GNUNET_HashCode port;
498 509
499 peer_ctx = get_peer_ctx (peer); 510 peer_ctx = get_peer_ctx (peer);
500 if (NULL == peer_ctx->send_channel) 511 if (NULL == peer_ctx->send_channel)
@@ -502,17 +513,21 @@ get_channel (const struct GNUNET_PeerIdentity *peer)
502 LOG (GNUNET_ERROR_TYPE_DEBUG, 513 LOG (GNUNET_ERROR_TYPE_DEBUG,
503 "Trying to establish channel to peer %s\n", 514 "Trying to establish channel to peer %s\n",
504 GNUNET_i2s (peer)); 515 GNUNET_i2s (peer));
516 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
517 strlen (GNUNET_APPLICATION_PORT_RPS),
518 &port);
505 peer_ctx->send_channel = 519 peer_ctx->send_channel =
506 GNUNET_CADET_channel_create (cadet_handle, 520 GNUNET_CADET_channel_create (cadet_handle,
507 peer_ctx->send_channel_flags, /* context */ 521 peer_ctx->send_channel_flags, /* context */
508 peer, 522 peer,
509 GC_u2h (GNUNET_RPS_CADET_PORT), 523 &port,
510 GNUNET_CADET_OPTION_RELIABLE); 524 GNUNET_CADET_OPTION_RELIABLE);
511 } 525 }
512 GNUNET_assert (NULL != peer_ctx->send_channel); 526 GNUNET_assert (NULL != peer_ctx->send_channel);
513 return peer_ctx->send_channel; 527 return peer_ctx->send_channel;
514} 528}
515 529
530
516/** 531/**
517 * Get the message queue (#GNUNET_MQ_Handle) of a specific peer. 532 * Get the message queue (#GNUNET_MQ_Handle) of a specific peer.
518 * 533 *
@@ -653,6 +668,7 @@ insert_pending_message (const struct GNUNET_PeerIdentity *peer,
653 return pending_msg; 668 return pending_msg;
654} 669}
655 670
671
656/** 672/**
657 * @brief Remove a pending message from the respective DLL 673 * @brief Remove a pending message from the respective DLL
658 * 674 *
@@ -673,6 +689,7 @@ remove_pending_message (struct PendingMessage *pending_msg)
673 GNUNET_free (pending_msg); 689 GNUNET_free (pending_msg);
674} 690}
675 691
692
676/** 693/**
677 * @brief Check whether function of type #PeerOp was already scheduled 694 * @brief Check whether function of type #PeerOp was already scheduled
678 * 695 *
@@ -699,6 +716,7 @@ check_operation_scheduled (const struct GNUNET_PeerIdentity *peer,
699 return GNUNET_NO; 716 return GNUNET_NO;
700} 717}
701 718
719
702/** 720/**
703 * Iterator over hash map entries. Deletes all contexts of peers. 721 * Iterator over hash map entries. Deletes all contexts of peers.
704 * 722 *
@@ -717,6 +735,7 @@ peermap_clear_iterator (void *cls,
717 return GNUNET_YES; 735 return GNUNET_YES;
718} 736}
719 737
738
720/** 739/**
721 * @brief This is called once a message is sent. 740 * @brief This is called once a message is sent.
722 * 741 *
@@ -734,6 +753,7 @@ mq_notify_sent_cb (void *cls)
734 remove_pending_message (pending_msg); 753 remove_pending_message (pending_msg);
735} 754}
736 755
756
737/** 757/**
738 * @brief Iterator function for #store_valid_peers. 758 * @brief Iterator function for #store_valid_peers.
739 * 759 *
@@ -774,6 +794,7 @@ store_peer_presistently_iterator (void *cls,
774 return GNUNET_YES; 794 return GNUNET_YES;
775} 795}
776 796
797
777/** 798/**
778 * @brief Store the peers currently in #valid_peers to disk. 799 * @brief Store the peers currently in #valid_peers to disk.
779 */ 800 */
@@ -828,6 +849,7 @@ store_valid_peers ()
828 GNUNET_CONTAINER_multipeermap_size (valid_peers)); 849 GNUNET_CONTAINER_multipeermap_size (valid_peers));
829} 850}
830 851
852
831/** 853/**
832 * @brief Convert string representation of peer id to peer id. 854 * @brief Convert string representation of peer id to peer id.
833 * 855 *
@@ -873,6 +895,7 @@ s2i_full (const char *string_repr)
873 return peer; 895 return peer;
874} 896}
875 897
898
876/** 899/**
877 * @brief Restore the peers on disk to #valid_peers. 900 * @brief Restore the peers on disk to #valid_peers.
878 */ 901 */
@@ -926,6 +949,7 @@ restore_valid_peers ()
926 num_peers); 949 num_peers);
927} 950}
928 951
952
929/** 953/**
930 * @brief Initialise storage of peers 954 * @brief Initialise storage of peers
931 * 955 *
@@ -946,6 +970,7 @@ Peers_initialise (char* fn_valid_peers,
946 restore_valid_peers (); 970 restore_valid_peers ();
947} 971}
948 972
973
949/** 974/**
950 * @brief Delete storage of peers that was created with #Peers_initialise () 975 * @brief Delete storage of peers that was created with #Peers_initialise ()
951 */ 976 */
@@ -1014,6 +1039,7 @@ Peers_get_valid_peers (PeersIterator iterator,
1014 return ret; 1039 return ret;
1015} 1040}
1016 1041
1042
1017/** 1043/**
1018 * @brief Add peer to known peers. 1044 * @brief Add peer to known peers.
1019 * 1045 *
@@ -1068,6 +1094,7 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
1068 return ret; 1094 return ret;
1069} 1095}
1070 1096
1097
1071/** 1098/**
1072 * @brief Remove unecessary data 1099 * @brief Remove unecessary data
1073 * 1100 *
@@ -1102,6 +1129,7 @@ Peers_clean_peer (const struct GNUNET_PeerIdentity *peer)
1102 return GNUNET_YES; 1129 return GNUNET_YES;
1103} 1130}
1104 1131
1132
1105/** 1133/**
1106 * @brief Remove peer 1134 * @brief Remove peer
1107 * 1135 *
@@ -1173,6 +1201,7 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1173 return GNUNET_YES; 1201 return GNUNET_YES;
1174} 1202}
1175 1203
1204
1176/** 1205/**
1177 * @brief set flags on a given peer. 1206 * @brief set flags on a given peer.
1178 * 1207 *
@@ -1188,6 +1217,7 @@ Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlag
1188 set_peer_flag (peer_ctx, flags); 1217 set_peer_flag (peer_ctx, flags);
1189} 1218}
1190 1219
1220
1191/** 1221/**
1192 * @brief unset flags on a given peer. 1222 * @brief unset flags on a given peer.
1193 * 1223 *
@@ -1203,6 +1233,7 @@ Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl
1203 unset_peer_flag (peer_ctx, flags); 1233 unset_peer_flag (peer_ctx, flags);
1204} 1234}
1205 1235
1236
1206/** 1237/**
1207 * @brief Check whether flags on a peer are set. 1238 * @brief Check whether flags on a peer are set.
1208 * 1239 *
@@ -1239,6 +1270,7 @@ Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1239 set_channel_flag (channel_flags, flags); 1270 set_channel_flag (channel_flags, flags);
1240} 1271}
1241 1272
1273
1242/** 1274/**
1243 * @brief unset flags on a given channel. 1275 * @brief unset flags on a given channel.
1244 * 1276 *
@@ -1251,6 +1283,7 @@ Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags
1251 unset_channel_flag (channel_flags, flags); 1283 unset_channel_flag (channel_flags, flags);
1252} 1284}
1253 1285
1286
1254/** 1287/**
1255 * @brief Check whether flags on a channel are set. 1288 * @brief Check whether flags on a channel are set.
1256 * 1289 *
@@ -1266,6 +1299,7 @@ Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags
1266 return check_channel_flag_set (channel_flags, flags); 1299 return check_channel_flag_set (channel_flags, flags);
1267} 1300}
1268 1301
1302
1269/** 1303/**
1270 * @brief Check whether we have information about the given peer. 1304 * @brief Check whether we have information about the given peer.
1271 * 1305 *
@@ -1282,6 +1316,7 @@ Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer)
1282 return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); 1316 return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
1283} 1317}
1284 1318
1319
1285/** 1320/**
1286 * @brief Check whether @a peer is actually a peer. 1321 * @brief Check whether @a peer is actually a peer.
1287 * 1322 *
@@ -1298,6 +1333,7 @@ Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer)
1298 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); 1333 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1299} 1334}
1300 1335
1336
1301/** 1337/**
1302 * @brief Indicate that we want to send to the other peer 1338 * @brief Indicate that we want to send to the other peer
1303 * 1339 *
@@ -1312,6 +1348,7 @@ Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
1312 (void) get_channel (peer); 1348 (void) get_channel (peer);
1313} 1349}
1314 1350
1351
1315/** 1352/**
1316 * @brief Check whether other peer has the intention to send/opened channel 1353 * @brief Check whether other peer has the intention to send/opened channel
1317 * towars us 1354 * towars us
@@ -1334,6 +1371,7 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1334 return GNUNET_NO; 1371 return GNUNET_NO;
1335} 1372}
1336 1373
1374
1337/** 1375/**
1338 * Handle the channel a peer opens to us. 1376 * Handle the channel a peer opens to us.
1339 * 1377 *
@@ -1375,6 +1413,7 @@ Peers_handle_inbound_channel (void *cls,
1375 return peer_ctx->recv_channel_flags; 1413 return peer_ctx->recv_channel_flags;
1376} 1414}
1377 1415
1416
1378/** 1417/**
1379 * @brief Check whether a sending channel towards the given peer exists 1418 * @brief Check whether a sending channel towards the given peer exists
1380 * 1419 *
@@ -1400,6 +1439,7 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
1400 return GNUNET_YES; 1439 return GNUNET_YES;
1401} 1440}
1402 1441
1442
1403/** 1443/**
1404 * @brief check whether the given channel is the sending channel of the given 1444 * @brief check whether the given channel is the sending channel of the given
1405 * peer 1445 * peer
@@ -1437,6 +1477,7 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
1437 return GNUNET_NO; 1477 return GNUNET_NO;
1438} 1478}
1439 1479
1480
1440/** 1481/**
1441 * @brief Destroy the send channel of a peer e.g. stop indicating a sending 1482 * @brief Destroy the send channel of a peer e.g. stop indicating a sending
1442 * intention to another peer 1483 * intention to another peer