/**
- * Handle for a request to the core to connect or disconnect
- * from a particular peer. Can be used to cancel the request
+ * Handle for a request to the core to connect to
+ * a particular peer. Can be used to cancel the request
* (before the 'cont'inuation is called).
*/
struct GNUNET_CORE_PeerRequestHandle
void *cont_cls;
/**
- * Identity of the peer to connect/disconnect.
+ * Identity of the peer to connect to.
*/
struct GNUNET_PeerIdentity peer;
/**
- * Request that the core should try to disconnect from a particular
- * peer. Once the request has been transmitted to the core, the
- * continuation function will be called. Note that this does NOT mean
- * that a connection was successfully cut -- it only means that the
- * core will now try. Typically this will work pretty much
- * immediately, but it is at least in theory also possible that a
- * reconnect is also triggered rather quickly. Successful creation
- * and destruction of connections will be signalled to the 'connects'
- * and 'disconnects' callback arguments of 'GNUNET_CORE_connect' only.
- * If the core service does not respond to our connection attempt
- * within the given time frame, 'cont' will be called with the TIMEOUT
- * reason code.
- *
- * @param sched scheduler to use
- * @param cfg configuration to use
- * @param timeout how long to try to talk to core
- * @param cont function to call once the request has been completed (or timed out)
- * @param cont_cls closure for cont
- * @return NULL on error (cont will not be called), otherwise handle for cancellation
- */
-struct GNUNET_CORE_PeerRequestHandle *
-GNUNET_CORE_peer_request_disconnect (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TIME_Relative timeout,
- const struct GNUNET_PeerIdentity * peer,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls)
-{
- struct GNUNET_CORE_PeerRequestHandle *ret;
- struct GNUNET_CLIENT_Connection *client;
-
- client = GNUNET_CLIENT_connect (sched, "core", cfg);
- if (client == NULL)
- return NULL;
- ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle));
- ret->client = client;
- ret->sched = sched;
- ret->cont = cont;
- ret->cont_cls = cont_cls;
- ret->peer = *peer;
- ret->type = GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT;
- GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct ConnectMessage),
- timeout,
- GNUNET_YES,
- &send_request,
- ret);
- return ret;
-}
-
-
-/**
- * Cancel a pending request to connect or disconnect from/to a particular
- * peer. Must not be called after the 'cont' function was invoked.
+ * Cancel a pending request to connect to a particular peer. Must not
+ * be called after the 'cont' function was invoked.
*
* @param req request handle that was returned for the original request
*/
void
-GNUNET_CORE_peer_request_cancel (struct GNUNET_CORE_PeerRequestHandle *req)
+GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req)
{
GNUNET_CLIENT_disconnect (req->client);
GNUNET_free (req);
}
-/**
- * Handle CORE_REQUEST_DISCONNECT request.
- *
- * @param cls unused
- * @param client the client issuing the request
- * @param message the "struct ConnectMessage"
- */
-static void
-handle_client_request_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-{
- const struct ConnectMessage *cm = (const struct ConnectMessage*) message;
- struct Neighbour *n;
-
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- n = find_neighbour (&cm->peer);
- if (n == NULL)
- return; /* done */
- /* FIXME: implement disconnect! */
-}
-
-
-
/**
* List of handlers for the messages understood by this
* service.
{&handle_client_request_connect, NULL,
GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT,
sizeof (struct ConnectMessage)},
- {&handle_client_request_disconnect, NULL,
- GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT,
- sizeof (struct ConnectMessage)},
{NULL, NULL, 0, 0}
};
/**
- * Request that the core should try to disconnect from a particular
- * peer. Once the request has been transmitted to the core, the
- * continuation function will be called. Note that this does NOT mean
- * that a connection was successfully cut -- it only means that the
- * core will now try. Typically this will work pretty much
- * immediately, but it is at least in theory also possible that a
- * reconnect is also triggered rather quickly. Successful creation
- * and destruction of connections will be signalled to the 'connects'
- * and 'disconnects' callback arguments of 'GNUNET_CORE_connect' only.
- * If the core service does not respond to our connection attempt
- * within the given time frame, 'cont' will be called with the TIMEOUT
- * reason code.
- *
- * @param sched scheduler to use
- * @param cfg configuration to use
- * @param timeout how long to try to talk to core
- * @param cont function to call once the request has been completed (or timed out)
- * @param cont_cls closure for cont
- * @return NULL on error (cont will not be called), otherwise handle for cancellation
- */
-struct GNUNET_CORE_PeerRequestHandle *
-GNUNET_CORE_peer_request_disconnect (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TIME_Relative timeout,
- const struct GNUNET_PeerIdentity * peer,
- GNUNET_SCHEDULER_Task cont,
- void *cont_cls);
-
-
-/**
- * Cancel a pending request to connect or disconnect from/to a particular
- * peer. Must not be called after the 'cont' function was invoked.
+ * Cancel a pending request to connect to a particular peer. Must not
+ * be called after the 'cont' function was invoked.
*
* @param req request handle that was returned for the original request
*/
void
-GNUNET_CORE_peer_request_cancel (struct GNUNET_CORE_PeerRequestHandle *req);
+GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req);
/**
*/
#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT 74
-/**
- * Request from client asking to disconnect from a peer.
- */
-#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT 75
-
/**
* Session key exchange between peers.
+/**
+ * Function called whenever there is an update to the
+ * HELLO of this peer.
+ *
+ * @param cls closure
+ * @param hello our updated HELLO
+ */
typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
const struct GNUNET_MessageHeader *hello);
* Our handle for the request to connect to this peer; NULL if no
* such request is pending.
*/
- struct GNUNET_CORE_TransmitHandle *connect_req;
+ struct GNUNET_CORE_PeerRequestHandle *connect_req;
/**
* Pointer to the HELLO message of this peer; can be NULL.
/**
* Our request handle.
*/
- struct GNUNET_CORE_PeerRequestHandle *rh;
-
+ struct GNUNET_TRANSPORT_BlacklistRequest *rh;
+
/**
* Peer we tried to disconnect.
*/
/**
- * Force a disconnect from the specified peer. This is currently done by
- * changing the bandwidth policy to 0 bytes per second.
- * FIXME: maybe we want a nicer CORE API for both connect and disconnect...
+ * Force a disconnect from the specified peer.
* FIXME: this policy change is never undone; how do we reconnect ever?
*/
static void
GNUNET_CONTAINER_DLL_insert (disconnect_head,
disconnect_tail,
dl);
- dl->rh = GNUNET_CORE_peer_request_disconnect (sched, cfg,
- GNUNET_TIME_UNIT_FOREVER_REL,
- peer,
- &disconnect_done,
- dl);
+ dl->rh = GNUNET_TRANSPORT_blacklist (sched, cfg,
+ peer,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &disconnect_done,
+ dl);
}
/**
* Function called by core when our attempt to connect succeeded.
- * Transmits a 'DUMMY' message to trigger the session key exchange.
- * FIXME: this is an issue with the current CORE API.
*/
-static size_t
-ready_callback (void *cls,
- size_t size, void *buf)
+static void
+connect_completed_callback (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerList *pos = cls;
- struct GNUNET_MessageHeader hdr;
pos->connect_req = NULL;
- if (buf == NULL)
- {
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core told us that our attempt to connect failed.\n");
-#endif
- return 0;
- }
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending dummy message to establish connection.\n");
-#endif
- hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
- hdr.type = htons (GNUNET_MESSAGE_TYPE_TOPOLOGY_DUMMY);
- memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader));
- return sizeof (struct GNUNET_MessageHeader);
}
"Asking core to connect to `%s'\n",
GNUNET_i2s (&pos->id));
#endif
- pos->connect_req = GNUNET_CORE_notify_transmit_ready (handle,
- 0 /* priority */,
- GNUNET_TIME_UNIT_MINUTES,
- &pos->id,
- sizeof(struct GNUNET_MessageHeader),
- &ready_callback,
- pos);
+ pos->connect_req = GNUNET_CORE_peer_request_connect (sched, cfg,
+ GNUNET_TIME_UNIT_MINUTES,
+ &pos->id,
+ &connect_completed_callback,
+ pos);
}
if (pos->hello_req != NULL)
GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req);
if (pos->connect_req != NULL)
- GNUNET_CORE_notify_transmit_ready_cancel (pos->connect_req);
+ GNUNET_CORE_peer_request_connect_cancel (pos->connect_req);
if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (sched,
pos->hello_delay_task);
GNUNET_CONTAINER_DLL_remove (disconnect_head,
disconnect_tail,
dl);
- GNUNET_CORE_peer_request_cancel (dl->rh);
+ GNUNET_TRANSPORT_blacklist_cancel (dl->rh);
GNUNET_free (dl);
}
}