error msg
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.c
index 047f13144756788e7169622527f718c16f983683..8c8397ee22090e6fdc936b51f248a84b678869ac 100644 (file)
@@ -318,7 +318,7 @@ struct SessionDisconnectMessage
    * Purpose of the signature.  Extends over the timestamp.
    * Purpose should be GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT.
    */
-  struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
+  struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
 
   /**
    * Absolute time at the sender.  Only the most recent connect
@@ -329,14 +329,14 @@ struct SessionDisconnectMessage
   /**
    * Public key of the sender.
    */
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
+  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
 
   /**
    * Signature of the peer that sends us the disconnect.  Only
    * valid if the timestamp is AFTER the timestamp from the
    * corresponding 'CONNECT' message.
    */
-  struct GNUNET_CRYPTO_RsaSignature signature;
+  struct GNUNET_CRYPTO_EccSignature signature;
 
 };
 
@@ -656,6 +656,11 @@ struct NeighbourMapEntry
    */
   struct GNUNET_TIME_Absolute connect_ack_timestamp;
 
+  /**
+   * ATS address suggest handle
+   */
+  struct GNUNET_ATS_SuggestHandle *suggest_handle;
+
   /**
    * Time where we should cut the connection (timeout) if we don't
    * make progress in the state machine (or get a KEEPALIVE_RESPONSE
@@ -1090,7 +1095,11 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions)
   // which states we do this from in the future (ATS should
   // have given us a 'suggest_address' handle, and if we have
   // such a handle, we should cancel the operation here!
-  GNUNET_ATS_suggest_address_cancel (GST_ats, &n->id);
+  if (NULL != n->suggest_handle)
+  {
+       GNUNET_ATS_suggest_address_cancel (GST_ats, &n->id);
+       n->suggest_handle = NULL;
+  }
 
   if (GNUNET_SCHEDULER_NO_TASK != n->task)
   {
@@ -1196,8 +1205,8 @@ send_disconnect (struct NeighbourMapEntry *n)
       htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
   disconnect_msg.reserved = htonl (0);
   disconnect_msg.purpose.size =
-      htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
-             sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
+      htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
+             sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
              sizeof (struct GNUNET_TIME_AbsoluteNBO));
   disconnect_msg.purpose.purpose =
       htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
@@ -1205,7 +1214,7 @@ send_disconnect (struct NeighbourMapEntry *n)
       GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
   disconnect_msg.public_key = GST_my_public_key;
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
+                 GNUNET_CRYPTO_ecc_sign (GST_my_private_key,
                                          &disconnect_msg.purpose,
                                          &disconnect_msg.signature));
 
@@ -1910,7 +1919,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
   n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
 
   GNUNET_ATS_reset_backoff (GST_ats, target);
-  GNUNET_ATS_suggest_address (GST_ats, target);
+  n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, target);
 }
 
 
@@ -1975,7 +1984,7 @@ handle_test_blacklist_cont (void *cls,
       n->state = S_INIT_ATS;
       n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
       // FIXME: do we need to ask ATS again for suggestions?
-      GNUNET_ATS_suggest_address (GST_ats, &n->id);
+      n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, &n->id);
     }
     break;
   case S_CONNECT_SENT:
@@ -2001,7 +2010,7 @@ handle_test_blacklist_cont (void *cls,
     n->state = S_CONNECT_RECV_ATS;
     n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
     GNUNET_ATS_reset_backoff (GST_ats, peer);
-    GNUNET_ATS_suggest_address (GST_ats, peer);
+    n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer);
     break;
   case S_CONNECT_RECV_ATS:
     /* still waiting on ATS suggestion, don't care about blacklist */
@@ -2030,7 +2039,7 @@ handle_test_blacklist_cont (void *cls,
       n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
       // FIXME: do we need to ask ATS again for suggestions?
       GNUNET_ATS_reset_backoff (GST_ats, peer);
-      GNUNET_ATS_suggest_address (GST_ats, &n->id);
+      n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, &n->id);
     }
     break;
   case S_CONNECT_RECV_ACK:
@@ -2075,7 +2084,7 @@ handle_test_blacklist_cont (void *cls,
       n->state = S_RECONNECT_ATS;
       n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
       // FIXME: do we need to ask ATS again for suggestions?
-      GNUNET_ATS_suggest_address (GST_ats, &n->id);
+      n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, &n->id);
     }
     break;
   case S_RECONNECT_SENT:
@@ -2286,7 +2295,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
     n = setup_neighbour (peer);
     n->state = S_CONNECT_RECV_ATS;
     GNUNET_ATS_reset_backoff (GST_ats, peer);
-    GNUNET_ATS_suggest_address (GST_ats, peer);
+    n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer);
     break;
   case S_DISCONNECT_FINISHED:
     /* should not be possible */
@@ -2336,6 +2345,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
   if (NULL == (papi = GST_plugins_find (address->transport_name)))
   {
     /* we don't have the plugin for this address */
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                     "2348 : `%s' \n", address->transport_name);
     GNUNET_ATS_address_destroyed (GST_ats, address, NULL);
     return;
   }
@@ -2963,7 +2974,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
     n->state = S_INIT_ATS;
     n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
     // FIXME: need to ask ATS for suggestions again?
-    GNUNET_ATS_suggest_address (GST_ats, &n->id);
+    n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, &n->id);
     break;
   case S_CONNECT_RECV_BLACKLIST_INBOUND:
   case S_CONNECT_RECV_ATS:    
@@ -2978,7 +2989,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
     n->state = S_RECONNECT_ATS;
     n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
     /* FIXME: is this ATS call needed? */
-    GNUNET_ATS_suggest_address (GST_ats, &n->id);
+    n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, &n->id);
     break;
   case S_RECONNECT_ATS:
     /* we don't have an address, how can it go down? */
@@ -2989,7 +3000,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
     n->state = S_RECONNECT_ATS;
     n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
     // FIXME: need to ask ATS for suggestions again?
-    GNUNET_ATS_suggest_address (GST_ats, &n->id);
+    n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, &n->id);
     break;
   case S_CONNECTED_SWITCHING_BLACKLIST:
     /* primary went down while we were checking secondary against
@@ -3184,7 +3195,7 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
     return;
   }
   GNUNET_CRYPTO_hash (&sdm->public_key,
-                      sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                      sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                       &hc);
   if (0 != memcmp (peer, &hc, sizeof (struct GNUNET_PeerIdentity)))
   {
@@ -3192,15 +3203,15 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
     return;
   }
   if (ntohl (sdm->purpose.size) !=
-      sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
-      sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
+      sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
+      sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
       sizeof (struct GNUNET_TIME_AbsoluteNBO))
   {
     GNUNET_break_op (0);
     return;
   }
   if (GNUNET_OK !=
-      GNUNET_CRYPTO_rsa_verify
+      GNUNET_CRYPTO_ecc_verify
       (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, &sdm->purpose,
        &sdm->signature, &sdm->public_key))
   {
@@ -3381,12 +3392,14 @@ GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
  * @param disconnect_cb function to call if we disconnect from a peer
  * @param peer_address_cb function to call if we change an active address
  *                   of a neighbour
+ * @param max_fds maximum number of fds to use
  */
 void
 GST_neighbours_start (void *cls,
-    NotifyConnect connect_cb,
+                                                                       NotifyConnect connect_cb,
                       GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb,
-                      GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb)
+                      GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb,
+                      unsigned int max_fds)
 {
   callback_cls = cls;
   connect_notify_cb = connect_cb;