+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Telling ATS to destroy session %p from peer %s\n",
+ session,
+ GNUNET_i2s (&address->peer));
+ if (GNUNET_YES == ai->expired)
+ {
+ /* last reason to keep this 'ai' around is now gone, the
+ session is dead as well, clean up */
+ if (NULL != ai->ar)
+ {
+ /* Address expired but not blocked, and thus 'ar' was still
+ live because of the session; deleting just the session
+ will do for an inbound session, but for an outbound we
+ then also need to destroy the address with ATS. */
+ if (GNUNET_NO ==
+ GNUNET_ATS_address_del_session (ai->ar,
+ session))
+ {
+ GNUNET_ATS_address_destroy (ai->ar);
+ }
+ /* "ar" has been freed, regardless how the branch
+ above played out: it was either freed in
+ #GNUNET_ATS_address_del_session() because it was
+ incoming, or explicitly in
+ #GNUNET_ATS_address_del_session(). */
+ ai->ar = NULL;
+ }
+ destroy_ai (ai);
+ return;
+ }
+
+ if (NULL == ai->ar)
+ {
+ /* If ATS doesn't know about the address/session, this means
+ this address was blocked. */
+ if (GNUNET_YES ==
+ GNUNET_HELLO_address_check_option (address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND))
+ {
+ /* This was a blocked inbound session, which now lost the
+ session. But inbound addresses are by themselves useless,
+ so we must forget about the address as well. */
+ destroy_ai (ai);
+ return;
+ }
+ /* Otherwise, we are done as we have set `ai->session` to NULL
+ already and ATS will simply not be told about the session when
+ the connection is unblocked and the outbound address becomes
+ available again. . */
+ return;
+ }
+
+ /* This is the "simple" case where ATS knows about the session and
+ the address is neither blocked nor expired. Delete the session,
+ and if it was inbound, free the address as well. */