-skeletons for transport-ng
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_peer.h
index 20ff5d9c662546a1d44dc847432ca38b55d9f98a..950c68fb63d514b6fb86936aad6608e904ab7dd5 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -39,6 +39,7 @@ extern "C"
 
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#include "cadet_path.h"
 
 /**
  * Struct containing all information regarding a given peer
@@ -52,6 +53,7 @@ struct CadetPeerQueue;
 
 #include "gnunet-service-cadet_connection.h"
 
+
 /**
  * Callback called when a queued message is sent.
  *
@@ -63,13 +65,28 @@ struct CadetPeerQueue;
  * @param fwd Was this a FWD going message?
  * @param size Size of the message.
  * @param wait Time spent waiting for core (only the time for THIS message)
- *
  * @return #GNUNET_YES if connection was destroyed, #GNUNET_NO otherwise.
  */
-typedef int (*GCP_sent) (void *cls,
-                          struct CadetConnection *c, int sent,
-                          uint16_t type, uint32_t pid, int fwd, size_t size,
-                          struct GNUNET_TIME_Relative wait);
+typedef int
+(*GCP_sent) (void *cls,
+             struct CadetConnection *c, int sent,
+             uint16_t type, uint32_t pid, int fwd, size_t size,
+             struct GNUNET_TIME_Relative wait);
+
+/**
+ * Peer path iterator.
+ *
+ * @param cls Closure.
+ * @param peer Peer this path is towards.
+ * @param path Path itself
+ * @return #GNUNET_YES if should keep iterating.
+ *         #GNUNET_NO otherwise.
+ */
+typedef int
+(*GCP_path_iterator) (void *cls,
+                      struct CadetPeer *peer,
+                      struct CadetPeerPath *path);
+
 
 /******************************************************************************/
 /********************************    API    ***********************************/
@@ -91,27 +108,32 @@ GCP_shutdown (void);
 
 
 /**
- * Retrieve the CadetPeer stucture associated with the peer, create one
- * and insert it in the appropriate structures if the peer is not known yet.
+ * Retrieve the CadetPeer stucture associated with the peer. Optionally create
+ * one and insert it in the appropriate structures if the peer is not known yet.
  *
  * @param peer_id Full identity of the peer.
+ * @param create #GNUNET_YES if a new peer should be created if unknown.
+ *               #GNUNET_NO otherwise.
  *
  * @return Existing or newly created peer structure.
+ *         NULL if unknown and not requested @a create
  */
 struct CadetPeer *
-GCP_get (const struct GNUNET_PeerIdentity *peer_id);
-
+GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create);
 
 /**
- * Retrieve the CadetPeer stucture associated with the peer, create one
- * and insert it in the appropriate structures if the peer is not known yet.
+ * Retrieve the CadetPeer stucture associated with the peer. Optionally create
+ * one and insert it in the appropriate structures if the peer is not known yet.
  *
  * @param peer Short identity of the peer.
+ * @param create #GNUNET_YES if a new peer should be created if unknown.
+ *               #GNUNET_NO otherwise.
  *
  * @return Existing or newly created peer structure.
+ *         NULL if unknown and not requested @a create
  */
 struct CadetPeer *
-GCP_get_short (const GNUNET_PEER_Id peer);
+GCP_get_short (const GNUNET_PEER_Id peer, int create);
 
 /**
  * Try to establish a new connection to this peer (in its tunnel).
@@ -148,9 +170,13 @@ GCP_queue_destroy (struct CadetPeerQueue *queue, int clear_cls,
  * @param peer Peer towards which to queue the message.
  * @param cls Closure (@c type dependant). It will be used by queue_send to
  *            build the message to be sent if not already prebuilt.
- * @param type Type of the message, 0 for a raw message.
+ * @param type Type of the message.
+ * @param payload_type Type of the message's payload
+ *                     0 if the message is a retransmission (unknown payload).
+ *                     UINT16_MAX if the message does not have payload.
+ * @param payload_id ID of the payload (MID, ACK #, etc)
  * @param size Size of the message.
- * @param c Connection this message belongs to (cannot be NULL).
+ * @param c Connection this message belongs to (can be NULL).
  * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
  * @param cont Continuation to be called once CORE has taken the message.
  * @param cont_cls Closure for @c cont.
@@ -159,10 +185,16 @@ GCP_queue_destroy (struct CadetPeerQueue *queue, int clear_cls,
  *         message has been sent and therefore the handle is no longer valid.
  */
 struct CadetPeerQueue *
