int check_self;
};
+struct HelloContext
+{
+
+ /**
+ * Size of the HELLO copied to end of struct.
+ */
+ uint16_t size;
+
+ /**
+ * Continuation to call once HELLO sent.
+ */
+ GNUNET_SCHEDULER_Task cont;
+
+ /**
+ * Closure to call with the continuation.
+ */
+ void *cont_cls;
+
+ /* HELLO */
+};
+
/**
* Get the neighbour list entry for the given peer
}
+/**
+ * FIXME: document
+ */
struct SetQuotaContext
{
+ /**
+ * FIXME: document
+ */
struct GNUNET_TRANSPORT_Handle *handle;
+ /**
+ * FIXME: document
+ */
struct GNUNET_PeerIdentity target;
+ /**
+ * FIXME: document
+ */
GNUNET_SCHEDULER_Task cont;
+ /**
+ * Closure for 'cont'.
+ */
void *cont_cls;
+ /**
+ * FIXME: document
+ */
struct GNUNET_TIME_Absolute timeout;
+ /**
+ * FIXME: document
+ */
struct GNUNET_BANDWIDTH_Value32NBO quota_in;
};
static size_t
send_hello (void *cls, size_t size, void *buf)
{
- struct GNUNET_MessageHeader *hello = cls;
- uint16_t msize;
-
+ struct HelloContext *hc = cls;
+ uint16_t ssize;
if (buf == NULL)
{
#if DEBUG_TRANSPORT_TIMEOUT
"Timeout while trying to transmit `%s' request.\n",
"HELLO");
#endif
- GNUNET_free (hello);
+ GNUNET_SCHEDULER_add_now(hc->cont, hc->cont_cls);
+ GNUNET_free (hc);
return 0;
}
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting `%s' request.\n", "HELLO");
#endif
- msize = ntohs (hello->size);
- GNUNET_assert (size >= msize);
- memcpy (buf, hello, msize);
- GNUNET_free (hello);
- return msize;
+ GNUNET_assert (size >= hc->size);
+ memcpy (buf, &hc[1], hc->size);
+
+ if (hc->cont != NULL)
+ {
+ GNUNET_SCHEDULER_add_continuation(hc->cont, hc->cont_cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ }
+ ssize = hc->size;
+ GNUNET_free (hc);
+ return ssize;
}
*
* @param handle connection to transport service
* @param hello the hello message
+ * @param cont continuation to call when HELLO has been sent
+ * @param cls closure for continuation
+ *
*/
void
GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
- const struct GNUNET_MessageHeader *hello)
+ const struct GNUNET_MessageHeader *hello,
+ GNUNET_SCHEDULER_Task cont,
+ void *cls)
{
- struct GNUNET_MessageHeader *hc;
uint16_t size;
struct GNUNET_PeerIdentity peer;
+ struct HelloContext *hc;
GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
size = ntohs (hello->size);
GNUNET_break (0);
return;
}
+ hc = GNUNET_malloc(sizeof(struct HelloContext) + size);
+ hc->size = size;
+ hc->cont = cont;
+ hc->cont_cls = cls;
+ memcpy (&hc[1], hello, size);
+
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Offering `%s' message of `%4s' to transport for validation.\n",
"HELLO",
GNUNET_i2s (&peer));
#endif
- hc = GNUNET_malloc (size);
- memcpy (hc, hello, size);
+
schedule_control_transmit (handle,
size,
GNUNET_NO, OFFER_HELLO_TIMEOUT, &send_hello, hc);
#endif
GNUNET_break (n->is_connected == GNUNET_YES);
n->is_connected = GNUNET_NO;
+ /* FIXME: this 'in_disconnect' flag is dubious; we should define
+ clearly what disconnect means for pending 'notify_transmit_ready'
+ requests; maybe a good approach is to REQUIRE clients to
+ call 'notify_transmit_ready_cancel' on pending requests on disconnect
+ and otherwise FAIL HARD with an assertion failure before
+ 'neighbour_free' right here (transmit_stage would be forced
+ to 'TS_NEW') */
n->in_disconnect = GNUNET_YES;
if (h->nd_cb != NULL)
h->nd_cb (h->cls, &n->id);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
#endif
+ /* FIXME: this flag is dubious, we should be able to do this
+ more cleanly; also, we should probably do 'disconnect'
+ callbacks for every connected peer here, i.e. by calling
+ the iterator with 'forget_neighbours' instead of 'delete_neighbours'.
+ */
+
handle->in_disconnect = GNUNET_YES;
GNUNET_assert (GNUNET_SYSERR !=
"Disconnecting from transport service for good.\n");
#endif
handle->client = NULL;
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ GNUNET_CLIENT_disconnect (client, GNUNET_YES);
}
GNUNET_free (handle);
}
struct NeighbourList *n;
struct GNUNET_PeerIdentity me;
uint16_t size;
+ uint32_t ats_count;
if (h->client == NULL)
{
}
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
- if (size != sizeof (struct ConnectInfoMessage))
+
+ if (size < sizeof (struct ConnectInfoMessage))
{
GNUNET_break (0);
break;
}
cim = (const struct ConnectInfoMessage *) msg;
+ ats_count = ntohl (cim->ats_count);
+ if (size != sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))
+ {
+ GNUNET_break (0);
+ break;
+ }
+
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Receiving `%s' message for `%4s'.\n",
#endif
n = neighbour_find (h, &cim->id);
if (n == NULL)
- n = neighbour_add (h,
- &cim->id);
+ n = neighbour_add (h, &cim->id);
if (n == NULL)
- {
- GNUNET_break (0);
- return;
- }
+ return;
GNUNET_break (n->is_connected == GNUNET_NO);
- if (ntohl ((&cim->ats)[ntohl (cim->ats_count)].type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
- {
- GNUNET_break (0);
- return;
- }
- fprintf(stderr,"transport_api GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT ats_count %u\n",ntohl (cim->ats_count));
- n->is_connected = GNUNET_YES;
+ n->is_connected = GNUNET_YES;
+ /* FIXME */
if (h->nc_cb != NULL)
- h->nc_cb (h->cls, &n->id,
- NULL,
- 0);
- /* if (h->nc_cb != NULL)
h->nc_cb (h->cls, &n->id,
- &(cim->ats),
- ntohl (cim->ats_count));*/
+ &cim->ats,ats_count);
+ /* FIXEND */
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
if (size != sizeof (struct DisconnectInfoMessage))
}
im = (const struct InboundMessage *) msg;
GNUNET_break (0 == ntohl (im->reserved));
- GNUNET_assert(sizeof (struct InboundMessage) + ntohl(im->ats_count) * sizeof(struct GNUNET_TRANSPORT_ATS_Information) + sizeof (struct GNUNET_MessageHeader) <= size);
- imm = (const struct GNUNET_MessageHeader *) &((&im->ats)[ntohl(im->ats_count)+1]);
- if (ntohs (imm->size) + sizeof (struct InboundMessage) + ntohl(im->ats_count) * sizeof(struct GNUNET_TRANSPORT_ATS_Information) != size)
+ ats_count = ntohl(im->ats_count);
+ //imm = (const struct GNUNET_MessageHeader *) &im[1];
+ imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count+1]);
+
+ if (ntohs (imm->size) + sizeof (struct InboundMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) != size)
{
GNUNET_break (0);
break;
GNUNET_break (0);
break;
}
- if (ntohl ((&im->ats)[ntohl(im->ats_count)].type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
- {
- GNUNET_break (0);
- return;
- }
- fprintf(stderr,"transport_api GNUNET_MESSAGE_TYPE_TRANSPORT_RECV ats_count %u\n",ntohl (im->ats_count));
- if (h->rec != NULL)
- h->rec (h->cls, &im->peer,
- imm,
- NULL,
- 0);
-
- /*h->rec (h->cls, &im->peer,
- imm,
- &im->ats,
- ntohl (im->ats_count));*/
+ /* FIXME: */
+ if (h->rec != NULL)
+ h->rec (h->cls, &im->peer, imm,
+ &im->ats, ats_count);
+ /* ENDFIX */
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,