stuff
authorChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 14:59:21 +0000 (14:59 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 14:59:21 +0000 (14:59 +0000)
src/transport/gnunet-service-transport-new.c
src/transport/gnunet-service-transport_blacklist.c
src/transport/gnunet-service-transport_blacklist.h
src/transport/gnunet-service-transport_neighbours.c
src/transport/gnunet-service-transport_neighbours.h
src/transport/gnunet-service-transport_validation.c

index e8369b661c1c839a59a36dbdd1ea39c58371bb1a..4536d2573ae1c11ab793483f712d7988930f3199 100644 (file)
@@ -150,9 +150,18 @@ plugin_env_receive_callback (void *cls,
                             uint16_t sender_address_len)
 {
   const char *plugin_name = cls;
-
-  
-  if (NULL != message)
+  int do_forward;
+  struct GNUNET_TIME_Relative ret;
+
+  do_forward = GNUNET_SYSERR;
+  ret = GST_neighbours_calculate_receive_delay (peer,
+                                               (message == NULL) 
+                                               ? 0 
+                                               : ntohs (message->size),
+                                               &do_forward);
+  /* FIXME: look at the type of the message (PING, PONG, CONNECT, payload...) */
+  if ( (NULL != message) &&
+       (do_forward == GNUNET_YES) )
     GST_clients_broadcast (message, GNUNET_YES);
   GNUNET_ATS_address_update (GST_ats,
                             peer,
@@ -162,10 +171,7 @@ plugin_env_receive_callback (void *cls,
                             sender_address,
                             sender_address_len,
                             ats, ats_count);
-  return GST_neighbours_calculate_receive_delay (peer,
-                                                (message == NULL) 
-                                                ? 0 
-                                                : ntohs (message->size));
+  return ret;
 }
 
 
index 83d8e44ec3fdb919edb052ef00bcf47a604feeca..4738cdc0f8452688c93f9a730108bb4f1fe0fba5 100644 (file)
@@ -768,7 +768,8 @@ test_blacklisted (void *cls,
  * @param transport_name name of the transport to test, never NULL
  * @param cont function to call with result
  * @param cont_cls closure for 'cont'
- * @return handle to the blacklist check
+ * @return handle to the blacklist check, NULL if the decision
+ *        was made instantly and 'cont' was already called
  */
 struct GST_BlacklistCheck *
 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
index 6721b6aa2e067eb6f8bca60bd40dbbad92af7497..26309818d0a8992eeb412accfae76ce362a87edf 100644 (file)
@@ -108,7 +108,8 @@ typedef void (*GST_BlacklistTestContinuation)(void *cls,
  * @param transport_name name of the transport to test, never NULL
  * @param cont function to call with result
  * @param cont_cls closure for 'cont'
- * @return handle to the blacklist check
+ * @return handle to the blacklist check, NULL if the decision
+ *        was made instantly and 'cont' was already called
  */
 struct GST_BlacklistCheck *
 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
index 9ae9712a94c3a16fcd5ce12dbf5b2018a990cacc..c310afc225f8ce0eecdc81c9b5cf458c89fb45a7 100644 (file)
@@ -756,18 +756,24 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
  *
  * @param sender sender of the message
  * @param size size of the message
+ * @param do_forward set to GNUNET_YES if the message should be forwarded to clients
+ *                   GNUNET_NO if the neighbour is not connected or violates the quota
  * @return how long to wait before reading more from this sender
  */
 struct GNUNET_TIME_Relative
 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender,
-                                       ssize_t size)
+                                       ssize_t size,
+                                       int *do_forward)
 {
   struct NeighbourMapEntry *n;
   struct GNUNET_TIME_Relative ret;
 
   n = lookup_neighbour (sender);
   if (n == NULL)
-    return GNUNET_TIME_UNIT_ZERO;
+    {
+      *do_forward = GNUNET_NO;
+      return GNUNET_TIME_UNIT_ZERO;
+    }
   if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
                                                      size))
     {
@@ -802,8 +808,10 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
                                gettext_noop ("# bandwidth quota violations by other peers"),
                                1,
                                GNUNET_NO);
+      *do_forward = GNUNET_NO;
       return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
     }
+  *do_forward = GNUNET_YES;
   ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
   if (ret.rel_value > 0)
     {
index d9b2fd6b4cf8fa10e29474c9ae3843e05c2f478f..14f2238117ad00a1e4941b716d4eb3f0d0fc2876 100644 (file)
@@ -111,11 +111,14 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
  *
  * @param sender sender of the message
  * @param size size of the message
+ * @param do_forward set to GNUNET_YES if the message should be forwarded to clients
+ *                   GNUNET_NO if the neighbour is not connected or violates the quota
  * @return how long to wait before reading more from this sender
  */
 struct GNUNET_TIME_Relative
 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender,
-                                       ssize_t size);
+                                       ssize_t size,
+                                       int *do_forward);
 
 
 /**
index 4f5a7fdc2e644bcbdbba4f4ec70e6a6e676172ba..aabb280688f734504da480a08d0d1d783cd501cc 100644 (file)
@@ -886,6 +886,7 @@ validate_address (void *cls,
   const struct ValidateAddressContext *vac = cls;
   const struct GNUNET_PeerIdentity *pid = &vac->pid;
   struct ValidationEntry *ve;
+  struct GST_BlacklistCheck *bc;
 
   if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
     return GNUNET_OK; /* expired */
@@ -901,10 +902,12 @@ validate_address (void *cls,
   ve->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_REVALIDATION_START_TIME,
                                                   &timeout_hello_validation,
                                                   ve);
-  ve->bc = GST_blacklist_test_allowed (pid,
-                                      tname,
-                                      &transmit_ping_if_allowed,
-                                      ve);
+  bc = GST_blacklist_test_allowed (pid,
+                                  tname,
+                                  &transmit_ping_if_allowed,
+                                  ve);
+  if (NULL != bc)
+    ve->bc = bc;
   return GNUNET_OK;
 }