You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file transport/gnunet-service-transport_ats.h
*/
struct GNUNET_SCHEDULER_Task *unblock_task;
+ /**
+ * Set to #GNUNET_YES if the address has expired but we could
+ * not yet remove it because we still have a valid session.
+ */
+ int expired;
+
};
*/
static struct GNUNET_CONTAINER_MultiPeerMap *p2a;
+/**
+ * Number of blocked addresses.
+ */
+static unsigned int num_blocked;
/**
* Closure for #find_ai().
{
GNUNET_STATISTICS_set (GST_stats,
gettext_noop ("# Addresses given to ATS"),
- GNUNET_CONTAINER_multipeermap_size (p2a),
+ GNUNET_CONTAINER_multipeermap_size (p2a) - num_blocked,
GNUNET_NO);
+ GNUNET_STATISTICS_set (GST_stats,
+ "# blocked addresses",
+ num_blocked,
+ GNUNET_NO);
}
/**
- * Test if ATS knows about this address.
+ * Test if ATS knows about this @a address and @a session.
*
* @param address the address
* @param session the session
- * @return #GNUNET_YES if address is known, #GNUNET_NO if not.
+ * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
*/
int
GST_ats_is_known (const struct GNUNET_HELLO_Address *address,
}
+/**
+ * Test if ATS knows about this @a address.
+ *
+ * @param address the address
+ * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
+ */
+int
+GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address)
+{
+ return (NULL != find_ai_no_session (address)) ? GNUNET_YES : GNUNET_NO;
+}
+
+
/**
* The blocking time for an address has expired, allow ATS to
* suggest it again.
ai->session,
&ai->properties);
GNUNET_break (NULL != ai->ar);
+ num_blocked--;
+ publish_p2a_stat_update ();
}
ai = find_ai (address, session);
if (NULL == ai)
{
- GNUNET_break (0);
+ GNUNET_assert (0);
return;
}
if (NULL == ai->ar)
GNUNET_break (0);
return;
}
+ ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off);
if (GNUNET_YES ==
GNUNET_HELLO_address_check_option (address,
GNUNET_HELLO_ADDRESS_INFO_INBOUND))
GST_plugins_a2s (address),
GNUNET_i2s (&address->peer));
else
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Blocking address %s of peer %s from use for a while\n",
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Blocking address %s of peer %s from use for %s\n",
GST_plugins_a2s (address),
- GNUNET_i2s (&address->peer));
+ GNUNET_i2s (&address->peer),
+ GNUNET_STRINGS_relative_time_to_string (ai->back_off,
+ GNUNET_YES));
/* destroy session and address */
if ( (NULL == session) ||
(GNUNET_NO ==
- GNUNET_ATS_address_del_session (ai->ar, session)) )
+ GNUNET_ATS_address_del_session (ai->ar,
+ session)) )
GNUNET_ATS_address_destroy (ai->ar);
ai->ar = NULL;
/* determine when the address should come back to life */
- ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off);
ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off);
ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off,
&unblock_address,
ai);
+ num_blocked++;
+ publish_p2a_stat_update ();
+}
+
+
+/**
+ * Reset address blocking time. Resets the exponential
+ * back-off timer for this address to zero. Done when
+ * an address was used to create a successful connection.
+ *
+ * @param address the address to reset the blocking timer
+ * @param session the session (can be NULL)
+ */
+void
+GST_ats_block_reset (const struct GNUNET_HELLO_Address *address,
+ struct Session *session)
+{
+ struct AddressInfo *ai;
+
+ ai = find_ai (address, session);
+ if (NULL == ai)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ /* address is in successful use, so it should not be blocked right now */
+ GNUNET_break (NULL == ai->unblock_task);
+ ai->back_off = GNUNET_TIME_UNIT_ZERO;
}
GNUNET_HELLO_ADDRESS_INFO_INBOUND));
ai = find_ai_no_session (address);
GNUNET_assert (NULL == ai);
+ GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
LOG (GNUNET_ERROR_TYPE_INFO,
"Notifying ATS about peer `%s''s new address `%s'\n",
GNUNET_i2s (&address->peer),
GNUNET_break (0);
return;
}
- ai = find_ai (address, session);
+ ai = find_ai (address,
+ session);
if (NULL == ai)
{
/* We sometimes create sessions just for sending a PING,
GNUNET_i2s (&address->peer));
if (NULL == ai->ar)
{
- /* If ATS doesn't know about the address/session, and this
- was an inbound session that expired, then we must forget
- about the address as well. Otherwise, we are done as
- we have set `ai->session` to NULL already. */
- if (GNUNET_YES ==
- GNUNET_HELLO_address_check_option (address,
- GNUNET_HELLO_ADDRESS_INFO_INBOUND))
+ /* If ATS doesn't know about the address/session, and this was an
+ inbound session or one that expired, then we must forget about
+ the address as well. Otherwise, we are done as we have set
+ `ai->session` to NULL already. */
+ if ( (GNUNET_YES == ai->expired) ||
+ (GNUNET_YES ==
+ GNUNET_HELLO_address_check_option (address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND)) )
GST_ats_expire_address (address);
return;
}
if (GNUNET_YES ==
- GNUNET_ATS_address_del_session (ai->ar, session))
+ GNUNET_ATS_address_del_session (ai->ar,
+ session))
{
ai->ar = NULL;
GST_ats_expire_address (address);
GNUNET_assert (0);
return;
}
+ if (NULL != ai->unblock_task)
+ {
+ GNUNET_SCHEDULER_cancel (ai->unblock_task);
+ ai->unblock_task = NULL;
+ num_blocked--;
+ }
+ if (NULL != ai->session)
+ {
+ ai->expired = GNUNET_YES;
+ if (NULL != ai->ar)
+ {
+ GNUNET_ATS_address_destroy (ai->ar);
+ ai->ar = NULL;
+ }
+ return;
+ }
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_remove (p2a,
&address->peer,
ai));
- publish_p2a_stat_update ();
- GNUNET_break (NULL == ai->session);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Telling ATS to destroy address from peer %s\n",
GNUNET_i2s (&address->peer));
GNUNET_ATS_address_destroy (ai->ar);
ai->ar = NULL;
}
- if (NULL != ai->unblock_task)
- {
- GNUNET_SCHEDULER_cancel (ai->unblock_task);
- ai->unblock_task = NULL;
- }
+ publish_p2a_stat_update ();
GNUNET_HELLO_address_free (ai->address);
GNUNET_free (ai);
}
{
GNUNET_SCHEDULER_cancel (ai->unblock_task);
ai->unblock_task = NULL;
+ num_blocked--;
}
if (NULL != ai->ar)
{