/**
* Connection to transport service.
*/
- struct GNUNET_CLIENT_Connection * client;
+ struct GNUNET_CLIENT_Connection *client;
/**
* Configuration to use.
* @param msg query
*/
static void
-query_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+query_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_TRANSPORT_Blacklist *br = cls;
const struct BlacklistMessage *bm;
- if ( (ntohs(msg->size) != sizeof (struct BlacklistMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY) )
- {
- reconnect (br);
- return;
- }
- bm = (const struct BlacklistMessage *)msg;
+ GNUNET_assert (br != NULL);
+ if ((NULL == msg) ||
+ (ntohs (msg->size) != sizeof (struct BlacklistMessage)) ||
+ (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY))
+ {
+ reconnect (br);
+ return;
+ }
+ bm = (const struct BlacklistMessage *) msg;
GNUNET_break (0 == ntohl (bm->is_allowed));
br->peer = bm->peer;
reply (br);
static void
receive (struct GNUNET_TRANSPORT_Blacklist *br)
{
- GNUNET_CLIENT_receive (br->client,
- &query_handler,
- br,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_CLIENT_receive (br->client, &query_handler, br,
+ GNUNET_TIME_UNIT_FOREVER_REL);
}
* @return number of bytes written to buf
*/
static size_t
-transmit_blacklist_init (void *cls,
- size_t size, void *buf)
+transmit_blacklist_init (void *cls, size_t size, void *buf)
{
struct GNUNET_TRANSPORT_Blacklist *br = cls;
struct GNUNET_MessageHeader req;
+ br->th = NULL;
if (buf == NULL)
- {
- reconnect (br);
- return 0;
- }
+ {
+ reconnect (br);
+ return 0;
+ }
req.size = htons (sizeof (struct GNUNET_MessageHeader));
req.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
memcpy (buf, &req, sizeof (req));
{
if (br->client != NULL)
GNUNET_CLIENT_disconnect (br->client, GNUNET_NO);
- br->client = GNUNET_CLIENT_connect ("transport",
- br->cfg);
+ br->client = GNUNET_CLIENT_connect ("transport", br->cfg);
GNUNET_assert (br->client != NULL);
- br->th = GNUNET_CLIENT_notify_transmit_ready (br->client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &transmit_blacklist_init,
- br);
+ br->th =
+ GNUNET_CLIENT_notify_transmit_ready (br->client,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &transmit_blacklist_init,
+ br);
}
* @return number of bytes written to buf
*/
static size_t
-transmit_blacklist_reply (void *cls,
- size_t size, void *buf)
+transmit_blacklist_reply (void *cls, size_t size, void *buf)
{
struct GNUNET_TRANSPORT_Blacklist *br = cls;
struct BlacklistMessage req;
+ br->th = NULL;
if (buf == NULL)
- {
- reconnect (br);
- return 0;
- }
+ {
+ reconnect (br);
+ return 0;
+ }
req.header.size = htons (sizeof (req));
req.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY);
req.is_allowed = htonl (br->cb (br->cb_cls, &br->peer));
req.peer = br->peer;
memcpy (buf, &req, sizeof (req));
+ br->th = NULL;
receive (br);
return sizeof (req);
}
static void
reply (struct GNUNET_TRANSPORT_Blacklist *br)
{
- br->th = GNUNET_CLIENT_notify_transmit_ready (br->client,
- sizeof (struct BlacklistMessage),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &transmit_blacklist_reply,
- br);
+ GNUNET_assert (br->th == NULL);
+ br->th =
+ GNUNET_CLIENT_notify_transmit_ready (br->client,
+ sizeof (struct BlacklistMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO, &transmit_blacklist_reply,
+ br);
if (br->th == NULL)
- {
- reconnect (br);
- return;
- }
+ {
+ reconnect (br);
+ return;
+ }
}
*/
struct GNUNET_TRANSPORT_Blacklist *
GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TRANSPORT_BlacklistCallback cb,
- void *cb_cls)
+ GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls)
{
- struct GNUNET_CLIENT_Connection * client;
+ struct GNUNET_CLIENT_Connection *client;
struct GNUNET_TRANSPORT_Blacklist *ret;
client = GNUNET_CLIENT_connect ("transport", cfg);
ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Blacklist));
ret->client = client;
ret->cfg = cfg;
- ret->th = GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &transmit_blacklist_init,
- ret);
+ ret->cb = cb;
+ ret->cb_cls = cb_cls;
+ GNUNET_assert (ret->th == NULL);
+ ret->th =
+ GNUNET_CLIENT_notify_transmit_ready (client,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &transmit_blacklist_init,
+ ret);
return ret;
}
GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br)
{
if (br->th != NULL)
+ {
GNUNET_CLIENT_notify_transmit_ready_cancel (br->th);
+ br->th = NULL;
+ }
GNUNET_CLIENT_disconnect (br->client, GNUNET_NO);
GNUNET_free (br);
}