- wip
[oweals/gnunet.git] / src / include / gnunet_transport_service.h
index 24fa124f05193d9459aeb5d6891b5270c666bda1..817d3a18f6832e404b2d45ab8e8527dcffcefdc6 100644 (file)
@@ -58,10 +58,7 @@ typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
                                                   GNUNET_PeerIdentity * peer,
                                                   const struct
                                                   GNUNET_MessageHeader *
-                                                  message,
-                                                  const struct
-                                                  GNUNET_ATS_Information * ats,
-                                                  uint32_t ats_count);
+                                                  message);
 
 
 /**
@@ -81,10 +78,7 @@ struct GNUNET_TRANSPORT_Handle;
  */
 typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
                                                 const struct GNUNET_PeerIdentity
-                                                * peer,
-                                                const struct
-                                                GNUNET_ATS_Information * ats,
-                                                uint32_t ats_count);
+                                                * peer);
 
 /**
  * Function called to notify transport users that another
@@ -98,6 +92,18 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
                                                    GNUNET_PeerIdentity * peer);
 
 
+/**
+ * Function to call with result of the try connect request.
+ *
+ *
+ * @param cls closure
+ * @param result GNUNET_OK if message was transmitted to transport service
+ *               GNUNET_SYSERR if message was not transmitted to transport service
+ */
+typedef void (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
+                                                     const int result);
+
+
 /**
  * Function to call with a textual representation of an address.
  * This function will be called several times with different possible
@@ -109,7 +115,7 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
  *        otherwise 0-terminated printable UTF-8 string
  */
 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
-                                                        const char *address);
+                                                          const char *address);
 
 
 /**
@@ -120,8 +126,12 @@ typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
  * @param address address, NULL for disconnect notification in monitor mode
  */
 typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
-                                                     const struct GNUNET_PeerIdentity *peer,
-                                                     const struct GNUNET_HELLO_Address *address);
+                                                      const struct
+                                                      GNUNET_PeerIdentity *
+                                                      peer,
+                                                      const struct
+                                                      GNUNET_HELLO_Address *
+                                                      address);
 
 
 /**
@@ -132,9 +142,9 @@ typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
  * @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
- * @param nd function to call on disconnect events
+ * @param rec receive function to call, or NULL
+ * @param nc function to call on connect events, or NULL
+ * @param nd function to call on disconnect events, or NULL
  * @return NULL on error
  */
 struct GNUNET_TRANSPORT_Handle *
@@ -154,16 +164,39 @@ void
 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
 
 
+/**
+ * Opaque handle for a transmission-ready request.
+ */
+struct GNUNET_TRANSPORT_TryConnectHandle;
+
+
 /**
  * Ask the transport service to establish a connection to
  * the given peer.
  *
  * @param handle connection to transport service
  * @param target who we should try to connect to
+ * @param cb callback to be called when request was transmitted to transport
+ *         service
+ * @param cb_cls closure for the callback
+ * @return a GNUNET_TRANSPORT_TryConnectHandle handle or
+ *         NULL on failure (cb will not be called)
  */
-void
+struct GNUNET_TRANSPORT_TryConnectHandle *
 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
-                              const struct GNUNET_PeerIdentity *target);
+                              const struct GNUNET_PeerIdentity *target,
+                              GNUNET_TRANSPORT_TryConnectCallback cb,
+                              void *cb_cls);
+
+
+/**
+ * Cancel the request to transport to try a connect
+ * Callback will not be called
+ *
+ * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel
+ */
+void
+GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
 
 
 /**
@@ -232,7 +265,56 @@ struct GNUNET_TRANSPORT_GetHelloHandle;
 
 
 /**
- * Obtain updates on changes to the HELLO message for this peer.
+  * Checks if a neighbour is connected
+  *
+  * @param handle connection to transport service
+  * @param peer the peer to check
+  * @return GNUNET_YES or GNUNET_NO
+  *
+  */
+int
+GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *handle,
+                                                               const struct GNUNET_PeerIdentity *peer);
+
+
+/**
+ * Set transport metrics for a peer and a direction
+ *
+ * @param handle transport handle
+ * @param peer the peer to set the metric for
+ * @param inbound set inbound direction (GNUNET_YES or GNUNET_NO)
+ * @param outbound set outbound direction (GNUNET_YES or GNUNET_NO)
+ * @param ats the metric as ATS information
+ * @param ats_count the number of metrics
+ *
+ * Supported ATS values:
+ * GNUNET_ATS_QUALITY_NET_DELAY  (value in ms)
+ * GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops))
+ *
+ * Example
+ * To enforce a delay of 10 ms for peer p1 in sending direction use:
+ *
+ * struct GNUNET_ATS_Information ats;
+ * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY);
+ * ats.value = ntohl (10);
+ * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1);
+ *
+ * Note:
+ * Delay restrictions in receiving direction will be enforced with
+ * 1 message delay.
+ */
+void
+GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
+                                    const struct GNUNET_PeerIdentity *peer,
+                                    int inbound,
+                                    int outbound,
+                                    const struct GNUNET_ATS_Information *ats,
+                                    size_t ats_count);
+
+
+/**
+ * Obtain updates on changes to the HELLO message for this peer. The callback
+ * given in this function is never called synchronously.
  *
  * @param handle connection to transport service
  * @param rec function to call with the HELLO
@@ -248,7 +330,7 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
 /**
  * Stop receiving updates about changes to our HELLO message.
  *
- * @param ghh handle returned from 'GNUNET_TRANSPORT_get_hello')
+ * @param ghh handle to cancel
  */
 void
 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
