for w32 port
[oweals/gnunet.git] / src / include / gnunet_transport_service.h
index 10b7e8f89900e03dd75b488780f93640a82a4f8b..2ee9fb71810cf3054aba1590f35a0d4c2561923f 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
  * @file include/gnunet_transport_service.h
  * @brief low-level P2P IO
  * @author Christian Grothoff
- *
- * TODO:
- * - define API for blacklisting, un-blacklisting and notifications
- *   about blacklisted peers
  */
 
 #ifndef GNUNET_TRANSPORT_SERVICE_H
@@ -39,6 +35,7 @@ extern "C"
 #endif
 #endif
 
+#include "gnunet_bandwidth_lib.h"
 #include "gnunet_configuration_lib.h"
 #include "gnunet_crypto_lib.h"
 #include "gnunet_connection_lib.h"
@@ -68,7 +65,7 @@ typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
                                                   message,
                                                  struct GNUNET_TIME_Relative
                                                   latency,
-                                                 unsigned int distance);
+                                                 uint32_t distance);
 
 
 /**
@@ -91,7 +88,7 @@ typedef void
   (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
                                      const struct GNUNET_PeerIdentity * peer,
                                      struct GNUNET_TIME_Relative latency,
-                                    unsigned int distance);
+                                    uint32_t distance);
 
 /**
  * Function called to notify transport users that another
@@ -123,6 +120,8 @@ typedef void
  *
  * @param sched scheduler to use
  * @param cfg configuration to use
+ * @param self our own identity (API should check that it matches
+ *             the identity found by transport), or NULL (no check)
  * @param cls closure for the callbacks
  * @param rec receive function to call
  * @param nc function to call on connect events
@@ -134,7 +133,9 @@ struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
                                                           *sched,
                                                           const struct
                                                           GNUNET_CONFIGURATION_Handle
-                                                          *cfg, void *cls,
+                                                          *cfg, 
+                                                         const struct GNUNET_PeerIdentity *self,
+                                                         void *cls,
                                                           GNUNET_TRANSPORT_ReceiveCallback
                                                           rec,
                                                           GNUNET_TRANSPORT_NotifyConnect
@@ -157,8 +158,8 @@ void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
  *
  * @param handle connection to transport service
  * @param target who's bandwidth quota is being changed
- * @param quota_in incoming bandwidth quota in bytes per ms
- * @param quota_out outgoing bandwidth quota in bytes per ms
+ * @param quota_in incoming bandwidth quota
+ * @param quota_out outgoing bandwidth quota
  * @param timeout how long to wait until signaling failure if
  *        we can not communicate the quota change
  * @param cont continuation to call when done, will be called
@@ -168,8 +169,8 @@ void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
 void
 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
                             const struct GNUNET_PeerIdentity *target,
-                            uint32_t quota_in,
-                            uint32_t quota_out,
+                            struct GNUNET_BANDWIDTH_Value32NBO quota_in,
+                            struct GNUNET_BANDWIDTH_Value32NBO quota_out,
                             struct GNUNET_TIME_Relative timeout,
                             GNUNET_SCHEDULER_Task cont, void *cont_cls);
 
@@ -182,9 +183,9 @@ struct GNUNET_TRANSPORT_TransmitHandle;
 
 /**
  * Check if we could queue a message of the given size for
- * transmission.  The transport service will take both its
- * internal buffers and bandwidth limits imposed by the
- * other peer into consideration when answering this query.
+ * transmission.  The transport service will take both its internal
+ * buffers and bandwidth limits imposed by the other peer into
+ * consideration when answering this query.
  *
  * @param handle connection to transport service
  * @param target who should receive the message
@@ -204,7 +205,7 @@ struct GNUNET_TRANSPORT_TransmitHandle
                                            *handle,
                                            const struct GNUNET_PeerIdentity
                                            *target, size_t size,
-                                          unsigned int priority,
+                                          uint32_t priority,
                                            struct GNUNET_TIME_Relative
                                            timeout,
                                            GNUNET_CONNECTION_TransmitReadyNotify
@@ -223,6 +224,13 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
 
 
 
+/**
+ * Function called whenever there is an update to the
+ * HELLO of this peer.
+ *
+ * @param cls closure
+ * @param hello our updated HELLO
+ */
 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
                                                     const struct GNUNET_MessageHeader *hello);
 
