-slightly better port setup, for RPS I don't quite see a better way yet
authorChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2016 09:58:55 +0000 (09:58 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2016 09:58:55 +0000 (09:58 +0000)
src/rps/gnunet-service-rps.c
src/rps/gnunet-service-rps_peers.c

index 00c541d1fe2ec618d602f20e43e8ecf5141622bb..eb538e9b5e1aa7b0ba1801b9ae623d03199c39c3 100644 (file)
@@ -24,6 +24,7 @@
  * @author Julius Bünger
  */
 #include "platform.h"
+#include "gnunet_applications.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_cadet_service.h"
 #include "gnunet_peerinfo_service.h"
@@ -2233,14 +2234,24 @@ rps_start (struct GNUNET_SERVER_Handle *server)
  * @param server the initialized server
  * @param c configuration to use
  */
-  static void
+static void
 run (void *cls,
      struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
+  static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
+    {&handle_peer_push        , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH        ,
+      sizeof (struct GNUNET_MessageHeader)},
+    {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
+      sizeof (struct GNUNET_MessageHeader)},
+    {&handle_peer_pull_reply  , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY  , 0},
+    {NULL, 0, 0}
+  };
+
   int size;
   int out_size;
   char* fn_valid_peers;
+  struct GNUNET_HashCode port;
 
   GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL);
   cfg = c;
@@ -2326,20 +2337,16 @@ run (void *cls,
 
 
   /* Initialise cadet */
-  static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
-    {&handle_peer_push        , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH        ,
-      sizeof (struct GNUNET_MessageHeader)},
-    {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
-      sizeof (struct GNUNET_MessageHeader)},
-    {&handle_peer_pull_reply  , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY  , 0},
-    {NULL, 0, 0}
-  };
   cadet_handle = GNUNET_CADET_connect (cfg,
                                        cls,
                                        &cleanup_destroyed_channel,
                                        cadet_handlers);
   GNUNET_assert (NULL != cadet_handle);
-  GNUNET_CADET_open_port (cadet_handle, GC_u2h (GNUNET_RPS_CADET_PORT),
+  GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
+                      strlen (GNUNET_APPLICATION_PORT_RPS),
+                      &port);
+  GNUNET_CADET_open_port (cadet_handle,
+                          &port,
                           &Peers_handle_inbound_channel, cls);
 
 
index 7c9f5ecd93dae4d6a6364a07c95a586ceba8a0a0..665061dc09995b408b18a9a2788418a286ce30f1 100644 (file)
@@ -24,6 +24,7 @@
  * @author Julius Bünger
  */
 #include "platform.h"
+#include "gnunet_applications.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_cadet_service.h"
 #include <inttypes.h>
@@ -271,6 +272,7 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
   return ctx;
 }
 
+
 /**
  * @brief Create a new #PeerContext and insert it into the peer map
  *
@@ -296,6 +298,7 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
   return ctx;
 }
 
+
 /**
  * @brief Create or get a #PeerContext
  *
@@ -313,6 +316,7 @@ create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
   return get_peer_ctx (peer);
 }
 
+
 /**
  * @brief Check whether we have a connection to this @a peer
  *
@@ -347,6 +351,7 @@ Peers_check_connected (const struct GNUNET_PeerIdentity *peer)
   return GNUNET_YES;
 }
 
+
 /**
  * @brief The closure to #get_rand_peer_iterator.
  */
@@ -365,6 +370,7 @@ struct GetRandPeerIteratorCls
   const struct GNUNET_PeerIdentity *peer;
 };
 
+
 /**
  * @brief Iterator function for #get_random_peer_from_peermap.
  *
@@ -395,6 +401,7 @@ get_rand_peer_iterator (void *cls,
   return GNUNET_YES;
 }
 
+
 /**
  * @brief Get a random peer from @a peer_map
  *
@@ -420,6 +427,7 @@ get_random_peer_from_peermap (const struct
   return ret;
 }
 
+
 /**
  * @brief Add a given @a peer to valid peers.
  *
@@ -448,6 +456,7 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer)
   return ret;
 }
 
+
 /**
  * @brief Set the peer flag to living and
  *        call the pending operations on this peer.
@@ -485,6 +494,7 @@ set_peer_live (struct PeerContext *peer_ctx)
   GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
 }
 
+
 /**
  * @brief Get the channel of a peer. If not existing, create.
  *
@@ -495,6 +505,7 @@ struct GNUNET_CADET_Channel *
 get_channel (const struct GNUNET_PeerIdentity *peer)
 {
   struct PeerContext *peer_ctx;
+  struct GNUNET_HashCode port;
 
   peer_ctx = get_peer_ctx (peer);
   if (NULL == peer_ctx->send_channel)
@@ -502,17 +513,21 @@ get_channel (const struct GNUNET_PeerIdentity *peer)
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Trying to establish channel to peer %s\n",
          GNUNET_i2s (peer));
+    GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
+                        strlen (GNUNET_APPLICATION_PORT_RPS),
+                        &port);
     peer_ctx->send_channel =
       GNUNET_CADET_channel_create (cadet_handle,
                                    peer_ctx->send_channel_flags, /* context */
                                    peer,