-GCP_queue_add (struct CadetPeer *peer, void *cls, uint16_t type,
-               uint16_t payload_type, uint32_t payload_id,
-               size_t size, struct CadetConnection *c, int fwd,
-               GCP_sent cont, void *cont_cls);
+GCP_queue_add (struct CadetPeer *peer,
+               void *cls,
+               uint16_t type,
+               uint16_t payload_type,
+               uint32_t payload_id,
+               size_t size,
+               struct CadetConnection *c,
+               int fwd,
+               GCP_sent cont,
+               void *cont_cls);
 
 /**
  * Cancel all queued messages to a peer that belong to a certain connection.
@@ -215,6 +247,7 @@ GCP_queue_unlock (struct CadetPeer *peer, struct CadetConnection *c);
 void
 GCP_set_tunnel (struct CadetPeer *peer, struct CadetTunnel *t);
 
+
 /**
  * Check whether there is a direct (core level)  connection to peer.
  *
@@ -225,6 +258,7 @@ GCP_set_tunnel (struct CadetPeer *peer, struct CadetTunnel *t);
 int
 GCP_is_neighbor (const struct CadetPeer *peer);
 
+
 /**
  * Create and initialize a new tunnel towards a peer, in case it has none.
  *
@@ -235,6 +269,7 @@ GCP_is_neighbor (const struct CadetPeer *peer);
 void
 GCP_add_tunnel (struct CadetPeer *peer);
 
+
 /**
  * Add a connection to a neighboring peer.
  *
@@ -244,11 +279,13 @@ GCP_add_tunnel (struct CadetPeer *peer);
  *
  * @param peer Peer to add connection to.
  * @param c Connection to add.
- *
- * @return GNUNET_OK on success.
+ * @param pred #GNUNET_YES if we are predecessor, #GNUNET_NO if we are successor
  */
-int
-GCP_add_connection (struct CadetPeer *peer, struct CadetConnection *c);
+void
+GCP_add_connection (struct CadetPeer *peer,
+                    struct CadetConnection *c,
+                    int pred);
+
 
 /**
  * Add the path to the peer and update the path used to reach it in case this
@@ -263,7 +300,10 @@ GCP_add_connection (struct CadetPeer *peer, struct CadetConnection *c);
  *         NULL on error.
  */
 struct CadetPeerPath *
-GCP_add_path (struct CadetPeer *peer, struct CadetPeerPath *p, int trusted);
+GCP_add_path (struct CadetPeer *peer,
+              struct CadetPeerPath *p,
+              int trusted);
+
 
 /**
  * Add the path to the origin peer and update the path used to reach it in case
@@ -293,6 +333,7 @@ GCP_add_path_to_origin (struct CadetPeer *peer,
 void
 GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed);
 
+
 /**
  * Remove any path to the peer that has the extact same peers as the one given.
  *
@@ -300,18 +341,31 @@ GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed);
  * @param path Path to remove. Is always destroyed .
  */
 void
-GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path);
+GCP_remove_path (struct CadetPeer *peer,
+                 struct CadetPeerPath *path);
+
+
+/**
+ * Check that we are aware of a connection from a neighboring peer.
+ *
+ * @param peer Peer to the connection is with
+ * @param c Connection that should be in the map with this peer.
+ */
+void
+GCP_check_connection (const struct CadetPeer *peer,
+                      const struct CadetConnection *c);
+
 
 /**
  * Remove a connection from a neighboring peer.
  *
  * @param peer Peer to remove connection from.
  * @param c Connection to remove.
- *
- * @return GNUNET_OK on success.
  */
