aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/gnunet-service-rps_peers.c')
-rw-r--r--src/rps/gnunet-service-rps_peers.c91
1 files changed, 79 insertions, 12 deletions
diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c
index e0b278bd0..db540fa3d 100644
--- a/src/rps/gnunet-service-rps_peers.c
+++ b/src/rps/gnunet-service-rps_peers.c
@@ -251,6 +251,17 @@ static const struct GNUNET_PeerIdentity *own_identity;
251 */ 251 */
252static struct GNUNET_CADET_Handle *cadet_handle; 252static struct GNUNET_CADET_Handle *cadet_handle;
253 253
254/**
255 * @brief Disconnect handler
256 */
257static GNUNET_CADET_DisconnectEventHandler cleanup_destroyed_channel;
258
259/**
260 * @brief cadet handlers
261 */
262static const struct GNUNET_MQ_MessageHandler *cadet_handlers;
263
264
254 265
255/** 266/**
256 * @brief Get the #PeerContext associated with a peer 267 * @brief Get the #PeerContext associated with a peer
@@ -522,11 +533,14 @@ get_channel (const struct GNUNET_PeerIdentity *peer)
522 strlen (GNUNET_APPLICATION_PORT_RPS), 533 strlen (GNUNET_APPLICATION_PORT_RPS),
523 &port); 534 &port);
524 peer_ctx->send_channel = 535 peer_ctx->send_channel =
525 GNUNET_CADET_channel_create (cadet_handle, 536 GNUNET_CADET_channel_creatE (cadet_handle,
526 peer_ctx->send_channel_flags, /* context */ 537 (struct GNUNET_PeerIdentity *) peer, /* context */
527 peer, 538 peer,
528 &port, 539 &port,
529 GNUNET_CADET_OPTION_RELIABLE); 540 GNUNET_CADET_OPTION_RELIABLE,
541 NULL, /* WindowSize handler */
542 cleanup_destroyed_channel, /* Disconnect handler */
543 cadet_handlers);
530 } 544 }
531 GNUNET_assert (NULL != peer_ctx->send_channel); 545 GNUNET_assert (NULL != peer_ctx->send_channel);
532 return peer_ctx->send_channel; 546 return peer_ctx->send_channel;
@@ -932,15 +946,21 @@ restore_valid_peers ()
932 * 946 *
933 * @param fn_valid_peers filename of the file used to store valid peer ids 947 * @param fn_valid_peers filename of the file used to store valid peer ids
934 * @param cadet_h cadet handle 948 * @param cadet_h cadet handle
949 * @param disconnect_handler Disconnect handler
950 * @param c_handlers cadet handlers
935 * @param own_id own peer identity 951 * @param own_id own peer identity
936 */ 952 */
937void 953void
938Peers_initialise (char* fn_valid_peers, 954Peers_initialise (char* fn_valid_peers,
939 struct GNUNET_CADET_Handle *cadet_h, 955 struct GNUNET_CADET_Handle *cadet_h,
956 GNUNET_CADET_DisconnectEventHandler disconnect_handler,
957 const struct GNUNET_MQ_MessageHandler *c_handlers,
940 const struct GNUNET_PeerIdentity *own_id) 958 const struct GNUNET_PeerIdentity *own_id)
941{ 959{
942 filename_valid_peers = GNUNET_strdup (fn_valid_peers); 960 filename_valid_peers = GNUNET_strdup (fn_valid_peers);
943 cadet_handle = cadet_h; 961 cadet_handle = cadet_h;
962 cleanup_destroyed_channel = disconnect_handler;
963 cadet_handlers = c_handlers;
944 own_identity = own_id; 964 own_identity = own_id;
945 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); 965 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
946 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); 966 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
@@ -1279,6 +1299,34 @@ Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags
1279 return check_channel_flag_set (channel_flags, flags); 1299 return check_channel_flag_set (channel_flags, flags);
1280} 1300}
1281 1301
1302/**
1303 * @brief Get the flags for the channel in @a role for @a peer.
1304 *
1305 * @param peer Peer to get the channel flags for.
1306 * @param role Role of channel to get flags for
1307 *
1308 * @return The flags.
1309 */
1310uint32_t *
1311Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
1312 enum Peers_ChannelRole role)
1313{
1314 const struct PeerContext *peer_ctx;
1315
1316 peer_ctx = get_peer_ctx (peer);
1317 if (Peers_CHANNEL_ROLE_SENDING == role)
1318 {
1319 return peer_ctx->send_channel_flags;
1320 }
1321 else if (Peers_CHANNEL_ROLE_RECEIVING == role)
1322 {
1323 return peer_ctx->recv_channel_flags;
1324 }
1325 else
1326 {
1327 GNUNET_assert (0);
1328 }
1329}
1282 1330
1283/** 1331/**
1284 * @brief Check whether we have information about the given peer. 1332 * @brief Check whether we have information about the given peer.
@@ -1358,8 +1406,6 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1358 * @param cls The closure 1406 * @param cls The closure
1359 * @param channel The channel the peer wants to establish 1407 * @param channel The channel the peer wants to establish
1360 * @param initiator The peer's peer ID 1408 * @param initiator The peer's peer ID
1361 * @param port The port the channel is being established over
1362 * @param options Further options
1363 * 1409 *
1364 * @return initial channel context for the channel 1410 * @return initial channel context for the channel
1365 * (can be NULL -- that's not an error) 1411 * (can be NULL -- that's not an error)
@@ -1367,9 +1413,7 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1367void * 1413void *
1368Peers_handle_inbound_channel (void *cls, 1414Peers_handle_inbound_channel (void *cls,
1369 struct GNUNET_CADET_Channel *channel, 1415 struct GNUNET_CADET_Channel *channel,
1370 const struct GNUNET_PeerIdentity *initiator, 1416 const struct GNUNET_PeerIdentity *initiator)
1371 const struct GNUNET_HashCode *port,
1372 enum GNUNET_CADET_ChannelOption options)
1373{ 1417{
1374 struct PeerContext *peer_ctx; 1418 struct PeerContext *peer_ctx;
1375 1419
@@ -1387,10 +1431,10 @@ Peers_handle_inbound_channel (void *cls,
1387 Peers_CHANNEL_ESTABLISHED_TWICE); 1431 Peers_CHANNEL_ESTABLISHED_TWICE);
1388 GNUNET_CADET_channel_destroy (channel); 1432 GNUNET_CADET_channel_destroy (channel);
1389 /* return the channel context */ 1433 /* return the channel context */
1390 return peer_ctx->recv_channel_flags; 1434 return (struct PeerContext *) initiator;
1391 } 1435 }
1392 peer_ctx->recv_channel = channel; 1436 peer_ctx->recv_channel = channel;
1393 return peer_ctx->recv_channel_flags; 1437 return (struct PeerContext *) initiator;
1394} 1438}
1395 1439
1396 1440
@@ -1500,8 +1544,7 @@ Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1500 */ 1544 */
1501void 1545void
1502Peers_cleanup_destroyed_channel (void *cls, 1546Peers_cleanup_destroyed_channel (void *cls,
1503 const struct GNUNET_CADET_Channel *channel, 1547 const struct GNUNET_CADET_Channel *channel)
1504 void *channel_ctx)
1505{ 1548{
1506 struct GNUNET_PeerIdentity *peer; 1549 struct GNUNET_PeerIdentity *peer;
1507 struct PeerContext *peer_ctx; 1550 struct PeerContext *peer_ctx;
@@ -1635,4 +1678,28 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
1635 return GNUNET_NO; 1678 return GNUNET_NO;
1636} 1679}
1637 1680
1681/**
1682 * @brief Get the recv_channel of @a peer.
1683 * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming
1684 * messages.
1685 *
1686 * @param peer The peer to get the recv_channel from.
1687 *
1688 * @return The recv_channel.
1689 */
1690struct GNUNET_CADET_Channel *
1691Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer)
1692{
1693 struct PeerContext *peer_ctx;
1694
1695 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, own_identity))
1696 {
1697 return GNUNET_NO;
1698 }
1699 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1700
1701 peer_ctx = get_peer_ctx (peer);
1702 return peer_ctx->recv_channel;
1703}
1704
1638/* end of gnunet-service-rps_peers.c */ 1705/* end of gnunet-service-rps_peers.c */