-                                   GC_u2h (GNUNET_RPS_CADET_PORT),
+                                   &port,
                                    GNUNET_CADET_OPTION_RELIABLE);
   }
   GNUNET_assert (NULL != peer_ctx->send_channel);
   return peer_ctx->send_channel;
 }
 
+
 /**
  * Get the message queue (#GNUNET_MQ_Handle) of a specific peer.
  *
@@ -653,6 +668,7 @@ insert_pending_message (const struct GNUNET_PeerIdentity *peer,
   return pending_msg;
 }
 
+
 /**
  * @brief Remove a pending message from the respective DLL
  *
@@ -673,6 +689,7 @@ remove_pending_message (struct PendingMessage *pending_msg)
   GNUNET_free (pending_msg);
 }
 
+
 /**
  * @brief Check whether function of type #PeerOp was already scheduled
  *
@@ -699,6 +716,7 @@ check_operation_scheduled (const struct GNUNET_PeerIdentity *peer,
   return GNUNET_NO;
 }
 
+
 /**
  * Iterator over hash map entries. Deletes all contexts of peers.
  *
@@ -717,6 +735,7 @@ peermap_clear_iterator (void *cls,
   return GNUNET_YES;
 }
 
+
 /**
  * @brief This is called once a message is sent.
  *
@@ -734,6 +753,7 @@ mq_notify_sent_cb (void *cls)
   remove_pending_message (pending_msg);
 }
 
+
 /**
  * @brief Iterator function for #store_valid_peers.
  *
@@ -774,6 +794,7 @@ store_peer_presistently_iterator (void *cls,
   return GNUNET_YES;
 }
 
+
 /**
  * @brief Store the peers currently in #valid_peers to disk.
  */
@@ -828,6 +849,7 @@ store_valid_peers ()
       GNUNET_CONTAINER_multipeermap_size (valid_peers));
 }
 
+
 /**
  * @brief Convert string representation of peer id to peer id.
  *
@@ -873,6 +895,7 @@ s2i_full (const char *string_repr)
   return peer;
 }
 
+
 /**
  * @brief Restore the peers on disk to #valid_peers.
  */
@@ -926,6 +949,7 @@ restore_valid_peers ()
       num_peers);
 }
 
+
 /**
  * @brief Initialise storage of peers
  *
@@ -946,6 +970,7 @@ Peers_initialise (char* fn_valid_peers,
   restore_valid_peers ();
 }
 
+
 /**
  * @brief Delete storage of peers that was created with #Peers_initialise ()
  */
@@ -1014,6 +1039,7 @@ Peers_get_valid_peers (PeersIterator iterator,
   return ret;
 }
 
+
 /**
  * @brief Add peer to known peers.
  *
@@ -1068,6 +1094,7 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
   return ret;
 }
 
+
 /**
  * @brief Remove unecessary data
  *
@@ -1102,6 +1129,7 @@ Peers_clean_peer (const struct GNUNET_PeerIdentity *peer)
   return GNUNET_YES;
 }
 
+
 /**
  * @brief Remove peer
  *
@@ -1173,6 +1201,7 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
   return GNUNET_YES;
 }
 
+
 /**
  * @brief set flags on a given peer.
  *
@@ -1188,6 +1217,7 @@ Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlag
   set_peer_flag (peer_ctx, flags);
 }
 
+
 /**
  * @brief unset flags on a given peer.
  *
@@ -1203,6 +1233,7 @@ Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl
   unset_peer_flag (peer_ctx, flags);
 }
 
+
 /**
  * @brief Check whether flags on a peer are set.
  *
@@ -1239,6 +1270,7 @@ Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
   set_channel_flag (channel_flags, flags);
 }
 
+
 /**
  * @brief unset flags on a given channel.
  *
@@ -1251,6 +1283,7 @@ Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags
   unset_channel_flag (channel_flags, flags);
 }
 
+
 /**
  * @brief Check whether flags on a channel are set.
  *
@@ -1266,6 +1299,7 @@ Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags
   return check_channel_flag_set (channel_flags, flags);
 }
 
+
 /**
  * @brief Check whether we have information about the given peer.
  *
@@ -1282,6 +1316,7 @@ Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer)
   return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
 }
 
+
 /**
  * @brief Check whether @a peer is actually a peer.
  *
@@ -1298,6 +1333,7 @@ Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer)
   return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
 }
 
+
 /**
  * @brief Indicate that we want to send to the other peer
  *
@@ -1312,6 +1348,7 @@ Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
   (void) get_channel (peer);
 }
 
+
 /**
  * @brief Check whether other peer has the intention to send/opened channel
  *        towars us
@@ -1334,6 +1371,7 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
   return GNUNET_NO;
 }
 
+
 /**
  * Handle the channel a peer opens to us.
  *
@@ -1375,6 +1413,7 @@ Peers_handle_inbound_channel (void *cls,
   return peer_ctx->recv_channel_flags;
 }
 
+
 /**
  * @brief Check whether a sending channel towards the given peer exists
  *
@@ -1400,6 +1439,7 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
   return GNUNET_YES;
 }
 
+
 /**
  * @brief check whether the given channel is the sending channel of the given
  *        peer
@@ -1437,6 +1477,7 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
   return GNUNET_NO;
 }
 
+
 /**
  * @brief Destroy the send channel of a peer e.g. stop indicating a sending
  *        intention to another peer