-int
-GCP_remove_connection (struct CadetPeer *peer, const struct CadetConnection *c);
+void
+GCP_remove_connection (struct CadetPeer *peer,
+                       const struct CadetConnection *c);
+
 
 /**
  * Start the DHT search for new paths towards the peer: we don't have
@@ -322,6 +376,7 @@ GCP_remove_connection (struct CadetPeer *peer, const struct CadetConnection *c);
 void
 GCP_start_search (struct CadetPeer *peer);
 
+
 /**
  * Stop the DHT search for new paths towards the peer: we already have
  * enough good connections.
@@ -331,6 +386,7 @@ GCP_start_search (struct CadetPeer *peer);
 void
 GCP_stop_search (struct CadetPeer *peer);
 
+
 /**
  * Get the Full ID of a peer.
  *
@@ -341,6 +397,7 @@ GCP_stop_search (struct CadetPeer *peer);
 const struct GNUNET_PeerIdentity *
 GCP_get_id (const struct CadetPeer *peer);
 
+
 /**
  * Get the Short ID of a peer.
  *
@@ -351,6 +408,7 @@ GCP_get_id (const struct CadetPeer *peer);
 GNUNET_PEER_Id
 GCP_get_short_id (const struct CadetPeer *peer);
 
+
 /**
  * Get the tunnel towards a peer.
  *
@@ -361,6 +419,7 @@ GCP_get_short_id (const struct CadetPeer *peer);
 struct CadetTunnel *
 GCP_get_tunnel (const struct CadetPeer *peer);
 
+
 /**
  * Set the hello message.
  *
@@ -368,7 +427,9 @@ GCP_get_tunnel (const struct CadetPeer *peer);
  * @param hello Hello message.
  */
 void
-GCP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello);
+GCP_set_hello (struct CadetPeer *peer,
+               const struct GNUNET_HELLO_Message *hello);
+
 
 /**
  * Get the hello message.
@@ -399,8 +460,9 @@ GCP_try_connect (struct CadetPeer *peer);
  */
 void
 GCP_notify_broken_link (struct CadetPeer *peer,
-                        struct GNUNET_PeerIdentity *peer1,
-                        struct GNUNET_PeerIdentity *peer2);
+                        const struct GNUNET_PeerIdentity *peer1,
+                        const struct GNUNET_PeerIdentity *peer2);
+
 
 /**
  * Count the number of known paths toward the peer.
@@ -412,6 +474,21 @@ GCP_notify_broken_link (struct CadetPeer *peer,
 unsigned int
 GCP_count_paths (const struct CadetPeer *peer);
 
+/**
+ * Iterate over the paths to a peer.
+ *
+ * @param peer Peer to get path info.
+ * @param callback Function to call for every path.
+ * @param cls Closure for @a callback.
+ *
+ * @return Number of iterated paths.
+ */
+unsigned int
+GCP_iterate_paths (struct CadetPeer *peer,
+                   GCP_path_iterator callback,
+                   void *cls);
+
+
 /**
  * Iterate all known peers.
  *
@@ -421,6 +498,7 @@ GCP_count_paths (const struct CadetPeer *peer);
 void
 GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls);
 
+
 /**
  * Get the static string for a peer ID.
  *
@@ -431,13 +509,15 @@ GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls);
 const char *
 GCP_2s (const struct CadetPeer *peer);
 
+
 /**
  * Log all kinds of info about a peer.
  *
  * @param peer Peer.
  */
 void
-GCP_debug (const struct CadetPeer *p, enum GNUNET_ErrorType level);
+GCP_debug (const struct CadetPeer *p,
+           enum GNUNET_ErrorType level);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */