GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
-/**
- * Opaque handle for a transmission-ready request.
- */
-struct GNUNET_TRANSPORT_TryDisconnectHandle;
-
-/**
- * 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_TryDisconnectCallback) (void *cls,
- int result);
-
-
-/**
- * Ask the transport service to disconnect from the given peer.
- *
- * @param handle connection to transport service
- * @param target who we should try to disconnect from
- * @param cb callback to be called when request was transmitted to transport
- * service
- * @param cb_cls closure for the callback @a cb
- * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
- * NULL on failure (@a cb will not be called)
- * @deprecated use blacklisting API instead!
- */
-struct GNUNET_TRANSPORT_TryDisconnectHandle *
-GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_PeerIdentity *target,
- GNUNET_TRANSPORT_TryDisconnectCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel the request to transport to disconnect.
- * Callback will not be called anymore.
- *
- * @param tdh handle for operation to cancel
- */
-void
-GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh);
-
-
/* ************************* Sending *************************** */
/**
}
-/**
- * Handle request disconnect message
- *
- * @param cls closure (always NULL)
- * @param client identification of the client
- * @param message the actual message
- */
-static void
-clients_handle_request_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct TransportRequestDisconnectMessage *trdm;
-
- trdm = (const struct TransportRequestDisconnectMessage *) message;
- GNUNET_break (0 == ntohl (trdm->reserved));
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop
- ("# REQUEST DISCONNECT messages received"), 1,
- GNUNET_NO);
- if (0 == memcmp (&trdm->peer,
- &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received a request disconnect message for peer `%s'\n",
- GNUNET_i2s (&trdm->peer));
- (void) GST_neighbours_force_disconnect (&trdm->peer);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
/**
* Take the given address and append it to the set of results sent back to
* the client. This function may be called serveral times for a single
{&clients_handle_request_connect, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
sizeof (struct TransportRequestConnectMessage)},
- {&clients_handle_request_disconnect, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT,
- sizeof (struct TransportRequestDisconnectMessage)},
{&clients_handle_address_to_string, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
{&clients_handle_monitor_peers, NULL,
};
-/**
- * Entry in linked list for all try-disconnect requests
- */
-struct GNUNET_TRANSPORT_TryDisconnectHandle
-{
- /**
- * For the DLL.
- */
- struct GNUNET_TRANSPORT_TryDisconnectHandle *prev;
-
- /**
- * For the DLL.
- */
- struct GNUNET_TRANSPORT_TryDisconnectHandle *next;
-
- /**
- * Peer we should try to connect to.
- */
- struct GNUNET_PeerIdentity pid;
-
- /**
- * Transport service handle this request is part of.
- */
- struct GNUNET_TRANSPORT_Handle *th;
-
- /**
- * Message transmission request to communicate to service.
- */
- struct GNUNET_TRANSPORT_TransmitHandle *tth;
-
- /**
- * Function to call upon completion (of request transmission).
- */
- GNUNET_TRANSPORT_TryDisconnectCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
-};
-
-
/**
* Entry in linked list for all offer-HELLO requests.
*/
*/
struct GNUNET_TRANSPORT_TryConnectHandle *tc_tail;
- /**
- * Linked list of pending try disconnect requests head
- */
- struct GNUNET_TRANSPORT_TryDisconnectHandle *td_head;
-
- /**
- * Linked list of pending try connect requests tail
- */
- struct GNUNET_TRANSPORT_TryDisconnectHandle *td_tail;
-
/**
* Linked list of pending offer HELLO requests head
*/
}
-/**
- * Send #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT message to the
- * service.
- *
- * @param cls the `struct GNUNET_TRANSPORT_TryDisconnectHandle`
- * @param size number of bytes available in @a buf
- * @param buf where to copy the message
- * @return number of bytes copied to @a buf
- */
-static size_t
-send_try_disconnect (void *cls,
- size_t size,
- void *buf)
-{
- struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh = cls;
- struct TransportRequestConnectMessage msg;
-
- tdh->th = NULL;
- if (NULL == buf)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Discarding `%s' request to `%s' due to error in transport service connection.\n",
- "REQUEST_DISCONNECT",
- GNUNET_i2s (&tdh->pid));
- if (NULL != tdh->cb)
- tdh->cb (tdh->cb_cls,
- GNUNET_SYSERR);
- GNUNET_TRANSPORT_try_disconnect_cancel (tdh);
- return 0;
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' request with respect to `%s'.\n",
- "REQUEST_DISCONNECT",
- GNUNET_i2s (&tdh->pid));
- GNUNET_assert (size >= sizeof (struct TransportRequestDisconnectMessage));
- msg.header.size = htons (sizeof (struct TransportRequestDisconnectMessage));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT);
- msg.reserved = htonl (0);
- msg.peer = tdh->pid;
- memcpy (buf, &msg, sizeof (msg));
- if (NULL != tdh->cb)
- tdh->cb (tdh->cb_cls, GNUNET_OK);
- GNUNET_TRANSPORT_try_disconnect_cancel (tdh);
- return sizeof (struct TransportRequestDisconnectMessage);
-}
-
-
-/**
- * Ask the transport service to shutdown 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 @a cb
- * @return a `struct GNUNET_TRANSPORT_TryDisconnectHandle` handle or
- * NULL on failure (cb will not be called)
- */
-struct GNUNET_TRANSPORT_TryDisconnectHandle *
-GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_PeerIdentity *target,
- GNUNET_TRANSPORT_TryDisconnectCallback cb,
- void *cb_cls)
-{
- struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh;
-
- if (NULL == handle->client)
- return NULL;
- tdh = GNUNET_new (struct GNUNET_TRANSPORT_TryDisconnectHandle);
- tdh->th = handle;
- tdh->pid = *target;
- tdh->cb = cb;
- tdh->cb_cls = cb_cls;
- tdh->tth = schedule_control_transmit (handle,
- sizeof (struct TransportRequestDisconnectMessage),
- &send_try_disconnect, tdh);
- GNUNET_CONTAINER_DLL_insert (handle->td_head,
- handle->td_tail,
- tdh);
- return tdh;
-}
-
-
-/**
- * Cancel the request to transport to try a disconnect
- * Callback will not be called
- *
- * @param tdh the handle to cancel
- */
-void
-GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryDisconnectHandle *tdh)
-{
- struct GNUNET_TRANSPORT_Handle *th;
-
- th = tdh->th;
- if (NULL != tdh->tth)
- cancel_control_transmit (th, tdh->tth);
- GNUNET_CONTAINER_DLL_remove (th->td_head,
- th->td_tail,
- tdh);
- GNUNET_free (tdh);
-}
-
-
/**
* Send HELLO message to the service.
*