Check that you are not present in trail twice
[oweals/gnunet.git] / src / transport / gnunet-service-transport_validation.h
index 374512e475a34a75b485299312a5660027f2e802..df2ef0ee82c66e956c31c40eeab5bf4f2c518201 100644 (file)
 
 /**
  * @file transport/gnunet-service-transport_validation.h
- * @brief plugin management API
+ * @brief address validation API
  * @author Christian Grothoff
  */
 #ifndef GNUNET_SERVICE_TRANSPORT_VALIDATION_H
 #define GNUNET_SERVICE_TRANSPORT_VALIDATION_H
 
 #include "gnunet_statistics_service.h"
-#include "gnunet_transport_validation.h"
+#include "gnunet_transport_plugin.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_hello_lib.h"
+
+/**
+ * Start the validation subsystem.
+ *
+ * @param max_fds maximum number of fds to use
+ */
+void
+GST_validation_start (unsigned int max_fds);
+
+
+/**
+ * Stop the validation subsystem.
+ */
+void
+GST_validation_stop (void);
+
+
+/**
+ * Update if we are using an address for a connection actively right now.
+ * Based on this, the validation module will measure latency for the
+ * address more or less often.
+ *
+ * @param address the address
+ * @param session the session
+ * @param in_use #GNUNET_YES if we are now using the address for a connection,
+ *               #GNUNET_NO if we are no longer using the address for a connection
+ */
+void
+GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
+                                struct Session *session,
+                                int in_use);
 
 
 /**
+ * Query validation about the latest observed latency on a given
+ * address.
  *
+ * @param sender peer
+ * @param address the address
+ * @param session session
+ * @return observed latency of the address, FOREVER if the address was
+ *         never successfully validated
  */
-void 
-GST_validation_start (void);
+struct GNUNET_TIME_Relative
+GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender,
+                                    const struct GNUNET_HELLO_Address *address,
+                                    struct Session *session);
 
 
 /**
+ * Function called to notify transport users that a neighbour peer changed its
+ * active address.
  *
+ * @param cls closure
+ * @param peer peer this update is about (never NULL)
+ * @param address address (never NULL)
+ * @param last_validation point in time when last validation was performed
+ * @param valid_until point in time how long address is valid
+ * @param next_validation point in time when next validation will be performed
+ * @param state state of validation notification
+ */
+typedef void
+(*GST_ValidationChangedCallback) (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  const struct GNUNET_HELLO_Address *address,
+                                  struct GNUNET_TIME_Absolute last_validation,
+                                  struct GNUNET_TIME_Absolute valid_until,
+                                  struct GNUNET_TIME_Absolute next_validation,
+                                  enum GNUNET_TRANSPORT_ValidationState state);
+
+
+/**
+ * Iterate over all iteration entries
+ *
+ * @param cb function to call
+ * @param cb_cls closure for @a cb
  */
 void
-GST_validation_stop (void);
+GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls);
 
 
 /**
+ * We've received a PING.  If appropriate, generate a PONG.
  *
+ * @param sender peer sending the PING
+ * @param hdr the PING
+ * @param sender_address address of the sender, NULL if we did not initiate
+ * @param session session we got the PING from
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
  */
 int
-GST_validation_handle_ping (const GNUNET_PeerIdentity *sender,
-                           const struct GNUNET_MessageHeader *hdr,
-                           const char *plugin_name,
-                           const void *sender_address,
-                           size_t sender_address_len);
+GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
+                            const struct GNUNET_MessageHeader *hdr,
+                            const struct GNUNET_HELLO_Address *sender_address,
+                            struct Session *session);
+
 
 /**
+ * We've received a PONG.  Check if it matches a pending PING and
+ * mark the respective address as confirmed.
  *
+ * @param sender peer sending the PONG
+ * @param hdr the PONG
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
  */
 int
-GST_validation_handle_pong (const GNUNET_PeerIdentity *sender,
-                           const struct GNUNET_MessageHeader *hdr,
-                           const char *plugin_name,
-                           const void *sender_address,
-                           size_t sender_address_len);
+GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
+                            const struct GNUNET_MessageHeader *hdr);
 
 
 /**
+ * We've received a HELLO, check which addresses are new and trigger
+ * validation.
  *
+ * @param hello the HELLO we received
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
  */
-void
+int
 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
 
 
-struct GST_ValidationIteratorContext;
-
 /**
- * @param last_validated_at is FOREVER if the address has not been validated (we're currently checking)
- *                          is ZERO if the address was validated a long time ago (from PEERINFO)
- *                          is a time in the past if this process validated the address
+ * Function called for each address (or address status change) that
+ * the validation module is aware of (for the given target).
+ *
+ * @param cls closure
+ * @param public_key public key for the peer, never NULL
+ * @param valid_until is ZERO if we never validated the address,
+ *                    otherwise a time up to when we consider it (or was) valid
  * @param validation_block  is FOREVER if the address is for an unsupported plugin (from PEERINFO)
  *                          is ZERO if the address is considered valid (no validation needed)
- *                          is a time in the future if we're currently denying re-validation
+ *                          otherwise a time in the future if we're currently denying re-validation
+ * @param address the address
  */
-typedef void (*GST_ValidationAddressCallback)(void *cls,
-                                             const GNUNET_PeerIdentity *target,
-                                             struct GNUNET_TIME_Absolute last_validated_at,
-                                             struct GNUNET_TIME_Absolute validation_block,
-                                             const char *plugin_name,
-                                             const void *plugin_address,
-                                             size_t plugin_address_len);
-
-struct GST_ValidationIteratorContext *
-GST_validation_get_addresses (const GNUNET_PeerIdentity *target,
-                             GST_ValidationAddressCallback cb,
-                             void *cb_cls);
-
+typedef void
+(*GST_ValidationAddressCallback) (void *cls,
+                                  const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
+                                  struct GNUNET_TIME_Absolute valid_until,
+                                  struct GNUNET_TIME_Absolute validation_block,
+                                  const struct GNUNET_HELLO_Address *address);
 
 
+/**
+ * Call the given function for each address for the given target.
+ *
+ * @param target peer information is requested for
+ * @param cb function to call; will not be called after this function returns
+ * @param cb_cls closure for @a cb
+ */
 void
-GST_validation_get_addresses_cancel (struct GST_ValidationIteratorContext *ctx);
-
+GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
+                              GST_ValidationAddressCallback cb, void *cb_cls);
 
 
 #endif