@@ -294,74 +302,53 @@ GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
 
 
 
-
-/**
- * Blacklist a peer for a given period of time.  All connections
- * (inbound and outbound) to a peer that is blacklisted will be
- * dropped (as soon as we learn who the connection is for).  A second
- * call to this function for the same peer overrides previous
- * blacklisting requests.
- *
- * @param sched scheduler to use
- * @param cfg configuration to use
- * @param peer identity of peer to blacklist
- * @param duration how long to blacklist, use GNUNET_TIME_UNIT_ZERO to
- *        re-enable connections
- */
-void
-GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
-                           const struct GNUNET_CONFIGURATION_Handle *cfg,
-                           const struct GNUNET_PeerIdentity *peer,
-                           struct GNUNET_TIME_Relative duration);
-
-
 /**
- * Handle for blacklist notifications.
+ * Handle for blacklisting peers.
  */
-struct GNUNET_TRANSPORT_BlacklistNotification;
+struct GNUNET_TRANSPORT_Blacklist;
 
 
 /**
- * Signature of function called whenever the blacklist status of
- * a peer changes.  This includes changes to the duration of the
- * blacklist status as well as the expiration of an existing
- * blacklist status.
+ * Function that decides if a connection is acceptable or not.
  *
  * @param cls closure
- * @param peer identity of peer with the change
- * @param until GNUNET_TIME_UNIT_ZERO_ABS if the peer is no
- *              longer blacklisted, otherwise the time at
- *              which the current blacklisting will expire
+ * @param pid peer to approve or disapproave
+ * @return GNUNET_OK if the connection is allowed
  */
-typedef void (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
-                                                  const struct GNUNET_PeerIdentity *peer,
-                                                  struct GNUNET_TIME_Absolute until);
+typedef int (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
+                                                 const struct GNUNET_PeerIdentity *pid);
 
 
 /**
- * Call a function whenever a peer's blacklisting status changes.
+ * Install a blacklist callback.  The service will be queried for all
+ * existing connections as well as any fresh connections to check if
+ * they are permitted.  If the blacklisting callback is unregistered,
+ * all hosts that were denied in the past will automatically be
+ * whitelisted again.  Cancelling the blacklist handle is also the
+ * only way to re-enable connections from peers that were previously
+ * blacklisted.
  *
  * @param sched scheduler to use
  * @param cfg configuration to use
- * @param bc function to call on status changes
- * @param bc_cls closure for bc
+ * @param cb callback to invoke to check if connections are allowed
+ * @param cb_cls closure for cb
  * @return NULL on error, otherwise handle for cancellation
  */
-struct GNUNET_TRANSPORT_BlacklistNotification *
-GNUNET_TRANSPORT_blacklist_notify (struct GNUNET_SCHEDULER_Handle *sched,
-                                  const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                  GNUNET_TRANSPORT_BlacklistCallback bc,
-                                  void *bc_cls);
+struct GNUNET_TRANSPORT_Blacklist *
+GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
+                           const struct GNUNET_CONFIGURATION_Handle *cfg,
+                           GNUNET_TRANSPORT_BlacklistCallback cb,
+                           void *cb_cls);
 
 
 /**
- * Stop calling the notification callback associated with
- * the given blacklist notification.
+ * Abort the blacklist.  Note that this function is the only way for
+ * removing a peer from the blacklist.
  *
- * @param bn handle of the request that is to be cancelled
+ * @param br handle of the request that is to be cancelled
  */
 void
-GNUNET_TRANSPORT_blacklist_notify_cancel (struct GNUNET_TRANSPORT_BlacklistNotification * bn);
+GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);