@@ -261,15 +343,29 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
  *
  * @param handle connection to transport service
  * @param hello the hello message
- * @param cont continuation to call when HELLO has been sent
+ * @param cont continuation to call when HELLO has been sent,
+ *      tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail
+ *      tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success
  * @param cls closure for continuation
+ * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
+ *      in case of failure cont will not be called
+ *
  */
-void
+struct GNUNET_TRANSPORT_OfferHelloHandle *
 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
                               const struct GNUNET_MessageHeader *hello,
                               GNUNET_SCHEDULER_Task cont, void *cls);
 
 
+/**
+ * Cancel the request to transport to offer the HELLO message
+ *
+ * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
+ */
+void
+GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
+
+
 /**
  * Handle to cancel a pending address lookup.
  */
@@ -281,22 +377,21 @@ struct GNUNET_TRANSPORT_AddressToStringContext;
  *
  * @param cfg configuration to use
  * @param address address to convert (binary format)
- * @param addressLen number of bytes in address
  * @param numeric should (IP) addresses be displayed in numeric form
  *                (otherwise do reverse DNS lookup)
- * @param nameTrans name of the transport to which the address belongs
  * @param timeout how long is the lookup allowed to take at most
  * @param aluc function to call with the results
  * @param aluc_cls closure for aluc
  * @return handle to cancel the operation, NULL on error
  */
 struct GNUNET_TRANSPORT_AddressToStringContext *
-GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                 const struct GNUNET_HELLO_Address *address,
-                                 int numeric,
-                                 struct GNUNET_TIME_Relative timeout,
-                                 GNUNET_TRANSPORT_AddressToStringCallback aluc,
-                                 void *aluc_cls);
+GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
+                                    *cfg,
+                                    const struct GNUNET_HELLO_Address *address,
+                                    int numeric,
+                                    struct GNUNET_TIME_Relative timeout,
+                                    GNUNET_TRANSPORT_AddressToStringCallback
+                                    aluc, void *aluc_cls);
 
 
 /**
@@ -306,13 +401,13 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
  */
 void
 GNUNET_TRANSPORT_address_to_string_cancel (struct
-                                        GNUNET_TRANSPORT_AddressToStringContext
-                                        *alc);
+                                           GNUNET_TRANSPORT_AddressToStringContext
+                                           *alc);
 
 
 /**
  * Return all the known addresses for a specific peer or all peers.
- * Returns continously all address if one_shot is set to GNUNET_NO
+ * Returns continuously all address if one_shot is set to GNUNET_NO
  *
  * CHANGE: Returns the address(es) that we are currently using for this
  * peer.  Upon completion, the 'AddressLookUpCallback' is called one more
@@ -328,12 +423,14 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct
  * @param peer_address_callback_cls closure for peer_address_callback
  */
 struct GNUNET_TRANSPORT_PeerIterateContext *
-GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                      const struct GNUNET_PeerIdentity *peer,
-                                     int one_shot,
-                                      struct GNUNET_TIME_Relative timeout,
-                                      GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback,
-                                      void *peer_address_callback_cls);
+GNUNET_TRANSPORT_peer_get_active_addresses (const struct
+                                            GNUNET_CONFIGURATION_Handle *cfg,
+                                            const struct GNUNET_PeerIdentity
+                                            *peer, int one_shot,
+                                            struct GNUNET_TIME_Relative timeout,
+                                            GNUNET_TRANSPORT_PeerIterateCallback
+                                            peer_address_callback,
+                                            void *peer_address_callback_cls);
 
 
 /**
@@ -343,8 +440,8 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha
  */
 void
 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
-                                             GNUNET_TRANSPORT_PeerIterateContext
-*alc);
+                                                   GNUNET_TRANSPORT_PeerIterateContext
+                                                   *alc);
 
 
 /**
@@ -358,7 +455,7 @@ struct GNUNET_TRANSPORT_Blacklist;
  *
  * @param cls closure
  * @param pid peer to approve or disapproave
- * @return GNUNET_OK if the connection is allowed
+ * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
  */
 typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
                                                    const struct