Merge branch 'crypto'
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_peer.h
index e581685fabf9fe3d9bd39c7466c550e4bd550e20..8fefd053d0adaa4cf40f6b624b9815c3e4c7ccfc 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -63,8 +63,10 @@ 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 void (*GCP_sent) (void *cls,
+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);
@@ -125,12 +127,18 @@ GCP_connect (struct CadetPeer *peer);
  * Free a transmission that was already queued with all resources
  * associated to the request.
  *
+ * If connection was marked to be destroyed, and this was the last queued
+ * message on it, the connection will be free'd as a result.
+ *
  * @param queue Queue handler to cancel.
  * @param clear_cls Is it necessary to free associated cls?
  * @param sent Was it really sent? (Could have been canceled)
  * @param pid PID, if relevant (was sent and was a payload message).
+ *
+ * @return #GNUNET_YES if connection was destroyed as a result,
+ *         #GNUNET_NO otherwise.
  */
-void
+int
 GCP_queue_destroy (struct CadetPeerQueue *queue, int clear_cls,
                    int sent, uint32_t pid);
 
@@ -170,19 +178,20 @@ GCP_queue_cancel (struct CadetPeer *peer, struct CadetConnection *c);
  * Get the first message for a connection and unqueue it.
  *
  * Only tunnel (or higher) level messages are unqueued. Connection specific
- * messages are destroyed and the count given to the caller.
+ * messages are silently destroyed upon encounter.
  *
  * @param peer Neighboring peer.
  * @param c Connection.
- * @param del[out] How many messages have been deleted without returning.
- *                 Can be NULL.
+ * @param destroyed[in/out] Was the connection destroyed as a result?.
+ *                          Can NOT be NULL.
+ *
  *
  * @return First message for this connection.
  */
 struct GNUNET_MessageHeader *
 GCP_connection_pop (struct CadetPeer *peer,
                     struct CadetConnection *c,
-                    unsigned int *del);
+                    int *destroyed);
 
 /**
  * Unlock a possibly locked queue for a connection.
@@ -206,6 +215,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.
  *
@@ -216,6 +226,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.
  *
@@ -226,6 +237,7 @@ GCP_is_neighbor (const struct CadetPeer *peer);
 void
 GCP_add_tunnel (struct CadetPeer *peer);
 
+
 /**
  * Add a connection to a neighboring peer.
  *
@@ -235,11 +247,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
@@ -254,7 +268,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
@@ -284,6 +301,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.
  *
@@ -291,18 +309,20 @@ 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);
+
 
 /**
  * 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
@@ -313,6 +333,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.
@@ -322,6 +343,7 @@ GCP_start_search (struct CadetPeer *peer);
 void
 GCP_stop_search (struct CadetPeer *peer);
 
+
 /**
  * Get the Full ID of a peer.
  *
@@ -332,6 +354,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.
  *
@@ -342,6 +365,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.
  *
@@ -352,6 +376,7 @@ GCP_get_short_id (const struct CadetPeer *peer);
 struct CadetTunnel *
 GCP_get_tunnel (const struct CadetPeer *peer);
 
+
 /**
  * Set the hello message.
  *
@@ -359,7 +384,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.
@@ -393,6 +420,7 @@ GCP_notify_broken_link (struct CadetPeer *peer,
                         struct GNUNET_PeerIdentity *peer1,
                         struct GNUNET_PeerIdentity *peer2);
 
+
 /**
  * Count the number of known paths toward the peer.
  *
@@ -403,6 +431,7 @@ GCP_notify_broken_link (struct CadetPeer *peer,
 unsigned int
 GCP_count_paths (const struct CadetPeer *peer);
 
+
 /**
  * Iterate all known peers.
  *
@@ -412,6 +441,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.
  *
@@ -422,13 +452,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 */