static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
send_task = GNUNET_SCHEDULER_add_now (&send_task_f, NULL);
}
enum StartFlag
{
-
+
START_FLAG_SCHEDULING = 0,
START_FLAG_PERFORMANCE_WITH_PIC = 1,
START_FLAG_PERFORMANCE_NO_PIC = 2
-
};
struct RequestAddressMessage
{
struct GNUNET_MessageHeader header;
-
+
uint32_t reserved GNUNET_PACKED;
struct GNUNET_PeerIdentity peer;
uint32_t session_id GNUNET_PACKED;
/* followed by:
- - struct GNUNET_ATS_Information [ats_count];
- - char address[address_length]
- - char plugin_name[plugin_name_length] (including '\0'-termination).
- */
+ * - struct GNUNET_ATS_Information [ats_count];
+ * - char address[address_length]
+ * - char plugin_name[plugin_name_length] (including '\0'-termination).
+ */
};
uint32_t session_id GNUNET_PACKED;
/* followed by:
- - char address[address_length]
- - char plugin_name[plugin_name_length] (including '\0'-termination).
- */
+ * - char address[address_length]
+ * - char plugin_name[plugin_name_length] (including '\0'-termination).
+ */
};
uint32_t session_id GNUNET_PACKED;
/* followed by:
- - char address[address_length]
- - char plugin_name[plugin_name_length] (including '\0'-termination).
- */
+ * - char address[address_length]
+ * - char plugin_name[plugin_name_length] (including '\0'-termination).
+ */
};
uint32_t session_id GNUNET_PACKED;
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
-
+
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
/* followed by:
- - struct GNUNET_ATS_Information [ats_count];
- - char address[address_length]
- - char plugin_name[plugin_name_length] (including '\0'-termination).
- */
+ * - struct GNUNET_ATS_Information [ats_count];
+ * - char address[address_length]
+ * - char plugin_name[plugin_name_length] (including '\0'-termination).
+ */
};
uint16_t plugin_name_length GNUNET_PACKED;
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
-
+
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
- /* followed by:
- - struct GNUNET_ATS_Information [ats_count];
- - char address[address_length]
- - char plugin_name[plugin_name_length] (including '\0'-termination).
- */
+ /* followed by:
+ * - struct GNUNET_ATS_Information [ats_count];
+ * - char address[address_length]
+ * - char plugin_name[plugin_name_length] (including '\0'-termination).
+ */
};
uint32_t preference_kind GNUNET_PACKED;
float preference_value GNUNET_PACKED;
-
+
};
struct GNUNET_PeerIdentity peer;
- /* followed by 'num_preferences'
- struct PreferenceInformation values */
+ /* followed by 'num_preferences'
+ * struct PreferenceInformation values */
};
GNUNET_assert (GNUNET_SYSERR != ar->connected);
/* FIXME: ||1 because we currently NEVER get 'connected' events... */
- if ( (GNUNET_YES == ar->connected) || 1)
+ if ((GNUNET_YES == ar->connected) || 1)
{
ar->bandwidth_in = sbc->bw_in;
ar->bandwidth_out = sbc->bw_out;
GNUNET_BANDWIDTH_tracker_update_quota (&ar->available_recv_window,
ar->bandwidth_in);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n",
- GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
- ntohl (ar->bandwidth_in.value__),
- ntohl (ar->bandwidth_out.value__));
+ "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n",
+ GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
+ ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__));
if (NULL != sbc->atc->alloc_cb)
sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
(const struct GNUNET_PeerIdentity *) key,
- ar->plugin_name, ar->plugin_addr,
- ar->plugin_addr_len,
- ar->session,
- ar->bandwidth_out,
- ar->bandwidth_in,
- NULL, 0);
+ ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len,
+ ar->session, ar->bandwidth_out, ar->bandwidth_in,
+ NULL, 0);
}
else if (ntohl (ar->bandwidth_out.value__) > 0)
{
if (NULL != sbc->atc->alloc_cb)
sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
(const struct GNUNET_PeerIdentity *) key,
- ar->plugin_name, ar->plugin_addr,
- ar->plugin_addr_len, ar->session, ar->bandwidth_out,
- ar->bandwidth_in, NULL, 0);
+ ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len,
+ ar->session, ar->bandwidth_out, ar->bandwidth_in,
+ NULL, 0);
}
else
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n",
- GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
- ntohl (ar->bandwidth_in.value__),
- ntohl (ar->bandwidth_out.value__));
-
+ "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n",
+ GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
+ ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__));
+
return GNUNET_YES;
}
bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Trivial implementation: bandwidth assigned to each peer is i:%u/o:%u bytes/s\n",
- ntohl (bwc.bw_in.value__),
- ntohl (bwc.bw_out.value__));
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
+ ntohl (bwc.bw_in.value__), ntohl (bwc.bw_out.value__));
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
}
#if DEBUG_ATS
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Suggesting address for peer `%s', starting with i:%u/o:%u bytes/s\n",
- GNUNET_h2s (key),
- asc->atc->total_bps_in/32,
- asc->atc->total_bps_out/32);
+ GNUNET_h2s (key), asc->atc->total_bps_in / 32,
+ asc->atc->total_bps_out / 32);
#endif
/* trivial strategy: pick first available address... */
struct GNUNET_ATS_SuggestionContext *asc;
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Looking up suggested address for peer `%s'\n", GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Looking up suggested address for peer `%s'\n",
+ GNUNET_i2s (peer));
#endif
asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext));
asc->cb = cb;
if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
return GNUNET_YES;
- if (! (((arnew->session == arold->session) && (arnew->session != NULL)) ||
- ((arold->session == NULL) &&
- (arold->plugin_addr_len == arnew->plugin_addr_len) &&
- (0 ==
- memcmp (arold->plugin_addr, arnew->plugin_addr,
- arnew->plugin_addr_len)))))
- return GNUNET_YES; /* no match */
+ if (!
+ (((arnew->session == arold->session) && (arnew->session != NULL)) ||
+ ((arold->session == NULL) &&
+ (arold->plugin_addr_len == arnew->plugin_addr_len) &&
+ (0 ==
+ memcmp (arold->plugin_addr, arnew->plugin_addr,
+ arnew->plugin_addr_len)))))
+ return GNUNET_YES; /* no match */
/* records match */
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Updating session for peer `%s' plugin `%s'\n", GNUNET_h2s (key),
- arold->plugin_name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating session for peer `%s' plugin `%s'\n",
+ GNUNET_h2s (key), arold->plugin_name);
#endif
if (arnew->session != arold->session)
- {
- arold->session = arnew->session;
- }
+ {
+ arold->session = arnew->session;
+ }
if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
- {
- arold->connected = GNUNET_YES;
- }
-
+ {
+ arold->connected = GNUNET_YES;
+ }
+
/* Update existing value */
c_new = 0;
while (c_new < arnew->ats_count)
+ {
+ c_old = 0;
+ found = GNUNET_NO;
+ while (c_old < arold->ats_count)
{
- c_old = 0;
- found = GNUNET_NO;
- while (c_old < arold->ats_count)
+ if (arold->ats[c_old].type == arnew->ats[c_new].type)
{
- if (arold->ats[c_old].type == arnew->ats[c_new].type)
- {
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found type %i, old value=%i new value=%i\n",
- ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value),
- ntohl (arnew->ats[c_new].value));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Found type %i, old value=%i new value=%i\n",
+ ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value),
+ ntohl (arnew->ats[c_new].value));
#endif
- arold->ats[c_old].value = arnew->ats[c_new].value;
- found = GNUNET_YES;
- }
- c_old++;
+ arold->ats[c_old].value = arnew->ats[c_new].value;
+ found = GNUNET_YES;
}
- /* Add new value */
- if (found == GNUNET_NO)
- {
+ c_old++;
+ }
+ /* Add new value */
+ if (found == GNUNET_NO)
+ {
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n",
- ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value));
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n",
+ ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count);
#endif
- GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1);
- GNUNET_assert (arold->ats_count >= 2);
- arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type;
- arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value;
- arold->ats[arold->ats_count - 1].type = htonl (0);
- arold->ats[arold->ats_count - 1].value = htonl (0);
+ GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1);
+ GNUNET_assert (arold->ats_count >= 2);
+ arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type;
+ arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value;
+ arold->ats[arold->ats_count - 1].type = htonl (0);
+ arold->ats[arold->ats_count - 1].value = htonl (0);
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count);
#endif
- }
- c_new++;
}
-
+ c_new++;
+ }
+
update_bandwidth_assignment (usc->atc, arold);
return GNUNET_NO;
}
MAX_WINDOW_TIME_S);
GNUNET_assert (ats_count > 0);
GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
- memcpy (ar->ats, ats,
- ats_count * sizeof (struct GNUNET_ATS_Information));
- ar->connected = GNUNET_SYSERR; /* aka: not known / no change */
+ memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
+ ar->connected = GNUNET_SYSERR; /* aka: not known / no change */
return ar;
}
struct UpdateSessionContext usc;
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to peer %s\n",
- GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n", GNUNET_i2s (peer));
#endif
-
+
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer,
atc);
ar = create_allocation_record (plugin_name, session, plugin_addr,
const struct GNUNET_PeerIdentity *peer)
{
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnected from peer %s\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnected from peer %s\n",
GNUNET_i2s (peer));
#endif
(void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
struct UpdateSessionContext usc;
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Updating address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer),
- plugin_name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s', plugin `%s'\n",
+ GNUNET_i2s (peer), plugin_name);
#endif
ar = create_allocation_record (plugin_name, session, plugin_addr,
plugin_addr_len, ats, ats_count);
return;
}
#if DEBUG_ATS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer),
plugin_name);
#endif
GNUNET_ATS_PeerConfigurationInfoCallback info;
void *info_cls;
-
+
struct GNUNET_PeerIdentity peer;
-
+
GNUNET_SCHEDULER_TaskIdentifier task;
};
static void
-exec_pcp (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+exec_pcp (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_ATS_InformationRequestContext *irc = cls;
int32_t want_reserv;
rdelay = GNUNET_TIME_UNIT_ZERO;
want_reserv = irc->amount;
- ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey);
+ ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey);
if (NULL == ar)
{
/* attempt to change preference on peer that is not connected */
/* FIXME: this can happen if the 'service' didn't yet tell us about
- a new connection, fake it! */
- irc->info (irc->info_cls,
- &irc->peer,
- want_reserv,
- rdelay);
+ * a new connection, fake it! */
+ irc->info (irc->info_cls, &irc->peer, want_reserv, rdelay);
GNUNET_free (irc);
return;
}
else if (want_reserv > 0)
{
rdelay =
- GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window,
- want_reserv);
+ GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window,
+ want_reserv);
if (rdelay.rel_value == 0)
got_reserv = want_reserv;
else
- got_reserv = 0; /* all or nothing */
+ got_reserv = 0; /* all or nothing */
}
else
got_reserv = 0;
GNUNET_BANDWIDTH_tracker_consume (&ar->available_recv_window, got_reserv);
- irc->info (irc->info_cls,
- &irc->peer,
- got_reserv,
- rdelay);
+ irc->info (irc->info_cls, &irc->peer, got_reserv, rdelay);
GNUNET_free (irc);
}
*/
struct GNUNET_ATS_InformationRequestContext *
GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
- const struct GNUNET_PeerIdentity *peer,
- int32_t amount, uint64_t preference,
- GNUNET_ATS_PeerConfigurationInfoCallback
- info, void *info_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ int32_t amount, uint64_t preference,
+ GNUNET_ATS_PeerConfigurationInfoCallback
+ info, void *info_cls)
{
struct GNUNET_ATS_InformationRequestContext *irc;
*/
void
GNUNET_ATS_peer_change_preference_cancel (struct
- GNUNET_ATS_InformationRequestContext
- *irc)
+ GNUNET_ATS_InformationRequestContext
+ *irc)
{
GNUNET_SCHEDULER_cancel (irc->task);
GNUNET_free (irc);
*/
struct GNUNET_ATS_InformationRequestContext *
GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
- const struct GNUNET_PeerIdentity *peer,
- int32_t amount, uint64_t preference,
- GNUNET_ATS_PeerConfigurationInfoCallback
- info, void *info_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ int32_t amount, uint64_t preference,
+ GNUNET_ATS_PeerConfigurationInfoCallback
+ info, void *info_cls)
{
struct GNUNET_ATS_InformationRequestContext *irc;
struct PeerRecord *pr;
*/
void
GNUNET_ATS_peer_change_preference_cancel (struct
- GNUNET_ATS_InformationRequestContext
- *irc)
+ GNUNET_ATS_InformationRequestContext
+ *irc)
{
struct GNUNET_ATS_SchedulingHandle *h = irc->h;
struct PeerRecord *pr = irc->pr;
/**
* Kept in a DLL.
- */
+ */
struct PendingMessage *next;
/**
* Kept in a DLL.
- */
+ */
struct PendingMessage *prev;
/**
/**
* Is this the 'ATS_START' message?
- */
+ */
int is_init;
};
/**
* Kept in a DLL.
- */
+ */
struct GNUNET_ATS_ReservationContext *next;
/**
* Kept in a DLL.
- */
+ */
struct GNUNET_ATS_ReservationContext *prev;
/**
* Target peer.
*/
struct GNUNET_PeerIdentity peer;
-
+
/**
* Desired reservation
*/
*/
struct GNUNET_ATS_PerformanceHandle
{
-
+
/**
* Our configuration.
*/
* Callback to invoke on performance changes.
*/
GNUNET_ATS_PeerInformationCallback infocb;
-
+
/**
* Closure for 'infocb'.
*/
/**
* Task to trigger reconnect.
- */
+ */
GNUNET_SCHEDULER_TaskIdentifier task;
-
+
};
* @param tc scheduler context
*/
static void
-reconnect_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_ATS_PerformanceHandle *ph = cls;
* @return number of bytes copied into buf
*/
static size_t
-transmit_message_to_ats (void *cls,
- size_t size,
- void *buf)
+transmit_message_to_ats (void *cls, size_t size, void *buf)
{
struct GNUNET_ATS_PerformanceHandle *ph = cls;
struct PendingMessage *p;
ph->th = NULL;
ret = 0;
cbuf = buf;
- while ( (NULL != (p = ph->pending_head)) &&
- (p->size <= size) )
+ while ((NULL != (p = ph->pending_head)) && (p->size <= size))
{
- memcpy (&cbuf[ret], &p[1], p->size);
+ memcpy (&cbuf[ret], &p[1], p->size);
ret += p->size;
size -= p->size;
- GNUNET_CONTAINER_DLL_remove (ph->pending_head,
- ph->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
GNUNET_free (p);
}
do_transmit (ph);
if (NULL == (p = ph->pending_head))
return;
if (NULL == ph->client)
- return; /* currently reconnecting */
- ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client,
- p->size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &transmit_message_to_ats, ph);
+ return; /* currently reconnecting */
+ ph->th =
+ GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &transmit_message_to_ats,
+ ph);
}
*/
static int
process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
const struct PeerInformationMessage *pi;
const struct GNUNET_ATS_Information *atsi;
{
GNUNET_break (0);
return GNUNET_SYSERR;
- }
+ }
if (ntohs (msg->size) < sizeof (struct PeerInformationMessage))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- pi = (const struct PeerInformationMessage*) msg;
+ pi = (const struct PeerInformationMessage *) msg;
ats_count = ntohl (pi->ats_count);
address_length = ntohs (pi->address_length);
plugin_name_length = ntohs (pi->plugin_name_length);
- atsi = (const struct GNUNET_ATS_Information*) &pi[1];
- address = (const char*) &atsi[ats_count];
+ atsi = (const struct GNUNET_ATS_Information *) &pi[1];
+ address = (const char *) &atsi[ats_count];
plugin_name = &address[address_length];
- if ( (address_length +
- plugin_name_length +
- ats_count * sizeof (struct GNUNET_ATS_Information) +
- sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
- (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ||
- (plugin_name[plugin_name_length - 1] != '\0') )
+ if ((address_length + plugin_name_length +
+ ats_count * sizeof (struct GNUNET_ATS_Information) +
+ sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
+ (ats_count >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
+ || (plugin_name[plugin_name_length - 1] != '\0'))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- ph->infocb (ph->infocb_cls,
- &pi->peer,
- plugin_name,
- address, address_length,
- pi->bandwidth_out,
- pi->bandwidth_in,
- atsi,
- ats_count);
+ ph->infocb (ph->infocb_cls, &pi->peer, plugin_name, address, address_length,
+ pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count);
return GNUNET_OK;
}
*/
static int
process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
const struct ReservationResultMessage *rr;
struct GNUNET_ATS_ReservationContext *rc;
GNUNET_break (0);
return GNUNET_SYSERR;
}
- rr = (const struct ReservationResultMessage*) msg;
+ rr = (const struct ReservationResultMessage *) msg;
amount = ntohl (rr->amount);
rc = ph->reservation_head;
- if (0 != memcmp (&rr->peer,
- &rc->peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
- ph->reservation_tail,
- rc);
- if ( (amount == 0) ||
- (rc->rcb != NULL) )
+ GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc);
+ if ((amount == 0) || (rc->rcb != NULL))
{
/* tell client if not cancelled */
if (rc->rcb != NULL)
- rc->rcb (rc->rcb_cls,
- &rr->peer,
- amount,
- GNUNET_TIME_relative_ntoh (rr->res_delay));
+ rc->rcb (rc->rcb_cls, &rr->peer, amount,
+ GNUNET_TIME_relative_ntoh (rr->res_delay));
GNUNET_free (rc);
return GNUNET_OK;
}
if (GNUNET_YES != rc->undo)
{
GNUNET_free (rc);
- return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
+ return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
}
GNUNET_free (rc);
(void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL);
* @param msg message received, NULL on timeout or fatal error
*/
static void
-process_ats_message (void *cls,
- const struct GNUNET_MessageHeader *msg)
+process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_ATS_PerformanceHandle *ph = cls;
- if (NULL == msg)
+ if (NULL == msg)
goto reconnect;
switch (ntohs (msg->type))
{
break;
case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
if (GNUNET_OK != process_rr_message (ph, msg))
- goto reconnect;
+ goto reconnect;
break;
default:
GNUNET_break (0);
goto reconnect;
return;
}
- GNUNET_CLIENT_receive (ph->client,
- &process_ats_message, ph,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
+ GNUNET_TIME_UNIT_FOREVER_REL);
return;
- reconnect:
+reconnect:
GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
ph->client = NULL;
- ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &reconnect_task, ph);
+ ph->task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
+ ph);
}
GNUNET_assert (NULL == ph->client);
ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg);
GNUNET_assert (NULL != ph->client);
- GNUNET_CLIENT_receive (ph->client,
- &process_ats_message, ph,
- GNUNET_TIME_UNIT_FOREVER_REL);
- if ( (NULL == (p = ph->pending_head)) ||
- (GNUNET_YES != p->is_init) )
+ GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
{
p = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct ClientStartMessage));
+ sizeof (struct ClientStartMessage));
p->size = sizeof (struct ClientStartMessage);
p->is_init = GNUNET_YES;
init = (struct ClientStartMessage *) &p[1];
init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
init->header.size = htons (sizeof (struct ClientStartMessage));
- init->start_flag = htonl ((ph->infocb == NULL)
- ? START_FLAG_PERFORMANCE_NO_PIC
- : START_FLAG_PERFORMANCE_WITH_PIC);
- GNUNET_CONTAINER_DLL_insert (ph->pending_head,
- ph->pending_tail,
- p);
+ init->start_flag =
+ htonl ((ph->infocb ==
+ NULL) ? START_FLAG_PERFORMANCE_NO_PIC :
+ START_FLAG_PERFORMANCE_WITH_PIC);
+ GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p);
}
do_transmit (ph);
}
*/
struct GNUNET_ATS_PerformanceHandle *
GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ATS_PeerInformationCallback infocb,
- void *infocb_cls)
+ GNUNET_ATS_PeerInformationCallback infocb,
+ void *infocb_cls)
{
struct GNUNET_ATS_PerformanceHandle *ph;
{
struct PendingMessage *p;
struct GNUNET_ATS_ReservationContext *rc;
-
+
while (NULL != (p = ph->pending_head))
{
- GNUNET_CONTAINER_DLL_remove (ph->pending_head,
- ph->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
GNUNET_free (p);
}
while (NULL != (rc = ph->reservation_head))
{
- GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
- ph->reservation_tail,
- rc);
+ GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail,
+ rc);
GNUNET_break (NULL == rc->rcb);
GNUNET_free (rc);
- }
+ }
if (GNUNET_SCHEDULER_NO_TASK != ph->task)
{
GNUNET_SCHEDULER_cancel (ph->task);
*/
struct GNUNET_ATS_ReservationContext *
GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
- const struct GNUNET_PeerIdentity *peer,
- int32_t amount,
- GNUNET_ATS_ReservationCallback rcb,
- void *rcb_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ int32_t amount,
+ GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
{
struct GNUNET_ATS_ReservationContext *rc;
struct PendingMessage *p;
rc->peer = *peer;
rc->rcb = rcb;
rc->rcb_cls = rcb_cls;
- if ( (rcb != NULL) && (amount > 0) )
+ if ((rcb != NULL) && (amount > 0))
rc->undo = GNUNET_YES;
- GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head,
- ph->reservation_tail,
- rc);
-
- p = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct ReservationRequestMessage));
+ GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, ph->reservation_tail,
+ rc);
+
+ p = GNUNET_malloc (sizeof (struct PendingMessage) +
+ sizeof (struct ReservationRequestMessage));
p->size = sizeof (struct ReservationRequestMessage);
p->is_init = GNUNET_NO;
- m = (struct ReservationRequestMessage*) &p[1];
+ m = (struct ReservationRequestMessage *) &p[1];
m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST);
m->header.size = htons (sizeof (struct ReservationRequestMessage));
m->amount = htonl (amount);
m->peer = *peer;
- GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head,
- ph->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
do_transmit (ph);
return rc;
}
* @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
*/
void
-GNUNET_ATS_reserve_bandwidth_cancel (struct
- GNUNET_ATS_ReservationContext *rc)
+GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
{
rc->rcb = NULL;
}
/**
* Change preferences for the given peer. Preference changes are forgotten if peers
* disconnect.
- *
+ *
* @param ph performance handle
* @param peer identifies the peer
* @param ... 0-terminated specification of the desired changes
*/
void
GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
- const struct GNUNET_PeerIdentity *peer,
- ...)
+ const struct GNUNET_PeerIdentity *peer, ...)
{
struct PendingMessage *p;
struct ChangePreferenceMessage *m;
count = 0;
va_start (ap, peer);
- while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
+ while (GNUNET_ATS_PREFERENCE_END !=
+ (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
{
switch (kind)
{
case GNUNET_ATS_PREFERENCE_BANDWIDTH:
count++;
(void) va_arg (ap, double);
+
break;
case GNUNET_ATS_PREFERENCE_LATENCY:
count++;
(void) va_arg (ap, double);
+
break;
default:
- GNUNET_assert (0);
+ GNUNET_assert (0);
}
}
va_end (ap);
- msize = count * sizeof (struct PreferenceInformation) +
- sizeof (struct ChangePreferenceMessage);
- p = GNUNET_malloc (sizeof (struct PendingMessage) +
- msize);
+ msize =
+ count * sizeof (struct PreferenceInformation) +
+ sizeof (struct ChangePreferenceMessage);
+ p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
p->size = msize;
p->is_init = GNUNET_NO;
- m = (struct ChangePreferenceMessage*) &p[1];
+ m = (struct ChangePreferenceMessage *) &p[1];
m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE);
m->header.size = htons (msize);
m->num_preferences = htonl (count);
m->peer = *peer;
- pi = (struct PreferenceInformation*) &m[1];
+ pi = (struct PreferenceInformation *) &m[1];
count = 0;
va_start (ap, peer);
- while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
+ while (GNUNET_ATS_PREFERENCE_END !=
+ (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
{
pi[count].preference_kind = htonl (kind);
switch (kind)
{
case GNUNET_ATS_PREFERENCE_BANDWIDTH:
pi[count].preference_value = (float) va_arg (ap, double);
+
count++;
break;
case GNUNET_ATS_PREFERENCE_LATENCY:
pi[count].preference_value = (float) va_arg (ap, double);
+
count++;
break;
default:
- GNUNET_assert (0);
+ GNUNET_assert (0);
}
}
va_end (ap);
- GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head,
- ph->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
do_transmit (ph);
}
/* end of ats_api_performance.c */
-
/**
* Kept in a DLL.
- */
+ */
struct PendingMessage *next;
/**
* Kept in a DLL.
- */
+ */
struct PendingMessage *prev;
/**
/**
* Is this the 'ATS_START' message?
- */
+ */
int is_init;
};
*/
struct GNUNET_ATS_SchedulingHandle
{
-
+
/**
* Our configuration.
*/
* Callback to invoke on suggestions.
*/
GNUNET_ATS_AddressSuggestionCallback suggest_cb;
-
+
/**
* Closure for 'suggest_cb'.
*/
/**
* Task to trigger reconnect.
- */
+ */
GNUNET_SCHEDULER_TaskIdentifier task;
-
+
/**
* Size of the session array.
*/
* @param tc scheduler context
*/
static void
-reconnect_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_ATS_SchedulingHandle *sh = cls;
sh->reconnect = GNUNET_NO;
GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
sh->client = NULL;
- sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &reconnect_task, sh);
+ sh->task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
+ sh);
}
* @param msg message received, NULL on timeout or fatal error
*/
static void
-process_ats_message (void *cls,
- const struct GNUNET_MessageHeader *msg);
+process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg);
/**
* @return number of bytes copied into buf
*/
static size_t
-transmit_message_to_ats (void *cls,
- size_t size,
- void *buf)
+transmit_message_to_ats (void *cls, size_t size, void *buf)
{
struct GNUNET_ATS_SchedulingHandle *sh = cls;
struct PendingMessage *p;
char *cbuf;
sh->th = NULL;
- if ( (size == 0) || (buf == NULL))
+ if ((size == 0) || (buf == NULL))
{
force_reconnect (sh);
return 0;
}
ret = 0;
cbuf = buf;
- while ( (NULL != (p = sh->pending_head)) &&
- (p->size <= size) )
+ while ((NULL != (p = sh->pending_head)) && (p->size <= size))
{
- memcpy (&cbuf[ret], &p[1], p->size);
+ memcpy (&cbuf[ret], &p[1], p->size);
ret += p->size;
size -= p->size;
- GNUNET_CONTAINER_DLL_remove (sh->pending_head,
- sh->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
if (GNUNET_YES == p->is_init)
- GNUNET_CLIENT_receive (sh->client,
- &process_ats_message, sh,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
+ GNUNET_TIME_UNIT_FOREVER_REL);
GNUNET_free (p);
}
do_transmit (sh);
if (NULL == (p = sh->pending_head))
return;
if (NULL == sh->client)
- return; /* currently reconnecting */
- sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client,
- p->size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &transmit_message_to_ats, sh);
+ return; /* currently reconnecting */
+ sh->th =
+ GNUNET_CLIENT_notify_transmit_ready (sh->client, p->size,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO, &transmit_message_to_ats,
+ sh);
}
* @param peer peer the session belongs to
* @return the session object (or NULL)
*/
-static struct Session*
-find_session (struct GNUNET_ATS_SchedulingHandle *sh,
- uint32_t session_id,
- const struct GNUNET_PeerIdentity *peer)
+static struct Session *
+find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
+ const struct GNUNET_PeerIdentity *peer)
{
if (session_id >= sh->session_array_size)
{
}
if (session_id == 0)
return NULL;
- if (0 != memcmp (peer,
- &sh->session_array[session_id].peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 !=
+ memcmp (peer, &sh->session_array[session_id].peer,
+ sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
sh->reconnect = GNUNET_YES;
* @param peer peer the session belongs to
* @return the session id
*/
-static uint32_t
-get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
- struct Session *session,
- const struct GNUNET_PeerIdentity *peer)
+static uint32_t
+get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
+ const struct GNUNET_PeerIdentity *peer)
{
unsigned int i;
unsigned int f;
-
+
if (NULL == session)
return 0;
f = 0;
- for (i=1;i<sh->session_array_size;i++)
+ for (i = 1; i < sh->session_array_size; i++)
{
if (session == sh->session_array[i].session)
{
- GNUNET_assert (0 == memcmp (peer,
- &sh->session_array[i].peer,
- sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_assert (0 ==
+ memcmp (peer, &sh->session_array[i].peer,
+ sizeof (struct GNUNET_PeerIdentity)));
return i;
}
- if ( (f == 0) &&
- (sh->session_array[i].slot_used == GNUNET_NO) )
+ if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO))
f = i;
}
if (f == 0)
- {
+ {
f = sh->session_array_size;
- GNUNET_array_grow (sh->session_array,
- sh->session_array_size,
- sh->session_array_size * 2);
+ GNUNET_array_grow (sh->session_array, sh->session_array_size,
+ sh->session_array_size * 2);
}
GNUNET_assert (f > 0);
sh->session_array[f].session = session;
* @param peer peer the session belongs to
*/
static void
-remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
- uint32_t session_id,
- const struct GNUNET_PeerIdentity *peer)
+remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
+ const struct GNUNET_PeerIdentity *peer)
{
if (0 == session_id)
return;
GNUNET_assert (session_id < sh->session_array_size);
GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
- GNUNET_assert (0 == memcmp (peer,
- &sh->session_array[session_id].peer,
- sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_assert (0 ==
+ memcmp (peer, &sh->session_array[session_id].peer,
+ sizeof (struct GNUNET_PeerIdentity)));
sh->session_array[session_id].session = NULL;
}
* @param peer peer the session belongs to
*/
static void
-release_session (struct GNUNET_ATS_SchedulingHandle *sh,
- uint32_t session_id,
- const struct GNUNET_PeerIdentity *peer)
+release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
+ const struct GNUNET_PeerIdentity *peer)
{
if (session_id >= sh->session_array_size)
{
sh->reconnect = GNUNET_YES;
return;
}
- if (0 != memcmp (peer,
- &sh->session_array[session_id].peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 !=
+ memcmp (peer, &sh->session_array[session_id].peer,
+ sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
sh->reconnect = GNUNET_YES;
return;
}
sh->session_array[session_id].slot_used = GNUNET_NO;
- memset (&sh->session_array[session_id].peer,
- 0,
- sizeof (struct GNUNET_PeerIdentity));
+ memset (&sh->session_array[session_id].peer, 0,
+ sizeof (struct GNUNET_PeerIdentity));
}
static void
process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
- const struct SessionReleaseMessage *srm)
+ const struct SessionReleaseMessage *srm)
{
- release_session (sh,
- ntohl (srm->session_id),
- &srm->peer);
+ release_session (sh, ntohl (srm->session_id), &srm->peer);
}
* @param msg message received, NULL on timeout or fatal error
*/
static void
-process_ats_message (void *cls,
- const struct GNUNET_MessageHeader *msg)
+process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_ATS_SchedulingHandle *sh = cls;
const struct AddressSuggestionMessage *m;
uint16_t plugin_name_length;
uint32_t ats_count;
- if (NULL == msg)
+ if (NULL == msg)
{
force_reconnect (sh);
return;
}
- if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
- (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) )
+ if ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
+ (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)))
{
- process_release_message (sh,
- (const struct SessionReleaseMessage*) msg);
- GNUNET_CLIENT_receive (sh->client,
- &process_ats_message, sh,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ process_release_message (sh, (const struct SessionReleaseMessage *) msg);
+ GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
+ GNUNET_TIME_UNIT_FOREVER_REL);
if (GNUNET_YES == sh->reconnect)
force_reconnect (sh);
return;
}
- if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
- (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) )
+ if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
+ (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)))
{
GNUNET_break (0);
force_reconnect (sh);
return;
}
- m = (const struct AddressSuggestionMessage*) msg;
+ m = (const struct AddressSuggestionMessage *) msg;
ats_count = ntohl (m->ats_count);
address_length = ntohs (m->address_length);
- atsi = (const struct GNUNET_ATS_Information*) &m[1];
- address = (const char*) &atsi[ats_count];
+ atsi = (const struct GNUNET_ATS_Information *) &m[1];
+ address = (const char *) &atsi[ats_count];
plugin_name = &address[address_length];
plugin_name_length = ntohs (m->plugin_name_length);
- if ( (address_length +
- plugin_name_length +
- ats_count * sizeof (struct GNUNET_ATS_Information) +
- sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) ||
- (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ||
- (plugin_name[plugin_name_length - 1] != '\0') )
+ if ((address_length + plugin_name_length +
+ ats_count * sizeof (struct GNUNET_ATS_Information) +
+ sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) ||
+ (ats_count >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
+ || (plugin_name[plugin_name_length - 1] != '\0'))
{
GNUNET_break (0);
force_reconnect (sh);
return;
}
- sh->suggest_cb (sh->suggest_cb_cls,
- &m->peer,
- plugin_name,
- address, address_length,
- find_session (sh, ntohl (m->session_id), &m->peer),
- m->bandwidth_out,
- m->bandwidth_in,
- atsi,
- ats_count);
- GNUNET_CLIENT_receive (sh->client,
- &process_ats_message, sh,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ sh->suggest_cb (sh->suggest_cb_cls, &m->peer, plugin_name, address,
+ address_length, find_session (sh, ntohl (m->session_id),
+ &m->peer), m->bandwidth_out,
+ m->bandwidth_in, atsi, ats_count);
+ GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
+ GNUNET_TIME_UNIT_FOREVER_REL);
if (GNUNET_YES == sh->reconnect)
force_reconnect (sh);
}
GNUNET_assert (NULL == sh->client);
sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg);
GNUNET_assert (NULL != sh->client);
- if ( (NULL == (p = sh->pending_head)) ||
- (GNUNET_YES != p->is_init) )
+ if ((NULL == (p = sh->pending_head)) || (GNUNET_YES != p->is_init))
{
p = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct ClientStartMessage));
+ sizeof (struct ClientStartMessage));
p->size = sizeof (struct ClientStartMessage);
p->is_init = GNUNET_YES;
init = (struct ClientStartMessage *) &p[1];
init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
init->header.size = htons (sizeof (struct ClientStartMessage));
init->start_flag = htonl (START_FLAG_SCHEDULING);
- GNUNET_CONTAINER_DLL_insert (sh->pending_head,
- sh->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, p);
}
do_transmit (sh);
}
*/
struct GNUNET_ATS_SchedulingHandle *
GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ATS_AddressSuggestionCallback suggest_cb,
- void *suggest_cb_cls)
+ GNUNET_ATS_AddressSuggestionCallback suggest_cb,
+ void *suggest_cb_cls)
{
struct GNUNET_ATS_SchedulingHandle *sh;
sh->cfg = cfg;
sh->suggest_cb = suggest_cb;
sh->suggest_cb_cls = suggest_cb_cls;
- GNUNET_array_grow (sh->session_array,
- sh->session_array_size,
- 4);
+ GNUNET_array_grow (sh->session_array, sh->session_array_size, 4);
reconnect (sh);
return sh;
}
while (NULL != (p = sh->pending_head))
{
- GNUNET_CONTAINER_DLL_remove (sh->pending_head,
- sh->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
GNUNET_free (p);
}
if (NULL != sh->client)
GNUNET_SCHEDULER_cancel (sh->task);
sh->task = GNUNET_SCHEDULER_NO_TASK;
}
- GNUNET_array_grow (sh->session_array,
- sh->session_array_size,
- 0);
+ GNUNET_array_grow (sh->session_array, sh->session_array_size, 0);
GNUNET_free (sh);
}
struct RequestAddressMessage *m;
p = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct RequestAddressMessage));
+ sizeof (struct RequestAddressMessage));
p->size = sizeof (struct RequestAddressMessage);
p->is_init = GNUNET_NO;
- m = (struct RequestAddressMessage*) &p[1];
+ m = (struct RequestAddressMessage *) &p[1];
m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
m->header.size = htons (sizeof (struct RequestAddressMessage));
m->reserved = htonl (0);
m->peer = *peer;
- GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
- sh->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
do_transmit (sh);
}
void
GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- struct Session *session,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session,
const struct GNUNET_ATS_Information *ats,
uint32_t ats_count)
{
size_t namelen;
size_t msize;
- namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
- msize = sizeof (struct AddressUpdateMessage) + plugin_addr_len +
- ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
- if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) )
+ namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
+ msize =
+ sizeof (struct AddressUpdateMessage) + plugin_addr_len +
+ ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
+ if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (ats_count >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)))
{
GNUNET_break (0);
return;
}
- p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
+ p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
p->size = msize;
p->is_init = GNUNET_NO;
- m = (struct AddressUpdateMessage*) &p[1];
+ m = (struct AddressUpdateMessage *) &p[1];
m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
m->header.size = htons (msize);
m->ats_count = htonl (ats_count);
m->address_length = htons (plugin_addr_len);
m->plugin_name_length = htons (namelen);
m->session_id = htonl (get_session_id (sh, session, peer));
- am = (struct GNUNET_ATS_Information*) &m[1];
+ am = (struct GNUNET_ATS_Information *) &m[1];
memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
pm = (char *) &am[ats_count];
memcpy (pm, plugin_addr, plugin_addr_len);
memcpy (&pm[plugin_addr_len], plugin_name, namelen);
- GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
- sh->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
do_transmit (sh);
}
*/
void
GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct Session *session,
- int in_use)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session,
+ int in_use)
{
struct PendingMessage *p;
struct AddressUseMessage *m;
namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen;
- if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
+ if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
{
GNUNET_break (0);
return;
}
- p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
+ p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
p->size = msize;
p->is_init = GNUNET_NO;
- m = (struct AddressUseMessage*) &p[1];
+ m = (struct AddressUseMessage *) &p[1];
m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
m->header.size = htons (msize);
m->peer = *peer;
- m->in_use = htons(in_use);
+ m->in_use = htons (in_use);
m->address_length = htons (plugin_addr_len);
m->plugin_name_length = htons (namelen);
m->session_id = htonl (get_session_id (sh, session, peer));
pm = (char *) &m[1];
memcpy (pm, plugin_addr, plugin_addr_len);
memcpy (&pm[plugin_addr_len], plugin_name, namelen);
- GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
- sh->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
do_transmit (sh);
}
void
GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct Session *session)
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session)
{
struct PendingMessage *p;
struct AddressDestroyedMessage *m;
size_t msize;
uint32_t session_id;
- namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
- msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len +
- namelen;
- if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
+ namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
+ msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + namelen;
+ if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
{
GNUNET_break (0);
return;
}
- p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
+ p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
p->size = msize;
p->is_init = GNUNET_NO;
- m = (struct AddressDestroyedMessage*) &p[1];
+ m = (struct AddressDestroyedMessage *) &p[1];
m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
m->header.size = htons (msize);
m->reserved = htonl (0);
pm = (char *) &m[1];
memcpy (pm, plugin_addr, plugin_addr_len);
memcpy (&pm[plugin_addr_len], plugin_name, namelen);
- GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
- sh->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
do_transmit (sh);
remove_session (sh, session_id, peer);
}
*/
static void
handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
- const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message;
+ const struct ClientStartMessage *msg =
+ (const struct ClientStartMessage *) message;
enum StartFlag flag;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "ATS_START");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ATS_START");
flag = ntohl (msg->start_flag);
switch (flag)
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
- { &handle_ats_start, NULL,
- GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)},
- { &GAS_handle_request_address, NULL,
- GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)},
- { &GAS_handle_address_update, NULL,
- GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
- { &GAS_handle_address_in_use, NULL,
- GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0},
- { &GAS_handle_address_destroyed, NULL,
- GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
- { &GAS_handle_reservation_request, NULL,
- GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)},
- { &GAS_handle_preference_change, NULL,
- GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
+ {&handle_ats_start, NULL,
+ GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)},
+ {&GAS_handle_request_address, NULL,
+ GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS,
+ sizeof (struct RequestAddressMessage)},
+ {&GAS_handle_address_update, NULL,
+ GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
+ {&GAS_handle_address_in_use, NULL,
+ GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0},
+ {&GAS_handle_address_destroyed, NULL,
+ GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
+ {&GAS_handle_reservation_request, NULL,
+ GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST,
+ sizeof (struct ReservationRequestMessage)},
+ {&GAS_handle_preference_change, NULL,
+ GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
{NULL, NULL, 0, 0}
};
GSA_stats = GNUNET_STATISTICS_create ("ats", cfg);
GAS_performance_init (server);
GAS_scheduling_init (server);
GAS_addresses_init (cfg);
- GNUNET_SERVER_disconnect_notify (server,
- &client_disconnect_handler,
- NULL);
+ GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
NULL);
main (int argc, char *const *argv)
{
return (GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv, "ats",
- GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_run (argc, argv, "ats", GNUNET_SERVICE_OPTION_NONE,
+ &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-ats.c */
uint32_t ats_count;
- const void * addr;
+ const void *addr;
- char * plugin;
+ char *plugin;
- struct GNUNET_ATS_Information * ats;
+ struct GNUNET_ATS_Information *ats;
struct GNUNET_TIME_Relative atsp_latency;
};
-static struct GNUNET_CONTAINER_MultiHashMap * addresses;
+static struct GNUNET_CONTAINER_MultiHashMap *addresses;
static unsigned long long total_quota_in;
* @param value the 'struct ATS_Address'
* @return GNUNET_OK (continue to iterate)
*/
-static int
-update_bw_it (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+update_bw_it (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ATS_Address *aa = value;
GNUNET_assert (active_addr_count > 0);
aa->assigned_bw_in.value__ = htonl (total_quota_in / active_addr_count);
aa->assigned_bw_out.value__ = htonl (total_quota_out / active_addr_count);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New bandwidth for peer %s is %u/%u\n",
- GNUNET_i2s (&aa->peer),
- ntohl (aa->assigned_bw_in.value__),
- ntohl (aa->assigned_bw_out.value__));
- GAS_scheduling_transmit_address_suggestion (&aa->peer,
- aa->plugin,
- aa->addr, aa->addr_len,
- aa->session_id,
- aa->ats, aa->ats_count,
- aa->assigned_bw_out, aa->assigned_bw_in);
- GAS_reservations_set_bandwidth (&aa->peer,
- aa->assigned_bw_in);
- GAS_performance_notify_clients (&aa->peer,
- aa->plugin,
- aa->addr, aa->addr_len,
- aa->ats, aa->ats_count,
- aa->assigned_bw_out, aa->assigned_bw_in);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
+ GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
+ ntohl (aa->assigned_bw_out.value__));
+ GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr,
+ aa->addr_len, aa->session_id,
+ aa->ats, aa->ats_count,
+ aa->assigned_bw_out,
+ aa->assigned_bw_in);
+ GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
+ GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len,
+ aa->ats, aa->ats_count, aa->assigned_bw_out,
+ aa->assigned_bw_in);
return GNUNET_OK;
}
recalculate_assigned_bw ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Recalculating bandwidth for all active connections\n");
- GNUNET_STATISTICS_update (GSA_stats,
- "# bandwidth recalculations performed",
- 1,
- GNUNET_NO);
- GNUNET_STATISTICS_set (GSA_stats,
- "# active addresses",
- active_addr_count,
- GNUNET_NO);
- GNUNET_CONTAINER_multihashmap_iterate (addresses,
- &update_bw_it,
- NULL);
+ "Recalculating bandwidth for all active connections\n");
+ GNUNET_STATISTICS_update (GSA_stats, "# bandwidth recalculations performed",
+ 1, GNUNET_NO);
+ GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count,
+ GNUNET_NO);
+ GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL);
}
int ret;
ret = GNUNET_NO;
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove(addresses,
- &addr->peer.hashPubKey,
- addr));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (addresses,
+ &addr->peer.hashPubKey,
+ addr));
if (GNUNET_YES == addr->active)
{
active_addr_count--;
struct CompareAddressContext
{
- const struct ATS_Address * search;
- struct ATS_Address * result;
+ const struct ATS_Address *search;
+ struct ATS_Address *result;
};
-static int
-compare_address_it (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+compare_address_it (void *cls, const GNUNET_HashCode * key, void *value)
{
- struct CompareAddressContext * cac = cls;
- struct ATS_Address * aa = value;
-
- if ( ( (aa->addr_len != cac->search->addr_len) ||
- (0 != strcmp(aa->plugin, cac->search->plugin)) ||
- (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len)) ) &&
- ( (aa->session_id != cac->search->session_id) ||
- (cac->search->session_id == 0) ))
+ struct CompareAddressContext *cac = cls;
+ struct ATS_Address *aa = value;
+
+ if (((aa->addr_len != cac->search->addr_len) ||
+ (0 != strcmp (aa->plugin, cac->search->plugin)) ||
+ (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len))) &&
+ ((aa->session_id != cac->search->session_id) ||
+ (cac->search->session_id == 0)))
return GNUNET_YES;
cac->result = aa;
return GNUNET_NO;
/**
- * Find an existing equivalent address record.
+ * Find an existing equivalent address record.
* Compares by peer identity and network address OR by session ID
* (one of the two must match).
*
*/
struct ATS_Address *
find_address (const struct GNUNET_PeerIdentity *peer,
- const struct ATS_Address * addr)
+ const struct ATS_Address *addr)
{
struct CompareAddressContext cac;
cac.result = NULL;
cac.search = addr;
- GNUNET_CONTAINER_multihashmap_get_multiple(addresses,
- &peer->hashPubKey,
- compare_address_it,
- &cac);
+ GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ compare_address_it, &cac);
return cac.result;
}
void
GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- uint32_t session_id,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count)
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, uint32_t session_id,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count)
{
- struct ATS_Address * aa;
- struct ATS_Address * old;
+ struct ATS_Address *aa;
+ struct ATS_Address *old;
uint32_t i;
aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
- aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_ATS_Information));
+ aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information));
aa->peer = *peer;
aa->addr_len = plugin_addr_len;
aa->ats_count = atsi_count;
{
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (addresses,
- &peer->hashPubKey,
- aa,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Added new address for peer `%s' %X\n",
- GNUNET_i2s (peer), aa);
+ &peer->hashPubKey, aa,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %X\n",
+ GNUNET_i2s (peer), aa);
old = aa;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Updated existing address for peer `%s' %X \n",
- GNUNET_i2s (peer), old);
+ "Updated existing address for peer `%s' %X \n",
+ GNUNET_i2s (peer), old);
GNUNET_free_non_null (old->ats);
old->session_id = session_id;
old->ats = NULL;
GNUNET_free (aa->plugin);
GNUNET_free (aa);
}
- for (i=0;i<atsi_count;i++)
+ for (i = 0; i < atsi_count; i++)
switch (ntohl (atsi[i].type))
{
case GNUNET_ATS_UTILIZATION_UP:
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Received unsupported ATS type %u\n",
- ntohl (atsi[i].type));
+ "Received unsupported ATS type %u\n", ntohl (atsi[i].type));
GNUNET_break (0);
break;
}
void
GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- uint32_t session_id)
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, uint32_t session_id)
{
struct ATS_Address aa;
struct ATS_Address *res;
aa.peer = *peer;
aa.addr_len = plugin_addr_len;
aa.addr = plugin_addr;
- aa.plugin = (char*) plugin_name;
+ aa.plugin = (char *) plugin_name;
aa.session_id = session_id;
res = find_address (peer, &aa);
if (res == NULL)
{
/* we don't even know this one, can this happen? */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to delete unknown address for peer `%s'\n",
- GNUNET_i2s (peer));
- return;
+ "Asked to delete unknown address for peer `%s'\n",
+ GNUNET_i2s (peer));
+ return;
}
- if ( (aa.session_id == session_id) &&
- (session_id != 0) &&
- (res->addr_len > 0) )
+ if ((aa.session_id == session_id) && (session_id != 0) && (res->addr_len > 0))
{
/* just session died */
res->session_id = 0;
return;
}
/* destroy address entirely (either was only session or was
- not even with a session) */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting address for peer `%s': `%s'\n",
- GNUNET_i2s (peer), plugin_name);
+ * not even with a session) */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting address for peer `%s': `%s'\n",
+ GNUNET_i2s (peer), plugin_name);
if (GNUNET_YES == destroy_address (res))
recalculate_assigned_bw ();
}
/**
* Find a "good" address to use for a peer. If we already have an existing
* address, we stick to it. Otherwise, we pick by lowest distance and then
- * by lowest latency.
- *
+ * by lowest latency.
+ *
* @param cls the 'struct ATS_Address**' where we store the result
* @param key unused
* @param value another 'struct ATS_Address*' to consider using
* @return GNUNET_OK (continue to iterate)
*/
-static int
-find_address_it (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+find_address_it (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ATS_Address **ap = cls;
- struct ATS_Address * aa = (struct ATS_Address *) value;
- struct ATS_Address * ab = *ap;
+ struct ATS_Address *aa = (struct ATS_Address *) value;
+ struct ATS_Address *ab = *ap;
if (NULL == ab)
{
*ap = aa;
return GNUNET_OK;
}
- if ( (ntohl (ab->assigned_bw_in.value__) == 0) &&
- (ntohl (aa->assigned_bw_in.value__) > 0) )
+ if ((ntohl (ab->assigned_bw_in.value__) == 0) &&
+ (ntohl (aa->assigned_bw_in.value__) > 0))
{
/* stick to existing connection */
*ap = aa;
void
GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
{
- struct ATS_Address * aa;
+ struct ATS_Address *aa;
aa = NULL;
- GNUNET_CONTAINER_multihashmap_get_multiple (addresses,
- &peer->hashPubKey,
- &find_address_it,
- &aa);
+ GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ &find_address_it, &aa);
if (aa == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cannot suggest address for peer `%s'\n",
- GNUNET_i2s (peer));
- return;
+ "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
+ return;
}
if (aa->active == GNUNET_NO)
{
else
{
/* just to be sure... */
- GAS_scheduling_transmit_address_suggestion (peer, aa->plugin,
- aa->addr, aa->addr_len,
- aa->session_id,
- aa->ats, aa->ats_count,
- aa->assigned_bw_out, aa->assigned_bw_in);
+ GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
+ aa->addr_len, aa->session_id,
+ aa->ats, aa->ats_count,
+ aa->assigned_bw_out,
+ aa->assigned_bw_in);
}
}
// not with 'addresses' in the future...
void
GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score)
+ enum GNUNET_ATS_PreferenceKind kind,
+ float score)
{
// do nothing for now...
}
GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "core",
- "TOTAL_QUOTA_IN",
- &total_quota_in));
+ GNUNET_CONFIGURATION_get_value_number (cfg, "core",
+ "TOTAL_QUOTA_IN",
+ &total_quota_in));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "core",
- "TOTAL_QUOTA_OUT",
- &total_quota_out));
- addresses = GNUNET_CONTAINER_multihashmap_create(128);
+ GNUNET_CONFIGURATION_get_value_number (cfg, "core",
+ "TOTAL_QUOTA_OUT",
+ &total_quota_out));
+ addresses = GNUNET_CONTAINER_multihashmap_create (128);
}
* @param value the 'struct ATS_Address' to free
* @return GNUNET_OK (continue to iterate)
*/
-static int
-free_address_it (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+free_address_it (void *cls, const GNUNET_HashCode * key, void *value)
{
- struct ATS_Address * aa = value;
+ struct ATS_Address *aa = value;
destroy_address (aa);
return GNUNET_OK;
GAS_addresses_destroy_all ()
{
if (addresses != NULL)
- GNUNET_CONTAINER_multihashmap_iterate(addresses,
- &free_address_it, NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL);
GNUNET_assert (active_addr_count == 0);
}
#define GNUNET_SERVICE_ATS_ADDRESSES_H
#include "gnunet_util_lib.h"
-#include "gnunet_ats_service.h"
+#include "gnunet_ats_service.h"
#include "ats.h"
/**
void
GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- uint32_t session_id,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count);
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, uint32_t session_id,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count);
void
GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- uint32_t session_id);
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, uint32_t session_id);
void
// not with 'addresses' in the future...
void
GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score);
+ enum GNUNET_ATS_PreferenceKind kind,
+ float score);
/* FIXME: add performance request API */
struct ATS_mechanism;
struct ATS_peer;
-typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer **
- peers, int *c_p,
- struct ATS_mechanism
- ** mechanisms,
- int *c_m);
+typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** peers,
+ int *c_p,
+ struct ATS_mechanism **
+ mechanisms, int *c_m);
typedef void (*GNUNET_ATS_ResultCallback) (void);
/**
* Next in doubly-linked list.
*/
- struct PerformanceClient * next;
+ struct PerformanceClient *next;
/**
* Previous in doubly-linked list.
*/
- struct PerformanceClient * prev;
-
+ struct PerformanceClient *prev;
+
/**
* Actual handle to the client.
*/
* Tail of linked list of all clients to this service.
*/
static struct PerformanceClient *pc_tail;
-
+
/**
* Context for sending messages to performance clients.
*/
* @param client server handle
* @return internal handle
*/
-static struct PerformanceClient *
+static struct PerformanceClient *
find_client (struct GNUNET_SERVER_Client *client)
{
- struct PerformanceClient * pc;
+ struct PerformanceClient *pc;
for (pc = pc_head; pc != NULL; pc = pc->next)
if (pc->client == client)
*/
void
GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
- enum StartFlag flag)
+ enum StartFlag flag)
{
- struct PerformanceClient * pc;
+ struct PerformanceClient *pc;
GNUNET_break (NULL == find_client (client));
pc = GNUNET_malloc (sizeof (struct PerformanceClient));
pc->flag = flag;
GNUNET_SERVER_notification_context_add (nc, client);
GNUNET_SERVER_client_keep (client);
- GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc);
+ GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
}
void
GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
{
- struct PerformanceClient * pc;
+ struct PerformanceClient *pc;
pc = find_client (client);
if (NULL == pc)
*/
void
GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+ const char *plugin_name,
+ const void *plugin_addr, size_t plugin_addr_len,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
{
struct PerformanceClient *pc;
struct PeerInformationMessage *msg;
size_t plugin_name_length = strlen (plugin_name) + 1;
- size_t msize = sizeof (struct PeerInformationMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information)
- + plugin_addr_len + plugin_name_length;
+ size_t msize =
+ sizeof (struct PeerInformationMessage) +
+ atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
+ plugin_name_length;
char buf[msize];
struct GNUNET_ATS_Information *atsp;
char *addrp;
GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
- GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information));
- msg = (struct PeerInformationMessage*) buf;
+ GNUNET_assert (atsi_count <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE /
+ sizeof (struct GNUNET_ATS_Information));
+ msg = (struct PeerInformationMessage *) buf;
msg->header.size = htons (msize);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
msg->ats_count = htonl (atsi_count);
msg->plugin_name_length = htons (plugin_name_length);
msg->bandwidth_out = bandwidth_out;
msg->bandwidth_in = bandwidth_in;
- atsp = (struct GNUNET_ATS_Information* ) &msg[1];
+ atsp = (struct GNUNET_ATS_Information *) &msg[1];
memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
- addrp = (char*) &atsp[atsi_count];
+ addrp = (char *) &atsp[atsi_count];
memcpy (addrp, plugin_addr, plugin_addr_len);
strcpy (&addrp[plugin_addr_len], plugin_name);
for (pc = pc_head; pc != NULL; pc = pc->next)
if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
{
- GNUNET_SERVER_notification_context_unicast (nc,
- pc->client,
- &msg->header,
- GNUNET_YES);
+ GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header,
+ GNUNET_YES);
GNUNET_STATISTICS_update (GSA_stats,
- "# performance updates given to clients",
- 1,
- GNUNET_NO);
+ "# performance updates given to clients", 1,
+ GNUNET_NO);
}
}
*/
void
GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
- const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message;
+ const struct ReservationRequestMessage *msg =
+ (const struct ReservationRequestMessage *) message;
struct ReservationResultMessage result;
int32_t amount;
struct GNUNET_TIME_Relative res_delay;
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "RESERVATION_REQUEST");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
+ "RESERVATION_REQUEST");
amount = (int32_t) ntohl (msg->amount);
- res_delay = GAS_reservations_reserve (&msg->peer,
- amount);
+ res_delay = GAS_reservations_reserve (&msg->peer, amount);
if (res_delay.rel_value > 0)
amount = 0;
result.header.size = htons (sizeof (struct ReservationResultMessage));
result.amount = htonl (amount);
result.peer = msg->peer;
result.res_delay = GNUNET_TIME_relative_hton (res_delay);
- GNUNET_STATISTICS_update (GSA_stats,
- "# reservation requests processed",
- 1,
- GNUNET_NO);
- GNUNET_SERVER_notification_context_unicast (nc,
- client,
- &result.header,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSA_stats, "# reservation requests processed", 1,
+ GNUNET_NO);
+ GNUNET_SERVER_notification_context_unicast (nc, client, &result.header,
+ GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
*/
void
GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
- const struct ChangePreferenceMessage * msg;
+ const struct ChangePreferenceMessage *msg;
const struct PreferenceInformation *pi;
uint16_t msize;
uint32_t nump;
uint32_t i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
+ "PREFERENCE_CHANGE");
msize = ntohs (message->size);
if (msize < sizeof (struct ChangePreferenceMessage))
{
}
msg = (const struct ChangePreferenceMessage *) message;
nump = ntohl (msg->num_preferences);
- if (msize != sizeof (struct ChangePreferenceMessage) + nump * sizeof (struct PreferenceInformation))
+ if (msize !=
+ sizeof (struct ChangePreferenceMessage) +
+ nump * sizeof (struct PreferenceInformation))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_STATISTICS_update (GSA_stats,
- "# preference change requests processed",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSA_stats, "# preference change requests processed",
+ 1, GNUNET_NO);
pi = (const struct PreferenceInformation *) &msg[1];
- for (i=0;i<nump;i++)
+ for (i = 0; i < nump; i++)
GAS_addresses_change_preference (&msg->peer,
- (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind),
- pi[i].preference_value);
+ (enum GNUNET_ATS_PreferenceKind)
+ ntohl (pi[i].preference_kind),
+ pi[i].preference_value);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
*/
void
GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
- enum StartFlag flag);
+ enum StartFlag flag);
/**
*/
void
GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
+ const char *plugin_name,
+ const void *plugin_addr, size_t plugin_addr_len,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in);
/**
*/
void
GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_MessageHeader *message);
/**
*/
void
GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_MessageHeader *message);
/**
#include "gnunet-service-ats_reservations.h"
/**
- * Number of seconds that available bandwidth carries over
+ * Number of seconds that available bandwidth carries over
* (can accumulate).
*/
#define MAX_BANDWIDTH_CARRY_S 5
*/
struct GNUNET_TIME_Relative
GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
- int32_t amount)
+ int32_t amount)
{
struct GNUNET_BANDWIDTH_Tracker *tracker;
struct GNUNET_TIME_Relative ret;
- tracker = GNUNET_CONTAINER_multihashmap_get (trackers,
- &peer->hashPubKey);
+ tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey);
if (NULL == tracker)
- return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */
+ return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */
if (amount >= 0)
{
- ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker,
- amount);
+ ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount);
if (ret.rel_value > 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delay to satisfy reservation for %d bytes is %llu ms\n",
- (int) amount,
- (unsigned long long) ret.rel_value);
+ "Delay to satisfy reservation for %d bytes is %llu ms\n",
+ (int) amount, (unsigned long long) ret.rel_value);
return ret;
}
}
(void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reserved %d bytes\n",
- (int) amount);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reserved %d bytes\n", (int) amount);
return GNUNET_TIME_UNIT_ZERO;
}
/**
* Set the amount of bandwidth the other peer could currently transmit
* to us (as far as we know) to the given value.
- *
+ *
* @param peer identity of the peer
* @param bandwidth_in currently available bandwidth from that peer to
* this peer (estimate)
*/
void
GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
{
struct GNUNET_BANDWIDTH_Tracker *tracker;
- tracker = GNUNET_CONTAINER_multihashmap_get (trackers,
- &peer->hashPubKey);
+ tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey);
if (0 == ntohl (bandwidth_in.value__))
{
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (trackers,
- &peer->hashPubKey,
- tracker));
+ GNUNET_CONTAINER_multihashmap_remove (trackers,
+ &peer->hashPubKey,
+ tracker));
GNUNET_free (tracker);
return;
}
if (NULL == tracker)
{
tracker = GNUNET_malloc (sizeof (struct GNUNET_BANDWIDTH_Tracker));
- GNUNET_BANDWIDTH_tracker_init (tracker,
- bandwidth_in,
- MAX_BANDWIDTH_CARRY_S);
- GNUNET_CONTAINER_multihashmap_put (trackers,
- &peer->hashPubKey,
- tracker,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ GNUNET_BANDWIDTH_tracker_init (tracker, bandwidth_in,
+ MAX_BANDWIDTH_CARRY_S);
+ GNUNET_CONTAINER_multihashmap_put (trackers, &peer->hashPubKey, tracker,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
return;
}
- GNUNET_BANDWIDTH_tracker_update_quota (tracker,
- bandwidth_in);
+ GNUNET_BANDWIDTH_tracker_update_quota (tracker, bandwidth_in);
}
void
GAS_reservations_init ()
{
- trackers = GNUNET_CONTAINER_multihashmap_create(128);
+ trackers = GNUNET_CONTAINER_multihashmap_create (128);
}
* @param value the 'struct GNUNET_BANDWIDTH_Tracker' to free
* @return GNUNET_OK (continue to iterate)
*/
-static int
-free_tracker (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+free_tracker (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_BANDWIDTH_Tracker *tracker = value;
/**
* Set the amount of bandwidth the other peer could currently transmit
* to us (as far as we know) to the given value.
- *
+ *
* @param peer identity of the peer
* @param bandwidth_in currently available bandwidth from that peer to
* this peer (estimate)
*/
void
GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in);
/**
*/
struct GNUNET_TIME_Relative
GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
- int32_t amount);
+ int32_t amount);
/**
* Register a new scheduling client.
*
* @param client handle of the new client
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
if (my_client != NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
+ "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
return GNUNET_SYSERR;
}
my_client = client;
* @param bandwidth_in assigned inbound bandwidth
*/
void
-GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- uint32_t session_id,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
+ *peer, const char *plugin_name,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ uint32_t session_id,
+ const struct GNUNET_ATS_Information
+ *atsi, uint32_t atsi_count,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in)
{
struct AddressSuggestionMessage *msg;
size_t plugin_name_length = strlen (plugin_name) + 1;
- size_t msize = sizeof (struct AddressSuggestionMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information)
- + plugin_addr_len + plugin_name_length;
+ size_t msize =
+ sizeof (struct AddressSuggestionMessage) +
+ atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
+ plugin_name_length;
char buf[msize];
struct GNUNET_ATS_Information *atsp;
char *addrp;
if (my_client == NULL)
return;
- GNUNET_STATISTICS_update (GSA_stats,
- "# address suggestions made",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSA_stats, "# address suggestions made", 1,
+ GNUNET_NO);
GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
- GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information));
- msg = (struct AddressSuggestionMessage*) buf;
+ GNUNET_assert (atsi_count <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE /
+ sizeof (struct GNUNET_ATS_Information));
+ msg = (struct AddressSuggestionMessage *) buf;
msg->header.size = htons (msize);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
msg->ats_count = htonl (atsi_count);
msg->session_id = htonl (session_id);
msg->bandwidth_out = bandwidth_out;
msg->bandwidth_in = bandwidth_in;
- atsp = (struct GNUNET_ATS_Information* ) &msg[1];
+ atsp = (struct GNUNET_ATS_Information *) &msg[1];
memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
- addrp = (char*) &atsp[atsi_count];
+ addrp = (char *) &atsp[atsi_count];
memcpy (addrp, plugin_addr, plugin_addr_len);
strcpy (&addrp[plugin_addr_len], plugin_name);
- GNUNET_SERVER_notification_context_unicast (nc,
- my_client,
- &msg->header,
- GNUNET_YES);
+ GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header,
+ GNUNET_YES);
}
*/
void
GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-
+ const struct GNUNET_MessageHeader *message)
{
- const struct RequestAddressMessage * msg = (const struct RequestAddressMessage *) message;
+ const struct RequestAddressMessage *msg =
+ (const struct RequestAddressMessage *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS");
- GNUNET_STATISTICS_update (GSA_stats,
- "# address requests received",
- 1,
- GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
+ "REQUEST_ADDRESS");
+ GNUNET_STATISTICS_update (GSA_stats, "# address requests received", 1,
+ GNUNET_NO);
GNUNET_break (0 == ntohl (msg->reserved));
GAS_addresses_request_address (&msg->peer);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
*/
void
GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
- const struct AddressUpdateMessage * m;
+ const struct AddressUpdateMessage *m;
const struct GNUNET_ATS_Information *atsi;
const char *address;
const char *plugin_name;
uint32_t ats_count;
uint16_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "ADDRESS_UPDATE");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
+ "ADDRESS_UPDATE");
size = ntohs (message->size);
if (size < sizeof (struct AddressUpdateMessage))
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- m = (const struct AddressUpdateMessage*) message;
+ m = (const struct AddressUpdateMessage *) message;
ats_count = ntohl (m->ats_count);
address_length = ntohs (m->address_length);
- plugin_name_length = ntohs (m->plugin_name_length);
- atsi = (const struct GNUNET_ATS_Information*) &m[1];
- address = (const char*) &atsi[ats_count];
+ plugin_name_length = ntohs (m->plugin_name_length);
+ atsi = (const struct GNUNET_ATS_Information *) &m[1];
+ address = (const char *) &atsi[ats_count];
if (plugin_name_length != 0)
plugin_name = &address[address_length];
else
plugin_name = "";
- if ( (address_length +
- plugin_name_length +
- ats_count * sizeof (struct GNUNET_ATS_Information) +
- sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
- (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ||
- (plugin_name[plugin_name_length - 1] != '\0') )
+ if ((address_length + plugin_name_length +
+ ats_count * sizeof (struct GNUNET_ATS_Information) +
+ sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
+ (ats_count >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
+ || (plugin_name[plugin_name_length - 1] != '\0'))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_STATISTICS_update (GSA_stats,
- "# address updates received",
- 1,
- GNUNET_NO);
- GAS_addresses_update (&m->peer,
- plugin_name,
- address,
- address_length,
- ntohl (m->session_id),
- atsi,
- ats_count);
+ GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1,
+ GNUNET_NO);
+ GAS_addresses_update (&m->peer, plugin_name, address, address_length,
+ ntohl (m->session_id), atsi, ats_count);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- const struct AddressUseMessage * m;
+ const struct AddressUseMessage *m;
const char *address;
const char *plugin_name;
uint16_t address_length;
uint16_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
"ADDRESS_IN_USE");
size = ntohs (message->size);
if (size < sizeof (struct AddressUseMessage))
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- m = (const struct AddressUseMessage*) message;
+ m = (const struct AddressUseMessage *) message;
address_length = ntohs (m->address_length);
plugin_name_length = ntohs (m->plugin_name_length);
- address = (const char*) &m[1];
+ address = (const char *) &m[1];
if (plugin_name_length != 0)
plugin_name = &address[address_length];
else
plugin_name = "";
- if ( (address_length +
- plugin_name_length +
- sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
- (plugin_name[plugin_name_length - 1] != '\0') )
+ if ((address_length + plugin_name_length +
+ sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
+ (plugin_name[plugin_name_length - 1] != '\0'))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
*/
void
GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-
+ const struct GNUNET_MessageHeader *message)
{
- const struct AddressDestroyedMessage * m;
+ const struct AddressDestroyedMessage *m;
struct SessionReleaseMessage srm;
const char *address;
const char *plugin_name;
uint16_t plugin_name_length;
uint16_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message of size %u %u\n",
- "ADDRESS_DESTROYED", ntohs (message->size), sizeof (struct AddressDestroyedMessage));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message of size %u %u\n",
+ "ADDRESS_DESTROYED", ntohs (message->size),
+ sizeof (struct AddressDestroyedMessage));
size = ntohs (message->size);
- if ( (size < sizeof (struct AddressDestroyedMessage)) ||
- (client != my_client) )
+ if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- m = (const struct AddressDestroyedMessage*) message;
+ m = (const struct AddressDestroyedMessage *) message;
GNUNET_break (0 == ntohl (m->reserved));
address_length = ntohs (m->address_length);
- plugin_name_length = ntohs (m->plugin_name_length);
- address = (const char*) &m[1];
+ plugin_name_length = ntohs (m->plugin_name_length);
+ address = (const char *) &m[1];
if (plugin_name_length != 0)
plugin_name = &address[address_length];
else
plugin_name = "";
- if ( (address_length +
- plugin_name_length +
- sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
+ if ((address_length + plugin_name_length +
+ sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
- }
- if ( (plugin_name_length != 0) &&
- (plugin_name[plugin_name_length - 1] != '\0') )
+ }
+ if ((plugin_name_length != 0) &&
+ (plugin_name[plugin_name_length - 1] != '\0'))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_STATISTICS_update (GSA_stats,
- "# addresses destroyed",
- 1,
- GNUNET_NO);
- GAS_addresses_destroy (&m->peer,
- plugin_name,
- address,
- address_length,
- ntohl (m->session_id));
+ GNUNET_STATISTICS_update (GSA_stats, "# addresses destroyed", 1, GNUNET_NO);
+ GAS_addresses_destroy (&m->peer, plugin_name, address, address_length,
+ ntohl (m->session_id));
if (0 != ntohl (m->session_id))
{
srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
srm.header.size = ntohs (sizeof (struct SessionReleaseMessage));
srm.session_id = m->session_id;
srm.peer = m->peer;
- GNUNET_SERVER_notification_context_unicast (nc,
- client,
- &srm.header,
- GNUNET_NO);
+ GNUNET_SERVER_notification_context_unicast (nc, client, &srm.header,
+ GNUNET_NO);
}
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
* @param server handle to our server
*/
void
-GAS_scheduling_init (struct GNUNET_SERVER_Handle *server)
+GAS_scheduling_init (struct GNUNET_SERVER_Handle *server)
{
nc = GNUNET_SERVER_notification_context_create (server, 128);
}
* Register a new scheduling client.
*
* @param client handle of the new client
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client);
* @param bandwidth_in assigned inbound bandwidth
*/
void
-GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- uint32_t session_id,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
+GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
+ *peer, const char *plugin_name,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ uint32_t session_id,
+ const struct GNUNET_ATS_Information
+ *atsi, uint32_t atsi_count,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in);
/**
*/
void
GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_MessageHeader *message);
*/
void
GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_MessageHeader *message);
/**
*/
void
GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_MessageHeader *message);
/**
struct GNUNET_ATS_ReservationContext *sh;
-static struct GNUNET_OS_Process * arm_proc;
+static struct GNUNET_OS_Process *arm_proc;
-static struct PeerContext * p;
+static struct PeerContext *p;
static uint32_t bw_in;
struct Address
{
- char * plugin;
+ char *plugin;
size_t plugin_len;
- void * addr;
+ void *addr;
size_t addr_len;
- struct GNUNET_ATS_Information * ats;
+ struct GNUNET_ATS_Information *ats;
int ats_count;
- void *session;
+ void *session;
};
struct PeerContext
{
struct GNUNET_PeerIdentity id;
- struct Address * addr;
+ struct Address *addr;
};
if (consume_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(consume_task);
+ GNUNET_SCHEDULER_cancel (consume_task);
consume_task = GNUNET_SCHEDULER_NO_TASK;
}
if (sh != NULL)
- GNUNET_ATS_reserve_bandwidth_cancel(sh);
+ GNUNET_ATS_reserve_bandwidth_cancel (sh);
if (ats != NULL)
GNUNET_ATS_scheduling_done (ats);
{
if (die_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
}
if (consume_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(consume_task);
+ GNUNET_SCHEDULER_cancel (consume_task);
consume_task = GNUNET_SCHEDULER_NO_TASK;
}
stop_arm ();
}
-void performance_cb (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_out,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_in,
- const struct
- GNUNET_ATS_Information
- * ats,
- uint32_t ats_count)
+void
+performance_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
}
-void reservation_cb (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- int32_t amount,
- struct
- GNUNET_TIME_Relative
- res_delay)
+void
+reservation_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
+ int32_t amount, struct GNUNET_TIME_Relative res_delay)
{
sh = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n",
- amount,
- GNUNET_i2s (peer),
- res_delay.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", amount,
+ GNUNET_i2s (peer), res_delay.rel_value);
}
static void
{
consume_task = GNUNET_SCHEDULER_NO_TASK;
int32_t to_reserve = 500;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
- to_reserve,
- GNUNET_i2s (&p->id));
- sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
+ to_reserve, GNUNET_i2s (&p->id));
+
+ sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb,
+ NULL);
}
static void
-address_suggest_cb (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct Session * session,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_out,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_in,
- const struct
- GNUNET_ATS_Information
- * ats,
+address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ const struct GNUNET_ATS_Information *ats,
uint32_t ats_count)
-
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n",
+ GNUNET_i2s (peer));
bw_in = ntohl (bandwidth_in.value__);
bw_out = ntohl (bandwidth_out.value__);
- consume_task = GNUNET_SCHEDULER_add_now(&consume_bandwidth, NULL);
+ consume_task = GNUNET_SCHEDULER_add_now (&consume_bandwidth, NULL);
}
void
start_arm (const char *cfgname)
{
- arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ arm_proc =
+ GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
}
static void
ret = GNUNET_SYSERR;
struct Address *addr;
- die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
start_arm (cfgfile);
ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
{
ret = GNUNET_SYSERR;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n");
- end_badly(NULL, NULL);
+ end_badly (NULL, NULL);
GNUNET_free (p);
GNUNET_free (addr);
return;
}
/* set up peer */
- GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p->id.hashPubKey);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &p->id.hashPubKey);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
+ GNUNET_i2s (&p->id));
p->addr = addr;
addr->plugin = "test";
addr->session = NULL;
addr->addr = NULL;
addr->addr_len = 0;
- GNUNET_ATS_address_update(ats, &p->id, addr->plugin, addr->addr, addr->addr_len, addr->session, NULL, 0);
+ GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr,
+ addr->addr_len, addr->session, NULL, 0);
- GNUNET_ATS_suggest_address(ats, &p->id);
+ GNUNET_ATS_suggest_address (ats, &p->id);
}
int
};
GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "test_ats_api_bandwidth_consumption", "nohelp", options, &check,
- NULL);
+ "test_ats_api_bandwidth_consumption", "nohelp", options,
+ &check, NULL);
return ret;
static struct GNUNET_ATS_SchedulingHandle *ats;
-struct GNUNET_OS_Process * arm_proc;
+struct GNUNET_OS_Process *arm_proc;
struct Address
{
- char * plugin;
+ char *plugin;
size_t plugin_len;
- void * addr;
+ void *addr;
size_t addr_len;
- struct GNUNET_ATS_Information * ats;
+ struct GNUNET_ATS_Information *ats;
int ats_count;
- void *session;
+ void *session;
};
struct PeerContext
{
struct GNUNET_PeerIdentity id;
- struct Address * addr;
+ struct Address *addr;
};
struct Address addr[2];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
if (die_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
}
static void
-address_suggest_cb (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct Session * session,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_out,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_in,
- const struct
- GNUNET_ATS_Information
- * ats,
+address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ const struct GNUNET_ATS_Information *ats,
uint32_t ats_count)
-
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n",
+ GNUNET_i2s (peer));
- GNUNET_assert (0 == memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_assert (0 ==
+ memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity)));
GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin));
GNUNET_assert (plugin_addr_len == addr[0].addr_len);
GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len));
/* TODO ats merge
- GNUNET_assert (ats_count == 2);
- GNUNET_assert (atsi[0].type == htons (1));
- GNUNET_assert (atsi[0].type == htons (2));
- GNUNET_assert (atsi[1].type == htons (2));
- GNUNET_assert (atsi[1].type == htons (2));
- */
+ * GNUNET_assert (ats_count == 2);
+ * GNUNET_assert (atsi[0].type == htons (1));
+ * GNUNET_assert (atsi[0].type == htons (2));
+ * GNUNET_assert (atsi[1].type == htons (2));
+ * GNUNET_assert (atsi[1].type == htons (2));
+ */
ret = 0;
- GNUNET_SCHEDULER_add_now(&end, NULL);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
void
start_arm (const char *cfgname)
{
- arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ arm_proc =
+ GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
}
static void
{
ret = GNUNET_SYSERR;
- die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
start_arm (cfgfile);
ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
}
/* set up peer */
- GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[0].id.hashPubKey);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[0].id));
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &p[0].id.hashPubKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
+ GNUNET_i2s (&p[0].id));
- GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[1].id.hashPubKey);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[1].id));
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &p[1].id.hashPubKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
+ GNUNET_i2s (&p[1].id));
addr[0].plugin = "test";
addr[0].session = NULL;
- addr[0].addr = strdup("test");
+ addr[0].addr = strdup ("test");
addr[0].addr_len = 4;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n");
- GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0);
+ GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
+ addr[0].addr_len, addr[0].session, NULL, 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n");
atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP);
atsi[0].value = htonl (1024);
- GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 1);
+ GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
+ addr[0].addr_len, addr[0].session, atsi, 1);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n");
atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN);
atsi[1].value = htonl (1024);
- GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 2);
+ GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
+ addr[0].addr_len, addr[0].session, atsi, 2);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n");
- GNUNET_ATS_address_update(ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0);
- GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session );
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p[0].id));
- GNUNET_ATS_suggest_address(ats, &p[0].id);
+ GNUNET_ATS_address_update (ats, &p[1].id, addr[0].plugin, addr[0].addr,
+ addr[0].addr_len, addr[0].session, NULL, 0);
+ GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr,
+ addr[0].addr_len, addr[0].session);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n",
+ GNUNET_i2s (&p[0].id));
+ GNUNET_ATS_suggest_address (ats, &p[0].id);
}
int
const char *plugin_name, const void *plugin_addr,
size_t plugin_addr_len, struct Session *session,
struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
struct ExpectedValues *ex = cls;
* @param lib_ret the plugin API
*/
static void
-add_plugin (void *cls,
- const char *library_name,
- void *lib_ret)
+add_plugin (void *cls, const char *library_name, void *lib_ret)
{
struct GNUNET_BLOCK_Context *ctx = cls;
struct GNUNET_BLOCK_PluginFunctions *api = lib_ret;
struct Plugin *plugin;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading block plugin `%s'\n"),
- library_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading block plugin `%s'\n"),
+ library_name);
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->api = api;
plugin->library_name = GNUNET_strdup (library_name);
ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context));
ctx->cfg = cfg;
- GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_",
- NULL,
- &add_plugin,
- ctx);
+ GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", NULL, &add_plugin, ctx);
return ctx;
}
unsigned int i;
struct Plugin *plugin;
- for (i = 0; i<ctx->num_plugins;i++)
+ for (i = 0; i < ctx->num_plugins; i++)
{
plugin = ctx->plugins[i];
GNUNET_break (NULL ==
unsigned int i;
unsigned int j;
- for (i=0;i<ctx->num_plugins;i++)
+ for (i = 0; i < ctx->num_plugins; i++)
{
plugin = ctx->plugins[i];
j = 0;
*/
struct GNUNET_CONTAINER_BloomFilter *
GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator,
- const GNUNET_HashCode *seen_results,
- unsigned int seen_results_count)
+ const GNUNET_HashCode * seen_results,
+ unsigned int seen_results_count)
{
struct GNUNET_CONTAINER_BloomFilter *bf;
GNUNET_HashCode mhash;
size_t nsize;
nsize = compute_bloomfilter_size (seen_results_count);
- bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, GNUNET_CONSTANTS_BLOOMFILTER_K);
+ bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
for (i = 0; i < seen_results_count; i++)
{
GNUNET_BLOCK_mingle_hash (&seen_results[i], bf_mutator, &mhash);
if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
if (NULL != bf)
+ {
+ GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash);
+ if (NULL != *bf)
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
+ else
{
- GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash);
- if (NULL != *bf)
- {
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
- return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
- }
- else
- {
- *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K);
- }
- GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ *bf =
+ GNUNET_CONTAINER_bloomfilter_init (NULL, 8,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
}
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ }
return GNUNET_BLOCK_EVALUATION_OK_MORE;
}
}
if (GNUNET_TIME_relative_get_zero ().rel_value ==
- GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (rec->expiration_time)).rel_value)
+ GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh
+ (rec->expiration_time)).rel_value)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
if (reply_block == NULL)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
if (NULL != bf)
+ {
+ GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
+ GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
+ if (NULL != *bf)
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
+ else
{
- GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
- GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
- if (NULL != *bf)
- {
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
- return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
- }
- else
- {
- *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
- }
- GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
}
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ }
return GNUNET_BLOCK_EVALUATION_OK_MORE;
case GNUNET_BLOCK_TYPE_FS_SBLOCK:
if (xquery_size != sizeof (GNUNET_HashCode))
return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
}
if (NULL != bf)
+ {
+ GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
+ GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
+ if (NULL != *bf)
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
+ else
{
- GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
- GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
- if (NULL != *bf)
- {
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
- return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
- }
- else
- {
- *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
- }
- GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
}
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ }
return GNUNET_BLOCK_EVALUATION_OK_MORE;
default:
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
if (NULL != *bf)
- {
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
- return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
- }
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
else
- {
- *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
- }
+ {
+ *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
+ }
GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
}
return GNUNET_BLOCK_EVALUATION_OK_MORE;
handle_p2p_join_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
const struct P2PJoinNotificationMessage *p2p_jnmsg;
char *room_name;
handle_p2p_leave_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
const struct P2PLeaveNotificationMessage *p2p_lnmsg;
GNUNET_HashCode id;
handle_p2p_message_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
const struct P2PReceiveNotificationMessage *p2p_rnmsg;
struct P2PReceiveNotificationMessage *my_p2p_rnmsg;
handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct ChatClient *entry;
struct GNUNET_CORE_TransmitHandle *th;
handle_p2p_confirmation_receipt (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
const struct P2PConfirmationReceiptMessage *p2p_crmsg;
struct P2PConfirmationReceiptMessage *my_p2p_crmsg;
static void
peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct ConnectedPeer *cp;
struct GNUNET_CORE_TransmitHandle *th;
core =
GNUNET_CORE_connect (cfg, QUEUE_SIZE, NULL, &core_init,
&peer_connect_handler, &peer_disconnect_handler,
- NULL, GNUNET_NO, NULL, GNUNET_NO,
- p2p_handlers);
+ NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
NULL);
const struct GNUNET_MessageHeader *em;
const struct SendMessageReady *smr;
const struct GNUNET_CORE_MessageHandler *mh;
- const struct GNUNET_ATS_Information* ats;
+ const struct GNUNET_ATS_Information *ats;
GNUNET_CORE_StartupCallback init;
struct PeerRecord *pr;
struct GNUNET_CORE_TransmitHandle *th;
cnm = (const struct ConnectNotifyMessage *) msg;
ats_count = ntohl (cnm->ats_count);
if (msize !=
- sizeof (struct ConnectNotifyMessage) +
- ats_count * sizeof (struct GNUNET_ATS_Information))
+ sizeof (struct ConnectNotifyMessage) +
+ ats_count * sizeof (struct GNUNET_ATS_Information))
{
GNUNET_break (0);
reconnect_later (h);
GNUNET_CONTAINER_multihashmap_put (h->peers,
&cnm->peer.hashPubKey, pr,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- ats = (const struct GNUNET_ATS_Information*) &cnm[1];
+ ats = (const struct GNUNET_ATS_Information *) &cnm[1];
if (NULL != h->connects)
- h->connects (h->cls, &cnm->peer,
- ats,
- ats_count);
+ h->connects (h->cls, &cnm->peer, ats, ats_count);
break;
case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
if (msize != sizeof (struct DisconnectNotifyMessage))
sizeof (struct NotifyTrafficMessage) +
ats_count * sizeof (struct GNUNET_ATS_Information) +
sizeof (struct GNUNET_MessageHeader)) ||
- (GNUNET_ATS_ARRAY_TERMINATOR !=
- ntohl ((&ntm->ats)[ats_count].type)))
+ (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
{
GNUNET_break (0);
reconnect_later (h);
continue;
if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected message size for message of type %u\n",
- mh->type);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected message size for message of type %u\n",
+ mh->type);
GNUNET_break_op (0);
continue;
}
if (GNUNET_OK !=
h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats,
- ats_count))
+ ats_count))
{
/* error in processing, do not process other messages! */
break;
}
}
if (NULL != h->inbound_notify)
- h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats,
- ats_count);
+ h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
break;
case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
if (msize < sizeof (struct NotifyTrafficMessage))
sizeof (struct NotifyTrafficMessage) +
ats_count * sizeof (struct GNUNET_ATS_Information) +
sizeof (struct GNUNET_MessageHeader)) ||
- (GNUNET_ATS_ARRAY_TERMINATOR !=
- ntohl ((&ntm->ats)[ats_count].type)))
+ (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
{
GNUNET_break (0);
reconnect_later (h);
ats_count = ntohl (connect_message->ats_count);
if (msize !=
sizeof (struct ConnectNotifyMessage) +
- ats_count * sizeof (struct GNUNET_ATS_Information))
+ ats_count * sizeof (struct GNUNET_ATS_Information))
{
GNUNET_break (0);
if (request_context->peer_cb != NULL)
/* Normal case */
if (request_context->peer_cb != NULL)
request_context->peer_cb (request_context->cb_cls, &connect_message->peer,
- (const struct GNUNET_ATS_Information *) &connect_message[1],
- ats_count);
+ (const struct GNUNET_ATS_Information *)
+ &connect_message[1], ats_count);
GNUNET_CLIENT_receive (request_context->client, &receive_info,
request_context, GNUNET_TIME_UNIT_FOREVER_REL);
}
static void
connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct PrintContext *pc;
cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core service shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n");
#endif
GSC_CLIENTS_done ();
GSC_NEIGHBOURS_done ();
run (void *cls, struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- GSC_cfg = c;
+ GSC_cfg = c;
GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
NULL);
GSC_TYPEMAP_init ();
- if ( (GNUNET_OK != GSC_KX_init ()) ||
- (GNUNET_OK != GSC_NEIGHBOURS_init ()) )
+ if ((GNUNET_OK != GSC_KX_init ()) || (GNUNET_OK != GSC_NEIGHBOURS_init ()))
{
GNUNET_SCHEDULER_shutdown ();
return;
/**
* Record kept for each request for transmission issued by a
- * client that is still pending. (This struct is used by
+ * client that is still pending. (This struct is used by
* both the 'CLIENTS' and 'SESSIONS' subsystems.)
*/
struct GSC_ClientActiveRequest
* client's queue is getting too large?
*/
static void
-send_to_client (struct GSC_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int can_drop)
+send_to_client (struct GSC_Client *client,
+ const struct GNUNET_MessageHeader *msg, int can_drop)
{
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
*/
void
GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int can_drop)
+ const struct GNUNET_MessageHeader *msg,
+ int can_drop)
{
struct GSC_Client *c;
* @return GNUNET_YES if 'c' is interested, GNUNET_NO if not.
*/
static int
-type_match (uint16_t type,
- struct GSC_Client *c)
+type_match (uint16_t type, struct GSC_Client *c)
{
unsigned int i;
if (c->tcnt == 0)
- return GNUNET_YES; /* peer without handlers matches ALL */
- for (i=0;i<c->tcnt;i++)
+ return GNUNET_YES; /* peer without handlers matches ALL */
+ for (i = 0; i < c->tcnt; i++)
if (type == c->types[i])
return GNUNET_YES;
return GNUNET_NO;
*/
static void
send_to_all_clients (const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *msg,
- int can_drop,
- int options,
- uint16_t type)
+ const struct GNUNET_MessageHeader *msg, int can_drop,
+ int options, uint16_t type)
{
struct GSC_Client *c;
for (c = client_head; c != NULL; c = c->next)
{
- if ( (0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
- (GNUNET_YES == type_match (type, c)) )
- continue; /* not the full message, but we'd like the full one! */
- if ( (0 == (c->options & options)) &&
- (GNUNET_YES != type_match (type, c)) )
- continue; /* neither options nor type match permit the message */
+ if ((0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
+ (GNUNET_YES == type_match (type, c)))
+ continue; /* not the full message, but we'd like the full one! */
+ if ((0 == (c->options & options)) && (GNUNET_YES != type_match (type, c)))
+ continue; /* neither options nor type match permit the message */
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message to client interested in messages of type %u.\n",
- (unsigned int) type);
+ "Sending message to client interested in messages of type %u.\n",
+ (unsigned int) type);
#endif
#if DEBUG_CONNECTS
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
- &sender->hashPubKey));
+ GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
+ &sender->hashPubKey));
#endif
send_to_client (c, msg, can_drop);
}
#if DEBUG_CONNECTS
c->connectmap = GNUNET_CONTAINER_multihashmap_create (16);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (c->connectmap,
- &GSC_my_identity.hashPubKey,
- NULL,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (c->connectmap,
+ &GSC_my_identity.hashPubKey,
+ NULL,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
#endif
wtypes = (uint16_t *) & c[1];
for (i = 0; i < c->tcnt; i++)
wtypes[i] = ntohs (types[i]);
GSC_TYPEMAP_add (wtypes, c->tcnt);
- GNUNET_CONTAINER_DLL_insert (client_head,
- client_tail,
- c);
+ GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client connecting to core service is interested in %u message types\n",
+ "Client connecting to core service is interested in %u message types\n",
(unsigned int) c->tcnt);
#endif
/* send init reply message */
c->requests = GNUNET_CONTAINER_multihashmap_create (16);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client asked for transmission to `%s'\n",
- GNUNET_i2s (&req->peer));
+ "Client asked for transmission to `%s'\n",
+ GNUNET_i2s (&req->peer));
#endif
car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey);
if (car == NULL)
car->smr_id = req->smr_id;
car->was_solicited = GNUNET_NO;
if (0 ==
- memcmp (&req->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ memcmp (&req->peer, &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
GSC_CLIENTS_solicit_request (car);
else
GSC_SESSIONS_queue_request (car);
/**
* Active request handle for the message.
- */
+ */
struct GSC_ClientActiveRequest *car;
/**
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- tc.car = GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey);
+ tc.car =
+ GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey);
if (NULL == tc.car)
{
/* Must have been that we first approved the request, then got disconnected
- (which triggered removal of the 'car') and now the client gives us a message
- just *before* the client learns about the disconnect. Theoretically, we
- might also now be *again* connected. So this can happen (but should be
- rare). If it does happen, the message is discarded. */
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# messages discarded (session disconnected)"),
- 1,
- GNUNET_NO);
+ * (which triggered removal of the 'car') and now the client gives us a message
+ * just *before* the client learns about the disconnect. Theoretically, we
+ * might also now be *again* connected. So this can happen (but should be
+ * rare). If it does happen, the message is discarded. */
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop
+ ("# messages discarded (session disconnected)"),
+ 1, GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (c->requests,
- &sm->peer.hashPubKey,
- tc.car));
+ GNUNET_CONTAINER_multihashmap_remove (c->requests,
+ &sm->peer.hashPubKey,
+ tc.car));
tc.cork = ntohl (sm->cork);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client asked for transmission of %u bytes to `%s' %s\n",
- msize,
- GNUNET_i2s (&sm->peer),
- tc.cork ? "now" : "");
+ "Client asked for transmission of %u bytes to `%s' %s\n", msize,
+ GNUNET_i2s (&sm->peer), tc.cork ? "now" : "");
#endif
- GNUNET_SERVER_mst_receive (client_mst,
- &tc,
- (const char*) &sm[1], msize,
- GNUNET_YES,
- GNUNET_NO);
+ GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize,
+ GNUNET_YES, GNUNET_NO);
if (0 !=
- memcmp (&tc.car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ memcmp (&tc.car->target, &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
GSC_SESSIONS_dequeue_request (tc.car);
- GNUNET_free (tc.car);
+ GNUNET_free (tc.car);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
*/
static void
client_tokenizer_callback (void *cls, void *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
struct TokenizerContext *tc = client;
struct GSC_ClientActiveRequest *car = tc->car;
if (0 ==
- memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ memcmp (&car->target, &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
{
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delivering message of type %u to myself\n",
- ntohs (message->type));
+ "Delivering message of type %u to myself\n",
+ ntohs (message->type));
#endif
- GSC_CLIENTS_deliver_message (&GSC_my_identity,
- NULL, 0,
- message,
- ntohs (message->size),
- GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
- GSC_CLIENTS_deliver_message (&GSC_my_identity,
- NULL, 0,
- message,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_CORE_OPTION_SEND_HDR_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
+ GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
+ ntohs (message->size),
+ GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
+ GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
+ GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_CORE_OPTION_SEND_HDR_INBOUND |
+ GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
}
else
{
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delivering message of type %u to %s\n",
- ntohs (message->type),
- GNUNET_i2s (&car->target));
+ "Delivering message of type %u to %s\n", ntohs (message->type),
+ GNUNET_i2s (&car->target));
#endif
GSC_SESSIONS_transmit (car, message, tc->cork);
}
struct GSC_ClientActiveRequest *car = value;
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests,
- &car->target.hashPubKey,
- car));
+ GNUNET_CONTAINER_multihashmap_remove (car->
+ client_handle->requests,
+ &car->target.hashPubKey,
+ car));
GSC_SESSIONS_dequeue_request (car);
GNUNET_free (car);
return GNUNET_YES;
* @param client identification of the client
*/
static void
-handle_client_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client)
+handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct GSC_Client *c;
#endif
c = find_client (client);
if (c == NULL)
- return; /* client never sent INIT */
- GNUNET_CONTAINER_DLL_remove (client_head,
- client_tail,
- c);
+ return; /* client never sent INIT */
+ GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c);
if (c->requests != NULL)
{
GNUNET_CONTAINER_multihashmap_iterate (c->requests,
smr.peer = car->target;
#if DEBUG_CONNECTS
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
- &car->target.hashPubKey));
+ GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
+ &car->
+ target.hashPubKey));
#endif
send_to_client (c, &smr.header, GNUNET_NO);
}
GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
{
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests,
- &car->target.hashPubKey,
- car));
+ GNUNET_CONTAINER_multihashmap_remove (car->
+ client_handle->requests,
+ &car->target.hashPubKey,
+ car));
GNUNET_free (car);
}
*/
void
GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
- const struct GNUNET_PeerIdentity *neighbour,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap *tmap_new)
+ const struct GNUNET_PeerIdentity
+ *neighbour,
+ const struct GNUNET_ATS_Information
+ *atsi, unsigned int atsi_count,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new)
{
struct ConnectNotifyMessage *cnm;
size_t size;
if (old_match == new_match)
{
GNUNET_assert (old_match ==
- GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
- &neighbour->hashPubKey));
- return; /* no change */
+ GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
+ &neighbour->hashPubKey));
+ return; /* no change */
}
if (old_match == GNUNET_NO)
{
- /* send connect */
+ /* send connect */
#if DEBUG_CONNECTS
GNUNET_assert (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
- &neighbour->hashPubKey));
+ GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
+ &neighbour->hashPubKey));
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (client->connectmap,
- &neighbour->hashPubKey,
- NULL,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (client->connectmap,
+ &neighbour->hashPubKey,
+ NULL,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
#endif
size =
- sizeof (struct ConnectNotifyMessage) +
- (atsi_count) * sizeof (struct GNUNET_ATS_Information);
+ sizeof (struct ConnectNotifyMessage) +
+ (atsi_count) * sizeof (struct GNUNET_ATS_Information);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- atsi_count = 0;
- size = sizeof (struct ConnectNotifyMessage);
- }
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw away performance data */
+ atsi_count = 0;
+ size = sizeof (struct ConnectNotifyMessage);
+ }
cnm = (struct ConnectNotifyMessage *) buf;
cnm->header.size = htons (size);
cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
cnm->ats_count = htonl (atsi_count);
- a = (struct GNUNET_ATS_Information* ) &cnm[1];
- memcpy (a, atsi,
- sizeof (struct GNUNET_ATS_Information) * atsi_count);
+ a = (struct GNUNET_ATS_Information *) &cnm[1];
+ memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message to client.\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
"NOTIFY_CONNECT");
#endif
cnm->peer = *neighbour;
/* send disconnect */
#if DEBUG_CONNECTS
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
- &neighbour->hashPubKey));
+ GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
+ &neighbour->hashPubKey));
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (client->connectmap,
- &neighbour->hashPubKey,
- NULL));
+ GNUNET_CONTAINER_multihashmap_remove (client->connectmap,
+ &neighbour->hashPubKey,
+ NULL));
#endif
dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
* @param tmap_new updated type map for the neighbour, NULL for disconnect
*/
void
-GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap *tmap_new)
+GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
+ *neighbour,
+ const struct GNUNET_ATS_Information
+ *atsi, unsigned int atsi_count,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new)
{
struct GSC_Client *c;
for (c = client_head; c != NULL; c = c->next)
- GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi,
- atsi_count,
- tmap_old, tmap_new);
+ GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, atsi_count,
+ tmap_old, tmap_new);
}
/**
* Deliver P2P message to interested clients. Caller must have checked
- * that the sending peer actually lists the given message type as one
+ * that the sending peer actually lists the given message type as one
* of its types.
*
- * @param sender peer who sent us the message
+ * @param sender peer who sent us the message
* @param atsi performance information about neighbour
* @param atsi_count number of entries in 'ats' array
* @param msg the message
*/
void
GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count,
- const struct GNUNET_MessageHeader *msg,
- uint16_t msize,
- int options)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count,
+ const struct GNUNET_MessageHeader *msg,
+ uint16_t msize, int options)
{
- size_t size = msize + sizeof (struct NotifyTrafficMessage) +
+ size_t size =
+ msize + sizeof (struct NotifyTrafficMessage) +
atsi_count * sizeof (struct GNUNET_ATS_Information);
char buf[size];
struct NotifyTrafficMessage *ntm;
if (0 == options)
{
GNUNET_snprintf (buf, sizeof (buf),
- gettext_noop ("# bytes of messages of type %u received"),
- (unsigned int) ntohs (msg->type));
+ gettext_noop ("# bytes of messages of type %u received"),
+ (unsigned int) ntohs (msg->type));
GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO);
}
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service passes message from `%4s' of type %u to client.\n",
- GNUNET_i2s (sender),
- (unsigned int) ntohs (msg->type));
+ GNUNET_i2s (sender), (unsigned int) ntohs (msg->type));
#endif
GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
ntm = (struct NotifyTrafficMessage *) buf;
ntm->ats_count = htonl (atsi_count);
ntm->peer = *sender;
a = &ntm->ats;
- memcpy (a, atsi,
- sizeof (struct GNUNET_ATS_Information) * atsi_count);
+ memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
a[atsi_count].value = htonl (0);
memcpy (&a[atsi_count + 1], msg, msize);
- send_to_all_clients (sender,
- &ntm->header, GNUNET_YES,
- options, ntohs (msg->type));
+ send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
+ ntohs (msg->type));
}
{
struct GSC_Client *c;
- while (NULL != (c = client_head))
+ while (NULL != (c = client_head))
handle_client_disconnect (NULL, c->client_handle);
if (NULL != notifier)
{
*/
void
GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int can_drop);
+ const struct GNUNET_MessageHeader *msg,
+ int can_drop);
/**
*/
void
GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
- const struct GNUNET_PeerIdentity *neighbour,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap *tmap_new);
+ const struct GNUNET_PeerIdentity
+ *neighbour,
+ const struct GNUNET_ATS_Information
+ *atsi, unsigned int atsi_count,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new);
/**
* @param tmap_new updated type map for the neighbour, NULL for disconnect
*/
void
-GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap *tmap_new);
+GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
+ *neighbour,
+ const struct GNUNET_ATS_Information
+ *atsi, unsigned int atsi_count,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new);
/**
* Deliver P2P message to interested clients. Caller must have checked
- * that the sending peer actually lists the given message type as one
+ * that the sending peer actually lists the given message type as one
* of its types.
*
- * @param sender peer who sent us the message
+ * @param sender peer who sent us the message
* @param atsi performance information about neighbour
* @param atsi_count number of entries in 'ats' array
* @param msg the message
*/
void
GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count,
- const struct GNUNET_MessageHeader *msg,
- uint16_t msize,
- int options);
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count,
+ const struct GNUNET_MessageHeader *msg,
+ uint16_t msize, int options);
/**
* first field after header (this is where we start to encrypt!).
*/
uint32_t challenge GNUNET_PACKED;
-
+
/**
* Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'.
*/
"Encrypted %u bytes for `%4s' using key %u, IV %u\n",
(unsigned int) size, GNUNET_i2s (&kx->peer),
(unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
- sizeof
- (iv)));
+ sizeof
+ (iv)));
#endif
return GNUNET_OK;
}
GNUNET_break (0);
return GNUNET_NO;
}
- if ((kx->status != KX_STATE_KEY_RECEIVED) &&
- (kx->status != KX_STATE_UP))
+ if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
if (size !=
- GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv, out))
+ GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv,
+ out))
{
GNUNET_break (0);
return GNUNET_SYSERR;
"Decrypted %u bytes from `%4s' using key %u, IV %u\n",
(unsigned int) size, GNUNET_i2s (&kx->peer),
(unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
- sizeof
- (*iv)));
+ sizeof
+ (*iv)));
#endif
return GNUNET_OK;
}
struct GSC_KeyExchangeInfo *kx = cls;
kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
- kx->set_key_retry_frequency = GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2);
+ kx->set_key_retry_frequency =
+ GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2);
send_key (kx);
}
*/
static void
process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Message *hello,
- const char *err_msg)
+ const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
struct GSC_KeyExchangeInfo *kx = cls;
struct SetKeyMessage *skm;
{
kx->pitr = NULL;
if (kx->public_key != NULL)
- return; /* done here */
+ return; /* done here */
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n",
- GNUNET_i2s (&kx->peer));
+ "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n",
+ GNUNET_i2s (&kx->peer));
#endif
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop
- ("# Delayed connecting due to lack of public key"),
- 1, GNUNET_NO);
+ gettext_noop
+ ("# Delayed connecting due to lack of public key"),
+ 1, GNUNET_NO);
kx->retry_set_key_task =
- GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
- &set_key_retry_task, kx);
+ GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
+ &set_key_retry_task, kx);
return;
}
if (kx->public_key != NULL)
struct GSC_KeyExchangeInfo *kx;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Initiating key exchange with `%s'\n",
- GNUNET_i2s (pid));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating key exchange with `%s'\n",
+ GNUNET_i2s (pid));
#endif
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# key exchanges initiated"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# key exchanges initiated"), 1,
+ GNUNET_NO);
kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo));
kx->peer = *pid;
kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
- kx->pitr = GNUNET_PEERINFO_iterate (peerinfo,
- pid,
- GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */,
- &process_hello,
- kx);
+ kx->pitr =
+ GNUNET_PEERINFO_iterate (peerinfo, pid,
+ GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
+ &process_hello, kx);
return kx;
}
void
GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
{
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# key exchanges stopped"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"),
+ 1, GNUNET_NO);
if (kx->pitr != NULL)
{
GNUNET_PEERINFO_iterate_cancel (kx->pitr);
*/
void
GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
const struct SetKeyMessage *m;
struct GNUNET_TIME_Absolute t;
struct PongMessage *pong;
enum KxStateMachine sender_status;
uint16_t size;
-
+
size = ntohs (msg->size);
if (size != sizeof (struct SetKeyMessage))
- {
- GNUNET_break_op (0);
- return;
- }
- m = (const struct SetKeyMessage*) msg;
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ m = (const struct SetKeyMessage *) msg;
GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"),
- 1, GNUNET_NO);
+ 1, GNUNET_NO);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
if (kx->public_key == NULL)
{
GNUNET_free_non_null (kx->skm_received);
- kx->skm_received = (struct SetKeyMessage*) GNUNET_copy_message (msg);
+ kx->skm_received = (struct SetKeyMessage *) GNUNET_copy_message (msg);
return;
}
if (0 !=
- memcmp (&m->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
+ memcmp (&m->target, &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("`%s' is for `%s', not for me. Ignoring.\n"),
- "SET_KEY", GNUNET_i2s (&m->target));
+ _("`%s' is for `%s', not for me. Ignoring.\n"), "SET_KEY",
+ GNUNET_i2s (&m->target));
return;
}
if ((ntohl (m->purpose.size) !=
return;
}
t = GNUNET_TIME_absolute_ntoh (m->creation_time);
- if (((kx->status == KX_STATE_KEY_RECEIVED) ||
- (kx->status == KX_STATE_UP)) &&
+ if (((kx->status == KX_STATE_KEY_RECEIVED) || (kx->status == KX_STATE_UP)) &&
(t.abs_value < kx->decrypt_key_created.abs_value))
{
/* this could rarely happen due to massive re-ordering of
gettext_noop ("# SET_KEY messages decrypted"), 1,
GNUNET_NO);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received SET_KEY from `%s'\n",
- GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_KEY from `%s'\n",
+ GNUNET_i2s (&kx->peer));
#endif
kx->decrypt_key = k;
if (kx->decrypt_key_created.abs_value != t.abs_value)
/* we're not up, so we are already doing 'send_key' */
break;
case KX_STATE_UP:
- if ( (sender_status == KX_STATE_DOWN) ||
- (sender_status == KX_STATE_KEY_SENT) )
- send_key (kx); /* we are up, but other peer is not! */
+ if ((sender_status == KX_STATE_DOWN) ||
+ (sender_status == KX_STATE_KEY_SENT))
+ send_key (kx); /* we are up, but other peer is not! */
break;
default:
GNUNET_break (0);
*/
void
GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
const struct PingMessage *m;
struct PingMessage t;
msize = ntohs (msg->size);
if (msize != sizeof (struct PingMessage))
- {
- GNUNET_break_op (0);
- return;
- }
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# PING messages received"),
- 1, GNUNET_NO);
- if ( (kx->status != KX_STATE_KEY_RECEIVED) &&
- (kx->status != KX_STATE_UP) )
- {
- /* defer */
- GNUNET_free_non_null (kx->ping_received);
- kx->ping_received = (struct PingMessage*) GNUNET_copy_message (msg);
- return;
- }
- m = (const struct PingMessage*) msg;
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# PING messages received"), 1,
+ GNUNET_NO);
+ if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
+ {
+ /* defer */
+ GNUNET_free_non_null (kx->ping_received);
+ kx->ping_received = (struct PingMessage *) GNUNET_copy_message (msg);
+ return;
+ }
+ m = (const struct PingMessage *) msg;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service receives `%s' request from `%4s'.\n", "PING",
GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer));
GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target));
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"),
+ _
+ ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"),
sender, GNUNET_i2s (&GSC_my_identity), peer);
GNUNET_break_op (0);
return;
}
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received PING from `%s'\n",
- GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PING from `%s'\n",
+ GNUNET_i2s (&kx->peer));
#endif
/* construct PONG */
tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX;
do_encrypt (kx, &iv, &tx.challenge, &tp.challenge,
sizeof (struct PongMessage) - ((void *) &tp.challenge -
(void *) &tp));
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# PONG messages created"), 1,
- GNUNET_NO);
- GSC_NEIGHBOURS_transmit (&kx->peer,
- &tp.header,
- GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */);
+ GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"),
+ 1, GNUNET_NO);
+ GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header,
+ GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ );
}
skm->header.size = htons (sizeof (struct SetKeyMessage));
skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY);
skm->purpose.size =
- htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) +
- sizeof (struct GNUNET_PeerIdentity));
+ htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
+ sizeof (struct GNUNET_TIME_AbsoluteNBO) +
+ sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) +
+ sizeof (struct GNUNET_PeerIdentity));
skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY);
skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created);
skm->target = kx->peer;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key,
- sizeof (struct
- GNUNET_CRYPTO_AesSessionKey),
- kx->public_key, &skm->encrypted_key));
+ GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key,
+ sizeof (struct
+ GNUNET_CRYPTO_AesSessionKey),
+ kx->public_key,
+ &skm->encrypted_key));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose,
- &skm->signature));
+ GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose,
+ &skm->signature));
}
pm->header.size = htons (sizeof (struct PingMessage));
pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
pm->iv_seed =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer);
pp.challenge = kx->ping_challenge;
pp.target = kx->peer;
do_encrypt (kx, &iv, &pp.target, &pm->target,
- sizeof (struct PingMessage) - ((void *) &pm->target -
- (void *) pm));
+ sizeof (struct PingMessage) - ((void *) &pm->target -
+ (void *) pm));
}
kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
left = GNUNET_TIME_absolute_get_remaining (kx->timeout);
if (left.rel_value == 0)
- {
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# sessions terminated by timeout"),
- 1,
- GNUNET_NO);
+ {
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# sessions terminated by timeout"),
+ 1, GNUNET_NO);
GSC_SESSIONS_end (&kx->peer);
kx->status = KX_STATE_DOWN;
return;
}
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending KEEPALIVE to `%s'\n",
- GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n",
+ GNUNET_i2s (&kx->peer));
#endif
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# keepalive messages sent"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# keepalive messages sent"), 1,
+ GNUNET_NO);
setup_fresh_ping (kx);
- GSC_NEIGHBOURS_transmit (&kx->peer,
- &kx->ping.header,
- kx->set_key_retry_frequency);
+ GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
+ kx->set_key_retry_frequency);
retry =
GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
MIN_PING_FREQUENCY);
kx->keep_alive_task =
- GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx);
+ GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx);
}
static void
update_timeout (struct GSC_KeyExchangeInfo *kx)
{
- kx->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ kx->timeout =
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
kx->keep_alive_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
- (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- 2), &send_keep_alive, kx);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ 2), &send_keep_alive, kx);
}
* @param m the encrypted PONG message itself
*/
void
-GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageHeader *msg)
+GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
+ const struct GNUNET_MessageHeader *msg)
{
const struct PongMessage *m;
struct PongMessage t;
GNUNET_break_op (0);
return;
}
- GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages received"),
- 1, GNUNET_NO);
- if ( (kx->status != KX_STATE_KEY_RECEIVED) &&
- (kx->status != KX_STATE_UP) )
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# PONG messages received"), 1,
+ GNUNET_NO);
+ if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
{
if (kx->status == KX_STATE_KEY_SENT)
{
GNUNET_free_non_null (kx->pong_received);
- kx->pong_received = (struct PongMessage*) GNUNET_copy_message (msg);
+ kx->pong_received = (struct PongMessage *) GNUNET_copy_message (msg);
}
return;
}
- m = (const struct PongMessage*) msg;
+ m = (const struct PongMessage *) msg;
#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service receives `%s' response from `%4s'.\n", "PONG",
GNUNET_break_op (0);
return;
}
- GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages decrypted"),
- 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# PONG messages decrypted"), 1,
+ GNUNET_NO);
if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity)))
|| (kx->ping_challenge != t.challenge))
{
return;
}
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received PONG from `%s'\n",
- GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n",
+ GNUNET_i2s (&kx->peer));
#endif
switch (kx->status)
{
{
emsg = kx->emsg_received;
kx->emsg_received = NULL;
- GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL, 0 /* FIXME: ATSI */);
+ GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL,
+ 0 /* FIXME: ATSI */ );
GNUNET_free (emsg);
}
update_timeout (kx);
send_key (struct GSC_KeyExchangeInfo *kx)
{
GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK);
- if (KX_STATE_UP == kx->status)
- return; /* nothing to do */
+ if (KX_STATE_UP == kx->status)
+ return; /* nothing to do */
if (kx->public_key == NULL)
{
/* lookup public key, then try again */
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to obtain public key for `%s'\n",
- GNUNET_i2s (&kx->peer));
+ "Trying to obtain public key for `%s'\n",
+ GNUNET_i2s (&kx->peer));
#endif
kx->pitr =
- GNUNET_PEERINFO_iterate (peerinfo, &kx->peer,
- GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */,
- &process_hello, kx);
+ GNUNET_PEERINFO_iterate (peerinfo, &kx->peer,
+ GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
+ &process_hello, kx);
return;
}
switch (kx->status)
{
case KX_STATE_DOWN:
- kx->status = KX_STATE_KEY_SENT;
+ kx->status = KX_STATE_KEY_SENT;
/* setup SET KEY message */
setup_fresh_setkey (kx);
setup_fresh_ping (kx);
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop
- ("# SET_KEY and PING messages created"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# SET_KEY and PING messages created"), 1,
+ GNUNET_NO);
break;
case KX_STATE_KEY_SENT:
break;
/* always update sender status in SET KEY message */
kx->skm.sender_status = htonl ((int32_t) kx->status);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending SET_KEY and PING to `%s'\n",
- GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SET_KEY and PING to `%s'\n",
+ GNUNET_i2s (&kx->peer));
#endif
- GSC_NEIGHBOURS_transmit (&kx->peer,
- &kx->skm.header,
- kx->set_key_retry_frequency);
- GSC_NEIGHBOURS_transmit (&kx->peer,
- &kx->ping.header,
- kx->set_key_retry_frequency);
+ GSC_NEIGHBOURS_transmit (&kx->peer, &kx->skm.header,
+ kx->set_key_retry_frequency);
+ GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
+ kx->set_key_retry_frequency);
kx->retry_set_key_task =
- GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
- &set_key_retry_task, kx);
+ GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
+ &set_key_retry_task, kx);
}
*/
void
GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
- const void *payload,
- size_t payload_size)
+ const void *payload, size_t payload_size)
{
size_t used = payload_size + sizeof (struct EncryptedMessage);
- char pbuf[used]; /* plaintext */
- char cbuf[used]; /* ciphertext */
+ char pbuf[used]; /* plaintext */
+ char cbuf[used]; /* ciphertext */
struct EncryptedMessage *em; /* encrypted message */
struct EncryptedMessage *ph; /* plaintext header */
struct GNUNET_CRYPTO_AesInitializationVector iv;
struct GNUNET_CRYPTO_AuthKey auth_key;
- ph = (struct EncryptedMessage*) pbuf;
+ ph = (struct EncryptedMessage *) pbuf;
ph->iv_seed =
htonl (GNUNET_CRYPTO_random_u32
(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
em->iv_seed = ph->iv_seed;
derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer);
GNUNET_assert (GNUNET_OK ==
- do_encrypt (kx, &iv, &ph->sequence_number, &em->sequence_number,
+ do_encrypt (kx, &iv, &ph->sequence_number,
+ &em->sequence_number,
used - ENCRYPTED_HEADER_SIZE));
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted %u bytes for %s\n",
- used - ENCRYPTED_HEADER_SIZE,
- GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n",
+ used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
#endif
derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed,
kx->encrypt_key_created);
GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number,
used - ENCRYPTED_HEADER_SIZE, &em->hmac);
- GSC_NEIGHBOURS_transmit (&kx->peer,
- &em->header,
- GNUNET_TIME_UNIT_FOREVER_REL);
-}
+ GSC_NEIGHBOURS_transmit (&kx->peer, &em->header,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+}
/**
*/
struct DeliverMessageContext
{
-
+
/**
* Performance information for the connection.
*/
uint32_t atsi_count;
};
-
+
/**
* We received an encrypted message. Decrypt, validate and
* pass on to the appropriate clients.
* @param atsi_count number of entries in ats (excluding 0-termination)
*/
void
-GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
- const struct GNUNET_MessageHeader *msg,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count)
+GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
+ const struct GNUNET_MessageHeader *msg,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count)
{
const struct EncryptedMessage *m;
struct EncryptedMessage *pt; /* plaintext */
GNUNET_break_op (0);
return;
}
- m = (const struct EncryptedMessage*) msg;
- if ( (kx->status != KX_STATE_KEY_RECEIVED) &&
- (kx->status != KX_STATE_UP) )
+ m = (const struct EncryptedMessage *) msg;
+ if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
{
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop
- ("# failed to decrypt message (no session key)"),
- 1, GNUNET_NO);
+ gettext_noop
+ ("# failed to decrypt message (no session key)"),
+ 1, GNUNET_NO);
return;
}
if (kx->status == KX_STATE_KEY_RECEIVED)
{
/* defer */
GNUNET_free_non_null (kx->ping_received);
- kx->emsg_received = (struct EncryptedMessage*) GNUNET_copy_message (msg);
+ kx->emsg_received = (struct EncryptedMessage *) GNUNET_copy_message (msg);
return;
}
/* validate hash */
size - ENCRYPTED_HEADER_SIZE))
return;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Decrypted %u bytes from %s\n",
- size - ENCRYPTED_HEADER_SIZE,
- GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n",
+ size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
#endif
pt = (struct EncryptedMessage *) buf;
dmc.atsi_count = atsi_count;
dmc.peer = &kx->peer;
if (GNUNET_OK !=
- GNUNET_SERVER_mst_receive (mst, &dmc, &buf[sizeof (struct EncryptedMessage)],
+ GNUNET_SERVER_mst_receive (mst, &dmc,
+ &buf[sizeof (struct EncryptedMessage)],
size - sizeof (struct EncryptedMessage),
GNUNET_YES, GNUNET_NO))
GNUNET_break_op (0);
/**
* Deliver P2P message to interested clients.
* Invokes send twice, once for clients that want the full message, and once
- * for clients that only want the header
+ * for clients that only want the header
*
* @param cls always NULL
* @param client who sent us the message (struct GSC_KeyExchangeInfo)
{
case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
- GSC_SESSIONS_set_typemap (dmc->peer,
- m);
+ GSC_SESSIONS_set_typemap (dmc->peer, m);
return;
default:
- GSC_CLIENTS_deliver_message (dmc->peer,
- dmc->atsi, dmc->atsi_count,
- m,
- ntohs (m->size),
- GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
- GSC_CLIENTS_deliver_message (dmc->peer,
- dmc->atsi, dmc->atsi_count,
- m,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
+ GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
+ ntohs (m->size),
+ GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
+ GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
}
}
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int
+int
GSC_KX_init ()
{
char *keyfile;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY",
- &keyfile))
+ &keyfile))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
+ _
+ ("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
return GNUNET_SYSERR;
}
my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
/**
* Shutdown KX subsystem.
*/
-void
+void
GSC_KX_done ()
{
if (my_private_key != NULL)
* @param msg the set key message we received
*/
void
-GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
- const struct GNUNET_MessageHeader *msg);
+GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
+ const struct GNUNET_MessageHeader *msg);
/**
* @param msg the encrypted PING message itself
*/
void
-GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
- const struct GNUNET_MessageHeader *msg);
+GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
+ const struct GNUNET_MessageHeader *msg);
/**
*/
void
GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
- const struct GNUNET_MessageHeader *msg);
+ const struct GNUNET_MessageHeader *msg);
/**
*/
void
GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
- const void *payload,
- size_t payload_size);
+ const void *payload, size_t payload_size);
/**
* @param atsi_count number of entries in ats (excluding 0-termination)
*/
void
-GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
- const struct GNUNET_MessageHeader *msg,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count);
+GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
+ const struct GNUNET_MessageHeader *msg,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count);
/**
*
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int
+int
GSC_KX_init (void);
/**
* Shutdown KX subsystem.
*/
-void
+void
GSC_KX_done (void);
#endif
GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
n->th = NULL;
}
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# sessions terminated by transport disconnect"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop
+ ("# sessions terminated by transport disconnect"),
+ 1, GNUNET_NO);
GSC_SESSIONS_end (&n->peer);
if (NULL != n->kxinfo)
{
}
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_remove (neighbours,
- &n->peer.hashPubKey, n));
- GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"),
+ &n->peer.hashPubKey, n));
+ GNUNET_STATISTICS_set (GSC_stats,
+ gettext_noop ("# neighbour entries allocated"),
GNUNET_CONTAINER_multihashmap_size (neighbours),
GNUNET_NO);
GNUNET_free (n);
ret = m->size;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Copied message of type %u and size %u into transport buffer for `%4s'\n",
- (unsigned int)
- ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
- (unsigned int) ret, GNUNET_i2s (&n->peer));
+ "Copied message of type %u and size %u into transport buffer for `%4s'\n",
+ (unsigned int)
+ ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
+ (unsigned int) ret, GNUNET_i2s (&n->peer));
#endif
GNUNET_free (m);
process_queue (n);
if (m == NULL)
{
/* notify sessions that the queue is empty and more messages
- could thus be queued now */
+ * could thus be queued now */
GSC_SESSIONS_solicit (&n->peer);
return;
}
GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value);
#endif
n->th =
- GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size,
- 0,
- GNUNET_TIME_absolute_get_remaining
- (m->deadline),
- &transmit_ready,
- n);
+ GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, 0,
+ GNUNET_TIME_absolute_get_remaining
+ (m->deadline), &transmit_ready,
+ n);
if (n->th != NULL)
return;
/* message request too large or duplicate request */
static void
handle_transport_notify_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information
- *atsi, uint32_t atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count)
{
struct Neighbour *n;
GNUNET_CONTAINER_multihashmap_put (neighbours,
&n->peer.hashPubKey, n,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"),
+ GNUNET_STATISTICS_set (GSC_stats,
+ gettext_noop ("# neighbour entries allocated"),
GNUNET_CONTAINER_multihashmap_size (neighbours),
GNUNET_NO);
n->kxinfo = GSC_KX_start (peer);
GSC_KX_handle_pong (n->kxinfo, message);
break;
case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
- GSC_KX_handle_encrypted_message (n->kxinfo,
- message, atsi,
- atsi_count);
+ GSC_KX_handle_encrypted_message (n->kxinfo, message, atsi, atsi_count);
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
/**
* Transmit the given message to the given target.
- *
+ *
* @param target peer that should receive the message (must be connected)
* @param msg message to transmit
* @param timeout by when should the transmission be done?
*/
void
GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
- const struct GNUNET_MessageHeader *msg,
- struct GNUNET_TIME_Relative timeout)
+ const struct GNUNET_MessageHeader *msg,
+ struct GNUNET_TIME_Relative timeout)
{
struct NeighbourMessageEntry *me;
struct Neighbour *n;
me->deadline = GNUNET_TIME_relative_to_absolute (timeout);
me->size = msize;
memcpy (&me[1], msg, msize);
- GNUNET_CONTAINER_DLL_insert_tail (n->message_head,
- n->message_tail,
- me);
+ GNUNET_CONTAINER_DLL_insert_tail (n->message_head, n->message_tail, me);
process_queue (n);
}
{
neighbours = GNUNET_CONTAINER_multihashmap_create (128);
transport =
- GNUNET_TRANSPORT_connect (GSC_cfg,
- &GSC_my_identity, NULL,
+ GNUNET_TRANSPORT_connect (GSC_cfg, &GSC_my_identity, NULL,
&handle_transport_receive,
&handle_transport_notify_connect,
&handle_transport_notify_disconnect);
}
/* end of gnunet-service-core_neighbours.c */
-
* when the message queue is empty). Outbound quotas and memory
* bounds will then be enfoced (as GSC_SESSION_solicit is only called
* if sufficient banwdith is available).
- *
+ *
* @param target peer that should receive the message (must be connected)
* @param msg message to transmit
* @param timeout by when should the transmission be done?
*/
void
GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
- const struct GNUNET_MessageHeader *msg,
- struct GNUNET_TIME_Relative timeout);
+ const struct GNUNET_MessageHeader *msg,
+ struct GNUNET_TIME_Relative timeout);
/**
/**
* @file core/gnunet-service-core_sessions.c
- * @brief code for managing of 'encrypted' sessions (key exchange done)
+ * @brief code for managing of 'encrypted' sessions (key exchange done)
* @author Christian Grothoff
*/
#include "platform.h"
/**
* Is the neighbour queue empty and thus ready for us
- * to transmit an encrypted message?
+ * to transmit an encrypted message?
*/
int ready_to_transmit;
/**
* End the session with the given peer (we are no longer
- * connected).
+ * connected).
*
* @param pid identity of peer to kill session with
*/
if (NULL == session)
return;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Destroying session for peer `%4s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying session for peer `%4s'\n",
GNUNET_i2s (&session->peer));
#endif
if (GNUNET_SCHEDULER_NO_TASK != session->cork_task)
while (NULL != (car = session->active_client_request_head))
{
GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
- session->active_client_request_tail,
- car);
+ session->active_client_request_tail, car);
GSC_CLIENTS_reject_request (car);
}
GNUNET_SCHEDULER_cancel (session->typemap_task);
- GSC_CLIENTS_notify_clients_about_neighbour (&session->peer,
- NULL, 0 /* FIXME: ATSI */,
- session->tmap,
- NULL);
+ GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, NULL,
+ 0 /* FIXME: ATSI */ ,
+ session->tmap, NULL);
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (sessions,
- &session->peer.hashPubKey, session));
- GNUNET_STATISTICS_set (GSC_stats,
- gettext_noop ("# entries in session map"),
- GNUNET_CONTAINER_multihashmap_size (sessions),
- GNUNET_NO);
+ &session->
+ peer.hashPubKey,
+ session));
+ GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"),
+ GNUNET_CONTAINER_multihashmap_size (sessions),
+ GNUNET_NO);
GSC_TYPEMAP_destroy (session->tmap);
session->tmap = NULL;
GNUNET_free (session);
*
* @param cls the 'struct Session*'
* @param tc unused
- */
+ */
static void
-transmit_typemap_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_typemap_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Session *session = cls;
struct GNUNET_MessageHeader *hdr;
delay = TYPEMAP_FREQUENCY;
/* randomize a bit to avoid spont. sync */
- delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 1000);
- session->typemap_task = GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_typemap_task,
- session);
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# type map refreshes sent"),
- 1,
- GNUNET_NO);
+ delay.rel_value +=
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
+ session->typemap_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session);
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# type map refreshes sent"), 1,
+ GNUNET_NO);
hdr = GSC_TYPEMAP_compute_type_map_message ();
- GSC_KX_encrypt_and_transmit (session->kxinfo,
- hdr,
- ntohs (hdr->size));
+ GSC_KX_encrypt_and_transmit (session->kxinfo, hdr, ntohs (hdr->size));
GNUNET_free (hdr);
}
*/
void
GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
- struct GSC_KeyExchangeInfo *kx)
+ struct GSC_KeyExchangeInfo *kx)
{
struct Session *session;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating session for peer `%4s'\n", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating session for peer `%4s'\n",
+ GNUNET_i2s (peer));
#endif
session = GNUNET_malloc (sizeof (struct Session));
session->tmap = GSC_TYPEMAP_create ();
session->peer = *peer;
session->kxinfo = kx;
session->time_established = GNUNET_TIME_absolute_get ();
- session->typemap_task = GNUNET_SCHEDULER_add_now (&transmit_typemap_task,
- session);
+ session->typemap_task =
+ GNUNET_SCHEDULER_add_now (&transmit_typemap_task, session);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (sessions,
- &peer->hashPubKey, session,
+ GNUNET_CONTAINER_multihashmap_put (sessions, &peer->hashPubKey,
+ session,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- GNUNET_STATISTICS_set (GSC_stats,
- gettext_noop ("# entries in session map"),
- GNUNET_CONTAINER_multihashmap_size (sessions),
- GNUNET_NO);
- GSC_CLIENTS_notify_clients_about_neighbour (peer,
- NULL, 0 /* FIXME: ATSI */,
- NULL,
- session->tmap);
+ GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"),
+ GNUNET_CONTAINER_multihashmap_size (sessions),
+ GNUNET_NO);
+ GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0 /* FIXME: ATSI */ ,
+ NULL, session->tmap);
}
* Notify the given client about the session (client is new).
*
* @param cls the 'struct GSC_Client'
- * @param key peer identity
+ * @param key peer identity
* @param value the 'struct Session'
* @return GNUNET_OK (continue to iterate)
*/
static int
-notify_client_about_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+notify_client_about_session (void *cls, const GNUNET_HashCode * key,
+ void *value)
{
struct GSC_Client *client = cls;
struct Session *session = value;
- GSC_CLIENTS_notify_client_about_neighbour (client,
- &session->peer,
- NULL, 0, /* FIXME: ATS!? */
- NULL, /* old TMAP: none */
- session->tmap);
+ GSC_CLIENTS_notify_client_about_neighbour (client, &session->peer, NULL, 0, /* FIXME: ATS!? */
+ NULL, /* old TMAP: none */
+ session->tmap);
return GNUNET_OK;
}
GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client)
{
/* notify new client about existing sessions */
- GNUNET_CONTAINER_multihashmap_iterate (sessions,
- ¬ify_client_about_session, client);
+ GNUNET_CONTAINER_multihashmap_iterate (sessions, ¬ify_client_about_session,
+ client);
}
"Received client transmission request. queueing\n");
#endif
GNUNET_CONTAINER_DLL_insert (session->active_client_request_head,
- session->active_client_request_tail, car);
+ session->active_client_request_tail, car);
try_transmission (session);
}
{
struct Session *s;
- if (0 == memcmp (&car->target,
- &GSC_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 ==
+ memcmp (&car->target, &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
return;
- s = find_session (&car->target);
+ s = find_session (&car->target);
GNUNET_assert (NULL != s);
GNUNET_CONTAINER_DLL_remove (s->active_client_request_head,
s->active_client_request_tail, car);
struct GSC_ClientActiveRequest *pos;
struct GSC_ClientActiveRequest *nxt;
struct GNUNET_TIME_Absolute now;
-
+
now = GNUNET_TIME_absolute_get ();
pos = NULL;
nxt = session->active_client_request_head;
{
pos = nxt;
nxt = pos->next;
- if ( (pos->deadline.abs_value < now.abs_value) &&
- (GNUNET_YES != pos->was_solicited) )
+ if ((pos->deadline.abs_value < now.abs_value) &&
+ (GNUNET_YES != pos->was_solicited))
{
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop
("# messages discarded (expired prior to transmission)"),
1, GNUNET_NO);
GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
- session->active_client_request_tail,
- pos);
+ session->active_client_request_tail, pos);
GSC_CLIENTS_reject_request (pos);
}
}
struct GSC_ClientActiveRequest *car;
size_t so_size;
- discard_expired_requests (session);
+ discard_expired_requests (session);
so_size = 0;
for (car = session->active_client_request_head; NULL != car; car = car->next)
{
/**
- * Some messages were delayed (corked), but the timeout has now expired.
+ * Some messages were delayed (corked), but the timeout has now expired.
* Send them now.
*
* @param cls 'struct Session' with the messages to transmit now
* @param tc scheduler context (unused)
*/
static void
-pop_cork_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+pop_cork_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Session *session = cls;
min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
/* check 'ready' messages */
pos = session->sme_head;
- while ( (NULL != pos) &&
- (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) )
+ while ((NULL != pos) &&
+ (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE))
{
GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
msize += pos->size;
- min_deadline = GNUNET_TIME_absolute_min (min_deadline,
- pos->deadline);
+ min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline);
pos = pos->next;
}
now = GNUNET_TIME_absolute_get ();
- if ( (msize == 0) ||
- ( (msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
- (min_deadline.abs_value > now.abs_value) ) )
+ if ((msize == 0) ||
+ ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
+ (min_deadline.abs_value > now.abs_value)))
{
/* not enough ready yet, try to solicit more */
solicit_messages (session);
if (msize > 0)
{
/* if there is data to send, just not yet, make sure we do transmit
- it once the deadline is reached */
+ * it once the deadline is reached */
if (session->cork_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (session->cork_task);
- session->cork_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (min_deadline),
- &pop_cork_task,
- session);
+ GNUNET_SCHEDULER_cancel (session->cork_task);
+ session->cork_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (min_deadline), &pop_cork_task,
+ session);
}
return;
}
{
static unsigned long long total_bytes;
static unsigned int total_msgs;
- char pbuf[msize]; /* plaintext */
+ char pbuf[msize]; /* plaintext */
size_t used;
used = 0;
- while ( (NULL != (pos = session->sme_head)) &&
- (used + pos->size <= msize) )
+ while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize))
{
memcpy (&pbuf[used], &pos[1], pos->size);
used += pos->size;
- GNUNET_CONTAINER_DLL_remove (session->sme_head,
- session->sme_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos);
GNUNET_free (pos);
}
/* compute average payload size */
total_msgs = 1;
total_bytes = used;
}
- GNUNET_STATISTICS_set (GSC_stats,
- "# avg payload per encrypted message",
- total_bytes / total_msgs,
- GNUNET_NO);
+ GNUNET_STATISTICS_set (GSC_stats, "# avg payload per encrypted message",
+ total_bytes / total_msgs, GNUNET_NO);
/* now actually transmit... */
session->ready_to_transmit = GNUNET_NO;
- GSC_KX_encrypt_and_transmit (session->kxinfo,
- pbuf,
- used);
+ GSC_KX_encrypt_and_transmit (session->kxinfo, pbuf, used);
}
}
m = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
memcpy (&m[1], hdr, size);
m->size = size;
- GNUNET_CONTAINER_DLL_insert (session->sme_head,
- session->sme_tail,
- m);
+ GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, m);
try_transmission (session);
return GNUNET_OK;
}
{
if (NULL == sessions)
return;
- GNUNET_CONTAINER_multihashmap_iterate (sessions,
- &do_send_message, (void*) msg);
+ GNUNET_CONTAINER_multihashmap_iterate (sessions, &do_send_message,
+ (void *) msg);
}
*/
void
GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
- const struct GNUNET_MessageHeader *msg,
- int cork)
+ const struct GNUNET_MessageHeader *msg, int cork)
{
struct Session *session;
struct SessionMessageEntry *sme;
memcpy (&sme[1], msg, msize);
sme->size = msize;
if (GNUNET_YES == cork)
- sme->deadline = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY);
- GNUNET_CONTAINER_DLL_insert_tail (session->sme_head,
- session->sme_tail,
- sme);
+ sme->deadline =
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY);
+ GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, session->sme_tail, sme);
try_transmission (session);
}
struct GNUNET_SERVER_TransmitContext *tc = cls;
struct Session *session = value;
struct ConnectNotifyMessage cnm;
-
+
/* FIXME: code duplication with clients... */
cnm.header.size = htons (sizeof (struct ConnectNotifyMessage));
cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
/**
* Handle CORE_ITERATE_PEERS request. For this request type, the client
* does not have to have transmitted an INIT request. All current peers
- * are returned, regardless of which message types they accept.
+ * are returned, regardless of which message types they accept.
*
* @param cls unused
* @param client client sending the iteration request
* @param message iteration request message
*/
void
-GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+GSC_SESSIONS_handle_client_iterate_peers (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader
+ *message)
{
struct GNUNET_MessageHeader done_msg;
struct GNUNET_SERVER_TransmitContext *tc;
tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_CONTAINER_multihashmap_iterate (sessions,
- &queue_connect_message,
- tc);
+ GNUNET_CONTAINER_multihashmap_iterate (sessions, &queue_connect_message, tc);
done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
GNUNET_SERVER_transmit_context_append_message (tc, &done_msg);
* @param message iteration request message
*/
void
-GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+GSC_SESSIONS_handle_client_have_peer (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader
+ *message)
{
struct GNUNET_MessageHeader done_msg;
struct GNUNET_SERVER_TransmitContext *tc;
const struct GNUNET_PeerIdentity *peer;
- peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK!
+ peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK!
tc = GNUNET_SERVER_transmit_context_create (client);
GNUNET_CONTAINER_multihashmap_get_multiple (sessions, &peer->hashPubKey,
&queue_connect_message, tc);
*/
void
GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
struct Session *session;
struct GSC_TypeMap *nmap;
nmap = GSC_TYPEMAP_get_from_message (msg);
if (NULL == nmap)
- return; /* malformed */
+ return; /* malformed */
session = find_session (peer);
if (NULL == session)
{
GNUNET_break (0);
return;
}
- GSC_CLIENTS_notify_clients_about_neighbour (peer,
- NULL, 0, /* FIXME: ATS */
- session->tmap,
- nmap);
+ GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */
+ session->tmap, nmap);
GSC_TYPEMAP_destroy (session->tmap);
session->tmap = nmap;
}
*/
void
GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
- uint16_t type)
+ uint16_t type)
{
struct Session *session;
struct GSC_TypeMap *nmap;
return;
session = find_session (peer);
GNUNET_assert (NULL != session);
- if (GNUNET_YES ==
- GSC_TYPEMAP_test_match (session->tmap,
- &type, 1))
- return; /* already in it */
- nmap = GSC_TYPEMAP_extend (session->tmap,
- &type, 1);
- GSC_CLIENTS_notify_clients_about_neighbour (peer,
- NULL, 0, /* FIXME: ATS */
- session->tmap,
- nmap);
+ if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1))
+ return; /* already in it */
+ nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1);
+ GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */
+ session->tmap, nmap);
GSC_TYPEMAP_destroy (session->tmap);
session->tmap = nmap;
}
void
GSC_SESSIONS_done ()
{
- GNUNET_CONTAINER_multihashmap_iterate (sessions,
- &free_session_helper,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (sessions, &free_session_helper, NULL);
GNUNET_CONTAINER_multihashmap_destroy (sessions);
sessions = NULL;
}
/* end of gnunet-service-core_sessions.c */
-
/**
* @file core/gnunet-service-core_neighbours.h
- * @brief code for managing of 'encrypted' sessions (key exchange done)
+ * @brief code for managing of 'encrypted' sessions (key exchange done)
* @author Christian Grothoff
*/
#ifndef GNUNET_SERVICE_CORE_SESSIONS_H
*/
void
GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
- struct GSC_KeyExchangeInfo *kx);
+ struct GSC_KeyExchangeInfo *kx);
/**
* End the session with the given peer (we are no longer
- * connected).
+ * connected).
*
* @param pid identity of peer to kill session with
*/
*/
void
GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
- const struct GNUNET_MessageHeader *msg,
- int cork);
+ const struct GNUNET_MessageHeader *msg, int cork);
/**
*/
void
GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *msg);
+ const struct GNUNET_MessageHeader *msg);
/**
*/
void
GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
- uint16_t type);
+ uint16_t type);
/**
* @param message iteration request message
*/
void
-GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+GSC_SESSIONS_handle_client_iterate_peers (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader
+ *message);
/**
* @param message iteration request message
*/
void
-GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+GSC_SESSIONS_handle_client_have_peer (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader
+ *message);
* A type map describing which messages a given neighbour is able
* to process.
*/
-struct GSC_TypeMap
+struct GSC_TypeMap
{
uint32_t bits[(UINT16_MAX + 1) / 32];
};
switch (ntohs (msg->type))
{
case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# type maps received"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
+ 1, GNUNET_NO);
if (size != sizeof (struct GSC_TypeMap))
{
GNUNET_break_op (0);
memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap));
return ret;
case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# type maps received"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
+ 1, GNUNET_NO);
ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
dlen = sizeof (struct GSC_TypeMap);
- if ( (Z_OK !=
- uncompress ((Bytef*) ret, &dlen,
- (const Bytef*) &msg[1], (uLong) size)) ||
- (dlen != sizeof (struct GSC_TypeMap) ) )
+ if ((Z_OK !=
+ uncompress ((Bytef *) ret, &dlen, (const Bytef *) &msg[1],
+ (uLong) size)) || (dlen != sizeof (struct GSC_TypeMap)))
{
GNUNET_break_op (0);
GNUNET_free (ret);
struct GNUNET_MessageHeader *hdr;
hdr = GSC_TYPEMAP_compute_type_map_message ();
- GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# updates to my type map"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats,
+ gettext_noop ("# updates to my type map"), 1,
+ GNUNET_NO);
GSC_SESSIONS_broadcast (hdr);
GNUNET_free (hdr);
}
* Add a set of types to our type map.
*/
void
-GSC_TYPEMAP_add (const uint16_t *types,
- unsigned int tlen)
+GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen)
{
unsigned int i;
int changed;
changed = GNUNET_NO;
- for (i=0;i<tlen;i++)
+ for (i = 0; i < tlen; i++)
{
if (0 == map_counters[types[i]]++)
{
* Remove a set of types from our type map.
*/
void
-GSC_TYPEMAP_remove (const uint16_t *types,
- unsigned int tlen)
+GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen)
{
unsigned int i;
int changed;
changed = GNUNET_NO;
- for (i=0;i<tlen;i++)
+ for (i = 0; i < tlen; i++)
{
if (0 == --map_counters[types[i]])
{
* @param types array of types
* @param tcnt number of entries in types
* @return GNUNET_YES if a type is in the map, GNUNET_NO if not
- */
+ */
int
-GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
- const uint16_t *types,
- unsigned int tcnt)
-{
+GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types,
+ unsigned int tcnt)
+{
unsigned int i;
if (NULL == tmap)
return GNUNET_NO;
if (0 == tcnt)
- return GNUNET_YES; /* matches all */
- for (i=0;i<tcnt;i++)
+ return GNUNET_YES; /* matches all */
+ for (i = 0; i < tcnt; i++)
if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32))))
return GNUNET_YES;
return GNUNET_NO;
* @param types array of types to add
* @param tcnt number of entries in types
* @return updated type map (fresh copy)
- */
+ */
struct GSC_TypeMap *
-GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
- const uint16_t *types,
- unsigned int tcnt)
+GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types,
+ unsigned int tcnt)
{
struct GSC_TypeMap *ret;
unsigned int i;
ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
if (NULL != tmap)
memcpy (ret, tmap, sizeof (struct GSC_TypeMap));
- for (i=0;i<tcnt;i++)
+ for (i = 0; i < tcnt; i++)
ret->bits[types[i] / 32] |= (1 << (types[i] % 32));
return ret;
}
* Add a set of types to our type map.
*/
void
-GSC_TYPEMAP_add (const uint16_t *types,
- unsigned int tlen);
+GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen);
/**
* Remove a set of types from our type map.
*/
void
-GSC_TYPEMAP_remove (const uint16_t *types,
- unsigned int tlen);
+GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen);
/**
* @param types array of types
* @param tcnt number of entries in types
* @return GNUNET_YES if a type is in the map, GNUNET_NO if not
- */
+ */
int
-GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
- const uint16_t *types,
- unsigned int tcnt);
+GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types,
+ unsigned int tcnt);
/**
* @param types array of types to add
* @param tcnt number of entries in types
* @return updated type map (fresh copy)
- */
+ */
struct GSC_TypeMap *
-GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
- const uint16_t *types,
- unsigned int tcnt);
+GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types,
+ unsigned int tcnt);
/**
* Create an empty type map.
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received (my) `%s' from transport service\n", "HELLO");
GNUNET_assert (message != NULL);
- if ((p == &p1) && (p2.th != NULL))
+ if ((p == &p1) && (p2.th != NULL))
GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
if ((p == &p2) && (p1.th != NULL))
GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct PeerContext *pc = cls;
static int
inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core provides inbound data from `%4s'.\n", GNUNET_i2s (other));
static int
outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core notifies about outbound data for `%4s'.\n",
static int
process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n",
GNUNET_i2s (peer));
/* connect p2 */
p2.ch =
GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
- &disconnect_notify, &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES,
- handlers);
+ &disconnect_notify, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
else
{
&terminate_task_error, NULL);
p1.ch =
GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
- &disconnect_notify, &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
+ &disconnect_notify, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
GNUNET_CORE_disconnect (p2.ch);
p2.ch = NULL;
}
- if (connect_task != GNUNET_SCHEDULER_NO_TASK)
+ if (connect_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (connect_task);
if (p1.th != NULL)
{
static void
try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &try_connect, NULL);
+ connect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
+ NULL);
GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
}
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct PeerContext *pc = cls;
static int
inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static int
outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static int
process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
static int n;
unsigned int s;
"test_core_api_peer1.conf"));
core =
- GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL,
- NULL, 0, NULL, 0, handlers);
+ GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, NULL,
+ 0, NULL, 0, handlers);
die_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
}
inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
return GNUNET_OK;
}
outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
return GNUNET_OK;
}
/* connect p2 */
p2.ch =
GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
- &disconnect_notify, &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES,
- handlers);
+ &disconnect_notify, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
else
{
&timeout_task, NULL);
p1.ch =
GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
- &disconnect_notify, &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
+ &disconnect_notify, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
static void
try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &try_connect, NULL);
+ connect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
+ NULL);
GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
}
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
- throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */
- throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */
+ throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */
+ throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */
- max_quota_in = GNUNET_MIN (current_quota_p1_in,
- current_quota_p2_in);
- max_quota_out = GNUNET_MIN (current_quota_p1_out,
- current_quota_p2_out);
+ max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in);
+ max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out);
if (max_quota_out < max_quota_in)
quota_delta = max_quota_in / 5;
else
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
if (ok != 0)
- kind = GNUNET_ERROR_TYPE_ERROR;
+ kind = GNUNET_ERROR_TYPE_ERROR;
switch (test)
{
case SYMMETRIC:
};
GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n",
throughput_out, total_bytes_sent, delta);
- GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n",
- current_quota_p1_out);
+ GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", current_quota_p1_out);
GNUNET_log (kind, "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n",
throughput_in, total_bytes_recv, delta);
- GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n",
- current_quota_p2_in);
+ GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", current_quota_p2_in);
/*
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in );
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
{
if ((p1.ch != NULL) && (p1.connect_status == 1))
GNUNET_break (NULL !=
- (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
- FAST_TIMEOUT, &p2.id,
- MESSAGESIZE,
- &transmit_ready, &p1)));
+ (p1.nth =
+ GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
+ FAST_TIMEOUT, &p2.id,
+ MESSAGESIZE,
+ &transmit_ready, &p1)));
return 0;
}
GNUNET_assert (tr_n < TOTAL_MSGS);
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct PeerContext *pc = cls;
if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
- return; /* loopback */
+ return; /* loopback */
GNUNET_assert (pc->connect_status == 0);
pc->connect_status = 1;
if (pc == &p1)
NULL);
GNUNET_break (NULL !=
- (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
- TIMEOUT, &p2.id,
- MESSAGESIZE,
- &transmit_ready, &p1)));
+ (p1.nth =
+ GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
+ TIMEOUT, &p2.id,
+ MESSAGESIZE,
+ &transmit_ready, &p1)));
}
}
struct PeerContext *pc = cls;
if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
- return; /* loopback */
+ return; /* loopback */
pc->connect_status = 0;
if (GNUNET_SCHEDULER_NO_TASK != measure_task)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Measurement aborted due to disconnect!\n");
+ "Measurement aborted due to disconnect!\n");
GNUNET_SCHEDULER_cancel (measure_task);
measure_task = GNUNET_SCHEDULER_NO_TASK;
}
static int
inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
#if DEBUG_TRANSMISSION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static int
outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
#if DEBUG_TRANSMISSION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static int
process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
static int n;
const struct TestMessage *hdr;
GNUNET_assert (ok == 2);
OKPP;
/* connect p2 */
- p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
- &disconnect_notify, &inbound_notify, GNUNET_YES,
- &outbound_notify, GNUNET_YES, handlers);
+ p2.ch =
+ GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
+ &disconnect_notify, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
else
{
"Asking core (1) to connect to peer `%4s'\n",
GNUNET_i2s (&p2.id));
#endif
- connect_task = GNUNET_SCHEDULER_add_now (&try_connect,
- NULL);
+ connect_task = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
}
}
"TOTAL_QUOTA_OUT",
¤t_quota_p2_out));
- p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
- &disconnect_notify, &inbound_notify, GNUNET_YES,
- &outbound_notify, GNUNET_YES, handlers);
+ p1.ch =
+ GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
+ &disconnect_notify, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
struct GNUNET_DATACACHE_Handle *h = cls;
#if DEBUG_DATACACHE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Content under key `%s' discarded\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Content under key `%s' discarded\n",
GNUNET_h2s (key));
#endif
GNUNET_assert (h->utilization >= size);
return GNUNET_SYSERR;
}
#if DEBUG_DATACACHE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Stored data under key `%s' in cache\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Stored data under key `%s' in cache\n",
GNUNET_h2s (key));
#endif
GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size,
GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1,
GNUNET_NO);
#if DEBUG_DATACACHE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Processing request for key `%s'\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing request for key `%s'\n",
GNUNET_h2s (key));
#endif
if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key))
("# requests filtered by bloom filter"), 1,
GNUNET_NO);
#if DEBUG_DATACACHE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Bloomfilter filters request for key `%s'\n",
- GNUNET_h2s (key));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Bloomfilter filters request for key `%s'\n",
+ GNUNET_h2s (key));
#endif
return 0; /* can not be present */
}
"INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)",
&stmt) != SQLITE_OK)
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sq_prepare");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sq_prepare");
return 0;
}
if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
"SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?",
&stmt) != SQLITE_OK)
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sq_prepare");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sq_prepare");
return 0;
}
ntime = (int64_t) now.abs_value;
sqlite3_finalize (stmt);
#if DEBUG_DATACACHE_SQLITE
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No content found when processing `%s' for key `%4s'\n",
- "GET", GNUNET_h2s (key));
+ "No content found when processing `%s' for key `%4s'\n", "GET",
+ GNUNET_h2s (key));
#endif
return 0;
}
#if DEBUG_DATACACHE_SQLITE
if (0 == total)
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No content found when processing `%s' for key `%4s'\n",
- "GET", GNUNET_h2s (key));
+ "No content found when processing `%s' for key `%4s'\n", "GET",
+ GNUNET_h2s (key));
#endif
return total;
}
off);
if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sq_prepare");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sq_prepare");
return cnt;
}
if ((SQLITE_OK !=
cnt++;
#if DEBUG_DATACACHE_SQLITE
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found %u-byte result when processing `%s' for key `%4s'\n",
- (unsigned int) size,
- "GET",
- GNUNET_h2s (key));
+ "Found %u-byte result when processing `%s' for key `%4s'\n",
+ (unsigned int) size, "GET", GNUNET_h2s (key));
#endif
if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type))
{
"SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1",
&stmt) != SQLITE_OK)
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sq_prepare");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sq_prepare");
if (stmt != NULL)
(void) sqlite3_finalize (stmt);
return GNUNET_SYSERR;
}
if (SQLITE_ROW != sqlite3_step (stmt))
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
(void) sqlite3_finalize (stmt);
return GNUNET_SYSERR;
}
memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
dsize = sqlite3_column_bytes (stmt, 2);
if (SQLITE_OK != sqlite3_finalize (stmt))
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
- if (sq_prepare
- (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?",
- &dstmt) != SQLITE_OK)
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
+ if (sq_prepare (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", &dstmt) !=
+ SQLITE_OK)
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sq_prepare");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sq_prepare");
if (stmt != NULL)
(void) sqlite3_finalize (stmt);
return GNUNET_SYSERR;
}
- if (SQLITE_OK !=
- sqlite3_bind_int64 (dstmt, 1, rowid))
+ if (SQLITE_OK != sqlite3_bind_int64 (dstmt, 1, rowid))
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_bind");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_bind");
(void) sqlite3_finalize (dstmt);
return GNUNET_SYSERR;
}
if (sqlite3_step (dstmt) != SQLITE_DONE)
{
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_step");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_step");
(void) sqlite3_finalize (dstmt);
return GNUNET_SYSERR;
}
plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
if (SQLITE_OK != sqlite3_finalize (dstmt))
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite3_finalize");
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "sqlite3_finalize");
return GNUNET_OK;
}
api->get = &sqlite_plugin_get;
api->put = &sqlite_plugin_put;
api->del = &sqlite_plugin_del;
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Sqlite datacache running\n"));
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Sqlite datacache running\n"));
return api;
}
if (result == SQLITE_BUSY)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Tried to close sqlite without finalizing all prepared statements.\n"));
+ _
+ ("Tried to close sqlite without finalizing all prepared statements.\n"));
stmt = sqlite3_next_stmt (plugin->dbh, NULL);
while (stmt != NULL)
{
#if DEBUG_SQLITE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Closing statement %p\n", stmt);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing statement %p\n", stmt);
#endif
result = sqlite3_finalize (stmt);
#if DEBUG_SQLITE
if (result != SQLITE_OK)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to close statement %p: %d\n", stmt, result);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to close statement %p: %d\n",
+ stmt, result);
#endif
stmt = sqlite3_next_stmt (plugin->dbh, NULL);
}
&plugin->updRepl) != SQLITE_OK) ||
(sq_prepare
(plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 "
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
#if SQLITE_VERSION_NUMBER >= 3007000
- "INDEXED BY idx_repl_rvalue "
+ "INDEXED BY idx_repl_rvalue "
#endif
- "WHERE repl=?2 AND "
- " (rvalue>=?1 OR "
+ "WHERE repl=?2 AND " " (rvalue>=?1 OR "
" NOT EXISTS (SELECT 1 FROM gn090 "
#if SQLITE_VERSION_NUMBER >= 3007000
- "INDEXED BY idx_repl_rvalue "
+ "INDEXED BY idx_repl_rvalue "
#endif
- "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
+ "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
"ORDER BY rvalue ASC LIMIT 1", &plugin->selRepl) != SQLITE_OK) ||
- (sq_prepare
- (plugin->dbh, "SELECT MAX(repl) FROM gn090"
+ (sq_prepare (plugin->dbh, "SELECT MAX(repl) FROM gn090"
#if SQLITE_VERSION_NUMBER >= 3007000
- " INDEXED BY idx_repl_rvalue"
+ " INDEXED BY idx_repl_rvalue"
#endif
- "",
- &plugin->maxRepl) != SQLITE_OK) ||
+ "", &plugin->maxRepl) != SQLITE_OK) ||
(sq_prepare
(plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 "
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
#if SQLITE_VERSION_NUMBER >= 3007000
- "INDEXED BY idx_expire "
+ "INDEXED BY idx_expire "
#endif
"WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
"ORDER BY expire ASC LIMIT 1", &plugin->selExpi) != SQLITE_OK) ||
(sq_prepare
(plugin->dbh,
- "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
- "FROM gn090 "
+ "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
#if SQLITE_VERSION_NUMBER >= 3007000
- "INDEXED BY idx_anon_type_hash "
+ "INDEXED BY idx_anon_type_hash "
#endif
"WHERE (anonLevel = 0 AND type=?1) "
"ORDER BY hash DESC LIMIT 1 OFFSET ?2",
if (NULL == key)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Value check failed (got NULL key) in %d/%d\n",
- crc->phase, crc->i);
+ "Value check failed (got NULL key) in %d/%d\n", crc->phase,
+ crc->i);
crc->phase = RP_ERROR;
GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
return;
}
#if 0
struct GNUNET_DHT_GetHandle *rh = value;
if (GNUNET_NO == rh->message->in_pending_queue)
- {
+ {
#if DEBUG_DHT
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Retransmitting request related to %s to DHT %p\n",
- GNUNET_h2s (key),
- handle);
+ "Retransmitting request related to %s to DHT %p\n", GNUNET_h2s (key),
+ handle);
#endif
GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
rh->message);
struct GNUNET_DHT_Handle *handle = cls;
#if DEBUG_DHT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Reconnecting with DHT %p\n",
- handle);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle);
#endif
handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value)
GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
handle->th = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from DHT service, will try to reconnect in %llu ms\n",
- (unsigned long long) handle->retry_time.rel_value);
+ "Disconnecting from DHT service, will try to reconnect in %llu ms\n",
+ (unsigned long long) handle->retry_time.rel_value);
GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
handle->client = NULL;
handle->reconnect_task =
if (handle->client == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "process_pending_messages called, but client is null, reconnecting\n");
+ "process_pending_messages called, but client is null, reconnecting\n");
do_disconnect (handle);
return;
}
if (NULL != handle->th)
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "notify_transmit_ready returned NULL, reconnecting\n");
+ "notify_transmit_ready returned NULL, reconnecting\n");
do_disconnect (handle);
}
#endif
handle->in_receive = GNUNET_YES;
GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_TIME_UNIT_FOREVER_REL);
}
return tsize;
}
{
/* UID mismatch */
#if DEBUG_DHT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring reply for %s: UID mismatch: %llu/%llu\n",
- GNUNET_h2s (key),
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Ignoring reply for %s: UID mismatch: %llu/%llu\n", GNUNET_h2s (key),
dht_msg->unique_id, get_handle->unique_id);
#endif
return GNUNET_YES;
}
data_length = msize - meta_length;
#if DEBUG_DHT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Giving %u byte reply for %s to application\n",
- (unsigned int) data_length,
- GNUNET_h2s (key));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n",
+ (unsigned int) data_length, GNUNET_h2s (key));
#endif
put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1];
get_path = &put_path[put_path_length];
}
dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg;
#if DEBUG_DHT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received reply for `%s' from DHT service %p\n",
- GNUNET_h2s (&dht_msg->key),
- handle);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply for `%s' from DHT service %p\n",
+ GNUNET_h2s (&dht_msg->key), handle);
#endif
GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests,
&dht_msg->key, &process_reply,
struct GNUNET_DHT_Handle *handle;
handle = pending->handle;
- GNUNET_assert (GNUNET_YES == pending->in_pending_queue);
+ GNUNET_assert (GNUNET_YES == pending->in_pending_queue);
GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
pending);
pending->in_pending_queue = GNUNET_NO;
return NULL;
}
#if DEBUG_DHT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending query for %s to DHT %p\n",
- GNUNET_h2s (key),
- handle);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending query for %s to DHT %p\n",
+ GNUNET_h2s (key), handle);
#endif
pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1];
get_msg =
(const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg;
#if DEBUG_DHT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending STOP for %s to DHT via %p\n",
- GNUNET_h2s (&get_msg->key),
- handle);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending STOP for %s to DHT via %p\n",
+ GNUNET_h2s (&get_msg->key), handle);
#endif
/* generate STOP */
pending =
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type,
(unsigned int) size, (char *) data);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
(absolute_timeout), &cleanup_task, NULL);
get_handle =
- GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key,
- replication, GNUNET_DHT_RO_NONE, NULL,
- 0, &get_result_iterator, NULL);
+ GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, replication,
+ GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator,
+ NULL);
}
if (verbose)
fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"),
query_key, data);
- GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE,
- query_type, strlen (data), data, expiration, timeout,
- &message_sent_cont, NULL);
+ GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, query_type,
+ strlen (data), data, expiration, timeout, &message_sent_cont,
+ NULL);
}
* @param message HELLO message of peer
*/
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (message != NULL);
GNUNET_free_non_null (GDS_my_hello);
GDS_DATACACHE_init ();
GDS_HELLO_init ();
GDS_CLIENTS_init (server);
- if (GNUNET_OK !=
- GDS_NEIGHBOURS_init ())
- {
- shutdown_task (NULL, NULL);
- return;
- }
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ if (GNUNET_OK != GDS_NEIGHBOURS_init ())
+ {
+ shutdown_task (NULL, NULL);
+ return;
+ }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+ NULL);
GDS_transport_handle =
- GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
+ GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
if (GDS_transport_handle == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to connect to transport service!\n"));
- return;
- }
- ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle,
- &process_hello, NULL);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to connect to transport service!\n"));
+ return;
+ }
+ ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, &process_hello, NULL);
}
main (int argc, char *const *argv)
{
int ret;
-
- ret = (GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv,
- "dht",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+
+ ret =
+ (GNUNET_OK ==
+ GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run,
+ NULL)) ? 0 : 1;
GDS_CLIENTS_done ();
return ret;
}
/**
* Actual message to be sent, allocated at the end of the struct:
- * // msg = (cast) &pm[1];
+ * // msg = (cast) &pm[1];
* // memcpy (&pm[1], data, len);
*/
const struct GNUNET_MessageHeader *msg;
}
ret = GNUNET_malloc (sizeof (struct ClientList));
ret->client_handle = client;
- GNUNET_CONTAINER_DLL_insert (client_head,
- client_tail,
- ret);
+ GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret);
return ret;
}
/**
- * Iterator over hash map entries that frees all entries
+ * Iterator over hash map entries that frees all entries
* associated with the given client.
*
* @param cls client to search for in source routes
return GNUNET_YES;
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing client %p's record for key %s\n",
- client,
- GNUNET_h2s (key));
+ "Removing client %p's record for key %s\n", client,
+ GNUNET_h2s (key));
#endif
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (forward_map,
- key, record));
+ GNUNET_CONTAINER_multihashmap_remove (forward_map, key,
+ record));
if (NULL != record->hnode)
GNUNET_CONTAINER_heap_remove_node (record->hnode);
- GNUNET_array_grow (record->seen_replies,
- record->seen_replies_count,
- 0);
+ GNUNET_array_grow (record->seen_replies, record->seen_replies_count, 0);
GNUNET_free (record);
return GNUNET_YES;
}
* for the last call when the server is destroyed
*/
static void
-handle_client_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client)
+handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct ClientList *pos;
struct PendingMessage *reply;
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Local client %p disconnects\n",
- client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Local client %p disconnects\n", client);
#endif
pos = find_active_client (client);
- GNUNET_CONTAINER_DLL_remove (client_head,
- client_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos);
if (pos->transmit_handle != NULL)
GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->transmit_handle);
while (NULL != (reply = pos->pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail,
- reply);
- GNUNET_free (reply);
- }
- GNUNET_CONTAINER_multihashmap_iterate (forward_map,
- &remove_client_records, pos);
+ {
+ GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, reply);
+ GNUNET_free (reply);
+ }
+ GNUNET_CONTAINER_multihashmap_iterate (forward_map, &remove_client_records,
+ pos);
GNUNET_free (pos);
}
/**
- * Route the given request via the DHT. This includes updating
+ * Route the given request via the DHT. This includes updating
* the bloom filter and retransmission times, building the P2P
* message and initiating the routing operation.
*/
struct GNUNET_CONTAINER_BloomFilter *peer_bf;
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# GET requests from clients injected"), 1,
+ gettext_noop
+ ("# GET requests from clients injected"), 1,
GNUNET_NO);
- reply_bf_mutator = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT32_MAX);
- reply_bf = GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator,
- cqr->seen_replies,
- cqr->seen_replies_count);
- peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
- DHT_BLOOM_SIZE,
- GNUNET_CONSTANTS_BLOOMFILTER_K);
- GDS_NEIGHBOURS_handle_get (cqr->type,
- cqr->msg_options,
- cqr->replication,
- 0 /* hop count */,
- &cqr->key,
- cqr->xquery,
- cqr->xquery_size,
- reply_bf,
- reply_bf_mutator,
- peer_bf);
+ reply_bf_mutator =
+ (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT32_MAX);
+ reply_bf =
+ GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, cqr->seen_replies,
+ cqr->seen_replies_count);
+ peer_bf =
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
+ GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication,
+ 0 /* hop count */ ,
+ &cqr->key, cqr->xquery, cqr->xquery_size, reply_bf,
+ reply_bf_mutator, peer_bf);
GNUNET_CONTAINER_bloomfilter_free (reply_bf);
GNUNET_CONTAINER_bloomfilter_free (peer_bf);
/* exponential back-off for retries, max 1h */
- cqr->retry_frequency =
- GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS,
- GNUNET_TIME_relative_multiply (cqr->retry_frequency, 2));
+ cqr->retry_frequency =
+ GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS,
+ GNUNET_TIME_relative_multiply
+ (cqr->retry_frequency, 2));
cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency);
}
*/
static void
transmit_next_request_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
+ {
+ cqr->hnode = NULL;
+ delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time);
+ if (delay.rel_value > 0)
{
- cqr->hnode = NULL;
- delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time);
- if (delay.rel_value > 0)
- {
- cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr,
- cqr->retry_time.abs_value);
- retry_task = GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_next_request_task,
- NULL);
- return;
- }
- transmit_request (cqr);
- cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr,
- cqr->retry_time.abs_value);
+ cqr->hnode =
+ GNUNET_CONTAINER_heap_insert (retry_heap, cqr,
+ cqr->retry_time.abs_value);
+ retry_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &transmit_next_request_task,
+ NULL);
+ return;
}
+ transmit_request (cqr);
+ cqr->hnode =
+ GNUNET_CONTAINER_heap_insert (retry_heap, cqr,
+ cqr->retry_time.abs_value);
+ }
}
*/
static void
handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ClientPutMessage *dht_msg;
struct GNUNET_CONTAINER_BloomFilter *peer_bf;
uint16_t size;
-
+
size = ntohs (message->size);
if (size < sizeof (struct GNUNET_DHT_ClientPutMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# PUT requests received from clients"), 1,
+ gettext_noop
+ ("# PUT requests received from clients"), 1,
GNUNET_NO);
dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message;
/* give to local clients */
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Handling local PUT of %u-bytes for query %s\n",
- size - sizeof (struct GNUNET_DHT_ClientPutMessage),
- GNUNET_h2s (&dht_msg->key));
+ "Handling local PUT of %u-bytes for query %s\n",
+ size - sizeof (struct GNUNET_DHT_ClientPutMessage),
+ GNUNET_h2s (&dht_msg->key));
#endif
GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
- &dht_msg->key,
- 0, NULL,
- 0, NULL,
- ntohl (dht_msg->type),
- size - sizeof (struct GNUNET_DHT_ClientPutMessage),
- &dht_msg[1]);
+ &dht_msg->key, 0, NULL, 0, NULL,
+ ntohl (dht_msg->type),
+ size - sizeof (struct GNUNET_DHT_ClientPutMessage),
+ &dht_msg[1]);
/* store locally */
GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
- &dht_msg->key,
- 0, NULL,
- ntohl (dht_msg->type),
- size - sizeof (struct GNUNET_DHT_ClientPutMessage),
- &dht_msg[1]);
+ &dht_msg->key, 0, NULL, ntohl (dht_msg->type),
+ size - sizeof (struct GNUNET_DHT_ClientPutMessage),
+ &dht_msg[1]);
/* route to other peers */
- peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
- DHT_BLOOM_SIZE,
- GNUNET_CONSTANTS_BLOOMFILTER_K);
- GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type),
- ntohl (dht_msg->options),
- ntohl (dht_msg->desired_replication_level),
- GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
- 0 /* hop count */,
- peer_bf,
- &dht_msg->key,
- 0, NULL,
- &dht_msg[1],
- size - sizeof (struct GNUNET_DHT_ClientPutMessage));
+ peer_bf =
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
+ GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), ntohl (dht_msg->options),
+ ntohl (dht_msg->desired_replication_level),
+ GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
+ 0 /* hop count */ ,
+ peer_bf, &dht_msg->key, 0, NULL, &dht_msg[1],
+ size -
+ sizeof (struct GNUNET_DHT_ClientPutMessage));
GNUNET_CONTAINER_bloomfilter_free (peer_bf);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
*/
static void
handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ClientGetMessage *get;
struct ClientQueryRecord *cqr;
size_t xquery_size;
- const char* xquery;
+ const char *xquery;
uint16_t size;
size = ntohs (message->size);
if (size < sizeof (struct GNUNET_DHT_ClientGetMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage);
get = (const struct GNUNET_DHT_ClientGetMessage *) message;
- xquery = (const char*) &get[1];
+ xquery = (const char *) &get[1];
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# GET requests received from clients"), 1,
+ gettext_noop
+ ("# GET requests received from clients"), 1,
GNUNET_NO);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received request for %s from local client %p\n",
- GNUNET_h2s (&get->key),
- client);
+ "Received request for %s from local client %p\n",
+ GNUNET_h2s (&get->key), client);
#endif
cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size);
cqr->key = get->key;
cqr->client = find_active_client (client);
- cqr->xquery = (void*) &cqr[1];
+ cqr->xquery = (void *) &cqr[1];
memcpy (&cqr[1], xquery, xquery_size);
- cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0);
+ cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0);
cqr->retry_frequency = GNUNET_TIME_UNIT_MILLISECONDS;
cqr->retry_time = GNUNET_TIME_absolute_get ();
cqr->unique_id = get->unique_id;
cqr->xquery_size = xquery_size;
cqr->replication = ntohl (get->desired_replication_level);
cqr->msg_options = ntohl (get->options);
- cqr->type = ntohl (get->type);
+ cqr->type = ntohl (get->type);
GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
/* start remote requests */
if (GNUNET_SCHEDULER_NO_TASK != retry_task)
GNUNET_SCHEDULER_cancel (retry_task);
retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL);
/* perform local lookup */
- GDS_DATACACHE_handle_get (&get->key,
- cqr->type,
- cqr->xquery,
- xquery_size,
- NULL, 0);
+ GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size,
+ NULL, 0);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
/**
- * Iterator over hash map entries that frees all entries
+ * Iterator over hash map entries that frees all entries
* that match the given client and unique ID.
*
* @param cls unique ID and client to search for in source routes
return GNUNET_YES;
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing client %p's record for key %s (by unique id)\n",
- ctx->client->client_handle,
- GNUNET_h2s (key));
+ "Removing client %p's record for key %s (by unique id)\n",
+ ctx->client->client_handle, GNUNET_h2s (key));
#endif
return remove_client_records (ctx->client, key, record);
}
*/
static void
handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg =
- (const struct GNUNET_DHT_ClientGetStopMessage *) message;
+ (const struct GNUNET_DHT_ClientGetStopMessage *) message;
struct RemoveByUniqueIdContext ctx;
-
+
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# GET STOP requests received from clients"), 1,
+ gettext_noop
+ ("# GET STOP requests received from clients"), 1,
GNUNET_NO);
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p stopped request for key %s\n",
- client,
- GNUNET_h2s (&dht_stop_msg->key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p stopped request for key %s\n",
+ client, GNUNET_h2s (&dht_stop_msg->key));
#endif
ctx.client = find_active_client (client);
ctx.unique_id = dht_stop_msg->unique_id;
- GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
- &dht_stop_msg->key,
- &remove_by_unique_id,
- &ctx);
+ GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, &dht_stop_msg->key,
+ &remove_by_unique_id, &ctx);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
/* client disconnected */
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected, pending messages will be discarded\n",
- client->client_handle);
+ "Client %p disconnected, pending messages will be discarded\n",
+ client->client_handle);
#endif
return 0;
}
memcpy (&cbuf[off], reply->msg, msize);
GNUNET_free (reply);
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting %u bytes to client %p\n",
- msize,
- client->client_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n",
+ msize, client->client_handle);
#endif
off += msize;
}
process_pending_messages (client);
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitted %u/%u bytes to client %p\n",
- (unsigned int) off,
- (unsigned int) size,
- client->client_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n",
+ (unsigned int) off, (unsigned int) size, client->client_handle);
#endif
return off;
}
{
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not asking for transmission to %p now: %s\n",
- client->client_handle,
- client->pending_head == NULL
- ? "no more messages"
- : "request already pending");
+ "Not asking for transmission to %p now: %s\n",
+ client->client_handle,
+ client->pending_head ==
+ NULL ? "no more messages" : "request already pending");
#endif
return;
}
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking for transmission of %u bytes to client %p\n",
- ntohs (client->pending_head->
- msg->size),
- client->client_handle);
+ "Asking for transmission of %u bytes to client %p\n",
+ ntohs (client->pending_head->msg->size), client->client_handle);
#endif
client->transmit_handle =
GNUNET_SERVER_notify_transmit_ready (client->client_handle,
struct PendingMessage *pending_message)
{
GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail,
- pending_message);
+ pending_message);
process_pending_messages (client);
}
{
/**
- * Actual message to send to matching clients.
+ * Actual message to send to matching clients.
*/
struct PendingMessage *pm;
int do_free;
GNUNET_HashCode ch;
unsigned int i;
-
- if ( (record->type != GNUNET_BLOCK_TYPE_ANY) &&
- (record->type != frc->type) )
+
+ if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type))
+ {
+#if DEBUG_DHT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Record type missmatch, not passing request for key %s to local client\n",
+ GNUNET_h2s (key));
+#endif
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop
+ ("# Key match, type mismatches in REPLY to CLIENT"),
+ 1, GNUNET_NO);
+ return GNUNET_YES; /* type mismatch */
+ }
+ GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch);
+ for (i = 0; i < record->seen_replies_count; i++)
+ if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (GNUNET_HashCode)))
{
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Record type missmatch, not passing request for key %s to local client\n",
- GNUNET_h2s (key));
+ "Duplicate reply, not passing request for key %s to local client\n",
+ GNUNET_h2s (key));
#endif
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Key match, type mismatches in REPLY to CLIENT"), 1,
- GNUNET_NO);
- return GNUNET_YES; /* type mismatch */
+ gettext_noop
+ ("# Duplicate REPLIES to CLIENT request dropped"),
+ 1, GNUNET_NO);
+ return GNUNET_YES; /* duplicate */
}
- GNUNET_CRYPTO_hash (frc->data,
- frc->data_size,
- &ch);
- for (i=0;i<record->seen_replies_count;i++)
- if (0 == memcmp (&record->seen_replies[i],
- &ch,
- sizeof (GNUNET_HashCode)))
- {
-#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Duplicate reply, not passing request for key %s to local client\n",
- GNUNET_h2s (key));
-#endif
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Duplicate REPLIES to CLIENT request dropped"), 1,
- GNUNET_NO);
- return GNUNET_YES; /* duplicate */
- }
eval =
- GNUNET_BLOCK_evaluate (GDS_block_context,
- record->type, key,
- NULL, 0,
- record->xquery,
- record->xquery_size,
- frc->data,
- frc->data_size);
+ GNUNET_BLOCK_evaluate (GDS_block_context, record->type, key, NULL, 0,
+ record->xquery, record->xquery_size, frc->data,
+ frc->data_size);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Evaluation result is %d for key %s for local client's query\n",
- (int) eval,
- GNUNET_h2s (key));
+ "Evaluation result is %d for key %s for local client's query\n",
+ (int) eval, GNUNET_h2s (key));
#endif
switch (eval)
{
do_free = GNUNET_YES;
break;
case GNUNET_BLOCK_EVALUATION_OK_MORE:
- GNUNET_array_append (record->seen_replies,
- record->seen_replies_count,
- ch);
+ GNUNET_array_append (record->seen_replies, record->seen_replies_count, ch);
do_free = GNUNET_NO;
break;
case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
return GNUNET_NO;
case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Unsupported block type (%u) in request!\n"),
- record->type);
+ _("Unsupported block type (%u) in request!\n"), record->type);
return GNUNET_NO;
default:
GNUNET_break (0);
return GNUNET_NO;
}
if (GNUNET_NO == frc->do_copy)
- {
- /* first time, we can use the original data */
- pm = frc->pm;
- frc->do_copy = GNUNET_YES;
- }
+ {
+ /* first time, we can use the original data */
+ pm = frc->pm;
+ frc->do_copy = GNUNET_YES;
+ }
else
- {
- /* two clients waiting for same reply, must copy for queueing */
- pm = GNUNET_malloc (sizeof (struct PendingMessage) +
- ntohs (frc->pm->msg->size));
- memcpy (pm, frc->pm,
- sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size));
- pm->next = pm->prev = NULL;
- }
+ {
+ /* two clients waiting for same reply, must copy for queueing */
+ pm = GNUNET_malloc (sizeof (struct PendingMessage) +
+ ntohs (frc->pm->msg->size));
+ memcpy (pm, frc->pm,
+ sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size));
+ pm->next = pm->prev = NULL;
+ }
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop ("# RESULTS queued for clients"), 1,
GNUNET_NO);
- reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1];
+ reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
reply->unique_id = record->unique_id;
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing reply to query %s for client %p\n",
- GNUNET_h2s (key),
- record->client->client_handle);
+ "Queueing reply to query %s for client %p\n", GNUNET_h2s (key),
+ record->client->client_handle);
#endif
add_pending_message (record->client, pm);
if (GNUNET_YES == do_free)
*/
void
GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
- const GNUNET_HashCode *key,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t data_size,
- const void *data)
+ const GNUNET_HashCode * key,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ enum GNUNET_BLOCK_Type type, size_t data_size,
+ const void *data)
{
struct ForwardReplyContext frc;
struct PendingMessage *pm;
struct GNUNET_PeerIdentity *paths;
size_t msize;
- if (NULL ==
- GNUNET_CONTAINER_multihashmap_get (forward_map, key))
+ if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key))
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1,
- GNUNET_NO);
- return; /* no matching request, fast exit! */
+ gettext_noop
+ ("# REPLIES ignored for CLIENTS (no match)"), 1,
+ GNUNET_NO);
+ return; /* no matching request, fast exit! */
}
- msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size +
- (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity);
+ msize =
+ sizeof (struct GNUNET_DHT_ClientResultMessage) + data_size +
+ (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity);
if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not pass reply to client, message too big!\n"));
- return;
- }
- pm = (struct PendingMessage *) GNUNET_malloc (msize + sizeof (struct PendingMessage));
- reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1];
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not pass reply to client, message too big!\n"));
+ return;
+ }
+ pm = (struct PendingMessage *) GNUNET_malloc (msize +
+ sizeof (struct PendingMessage));
+ reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
pm->msg = &reply->header;
reply->header.size = htons ((uint16_t) msize);
reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT);
reply->type = htonl (type);
reply->get_path_length = htonl (get_path_length);
reply->put_path_length = htonl (put_path_length);
- reply->unique_id = 0; /* filled in later */
+ reply->unique_id = 0; /* filled in later */
reply->expiration = GNUNET_TIME_absolute_hton (expiration);
reply->key = *key;
- paths = (struct GNUNET_PeerIdentity*) &reply[1];
- memcpy (paths, put_path,
- sizeof (struct GNUNET_PeerIdentity) * put_path_length);
- memcpy (&paths[put_path_length],
- get_path, sizeof (struct GNUNET_PeerIdentity) * get_path_length);
- memcpy (&paths[get_path_length + put_path_length],
- data,
- data_size);
+ paths = (struct GNUNET_PeerIdentity *) &reply[1];
+ memcpy (paths, put_path,
+ sizeof (struct GNUNET_PeerIdentity) * put_path_length);
+ memcpy (&paths[put_path_length], get_path,
+ sizeof (struct GNUNET_PeerIdentity) * get_path_length);
+ memcpy (&paths[get_path_length + put_path_length], data, data_size);
frc.do_copy = GNUNET_NO;
frc.pm = pm;
frc.data = data;
frc.data_size = data_size;
frc.type = type;
- GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key,
- &forward_reply,
- &frc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply,
+ &frc);
if (GNUNET_NO == frc.do_copy)
- {
- /* did not match any of the requests, free! */
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1,
- GNUNET_NO);
- GNUNET_free (pm);
- }
+ {
+ /* did not match any of the requests, free! */
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop
+ ("# REPLIES ignored for CLIENTS (no match)"), 1,
+ GNUNET_NO);
+ GNUNET_free (pm);
+ }
}
*
* @param server the initialized server
*/
-void
+void
GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
{
static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
- {&handle_dht_local_put, NULL,
+ {&handle_dht_local_put, NULL,
GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0},
- {&handle_dht_local_get, NULL,
+ {&handle_dht_local_get, NULL,
GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0},
{&handle_dht_local_get_stop, NULL,
- GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP,
- sizeof (struct GNUNET_DHT_ClientGetStopMessage) },
+ GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP,
+ sizeof (struct GNUNET_DHT_ClientGetStopMessage)},
{NULL, NULL, 0, 0}
};
forward_map = GNUNET_CONTAINER_multihashmap_create (1024);
GNUNET_assert (client_head == NULL);
GNUNET_assert (client_tail == NULL);
if (GNUNET_SCHEDULER_NO_TASK != retry_task)
- {
- GNUNET_SCHEDULER_cancel (retry_task);
- retry_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (retry_task);
+ retry_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap));
GNUNET_CONTAINER_heap_destroy (retry_heap);
retry_heap = NULL;
}
/* end of gnunet-service-dht_clients.c */
-
*/
void
GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
- const GNUNET_HashCode *key,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t data_size,
- const void *data);
+ const GNUNET_HashCode * key,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ enum GNUNET_BLOCK_Type type, size_t data_size,
+ const void *data);
/**
*
* @param server the initialized server
*/
-void
+void
GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server);
*/
void
GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t data_size,
- const void *data)
+ const GNUNET_HashCode * key,
+ unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ enum GNUNET_BLOCK_Type type, size_t data_size,
+ const void *data)
{
- size_t plen = data_size + put_path_length * sizeof(struct GNUNET_PeerIdentity) + sizeof(struct DHTPutEntry);
+ size_t plen =
+ data_size + put_path_length * sizeof (struct GNUNET_PeerIdentity) +
+ sizeof (struct DHTPutEntry);
char buf[plen];
struct DHTPutEntry *pe;
struct GNUNET_PeerIdentity *pp;
if (datacache == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("%s request received, but have no datacache!\n"),
- "PUT");
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("%s request received, but have no datacache!\n"), "PUT");
+ return;
+ }
if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
/* Put size is actual data size plus struct overhead plus path length (if any) */
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# ITEMS stored in datacache"), 1,
- GNUNET_NO);
+ gettext_noop ("# ITEMS stored in datacache"), 1,
+ GNUNET_NO);
pe = (struct DHTPutEntry *) buf;
pe->data_size = htons (data_size);
pe->path_length = htons ((uint16_t) put_path_length);
pp = (struct GNUNET_PeerIdentity *) &pe[1];
memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity));
- memcpy (&pp[put_path_length],
- data, data_size);
- (void) GNUNET_DATACACHE_put (datacache, key,
- plen, (const char *) pe, type,
- expiration);
+ memcpy (&pp[put_path_length], data, data_size);
+ (void) GNUNET_DATACACHE_put (datacache, key, plen, (const char *) pe, type,
+ expiration);
}
return GNUNET_OK;
}
pp = (const struct GNUNET_PeerIdentity *) &pe[1];
- rdata = (const char*) &pp[put_path_length];
+ rdata = (const char *) &pp[put_path_length];
eval =
- GNUNET_BLOCK_evaluate (GDS_block_context, type, key,
- ctx->reply_bf,
- ctx->reply_bf_mutator,
- ctx->xquery,
- ctx->xquery_size,
- rdata,
- rdata_size);
+ GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf,
+ ctx->reply_bf_mutator, ctx->xquery,
+ ctx->xquery_size, rdata, rdata_size);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found reply for query %s in datacache, evaluation result is %d\n",
- GNUNET_h2s (key),
- (int) eval);
+ "Found reply for query %s in datacache, evaluation result is %d\n",
+ GNUNET_h2s (key), (int) eval);
#endif
ctx->eval = eval;
switch (eval)
case GNUNET_BLOCK_EVALUATION_OK_MORE:
/* forward to local clients */
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Good RESULTS found in datacache"), 1,
- GNUNET_NO);
- GDS_CLIENTS_handle_reply (exp,
- key,
- 0, NULL,
- put_path_length, pp,
- type, rdata_size, rdata);
+ gettext_noop
+ ("# Good RESULTS found in datacache"), 1,
+ GNUNET_NO);
+ GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, pp, type,
+ rdata_size, rdata);
/* forward to other peers */
- GDS_ROUTING_process (type, exp,
- key, put_path_length, pp,
- 0, NULL, rdata, rdata_size);
+ GDS_ROUTING_process (type, exp, key, put_path_length, pp, 0, NULL, rdata,
+ rdata_size);
break;
case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Duplicate RESULTS found in datacache"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Duplicate RESULTS found in datacache"), 1,
+ GNUNET_NO);
break;
case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Invalid RESULTS found in datacache"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Invalid RESULTS found in datacache"), 1,
+ GNUNET_NO);
break;
case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
GNUNET_break (0);
return GNUNET_SYSERR;
case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Unsupported RESULTS found in datacache"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Unsupported RESULTS found in datacache"), 1,
+ GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Unsupported block type (%u) in local response!\n"),
- type);
+ _("Unsupported block type (%u) in local response!\n"), type);
break;
}
return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK;
/**
* Handle a GET request we've received from another peer.
*
- * @param key the query
+ * @param key the query
* @param type requested data type
* @param xquery extended query
* @param xquery_size number of bytes in xquery
* @return evaluation result for the local replies
*/
enum GNUNET_BLOCK_EvaluationResult
-GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
- enum GNUNET_BLOCK_Type type,
- const void *xquery,
- size_t xquery_size,
- struct GNUNET_CONTAINER_BloomFilter **reply_bf,
- uint32_t reply_bf_mutator)
+GDS_DATACACHE_handle_get (const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type, const void *xquery,
+ size_t xquery_size,
+ struct GNUNET_CONTAINER_BloomFilter **reply_bf,
+ uint32_t reply_bf_mutator)
{
struct GetRequestContext ctx;
if (datacache == NULL)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# GET requests given to datacache"), 1,
- GNUNET_NO);
+ gettext_noop ("# GET requests given to datacache"),
+ 1, GNUNET_NO);
ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
ctx.key = *key;
ctx.xquery = xquery;
ctx.xquery_size = xquery_size;
ctx.reply_bf = reply_bf;
ctx.reply_bf_mutator = reply_bf_mutator;
- (void) GNUNET_DATACACHE_get (datacache, key, type,
- &datacache_get_iterator, &ctx);
+ (void) GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator,
+ &ctx);
return ctx.eval;
}
/**
* Initialize datacache subsystem.
*/
-void
+void
GDS_DATACACHE_init ()
{
datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache");
*/
void
GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- enum GNUNET_BLOCK_Type type,
- size_t data_size,
- const void *data);
+ const GNUNET_HashCode * key,
+ unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ enum GNUNET_BLOCK_Type type, size_t data_size,
+ const void *data);
/**
* Handle a GET request we've received from another peer.
*
- * @param key the query
+ * @param key the query
* @param type requested data type
* @param xquery extended query
* @param xquery_size number of bytes in xquery
* @param reply_bf_mutator mutation value for reply_bf
* @return evaluation result for the local replies
*/
-enum GNUNET_BLOCK_EvaluationResult
-GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
- enum GNUNET_BLOCK_Type type,
- const void *xquery,
- size_t xquery_size,
- struct GNUNET_CONTAINER_BloomFilter **reply_bf,
- uint32_t reply_bf_mutator);
+enum GNUNET_BLOCK_EvaluationResult
+GDS_DATACACHE_handle_get (const GNUNET_HashCode * key,
+ enum GNUNET_BLOCK_Type type, const void *xquery,
+ size_t xquery_size,
+ struct GNUNET_CONTAINER_BloomFilter **reply_bf,
+ uint32_t reply_bf_mutator);
/**
* Initialize datacache subsystem.
*/
-void
+void
GDS_DATACACHE_init (void);
{
if (NULL == peer_to_hello)
return NULL;
- return GNUNET_CONTAINER_multihashmap_get (peer_to_hello,
- &peer->hashPubKey);
+ return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey);
}
* @param error message
*/
static void
-process_hello (void *cls,
- const struct GNUNET_PeerIdentity *
- peer,
- const struct GNUNET_HELLO_Message *
- hello, const char *err_msg)
+process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
struct GNUNET_TIME_Absolute ex;
struct GNUNET_HELLO_Message *hm;
if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0)
return;
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# HELLOs obtained from peerinfo"), 1,
- GNUNET_NO);
- hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello,
- &peer->hashPubKey);
+ gettext_noop ("# HELLOs obtained from peerinfo"), 1,
+ GNUNET_NO);
+ hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey);
GNUNET_free_non_null (hm);
hm = GNUNET_malloc (GNUNET_HELLO_size (hello));
memcpy (hm, hello, GNUNET_HELLO_size (hello));
GNUNET_assert (GNUNET_SYSERR !=
- GNUNET_CONTAINER_multihashmap_put (peer_to_hello,
- &peer->hashPubKey,
- hm,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
+ GNUNET_CONTAINER_multihashmap_put (peer_to_hello,
+ &peer->hashPubKey, hm,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
}
void
GDS_HELLO_init ()
{
- pnc = GNUNET_PEERINFO_notify (GDS_cfg,
- &process_hello,
- NULL);
+ pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL);
peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256);
}
* Free memory occopied by the HELLO.
*/
static int
-free_hello (void *cls,
- const GNUNET_HashCode *key,
- void *hello)
+free_hello (void *cls, const GNUNET_HashCode * key, void *hello)
{
GNUNET_free (hello);
return GNUNET_OK;
}
if (NULL != peer_to_hello)
{
- GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello,
- &free_hello,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, &free_hello, NULL);
GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello);
}
}
/**
* Actual message to be sent, allocated at the end of the struct:
- * // msg = (cast) &pm[1];
+ * // msg = (cast) &pm[1];
* // memcpy (&pm[1], data, len);
*/
const struct GNUNET_MessageHeader *msg;
/**
* Identity of this peer.
- */
+ */
static struct GNUNET_PeerIdentity my_identity;
/**
bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc);
if (bits == MAX_BUCKETS)
- {
- /* How can all bits match? Got my own ID? */
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ /* How can all bits match? Got my own ID? */
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return MAX_BUCKETS - bits - 1;
}
*
* @param cls the 'struct PeerInfo' of the peer
* @param tc scheduler context.
- */
+ */
static void
update_core_preference (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
peer->preference_task = GNUNET_SCHEDULER_NO_TASK;
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+ return;
matching =
- GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
- &peer->id.hashPubKey);
+ GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
+ &peer->id.hashPubKey);
if (matching >= 64)
matching = 63;
bucket = find_bucket (&peer->id.hashPubKey);
preference = (1LL << matching) / k_buckets[bucket].peers_size;
}
if (preference == 0)
- {
- peer->preference_task
- = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
- &update_core_preference, peer);
- return;
- }
+ {
+ peer->preference_task =
+ GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
+ &update_core_preference, peer);
+ return;
+ }
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Preference updates given to core"), 1,
- GNUNET_NO);
+ gettext_noop ("# Preference updates given to core"),
+ 1, GNUNET_NO);
GNUNET_ATS_change_preference (atsAPI, &peer->id,
- GNUNET_ATS_PREFERENCE_BANDWIDTH,
- (double) preference,
- GNUNET_ATS_PREFERENCE_END);
- peer->preference_task
- = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
- &update_core_preference, peer);
+ GNUNET_ATS_PREFERENCE_BANDWIDTH,
+ (double) preference, GNUNET_ATS_PREFERENCE_END);
+ peer->preference_task =
+ GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
+ &update_core_preference, peer);
}
GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n",
- GNUNET_h2s (key),
- ctx->bf_mutator);
+ "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n",
+ GNUNET_h2s (key), ctx->bf_mutator);
#endif
GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh);
return GNUNET_YES;
find_peer_task = GNUNET_SCHEDULER_NO_TASK;
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- if (newly_found_peers > bucket_size)
+ if (newly_found_peers > bucket_size)
{
/* If we are finding many peers already, no need to send out our request right now! */
- find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &send_find_peer_message, NULL);
+ find_peer_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &send_find_peer_message, NULL);
newly_found_peers = 0;
return;
}
- bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+ bcc.bf_mutator =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
bcc.bloom =
- GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K);
- GNUNET_CONTAINER_multihashmap_iterate (all_known_peers,
- &add_known_to_bloom,
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
+ GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom,
&bcc);
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# FIND PEER messages initiated"), 1,
- GNUNET_NO);
- peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
- DHT_BLOOM_SIZE,
- GNUNET_CONSTANTS_BLOOMFILTER_K);
+ gettext_noop ("# FIND PEER messages initiated"), 1,
+ GNUNET_NO);
+ peer_bf =
+ GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
// FIXME: pass priority!?
GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO,
- GNUNET_DHT_RO_FIND_PEER,
- FIND_PEER_REPLICATION_LEVEL,
- 0,
- &my_identity.hashPubKey,
- NULL, 0,
- bcc.bloom, bcc.bf_mutator,
- peer_bf);
+ GNUNET_DHT_RO_FIND_PEER,
+ FIND_PEER_REPLICATION_LEVEL, 0,
+ &my_identity.hashPubKey, NULL, 0, bcc.bloom,
+ bcc.bf_mutator, peer_bf);
GNUNET_CONTAINER_bloomfilter_free (peer_bf);
GNUNET_CONTAINER_bloomfilter_free (bcc.bloom);
/* schedule next round */
next_send_time.rel_value =
- DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
- GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1));
+ DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
+ (newly_found_peers + 1));
newly_found_peers = 0;
- find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time,
- &send_find_peer_message,
- NULL);
+ find_peer_task =
+ GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message,
+ NULL);
}
static void
handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct PeerInfo *ret;
int peer_bucket;
if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected %s to %s\n",
- GNUNET_i2s (&my_identity),
- GNUNET_h2s (&peer->hashPubKey));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n",
+ GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey));
#endif
if (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
GNUNET_break (0);
return;
}
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Peers connected"), 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), 1,
+ GNUNET_NO);
peer_bucket = find_bucket (&peer->hashPubKey);
- GNUNET_assert ( (peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS) );
+ GNUNET_assert ((peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS));
ret = GNUNET_malloc (sizeof (struct PeerInfo));
#if 0
ret->latency = latency;
#endif
ret->id = *peer;
GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head,
- k_buckets[peer_bucket].tail, ret);
+ k_buckets[peer_bucket].tail, ret);
k_buckets[peer_bucket].peers_size++;
- closest_bucket = GNUNET_MAX (closest_bucket,
- peer_bucket);
- if ( (peer_bucket > 0) &&
- (k_buckets[peer_bucket].peers_size <= bucket_size) )
+ closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket);
+ if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size))
{
- ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret);
+ ret->preference_task =
+ GNUNET_SCHEDULER_add_now (&update_core_preference, ret);
newly_found_peers++;
}
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (all_known_peers,
- &peer->hashPubKey, ret,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (all_known_peers,
+ &peer->hashPubKey, ret,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers))
{
/* got a first connection, good time to start with FIND PEER requests... */
- find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message,
- NULL);
+ find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL);
}
}
if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnected %s from %s\n",
- GNUNET_i2s (&my_identity),
- GNUNET_h2s (&peer->hashPubKey));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n",
+ GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey));
#endif
to_remove =
GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey);
if (NULL == to_remove)
- {
- GNUNET_break (0);
- return;
- }
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Peers connected"), -1,
- GNUNET_NO);
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), -1,
+ GNUNET_NO);
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (all_known_peers,
&peer->hashPubKey,
current_bucket = find_bucket (&to_remove->id.hashPubKey);
GNUNET_assert (current_bucket >= 0);
GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head,
- k_buckets[current_bucket].tail,
- to_remove);
+ k_buckets[current_bucket].tail, to_remove);
GNUNET_assert (k_buckets[current_bucket].peers_size > 0);
k_buckets[current_bucket].peers_size--;
- while ( (closest_bucket > 0) &&
- (k_buckets[closest_bucket].peers_size == 0) )
+ while ((closest_bucket > 0) && (k_buckets[closest_bucket].peers_size == 0))
closest_bucket--;
- if (to_remove->th != NULL)
+ if (to_remove->th != NULL)
{
GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th);
to_remove->th = NULL;
discarded = 0;
while (NULL != (pos = to_remove->head))
{
- GNUNET_CONTAINER_DLL_remove (to_remove->head,
- to_remove->tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (to_remove->head, to_remove->tail, pos);
discarded++;
GNUNET_free (pos);
}
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Queued messages discarded (peer disconnected)"), discarded,
- GNUNET_NO);
+ gettext_noop
+ ("# Queued messages discarded (peer disconnected)"),
+ discarded, GNUNET_NO);
GNUNET_free (to_remove);
}
size_t msize;
peer->th = NULL;
- while ( (NULL != (pending = peer->head)) &&
- (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0) )
+ while ((NULL != (pending = peer->head)) &&
+ (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0))
{
peer->pending_count--;
GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
}
if (buf == NULL)
{
- peer->th
- = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
- pending->importance,
- GNUNET_TIME_absolute_get_remaining (pending->timeout),
- &peer->id, ntohs (pending->msg->size),
- &core_transmit_notify, peer);
+ peer->th =
+ GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
+ pending->importance,
+ GNUNET_TIME_absolute_get_remaining
+ (pending->timeout), &peer->id,
+ ntohs (pending->msg->size),
+ &core_transmit_notify, peer);
GNUNET_break (NULL != peer->th);
return 0;
}
off = 0;
- while ( (NULL != (pending = peer->head)) &&
- (size - off >= (msize = ntohs (pending->msg->size))) )
+ while ((NULL != (pending = peer->head)) &&
+ (size - off >= (msize = ntohs (pending->msg->size))))
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Bytes transmitted to other peers"), msize,
- GNUNET_NO);
+ gettext_noop
+ ("# Bytes transmitted to other peers"), msize,
+ GNUNET_NO);
memcpy (&cbuf[off], pending->msg, msize);
off += msize;
peer->pending_count--;
}
if (peer->head != NULL)
{
- peer->th
- = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
- pending->importance,
- GNUNET_TIME_absolute_get_remaining (pending->timeout),
- &peer->id, msize,
- &core_transmit_notify, peer);
+ peer->th =
+ GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
+ pending->importance,
+ GNUNET_TIME_absolute_get_remaining
+ (pending->timeout), &peer->id, msize,
+ &core_transmit_notify, peer);
GNUNET_break (NULL != peer->th);
}
return off;
if (NULL != peer->th)
return;
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Bytes of bandwdith requested from core"),
- ntohs (pending->msg->size),
- GNUNET_NO);
- peer->th
- = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
- pending->importance,
- GNUNET_TIME_absolute_get_remaining (pending->timeout),
- &peer->id,
- ntohs (pending->msg->size),
- &core_transmit_notify, peer);
+ gettext_noop
+ ("# Bytes of bandwdith requested from core"),
+ ntohs (pending->msg->size), GNUNET_NO);
+ peer->th =
+ GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
+ pending->importance,
+ GNUNET_TIME_absolute_get_remaining
+ (pending->timeout), &peer->id,
+ ntohs (pending->msg->size),
+ &core_transmit_notify, peer);
GNUNET_break (NULL != peer->th);
}
* @return Some number of peers to forward the message to
*/
static unsigned int
-get_forward_count (uint32_t hop_count,
- uint32_t target_replication)
+get_forward_count (uint32_t hop_count, uint32_t target_replication)
{
uint32_t random_value;
uint32_t forward_count;
return 1;
}
/* bound by system-wide maximum */
- target_replication = GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL,
- target_replication);
+ target_replication =
+ GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication);
target_value =
- 1 + (target_replication - 1.0) / (GDS_NSE_get () +
- ((float) (target_replication - 1.0) *
- hop_count));
+ 1 + (target_replication - 1.0) / (GDS_NSE_get () +
+ ((float) (target_replication - 1.0) *
+ hop_count));
/* Set forward count to floor of target_value */
forward_count = (uint32_t) target_value;
/* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
target_value = target_value - forward_count;
random_value =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
if (random_value < (target_value * UINT32_MAX))
forward_count++;
return forward_count;
* GNUNET_NO otherwise.
*/
static int
-am_closest_peer (const GNUNET_HashCode *key,
+am_closest_peer (const GNUNET_HashCode * key,
const struct GNUNET_CONTAINER_BloomFilter *bloom)
{
int bits;
other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key);
if (other_bits > bits)
return GNUNET_NO;
- if (other_bits == bits) /* We match the same number of bits */
+ if (other_bits == bits) /* We match the same number of bits */
return GNUNET_YES;
pos = pos->next;
}
* exponentially declining probability.
*
* FIXME: double-check that this is fine
- *
+ *
*
* @param key the key we are selecting a peer to route to
* @param bloom a bloomfilter containing entries this request has seen already
* @return Peer to route to, or NULL on error
*/
static struct PeerInfo *
-select_peer (const GNUNET_HashCode *key,
- const struct GNUNET_CONTAINER_BloomFilter *bloom,
- uint32_t hops)
+select_peer (const GNUNET_HashCode * key,
+ const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops)
{
unsigned int bc;
unsigned int count;
count = 0;
while ((pos != NULL) && (count < bucket_size))
{
- if ( (bloom == NULL) ||
- (GNUNET_NO ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
- {
+ if ((bloom == NULL) ||
+ (GNUNET_NO ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
+ {
dist = get_distance (key, &pos->id.hashPubKey);
if (dist < smallest_distance)
{
}
}
else
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Excluded peer `%s' due to BF match in greedy routing for %s\n",
- GNUNET_i2s (&pos->id),
- GNUNET_h2s (key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Excluded peer `%s' due to BF match in greedy routing for %s\n",
+ GNUNET_i2s (&pos->id), GNUNET_h2s (key));
#endif
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1,
- GNUNET_NO);
- }
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop
+ ("# Peers excluded from routing due to Bloomfilter"),
+ 1, GNUNET_NO);
+ }
count++;
pos = pos->next;
}
}
if (NULL == chosen)
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Peer selection failed"), 1,
- GNUNET_NO);
+ gettext_noop ("# Peer selection failed"), 1,
+ GNUNET_NO);
return chosen;
}
pos = k_buckets[bc].head;
while ((pos != NULL) && (count < bucket_size))
{
- if ( (bloom != NULL) &&
- (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
+ if ((bloom != NULL) &&
+ (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
{
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop
+ ("# Peers excluded from routing due to Bloomfilter"),
+ 1, GNUNET_NO);
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Excluded peer `%s' due to BF match in random routing for %s\n",
- GNUNET_i2s (&pos->id),
- GNUNET_h2s (key));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Excluded peer `%s' due to BF match in random routing for %s\n",
+ GNUNET_i2s (&pos->id), GNUNET_h2s (key));
#endif
pos = pos->next;
continue; /* Ignore bloomfiltered peers */
if (count == 0) /* No peers to select from! */
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Peer selection failed"), 1,
- GNUNET_NO);
+ gettext_noop ("# Peer selection failed"), 1,
+ GNUNET_NO);
return NULL;
}
/* Now actually choose a peer */
pos = k_buckets[bc].head;
while ((pos != NULL) && (count < bucket_size))
{
- if ( (bloom != NULL) &&
- (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
+ if ((bloom != NULL) &&
+ (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
{
pos = pos->next;
continue; /* Ignore bloomfiltered peers */
* @return number of peers returned in 'targets'.
*/
static unsigned int
-get_target_peers (const GNUNET_HashCode *key,
- struct GNUNET_CONTAINER_BloomFilter *bloom,
- uint32_t hop_count,
- uint32_t target_replication,
- struct PeerInfo ***targets)
+get_target_peers (const GNUNET_HashCode * key,
+ struct GNUNET_CONTAINER_BloomFilter *bloom,
+ uint32_t hop_count, uint32_t target_replication,
+ struct PeerInfo ***targets)
{
unsigned int ret;
unsigned int off;
*targets = NULL;
return 0;
}
- rtargets = GNUNET_malloc (sizeof (struct PeerInfo*) * ret);
+ rtargets = GNUNET_malloc (sizeof (struct PeerInfo *) * ret);
for (off = 0; off < ret; off++)
{
nxt = select_peer (key, bloom, hop_count);
if (nxt == NULL)
- break;
+ break;
rtargets[off] = nxt;
GNUNET_break (GNUNET_NO ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey));
+ GNUNET_CONTAINER_bloomfilter_test (bloom,
+ &nxt->id.hashPubKey));
GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey);
}
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Selected %u/%u peers at hop %u for %s (target was %u)\n",
- off,
- GNUNET_CONTAINER_multihashmap_size (all_known_peers),
- (unsigned int) hop_count,
- GNUNET_h2s (key),
- ret);
+ "Selected %u/%u peers at hop %u for %s (target was %u)\n", off,
+ GNUNET_CONTAINER_multihashmap_size (all_known_peers),
+ (unsigned int) hop_count, GNUNET_h2s (key), ret);
#endif
if (0 == off)
{
*/
void
GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
- enum GNUNET_DHT_RouteOption options,
- uint32_t desired_replication_level,
- struct GNUNET_TIME_Absolute expiration_time,
- uint32_t hop_count,
- struct GNUNET_CONTAINER_BloomFilter *bf,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- struct GNUNET_PeerIdentity *put_path,
- const void *data,
- size_t data_size)
+ enum GNUNET_DHT_RouteOption options,
+ uint32_t desired_replication_level,
+ struct GNUNET_TIME_Absolute expiration_time,
+ uint32_t hop_count,
+ struct GNUNET_CONTAINER_BloomFilter *bf,
+ const GNUNET_HashCode * key,
+ unsigned int put_path_length,
+ struct GNUNET_PeerIdentity *put_path,
+ const void *data, size_t data_size)
{
unsigned int target_count;
unsigned int i;
size_t msize;
struct PeerPutMessage *ppm;
struct GNUNET_PeerIdentity *pp;
-
+
GNUNET_assert (NULL != bf);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding myself (%s) to PUT bloomfilter for %s\n",
- GNUNET_i2s (&my_identity),
- GNUNET_h2s (key));
+ "Adding myself (%s) to PUT bloomfilter for %s\n",
+ GNUNET_i2s (&my_identity), GNUNET_h2s (key));
#endif
GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey);
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# PUT requests routed"), 1,
- GNUNET_NO);
- target_count = get_target_peers (key, bf, hop_count,
- desired_replication_level,
- &targets);
+ GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"),
+ 1, GNUNET_NO);
+ target_count =
+ get_target_peers (key, bf, hop_count, desired_replication_level,
+ &targets);
if (0 == target_count)
- {
+ {
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Routing PUT for %s terminates after %u hops at %s\n",
- GNUNET_h2s (key),
- (unsigned int) hop_count,
- GNUNET_i2s (&my_identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Routing PUT for %s terminates after %u hops at %s\n",
+ GNUNET_h2s (key), (unsigned int) hop_count,
+ GNUNET_i2s (&my_identity));
#endif
- return;
- }
- msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage);
+ return;
+ }
+ msize =
+ put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
+ sizeof (struct PeerPutMessage);
if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
{
put_path_length = 0;
return;
}
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# PUT messages queued for transmission"), target_count,
- GNUNET_NO);
- for (i=0;i<target_count;i++)
+ gettext_noop
+ ("# PUT messages queued for transmission"),
+ target_count, GNUNET_NO);
+ for (i = 0; i < target_count; i++)
{
target = targets[i];
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Routing PUT for %s after %u hops to %s\n",
- GNUNET_h2s (key),
- (unsigned int) hop_count,
- GNUNET_i2s (&target->id));
+ "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key),
+ (unsigned int) hop_count, GNUNET_i2s (&target->id));
#endif
pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
- pending->importance = 0; /* FIXME */
- pending->timeout = expiration_time;
- ppm = (struct PeerPutMessage*) &pending[1];
+ pending->importance = 0; /* FIXME */
+ pending->timeout = expiration_time;
+ ppm = (struct PeerPutMessage *) &pending[1];
pending->msg = &ppm->header;
ppm->header.size = htons (msize);
ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT);
ppm->desired_replication_level = htonl (desired_replication_level);
ppm->put_path_length = htonl (put_path_length);
ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
- GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &target->id.hashPubKey));
+ GNUNET_break (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bf,
+ &target->id.hashPubKey));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
- ppm->bloomfilter,
- DHT_BLOOM_SIZE));
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
+ ppm->bloomfilter,
+ DHT_BLOOM_SIZE));
ppm->key = *key;
- pp = (struct GNUNET_PeerIdentity*) &ppm[1];
- memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length);
+ pp = (struct GNUNET_PeerIdentity *) &ppm[1];
+ memcpy (pp, put_path,
+ sizeof (struct GNUNET_PeerIdentity) * put_path_length);
memcpy (&pp[put_path_length], data, data_size);
- GNUNET_CONTAINER_DLL_insert_tail (target->head,
- target->tail,
- pending);
+ GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending);
target->pending_count++;
process_peer_queue (target);
}
*/
void
GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
- enum GNUNET_DHT_RouteOption options,
- uint32_t desired_replication_level,
- uint32_t hop_count,
- const GNUNET_HashCode *key,
- const void *xquery,
- size_t xquery_size,
- const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
- uint32_t reply_bf_mutator,
- struct GNUNET_CONTAINER_BloomFilter *peer_bf)
+ enum GNUNET_DHT_RouteOption options,
+ uint32_t desired_replication_level,
+ uint32_t hop_count, const GNUNET_HashCode * key,
+ const void *xquery, size_t xquery_size,
+ const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
+ uint32_t reply_bf_mutator,
+ struct GNUNET_CONTAINER_BloomFilter *peer_bf)
{
unsigned int target_count;
unsigned int i;
char *xq;
size_t reply_bf_size;
- GNUNET_assert (NULL != peer_bf);
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# GET requests routed"), 1,
- GNUNET_NO);
- target_count = get_target_peers (key, peer_bf, hop_count,
- desired_replication_level,
- &targets);
+ GNUNET_assert (NULL != peer_bf);
+ GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"),
+ 1, GNUNET_NO);
+ target_count =
+ get_target_peers (key, peer_bf, hop_count, desired_replication_level,
+ &targets);
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding myself (%s) to GET bloomfilter for %s\n",
- GNUNET_i2s (&my_identity),
- GNUNET_h2s (key));
+ "Adding myself (%s) to GET bloomfilter for %s\n",
+ GNUNET_i2s (&my_identity), GNUNET_h2s (key));
#endif
GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey);
if (0 == target_count)
{
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Routing GET for %s terminates after %u hops at %s\n",
- GNUNET_h2s (key),
- (unsigned int) hop_count,
- GNUNET_i2s (&my_identity));
+ "Routing GET for %s terminates after %u hops at %s\n",
+ GNUNET_h2s (key), (unsigned int) hop_count,
+ GNUNET_i2s (&my_identity));
#endif
return;
}
return;
}
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# GET messages queued for transmission"), target_count,
- GNUNET_NO);
+ gettext_noop
+ ("# GET messages queued for transmission"),
+ target_count, GNUNET_NO);
/* forward request */
- for (i=0;i<target_count;i++)
+ for (i = 0; i < target_count; i++)
{
target = targets[i];
#if DEBUG_DHT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Routing GET for %s after %u hops to %s\n",
- GNUNET_h2s (key),
- (unsigned int) hop_count,
- GNUNET_i2s (&target->id));
+ "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key),
+ (unsigned int) hop_count, GNUNET_i2s (&target->id));
#endif
- pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
- pending->importance = 0; /* FIXME */
+ pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
+ pending->importance = 0; /* FIXME */
pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
- pgm = (struct PeerGetMessage*) &pending[1];
+ pgm = (struct PeerGetMessage *) &pending[1];
pending->msg = &pgm->header;
pgm->header.size = htons (msize);
pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET);
pgm->hop_count = htonl (hop_count + 1);
pgm->desired_replication_level = htonl (desired_replication_level);
pgm->xquery_size = htonl (xquery_size);
- pgm->bf_mutator = reply_bf_mutator;
- GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &target->id.hashPubKey));
+ pgm->bf_mutator = reply_bf_mutator;
+ GNUNET_break (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (peer_bf,
+ &target->id.hashPubKey));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf,
- pgm->bloomfilter,
- DHT_BLOOM_SIZE));
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf,
+ pgm->bloomfilter,
+ DHT_BLOOM_SIZE));
pgm->key = *key;
xq = (char *) &pgm[1];
memcpy (xq, xquery, xquery_size);
if (NULL != reply_bf)
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
- &xq[xquery_size],
- reply_bf_size));
- GNUNET_CONTAINER_DLL_insert_tail (target->head,
- target->tail,
- pending);
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
+ &xq
+ [xquery_size],
+ reply_bf_size));
+ GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending);
target->pending_count++;
process_peer_queue (target);
}
*/
void
GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute expiration_time,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *get_path,
- const void *data,
- size_t data_size)
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute expiration_time,
+ const GNUNET_HashCode * key,
+ unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *get_path,
+ const void *data, size_t data_size)
{
struct PeerInfo *pi;
struct P2PPendingMessage *pending;
size_t msize;
struct PeerResultMessage *prm;
struct GNUNET_PeerIdentity *paths;
-
- msize = data_size + sizeof (struct PeerResultMessage) +
- (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity);
- if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
- (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
- (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) )
+
+ msize =
+ data_size + sizeof (struct PeerResultMessage) + (get_path_length +
+ put_path_length) *
+ sizeof (struct GNUNET_PeerIdentity);
+ if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (get_path_length >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
+ (put_path_length >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
+ (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE))
{
GNUNET_break (0);
return;
}
- pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers,
- &target->hashPubKey);
+ pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &target->hashPubKey);
if (NULL == pi)
{
/* peer disconnected in the meantime, drop reply */
return;
}
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# RESULT messages queued for transmission"), 1,
- GNUNET_NO);
- pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
- pending->importance = 0; /* FIXME */
+ gettext_noop
+ ("# RESULT messages queued for transmission"), 1,
+ GNUNET_NO);
+ pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
+ pending->importance = 0; /* FIXME */
pending->timeout = expiration_time;
- prm = (struct PeerResultMessage*) &pending[1];
+ prm = (struct PeerResultMessage *) &pending[1];
pending->msg = &prm->header;
prm->header.size = htons (msize);
prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT);
prm->get_path_length = htonl (get_path_length);
prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
prm->key = *key;
- paths = (struct GNUNET_PeerIdentity*) &prm[1];
- memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity));
- memcpy (&paths[put_path_length],
- get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity));
- memcpy (&paths[put_path_length + get_path_length],
- data, data_size);
- GNUNET_CONTAINER_DLL_insert (pi->head,
- pi->tail,
- pending);
+ paths = (struct GNUNET_PeerIdentity *) &prm[1];
+ memcpy (paths, put_path,
+ put_path_length * sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&paths[put_path_length], get_path,
+ get_path_length * sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&paths[put_path_length + get_path_length], data, data_size);
+ GNUNET_CONTAINER_DLL_insert (pi->head, pi->tail, pending);
pi->pending_count++;
process_peer_queue (pi);
}
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
-handle_dht_p2p_put (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
const struct PeerPutMessage *put;
const struct GNUNET_PeerIdentity *put_path;
enum GNUNET_DHT_RouteOption options;
struct GNUNET_CONTAINER_BloomFilter *bf;
GNUNET_HashCode test_key;
-
+
msize = ntohs (message->size);
if (msize < sizeof (struct PeerPutMessage))
{
GNUNET_break_op (0);
return GNUNET_YES;
}
- put = (const struct PeerPutMessage*) message;
+ put = (const struct PeerPutMessage *) message;
putlen = ntohl (put->put_path_length);
- if ( (msize < sizeof (struct PeerPutMessage) + putlen * sizeof (struct GNUNET_PeerIdentity)) ||
- (putlen > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) )
- {
- GNUNET_break_op (0);
- return GNUNET_YES;
- }
+ if ((msize <
+ sizeof (struct PeerPutMessage) +
+ putlen * sizeof (struct GNUNET_PeerIdentity)) ||
+ (putlen >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_YES;
+ }
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# P2P PUT requests received"), 1,
- GNUNET_NO);
- put_path = (const struct GNUNET_PeerIdentity*) &put[1];
+ gettext_noop ("# P2P PUT requests received"), 1,
+ GNUNET_NO);
+ put_path = (const struct GNUNET_PeerIdentity *) &put[1];
payload = &put_path[putlen];
options = ntohl (put->options);
- payload_size = msize - (sizeof (struct PeerPutMessage) +
- putlen * sizeof (struct GNUNET_PeerIdentity));
- switch (GNUNET_BLOCK_get_key (GDS_block_context,
- ntohl (put->type),
- payload, payload_size,
- &test_key))
+ payload_size =
+ msize - (sizeof (struct PeerPutMessage) +
+ putlen * sizeof (struct GNUNET_PeerIdentity));
+ switch (GNUNET_BLOCK_get_key
+ (GDS_block_context, ntohl (put->type), payload, payload_size,
+ &test_key))
{
case GNUNET_YES:
if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode)))
break;
}
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "PUT for %s at %s\n",
- GNUNET_h2s (&put->key),
- GNUNET_i2s (&my_identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for %s at %s\n",
+ GNUNET_h2s (&put->key), GNUNET_i2s (&my_identity));
#endif
- bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter,
- DHT_BLOOM_SIZE,
- GNUNET_CONSTANTS_BLOOMFILTER_K);
- GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey));
+ bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
+ GNUNET_break_op (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey));
{
- struct GNUNET_PeerIdentity pp[putlen+1];
-
+ struct GNUNET_PeerIdentity pp[putlen + 1];
+
/* extend 'put path' by sender */
if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE))
{
}
else
putlen = 0;
-
+
/* give to local clients */
GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time),
- &put->key,
- 0, NULL,
- putlen,
- pp,
- ntohl (put->type),
- payload_size,
- payload);
+ &put->key, 0, NULL, putlen, pp, ntohl (put->type),
+ payload_size, payload);
/* store locally */
- if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
- (am_closest_peer (&put->key,
- bf) ) )
- GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time),
- &put->key,
- putlen, pp,
- ntohl (put->type),
- payload_size,
- payload);
+ if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
+ (am_closest_peer (&put->key, bf)))
+ GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh
+ (put->expiration_time), &put->key, putlen, pp,
+ ntohl (put->type), payload_size, payload);
/* route to other peers */
- GDS_NEIGHBOURS_handle_put (ntohl (put->type),
- options,
- ntohl (put->desired_replication_level),
- GNUNET_TIME_absolute_ntoh (put->expiration_time),
- ntohl (put->hop_count),
- bf,
- &put->key,
- putlen, pp,
- payload,
- payload_size);
+ GDS_NEIGHBOURS_handle_put (ntohl (put->type), options,
+ ntohl (put->desired_replication_level),
+ GNUNET_TIME_absolute_ntoh (put->expiration_time),
+ ntohl (put->hop_count), bf, &put->key, putlen,
+ pp, payload, payload_size);
}
GNUNET_CONTAINER_bloomfilter_free (bf);
return GNUNET_YES;
*/
static void
handle_find_peer (const struct GNUNET_PeerIdentity *sender,
- const GNUNET_HashCode *key,
- struct GNUNET_CONTAINER_BloomFilter *bf,
- uint32_t bf_mutator)
+ const GNUNET_HashCode * key,
+ struct GNUNET_CONTAINER_BloomFilter *bf, uint32_t bf_mutator)
{
int bucket_idx;
struct PeerBucket *bucket;
if (NULL != GDS_my_hello)
{
GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash);
- if ( (NULL == bf) ||
- (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) )
+ if ((NULL == bf) ||
+ (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)))
{
- GDS_NEIGHBOURS_handle_reply (sender,
- GNUNET_BLOCK_TYPE_DHT_HELLO,
- GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
- key,
- 0, NULL,
- 0, NULL,
- GDS_my_hello,
- GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*) GDS_my_hello));
+ GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
+ key, 0, NULL, 0, NULL, GDS_my_hello,
+ GNUNET_HELLO_size ((const struct
+ GNUNET_HELLO_Message *)
+ GDS_my_hello));
}
else
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# FIND PEER requests ignored due to Bloomfilter"),
+ 1, GNUNET_NO);
}
}
else
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# FIND PEER requests ignored due to lack of HELLO"),
+ 1, GNUNET_NO);
}
/* then, also consider sending a random HELLO from the closest bucket */
bucket = &k_buckets[bucket_idx];
if (bucket->peers_size == 0)
return;
- choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- bucket->peers_size);
+ choice =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, bucket->peers_size);
peer = bucket->head;
while (choice > 0)
{
}
choice = bucket->peers_size;
do
- {
- peer = peer->next;
- if (choice-- == 0)
- return; /* no non-masked peer available */
- if (peer == NULL)
- peer = bucket->head;
- GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash);
- hello = GDS_HELLO_get (&peer->id);
- }
- while ( (hello == NULL) ||
- (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) );
- GDS_NEIGHBOURS_handle_reply (sender,
- GNUNET_BLOCK_TYPE_DHT_HELLO,
- GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
- key,
- 0, NULL,
- 0, NULL,
- hello,
- GNUNET_HELLO_size (hello));
+ {
+ peer = peer->next;
+ if (choice-- == 0)
+ return; /* no non-masked peer available */
+ if (peer == NULL)
+ peer = bucket->head;
+ GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash);
+ hello = GDS_HELLO_get (&peer->id);
+ }
+ while ((hello == NULL) ||
+ (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)));
+ GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), key,
+ 0, NULL, 0, NULL, hello,
+ GNUNET_HELLO_size (hello));
}
*/
static int
handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct PeerGetMessage *get;
uint32_t xquery_size;
struct GNUNET_CONTAINER_BloomFilter *peer_bf;
const char *xquery;
- GNUNET_break (0 != memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_break (0 !=
+ memcmp (peer, &my_identity,
+ sizeof (struct GNUNET_PeerIdentity)));
/* parse and validate message */
msize = ntohs (message->size);
if (msize < sizeof (struct PeerGetMessage))
return GNUNET_YES;
}
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# P2P GET requests received"), 1,
- GNUNET_NO);
+ gettext_noop ("# P2P GET requests received"), 1,
+ GNUNET_NO);
reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size);
type = ntohl (get->type);
options = ntohl (get->options);
- xquery = (const char*) &get[1];
+ xquery = (const char *) &get[1];
reply_bf = NULL;
if (reply_bf_size > 0)
- reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size],
- reply_bf_size,
- GNUNET_CONSTANTS_BLOOMFILTER_K);
- eval = GNUNET_BLOCK_evaluate (GDS_block_context,
- type,
- &get->key,
- &reply_bf,
- get->bf_mutator,
- xquery, xquery_size,
- NULL, 0);
+ reply_bf =
+ GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], reply_bf_size,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
+ eval =
+ GNUNET_BLOCK_evaluate (GDS_block_context, type, &get->key, &reply_bf,
+ get->bf_mutator, xquery, xquery_size, NULL, 0);
if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID)
{
/* request invalid or block type not supported */
return GNUNET_YES;
}
peer_bf =
- GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter,
- DHT_BLOOM_SIZE,
- GNUNET_CONSTANTS_BLOOMFILTER_K);
- GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->hashPubKey));
+ GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, DHT_BLOOM_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
+ GNUNET_break_op (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (peer_bf,
+ &peer->hashPubKey));
/* remember request for routing replies */
- GDS_ROUTING_add (peer,
- type,
- options,
- &get->key,
- xquery, xquery_size,
- reply_bf, get->bf_mutator);
+ GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size,
+ reply_bf, get->bf_mutator);
#if DEBUG_DHT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GET for %s at %s after %u hops\n",
- GNUNET_h2s (&get->key),
- GNUNET_i2s (&my_identity),
- (unsigned int) ntohl (get->hop_count));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n",
+ GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity),
+ (unsigned int) ntohl (get->hop_count));
#endif
/* local lookup (this may update the reply_bf) */
- if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
- (am_closest_peer (&get->key,
- peer_bf) ) )
- {
- if ( (0 != (options & GNUNET_DHT_RO_FIND_PEER)))
+ if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
+ (am_closest_peer (&get->key, peer_bf)))
+ {
+ if ((0 != (options & GNUNET_DHT_RO_FIND_PEER)))
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# P2P FIND PEER requests processed"), 1,
- GNUNET_NO);
- handle_find_peer (peer,
- &get->key,
- reply_bf,
- get->bf_mutator);
+ gettext_noop
+ ("# P2P FIND PEER requests processed"), 1,
+ GNUNET_NO);
+ handle_find_peer (peer, &get->key, reply_bf, get->bf_mutator);
}
else
{
- eval = GDS_DATACACHE_handle_get (&get->key,
- type,
- xquery, xquery_size,
- &reply_bf,
- get->bf_mutator);
+ eval =
+ GDS_DATACACHE_handle_get (&get->key, type, xquery, xquery_size,
+ &reply_bf, get->bf_mutator);
}
}
else
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# P2P GET requests ONLY routed"), 1,
- GNUNET_NO);
+ gettext_noop ("# P2P GET requests ONLY routed"),
+ 1, GNUNET_NO);
}
-
+
/* P2P forwarding */
if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
- GDS_NEIGHBOURS_handle_get (type,
- options,
- ntohl (get->desired_replication_level),
- ntohl (get->hop_count),
- &get->key,
- xquery, xquery_size,
- reply_bf,
- get->bf_mutator,
- peer_bf);
+ GDS_NEIGHBOURS_handle_get (type, options,
+ ntohl (get->desired_replication_level),
+ ntohl (get->hop_count), &get->key, xquery,
+ xquery_size, reply_bf, get->bf_mutator, peer_bf);
/* clean up */
if (NULL != reply_bf)
GNUNET_CONTAINER_bloomfilter_free (reply_bf);
- GNUNET_CONTAINER_bloomfilter_free (peer_bf);
+ GNUNET_CONTAINER_bloomfilter_free (peer_bf);
return GNUNET_YES;
}
*/
static int
handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
const struct PeerResultMessage *prm;
const struct GNUNET_PeerIdentity *put_path;
uint16_t msize;
size_t data_size;
enum GNUNET_BLOCK_Type type;
-
+
/* parse and validate message */
msize = ntohs (message->size);
if (msize < sizeof (struct PeerResultMessage))
prm = (struct PeerResultMessage *) message;
put_path_length = ntohl (prm->put_path_length);
get_path_length = ntohl (prm->get_path_length);
- if ( (msize < sizeof (struct PeerResultMessage) +
- (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)) ||
- (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
- (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) )
+ if ((msize <
+ sizeof (struct PeerResultMessage) + (get_path_length +
+ put_path_length) *
+ sizeof (struct GNUNET_PeerIdentity)) ||
+ (get_path_length >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
+ (put_path_length >
+ GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break_op (0);
return GNUNET_YES;
- }
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# P2P RESULTS received"), 1,
- GNUNET_NO);
- put_path = (const struct GNUNET_PeerIdentity*) &prm[1];
+ }
+ GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P RESULTS received"),
+ 1, GNUNET_NO);
+ put_path = (const struct GNUNET_PeerIdentity *) &prm[1];
get_path = &put_path[put_path_length];
type = ntohl (prm->type);
- data = (const void*) &get_path[get_path_length];
- data_size = msize - (sizeof (struct PeerResultMessage) +
- (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity));
+ data = (const void *) &get_path[get_path_length];
+ data_size =
+ msize - (sizeof (struct PeerResultMessage) +
+ (get_path_length +
+ put_path_length) * sizeof (struct GNUNET_PeerIdentity));
/* if we got a HELLO, consider it for our own routing table */
if (type == GNUNET_BLOCK_TYPE_DHT_HELLO)
return GNUNET_YES;
}
if (GNUNET_OK !=
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) h,
- &pid))
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid))
{
GNUNET_break_op (0);
return GNUNET_YES;
if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity)))
{
bucket = find_bucket (&pid.hashPubKey);
- if ( (bucket >= 0) &&
- (k_buckets[bucket].peers_size < bucket_size) )
- {
- if (NULL != GDS_transport_handle)
- {
- GNUNET_TRANSPORT_offer_hello (GDS_transport_handle,
- h, NULL, NULL);
- GNUNET_TRANSPORT_try_connect (GDS_transport_handle,
- &pid);
- }
- }
+ if ((bucket >= 0) && (k_buckets[bucket].peers_size < bucket_size))
+ {
+ if (NULL != GDS_transport_handle)
+ {
+ GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL);
+ GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid);
+ }
+ }
}
}
/* append 'peer' to 'get_path' */
- {
- struct GNUNET_PeerIdentity xget_path[get_path_length+1];
+ {
+ struct GNUNET_PeerIdentity xget_path[get_path_length + 1];
- memcpy (xget_path, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity));
+ memcpy (xget_path, get_path,
+ get_path_length * sizeof (struct GNUNET_PeerIdentity));
xget_path[get_path_length] = *peer;
get_path_length++;
- /* forward to local clients */
+ /* forward to local clients */
GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time),
- &prm->key,
- get_path_length,
- xget_path,
- put_path_length,
- put_path,
- type,
- data_size,
- data);
+ &prm->key, get_path_length, xget_path,
+ put_path_length, put_path, type, data_size, data);
/* forward to other peers */
- GDS_ROUTING_process (type,
- GNUNET_TIME_absolute_ntoh (prm->expiration_time),
- &prm->key,
- put_path_length,
- put_path,
- get_path_length,
- xget_path,
- data,
- data_size);
+ GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time),
+ &prm->key, put_path_length, put_path, get_path_length,
+ xget_path, data, data_size);
}
return GNUNET_YES;
}
{NULL, 0, 0}
};
unsigned long long temp_config_num;
-
+
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size",
&temp_config_num))
- bucket_size = (unsigned int) temp_config_num;
+ bucket_size = (unsigned int) temp_config_num;
atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL);
- coreAPI = GNUNET_CORE_connect (GDS_cfg,
- 1,
- NULL,
- &core_init,
- &handle_core_connect,
- &handle_core_disconnect,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- core_handlers);
+ coreAPI =
+ GNUNET_CORE_connect (GDS_cfg, 1, NULL, &core_init, &handle_core_connect,
+ &handle_core_disconnect, NULL, GNUNET_NO, NULL,
+ GNUNET_NO, core_handlers);
if (coreAPI == NULL)
return GNUNET_SYSERR;
all_known_peers = GNUNET_CONTAINER_multihashmap_create (256);
if (coreAPI == NULL)
return;
GNUNET_CORE_disconnect (coreAPI);
- coreAPI = NULL;
+ coreAPI = NULL;
GNUNET_ATS_performance_done (atsAPI);
- atsAPI = NULL;
+ atsAPI = NULL;
GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers));
GNUNET_CONTAINER_multihashmap_destroy (all_known_peers);
all_known_peers = NULL;
*/
void
GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
- enum GNUNET_DHT_RouteOption options,
- uint32_t desired_replication_level,
- struct GNUNET_TIME_Absolute expiration_time,
- uint32_t hop_count,
- struct GNUNET_CONTAINER_BloomFilter *bf,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- struct GNUNET_PeerIdentity *put_path,
- const void *data,
- size_t data_size);
+ enum GNUNET_DHT_RouteOption options,
+ uint32_t desired_replication_level,
+ struct GNUNET_TIME_Absolute expiration_time,
+ uint32_t hop_count,
+ struct GNUNET_CONTAINER_BloomFilter *bf,
+ const GNUNET_HashCode * key,
+ unsigned int put_path_length,
+ struct GNUNET_PeerIdentity *put_path,
+ const void *data, size_t data_size);
/**
*/
void
GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
- enum GNUNET_DHT_RouteOption options,
- uint32_t desired_replication_level,
- uint32_t hop_count,
- const GNUNET_HashCode *key,
- const void *xquery,
- size_t xquery_size,
- const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
- uint32_t reply_bf_mutator,
- struct GNUNET_CONTAINER_BloomFilter *peer_bf);
+ enum GNUNET_DHT_RouteOption options,
+ uint32_t desired_replication_level,
+ uint32_t hop_count, const GNUNET_HashCode * key,
+ const void *xquery, size_t xquery_size,
+ const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
+ uint32_t reply_bf_mutator,
+ struct GNUNET_CONTAINER_BloomFilter *peer_bf);
/**
*/
void
GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute expiration_time,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *get_path,
- const void *data,
- size_t data_size);
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_TIME_Absolute expiration_time,
+ const GNUNET_HashCode * key,
+ unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *get_path,
+ const void *data, size_t data_size);
/**
double logestimate, double std_dev)
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Network size estimates received"), 1,
- GNUNET_NO);
+ gettext_noop ("# Network size estimates received"),
+ 1, GNUNET_NO);
/* do not allow estimates < 0.5 */
- log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate);
+ log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate);
}
*/
void
GDS_NSE_done ()
-{
+{
if (NULL != nse)
- {
+ {
GNUNET_NSE_disconnect (nse);
nse = NULL;
}
* Type of the requested block.
*/
enum GNUNET_BLOCK_Type type;
-
+
/**
* extended query (see gnunet_block_lib.h). Allocated at the
* end of this struct.
/**
* Path of the reply.
- */
+ */
const struct GNUNET_PeerIdentity *get_path;
/**
* @param cls the 'struct ProcessContext' with the result
* @param key the query
* @param value the 'struct RecentRequest' with the request
- * @return GNUNET_OK (continue to iterate),
+ * @return GNUNET_OK (continue to iterate),
* GNUNET_SYSERR if the result is malformed or type unsupported
*/
static int
-process (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+process (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ProcessContext *pc = cls;
struct RecentRequest *rr = value;
GNUNET_HashCode hc;
const GNUNET_HashCode *eval_key;
- if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) &&
- (rr->type != pc->type) )
- return GNUNET_OK; /* type missmatch */
+ if ((rr->type != GNUNET_BLOCK_TYPE_ANY) && (rr->type != pc->type))
+ return GNUNET_OK; /* type missmatch */
if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE))
{
gpl = 0;
ppl = 0;
}
- if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) &&
- (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) )
+ if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) &&
+ (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO))
{
/* key may not match HELLO, which is OK since
- the search is approximate. Still, the evaluation
- would fail since the match is not exact. So
- we fake it by changing the key to the actual PID ... */
- GNUNET_BLOCK_get_key (GDS_block_context,
- GNUNET_BLOCK_TYPE_DHT_HELLO,
- pc->data, pc->data_size,
- &hc);
+ * the search is approximate. Still, the evaluation
+ * would fail since the match is not exact. So
+ * we fake it by changing the key to the actual PID ... */
+ GNUNET_BLOCK_get_key (GDS_block_context, GNUNET_BLOCK_TYPE_DHT_HELLO,
+ pc->data, pc->data_size, &hc);
eval_key = &hc;
}
else
{
eval_key = key;
}
- eval = GNUNET_BLOCK_evaluate (GDS_block_context,
- pc->type,
- eval_key,
- &rr->reply_bf,
- rr->reply_bf_mutator,
- rr->xquery,
- rr->xquery_size,
- pc->data,
- pc->data_size);
+ eval =
+ GNUNET_BLOCK_evaluate (GDS_block_context, pc->type, eval_key,
+ &rr->reply_bf, rr->reply_bf_mutator, rr->xquery,
+ rr->xquery_size, pc->data, pc->data_size);
switch (eval)
{
case GNUNET_BLOCK_EVALUATION_OK_MORE:
case GNUNET_BLOCK_EVALUATION_OK_LAST:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Good REPLIES matched against routing table"), 1,
- GNUNET_NO);
- GDS_NEIGHBOURS_handle_reply (&rr->peer,
- pc->type,
- pc->expiration_time,
- key,
- ppl,
- pc->put_path,
- gpl,
- pc->get_path,
- pc->data,
- pc->data_size);
+ gettext_noop
+ ("# Good REPLIES matched against routing table"),
+ 1, GNUNET_NO);
+ GDS_NEIGHBOURS_handle_reply (&rr->peer, pc->type, pc->expiration_time, key,
+ ppl, pc->put_path, gpl, pc->get_path, pc->data,
+ pc->data_size);
break;
case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Duplicate REPLIES matched against routing table"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Duplicate REPLIES matched against routing table"),
+ 1, GNUNET_NO);
return GNUNET_OK;
case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Invalid REPLIES matched against routing table"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Invalid REPLIES matched against routing table"),
+ 1, GNUNET_NO);
return GNUNET_SYSERR;
case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
return GNUNET_OK;
case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Unsupported REPLIES matched against routing table"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Unsupported REPLIES matched against routing table"),
+ 1, GNUNET_NO);
return GNUNET_SYSERR;
default:
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
}
return GNUNET_OK;
}
*/
void
GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute expiration_time,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *get_path,
- const void *data,
- size_t data_size)
+ struct GNUNET_TIME_Absolute expiration_time,
+ const GNUNET_HashCode * key, unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *get_path,
+ const void *data, size_t data_size)
{
struct ProcessContext pc;
pc.get_path = get_path;
pc.data = data;
pc.data_size = data_size;
- GNUNET_CONTAINER_multihashmap_get_multiple (recent_map,
- key,
- &process,
- &pc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key, &process, &pc);
}
*/
void
GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
- enum GNUNET_BLOCK_Type type,
- enum GNUNET_DHT_RouteOption options,
- const GNUNET_HashCode *key,
- const void *xquery,
- size_t xquery_size,
- const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
- uint32_t reply_bf_mutator)
+ enum GNUNET_BLOCK_Type type,
+ enum GNUNET_DHT_RouteOption options,
+ const GNUNET_HashCode * key, const void *xquery,
+ size_t xquery_size,
+ const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
+ uint32_t reply_bf_mutator)
{
struct RecentRequest *recent_req;
while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT)
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Entries removed from routing table"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Entries removed from routing table"), 1,
+ GNUNET_NO);
recent_req = GNUNET_CONTAINER_heap_peek (recent_heap);
GNUNET_assert (recent_req != NULL);
GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node);
}
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Entries added to routing table"), 1,
- GNUNET_NO);
+ gettext_noop ("# Entries added to routing table"),
+ 1, GNUNET_NO);
recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size);
recent_req->peer = *sender;
recent_req->key = *key;
recent_req->heap_node =
- GNUNET_CONTAINER_heap_insert (recent_heap, recent_req,
- GNUNET_TIME_absolute_get ().abs_value);
- recent_req->reply_bf =
- GNUNET_CONTAINER_bloomfilter_copy (reply_bf);
+ GNUNET_CONTAINER_heap_insert (recent_heap, recent_req,
+ GNUNET_TIME_absolute_get ().abs_value);
+ recent_req->reply_bf = GNUNET_CONTAINER_bloomfilter_copy (reply_bf);
recent_req->type = type;
recent_req->options = options;
recent_req->xquery = &recent_req[1];
recent_req->xquery_size = xquery_size;
recent_req->reply_bf_mutator = reply_bf_mutator;
- GNUNET_CONTAINER_multihashmap_put (recent_map,
- key,
- recent_req,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_CONTAINER_multihashmap_put (recent_map, key, recent_req,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
}
void
GDS_ROUTING_init ()
{
- recent_heap =
- GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
- recent_map =
- GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3);
+ recent_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ recent_map = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3);
}
while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0)
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Entries removed from routing table"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# Entries removed from routing table"), 1,
+ GNUNET_NO);
recent_req = GNUNET_CONTAINER_heap_peek (recent_heap);
GNUNET_assert (recent_req != NULL);
GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node);
*/
void
GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
- struct GNUNET_TIME_Absolute expiration_time,
- const GNUNET_HashCode *key,
- unsigned int put_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *get_path,
- const void *data,
- size_t data_size);
+ struct GNUNET_TIME_Absolute expiration_time,
+ const GNUNET_HashCode * key, unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *get_path,
+ const void *data, size_t data_size);
/**
*/
void
GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
- enum GNUNET_BLOCK_Type type,
- enum GNUNET_DHT_RouteOption options,
- const GNUNET_HashCode *key,
- const void *xquery,
- size_t xquery_size,
- const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
- uint32_t reply_bf_mutator);
+ enum GNUNET_BLOCK_Type type,
+ enum GNUNET_DHT_RouteOption options,
+ const GNUNET_HashCode * key, const void *xquery,
+ size_t xquery_size,
+ const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
+ uint32_t reply_bf_mutator);
/**
else
{
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test: All peers successfully shut down!\n");
#endif
}
}
{
unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: disconnecting peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n");
disconnect_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_SCHEDULER_cancel (put_task);
if (NULL != get_h)
- GNUNET_DHT_get_stop(get_h);
+ GNUNET_DHT_get_stop (get_h);
if (NULL != get_h_2)
- GNUNET_DHT_get_stop(get_h_2);
+ GNUNET_DHT_get_stop (get_h_2);
if (NULL != get_h_far)
- GNUNET_DHT_get_stop(get_h_far);
- for (i = 0; i < num_peers; i++)
+ GNUNET_DHT_get_stop (get_h_far);
+ for (i = 0; i < num_peers; i++)
{
- GNUNET_DHT_disconnect(hs[i]);
+ GNUNET_DHT_disconnect (hs[i]);
}
GNUNET_SCHEDULER_cancel (shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
static void
const struct GNUNET_PeerIdentity *get_path,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
int i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: ************* FOUND!!! ***********\n");
- if (sizeof(GNUNET_HashCode) == size)
+ "test: ************* FOUND!!! ***********\n");
+ if (sizeof (GNUNET_HashCode) == size)
{
const GNUNET_HashCode *h = data;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Contents: %s\n",
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n",
GNUNET_h2s_full (h));
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: PATH: (get %u, put %u)\n",
- get_path_length,
- put_path_length);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: LOCAL\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n",
+ get_path_length, put_path_length);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n");
for (i = get_path_length - 1; i >= 0; i--)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: %s\n",
- GNUNET_i2s (&get_path[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
+ GNUNET_i2s (&get_path[i]));
}
for (i = put_path_length - 1; i >= 0; i--)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: %s\n",
- GNUNET_i2s (&put_path[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
+ GNUNET_i2s (&put_path[i]));
}
found++;
if (found < 3)
return;
ok = 0;
- GNUNET_SCHEDULER_cancel(disconnect_task);
+ GNUNET_SCHEDULER_cancel (disconnect_task);
disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
}
if (strcmp (id_aux, id_near2) == 0)
d2 = aux;
}
- if ( (NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far))
+ if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"test: Peers not found (hostkey file changed?)\n");
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: looking for %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
GNUNET_h2s_full (&d->id.hashPubKey));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: looking for %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
GNUNET_h2s_full (&d2->id.hashPubKey));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: looking for %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
GNUNET_h2s_full (&d_far->id.hashPubKey));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: from %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n",
GNUNET_h2s_full (&o->id.hashPubKey));
found = 0;
- get_h = GNUNET_DHT_get_start (hs[0],
- GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
- GNUNET_BLOCK_TYPE_TEST, /* type */
- &d->id.hashPubKey, /*key to search */
- 4U, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */
- 0, /* xquery bits */
- &dht_get_id_handler,
- NULL);
- get_h_2 = GNUNET_DHT_get_start (hs[0],
- GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
- GNUNET_BLOCK_TYPE_TEST, /* type */
+ get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
+ GNUNET_BLOCK_TYPE_TEST, /* type */
+ &d->id.hashPubKey, /*key to search */
+ 4U, /* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
+ 0, /* xquery bits */
+ &dht_get_id_handler, NULL);
+ get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
+ GNUNET_BLOCK_TYPE_TEST, /* type */
&d2->id.hashPubKey, /*key to search */
- 4U, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */
- 0, /* xquery bits */
- &dht_get_id_handler,
- NULL);
- get_h_far = GNUNET_DHT_get_start (hs[0],
- GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
- GNUNET_BLOCK_TYPE_TEST, /* type */
- &d_far->id.hashPubKey, /*key to search */
- 4U, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */
- 0, /* xquery bits */
- &dht_get_id_handler,
- NULL);
+ 4U, /* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
+ 0, /* xquery bits */
+ &dht_get_id_handler, NULL);
+ get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
+ GNUNET_BLOCK_TYPE_TEST, /* type */
+ &d_far->id.hashPubKey, /*key to search */
+ 4U, /* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
+ 0, /* xquery bits */
+ &dht_get_id_handler, NULL);
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT,
- &disconnect_peers, NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
}
unsigned int i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n");
- for (i = 0; i < num_peers; i++)
+ for (i = 0; i < num_peers; i++)
{
d = GNUNET_TESTING_daemon_get (pg, i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: putting into DHT: %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n",
GNUNET_h2s_full (&d->id.hashPubKey));
- GNUNET_DHT_put(hs[i],
- &d->id.hashPubKey,
- 10U,
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- GNUNET_BLOCK_TYPE_TEST,
- sizeof(struct GNUNET_PeerIdentity),
- (const char *) &d->id,
- GNUNET_TIME_UNIT_FOREVER_ABS,
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- NULL);
+ GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U,
+ GNUNET_DHT_RO_RECORD_ROUTE |
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity),
+ (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
}
- put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY,
- &put_id, NULL);
+ put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL);
}
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"test: Peergroup callback called with error, aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Error from testing: `%s'\n", emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
+ emsg);
ok++;
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
return;
"************************************************************\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"test: Peer Group started successfully!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Have %u connections\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
total_connections);
#endif
GNUNET_free (buf);
}
peers_running = GNUNET_TESTING_daemons_running (pg);
-
+
GNUNET_assert (peers_running == num_peers);
- hs = GNUNET_malloc (num_peers * sizeof(struct GNUNET_DHT_Handle *));
- for (i = 0; i < num_peers; i++)
+ hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *));
+ for (i = 0; i < num_peers; i++)
{
d = GNUNET_TESTING_daemon_get (pg, i);
- hs[i] = GNUNET_DHT_connect(d->cfg, 32);
+ hs[i] = GNUNET_DHT_connect (d->cfg, 32);
}
- put_task = GNUNET_SCHEDULER_add_now(&put_id, NULL);
+ put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL);
test_task =
- GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
- &do_test, NULL);
- disconnect_task =
- GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
- &disconnect_peers,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 2), &do_test,
NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
}
if (emsg == NULL)
{
total_connections++;
- GNUNET_PEER_intern(first);
- GNUNET_PEER_intern(second);
+ GNUNET_PEER_intern (first);
+ GNUNET_PEER_intern (second);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Problem with new connection (%s)\n",
- emsg);
+ "test: Problem with new connection (%s)\n", emsg);
}
}
"num_peers", &num_peers))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Option TESTING:NUM_PEERS is required!\n");
+ "Option TESTING:NUM_PEERS is required!\n");
return;
}
&data_filename))
{
data_file =
- GNUNET_DISK_file_open (data_filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_file_open (data_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (data_file == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
- data_filename);
- GNUNET_free (data_filename);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
+ data_filename);
+ GNUNET_free (data_filename);
+ }
}
if (GNUNET_YES ==
hosts);
GNUNET_assert (pg != NULL);
shutdown_handle =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task, NULL);
}
NULL
};
- GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus",
+ GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv,
+ "test_dht_2dtorus",
gettext_noop ("Test dht in a small 2D torus."), options,
&run, NULL);
#if REMOVE_DIR
test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"test_get_iterator called (we got a result), stopping get request!\n");
peer->get_handle =
GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT,
- GNUNET_BLOCK_TYPE_TEST, &hash,
- 1, GNUNET_DHT_RO_NONE, NULL,
- 0, &test_get_iterator, NULL);
+ GNUNET_BLOCK_TYPE_TEST, &hash, 1,
+ GNUNET_DHT_RO_NONE, NULL, 0, &test_get_iterator,
+ NULL);
if (peer->get_handle == NULL)
{
GNUNET_assert (peer->dht_handle != NULL);
- GNUNET_DHT_put (peer->dht_handle, &hash, 1,
- GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data,
+ GNUNET_DHT_put (peer->dht_handle, &hash, 1, GNUNET_DHT_RO_NONE,
+ GNUNET_BLOCK_TYPE_TEST, data_size, data,
GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT),
TOTAL_TIMEOUT, &test_get, &p1);
GNUNET_free (data);
struct TestGetContext
{
/**
- * This is a linked list
+ * This is a linked list
*/
struct TestGetContext *next;
/**
- * This is a linked list
+ * This is a linked list
*/
struct TestGetContext *prev;
{
if (emsg != NULL)
{
- fprintf (stderr,
- "Failed to shutdown testing topology: %s\n",
- emsg);
+ fprintf (stderr, "Failed to shutdown testing topology: %s\n", emsg);
if (ok == 0)
ok = 2;
}
GNUNET_free (sm);
i = 0;
while (stats[i].name != NULL)
- {
- fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem,
- stats[i].name, (unsigned long long) stats[i].total);
- i++;
- }
+ {
+ fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem,
+ stats[i].name, (unsigned long long) stats[i].total);
+ i++;
+ }
die_task = GNUNET_SCHEDULER_add_now (&do_stop, NULL);
return;
}
sm->stat =
GNUNET_STATISTICS_create ("<driver>",
- GNUNET_TESTING_daemon_get (pg,
- sm->daemon)->cfg);
+ GNUNET_TESTING_daemon_get (pg,
+ sm->daemon)->cfg);
die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm);
}
GNUNET_SCHEDULER_cancel (test_put->task);
if (test_put->dht_handle != NULL)
GNUNET_DHT_disconnect (test_put->dht_handle);
- GNUNET_CONTAINER_DLL_remove (all_puts_head,
- all_puts_tail,
- test_put);
+ GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put);
GNUNET_free (test_put);
}
GNUNET_DHT_get_stop (test_get->get_handle);
if (test_get->dht_handle != NULL)
GNUNET_DHT_disconnect (test_get->dht_handle);
- GNUNET_CONTAINER_DLL_remove (all_gets_head,
- all_gets_tail,
- test_get);
+ GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get);
GNUNET_free (test_get);
}
sm = GNUNET_malloc (sizeof (struct StatMaster));
sm->stat =
- GNUNET_STATISTICS_create ("<driver>",
- GNUNET_TESTING_daemon_get (pg,
- sm->daemon)->cfg);
+ GNUNET_STATISTICS_create ("<driver>",
+ GNUNET_TESTING_daemon_get (pg,
+ sm->daemon)->cfg);
die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm);
}
struct TestGetContext *test_get;
die_task = GNUNET_SCHEDULER_NO_TASK;
- fprintf (stderr,
- "Failing test with error: `%s'!\n",
- emsg);
+ fprintf (stderr, "Failing test with error: `%s'!\n", emsg);
while (NULL != (test_put = all_puts_head))
{
if (test_put->task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (test_put->task);
if (test_put->dht_handle != NULL)
GNUNET_DHT_disconnect (test_put->dht_handle);
- GNUNET_CONTAINER_DLL_remove (all_puts_head,
- all_puts_tail,
- test_put);
+ GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put);
GNUNET_free (test_put);
}
GNUNET_DHT_get_stop (test_get->get_handle);
if (test_get->dht_handle != NULL)
GNUNET_DHT_disconnect (test_get->dht_handle);
- GNUNET_CONTAINER_DLL_remove (all_gets_head,
- all_gets_tail,
- test_get);
+ GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get);
GNUNET_free (test_get);
}
ok = 1;
if (test_get->succeeded != GNUNET_YES)
{
gets_failed++;
- fprintf (stderr,
- "Get from peer %s for key %s failed!\n",
- GNUNET_i2s (&test_get->daemon->id),
- GNUNET_h2s (&search_key));
+ fprintf (stderr, "Get from peer %s for key %s failed!\n",
+ GNUNET_i2s (&test_get->daemon->id), GNUNET_h2s (&search_key));
}
GNUNET_assert (test_get->get_handle != NULL);
GNUNET_DHT_get_stop (test_get->get_handle);
GNUNET_DHT_disconnect (test_get->dht_handle);
test_get->dht_handle = NULL;
- GNUNET_CONTAINER_DLL_remove (all_gets_head,
- all_gets_tail,
- test_get);
+ GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get);
GNUNET_free (test_get);
- if ((gets_failed > 10) && (outstanding_gets == 0))
+ if ((gets_failed > 10) && (outstanding_gets == 0))
{
/* Had more than 10% failures */
- fprintf (stderr,
- "%llu gets succeeded, %llu gets failed!\n",
- gets_completed, gets_failed);
+ fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed,
+ gets_failed);
GNUNET_SCHEDULER_cancel (die_task);
- ok = 1;
- die_task = GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded");
+ ok = 1;
+ die_task =
+ GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded");
return;
}
- if ( (gets_completed + gets_failed == num_peers * num_peers) &&
- (outstanding_gets == 0) ) /* All gets successful */
+ if ((gets_completed + gets_failed == num_peers * num_peers) && (outstanding_gets == 0)) /* All gets successful */
{
- fprintf (stderr,
- "%llu gets succeeded, %llu gets failed!\n",
- gets_completed, gets_failed);
+ fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed,
+ gets_failed);
GNUNET_SCHEDULER_cancel (die_task);
- ok = 0;
+ ok = 0;
die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
}
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
struct TestGetContext *test_get = cls;
GNUNET_HashCode search_key; /* Key stored under */
{
unsigned int i;
- fprintf (stderr, "PUT (%u) Path: ",
- test_get->uid);
- for (i = 0; i<put_path_length; i++)
+ fprintf (stderr, "PUT (%u) Path: ", test_get->uid);
+ for (i = 0; i < put_path_length; i++)
fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i]));
fprintf (stderr, "\n");
}
{
unsigned int i;
- fprintf (stderr, "GET (%u) Path: ",
- test_get->uid);
+ fprintf (stderr, "GET (%u) Path: ", test_get->uid);
for (i = 0; i < get_path_length; i++)
fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i]));
- fprintf (stderr, "%s%s\n",
- get_path_length > 0 ? "->":"",
- GNUNET_i2s (&test_get->daemon->id));
+ fprintf (stderr, "%s%s\n", get_path_length > 0 ? "->" : "",
+ GNUNET_i2s (&test_get->daemon->id));
}
#endif
if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) ||
(0 != memcmp (original_data, data, sizeof (original_data))))
{
- fprintf (stderr,
- "Key or data is not the same as was inserted!\n");
+ fprintf (stderr, "Key or data is not the same as was inserted!\n");
return;
}
gets_completed++;
- test_get->succeeded = GNUNET_YES;
+ test_get->succeeded = GNUNET_YES;
GNUNET_SCHEDULER_cancel (test_get->task);
test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get);
}
if (outstanding_gets > MAX_OUTSTANDING_GETS)
{
- test_get->task = GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
+ test_get->task =
+ GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
return;
}
memset (data, test_get->uid, sizeof (data));
GNUNET_assert (test_get->dht_handle != NULL);
outstanding_gets++;
test_get->get_handle =
- GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BLOCK_TYPE_TEST, &key,
- 1, route_option, NULL, 0,
- &get_result_iterator, test_get);
+ GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BLOCK_TYPE_TEST, &key, 1, route_option, NULL,
+ 0, &get_result_iterator, test_get);
test_get->task =
- GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get);
+ GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get);
}
test_put->task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_DHT_disconnect (test_put->dht_handle);
test_put->dht_handle = NULL;
- GNUNET_CONTAINER_DLL_remove (all_puts_head,
- all_puts_tail,
- test_put);
+ GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put);
GNUNET_free (test_put);
}
unsigned long long j;
struct TestGetContext *test_get;
-#if VERBOSE
- fprintf (stderr,
- "Issuing %llu GETs\n",
- (unsigned long long) (num_peers * num_peers));
+#if VERBOSE
+ fprintf (stderr, "Issuing %llu GETs\n",
+ (unsigned long long) (num_peers * num_peers));
#endif
for (i = 0; i < num_peers; i++)
for (j = 0; j < num_peers; j++)
- {
- test_get = GNUNET_malloc (sizeof (struct TestGetContext));
- test_get->uid = i + j*num_peers;
- test_get->daemon = GNUNET_TESTING_daemon_get (pg, j);
- GNUNET_CONTAINER_DLL_insert (all_gets_head,
- all_gets_tail,
- test_get);
- test_get->task = GNUNET_SCHEDULER_add_now (&do_get,
- test_get);
- }
+ {
+ test_get = GNUNET_malloc (sizeof (struct TestGetContext));
+ test_get->uid = i + j * num_peers;
+ test_get->daemon = GNUNET_TESTING_daemon_get (pg, j);
+ GNUNET_CONTAINER_DLL_insert (all_gets_head, all_gets_tail, test_get);
+ test_get->task = GNUNET_SCHEDULER_add_now (&do_get, test_get);
+ }
}
outstanding_puts--;
puts_completed++;
GNUNET_SCHEDULER_cancel (test_put->task);
- test_put->task =
- GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
+ test_put->task = GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
if (puts_completed != num_peers * num_peers)
return;
-
+
GNUNET_assert (outstanding_puts == 0);
- GNUNET_SCHEDULER_add_delayed (START_DELAY,
- &start_gets,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (START_DELAY, &start_gets, NULL);
}
test_put->task = GNUNET_SCHEDULER_NO_TASK;
if (outstanding_puts > MAX_OUTSTANDING_PUTS)
{
- test_put->task = GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
+ test_put->task =
+ GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
return;
}
memset (data, test_put->uid, sizeof (data));
GNUNET_assert (test_put->dht_handle != NULL);
outstanding_puts++;
#if VERBOSE > 2
- fprintf (stderr, "PUT %u at `%s'\n",
- test_put->uid,
- GNUNET_i2s (&test_put->daemon->id));
+ fprintf (stderr, "PUT %u at `%s'\n", test_put->uid,
+ GNUNET_i2s (&test_put->daemon->id));
#endif
- GNUNET_DHT_put (test_put->dht_handle, &key, 1,
- route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
+ GNUNET_DHT_put (test_put->dht_handle, &key, 1, route_option,
+ GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
&put_finished, test_put);
test_put->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &put_disconnect_task, test_put);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &put_disconnect_task, test_put);
}
static void
run_dht_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+{
unsigned long long i;
struct TestPutContext *test_put;
#if PATH_TRACKING
- route_option = GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
+ route_option =
+ GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
#else
route_option = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
#endif
die_task =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
- "from setup puts/gets");
- fprintf (stderr,
- "Issuing %llu PUTs (one per peer)\n",
- (unsigned long long) (num_peers * num_peers));
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "from setup puts/gets");
+ fprintf (stderr, "Issuing %llu PUTs (one per peer)\n",
+ (unsigned long long) (num_peers * num_peers));
for (i = 0; i < num_peers * num_peers; i++)
{
test_put = GNUNET_malloc (sizeof (struct TestPutContext));
test_put->uid = i;
- test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers);
+ test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers);
test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put);
- GNUNET_CONTAINER_DLL_insert (all_puts_head,
- all_puts_tail,
- test_put);
+ GNUNET_CONTAINER_DLL_insert (all_puts_head, all_puts_tail, test_put);
}
}
{
if (emsg != NULL)
{
- fprintf (stderr,
- "Failed to setup topology: %s\n",
- emsg);
- die_task =
- GNUNET_SCHEDULER_add_now (&end_badly,
- "topology setup failed");
+ fprintf (stderr, "Failed to setup topology: %s\n", emsg);
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, "topology setup failed");
return;
}
die_task =
- GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test,
- "from setup puts/gets");
+ GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test,
+ "from setup puts/gets");
}
GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
&num_peers))
num_peers = DEFAULT_NUM_PEERS;
- pg = GNUNET_TESTING_peergroup_start (cfg,
- num_peers,
- TIMEOUT,
- NULL,
- &startup_done,
- NULL,
- NULL);
+ pg = GNUNET_TESTING_peergroup_start (cfg, num_peers, TIMEOUT, NULL,
+ &startup_done, NULL, NULL);
GNUNET_assert (NULL != pg);
}
{
const char *emsg = cls;
- fprintf (stderr,
- "Error: %s\n",
- emsg);
+ fprintf (stderr, "Error: %s\n", emsg);
if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
struct PeerGetContext *get_context = cls;
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 5),
GNUNET_BLOCK_TYPE_DHT_HELLO,
- &get_context->peer->hashPubKey,
- 1, GNUNET_DHT_RO_NONE, NULL,
- 0, &get_result_iterator, get_context);
+ &get_context->peer->hashPubKey, 1,
+ GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator,
+ get_context);
}
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 5),
GNUNET_BLOCK_TYPE_DHT_HELLO,
- &get_context->peer->hashPubKey,
- 1, GNUNET_DHT_RO_FIND_PEER, NULL,
- 0, &get_result_iterator, get_context);
+ &get_context->peer->hashPubKey, 1,
+ GNUNET_DHT_RO_FIND_PEER, NULL, 0,
+ &get_result_iterator, get_context);
}
#endif
GNUNET_SCHEDULER_cancel (die_task);
die_task =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "Timeout trying to GET");
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "Timeout trying to GET");
curr_get_ctx.dht_handle = peer1dht;
curr_get_ctx.peer = &peer2id;
{
if (emsg != NULL)
{
- fprintf (stderr,
- "Failed to start daemon: `%s'\n",
- emsg);
+ fprintf (stderr, "Failed to start daemon: `%s'\n", emsg);
return;
}
GNUNET_assert (id != NULL);
void
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_size,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_size,
- enum GNUNET_BLOCK_Type type, size_t size,
- const void *result_data)
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_size,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_size, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *result_data)
{
GNUNET_HashCode original_key; /* Key data was stored data under */
char original_data[4]; /* Made up data that was stored */
#else
GNUNET_BLOCK_TYPE_TEST,
#endif
- &key, 1, GNUNET_DHT_RO_NONE,
- NULL, 0, &get_result_iterator, NULL);
+ &key, 1, GNUNET_DHT_RO_NONE, NULL, 0,
+ &get_result_iterator, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10), &do_put, NULL);
}
memset (data, 43, sizeof (data));
/* Insert the data at the first peer */
- GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE,
- GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
- GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
- &put_finished, NULL);
+ GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST,
+ sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
}
#else
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
GNUNET_HashCode original_key; /* Key data was stored data under */
char original_data[4]; /* Made up data that was stored */
if (put_path != NULL)
{
fprintf (stderr, "PUT Path: ");
- for (i = 0; i<put_path_length; i++)
+ for (i = 0; i < put_path_length; i++)
fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i]));
fprintf (stderr, "\n");
}
if (get_path != NULL)
{
fprintf (stderr, "GET Path: ");
- for (i = 0; i<get_path_length; i++)
+ for (i = 0; i < get_path_length; i++)
fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i]));
fprintf (stderr, "\n");
}
memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
global_get_handle =
GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
- GNUNET_BLOCK_TYPE_TEST, &key,
- 1, GNUNET_DHT_RO_RECORD_ROUTE,
- NULL, 0, &get_result_iterator, NULL);
+ GNUNET_BLOCK_TYPE_TEST, &key, 1,
+ GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0,
+ &get_result_iterator, NULL);
}
/**
memset (data, 43, sizeof (data));
/* Insert the data at the first peer */
- GNUNET_DHT_put (peer1dht, &key, 1,
- GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_TEST,
- sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS,
- GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
+ GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_RECORD_ROUTE,
+ GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
+ GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
+ &put_finished, NULL);
}
/**
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_size,
+ unsigned int get_path_size,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_size,
- enum GNUNET_BLOCK_Type type, size_t size,
- const void *result_data)
+ unsigned int put_path_size, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *result_data)
{
GNUNET_HashCode original_key; /* Key data was stored data under */
char original_data[4]; /* Made up data that was stored */
memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
global_get_handle =
- GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BLOCK_TYPE_TEST,
- &key, 1, GNUNET_DHT_RO_NONE,
- NULL, 0, &get_result_iterator, NULL);
+ GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BLOCK_TYPE_TEST, &key, 1, GNUNET_DHT_RO_NONE,
+ NULL, 0, &get_result_iterator, NULL);
}
memset (data, 43, sizeof (data));
/* Insert the data at the first peer */
- GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE,
- GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
- GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
- &put_finished, NULL);
+ GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST,
+ sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
}
*/
static uint32_t
get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
unsigned int i;
- for (i=0;i<atsi_count;i++)
+ for (i = 0; i < atsi_count; i++)
if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE)
- return ntohl (atsi->value);
+ return ntohl (atsi->value);
/* FIXME: we do not have distance data? Assume direct neighbor. */
return DIRECT_NEIGHBOR_COST;
}
*/
static struct GNUNET_TIME_Relative
get_atsi_latency (const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
unsigned int i;
- for (i=0;i<atsi_count;i++)
+ for (i = 0; i < atsi_count; i++)
if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- ntohl (atsi->value));
+ ntohl (atsi->value));
GNUNET_break (0);
/* how can we not have latency data? */
return GNUNET_TIME_UNIT_SECONDS;
handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
const struct GNUNET_MessageHeader *packed_message;
handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count);
+ unsigned int atsi_count);
static int
handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count);
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count);
/** End forward declarations **/
atsi[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
atsi[1].value =
htonl ((uint32_t) referrer->pending_messages[i].
- latency.rel_value);
+ latency.rel_value);
handle_dv_data_message (NULL, &referrer->pending_messages[i].sender,
- referrer->pending_messages[i].message,
- atsi, 2);
+ referrer->pending_messages[i].message, atsi,
+ 2);
GNUNET_free (referrer->pending_messages[i].message);
referrer->pending_messages[i].sender_id = 0;
}
static int
handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct DirectNeighbor *referrer;
struct DistantNeighbor *distant;
handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct DirectNeighbor *referrer;
p2p_dv_MESSAGE_NeighborInfo *enc_message =
static void
handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct DirectNeighbor *neighbor;
struct DistantNeighbor *about;
GNUNET_SERVER_add_handlers (server, plugin_handlers);
coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */
&core_init, &handle_core_connect,
- &handle_core_disconnect, NULL, GNUNET_NO,
- NULL, GNUNET_NO, core_handlers);
+ &handle_core_disconnect, NULL, GNUNET_NO, NULL,
+ GNUNET_NO, core_handlers);
if (coreAPI == NULL)
return;
plugin->env->receive (plugin->env->cls, sender,
(struct GNUNET_MessageHeader *) msg,
- (const struct GNUNET_ATS_Information *) &ats,
- 2, NULL, sender_address, sender_address_len);
+ (const struct GNUNET_ATS_Information *) &ats, 2, NULL,
+ sender_address, sender_address_len);
}
*/
pos->peer2handle =
GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2,
- &connect_notify_peer2, NULL, NULL,
- GNUNET_YES, NULL, GNUNET_YES, handlers);
+ &connect_notify_peer2, NULL, NULL, GNUNET_YES,
+ NULL, GNUNET_YES, handlers);
}
}
*/
pos->peer1handle =
GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
- &connect_notify_peer1, NULL, NULL, GNUNET_NO,
- NULL, GNUNET_NO, no_handlers);
+ &connect_notify_peer1, NULL, NULL, GNUNET_NO, NULL,
+ GNUNET_NO, no_handlers);
GNUNET_assert (pos->peer1handle != NULL);
new_peer = GNUNET_malloc (sizeof (struct PeerContext));
new_peer->peer_handle =
- GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL,
- NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
+ GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, NULL,
+ GNUNET_NO, NULL, GNUNET_NO, no_handlers);
new_peer->daemon = d;
new_peer->next = all_peers;
all_peers = new_peer;
size = ntohs (fc->msg->size);
if (bit == size / (fc->mtu - sizeof (struct FragmentHeader)))
fsize =
- (size % (fc->mtu - sizeof (struct FragmentHeader))) +
+ (size % (fc->mtu - sizeof (struct FragmentHeader))) +
sizeof (struct FragmentHeader);
else
fsize = fc->mtu;
static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
static void
-do_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
unsigned int i;
continue;
GNUNET_FRAGMENT_context_destroy (frags[i]);
frags[i] = NULL;
- }
+ }
}
fprintf (stderr, ".");
#endif
/* tolerate 10% loss, i.e. due to duplicate fragment IDs */
- if ( (total >= NUM_MSGS - (NUM_MSGS / 10)) &&
- (ret != 0) )
+ if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
{
if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)
shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
*/
struct MetaValueInformation
{
-
+
/**
* Mime-type of data.
*/
* used in the main libextractor library and yielding
* meta data).
* @param type libextractor-type describing the meta data
- * @param format basic format information about data
+ * @param format basic format information about data
* @param data_mime_type mime-type of data (not of the original file);
* can be NULL (if mime-type is not known)
* @param data actual meta-data found
* @param data_len number of bytes in data
* @return 0 to continue extracting / iterating
- */
+ */
static int
-update_metamap (void *cls,
- const char *plugin_name,
- enum EXTRACTOR_MetaType type,
- enum EXTRACTOR_MetaFormat format,
- const char *data_mime_type,
- const char *data,
- size_t data_len)
+update_metamap (void *cls, const char *plugin_name,
+ enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type, const char *data, size_t data_len)
{
struct GNUNET_CONTAINER_MultiHashMap *map = cls;
GNUNET_HashCode key;
mvi->type = type;
mvi->format = format;
GNUNET_CONTAINER_multihashmap_put (map, &key, mvi,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
}
- mvi->frequency++;
- return 0;
+ mvi->frequency++;
+ return 0;
}
*/
struct KeywordInformation
{
-
+
/**
* Mime-type of keyword.
*/
* @param fi information for publishing the file
*/
static void
-dirproc_add (void *cls, const char *filename,
- struct GNUNET_FS_FileInformation *fi)
+dirproc_add (void *cls, const char *filename,
+ struct GNUNET_FS_FileInformation *fi)
{
struct EntryProcCls *dc = cls;
unsigned int i;
const char *kw;
struct KeywordInformation *ki;
GNUNET_HashCode key;
-
+
GNUNET_assert (fi->next == NULL);
GNUNET_assert (fi->dir == NULL);
fi->next = dc->entries;
dc->entries = fi;
dc->count++;
if (NULL != fi->meta)
- GNUNET_CONTAINER_meta_data_iterate (fi->meta,
- &update_metamap,
- dc->metamap);
- for (i=0;i<fi->keywords->data.ksk.keywordCount;i++)
+ GNUNET_CONTAINER_meta_data_iterate (fi->meta, &update_metamap, dc->metamap);
+ for (i = 0; i < fi->keywords->data.ksk.keywordCount; i++)
{
- kw = fi->keywords->data.ksk.keywords[i];
- GNUNET_CRYPTO_hash (kw, strlen(kw), &key);
+ kw = fi->keywords->data.ksk.keywords[i];
+ GNUNET_CRYPTO_hash (kw, strlen (kw), &key);
ki = GNUNET_CONTAINER_multihashmap_get (dc->keywordmap, &key);
if (ki == NULL)
{
ki = GNUNET_malloc (sizeof (struct KeywordInformation));
ki->keyword = &kw[1];
GNUNET_CONTAINER_multihashmap_put (dc->keywordmap, &key, ki,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
}
- ki->frequency++;
+ ki->frequency++;
}
}
/**
* Threshold to apply for adding meta data.
- */
+ */
unsigned int threshold;
};
* @return GNUNET_OK
*/
static int
-compute_directory_metadata (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+compute_directory_metadata (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ComputeDirectoryMetadataContext *cdmc = cls;
struct MetaValueInformation *mvi = value;
- if (mvi->frequency > cdmc->threshold)
+ if (mvi->frequency > cdmc->threshold)
{
if (mvi->type != EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
- (void) GNUNET_CONTAINER_meta_data_insert (cdmc->meta,
- "<children>",
- mvi->type,
- mvi->format,
- mvi->mime_type,
- mvi->data,
- mvi->data_size);
- if ( (mvi->format == EXTRACTOR_METAFORMAT_UTF8) ||
- (mvi->format == EXTRACTOR_METAFORMAT_C_STRING) )
- GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk,
- mvi->data,
- GNUNET_NO);
- }
+ (void) GNUNET_CONTAINER_meta_data_insert (cdmc->meta, "<children>",
+ mvi->type, mvi->format,
+ mvi->mime_type, mvi->data,
+ mvi->data_size);
+ if ((mvi->format == EXTRACTOR_METAFORMAT_UTF8) ||
+ (mvi->format == EXTRACTOR_METAFORMAT_C_STRING))
+ GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, mvi->data, GNUNET_NO);
+ }
GNUNET_free (mvi);
return GNUNET_OK;
}
/**
* Add keywords that occur in more than the threshold entries of the
- * directory to the directory itself.
+ * directory to the directory itself.
*
* @param cls the 'struct ComputeDirectoryMetadataContext'
* @param key unused
* @return GNUNET_OK
*/
static int
-compute_directory_keywords (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+compute_directory_keywords (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ComputeDirectoryMetadataContext *cdmc = cls;
struct KeywordInformation *ki = value;
- if (ki->frequency > cdmc->threshold)
- (void) GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk,
- ki->keyword,
- GNUNET_NO);
+ if (ki->frequency > cdmc->threshold)
+ (void) GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, ki->keyword, GNUNET_NO);
GNUNET_free (ki);
return GNUNET_OK;
}
dc.metamap = GNUNET_CONTAINER_multihashmap_create (64);
dc.keywordmap = GNUNET_CONTAINER_multihashmap_create (64);
/* update children to point to directory and generate statistics
- on all meta data in children */
+ * on all meta data in children */
scanner (scanner_cls, h, filename, do_index, bo, &dirproc_add, &dc, emsg);
cdmc.meta = GNUNET_CONTAINER_meta_data_create ();
cdmc.ksk = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
cdmc.ksk->type = ksk;
- cdmc.threshold = 1 + dc.count / 2; /* 50% threshold for now */
+ cdmc.threshold = 1 + dc.count / 2; /* 50% threshold for now */
GNUNET_FS_meta_data_make_directory (cdmc.meta);
GNUNET_CONTAINER_multihashmap_iterate (dc.metamap,
- &compute_directory_metadata,
- &cdmc);
+ &compute_directory_metadata, &cdmc);
GNUNET_CONTAINER_multihashmap_iterate (dc.keywordmap,
- &compute_directory_keywords,
- &cdmc);
+ &compute_directory_keywords, &cdmc);
GNUNET_CONTAINER_multihashmap_destroy (dc.metamap);
GNUNET_CONTAINER_multihashmap_destroy (dc.keywordmap);
- GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk,
- GNUNET_FS_DIRECTORY_MIME,
- GNUNET_NO);
+ GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk, GNUNET_FS_DIRECTORY_MIME, GNUNET_NO);
cksk = GNUNET_FS_uri_ksk_canonicalize (cdmc.ksk);
/* remove keywords in children that are already in the
- parent */
+ * parent */
for (epos = dc.entries; NULL != epos; epos = epos->next)
{
- for (i=0;i<cksk->data.ksk.keywordCount;i++)
- {
- kw = cksk->data.ksk.keywords[i];
- GNUNET_FS_uri_ksk_remove_keyword (epos->keywords,
- &kw[1]);
- }
+ for (i = 0; i < cksk->data.ksk.keywordCount; i++)
+ {
+ kw = cksk->data.ksk.keywords[i];
+ GNUNET_FS_uri_ksk_remove_keyword (epos->keywords, &kw[1]);
+ }
}
ret =
GNUNET_FS_file_information_create_empty_directory (h, client_info, cksk,
wpos++;
break;
default:
- if (isspace ((unsigned char) *rpos) ||
- isdigit ((unsigned char) *rpos) )
- break;
+ if (isspace ((unsigned char) *rpos) || isdigit ((unsigned char) *rpos))
+ break;
/* replace characters listed above with '_' */
*wpos = '_';
wpos++;
for (i = 0; i < kc; i++)
{
in = uri->data.ksk.keywords[i];
- GNUNET_FS_uri_ksk_add_keyword (ret,
- &in[1],
- (in[0] == '+') ? GNUNET_YES : GNUNET_NO);
+ GNUNET_FS_uri_ksk_add_keyword (ret, &in[1],
+ (in[0] == '+') ? GNUNET_YES : GNUNET_NO);
sb = GNUNET_strdup (&in[1]);
#define DELIMS " \\|\"'`/&@-_,.;!?+-*^$#~=[]{}()<>"
for (tok = strtok (sb, DELIMS); NULL != tok; tok = strtok (NULL, DELIMS))
#undef DELIMS
{
- if (strlen(tok) < 3)
- continue;
- GNUNET_FS_uri_ksk_add_keyword (ret,
- tok,
- GNUNET_NO);
+ if (strlen (tok) < 3)
+ continue;
+ GNUNET_FS_uri_ksk_add_keyword (ret, tok, GNUNET_NO);
cc = canonicalize_keyword (tok);
if (strlen (cc) > 2)
- GNUNET_FS_uri_ksk_add_keyword (ret,
- cc,
- GNUNET_NO);
+ GNUNET_FS_uri_ksk_add_keyword (ret, cc, GNUNET_NO);
}
GNUNET_free (sb);
}
* @param tc unused
*/
static void
-do_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_FS_stop (fs);
fs = NULL;
* @return GNUNET_OK to continue iteration
*/
static int
-print_indexed (void *cls, const char *filename,
- const GNUNET_HashCode * file_id)
+print_indexed (void *cls, const char *filename, const GNUNET_HashCode * file_id)
{
if (verbose)
- fprintf (stdout,
- "%s: %s\n",
- GNUNET_h2s (file_id),
- filename);
+ fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
else
- fprintf (stdout,
- "%s\n",
- filename);
+ fprintf (stdout, "%s\n", filename);
return GNUNET_OK;
}
{
if (list_indexed_files)
{
- fs = GNUNET_FS_start (cfg,
- "gnunet-fs",
- NULL, NULL,
- GNUNET_FS_FLAGS_NONE);
+ fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE);
if (NULL == fs)
{
ret = 1;
return;
}
- GNUNET_FS_get_indexed_files (fs,
- &print_indexed, NULL,
- &do_shutdown, NULL);
+ GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL, &do_shutdown, NULL);
}
}
};
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]",
- gettext_noop
- ("Special file-sharing operations"),
+ gettext_noop ("Special file-sharing operations"),
options, &run, NULL)) ? ret : 1;
}
*/
static void
update_latencies (const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
unsigned int i;
- for (i=0;i<atsi_count;i++)
+ for (i = 0; i < atsi_count; i++)
{
- if (ntohl(atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
+ if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
{
- GSF_avg_latency.rel_value = (GSF_avg_latency.rel_value * 31 + ntohl (atsi[i].value)) / 32;
+ GSF_avg_latency.rel_value =
+ (GSF_avg_latency.rel_value * 31 + ntohl (atsi[i].value)) / 32;
GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop ("# running average P2P latency (ms)"),
- GSF_avg_latency.rel_value,
- GNUNET_NO);
+ gettext_noop
+ ("# running average P2P latency (ms)"),
+ GSF_avg_latency.rel_value, GNUNET_NO);
break;
}
}
handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GSF_ConnectedPeer *cp;
{
struct GSF_PendingRequest *pr = cls;
- if (GNUNET_YES !=
- GSF_pending_request_test_target_ (pr,
- peer))
+ if (GNUNET_YES != GSF_pending_request_test_target_ (pr, peer))
{
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Loopback routes suppressed"), 1,
- GNUNET_NO);
+ gettext_noop ("# Loopback routes suppressed"), 1,
+ GNUNET_NO);
return;
}
GSF_plan_add_ (cp, pr);
handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GSF_PendingRequest *pr;
struct GNUNET_PeerIdentity pid;
GSF_connected_peer_get_identity_ (cp, &pid);
- if (GNUNET_YES !=
- GSF_pending_request_test_target_ (pr,
- &pid))
+ if (GNUNET_YES != GSF_pending_request_test_target_ (pr, &pid))
{
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# Loopback routes suppressed"), 1,
- GNUNET_NO);
+ gettext_noop ("# Loopback routes suppressed"), 1,
+ GNUNET_NO);
return GNUNET_YES;
}
GSF_plan_add_ (cp, pr);
static void
peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GSF_ConnectedPeer *cp;
GSF_core = GNUNET_CORE_connect (GSF_cfg, 2, /* larger? */
NULL, &peer_init_handler,
&peer_connect_handler,
- &GSF_peer_disconnect_handler_,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO, p2p_handlers);
+ &GSF_peer_disconnect_handler_, NULL,
+ GNUNET_NO, NULL, GNUNET_NO, p2p_handlers);
if (NULL == GSF_core)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
* @return connection latency
*/
static struct GNUNET_TIME_Relative
-get_latency (const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+get_latency (const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
{
unsigned int i;
- for (i=0;i<atsi_count;i++)
+ for (i = 0; i < atsi_count; i++)
if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY)
return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- ntohl (atsi->value));
+ ntohl (atsi->value));
return GNUNET_TIME_UNIT_SECONDS;
}
*/
static void
update_atsi (struct GSF_ConnectedPeer *cp,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
{
struct GNUNET_TIME_Relative latency;
*/
static void
ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
- int32_t amount, struct GNUNET_TIME_Relative res_delay);
+ int32_t amount, struct GNUNET_TIME_Relative res_delay);
/**
if (0 != cp->inc_preference)
{
- GNUNET_ATS_change_preference (ats,
- &target,
- GNUNET_ATS_PREFERENCE_BANDWIDTH,
- (double) cp->inc_preference,
- GNUNET_ATS_PREFERENCE_END);
+ GNUNET_ATS_change_preference (ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
+ (double) cp->inc_preference,
+ GNUNET_ATS_PREFERENCE_END);
cp->inc_preference = 0;
}
/* reservation already done! */
pth->was_reserved = GNUNET_YES;
cp->rc =
- GNUNET_ATS_reserve_bandwidth (ats, &target,
- DBLOCK_SIZE,
- &ats_reserve_callback, cp);
+ GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
+ &ats_reserve_callback, cp);
}
GNUNET_assert (pth->cth == NULL);
pth->cth_in_progress++;
GNUNET_PEER_resolve (cp->ppd.pid, &target);
cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
cp->rc =
- GNUNET_ATS_reserve_bandwidth (ats, &target,
- DBLOCK_SIZE,
- &ats_reserve_callback, cp);
+ GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
+ &ats_reserve_callback, cp);
}
*/
static void
ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
- int32_t amount, struct GNUNET_TIME_Relative res_delay)
+ int32_t amount, struct GNUNET_TIME_Relative res_delay)
{
struct GSF_ConnectedPeer *cp = cls;
struct GSF_PeerTransmitHandle *pth;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reserved %d bytes / need to wait %llu ms for reservation\n",
- (int) amount,
- (unsigned long long) res_delay.rel_value);
+ "Reserved %d bytes / need to wait %llu ms for reservation\n",
+ (int) amount, (unsigned long long) res_delay.rel_value);
cp->rc = NULL;
if (0 == amount)
{
struct GSF_ConnectedPeer *
GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GSF_ConnectedPeer *cp;
char *fn;
uint32_t trust;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to peer %s\n",
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n",
+ GNUNET_i2s (peer));
cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer));
cp->ppd.pid = GNUNET_PEER_intern (peer);
cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
cp->rc =
- GNUNET_ATS_reserve_bandwidth (ats, peer,
- DBLOCK_SIZE,
- &ats_reserve_callback, cp);
+ GNUNET_ATS_reserve_bandwidth (ats, peer, DBLOCK_SIZE,
+ &ats_reserve_callback, cp);
fn = get_trust_filename (peer);
if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
(sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
GNUNET_CONTAINER_multihashmap_put (cp_map, &peer->hashPubKey,
cp,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop
- ("# peers connected"),
- GNUNET_CONTAINER_multihashmap_size (cp_map),
- GNUNET_NO);
+ GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
+ GNUNET_CONTAINER_multihashmap_size (cp_map),
+ GNUNET_NO);
update_atsi (cp, atsi, atsi_count);
GSF_push_start_ (cp);
return cp;
GSF_handle_p2p_migration_stop_ (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct GSF_ConnectedPeer *cp;
const struct MigrationStopMessage *msm;
return GNUNET_OK;
}
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop
- ("# migration stop messages received"),
- 1, GNUNET_NO);
+ gettext_noop ("# migration stop messages received"),
+ 1, GNUNET_NO);
bt = GNUNET_TIME_relative_ntoh (msm->duration);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Migration of content to peer `%s' blocked for %llu ms\n"),
ret =
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_WEAK,
- 2 * GSF_avg_latency.rel_value + 1));
+ (GNUNET_CRYPTO_QUALITY_WEAK,
+ 2 * GSF_avg_latency.rel_value + 1));
GNUNET_STATISTICS_update (GSF_stats,
gettext_noop
("# artificial delays introduced (ms)"),
return NULL;
}
if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
- cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity*) &opt[bits++]);
+ cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity *) &opt[bits++]);
else
cp = cps;
if (cp == NULL)
0) ? (const char *) &opt[bits] : NULL,
bfsize, ntohl (gm->filter_mutator),
1 /* anonymity */ ,
- (uint32_t) priority, ttl, spid,
- GNUNET_PEER_intern (other),
- NULL, 0, /* replies_seen */
+ (uint32_t) priority, ttl, spid, GNUNET_PEER_intern (other), NULL, 0, /* replies_seen */
&handle_p2p_reply, peerreq);
GNUNET_assert (NULL != pr);
peerreq->pr = pr;
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (cp_map,
&peer->hashPubKey, cp));
- GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop
- ("# peers connected"),
- GNUNET_CONTAINER_multihashmap_size (cp_map),
- GNUNET_NO);
+ GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
+ GNUNET_CONTAINER_multihashmap_size (cp_map),
+ GNUNET_NO);
if (NULL != cp->migration_pth)
{
GSF_peer_transmit_cancel_ (cp->migration_pth);
struct GSF_ConnectedPeer *
GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count);
+ unsigned int atsi_count);
/**
GSF_handle_p2p_migration_stop_ (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi,
- unsigned int atsi_count);
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count);
/**
odb = (const struct OnDemandBlock *) data;
off = GNUNET_ntohll (odb->offset);
fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
- if ( (NULL == fn) ||
- (0 != ACCESS (fn, R_OK)) )
+ if ((NULL == fn) || (0 != ACCESS (fn, R_OK)))
{
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# index blocks removed: original file inaccessible"),
- 1,
- GNUNET_YES);
+ gettext_noop
+ ("# index blocks removed: original file inaccessible"),
+ 1, GNUNET_YES);
GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
return GNUNET_SYSERR;
ntohl (sm->anonymity_level),
0 /* priority */ ,
0 /* ttl */ ,
- 0 /* sender PID */ , 0 /* origin PID */,
+ 0 /* sender PID */ ,
+ 0 /* origin PID */ ,
(const GNUNET_HashCode *) &sm[1], sc,
&client_response_handler, cr);
return cr->pr;
if (rp->transmission_counter < 8)
delay =
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- rp->transmission_counter);
+ rp->transmission_counter);
else if (rp->transmission_counter < 32)
delay =
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- 8 + (1LL << (rp->transmission_counter - 8)));
+ 8 +
+ (1LL << (rp->transmission_counter - 8)));
else
- delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- 8 + (1LL << 24));
- delay.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- delay.rel_value + 1);
+ delay =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ 8 + (1LL << 24));
+ delay.rel_value =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ delay.rel_value + 1);
if (rp->transmission_counter != 0)
delay.rel_value += TTL_DECREMENT;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Considering (re)transmission number %u in %llu ms\n",
- (unsigned int) rp->transmission_counter,
- (unsigned long long) delay.rel_value);
+ "Considering (re)transmission number %u in %llu ms\n",
+ (unsigned int) rp->transmission_counter,
+ (unsigned long long) delay.rel_value);
rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay);
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_CONTAINER_heap_insert (pp->delay_heap, rp,
rp->earliest_transmission.abs_value);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map,
- get_rp_key (rp),
- rp));
+ GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map,
+ get_rp_key (rp),
+ rp));
if (GNUNET_SCHEDULER_NO_TASK != pp->task)
GNUNET_SCHEDULER_cancel (pp->task);
pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
/* failed, try again... */
pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# transmission failed (core has no bandwidth)"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# transmission failed (core has no bandwidth)"),
+ 1, GNUNET_NO);
return 0;
}
rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sleeping for %llu ms before retrying requests on plan %p.\n",
- (unsigned long long)
- delay.rel_value, pp);
+ (unsigned long long) delay.rel_value, pp);
#endif
- GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop ("# delay heap timeout"),
- delay.rel_value,
- GNUNET_NO);
-
+ GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# delay heap timeout"),
+ delay.rel_value, GNUNET_NO);
+
pp->task =
- GNUNET_SCHEDULER_add_delayed (delay,
- &schedule_peer_transmission, pp);
+ GNUNET_SCHEDULER_add_delayed (delay, &schedule_peer_transmission, pp);
return;
}
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# query plans executed"), 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# query plans executed"),
+ 1, GNUNET_NO);
/* process from priority heap */
rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
#if DEBUG_FS > 1
* GNUNET_NO if not (merge success)
*/
static int
-merge_pr (void *cls,
- const GNUNET_HashCode *query,
- void *element)
+merge_pr (void *cls, const GNUNET_HashCode * query, void *element)
{
struct MergeContext *mpr = cls;
struct GSF_RequestPlan *rp = element;
if (NULL == pp)
{
pp = GNUNET_malloc (sizeof (struct PeerPlan));
- pp->plan_map =
- GNUNET_CONTAINER_multihashmap_create (128);
+ pp->plan_map = GNUNET_CONTAINER_multihashmap_create (128);
pp->priority_heap =
GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
pp->delay_heap =
mpc.merged = GNUNET_NO;
mpc.pr = pr;
GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map,
- &GSF_pending_request_get_data_ (pr)->query,
- &merge_pr, &mpc);
+ &GSF_pending_request_get_data_
+ (pr)->query, &merge_pr, &mpc);
if (mpc.merged != GNUNET_NO)
return;
GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map,
- &GSF_pending_request_get_data_ (pr)->query,
- &merge_pr, &mpc);
+ &GSF_pending_request_get_data_
+ (pr)->query, &merge_pr, &mpc);
if (mpc.merged != GNUNET_NO)
return;
plan_count++;
GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
rp->pp = pp;
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (pp->plan_map,
- get_rp_key (rp),
- rp,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (pp->plan_map,
+ get_rp_key (rp), rp,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
plan (pp, rp);
}
while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap)))
{
GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (pp->plan_map,
- get_rp_key (rp),
- rp));
+ GNUNET_CONTAINER_multihashmap_remove (pp->plan_map,
+ get_rp_key (rp), rp));
while (NULL != (prl = rp->prl_head))
{
GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)))
{
GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (pp->plan_map,
- get_rp_key (rp),
- rp));
+ GNUNET_CONTAINER_multihashmap_remove (pp->plan_map,
+ get_rp_key (rp), rp));
while (NULL != (prl = rp->prl_head))
{
GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
GNUNET_CONTAINER_heap_remove_node (rp->hn);
plan_count--;
GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map,
- &GSF_pending_request_get_data_ (rpr->prl->pr)->query,
- rp));
+ GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map,
+ &GSF_pending_request_get_data_
+ (rpr->prl->pr)->query,
+ rp));
GNUNET_free (rp);
}
GNUNET_free (rpr->prl);
if (pr->bf != NULL)
GNUNET_CONTAINER_bloomfilter_free (pr->bf);
pr->mingle =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
- pr->bf = GNUNET_BLOCK_construct_bloomfilter (pr->mingle,
- pr->replies_seen,
- pr->replies_seen_count);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+ pr->bf =
+ GNUNET_BLOCK_construct_bloomfilter (pr->mingle, pr->replies_seen,
+ pr->replies_seen_count);
}
if (NULL != bf_data)
{
pr->bf =
- GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, GNUNET_CONSTANTS_BLOOMFILTER_K);
+ GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size,
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
pr->mingle = mingle;
}
else if ((replies_seen_count > 0) &&
pr->mingle =
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
pr->bf =
- GNUNET_BLOCK_construct_bloomfilter (pr->mingle,
- replies_seen,
- replies_seen_count);
- }
+ GNUNET_BLOCK_construct_bloomfilter (pr->mingle, replies_seen,
+ replies_seen_count);
+ }
else
{
for (i = 0; i < pr->replies_seen_count; i++)
- {
- GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
- GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
- }
+ {
+ GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
+ GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
+ }
}
}
}
handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
struct GSF_PendingRequest *pr = cls;
struct ProcessReplyClosure prq;
pr->gh =
GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL,
pr->public_data.type, &pr->public_data.query,
- 5 /* DEFAULT_GET_REPLICATION */,
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- /* FIXME: can no longer pass pr->bf/pr->mingle... */
- xquery, xquery_size, &handle_dht_reply,
- pr);
+ 5 /* DEFAULT_GET_REPLICATION */ ,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ /* FIXME: can no longer pass pr->bf/pr->mingle... */
+ xquery, xquery_size, &handle_dht_reply, pr);
}
/* queue priority */ ,
(0 !=
(GSF_PRO_PRIORITY_UNLIMITED &
- pr->public_data.options)) ? UINT_MAX : datastore_queue_size
+ pr->public_data.options)) ? UINT_MAX :
+ datastore_queue_size
/* max queue size */ ,
GNUNET_TIME_UNIT_FOREVER_REL,
&process_local_reply, pr);
if (NULL != pr->qe)
- return; /* we're done */
+ return; /* we're done */
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop
- ("# Datastore lookups concluded (error queueing)"),
- 1, GNUNET_NO);
+ gettext_noop
+ ("# Datastore lookups concluded (error queueing)"),
+ 1, GNUNET_NO);
goto check_error_and_continue;
}
old_rf = pr->public_data.results_found;
/* queue priority */ ,
(0 !=
(GSF_PRO_PRIORITY_UNLIMITED &
- pr->public_data.options)) ? UINT_MAX : datastore_queue_size
+ pr->public_data.options)) ? UINT_MAX :
+ datastore_queue_size
/* max queue size */ ,
GNUNET_TIME_UNIT_FOREVER_REL,
&process_local_reply, pr);
/* queue priority */ ,
(0 !=
(GSF_PRO_PRIORITY_UNLIMITED & pr->
- public_data.options)) ? UINT_MAX : datastore_queue_size
+ public_data.options)) ? UINT_MAX :
+ datastore_queue_size
/* max queue size */ ,
GNUNET_TIME_UNIT_FOREVER_REL,
&process_local_reply, pr);
/**
* Is the given target a legitimate peer for forwarding the given request?
- *
+ *
* @param pr request
* @param target
* @return GNUNET_YES if this request could be forwarded to the given peer
*/
int
GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
- const struct GNUNET_PeerIdentity *target)
+ const struct GNUNET_PeerIdentity *target)
{
struct GNUNET_PeerIdentity pi;
-
+
if (0 == pr->origin_pid)
return GNUNET_YES;
GNUNET_PEER_resolve (pr->origin_pid, &pi);
- return (0 == memcmp (&pi, target, sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :GNUNET_YES;
+ return (0 ==
+ memcmp (&pi, target,
+ sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :
+ GNUNET_YES;
}
/* queue priority */ ,
(0 !=
(GSF_PRO_PRIORITY_UNLIMITED & pr->
- public_data.options)) ? UINT_MAX : datastore_queue_size
+ public_data.options)) ? UINT_MAX :
+ datastore_queue_size
/* max queue size */ ,
GNUNET_TIME_UNIT_FOREVER_REL,
&process_local_reply, pr);
if (NULL != pr->qe)
return;
GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop
- ("# Datastore lookups concluded (error queueing)"),
- 1, GNUNET_NO);
+ gettext_noop
+ ("# Datastore lookups concluded (error queueing)"),
+ 1, GNUNET_NO);
GNUNET_SCHEDULER_cancel (pr->warn_task);
pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
pr->llc_cont = NULL;
"MAX_PENDING_REQUESTS");
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (GSF_cfg,
- "core",
- "TOTAL_QUOTA_OUT",
- &bps))
+ GNUNET_CONFIGURATION_get_value_number (GSF_cfg, "core", "TOTAL_QUOTA_OUT",
+ &bps))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_
bps = 65536;
}
/* queue size should be #queries we can have pending and satisfy within
- a carry interval: */
- datastore_queue_size = bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE;
-
+ * a carry interval: */
+ datastore_queue_size =
+ bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE;
+
active_to_migration =
GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING");
datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
/**
* Is the given target a legitimate peer for forwarding the given request?
- *
+ *
* @param pr request
* @param target
* @return GNUNET_YES if this request could be forwarded to the given peer
*/
int
GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
- const struct GNUNET_PeerIdentity *target);
+ const struct GNUNET_PeerIdentity *target);
"Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key),
type);
#endif
- GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */,
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- type, size, data, expiration, GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */ ,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, type, size, data,
+ expiration, GNUNET_TIME_UNIT_FOREVER_REL,
&delay_dht_put_blocks, po);
}
static int
find_min_expire (void *cls, const char *tname,
- struct GNUNET_TIME_Absolute expiration, const void *addr,
- uint16_t addrlen)
+ struct GNUNET_TIME_Absolute expiration, const void *addr,
+ uint16_t addrlen)
{
struct GNUNET_TIME_Absolute *min = cls;
advertisement_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
GNUNET_assert (NULL != client_adv_handler);
return (*client_adv_handler) (cls, peer, message, atsi, atsi_count);
static void
connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
static void
handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
GNUNET_assert (stat_connection_count < UINT_MAX);
stat_connection_count++;
handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
size_t size;
size_t uri_size;
static void
connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
size_t size;
*/
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
if (peer == NULL)
return;
ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
char *hostname;
char *expected_uri;
GNUNET_free (filename);
}
p->core =
- GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL,
- GNUNET_NO, NULL, GNUNET_NO, learn_handlers);
+ GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, GNUNET_NO,
+ NULL, GNUNET_NO, learn_handlers);
GNUNET_assert (NULL != p->core);
p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
GNUNET_assert (NULL != p->stats);
*/
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
if (peer == NULL)
return;
/**
* Actual traffic on this connection from the other peer to this peer.
- *
+ *
* Unit: [bytes/second]
*/
GNUNET_ATS_UTILIZATION_UP,
/**
* Actual traffic on this connection from this peer to the other peer.
- *
+ *
* Unit: [bytes/second]
*/
GNUNET_ATS_UTILIZATION_DOWN,
* Dialup: 500
*/
GNUNET_ATS_QUALITY_NET_DELAY,
-
+
/**
* Distance on network layer (required for distance-vector routing).
*
* Unit: [DV-hops]
*/
GNUNET_ATS_QUALITY_NET_DISTANCE,
-
+
/**
* Network overhead on WAN (Wide-Area Network)
*
* UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
*/
GNUNET_ATS_COST_WAN,
-
+
/**
* Network overhead on LAN (Local-Area Network)
*
* UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
*/
GNUNET_ATS_COST_LAN,
-
+
/**
* Network overhead on WLAN (Wireless Local Area Network)
*
* UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
*/
GNUNET_ATS_COST_WLAN
-
-
-
- /* Cost related values */
- /* =================== */
-
+ /* Cost related values */
+ /* =================== */
/**
* Volume based cost in financial units to transmit data
*
* LAN: 0 [cent/MB]
* 2G : 10 [cent/MB]
*/
- // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
-
+ // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
/**
* Time based cost in financial units to transmit data
*
* LAN : 0 [cent/h]
* Dialup: 10 [cent/h]
*/
- // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
-
+ // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
/**
* Computational costs
*
* HTTPS with AES CBC-128: 5,279
* HTTPS with RC4-1024: 2,652
*/
- // GNUNET_ATS_COST_COMPUTATIONAL = 3,
-
+ // GNUNET_ATS_COST_COMPUTATIONAL = 3,
/**
* Energy consumption
*
* WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s)
* Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
*/
- // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
-
+ // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
/**
* Connect cost
* How many bytes are transmitted to initiate a new connection using
* 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS
*
* */
- // GNUNET_ATS_COST_CONNECT = 5,
-
+ // GNUNET_ATS_COST_CONNECT = 5,
/**
* Bandwidth cost
*
* Dial-up: 8 (64 Kbit/s)
*
*/
- // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
-
+ // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
/**
* Network overhead
*
* UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
* UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
*/
- // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
-
-
- /* Quality related values */
- /* ====================== */
-
- /* Physical layer quality properties */
-
+ // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
+ /* Quality related values */
+ /* ====================== */
+ /* Physical layer quality properties */
/**
* Signal strength on physical layer
*
* Unit: [dBm]
*/
- // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
-
+ // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
/**
* Collision rate on physical layer
*
* Unit: [B/s]
*/
- // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
-
+ // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
/**
* Error rate on physical layer
*
* Unit: [B/s]
*/
- // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
-
+ // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
/**
* Jitter
* Time variations of the delay
*
* Unit: [ms]
*/
- // GNUNET_ATS_QUALITY_NET_JITTER = 1029,
-
+ // GNUNET_ATS_QUALITY_NET_JITTER = 1029,
/**
* Error rate on network layer
*
* Note: This numbers are just assumptions as an example, not
* measured or somehow determined
*/
- // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
-
+ // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
/**
* Drop rate on network layer
* Bytes actively dismissed by a network component during transmission
* Note: This numbers are just assumptions as an example, not
* measured or somehow determined
*/
- // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
-
+ // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
/**
* Loss rate on network layer
* Bytes lost during transmission
* Note: This numbers are just assumptions as an example, not measured
* or somehow determined
*/
- // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
-
+ // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
/**
* Throughput on network layer
*
* Dialup: 4
*
*/
- // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033,
-
-
- /* Availability related values */
- /* =========================== */
-
+ // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033,
+ /* Availability related values */
+ /* =========================== */
/**
* Is a peer reachable?
*/
- // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048,
-
+ // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048,
/**
* Is there a connection established to a peer using this transport
*/
- // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
+ // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
};
/**
* Signature of a function called by ATS with the current bandwidth
- * and address preferences as determined by ATS.
+ * and address preferences as determined by ATS.
*
* @param cls closure
* @param peer identity of the new peer
struct
GNUNET_BANDWIDTH_Value32NBO
bandwidth_in,
- const struct
- GNUNET_ATS_Information
- * ats,
- uint32_t ats_count);
+ const struct
+ GNUNET_ATS_Information *
+ ats, uint32_t ats_count);
/**
*/
struct GNUNET_ATS_SchedulingHandle *
GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ATS_AddressSuggestionCallback suggest_cb,
- void *suggest_cb_cls);
+ GNUNET_ATS_AddressSuggestionCallback suggest_cb,
+ void *suggest_cb_cls);
/**
void
GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- struct Session *session,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session,
const struct GNUNET_ATS_Information *ats,
uint32_t ats_count);
*/
void
GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct Session *session,
- int in_use);
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session,
+ int in_use);
/**
* A session got destroyed, stop including it as a valid address.
void
GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct Session *session);
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session);
/* ******************************** Performance API ***************************** */
* @param ats_count number of performance records in 'ats'
*/
typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_out,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_in,
- const struct
- GNUNET_ATS_Information
- * ats,
- uint32_t ats_count);
+ const struct
+ GNUNET_PeerIdentity * peer,
+ const char *plugin_name,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ struct
+ GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out,
+ struct
+ GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in,
+ const struct
+ GNUNET_ATS_Information *
+ ats, uint32_t ats_count);
/**
*/
struct GNUNET_ATS_PerformanceHandle *
GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ATS_PeerInformationCallback infocb,
- void *infocb_cls);
+ GNUNET_ATS_PeerInformationCallback infocb,
+ void *infocb_cls);
/**
* long should the client wait until re-trying?
*/
typedef void (*GNUNET_ATS_ReservationCallback) (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- int32_t amount,
- struct
- GNUNET_TIME_Relative
- res_delay);
+ const struct GNUNET_PeerIdentity
+ * peer, int32_t amount,
+ struct GNUNET_TIME_Relative
+ res_delay);
*/
struct GNUNET_ATS_ReservationContext *
GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
- const struct GNUNET_PeerIdentity *peer,
- int32_t amount,
- GNUNET_ATS_ReservationCallback rcb,
- void *rcb_cls);
+ const struct GNUNET_PeerIdentity *peer,
+ int32_t amount,
+ GNUNET_ATS_ReservationCallback rcb,
+ void *rcb_cls);
/**
* @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
*/
void
-GNUNET_ATS_reserve_bandwidth_cancel (struct
- GNUNET_ATS_ReservationContext *rc);
+GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
* Change the peer's bandwidth value (value per byte of bandwidth in
* the goal function) to the given amount. The argument is followed
* by a double value giving the desired value (can be negative).
- * Preference changes are forgotten if peers disconnect.
+ * Preference changes are forgotten if peers disconnect.
*/
GNUNET_ATS_PREFERENCE_BANDWIDTH,
* the latency preferences.
*/
GNUNET_ATS_PREFERENCE_LATENCY
-
};
-
+
/**
* Change preferences for the given peer. Preference changes are forgotten if peers
* disconnect.
- *
+ *
* @param ph performance handle
* @param peer identifies the peer
* @param ... 0-terminated specification of the desired changes
*/
void
GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
- const struct GNUNET_PeerIdentity *peer,
- ...);
+ const struct GNUNET_PeerIdentity *peer, ...);
*/
struct GNUNET_CONTAINER_BloomFilter *
GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator,
- const GNUNET_HashCode *seen_results,
- unsigned int seen_results_count);
+ const GNUNET_HashCode * seen_results,
+ unsigned int seen_results_count);
#if 0 /* keep Emacsens' auto-indent happy */
* Number of log calls to ignore.
*/
extern unsigned int skip_log;
+
#if !defined(GNUNET_CULL_LOGGING)
-int
-GNUNET_get_log_call_status (int caller_level, const char *comp, const char *file, const char *function, int line);
+int
+GNUNET_get_log_call_status (int caller_level, const char *comp,
+ const char *file, const char *function, int line);
#endif
/**
* Main log function.
*/
void
GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
- const char *message, ...);
+ const char *message, ...);
#if !defined(GNUNET_CULL_LOGGING)
#define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\
const struct
GNUNET_PeerIdentity * peer,
const struct
- GNUNET_ATS_Information
- * atsi,
- unsigned int atsi_count);
+ GNUNET_ATS_Information * atsi,
+ unsigned int atsi_count);
/**
other,
const struct GNUNET_MessageHeader *
message,
- const struct
- GNUNET_ATS_Information *
- atsi,
- unsigned int atsi_count);
+ const struct GNUNET_ATS_Information
+ * atsi, unsigned int atsi_count);
/**
*/
typedef void (*GNUNET_CORE_StartupCallback) (void *cls,
struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *my_identity);
+ const struct GNUNET_PeerIdentity *
+ my_identity);
/**
typedef void (*GNUNET_DHT_GetIterator) (void *cls,
struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
+ const struct GNUNET_PeerIdentity *
+ get_path, unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *
+ put_path, unsigned int put_path_length,
enum GNUNET_BLOCK_Type type,
size_t size, const void *data);
struct GNUNET_TIME_Relative timeout,
enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
uint32_t desired_replication_level,
- enum GNUNET_DHT_RouteOption options,
- const void *xquery,
+ enum GNUNET_DHT_RouteOption options, const void *xquery,
size_t xquery_size, GNUNET_DHT_GetIterator iter,
void *iter_cls);
sender,
const struct GNUNET_MessageHeader *
message,
- const struct
- GNUNET_ATS_Information *
- atsi);
+ const struct GNUNET_ATS_Information
+ * atsi);
/**
const struct GNUNET_PeerIdentity
* peer,
const struct
- GNUNET_ATS_Information
- * atsi);
+ GNUNET_ATS_Information * atsi);
* of the library (same as what 'GNUNET_PLUGIN_load' would
* have returned for the given library name)
*/
-typedef void (*GNUNET_PLUGIN_LoaderCallback)(void *cls,
- const char *library_name,
- void *lib_ret);
+typedef void (*GNUNET_PLUGIN_LoaderCallback) (void *cls,
+ const char *library_name,
+ void *lib_ret);
/**
* @param cb function to call for each plugin found
* @param cb_cls closure for 'cb'
*/
-void
-GNUNET_PLUGIN_load_all (const char *basename,
- void *arg,
- GNUNET_PLUGIN_LoaderCallback cb,
- void *cb_cls);
+void
+GNUNET_PLUGIN_load_all (const char *basename, void *arg,
+ GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls);
/**
*/
void
GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
- *tc,
- int success);
+ *tc, int success);
/**
*/
int
GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
- unsigned long long *size);
+ unsigned long long *size);
/**
*/
int
GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
- struct GNUNET_TIME_Relative *rtime);
+ struct GNUNET_TIME_Relative *rtime);
/**
* @param peer (claimed) identity of the other peer
* @param message the message
* @param ats performance data
- * @param ats_count number of entries in ats
+ * @param ats_count number of entries in ats
*/
typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
const struct
GNUNET_MessageHeader *
message,
const struct
- GNUNET_ATS_Information
- * ats, uint32_t ats_count);
+ GNUNET_ATS_Information * ats,
+ uint32_t ats_count);
/**
const struct GNUNET_PeerIdentity
* peer,
const struct
- GNUNET_ATS_Information
- * ats, uint32_t ats_count);
+ GNUNET_ATS_Information * ats,
+ uint32_t ats_count);
/**
* Function called to notify transport users that another
* Path itself
*/
struct MeshPeerPath *path;
-
+
/**
* Position in peer's transmit queue
*/
/**
* Own private key
*/
-static struct GNUNET_CRYPTO_RsaPrivateKey* my_private_key;
+static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
/**
* Own public key.
announce_application (void *cls, const GNUNET_HashCode * key, void *value)
{
/* FIXME are hashes in multihash map equal on all aquitectures? */
- GNUNET_DHT_put (dht_handle,
- key,
- 10U,
+ GNUNET_DHT_put (dht_handle, key, 10U,
GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- GNUNET_BLOCK_TYPE_TEST,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_BLOCK_TYPE_TEST,
sizeof (struct GNUNET_PeerIdentity),
(const char *) &my_full_id,
#if MESH_DEBUG
GNUNET_DHT_put (dht_handle, /* DHT handle */
&my_full_id.hashPubKey, /* Key to use */
10U, /* Replication level */
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
+ GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
GNUNET_BLOCK_TYPE_TEST, /* Block type */
- sizeof(my_full_id), /* Size of the data */
- (char *)&my_full_id, /* Data itself */
+ sizeof (my_full_id), /* Size of the data */
+ (char *) &my_full_id, /* Data itself */
GNUNET_TIME_absolute_get_forever (), /* Data expiration */
GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */
#if MESH_DEBUG_DHT
const struct GNUNET_PeerIdentity *get_path,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data);
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data);
/******************************************************************************/
* Allow a client to send more data after transmitting a multicast message
* which some neighbor has not yet accepted altough a reasonable time has
* passed.
- *
+ *
* @param cls Closure (DataDescriptor containing the task identifier)
* @param tc Task Context
*/
static void
-client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_allow_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct MeshDataDescriptor *info = cls;
*(info->copies));
#endif
*(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SERVER_receive_done(info->client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (info->client, GNUNET_OK);
}
* 0 if the tunnel remained unaffected.
*/
static GNUNET_PEER_Id
-tunnel_notify_connection_broken (struct MeshTunnel *t,
- GNUNET_PEER_Id p1,
+tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1,
GNUNET_PEER_Id p2);
MESH_TunnelNumber *tid;
unsigned int count;
uint16_t type;
- char cbuf[htons(msg->size)];
+ char cbuf[htons (msg->size)];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n");
type = ntohs (payload->type);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type);
- memcpy (cbuf, msg, sizeof(cbuf));
- switch (htons(msg->type))
+ memcpy (cbuf, msg, sizeof (cbuf));
+ switch (htons (msg->type))
{
struct GNUNET_MESH_Unicast *uc;
struct GNUNET_MESH_Multicast *mc;
struct GNUNET_MESH_ToOrigin *to;
- case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- uc = (struct GNUNET_MESH_Unicast *) cbuf;
- tid = &uc->tid;
- oid = &uc->oid;
- break;
- case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
- mc = (struct GNUNET_MESH_Multicast *) cbuf;
- tid = &mc->tid;
- oid = &mc->oid;
- break;
- case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- to = (struct GNUNET_MESH_ToOrigin *) cbuf;
- tid = &to->tid;
- oid = &to->oid;
- break;
- default:
- GNUNET_break (0);
- return 0;
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ uc = (struct GNUNET_MESH_Unicast *) cbuf;
+ tid = &uc->tid;
+ oid = &uc->oid;
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+ mc = (struct GNUNET_MESH_Multicast *) cbuf;
+ tid = &mc->tid;
+ oid = &mc->oid;
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ to = (struct GNUNET_MESH_ToOrigin *) cbuf;
+ tid = &to->tid;
+ oid = &to->oid;
+ break;
+ default:
+ GNUNET_break (0);
+ return 0;
}
- t = tunnel_get (oid, ntohl(*tid));
+ t = tunnel_get (oid, ntohl (*tid));
if (NULL == t)
{
GNUNET_break (0);
{
count++;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n");
- GNUNET_SERVER_notification_context_unicast (
- nc,
- c->handle,
- (struct GNUNET_MessageHeader *) cbuf,
- GNUNET_YES);
+ GNUNET_SERVER_notification_context_unicast (nc, c->handle,
+ (struct GNUNET_MessageHeader
+ *) cbuf, GNUNET_YES);
}
}
return count;
/**
* Notify the client that owns the tunnel that a peer has connected to it
* (the requested path to it has been confirmed).
- *
+ *
* @param t Tunnel whose owner to notify
* @param id Short id of the peer that has connected
*/
pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
pc.tunnel_id = htonl (t->local_tid);
GNUNET_PEER_resolve (id, &pc.peer);
- GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
- &pc.header, GNUNET_NO);
+ GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, &pc.header,
+ GNUNET_NO);
}
/**
* Notify all clients (not depending on registration status) that the incoming
* tunnel is no longer valid.
- *
+ *
* @param t Tunnel that was destroyed.
*/
static void
send_clients_tunnel_destroy (struct MeshTunnel *t)
{
- struct GNUNET_MESH_TunnelMessage msg;
+ struct GNUNET_MESH_TunnelMessage msg;
- msg.header.size = htons (sizeof (msg));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
- msg.tunnel_id = htonl (t->local_tid);
- GNUNET_SERVER_notification_context_broadcast(nc, &msg.header, GNUNET_NO);
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
+ msg.tunnel_id = htonl (t->local_tid);
+ GNUNET_SERVER_notification_context_broadcast (nc, &msg.header, GNUNET_NO);
}
/**
* Decrements the reference counter and frees all resources if needed
- *
+ *
* @param dd Data Descriptor used in a multicast message
*/
static void
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: cancelling client timeout (%u)...\n",
*(dd->timeout_task));
- GNUNET_SCHEDULER_cancel(*(dd->timeout_task));
+ GNUNET_SCHEDULER_cancel (*(dd->timeout_task));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n");
GNUNET_SERVER_receive_done (dd->client, GNUNET_OK);
}
/**
* Cancel a core transmission that was already requested and free all resources
* associated to the request.
- *
+ *
* @param peer PeeInfo of the peer whose transmission is cancelled.
* @param i Position of the transmission to be cancelled.
*/
static void
-peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i)
+peer_info_cancel_transmission (struct MeshPeerInfo *peer, unsigned int i)
{
if (NULL != peer->core_transmit[i])
{
GNUNET_PEER_resolve (peer->id, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: Cancelling data transmission at %s [%u]\n",
- GNUNET_i2s (&id),
- i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: message type %u\n",
+ GNUNET_i2s (&id), i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message type %u\n",
peer->types[i]);
}
#endif
/* TODO: notify that tranmission has failed */
switch (peer->types[i])
{
- case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
- case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n");
- dd = peer->infos[i];
- data_descriptor_decrement_multicast (dd);
- break;
- case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n");
- path_info = peer->infos[i];
- path_destroy(path_info->path);
- break;
- default:
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n");
+ case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n");
+ dd = peer->infos[i];
+ data_descriptor_decrement_multicast (dd);
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n");
+ path_info = peer->infos[i];
+ path_destroy (path_info->path);
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n");
}
GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]);
peer->core_transmit[i] = NULL;
GNUNET_free (peer->infos[i]);
- }
+ }
}
{
/* All positions are taken! Overwriting! */
GNUNET_break (0);
- peer_info_cancel_transmission(peer, 0);
+ peer_info_cancel_transmission (peer, 0);
return 0;
}
}
{
struct GNUNET_PeerIdentity id;
- GNUNET_PEER_resolve(peer, &id);
- return peer_info_get(&id);
+ GNUNET_PEER_resolve (peer, &id);
+ return peer_info_get (&id);
}
* @return always GNUNET_YES, to keep iterating
*/
static int
-peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value)
+peer_info_delete_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
{
struct MeshTunnel *t = cls;
struct MeshPeerInfo *peer = value;
for (i = 0; i < peer->ntunnels; i++)
{
- if (0 == memcmp(&peer->tunnels[i]->id,
- &t->id,
- sizeof(struct MESH_TunnelID)))
+ if (0 ==
+ memcmp (&peer->tunnels[i]->id, &t->id, sizeof (struct MESH_TunnelID)))
{
peer->ntunnels--;
peer->tunnels[i] = peer->tunnels[peer->ntunnels];
/**
- * Core callback to write a
+ * Core callback to write a
*
* @param cls Closure (MeshDataDescriptor with data in "data" member).
* @param size Number of bytes available in buf.
* @param buf Where the to write the message.
- *
+ *
* @return number of bytes written to buf
*/
static size_t
GNUNET_PEER_resolve (info->peer->id, &id);
info->peer->core_transmit[info->handler_n] =
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 100,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- size,
- &send_core_data_raw,
- info);
- return 0;
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
+ GNUNET_TIME_UNIT_FOREVER_REL, &id,
+ size, &send_core_data_raw, info);
+ return 0;
}
info->peer->core_transmit[info->handler_n] = NULL;
memcpy (buf, msg, total_size);
neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST;
neighbor->infos[i] = info;
neighbor->core_transmit[i] =
- GNUNET_CORE_notify_transmit_ready(core_handle,
- 0,
- 100,
- GNUNET_TIME_UNIT_FOREVER_REL,
- peer,
- size,
- &send_core_data_raw,
- info);
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
+ GNUNET_TIME_UNIT_FOREVER_REL, peer,
+ size, &send_core_data_raw, info);
}
/**
* Sends a CREATE PATH message for a path to a peer, properly registrating
* all used resources.
- *
+ *
* @param peer PeerInfo of the final peer for whom this path is being created.
* @param p Path itself.
* @param t Tunnel for which the path is created.
*/
static void
-send_create_path (struct MeshPeerInfo *peer,
- struct MeshPeerPath *p,
+send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
struct MeshTunnel *t)
{
struct GNUNET_PeerIdentity id;
if (NULL == p)
{
- p = tree_get_path_to_peer(t->tree, peer->id);
+ p = tree_get_path_to_peer (t->tree, peer->id);
if (NULL == p)
{
GNUNET_break (0);
}
if (i >= p->length - 1)
{
- path_destroy(p);
+ path_destroy (p);
GNUNET_break (0);
return;
}
- GNUNET_PEER_resolve(p->peers[i + 1], &id);
+ GNUNET_PEER_resolve (p->peers[i + 1], &id);
path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
path_info->path = p;
path_info->t = t;
- neighbor = peer_info_get(&id);
+ neighbor = peer_info_get (&id);
path_info->peer = neighbor;
- path_info->pos = peer_info_transmit_slot(neighbor);
+ path_info->pos = peer_info_transmit_slot (neighbor);
neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE;
neighbor->infos[path_info->pos] = path_info;
- neighbor->core_transmit[path_info->pos] =
- GNUNET_CORE_notify_transmit_ready (
- core_handle, /* handle */
- 0, /* cork */
- 0, /* priority */
- GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
- &id, /* target */
- sizeof (struct GNUNET_MESH_ManipulatePath)
- + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
- &send_core_create_path, /* callback */
- path_info); /* cls */
+ neighbor->core_transmit[path_info->pos] = GNUNET_CORE_notify_transmit_ready (core_handle, /* handle */
+ 0, /* cork */
+ 0, /* priority */
+ GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
+ &id, /* target */
+ sizeof (struct GNUNET_MESH_ManipulatePath) + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
+ &send_core_create_path, /* callback */
+ path_info); /* cls */
}
/**
* Sends a DESTROY PATH message to free resources for a path in a tunnel
- *
+ *
* @param t Tunnel whose path to destroy.
* @param destination Short ID of the peer to whom the path to destroy.
*/
struct MeshPeerPath *p;
size_t size;
- p = tree_get_path_to_peer(t->tree, destination);
+ p = tree_get_path_to_peer (t->tree, destination);
if (NULL == p)
{
GNUNET_break (0);
pi = (struct GNUNET_PeerIdentity *) &msg[1];
for (i = 0; i < p->length; i++)
{
- GNUNET_PEER_resolve(p->peers[i], &pi[i]);
+ GNUNET_PEER_resolve (p->peers[i], &pi[i]);
}
- send_message (&msg->header, path_get_first_hop(t->tree, destination));
+ send_message (&msg->header, path_get_first_hop (t->tree, destination));
}
path_destroy (p);
}
/**
* Try to establish a new connection to this peer.
* Use the best path for the given tunnel.
- * If the peer doesn't have any path to it yet, try to get one.
+ * If the peer doesn't have any path to it yet, try to get one.
* If the peer already has some path, send a CREATE PATH towards it.
*
* @param peer PeerInfo of the peer.
if (NULL != peer->path_head)
{
- p = tree_get_path_to_peer(t->tree, peer->id);
+ p = tree_get_path_to_peer (t->tree, peer->id);
if (NULL == p)
{
GNUNET_break (0);
if (p->length > 1)
{
- send_create_path(peer, p, t);
+ send_create_path (peer, p, t);
}
else
{
- path_destroy(p);
- send_client_peer_connected(t, myid);
+ path_destroy (p);
+ send_client_peer_connected (t, myid);
}
}
else if (NULL == peer->dhtget)
{
struct GNUNET_PeerIdentity id;
- GNUNET_PEER_resolve(peer->id, &id);
- path_info = GNUNET_malloc(sizeof(struct MeshPathInfo));
+ GNUNET_PEER_resolve (peer->id, &id);
+ path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
path_info->peer = peer;
path_info->t = t;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Starting DHT GET for peer %s\n",
- GNUNET_i2s (&id));
+ "MESH: Starting DHT GET for peer %s\n", GNUNET_i2s (&id));
peer->dhtgetcls = path_info;
- peer->dhtget =
- GNUNET_DHT_get_start(dht_handle, /* handle */
- GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
- GNUNET_BLOCK_TYPE_TEST, /* type */
- &id.hashPubKey, /* key to search */
- 4, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */
- 0, /* xquery bits */
- &dht_get_id_handler,
- path_info);
+ peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
+ GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
+ GNUNET_BLOCK_TYPE_TEST, /* type */
+ &id.hashPubKey, /* key to search */
+ 4, /* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
+ 0, /* xquery bits */
+ &dht_get_id_handler, path_info);
}
/* Otherwise, there is no path but the DHT get is already started. */
}
/**
* Destroy the peer_info and free any allocated resources linked to it
- *
+ *
* @param pi The peer_info to destroy.
- *
+ *
* @return GNUNET_OK on success
*/
static int
GNUNET_PEER_change_rc (pi->id, -1);
if (GNUNET_YES !=
- GNUNET_CONTAINER_multihashmap_remove (peers,&id.hashPubKey, pi))
+ GNUNET_CONTAINER_multihashmap_remove (peers, &id.hashPubKey, pi))
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "MESH: removing peer %s, not in hashmap\n",
- GNUNET_i2s (&id));
+ "MESH: removing peer %s, not in hashmap\n", GNUNET_i2s (&id));
}
if (NULL != pi->dhtget)
{
- GNUNET_DHT_get_stop(pi->dhtget);
+ GNUNET_DHT_get_stop (pi->dhtget);
GNUNET_free (pi->dhtgetcls);
}
for (i = 0; i < CORE_QUEUE_SIZE; i++)
{
- peer_info_cancel_transmission(pi, i);
+ peer_info_cancel_transmission (pi, i);
}
p = pi->path_head;
while (NULL != p)
* TODO: optimize (see below)
*/
static void
-peer_info_remove_path (struct MeshPeerInfo *peer,
- GNUNET_PEER_Id p1,
+peer_info_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1,
GNUNET_PEER_Id p2)
{
struct MeshPeerPath *p;
* Some of them might already have a path to reach them that does not
* involve p1 and p2. Adding all anew might render in a better tree than
* the trivial immediate fix.
- *
+ *
* Trivial immiediate fix: try to reconnect to the disconnected node. All
* its children will be reachable trough him.
*/
- peer_d = peer_info_get_short(d);
+ peer_d = peer_info_get_short (d);
best = UINT_MAX;
aux = NULL;
for (p = peer_d->path_head; NULL != p; p = p->next)
{
- if ((cost = path_get_cost(peer->tunnels[i]->tree, p)) < best)
+ if ((cost = path_get_cost (peer->tunnels[i]->tree, p)) < best)
{
best = cost;
aux = p;
if (NULL != aux)
{
/* No callback, as peer will be already disconnected */
- tree_add_path(peer->tunnels[i]->tree, aux, NULL, NULL);
+ tree_add_path (peer->tunnels[i]->tree, aux, NULL, NULL);
}
else
{
* @param trusted Do we trust that this path is real?
*/
void
-peer_info_add_path (struct MeshPeerInfo *peer_info,
- struct MeshPeerPath *path,
+peer_info_add_path (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path,
int trusted)
{
struct MeshPeerPath *aux;
{
if (path->peers[l] == myid)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: shortening path by %u\n",
- l);
- for (l2 = 0; l2 < path->length - l - 1 ; l2++)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shortening path by %u\n", l);
+ for (l2 = 0; l2 < path->length - l - 1; l2++)
{
path->peers[l2] = path->peers[l + l2];
}
path->length -= l;
l = 1;
- path->peers = GNUNET_realloc (path->peers,
- path->length * sizeof (GNUNET_PEER_Id));
+ path->peers =
+ GNUNET_realloc (path->peers, path->length * sizeof (GNUNET_PEER_Id));
}
}
#if MESH_DEBUG
- {
+ {
struct GNUNET_PeerIdentity id;
GNUNET_PEER_resolve (peer_info->id, &id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: adding path [%u] to peer %s\n",
- path->length,
- GNUNET_i2s (&id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: adding path [%u] to peer %s\n",
+ path->length, GNUNET_i2s (&id));
}
#endif
l = path_get_length (path);
if (l2 > l)
{
GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head,
- peer_info->path_tail,
- aux,
- path);
+ peer_info->path_tail, aux, path);
return;
}
else
{
- if (l2 == l && memcmp(path->peers, aux->peers, l) == 0)
+ if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
{
- path_destroy(path);
+ path_destroy (path);
return;
}
}
}
- GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head,
- peer_info->path_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail,
path);
return;
}
*/
static void
peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info,
- struct MeshPeerPath *path,
- int trusted)
+ struct MeshPeerPath *path, int trusted)
{
- path_invert(path);
+ path_invert (path);
peer_info_add_path (peer_info, path, trusted);
}
p = path_new (1);
p->peers[0] = myid;
- GNUNET_PEER_change_rc(myid, 1);
+ GNUNET_PEER_change_rc (myid, 1);
i = get_path_length;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i);
for (i--; i >= 0; i--)
{
id = GNUNET_PEER_intern (&get_path[i]);
if (p->length > 0 && id == p->peers[p->length - 1])
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
- GNUNET_PEER_change_rc(id, -1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
+ GNUNET_PEER_change_rc (id, -1);
}
else
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Adding from GET: %s.\n",
- GNUNET_i2s(&get_path[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from GET: %s.\n",
+ GNUNET_i2s (&get_path[i]));
p->length++;
p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length);
p->peers[p->length - 1] = id;
}
}
i = put_path_length;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i);
for (i--; i >= 0; i--)
{
id = GNUNET_PEER_intern (&put_path[i]);
}
if (p->length > 0 && id == p->peers[p->length - 1])
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
- GNUNET_PEER_change_rc(id, -1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
+ GNUNET_PEER_change_rc (id, -1);
}
else
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Adding from PUT: %s.\n",
- GNUNET_i2s(&put_path[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from PUT: %s.\n",
+ GNUNET_i2s (&put_path[i]));
p->length++;
p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length);
p->peers[p->length - 1] = id;
}
#if MESH_DEBUG
if (get_path_length > 0)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: (first of GET: %s)\n",
- GNUNET_i2s(&get_path[0]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of GET: %s)\n",
+ GNUNET_i2s (&get_path[0]));
if (put_path_length > 0)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: (first of PUT: %s)\n",
- GNUNET_i2s(&put_path[0]));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: In total: %d hops\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of PUT: %s)\n",
+ GNUNET_i2s (&put_path[0]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: In total: %d hops\n",
p->length);
for (i = 0; i < p->length; i++)
{
struct GNUNET_PeerIdentity peer_id;
- GNUNET_PEER_resolve(p->peers[i], &peer_id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: %u: %s\n",
- p->peers[i],
- GNUNET_i2s(&peer_id));
+ GNUNET_PEER_resolve (p->peers[i], &peer_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %u: %s\n", p->peers[i],
+ GNUNET_i2s (&peer_id));
}
#endif
return p;
if (NULL != t->client && NULL != nc)
{
struct GNUNET_MESH_PeerControl msg;
+
msg.header.size = htons (sizeof (msg));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
msg.tunnel_id = htonl (t->local_tid);
GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
&msg.header, GNUNET_NO);
}
- peer = peer_info_get_short(peer_id);
+ peer = peer_info_get_short (peer_id);
path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
path_info->peer = peer;
path_info->t = t;
- GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info);
+ GNUNET_SCHEDULER_add_now (&peer_info_connect_task, path_info);
}
unsigned int best_cost;
unsigned int cost;
- GNUNET_PEER_resolve(peer->id, &id);
+ GNUNET_PEER_resolve (peer->id, &id);
if (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey))
+ GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey))
{
t->peers_total++;
GNUNET_array_append (peer->tunnels, peer->ntunnels, t);
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(
- t->peers,
- &id.hashPubKey,
- peer,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (t->peers, &id.hashPubKey,
+ peer,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
}
if (NULL != (p = peer->path_head))
{
best_p = p;
- best_cost = path_get_cost(t->tree, p);
+ best_cost = path_get_cost (t->tree, p);
while (NULL != p)
{
if ((cost = path_get_cost (t->tree, p)) < best_cost)
else
{
/* Start a DHT get if necessary */
- peer_info_connect(peer, t);
+ peer_info_connect (peer, t);
}
}
*
*/
static void
-tunnel_add_path (struct MeshTunnel *t,
- struct MeshPeerPath *p,
+tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p,
unsigned int own_pos)
{
struct GNUNET_PeerIdentity id;
GNUNET_assert (0 != own_pos);
- tree_add_path(t->tree, p, NULL, NULL);
+ tree_add_path (t->tree, p, NULL, NULL);
if (tree_get_me (t->tree) == 0)
tree_set_me (t->tree, p->peers[own_pos]);
if (own_pos < p->length - 1)
{
GNUNET_PEER_resolve (p->peers[own_pos + 1], &id);
- tree_update_first_hops(t->tree,
- tree_get_me (t->tree),
- &id);
+ tree_update_first_hops (t->tree, tree_get_me (t->tree), &id);
}
}
* 0 if the tunnel remained unaffected.
*/
static GNUNET_PEER_Id
-tunnel_notify_connection_broken (struct MeshTunnel *t,
- GNUNET_PEER_Id p1,
+tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1,
GNUNET_PEER_Id p2)
{
GNUNET_PEER_Id pid;
- pid = tree_notify_connection_broken (t->tree,
- p1,
- p2,
- ¬ify_peer_disconnected,
- t);
+ pid =
+ tree_notify_connection_broken (t->tree, p1, p2, ¬ify_peer_disconnected,
+ t);
if (myid != p1 && myid != p2)
{
return pid;
}
if (pid != myid)
{
- if (tree_get_predecessor(t->tree) != 0)
+ if (tree_get_predecessor (t->tree) != 0)
{
/* We are the peer still connected, notify owner of the disconnection. */
struct GNUNET_MESH_PathBroken msg;
* Send a multicast packet to a neighbor.
*/
static void
-tunnel_send_multicast_iterator (void *cls,
- GNUNET_PEER_Id neighbor_id)
+tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id)
{
struct MeshMulticastData *mdata = cls;
struct MeshDataDescriptor *info;
info->destination = neighbor_id;
GNUNET_PEER_resolve (neighbor_id, &neighbor);
#if MESH_DEBUG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: sending to %s...\n",
- GNUNET_i2s (&neighbor));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending to %s...\n",
+ GNUNET_i2s (&neighbor));
#endif
- info->peer = peer_info_get(&neighbor);
+ info->peer = peer_info_get (&neighbor);
GNUNET_assert (NULL != info->peer);
- i = peer_info_transmit_slot(info->peer);
+ i = peer_info_transmit_slot (info->peer);
info->handler_n = i;
info->peer->infos[i] = info;
info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
info->peer->core_transmit[i] =
- GNUNET_CORE_notify_transmit_ready (core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &neighbor,
- info->size,
- &send_core_data_multicast, info);
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &neighbor, info->size,
+ &send_core_data_multicast, info);
}
/**
if (NULL != t->client)
{
mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier));
- *(mdata->task) = GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT,
- &client_allow_send,
- t->client->handle);
+ *(mdata->task) =
+ GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, &client_allow_send,
+ t->client->handle);
}
tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata);
{
struct GNUNET_PeerIdentity id;
- GNUNET_PEER_resolve(t->id.oid, &id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: destroying tunnel %s [%x]\n",
- GNUNET_i2s (&id),
- t->id.tid);
+ GNUNET_PEER_resolve (t->id.oid, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: destroying tunnel %s [%x]\n",
+ GNUNET_i2s (&id), t->id.tid);
if (NULL != c)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id);
}
{
GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t));
+ GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash,
+ t));
}
if (NULL != t->peers)
{
- GNUNET_CONTAINER_multihashmap_iterate(t->peers,
- &peer_info_delete_tunnel, t);
+ GNUNET_CONTAINER_multihashmap_iterate (t->peers, &peer_info_delete_tunnel,
+ t);
GNUNET_CONTAINER_multihashmap_destroy (t->peers);
}
q = t->queue_head;
q = qn;
/* TODO cancel core transmit ready in case it was active */
}
- tree_destroy(t->tree);
+ tree_destroy (t->tree);
if (NULL != t->dht_get_type)
- GNUNET_DHT_get_stop(t->dht_get_type);
+ GNUNET_DHT_get_stop (t->dht_get_type);
if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
- GNUNET_SCHEDULER_cancel(t->timeout_task);
+ GNUNET_SCHEDULER_cancel (t->timeout_task);
if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task)
- GNUNET_SCHEDULER_cancel(t->path_refresh_task);
+ GNUNET_SCHEDULER_cancel (t->path_refresh_task);
GNUNET_free (t);
return r;
}
* @param p Peer which should be removed.
*/
static void
-tunnel_delete_peer (struct MeshTunnel *t,
- GNUNET_PEER_Id peer)
+tunnel_delete_peer (struct MeshTunnel *t, GNUNET_PEER_Id peer)
{
if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL))
tunnel_destroy (t);
/**
* tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a
* client when the client disconnects.
- *
+ *
* @param cls closure (client that is disconnecting)
* @param key the hash of the local tunnel id (used to access the hashmap)
* @param value the value stored at the key (tunnel to destroy)
- *
+ *
* @return GNUNET_OK on success
*/
static int
{
if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
GNUNET_SCHEDULER_cancel (t->timeout_task);
- t->timeout_task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply(REFRESH_PATH_TIME, 4),
- &tunnel_timeout,
- t);
+ t->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (REFRESH_PATH_TIME, 4), &tunnel_timeout, t);
}
size_t size_needed;
int i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: CREATE PATH sending...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATE PATH sending...\n");
size_needed =
sizeof (struct GNUNET_MESH_ManipulatePath) +
p->length * sizeof (struct GNUNET_PeerIdentity);
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n",
- size, size_needed);
- info->peer->core_transmit[info->pos] =
- GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- path_get_first_hop (t->tree, peer->id),
- size_needed,
- &send_core_create_path,
- info);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", size,
+ size_needed);
+ info->peer->core_transmit[info->pos] =
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ path_get_first_hop (t->tree,
+ peer->id),
+ size_needed, &send_core_create_path,
+ info);
return 0;
}
info->peer->core_transmit[info->pos] = NULL;
GNUNET_PEER_resolve (peer->id, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: setting core_transmit %s [%u] to NULL\n",
- GNUNET_i2s (&id),
- info->pos);
+ GNUNET_i2s (&id), info->pos);
}
#endif
msg = (struct GNUNET_MESH_ManipulatePath *) buf;
GNUNET_free (info);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: CREATE PATH (%u bytes long) sent!\n",
- size_needed);
+ "MESH: CREATE PATH (%u bytes long) sent!\n", size_needed);
return size_needed;
}
* @param cls closure (data itself)
* @param size number of bytes available in buf
* @param buf where the callee should write the message
- *
+ *
* @return number of bytes written to buf
*/
static size_t
struct GNUNET_PeerIdentity id;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Multicast: retransmitting... (%u/%u)\n",
- size, total_size);
- GNUNET_PEER_resolve(info->peer->id, &id);
+ "MESH: Multicast: retransmitting... (%u/%u)\n", size,
+ total_size);
+ GNUNET_PEER_resolve (info->peer->id, &id);
info->peer->core_transmit[info->handler_n] =
- GNUNET_CORE_notify_transmit_ready (core_handle,
- 0,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &id,
- total_size,
- &send_core_data_multicast,
- info);
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL, &id,
+ total_size,
+ &send_core_data_multicast, info);
return 0;
}
info->peer->core_transmit[info->handler_n] = NULL;
mc = (struct GNUNET_MESH_Multicast *) mh;
mh = (struct GNUNET_MessageHeader *) &mc[1];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: multicast, payload type %u\n",
- ntohs (mh->type));
+ "MESH: multicast, payload type %u\n", ntohs (mh->type));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: multicast, payload size %u\n",
- ntohs (mh->size));
+ "MESH: multicast, payload size %u\n", ntohs (mh->size));
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: type %u\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type %u\n",
ntohs (mh->type));
}
}
* @param peer peer identity this notification is about
* @param atsi performance data
* @param atsi_count number of records in 'atsi'
- *
+ *
* @return GNUNET_OK to keep the connection open,
* GNUNET_SYSERR to close it (signal serious error)
*/
handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
unsigned int own_pos;
uint16_t size;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: Received a path create msg [%s]\n",
- GNUNET_i2s(&my_full_id));
+ GNUNET_i2s (&my_full_id));
size = ntohs (message->size);
if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
{
GNUNET_break_op (0);
return GNUNET_OK;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: path has %u hops.\n",
- size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size);
msg = (struct GNUNET_MESH_ManipulatePath *) message;
tid = ntohl (msg->tid);
pi = (struct GNUNET_PeerIdentity *) &msg[1];
t = tunnel_get (pi, tid);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: path is for tunnel %s [%X].\n",
- GNUNET_i2s(pi),
- tid);
+ "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi), tid);
if (NULL == t)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n");
next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
t->local_tid = next_local_tid++;
next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
- t->tree = tree_new(t->id.oid);
+ t->tree = tree_new (t->id.oid);
GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (
- tunnels,
- &hash,
- t,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+ GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
{
tunnel_destroy (t);
GNUNET_break (0);
tunnel_reset_timeout (t);
GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (
- incoming_tunnels,
- &hash,
- t,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+ GNUNET_CONTAINER_multihashmap_put (incoming_tunnels, &hash, t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
{
tunnel_destroy (t);
GNUNET_break (0);
own_pos = 0;
for (i = 0; i < size; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: ... adding %s\n",
- GNUNET_i2s(&pi[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n",
+ GNUNET_i2s (&pi[i]));
path->peers[i] = GNUNET_PEER_intern (&pi[i]);
if (path->peers[i] == myid)
own_pos = i;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Own position: %u\n", own_pos);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos);
if (own_pos == 0)
{
/* cannot be self, must be 'not found' */
struct MeshDataDescriptor *info;
unsigned int j;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: It's for us!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n");
peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
if (NULL == t->peers)
- t->peers = GNUNET_CONTAINER_multihashmap_create(4);
- GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
- t->peers,
- &my_full_id.hashPubKey,
- peer_info_get(&my_full_id),
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ t->peers = GNUNET_CONTAINER_multihashmap_create (4);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (t->peers,
+ &my_full_id.hashPubKey,
+ peer_info_get
+ (&my_full_id),
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
/* FIXME use send_message */
info = GNUNET_malloc (sizeof (struct MeshDataDescriptor));
info->origin = &t->id;
info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
GNUNET_assert (NULL != info->peer);
- j = peer_info_transmit_slot(info->peer);
+ j = peer_info_transmit_slot (info->peer);
info->handler_n = j;
info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK;
info->peer->infos[j] = info;
GNUNET_TIME_UNIT_FOREVER_REL, peer,
sizeof (struct GNUNET_MESH_PathACK),
&send_core_path_ack, info);
- cmsg.header.size = htons(sizeof(cmsg));
- cmsg.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
- GNUNET_PEER_resolve(t->id.oid, &cmsg.peer);
- cmsg.tunnel_id = htonl(t->local_tid);
- GNUNET_SERVER_notification_context_broadcast(nc, &cmsg.header, GNUNET_NO);
+ cmsg.header.size = htons (sizeof (cmsg));
+ cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
+ GNUNET_PEER_resolve (t->id.oid, &cmsg.peer);
+ cmsg.tunnel_id = htonl (t->local_tid);
+ GNUNET_SERVER_notification_context_broadcast (nc, &cmsg.header, GNUNET_NO);
}
else
{
struct MeshPeerPath *path2;
/* It's for somebody else! Retransmit. */
- path2 = path_duplicate(path);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Retransmitting.\n");
- peer_info_add_path(dest_peer_info, path2, GNUNET_NO);
- path2 = path_duplicate(path);
- peer_info_add_path_to_origin(orig_peer_info, path2, GNUNET_NO);
- send_create_path(dest_peer_info, path, t);
+ path2 = path_duplicate (path);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting.\n");
+ peer_info_add_path (dest_peer_info, path2, GNUNET_NO);
+ path2 = path_duplicate (path);
+ peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO);
+ send_create_path (dest_peer_info, path, t);
}
return GNUNET_OK;
}
handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_MESH_ManipulatePath *msg;
struct GNUNET_PeerIdentity *pi;
size_t size;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Received a PATH DESTROY msg from %s\n",
- GNUNET_i2s(peer));
+ "MESH: Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer));
size = ntohs (message->size);
if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
{
GNUNET_break_op (0);
return GNUNET_OK;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: path has %u hops.\n",
- size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size);
msg = (struct GNUNET_MESH_ManipulatePath *) message;
pi = (struct GNUNET_PeerIdentity *) &msg[1];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: path is for tunnel %s [%X].\n",
- GNUNET_i2s(pi),
+ "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi),
msg->tid);
t = tunnel_get (pi, ntohl (msg->tid));
if (NULL == t)
own_pos = 0;
for (i = 0; i < size; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: ... adding %s\n",
- GNUNET_i2s(&pi[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n",
+ GNUNET_i2s (&pi[i]));
path->peers[i] = GNUNET_PEER_intern (&pi[i]);
if (path->peers[i] == myid)
own_pos = i;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Own position: %u\n", own_pos);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos);
if (own_pos < path->length - 1)
send_message (message, &pi[own_pos + 1]);
tunnel_delete_peer (t, path->peers[path->length - 1]);
*/
static int
handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct GNUNET_MESH_PathBroken *msg;
struct MeshTunnel *t;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Received a PATH BROKEN msg from %s\n",
- GNUNET_i2s(peer));
+ "MESH: Received a PATH BROKEN msg from %s\n", GNUNET_i2s (peer));
msg = (struct GNUNET_MESH_PathBroken *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: regarding %s\n",
- GNUNET_i2s(&msg->peer1));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: regarding %s\n",
- GNUNET_i2s(&msg->peer2));
- t = tunnel_get(&msg->oid, ntohl (msg->tid));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n",
+ GNUNET_i2s (&msg->peer1));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n",
+ GNUNET_i2s (&msg->peer2));
+ t = tunnel_get (&msg->oid, ntohl (msg->tid));
if (NULL == t)
{
GNUNET_break_op (0);
return GNUNET_OK;
}
- tunnel_notify_connection_broken(t,
- GNUNET_PEER_search(&msg->peer1),
- GNUNET_PEER_search(&msg->peer2));
+ tunnel_notify_connection_broken (t, GNUNET_PEER_search (&msg->peer1),
+ GNUNET_PEER_search (&msg->peer2));
return GNUNET_OK;
}
handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_MESH_TunnelDestroy *msg;
struct MeshTunnel *t;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Got a TUNNEL DESTROY packet from %s\n",
- GNUNET_i2s (peer));
+ "MESH: Got a TUNNEL DESTROY packet from %s\n", GNUNET_i2s (peer));
msg = (struct GNUNET_MESH_TunnelDestroy *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: for tunnel %s [%u]\n",
- GNUNET_i2s (&msg->oid),
- ntohl (msg->tid));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for tunnel %s [%u]\n",
+ GNUNET_i2s (&msg->oid), ntohl (msg->tid));
t = tunnel_get (&msg->oid, ntohl (msg->tid));
if (NULL == t)
{
handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_MESH_Unicast *msg;
struct MeshTunnel *t;
GNUNET_PEER_Id pid;
size_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: got a unicast packet from %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a unicast packet from %s\n",
GNUNET_i2s (peer));
size = ntohs (message->size);
if (size <
return GNUNET_OK;
}
msg = (struct GNUNET_MESH_Unicast *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: of type %u\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n",
ntohs (msg[1].header.type));
t = tunnel_get (&msg->oid, ntohl (msg->tid));
if (NULL == t)
return GNUNET_OK;
}
tunnel_reset_timeout (t);
- pid = GNUNET_PEER_search(&msg->destination);
+ pid = GNUNET_PEER_search (&msg->destination);
if (pid == myid)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: not for us, retransmitting...\n");
- send_message (message, path_get_first_hop(t->tree, pid));
+ send_message (message, path_get_first_hop (t->tree, pid));
return GNUNET_OK;
}
handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_MESH_Multicast *msg;
struct MeshTunnel *t;
size_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: got a multicast packet from %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a multicast packet from %s\n",
GNUNET_i2s (peer));
size = ntohs (message->size);
if (sizeof (struct GNUNET_MESH_Multicast) +
{
send_subscribed_clients (message, &msg[1].header);
}
- tunnel_send_multicast(t, message);
+ tunnel_send_multicast (t, message);
return GNUNET_OK;
}
handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_MESH_ToOrigin *msg;
struct GNUNET_PeerIdentity id;
struct MeshTunnel *t;
size_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: got a ToOrigin packet from %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a ToOrigin packet from %s\n",
GNUNET_i2s (peer));
size = ntohs (message->size);
if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */
return GNUNET_OK;
}
msg = (struct GNUNET_MESH_ToOrigin *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: of type %u\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n",
ntohs (msg[1].header.type));
t = tunnel_get (&msg->oid, ntohl (msg->tid));
if (NULL == t->client)
{
/* got data packet for ownerless tunnel */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: no clients!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: no clients!\n");
GNUNET_break_op (0);
return GNUNET_OK;
}
memcpy (cbuf, message, size);
copy = (struct GNUNET_MESH_ToOrigin *) cbuf;
copy->tid = htonl (t->local_tid);
- GNUNET_SERVER_notification_context_unicast (nc,
- t->client->handle,
- ©->header,
- GNUNET_YES);
+ GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
+ ©->header, GNUNET_YES);
return GNUNET_OK;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_break (0);
return GNUNET_OK;
}
- GNUNET_PEER_resolve (tree_get_predecessor(t->tree), &id);
+ GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
send_message (message, &id);
return GNUNET_OK;
handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_MESH_PathACK *msg;
struct GNUNET_PeerIdentity id;
struct MeshPeerInfo *peer_info;
struct MeshTunnel *t;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Received a path ACK msg [%s]\n",
- GNUNET_i2s(&my_full_id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a path ACK msg [%s]\n",
+ GNUNET_i2s (&my_full_id));
msg = (struct GNUNET_MESH_PathACK *) message;
t = tunnel_get (&msg->oid, msg->tid);
if (NULL == t)
t->dht_get_type = NULL;
}
peer_info = peer_info_get (&msg->peer_id);
- tree_set_status(t->tree, peer_info->id, MESH_PEER_READY);
- send_client_peer_connected(t, peer_info->id);
+ tree_set_status (t->tree, peer_info->id, MESH_PEER_READY);
+ send_client_peer_connected (t, peer_info->id);
return GNUNET_OK;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: not for us, retransmitting...\n");
- GNUNET_PEER_resolve(tree_get_predecessor(t->tree), &id);
+ GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
peer_info = peer_info_get (&msg->oid);
if (NULL == peer_info)
{
{&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
{&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0},
{&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN,
- sizeof (struct GNUNET_MESH_PathBroken)},
+ sizeof (struct GNUNET_MESH_PathBroken)},
{&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0},
{&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
{&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0},
{&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
{&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK,
- sizeof (struct GNUNET_MESH_PathACK)},
+ sizeof (struct GNUNET_MESH_PathACK)},
{NULL, 0, 0}
};
/**
* deregister_app: iterator for removing each application registered by a client
- *
+ *
* @param cls closure
* @param key the hash of the application id (used to access the hashmap)
* @param value the value stored at the key (client)
- *
+ *
* @return GNUNET_OK on success
*/
static int
deregister_app (void *cls, const GNUNET_HashCode * key, void *value)
{
- GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (applications, key, value));
+ GNUNET_break (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (applications, key,
+ value));
return GNUNET_OK;
}
struct MeshTunnel *t = cls;
struct GNUNET_MessageHeader *payload;
struct GNUNET_MESH_Multicast *msg;
- size_t size = sizeof(struct GNUNET_MESH_Multicast) +
- sizeof(struct GNUNET_MessageHeader);
+ size_t size =
+ sizeof (struct GNUNET_MESH_Multicast) +
+ sizeof (struct GNUNET_MessageHeader);
char cbuf[size];
if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: sending keepalive for tunnel %d\n",
- t->id.tid);
+ "MESH: sending keepalive for tunnel %d\n", t->id.tid);
msg = (struct GNUNET_MESH_Multicast *) cbuf;
msg->header.size = htons (size);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
msg->oid = my_full_id;
- msg->tid = htonl(t->id.tid);
+ msg->tid = htonl (t->id.tid);
payload = (struct GNUNET_MessageHeader *) &msg[1];
- payload->size = htons (sizeof(struct GNUNET_MessageHeader));
+ payload->size = htons (sizeof (struct GNUNET_MessageHeader));
payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE);
tunnel_send_multicast (t, &msg->header);
const struct GNUNET_PeerIdentity *get_path,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
struct MeshPathInfo *path_info = cls;
struct MeshPeerPath *p;
struct GNUNET_PeerIdentity pi;
int i;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: Got results from DHT!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n");
GNUNET_PEER_resolve (path_info->peer->id, &pi);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: for %s\n",
- GNUNET_i2s(&pi));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi));
// GNUNET_DHT_get_stop(path_info->peer->dhtget);
// path_info->peer->dhtget = NULL;
- p = path_build_from_dht (get_path, get_path_length,
- put_path, put_path_length);
+ p = path_build_from_dht (get_path, get_path_length, put_path,
+ put_path_length);
peer_info_add_path (path_info->peer, p, GNUNET_NO);
for (i = 0; i < path_info->peer->ntunnels; i++)
{
tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer);
- peer_info_connect(path_info->peer, path_info->t);
+ peer_info_connect (path_info->peer, path_info->t);
}
// GNUNET_free (path_info);
dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type, size_t size,
- const void *data)
+ unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
const struct GNUNET_PeerIdentity *pi = data;
struct MeshTunnel *t = cls;
}
GNUNET_assert (NULL != t->client);
peer_info = peer_info_get (pi);
- (void) GNUNET_CONTAINER_multihashmap_put (
- t->peers,
- &pi->hashPubKey,
- peer_info,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
-
- p = path_build_from_dht (get_path, get_path_length,
- put_path, put_path_length);
+ (void) GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey,
+ peer_info,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
+
+ p = path_build_from_dht (get_path, get_path_length, put_path,
+ put_path_length);
peer_info_add_path (peer_info, p, GNUNET_NO);
- tunnel_add_peer(t, peer_info);
+ tunnel_add_peer (t, peer_info);
peer_info_connect (peer_info, t);
}
if (NULL != c->tunnels)
{
GNUNET_CONTAINER_multihashmap_iterate (c->tunnels,
- &tunnel_destroy_iterator,
- c);
+ &tunnel_destroy_iterator, c);
GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
}
#if MESH_DEBUG
c->id = next_client_id++;
#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, c);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id,
+ c);
c->handle = client;
GNUNET_SERVER_client_keep (client);
a = (GNUNET_MESH_ApplicationType *) &cc_msg[1];
t->id.oid = myid;
t->local_tid = ntohl (t_msg->tunnel_id);
#if MESH_DEBUG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: CREATED TUNNEL %s [%x] (%x)\n",
- GNUNET_i2s (&my_full_id),
- t->id.tid,
- t->local_tid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATED TUNNEL %s [%x] (%x)\n",
+ GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
#endif
t->client = c;
t->peers = GNUNET_CONTAINER_multihashmap_create (32);
GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (
- c->tunnels, &hash, t,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ GNUNET_CONTAINER_multihashmap_put (c->tunnels, &hash, t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (
- tunnels, &hash, t,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
t->tree = tree_new (myid);
- tree_set_me(t->tree, myid);
+ tree_set_me (t->tree, myid);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t));
+ GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t));
t->client = NULL;
tunnel_send_destroy (t);
- tunnel_destroy(t);
+ tunnel_destroy (t);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
struct MeshTunnel *t;
MESH_TunnelNumber tid;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n");
/* Sanity check for client registration */
if (NULL == (c = client_get (client)))
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n",
- GNUNET_i2s(&peer_msg->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n",
+ GNUNET_i2s (&peer_msg->peer));
peer_info = peer_info_get (&peer_msg->peer);
- tunnel_add_peer(t, peer_info);
- peer_info_connect(peer_info, t);
+ tunnel_add_peer (t, peer_info);
+ peer_info_connect (peer_info, t);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: for peer %s\n",
- GNUNET_i2s(&peer_msg->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for peer %s\n",
+ GNUNET_i2s (&peer_msg->peer));
/* Is the peer in the tunnel? */
- peer_info = GNUNET_CONTAINER_multihashmap_get(t->peers,
- &peer_msg->peer.hashPubKey);
+ peer_info =
+ GNUNET_CONTAINER_multihashmap_get (t->peers, &peer_msg->peer.hashPubKey);
if (NULL == peer_info)
{
GNUNET_break (0);
&peer_msg->peer.hashPubKey);
send_destroy_path (t, peer_info->id);
- tunnel_delete_peer(t, peer_info->id);
+ tunnel_delete_peer (t, peer_info->id);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n");
- send_client_peer_connected(t, myid);
+ send_client_peer_connected (t, myid);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n",
GNUNET_h2s (&hash));
t->dht_get_type =
- GNUNET_DHT_get_start (dht_handle,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_BLOCK_TYPE_TEST,
- &hash,
- 10U,
+ GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_BLOCK_TYPE_TEST, &hash, 10U,
GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, 0,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, 0,
&dht_get_type_handler, t);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
/* Is it a local tunnel? Then, does client own the tunnel? */
- if (NULL != t->client &&
- NULL != t->client->handle &&
+ if (NULL != t->client && NULL != t->client->handle &&
t->client->handle != client)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_PEER_resolve(t->id.oid, &id);
+ GNUNET_PEER_resolve (t->id.oid, &id);
/* Ok, everything is correct, send the message
* (pretend we got it from a mesh peer)
}
{
- char buf[ntohs(message->size)];
+ char buf[ntohs (message->size)];
struct GNUNET_MESH_Multicast *copy;
- copy = (struct GNUNET_MESH_Multicast *)buf;
- memcpy(buf, message, ntohs(message->size));
+ copy = (struct GNUNET_MESH_Multicast *) buf;
+ memcpy (buf, message, ntohs (message->size));
copy->oid = my_full_id;
- copy->tid = htonl(t->id.tid);
+ copy->tid = htonl (t->id.tid);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: calling generic handler...\n");
- handle_mesh_data_multicast(client, &my_full_id, ©->header, NULL, 0);
+ handle_mesh_data_multicast (client, &my_full_id, ©->header, NULL, 0);
}
/* receive done gets called when last copy is sent to a neighbor */
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n");
core_handle = server;
- if (0 != memcmp(identity, &my_full_id, sizeof(my_full_id)) || NULL == server)
+ if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)) ||
+ NULL == server)
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n"));
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n"));
+ GNUNET_SCHEDULER_shutdown ();
}
return;
}
#if MESH_DEBUG_CONNECTION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n",
- GNUNET_i2s(&my_full_id));
+ GNUNET_i2s (&my_full_id));
#endif
peer_info = peer_info_get (peer);
if (myid == peer_info->id)
#if MESH_DEBUG_CONNECTION
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n",
- GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", GNUNET_i2s (peer));
}
#endif
path = path_new (2);
path->peers[0] = myid;
path->peers[1] = peer_info->id;
- GNUNET_PEER_change_rc(myid, 1);
- GNUNET_PEER_change_rc(peer_info->id, 1);
+ GNUNET_PEER_change_rc (myid, 1);
+ GNUNET_PEER_change_rc (peer_info->id, 1);
peer_info_add_path (peer_info, path, GNUNET_YES);
return;
}
for (i = 0; i < CORE_QUEUE_SIZE; i++)
{
/* TODO: notify that the transmission failed */
- peer_info_cancel_transmission(pi, i);
+ peer_info_cancel_transmission (pi, i);
}
peer_info_remove_path (pi, pi->id, myid);
#if MESH_DEBUG_CONNECTION
shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
{
struct MeshTunnel *t = value;
- tunnel_destroy(t);
+
+ tunnel_destroy (t);
return GNUNET_YES;
}
shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct MeshPeerInfo *p = value;
+
peer_info_destroy (p);
return GNUNET_YES;
}
GNUNET_CORE_disconnect (core_handle);
core_handle = NULL;
}
- GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL);
- GNUNET_CONTAINER_multihashmap_iterate(peers, &shutdown_peer, NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL);
if (dht_handle != NULL)
{
GNUNET_DHT_disconnect (dht_handle);
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
- &keyfile))
+ GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
+ &keyfile))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
nc = GNUNET_SERVER_notification_context_create (server_handle,
LOCAL_QUEUE_SIZE);
GNUNET_SERVER_disconnect_notify (server_handle,
- &handle_local_client_disconnect,
- NULL);
+ &handle_local_client_disconnect, NULL);
clients = NULL;
announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls);
/* Create a peer_info for the local peer */
- peer = peer_info_get(&my_full_id);
+ peer = peer_info_get (&my_full_id);
p = path_new (1);
p->peers[0] = myid;
GNUNET_PEER_change_rc (myid, 1);
- peer_info_add_path(peer, p, GNUNET_YES);
+ peer_info_add_path (peer, p, GNUNET_YES);
/* Scheduled the task to clean up when shutdown is called */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
t = retrieve_tunnel (h, ntohl (ucast->tid));
payload = (struct GNUNET_MessageHeader *) &ucast[1];
peer = &ucast->oid;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: on tunnel %s [%x]\n",
- GNUNET_i2s (peer),
- ntohl (ucast->tid));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: on tunnel %s [%x]\n",
+ GNUNET_i2s (peer), ntohl (ucast->tid));
break;
case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
mcast = (struct GNUNET_MESH_Multicast *) message;
GNUNET_assert (size >= th->size);
mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
- psize =
- th->notify (th->notify_cls, size - sizeof (to), mh);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: to origin, type %u\n",
- ntohs (mh->type));
+ psize = th->notify (th->notify_cls, size - sizeof (to), mh);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: to origin, type %u\n",
+ ntohs (mh->type));
if (psize > 0)
{
psize += sizeof (to);
GNUNET_assert (size >= th->size);
mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)];
- psize =
- th->notify (th->notify_cls, size - sizeof (mc), mh);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: multicast, type %u\n",
+ psize = th->notify (th->notify_cls, size - sizeof (mc), mh);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: multicast, type %u\n",
ntohs (mh->type));
if (psize > 0)
{
GNUNET_assert (size >= th->size);
mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
- psize =
- th->notify (th->notify_cls, size - sizeof (uc), mh);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: unicast, type %u\n",
- ntohs (mh->type));
+ psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: unicast, type %u\n",
+ ntohs (mh->type));
if (psize > 0)
{
psize += sizeof (uc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"mesh: mesh notify transmit ready called\n");
if (NULL != target)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: target %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target %s\n",
GNUNET_i2s (target));
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: target multicast\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target multicast\n");
#endif
GNUNET_assert (NULL != notify);
if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
if (NULL != tunnel->mesh->th)
return th;
tunnel->mesh->th =
- GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client,
- th->size,
+ GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size,
GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES,
- &send_callback,
+ GNUNET_YES, &send_callback,
tunnel->mesh);
return th;
}
* ID of the endpoint
*/
struct GNUNET_PeerIdentity peer1;
-
+
/**
* ID of the endpoint
*/
{
struct MeshPeerPath *p;
- p = GNUNET_malloc (sizeof(struct MeshPeerPath));
+ p = GNUNET_malloc (sizeof (struct MeshPeerPath));
if (length > 0)
{
p->length = length;
- p->peers = GNUNET_malloc (length * sizeof(GNUNET_PEER_Id));
+ p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id));
}
return p;
}
struct MeshPeerPath *aux;
unsigned int i;
- aux = path_new(path->length);
- memcpy (aux->peers, path->peers, path->length * sizeof(GNUNET_PEER_Id));
+ aux = path_new (path->length);
+ memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id));
for (i = 0; i < path->length; i++)
- GNUNET_PEER_change_rc(path->peers[i], 1);
+ GNUNET_PEER_change_rc (path->peers[i], 1);
return aux;
}
{
struct MeshTunnelTreeNode *n;
- n = tree_find_peer(t, peer);
+ n = tree_find_peer (t, peer);
if (NULL != t->me && NULL != n)
{
- tree_node_update_first_hops(t, n, NULL);
+ tree_node_update_first_hops (t, n, NULL);
r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
GNUNET_assert (NULL != r);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Tree structure inconsistent! me: %p, n: %p",
- t->me, n);
+ "Tree structure inconsistent! me: %p, n: %p", t->me, n);
GNUNET_break (0);
}
}
* @return Newly allocated node
*/
static struct MeshTunnelTreeNode *
-tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
+tree_node_new (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
{
struct MeshTunnelTreeNode *node;
- node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
+ node = GNUNET_malloc (sizeof (struct MeshTunnelTreeNode));
node->peer = peer;
- GNUNET_PEER_change_rc(peer, 1);
+ GNUNET_PEER_change_rc (peer, 1);
node->parent = parent;
if (NULL != parent)
- GNUNET_CONTAINER_DLL_insert(parent->children_head,
- parent->children_tail,
- node);
+ GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail,
+ node);
return node;
}
* @return Pointer to the node of the peer. NULL if not found.
*/
static struct MeshTunnelTreeNode *
-tree_node_find_peer (struct MeshTunnelTreeNode *parent,
- GNUNET_PEER_Id peer_id)
+tree_node_find_peer (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer_id)
{
struct MeshTunnelTreeNode *n;
struct MeshTunnelTreeNode *r;
struct MeshTunnelTreeNode *n;
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(parent->peer, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Finding first hop for %s.\n",
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (parent->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Finding first hop for %s.\n",
+ GNUNET_i2s (&id));
#endif
if (NULL == hop)
{
while (aux != tree->me)
{
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(old->peer, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: ... its not %s.\n",
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (old->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: ... its not %s.\n",
+ GNUNET_i2s (&id));
#endif
old = aux;
aux = aux->parent;
- GNUNET_assert(NULL != aux);
+ GNUNET_assert (NULL != aux);
}
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(old->peer, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: It's %s!\n",
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (old->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: It's %s!\n",
+ GNUNET_i2s (&id));
#endif
hop = π
- GNUNET_PEER_resolve(old->peer, hop);
+ GNUNET_PEER_resolve (old->peer, hop);
}
- GNUNET_PEER_resolve(parent->peer, &id);
+ GNUNET_PEER_resolve (parent->peer, &id);
copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
if (NULL == copy)
- copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
+ copy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
*copy = *hop;
- (void) GNUNET_CONTAINER_multihashmap_put(
- tree->first_hops,
- &id.hashPubKey,
- copy,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
+ (void) GNUNET_CONTAINER_multihashmap_put (tree->first_hops, &id.hashPubKey,
+ copy,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
for (n = parent->children_head; NULL != n; n = n->next)
{
static void
-tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level)
+tree_node_debug (struct MeshTunnelTreeNode *n, uint16_t level)
{
struct MeshTunnelTreeNode *c;
struct GNUNET_PeerIdentity id;;
uint16_t i;
for (i = 0; i < level; i++)
- fprintf(stderr, " ");
+ fprintf (stderr, " ");
if (n->status == MESH_PEER_READY)
- fprintf(stderr, "#");
+ fprintf (stderr, "#");
if (n->status == MESH_PEER_SEARCHING)
- fprintf(stderr, "+");
+ fprintf (stderr, "+");
if (n->status == MESH_PEER_RELAY)
- fprintf(stderr, "-");
+ fprintf (stderr, "-");
if (n->status == MESH_PEER_RECONNECTING)
- fprintf(stderr, "*");
+ fprintf (stderr, "*");
- GNUNET_PEER_resolve(n->peer, &id);
- fprintf(stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n);
+ GNUNET_PEER_resolve (n->peer, &id);
+ fprintf (stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n);
if (NULL != n->parent)
{
- GNUNET_PEER_resolve(n->parent->peer, &id);
- fprintf(stderr, "(-> %s [%u])\n", GNUNET_i2s(&id), n->parent->peer);
+ GNUNET_PEER_resolve (n->parent->peer, &id);
+ fprintf (stderr, "(-> %s [%u])\n", GNUNET_i2s (&id), n->parent->peer);
}
else
- fprintf(stderr, "(root)\n");
+ fprintf (stderr, "(root)\n");
for (c = n->children_head; NULL != c; c = c->next)
- tree_node_debug(c, level + 1);
+ tree_node_debug (c, level + 1);
}
{
struct MeshTunnelTreeNode *n;
struct MeshTunnelTreeNode *next;
+
#if MESH_TREE_DEBUG
struct GNUNET_PeerIdentity id;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "tree: Destroying node %u\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying node %u\n",
parent->peer);
GNUNET_PEER_resolve (parent->peer, &id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "tree: (%s)\n",
- GNUNET_i2s (&id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: (%s)\n", GNUNET_i2s (&id));
#endif
n = parent->children_head;
while (NULL != n)
{
next = n->next;
- tree_node_destroy(n);
+ tree_node_destroy (n);
n = next;
}
- GNUNET_PEER_change_rc(parent->peer, -1);
+ GNUNET_PEER_change_rc (parent->peer, -1);
if (NULL != parent->parent)
- GNUNET_CONTAINER_DLL_remove(parent->parent->children_head,
- parent->parent->children_tail,
- parent);
- GNUNET_free(parent);
+ GNUNET_CONTAINER_DLL_remove (parent->parent->children_head,
+ parent->parent->children_tail, parent);
+ GNUNET_free (parent);
}
{
struct MeshTunnelTree *tree;
- tree = GNUNET_malloc(sizeof (struct MeshTunnelTree));
- tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
- tree->root = tree_node_new(NULL, peer);
+ tree = GNUNET_malloc (sizeof (struct MeshTunnelTree));
+ tree->first_hops = GNUNET_CONTAINER_multihashmap_create (32);
+ tree->root = tree_node_new (NULL, peer);
tree->root->status = MESH_PEER_ROOT;
return tree;
void
tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer)
{
- tree->me = tree_find_peer(tree, peer);
+ tree->me = tree_find_peer (tree, peer);
}
* @param peer A short peer id of local peer.
*/
void
-tree_set_status (struct MeshTunnelTree *tree,
- GNUNET_PEER_Id peer,
+tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer,
enum MeshPeerState status)
{
struct MeshTunnelTreeNode *n;
- n = tree_find_peer(tree, peer);
+ n = tree_find_peer (tree, peer);
if (NULL == n)
return;
n->status = status;
{
struct MeshTunnelTreeNode *n;
- n = tree_find_peer(tree, peer);
+ n = tree_find_peer (tree, peer);
if (NULL == n)
return MESH_PEER_INVALID;
return n->status;
struct MeshTunnelTreeNode *
tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id)
{
- return tree_node_find_peer(tree->root, peer_id);
+ return tree_node_find_peer (tree->root, peer_id);
}
static void
tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
struct MeshTunnelTreeNode *parent,
- MeshTreeCallback cb,
- void *cbcls)
+ MeshTreeCallback cb, void *cbcls)
{
struct GNUNET_PeerIdentity *pi;
struct GNUNET_PeerIdentity id;
}
/* Remove and free info about first hop */
- GNUNET_PEER_resolve(parent->peer, &id);
- pi = GNUNET_CONTAINER_multihashmap_get(tree->first_hops, &id.hashPubKey);
- GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey);
+ GNUNET_PEER_resolve (parent->peer, &id);
+ pi = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
+ GNUNET_CONTAINER_multihashmap_remove_all (tree->first_hops, &id.hashPubKey);
if (NULL != pi)
- GNUNET_free(pi);
+ GNUNET_free (pi);
}
/**
* Iterate over all children of the local node.
- *
+ *
* @param tree Tree to use. Must have "me" set.
* @param cb Callback to call over each child.
* @param cls Closure.
*/
void
-tree_iterate_children (struct MeshTunnelTree *tree,
- MeshTreeCallback cb,
+tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
void *cls)
{
struct MeshTunnelTreeNode *n;
* If not known, NULL to find out and pass on children.
*/
void
-tree_update_first_hops (struct MeshTunnelTree *tree,
- GNUNET_PEER_Id parent_id,
+tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id,
struct GNUNET_PeerIdentity *hop)
{
- tree_node_update_first_hops(tree,
- tree_find_peer(tree, parent_id),
- hop);
+ tree_node_update_first_hops (tree, tree_find_peer (tree, parent_id), hop);
}
* NULL when not found
*/
struct MeshTunnelTreeNode *
-tree_del_path (struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer_id,
- MeshTreeCallback cb,
- void *cbcls)
+tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
+ MeshTreeCallback cb, void *cbcls)
{
struct MeshTunnelTreeNode *parent;
struct MeshTunnelTreeNode *node;
#if MESH_TREE_DEBUG
struct GNUNET_PeerIdentity id;
- GNUNET_PEER_resolve(peer_id, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Deleting path to %s.\n",
- GNUNET_i2s (&id));
+
+ GNUNET_PEER_resolve (peer_id, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %s.\n",
+ GNUNET_i2s (&id));
#endif
if (peer_id == t->root->peer)
return NULL;
if (n->peer == peer_id)
{
/* Was already pathless, waiting for reconnection */
- GNUNET_CONTAINER_DLL_remove (t->disconnected_head,
- t->disconnected_tail,
+ GNUNET_CONTAINER_DLL_remove (t->disconnected_head, t->disconnected_tail,
n);
return n;
}
node = n;
parent = n->parent;
- GNUNET_CONTAINER_DLL_remove(parent->children_head, parent->children_tail, n);
+ GNUNET_CONTAINER_DLL_remove (parent->children_head, parent->children_tail, n);
n->parent = NULL;
while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head)
{
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(parent->peer, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Deleting node %s.\n",
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (parent->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting node %s.\n",
+ GNUNET_i2s (&id));
#endif
n = parent->parent;
- tree_node_destroy(parent);
+ tree_node_destroy (parent);
parent = n;
}
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(parent->peer, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Not deleted peer %s.\n",
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (parent->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Not deleted peer %s.\n",
+ GNUNET_i2s (&id));
#endif
tree_mark_peers_disconnected (t, node, cb, cbcls);
* Path must be destroyed afterwards.
*/
struct MeshPeerPath *
-tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
+tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
{
struct MeshTunnelTreeNode *n;
struct MeshPeerPath *p;
GNUNET_PEER_Id myid = t->me->peer;
- n = tree_find_peer(t, peer);
+ n = tree_find_peer (t, peer);
if (NULL == n)
return NULL;
- p = path_new(0);
+ p = path_new (0);
/* Building the path (inverted!) */
while (n->peer != myid)
{
- GNUNET_array_append(p->peers, p->length, n->peer);
- GNUNET_PEER_change_rc(n->peer, 1);
+ GNUNET_array_append (p->peers, p->length, n->peer);
+ GNUNET_PEER_change_rc (n->peer, 1);
n = n->parent;
if (NULL == n)
return NULL;
}
- GNUNET_array_append(p->peers, p->length, myid);
- GNUNET_PEER_change_rc(myid, 1);
+ GNUNET_array_append (p->peers, p->length, myid);
+ GNUNET_PEER_change_rc (myid, 1);
- path_invert(p);
+ path_invert (p);
return p;
}
* - do not disconnect peers until new path is created & connected
*/
int
-tree_add_path (struct MeshTunnelTree *t,
- const struct MeshPeerPath *p,
- MeshTreeCallback cb,
- void *cbcls)
+tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
+ MeshTreeCallback cb, void *cbcls)
{
struct MeshTunnelTreeNode *parent;
struct MeshTunnelTreeNode *oldnode;
unsigned int i;
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(p->peers[p->length - 1], &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Adding path [%u] towards peer %s.\n",
- p->length,
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (p->peers[p->length - 1], &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tree: Adding path [%u] towards peer %s.\n", p->length,
+ GNUNET_i2s (&id));
#endif
if (NULL != t->me)
myid = t->me->peer;
else
myid = 0;
- GNUNET_assert(0 != p->length);
+ GNUNET_assert (0 != p->length);
parent = n = t->root;
if (n->peer != p->peers[0])
{
for (i = 1; i < p->length; i++)
{
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(p->peers[i], &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Looking for peer %s.\n",
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (p->peers[i], &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Looking for peer %s.\n",
+ GNUNET_i2s (&id));
#endif
parent = n;
if (p->peers[i] == myid)
if (c->peer == p->peers[i])
{
#if MESH_TREE_DEBUG
- GNUNET_PEER_resolve(parent->peer, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Found in children of %s.\n",
- GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (parent->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tree: Found in children of %s.\n", GNUNET_i2s (&id));
#endif
n = c;
break;
break;
}
#if MESH_TREE_DEBUG
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: All childen visited.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: All childen visited.\n");
#endif
/* Add the rest of the path as a branch from parent. */
while (i < p->length)
{
#if MESH_TREE_DEBUG
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Adding peer %u to %u.\n",
- p->peers[i], parent->peer);
- GNUNET_PEER_resolve(p->peers[i], &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Adding peer %s.\n",
- GNUNET_i2s (&id));
- GNUNET_PEER_resolve(parent->peer, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: to %s.\n",
- GNUNET_i2s (&id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %u to %u.\n",
+ p->peers[i], parent->peer);
+ GNUNET_PEER_resolve (p->peers[i], &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %s.\n",
+ GNUNET_i2s (&id));
+ GNUNET_PEER_resolve (parent->peer, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: to %s.\n",
+ GNUNET_i2s (&id));
#endif
if (i == p->length - 1 && NULL != oldnode)
{
#if MESH_TREE_DEBUG
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tree: Putting old node into place.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tree: Putting old node into place.\n");
#endif
oldnode->parent = parent;
- GNUNET_CONTAINER_DLL_insert(parent->children_head,
- parent->children_tail,
- oldnode);
+ GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail,
+ oldnode);
tree_node_update_first_hops (t, oldnode, NULL);
n = oldnode;
}
else
{
#if MESH_TREE_DEBUG
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n");
#endif
- n = tree_node_new(parent, p->peers[i]);
+ n = tree_node_new (parent, p->peers[i]);
n->status = MESH_PEER_RELAY;
if (n->peer == myid)
t->me = n;
{
#if MESH_TREE_DEBUG
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: finding first hop (own pos %d/%u)\n",
- me, p->length - 1);
+ "MESH: finding first hop (own pos %d/%u)\n", me,
+ p->length - 1);
#endif
GNUNET_PEER_resolve (p->peers[me + 1], &id);
- tree_update_first_hops(t,
- p->peers[p->length - 1],
- &id);
+ tree_update_first_hops (t, p->peers[p->length - 1], &id);
}
#if MESH_TREE_DEBUG
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n");
#endif
return GNUNET_OK;
}
* @return Short ID of the first disconnected peer in the tree.
*/
GNUNET_PEER_Id
-tree_notify_connection_broken (struct MeshTunnelTree *t,
- GNUNET_PEER_Id p1,
- GNUNET_PEER_Id p2,
- MeshTreeCallback cb,
+tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1,
+ GNUNET_PEER_Id p2, MeshTreeCallback cb,
void *cbcls)
{
struct MeshTunnelTreeNode *n;
struct MeshTunnelTreeNode *c;
- n = tree_find_peer(t, p1);
+ n = tree_find_peer (t, p1);
if (NULL == n)
return 0;
if (NULL != n->parent && n->parent->peer == p2)
{
- tree_mark_peers_disconnected(t, n, cb, cbcls);
- GNUNET_CONTAINER_DLL_remove(n->parent->children_head,
- n->parent->children_tail,
- n);
- GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
- t->disconnected_tail,
- n);
+ tree_mark_peers_disconnected (t, n, cb, cbcls);
+ GNUNET_CONTAINER_DLL_remove (n->parent->children_head,
+ n->parent->children_tail, n);
+ GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail, n);
return p1;
}
for (c = n->children_head; NULL != c; c = c->next)
{
if (c->peer == p2)
{
- tree_mark_peers_disconnected(t, c, cb, cbcls);
- GNUNET_CONTAINER_DLL_remove(n->children_head,
- n->children_tail,
- c);
- GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
- t->disconnected_tail,
- c);
+ tree_mark_peers_disconnected (t, c, cb, cbcls);
+ GNUNET_CONTAINER_DLL_remove (n->children_head, n->children_tail, c);
+ GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail,
+ c);
return p2;
}
}
* @return GNUNET_OK or GNUNET_SYSERR
*/
int
-tree_del_peer (struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer,
- MeshTreeCallback cb,
- void *cbcls)
+tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
+ MeshTreeCallback cb, void *cbcls)
{
struct MeshTunnelTreeNode *n;
- n = tree_del_path(t, peer, cb, cbcls);
+ n = tree_del_path (t, peer, cb, cbcls);
if (NULL == n)
{
GNUNET_break (0);
return GNUNET_YES;
}
GNUNET_break_op (NULL == n->children_head);
- tree_node_destroy(n);
+ tree_node_destroy (n);
if (NULL == t->root->children_head && t->me != t->root)
{
tree_node_destroy (t->root);
* @param t The tree
*/
void
-tree_debug(struct MeshTunnelTree *t)
+tree_debug (struct MeshTunnelTree *t)
{
- tree_node_debug(t->root, 0);
+ tree_node_debug (t->root, 0);
}
static int
iterate_free (void *cls, const GNUNET_HashCode * key, void *value)
{
- GNUNET_free(value);
+ GNUNET_free (value);
return GNUNET_YES;
}
/**
* Destroy the whole tree and free all used memory and Peer_Ids
- *
+ *
* @param t Tree to be destroyed
*/
void
#if MESH_TREE_DEBUG
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n");
#endif
- tree_node_destroy(t->root);
- GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL);
- GNUNET_CONTAINER_multihashmap_destroy(t->first_hops);
- GNUNET_free(t);
+ tree_node_destroy (t->root);
+ GNUNET_CONTAINER_multihashmap_iterate (t->first_hops, &iterate_free, NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (t->first_hops);
+ GNUNET_free (t);
}
* NULL on error
*/
struct GNUNET_PeerIdentity *
-path_get_first_hop (struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer);
+path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
/**
* in the path
*/
unsigned int
-path_get_cost (struct MeshTunnelTree *t,
- struct MeshPeerPath *path);
+path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path);
/**
* @param cls Closure.
* @param peer_id short ID of peer that is no longer reachable.
*/
-typedef void (*MeshTreeCallback) (void *cls,
- GNUNET_PEER_Id peer_id);
+typedef void (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id);
/**
* @param peer A short peer id of local peer.
*/
void
-tree_set_status (struct MeshTunnelTree *tree,
- GNUNET_PEER_Id peer,
+tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer,
enum MeshPeerState status);
/**
* Iterate over all children of the local node.
- *
+ *
* @param tree Tree to use. Must have "me" set.
* @param cb Callback to call over each child.
* @param cls Closure.
*/
void
-tree_iterate_children (struct MeshTunnelTree *tree,
- MeshTreeCallback cb,
+tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
void *cls);
* If not known, NULL to find out and pass on children.
*/
void
-tree_update_first_hops (struct MeshTunnelTree *tree,
- GNUNET_PEER_Id parent_id,
+tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id,
struct GNUNET_PeerIdentity *hop);
/**
* NULL when not found
*/
struct MeshTunnelTreeNode *
-tree_del_path (struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer,
- MeshTreeCallback cb,
- void *cbcls);
+tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
+ MeshTreeCallback cb, void *cbcls);
/**
* Path must be destroyed afterwards.
*/
struct MeshPeerPath *
-tree_get_path_to_peer(struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer);
+tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
/**
* GNUNET_SYSERR in case of error.
*/
int
-tree_add_path (struct MeshTunnelTree *t,
- const struct MeshPeerPath *p,
- MeshTreeCallback cb,
- void *cbcls);
+tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
+ MeshTreeCallback cb, void *cbcls);
/**
* @return Short ID of the first disconnected peer in the tree.
*/
GNUNET_PEER_Id
-tree_notify_connection_broken (struct MeshTunnelTree *t,
- GNUNET_PEER_Id p1,
- GNUNET_PEER_Id p2,
- MeshTreeCallback cb,
+tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1,
+ GNUNET_PEER_Id p2, MeshTreeCallback cb,
void *cbcls);
* @return GNUNET_YES if the tunnel still has nodes
*/
int
-tree_del_peer (struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer,
- MeshTreeCallback cb,
- void *cbcls);
+tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
+ MeshTreeCallback cb, void *cbcls);
/**
* Print the tree on stderr
* @param t The tree
*/
void
-tree_debug(struct MeshTunnelTree *t);
+tree_debug (struct MeshTunnelTree *t);
/**
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown, NULL);
+ (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown,
+ NULL);
}
&peer_disconnected, (void *) &two);
GNUNET_MESH_peer_request_connect_by_type (t, 1);
test_task =
- GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
- &do_connect_peer_1,
- cfg);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ &do_connect_peer_1, cfg);
}
if (emsg != NULL)
{
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Shutdown of peers failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Shutdown of peers failed!\n");
#endif
ok--;
}
else
{
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: All peers successfully shut down!\n");
#endif
}
}
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Ending test.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Ending test.\n");
#endif
if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: disconnecting mesh service of peers\n");
disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_MESH_disconnect(h1);
- GNUNET_MESH_disconnect(h2);
+ GNUNET_MESH_disconnect (h1);
+ GNUNET_MESH_disconnect (h2);
if (test == MULTICAST)
- GNUNET_MESH_disconnect(h3);
+ GNUNET_MESH_disconnect (h3);
if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
{
GNUNET_SCHEDULER_cancel (shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
}
{
struct GNUNET_MessageHeader *msg = buf;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: tmt_rdy called\n");
- if (size < sizeof(struct GNUNET_MessageHeader) || NULL == buf)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: tmt_rdy called\n");
+ if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf)
return 0;
- msg->size = htons (sizeof(struct GNUNET_MessageHeader));
+ msg->size = htons (sizeof (struct GNUNET_MessageHeader));
msg->type = htons ((long) cls);
- return sizeof(struct GNUNET_MessageHeader);
+ return sizeof (struct GNUNET_MessageHeader);
}
* GNUNET_SYSERR to close it (signal serious error)
*/
int
-data_callback (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- void **tunnel_ctx,
- const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi)
+data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi)
{
long client = (long) cls;
switch (client)
{
- case 1L:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: Origin client got a response!\n");
- ok++;
- peers_responded++;
- if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
- {
- GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
- &disconnect_mesh_peers,
- NULL);
- }
- if (test == MULTICAST && peers_responded < 2)
- return GNUNET_OK;
- GNUNET_MESH_tunnel_destroy (tunnel);
- break;
- case 2L:
- case 3L:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: Destination client %u got a message.\n",
- client);
- ok++;
- GNUNET_MESH_notify_transmit_ready(tunnel,
- GNUNET_NO,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- sender,
- sizeof(struct GNUNET_MessageHeader),
- &tmt_rdy,
- (void *) 1L);
- if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
- {
- GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
- &disconnect_mesh_peers,
- NULL);
- }
- break;
- default:
- break;
+ case 1L:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Origin client got a response!\n");
+ ok++;
+ peers_responded++;
+ if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
+ NULL);
+ }
+ if (test == MULTICAST && peers_responded < 2)
+ return GNUNET_OK;
+ GNUNET_MESH_tunnel_destroy (tunnel);
+ break;
+ case 2L:
+ case 3L:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Destination client %u got a message.\n",
+ client);
+ ok++;
+ GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL, sender,
+ sizeof (struct GNUNET_MessageHeader),
+ &tmt_rdy, (void *) 1L);
+ if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
+ NULL);
+ }
+ break;
+ default:
+ break;
}
return GNUNET_OK;
}
* Handlers, for diverse services
*/
static struct GNUNET_MESH_MessageHandler handlers[] = {
- {&data_callback, 1, sizeof(struct GNUNET_MessageHeader)},
+ {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
{NULL, 0, 0}
};
* (can be NULL -- that's not an error)
*/
static void *
-incoming_tunnel (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- const struct GNUNET_PeerIdentity * initiator,
- const struct GNUNET_ATS_Information * atsi)
+incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
+ const struct GNUNET_PeerIdentity *initiator,
+ const struct GNUNET_ATS_Information *atsi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: Incoming tunnel from %s to peer %d\n",
- GNUNET_i2s(initiator),
- (long) cls);
+ GNUNET_i2s (initiator), (long) cls);
ok++;
if ((long) cls == 1L)
incoming_t = tunnel;
if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
{
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
- &disconnect_mesh_peers,
- NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
}
return NULL;
}
ok++;
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: Unknown peer! %d\n",
- i);
+ "***************** test: Unknown peer! %d\n", i);
peers_in_tunnel--;
if (peers_in_tunnel > 0)
return;
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: peer %s disconnected\n",
- GNUNET_i2s(peer));
+ GNUNET_i2s (peer));
return;
}
struct GNUNET_PeerIdentity *dest;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: peer %s connected\n",
- GNUNET_i2s(peer));
+ "***************** test: peer %s connected\n", GNUNET_i2s (peer));
- if (0 == memcmp(&d2->id, peer, sizeof(d2->id)) && (long) cls == 1L)
+ if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
ok++;
- if (test == MULTICAST &&
- 0 == memcmp(&d3->id, peer, sizeof(d3->id)) &&
+ if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
(long) cls == 1L)
ok++;
switch (test)
{
- case UNICAST:
- dest = &d2->id;
- break;
- case MULTICAST:
- peers_in_tunnel++;
- if (peers_in_tunnel < 2)
- return;
- dest = NULL;
- break;
- default:
+ case UNICAST:
+ dest = &d2->id;
+ break;
+ case MULTICAST:
+ peers_in_tunnel++;
+ if (peers_in_tunnel < 2)
return;
+ dest = NULL;
+ break;
+ default:
+ return;
}
if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
{
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
- &disconnect_mesh_peers,
- NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: Sending data...\n");
peers_responded = 0;
- GNUNET_MESH_notify_transmit_ready(t,
- GNUNET_NO,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- dest,
- sizeof(struct GNUNET_MessageHeader),
- &tmt_rdy,
- (void *) 1L);
+ GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL, dest,
+ sizeof (struct GNUNET_MessageHeader),
+ &tmt_rdy, (void *) 1L);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Disconnect already run?\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Aborting...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Disconnect already run?\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Aborting...\n");
}
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: add peer 3\n");
- GNUNET_MESH_peer_request_connect_add(t, &d3->id);
+ GNUNET_MESH_peer_request_connect_add (t, &d3->id);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: add peer 2\n");
- GNUNET_MESH_peer_request_connect_add(t, &d2->id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: add peer 2\n");
+ GNUNET_MESH_peer_request_connect_add (t, &d2->id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: schedule timeout in 30s\n");
if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
{
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30),
- &disconnect_mesh_peers,
- NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 30),
+ &disconnect_mesh_peers, NULL);
}
}
* @param emsg error message (NULL on success)
*/
void
-topo_cb (void *cls,
- const struct GNUNET_PeerIdentity* first,
- const struct GNUNET_PeerIdentity* second,
- const char *emsg)
+topo_cb (void *cls, const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second, const char *emsg)
{
GNUNET_PEER_Id p1;
GNUNET_PEER_Id p2;
struct GNUNET_PeerIdentity id;
- GNUNET_PEER_resolve(1, &id);
- p1 = GNUNET_PEER_search(first);
+ GNUNET_PEER_resolve (1, &id);
+ p1 = GNUNET_PEER_search (first);
if (p1 == pid1)
{
- p2 = GNUNET_PEER_search(second);
+ p2 = GNUNET_PEER_search (second);
if (p2 == 0 || p2 > num_peers)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"***************** test: %s is UNKNOWN!? (%u)\n",
- GNUNET_i2s(second),
- p2);
+ GNUNET_i2s (second), p2);
return;
}
mesh_peers[p2]++;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: %s IS a neighbor\n",
- GNUNET_i2s(second));
+ GNUNET_i2s (second));
return;
}
- p1 = GNUNET_PEER_search(second);
+ p1 = GNUNET_PEER_search (second);
if (p1 == pid1)
{
- p2 = GNUNET_PEER_search(first);
+ p2 = GNUNET_PEER_search (first);
if (p2 == 0 || p2 > num_peers)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"***************** test: %s is UNKNOWN!? (%u)\n",
- GNUNET_i2s(first),
- p2);
+ GNUNET_i2s (first), p2);
return;
}
mesh_peers[p2]++;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: %s IS a neighbor\n",
- GNUNET_i2s(first));
+ GNUNET_i2s (first));
return;
}
}
unsigned int i;
struct GNUNET_PeerIdentity id;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: connect_mesh_service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: connect_mesh_service\n");
for (i = 1; i <= num_peers; i++)
{
- GNUNET_PEER_resolve(i, &id);
+ GNUNET_PEER_resolve (i, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: peer %s has %u conns to d1\n",
- GNUNET_i2s (&id),
- mesh_peers[i]);
+ "***************** test: peer %s has %u conns to d1\n",
+ GNUNET_i2s (&id), mesh_peers[i]);
if (mesh_peers[i] == 0)
break;
}
{
for (i++; i <= num_peers; i++)
{
- GNUNET_PEER_resolve(i, &id);
+ GNUNET_PEER_resolve (i, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: peer %s has %u conns to d1\n",
- GNUNET_i2s (&id),
- mesh_peers[i]);
+ "***************** test: peer %s has %u conns to d1\n",
+ GNUNET_i2s (&id), mesh_peers[i]);
if (mesh_peers[i] == 0)
break;
}
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: connecting to mesh service of peer %s (%u)\n",
- GNUNET_i2s (&d1->id),
- mesh_peers[0]);
+ GNUNET_i2s (&d1->id), mesh_peers[0]);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: connecting to mesh service of peer %s (%u)\n",
- GNUNET_i2s (&d2->id),
- i);
+ GNUNET_i2s (&d2->id), i);
if (test == MULTICAST)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: connecting to mesh service of peer %s (%u)\n",
- GNUNET_i2s (&d3->id),
- i);
+ GNUNET_i2s (&d3->id), i);
}
#endif
- h1 = GNUNET_MESH_connect (d1->cfg,
- 10,
- (void *) 1L,
- NULL,
- &tunnel_cleaner,
- handlers,
- &app);
- h2 = GNUNET_MESH_connect (d2->cfg,
- 10,
- (void *) 2L,
- &incoming_tunnel,
- &tunnel_cleaner,
- handlers,
- &app);
+ h1 = GNUNET_MESH_connect (d1->cfg, 10, (void *) 1L, NULL, &tunnel_cleaner,
+ handlers, &app);
+ h2 = GNUNET_MESH_connect (d2->cfg, 10, (void *) 2L, &incoming_tunnel,
+ &tunnel_cleaner, handlers, &app);
if (test == MULTICAST)
{
- h3 = GNUNET_MESH_connect (d3->cfg,
- 10,
- (void *) 3L,
- &incoming_tunnel,
- &tunnel_cleaner,
- handlers,
- &app);
+ h3 = GNUNET_MESH_connect (d3->cfg, 10, (void *) 3L, &incoming_tunnel,
+ &tunnel_cleaner, handlers, &app);
}
t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
peers_in_tunnel = 0;
test_task =
- GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6),
- &do_test, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
+ NULL);
}
GNUNET_PEER_Id peer_id;
d1 = GNUNET_TESTING_daemon_get (pg, i);
- peer_id = GNUNET_PEER_intern(&d1->id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: %u: %s\n",
- peer_id,
- GNUNET_i2s (&d1->id));
+ peer_id = GNUNET_PEER_intern (&d1->id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: %u: %s\n",
+ peer_id, GNUNET_i2s (&d1->id));
}
d1 = GNUNET_TESTING_daemon_get (pg, 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: Peer looking: %s\n",
GNUNET_i2s (&d1->id));
- pid1 = GNUNET_PEER_intern(&d1->id);
+ pid1 = GNUNET_PEER_intern (&d1->id);
mesh_peers[pid1] = 100;
- GNUNET_TESTING_get_topology(pg, &topo_cb, NULL);
+ GNUNET_TESTING_get_topology (pg, &topo_cb, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS,
- 4),
- &connect_mesh_service,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 4),
+ &connect_mesh_service, NULL);
disconnect_task =
GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"***************** test: Problem with new connection (%s)\n",
emsg);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: (%s)\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n",
GNUNET_i2s (first));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: (%s)\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n",
GNUNET_i2s (second));
}
NULL);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Starting daemons.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "***************** test: Starting daemons.\n");
GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
"use_progressbars", "YES");
#endif
return;
}
- mesh_peers = GNUNET_malloc (sizeof(uint16_t) * (num_peers + 1));
+ mesh_peers = GNUNET_malloc (sizeof (uint16_t) * (num_peers + 1));
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
&data_filename))
{
data_file =
- GNUNET_DISK_file_open (data_filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_file_open (data_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (data_file == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
- data_filename);
+ data_filename);
GNUNET_free (data_filename);
}
}
GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
"test_mesh_small",
- gettext_noop ("Test mesh in a small network."),
- options, &run, NULL);
+ gettext_noop ("Test mesh in a small network."), options,
+ &run, NULL);
#if REMOVE_DIR
GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
#endif
"***************** test: FAILED! (%d/%d)\n", ok, ok_goal);
return 1;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "***************** test: success\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: success\n");
return 0;
}
else
{
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test: All peers successfully shut down!\n");
#endif
}
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"test: disconnecting mesh service of peers\n");
disconnect_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_MESH_disconnect(h1);
- GNUNET_MESH_disconnect(h2);
+ GNUNET_MESH_disconnect (h1);
+ GNUNET_MESH_disconnect (h2);
GNUNET_SCHEDULER_cancel (shutdown_handle);
- shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
+ shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
* (can be NULL -- that's not an error)
*/
static void *
-incoming_tunnel (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- const struct GNUNET_PeerIdentity * initiator,
- const struct GNUNET_ATS_Information * atsi)
+incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
+ const struct GNUNET_PeerIdentity *initiator,
+ const struct GNUNET_ATS_Information *atsi)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Incoming tunnel from %s\n",
- GNUNET_i2s(initiator));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Incoming tunnel from %s\n",
+ GNUNET_i2s (initiator));
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_mesh_peers, NULL);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
ok = 0;
return NULL;
}
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n");
#endif
-
+
return;
}
static void
dh (void *cls, const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: peer %s disconnected\n",
- GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s disconnected\n",
+ GNUNET_i2s (peer));
return;
}
ch (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: peer %s connected\n",
- GNUNET_i2s(peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s connected\n",
+ GNUNET_i2s (peer));
return;
}
do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
- GNUNET_MESH_peer_request_connect_add(t, &d2->id);
+ GNUNET_MESH_peer_request_connect_add (t, &d2->id);
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30),
- &disconnect_mesh_peers, NULL);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 30),
+ &disconnect_mesh_peers, NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n");
- GNUNET_PEER_resolve(11, &id);
+ GNUNET_PEER_resolve (11, &id);
d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Peer searched: %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer searched: %s\n",
GNUNET_i2s (&d2->id));
app = (GNUNET_MESH_ApplicationType) 0;
"test: connecting to mesh service of peer %s\n",
GNUNET_i2s (&d2->id));
#endif
- h1 = GNUNET_MESH_connect (d1->cfg,
- 10,
- NULL,
- NULL,
- &tunnel_cleaner,
- handlers,
- &app);
- h2 = GNUNET_MESH_connect (d2->cfg,
- 10,
- NULL,
- &incoming_tunnel,
- &tunnel_cleaner,
- handlers,
+ h1 = GNUNET_MESH_connect (d1->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers,
&app);
+ h2 = GNUNET_MESH_connect (d2->cfg, 10, NULL, &incoming_tunnel,
+ &tunnel_cleaner, handlers, &app);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"test: connected to mesh service of peer %s\n",
#endif
t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL);
test_task =
- GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6),
- &do_test, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
+ NULL);
}
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"test: Peergroup callback called with error, aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Error from testing: `%s'\n", emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
+ emsg);
ok++;
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
return;
"************************************************************\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"test: Peer Group started successfully!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Have %u connections\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
total_connections);
#endif
for (i = 0; i < num_peers; i++)
{
d1 = GNUNET_TESTING_daemon_get (pg, i);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: %u: %s\n",
- GNUNET_PEER_intern(&d1->id),
- GNUNET_i2s (&d1->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %u: %s\n",
+ GNUNET_PEER_intern (&d1->id), GNUNET_i2s (&d1->id));
}
d1 = GNUNET_TESTING_daemon_get (pg, 0);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Peer looking: %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer looking: %s\n",
GNUNET_i2s (&d1->id));
- GNUNET_SCHEDULER_add_now (&connect_mesh_service,
- NULL);
+ GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
disconnect_task =
GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test: Problem with new connection (%s)\n",
- emsg);
+ "test: Problem with new connection (%s)\n", emsg);
}
}
}
}
- mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1));
+ mesh_peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * (num_peers + 1));
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
&data_filename))
{
data_file =
- GNUNET_DISK_file_open (data_filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_file_open (data_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (data_file == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
- data_filename);
+ data_filename);
GNUNET_free (data_filename);
}
}
main (int argc, char *argv[])
{
GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast",
- gettext_noop ("Test mesh unicast in a small network."), options,
- &run, NULL);
+ gettext_noop ("Test mesh unicast in a small network."),
+ options, &run, NULL);
#if REMOVE_DIR
GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast");
#endif
int failed;
int cb_call;
-struct GNUNET_PeerIdentity* pi[10];
+struct GNUNET_PeerIdentity *pi[10];
struct MeshTunnelTree *tree;
static void
cb (void *cls, GNUNET_PEER_Id peer_id)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id);
- if(0 == cb_call)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id);
+ if (0 == cb_call)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
failed++;
}
cb_call--;
* @param first_hop Short ID of the expected first hop towards the peer.
*/
static void
-test_assert (GNUNET_PEER_Id peer_id,
- enum MeshPeerState status,
- unsigned int children,
- GNUNET_PEER_Id first_hop)
+test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status,
+ unsigned int children, GNUNET_PEER_Id first_hop)
{
struct MeshTunnelTreeNode *n;
struct MeshTunnelTreeNode *c;
int pre_failed;
pre_failed = failed;
- n = tree_find_peer(tree, peer_id);
+ n = tree_find_peer (tree, peer_id);
if (n->peer != peer_id)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Retrieved peer has wrong ID! (%u, %u)\n",
- n->peer, peer_id);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Retrieved peer has wrong ID! (%u, %u)\n", n->peer, peer_id);
failed++;
}
if (n->status != status)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Retrieved peer has wrong status! (%u, %u)\n",
- n->status, status);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Retrieved peer has wrong status! (%u, %u)\n", n->status,
+ status);
failed++;
}
- for (c = n->children_head, i = 0; NULL != c; c = c->next, i++);
+ for (c = n->children_head, i = 0; NULL != c; c = c->next, i++) ;
if (i != children)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Retrieved peer wrong has number of children! (%u, %u)\n",
- i, children);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Retrieved peer wrong has number of children! (%u, %u)\n", i,
+ children);
failed++;
}
if (0 != first_hop &&
- GNUNET_PEER_search(path_get_first_hop(tree, peer_id)) != first_hop)
+ GNUNET_PEER_search (path_get_first_hop (tree, peer_id)) != first_hop)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Wrong first hop! (%u, %u)\n",
- GNUNET_PEER_search(path_get_first_hop(tree, peer_id)),
- first_hop);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (%u, %u)\n",
+ GNUNET_PEER_search (path_get_first_hop (tree, peer_id)),
+ first_hop);
failed++;
}
if (pre_failed != failed)
{
struct GNUNET_PeerIdentity id;
+
GNUNET_PEER_resolve (peer_id, &id);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "*** Peer %s (%u) has failed %d checks! (real, expected)\n",
- GNUNET_i2s (&id), peer_id, failed - pre_failed);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "*** Peer %s (%u) has failed %d checks! (real, expected)\n",
+ GNUNET_i2s (&id), peer_id, failed - pre_failed);
}
}
static void
-finish(void)
+finish (void)
{
unsigned int i;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
for (i = 0; i < 10; i++)
{
- GNUNET_free(pi[i]);
+ GNUNET_free (pi[i]);
}
}
{
struct GNUNET_PeerIdentity *pi;
- pi = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
+ pi = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
pi->hashPubKey.bits[0] = id + 1;
return pi;
}
NULL);
for (i = 0; i < 10; i++)
{
- pi[i] = get_pi(i);
- GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i]));
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n",
- i + 1,
- GNUNET_h2s(&pi[i]->hashPubKey));
+ pi[i] = get_pi (i);
+ GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i + 1,
+ GNUNET_h2s (&pi[i]->hashPubKey));
}
tree = tree_new (1);
tree->me = tree->root;
path->peers[3] = 4;
path->length = 4;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n");
- tree_add_path(tree, path, &cb, NULL);
- tree_debug(tree);
- path1 = tree_get_path_to_peer(tree, 4);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n");
+ tree_add_path (tree, path, &cb, NULL);
+ tree_debug (tree);
+ path1 = tree_get_path_to_peer (tree, 4);
if (path->length != path1->length ||
- memcmp(path->peers, path1->peers, path->length) != 0)
+ memcmp (path->peers, path1->peers, path->length) != 0)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
failed++;
}
- path_destroy(path1);
+ path_destroy (path1);
test_assert (4, MESH_PEER_SEARCHING, 0, 2);
test_assert (3, MESH_PEER_RELAY, 1, 0);
test_assert (2, MESH_PEER_RELAY, 1, 0);
test_assert (1, MESH_PEER_ROOT, 1, 0);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
path->length--;
- tree_add_path(tree, path, &cb, NULL);
- tree_debug(tree);
+ tree_add_path (tree, path, &cb, NULL);
+ tree_debug (tree);
test_assert (4, MESH_PEER_SEARCHING, 0, 2);
test_assert (3, MESH_PEER_SEARCHING, 1, 2);
test_assert (2, MESH_PEER_RELAY, 1, 0);
test_assert (1, MESH_PEER_ROOT, 1, 0);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
path->length++;
path->peers[3] = 5;
- tree_add_path(tree, path, &cb, NULL);
- tree_debug(tree);
+ tree_add_path (tree, path, &cb, NULL);
+ tree_debug (tree);
test_assert (5, MESH_PEER_SEARCHING, 0, 2);
test_assert (4, MESH_PEER_SEARCHING, 0, 2);
test_assert (2, MESH_PEER_RELAY, 1, 0);
test_assert (1, MESH_PEER_ROOT, 1, 0);
- node = tree_find_peer(tree, 5);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
+ node = tree_find_peer (tree, 5);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
node->status = MESH_PEER_READY;
cb_call = 1;
- node2 = tree_del_path(tree, 5, &cb, NULL);
- tree_debug(tree);
+ node2 = tree_del_path (tree, 5, &cb, NULL);
+ tree_debug (tree);
if (cb_call != 0)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
failed++;
}
if (node2->peer != 5)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
failed++;
}
test_assert (2, MESH_PEER_RELAY, 1, 0);
test_assert (1, MESH_PEER_ROOT, 1, 0);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
GNUNET_free (node2);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: Adding new shorter first path...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test: Adding new shorter first path...\n");
path->length = 2;
path->peers[1] = 4;
cb_call = 1;
- tree_find_peer(tree, 4)->status = MESH_PEER_READY;
- tree_add_path(tree, path, &cb, NULL);
- tree_debug(tree);
+ tree_find_peer (tree, 4)->status = MESH_PEER_READY;
+ tree_add_path (tree, path, &cb, NULL);
+ tree_debug (tree);
if (cb_call != 0)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
failed++;
}
GNUNET_free (path);
tree_destroy (tree);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test:\n");
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n");
for (i = 0; i < 10; i++)
{
- GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i]));
+ GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
}
- tree = tree_new(1);
+ tree = tree_new (1);
path = path_new (3);
path->peers[0] = 1;
path->peers[1] = 2;
path->peers[2] = 3;
path->length = 3;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
- tree_add_path(tree, path, &cb, NULL);
- tree_debug(tree);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
+ tree_add_path (tree, path, &cb, NULL);
+ tree_debug (tree);
tree_set_me (tree, 2);
test_assert (3, MESH_PEER_SEARCHING, 0, 3);
test_assert (2, MESH_PEER_RELAY, 1, 0);
test_assert (1, MESH_PEER_ROOT, 1, 0);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
- tree_add_path(tree, path, &cb, NULL);
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
+ tree_add_path (tree, path, &cb, NULL);
+
GNUNET_free (path->peers);
GNUNET_free (path);
tree_destroy (tree);
- finish();
+ finish ();
if (failed > 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);
ip = &s4->sin_addr;
/* Check if address is in 127.0.0.0/8 */
- uint32_t address = ntohl((in_addr_t)(s4->sin_addr.s_addr));
+ uint32_t address = ntohl ((in_addr_t) (s4->sin_addr.s_addr));
uint32_t value = (address & 0xFF000000) ^ 0x7F000000;
+
if ((h->return_localaddress == GNUNET_NO) && (value == 0))
{
return GNUNET_OK;
h->use_localaddresses =
GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_LOCALADDR");
h->return_localaddress =
- GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "RETURN_LOCAL_ADDRESSES");
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat",
+ "RETURN_LOCAL_ADDRESSES");
h->use_hostname =
GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_HOSTNAME");
nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server");
if (GNUNET_SYSERR == nat_res)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' file not found\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Cannot run NAT test: `%s' file not found\n",
"gnunet-nat-server");
return 0;
}
&data_filename))
{
data_file =
- GNUNET_DISK_file_open (data_filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_file_open (data_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (data_file == NULL)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
- data_filename);
+ data_filename);
GNUNET_free (data_filename);
}
std_dev = sqrt (variance);
current_std_dev = std_dev;
current_size_estimate = mean;
-
+
em->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage));
em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE);
em->reserved = htonl (0);
fm->pkey = my_public_key;
fm->proof_of_work = my_proof;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, &fm->signature));
+ GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose,
+ &fm->signature));
}
{
size_estimate_messages[i].proof_of_work = my_proof;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (my_private_key,
- &size_estimate_messages[i].purpose,
- &size_estimate_messages[i].signature));
+ GNUNET_CRYPTO_rsa_sign (my_private_key,
+ &size_estimate_messages
+ [i].purpose,
+ &size_estimate_messages
+ [i].signature));
}
write_proof ();
return;
handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
const struct GNUNET_NSE_FloodMessage *incoming_flood;
struct GNUNET_TIME_Absolute ts;
static void
handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct NSEPeerEntry *peer_entry;
/**
* Schedule the next action to be performed.
*/
-static void schedule_action (struct GNUNET_STATISTICS_Handle *h);
+static void
+schedule_action (struct GNUNET_STATISTICS_Handle *h);
/**
* Try to (re)connect to the statistics service.
*
* @return GNUNET_YES on success, GNUNET_NO on failure.
*/
-static int try_connect (struct GNUNET_STATISTICS_Handle *ret);
+static int
+try_connect (struct GNUNET_STATISTICS_Handle *ret);
static void
insert_ai (struct GNUNET_STATISTICS_Handle *h,
- struct GNUNET_STATISTICS_GetHandle *ai)
+ struct GNUNET_STATISTICS_GetHandle *ai)
{
GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail,
- h->action_tail, ai);
+ h->action_tail, ai);
if (h->action_head == ai)
schedule_action (h);
}
static void
schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
- struct GNUNET_STATISTICS_WatchEntry *watch)
+ struct GNUNET_STATISTICS_WatchEntry *watch)
{
struct GNUNET_STATISTICS_GetHandle *ai;
GNUNET_assert (h != NULL);
if (GNUNET_YES != try_connect (h))
- {
- schedule_action (h);
- return;
- }
+ {
+ schedule_action (h);
+ return;
+ }
slen = strlen (watch->subsystem) + 1;
nlen = strlen (watch->name) + 1;
nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen;
if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
ai->sh = h;
ai->subsystem = GNUNET_strdup (watch->subsystem);
return GNUNET_YES;
ret->client = GNUNET_CLIENT_connect ("statistics", ret->cfg);
if (ret->client != NULL)
- {
- for (i = 0; i < ret->watches_size; i++)
- schedule_watch_request (ret, ret->watches[i]);
- return GNUNET_YES;
- }
+ {
+ for (i = 0; i < ret->watches_size; i++)
+ schedule_watch_request (ret, ret->watches[i]);
+ return GNUNET_YES;
+ }
#if DEBUG_STATISTICS
LOG (GNUNET_ERROR_TYPE_DEBUG,
_("Failed to connect to statistics service!\n"));
h->current = NULL;
schedule_action (h);
if (pos != NULL)
- {
- if (pos->cont != NULL)
- pos->cont (pos->cls, code);
- free_action_item (pos);
- }
+ {
+ if (pos->cont != NULL)
+ pos->cont (pos->cls, code);
+ free_action_item (pos);
+ }
}
*/
static int
process_message (struct GNUNET_STATISTICS_Handle *h,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
char *service;
char *name;
uint16_t size;
if (h->current->aborted)
- {
+ {
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Iteration was aborted, ignoring VALUE\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Iteration was aborted, ignoring VALUE\n");
#endif
- return GNUNET_OK; /* don't bother */
- }
+ return GNUNET_OK; /* don't bother */
+ }
size = ntohs (msg->size);
if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg;
size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
if (size !=
GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2,
- &service, &name))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ &service, &name))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received valid statistic on `%s:%s': %llu\n", service, name,
- GNUNET_ntohll (smsg->value));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received valid statistic on `%s:%s': %llu\n",
+ service, name, GNUNET_ntohll (smsg->value));
#endif
if (GNUNET_OK !=
h->current->proc (h->current->cls, service, name,
- GNUNET_ntohll (smsg->value),
- 0 !=
- (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
- {
+ GNUNET_ntohll (smsg->value),
+ 0 !=
+ (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
+ {
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Processing of remaining statistics aborted by client.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Processing of remaining statistics aborted by client.\n");
#endif
- h->current->aborted = GNUNET_YES;
- }
+ h->current->aborted = GNUNET_YES;
+ }
#if DEBUG_STATISTICS
LOG (GNUNET_ERROR_TYPE_DEBUG, "VALUE processed successfully\n");
#endif
static int
process_watch_value (struct GNUNET_STATISTICS_Handle *h,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_MessageHeader *msg)
{
const struct GNUNET_STATISTICS_WatchValueMessage *wvm;
struct GNUNET_STATISTICS_WatchEntry *w;
uint32_t wid;
- if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) !=
- ntohs (msg->size))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != ntohs (msg->size))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg;
GNUNET_break (0 == ntohl (wvm->reserved));
wid = ntohl (wvm->wid);
if (wid >= h->watches_size)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
w = h->watches[wid];
(void) w->proc (w->proc_cls, w->subsystem, w->name,
- GNUNET_ntohll (wvm->value),
- 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
+ GNUNET_ntohll (wvm->value),
+ 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
return GNUNET_OK;
}
struct GNUNET_STATISTICS_Handle *h = cls;
if (msg == NULL)
+ {
+ if (NULL != h->client)
{
- if (NULL != h->client)
- {
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
- }
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Error receiving statistics from service, is the service running?\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+ "Error receiving statistics from service, is the service running?\n");
#endif
- finish (h, GNUNET_SYSERR);
- return;
- }
+ finish (h, GNUNET_SYSERR);
+ return;
+ }
switch (ntohs (msg->type))
+ {
+ case GNUNET_MESSAGE_TYPE_STATISTICS_END:
+#if DEBUG_STATISTICS
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n");
+#endif
+ h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
+ if (h->watches_size > 0)
{
- case GNUNET_MESSAGE_TYPE_STATISTICS_END:
+ GNUNET_CLIENT_receive (h->client, &receive_stats, h,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ }
+ else
+ {
+ h->receiving = GNUNET_NO;
+ }
+ finish (h, GNUNET_OK);
+ return;
+ case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
+ if (GNUNET_OK == process_message (h, msg))
+ {
+ /* finally, look for more! */
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Processing VALUE done, now reading more\n");
#endif
+ GNUNET_CLIENT_receive (h->client, &receive_stats, h,
+ GNUNET_TIME_absolute_get_remaining (h->
+ current->timeout));
h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- if (h->watches_size > 0)
- {
- GNUNET_CLIENT_receive (h->client, &receive_stats, h,
- GNUNET_TIME_UNIT_FOREVER_REL);
- }
- else
- {
- h->receiving = GNUNET_NO;
- }
- finish (h, GNUNET_OK);
return;
- case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
- if (GNUNET_OK == process_message (h, msg))
- {
- /* finally, look for more! */
-#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Processing VALUE done, now reading more\n");
-#endif
- GNUNET_CLIENT_receive (h->client, &receive_stats, h,
- GNUNET_TIME_absolute_get_remaining
- (h->current->timeout));
- h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- return;
- }
- GNUNET_break (0);
- break;
- case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
- if (GNUNET_OK == process_watch_value (h, msg))
- {
- h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- GNUNET_assert (h->watches_size > 0);
- GNUNET_CLIENT_receive (h->client, &receive_stats, h,
- GNUNET_TIME_UNIT_FOREVER_REL);
- return;
- }
- GNUNET_break (0);
- break;
- default:
- GNUNET_break (0);
- break;
}
- if (NULL != h->client)
+ GNUNET_break (0);
+ break;
+ case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
+ if (GNUNET_OK == process_watch_value (h, msg))
{
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
+ h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
+ GNUNET_assert (h->watches_size > 0);
+ GNUNET_CLIENT_receive (h->client, &receive_stats, h,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ return;
}
+ GNUNET_break (0);
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
+ if (NULL != h->client)
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
finish (h, GNUNET_SYSERR);
}
uint16_t msize;
if (buf == NULL)
- {
- /* timeout / error */
+ {
+ /* timeout / error */
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission of request for statistics failed!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission of request for statistics failed!\n");
#endif
- finish (handle, GNUNET_SYSERR);
- return 0;
- }
+ finish (handle, GNUNET_SYSERR);
+ return 0;
+ }
slen1 = strlen (handle->current->subsystem) + 1;
slen2 = strlen (handle->current->name) + 1;
msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
hdr->size = htons (msize);
hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET);
GNUNET_assert (slen1 + slen2 ==
- GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2,
- 2, handle->current->subsystem,
- handle->current->name));
+ GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
+ handle->current->subsystem,
+ handle->current->name));
if (!handle->receiving)
- {
+ {
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission of GET done, now reading response\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission of GET done, now reading response\n");
#endif
- handle->receiving = GNUNET_YES;
- GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
- GNUNET_TIME_absolute_get_remaining
- (handle->current->timeout));
- }
+ handle->receiving = GNUNET_YES;
+ GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
+ GNUNET_TIME_absolute_get_remaining (handle->
+ current->timeout));
+ }
return msize;
}
* the response).
*/
static size_t
-transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size,
- void *buf)
+transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
{
struct GNUNET_MessageHeader *hdr;
size_t slen1;
uint16_t msize;
if (buf == NULL)
- {
- /* timeout / error */
+ {
+ /* timeout / error */
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission of request for statistics failed!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission of request for statistics failed!\n");
#endif
- finish (handle, GNUNET_SYSERR);
- return 0;
- }
+ finish (handle, GNUNET_SYSERR);
+ return 0;
+ }
#if DEBUG_STATISTICS
LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n",
handle->current->name);
hdr->size = htons (msize);
hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
GNUNET_assert (slen1 + slen2 ==
- GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2,
- 2, handle->current->subsystem,
- handle->current->name));
+ GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
+ handle->current->subsystem,
+ handle->current->name));
if (GNUNET_YES != handle->receiving)
- {
- handle->receiving = GNUNET_YES;
- GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
- GNUNET_TIME_UNIT_FOREVER_REL);
- }
+ {
+ handle->receiving = GNUNET_YES;
+ GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ }
finish (handle, GNUNET_OK);
return msize;
}
size_t nsize;
if (NULL == buf)
- {
- finish (handle, GNUNET_SYSERR);
- return 0;
- }
+ {
+ finish (handle, GNUNET_SYSERR);
+ return 0;
+ }
slen = strlen (handle->current->subsystem) + 1;
nlen = strlen (handle->current->name) + 1;
nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
if (size < nsize)
- {
- GNUNET_break (0);
- finish (handle, GNUNET_SYSERR);
- return 0;
- }
+ {
+ GNUNET_break (0);
+ finish (handle, GNUNET_SYSERR);
+ return 0;
+ }
r = buf;
r->header.size = htons (nsize);
r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
if (handle->current->type == ACTION_UPDATE)
r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
GNUNET_assert (slen + nlen ==
- GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2,
- handle->current->subsystem,
- handle->current->name));
+ GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2,
+ handle->current->subsystem,
+ handle->current->name));
finish (handle, GNUNET_OK);
return nsize;
}
handle->th = NULL;
switch (handle->current->type)
- {
- case ACTION_GET:
- ret = transmit_get (handle, size, buf);
- break;
- case ACTION_SET:
- case ACTION_UPDATE:
- ret = transmit_set (handle, size, buf);
- break;
- case ACTION_WATCH:
- ret = transmit_watch (handle, size, buf);
- break;
- default:
- ret = 0;
- GNUNET_break (0);
- break;
- }
+ {
+ case ACTION_GET:
+ ret = transmit_get (handle, size, buf);
+ break;
+ case ACTION_SET:
+ case ACTION_UPDATE:
+ ret = transmit_set (handle, size, buf);
+ break;
+ case ACTION_WATCH:
+ ret = transmit_watch (handle, size, buf);
+ break;
+ default:
+ ret = 0;
+ GNUNET_break (0);
+ break;
+ }
return ret;
}
*/
struct GNUNET_STATISTICS_Handle *
GNUNET_STATISTICS_create (const char *subsystem,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_STATISTICS_Handle *ret;
ret->subsystem = GNUNET_strdup (subsystem);
ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
if (GNUNET_YES != try_connect (ret))
- {
- GNUNET_free (ret->subsystem);
- GNUNET_free (ret);
- return NULL;
- }
+ {
+ GNUNET_free (ret->subsystem);
+ GNUNET_free (ret);
+ return NULL;
+ }
return ret;
}
if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
GNUNET_SCHEDULER_cancel (h->backoff_task);
if (sync_first)
+ {
+ if (h->current != NULL)
{
- if (h->current != NULL)
- {
- if (h->current->type == ACTION_GET)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
- h->th = NULL;
- free_action_item (h->current);
- h->current = NULL;
- }
- }
- pos = h->action_head;
- prev = NULL;
- while (pos != NULL)
- {
- next = pos->next;
- if (pos->type == ACTION_GET)
- {
- if (prev == NULL)
- h->action_head = next;
- else
- prev->next = next;
- free_action_item (pos);
- }
- else
- {
- prev = pos;
- }
- pos = next;
- }
- h->action_tail = prev;
- if (h->current == NULL)
- {
- h->current = h->action_head;
- if (h->action_head != NULL)
- {
- h->action_head = h->action_head->next;
- if (h->action_head == NULL)
- h->action_tail = NULL;
- }
- }
- h->do_destroy = GNUNET_YES;
- if ((h->current != NULL) && (h->th == NULL))
- {
- timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
- h->th =
- GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
- timeout, GNUNET_YES,
- &transmit_action, h);
- GNUNET_assert (NULL != h->th);
- }
- if (h->th != NULL)
- return;
+ if (h->current->type == ACTION_GET)
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ free_action_item (h->current);
+ h->current = NULL;
+ }
}
- if (NULL != h->th)
+ pos = h->action_head;
+ prev = NULL;
+ while (pos != NULL)
{
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
- h->th = NULL;
+ next = pos->next;
+ if (pos->type == ACTION_GET)
+ {
+ if (prev == NULL)
+ h->action_head = next;
+ else
+ prev->next = next;
+ free_action_item (pos);
+ }
+ else
+ {
+ prev = pos;
+ }
+ pos = next;
}
- if (h->current != NULL)
- free_action_item (h->current);
- while (NULL != (pos = h->action_head))
+ h->action_tail = prev;
+ if (h->current == NULL)
{
- h->action_head = pos->next;
- free_action_item (pos);
+ h->current = h->action_head;
+ if (h->action_head != NULL)
+ {
+ h->action_head = h->action_head->next;
+ if (h->action_head == NULL)
+ h->action_tail = NULL;
+ }
}
- if (h->client != NULL)
+ h->do_destroy = GNUNET_YES;
+ if ((h->current != NULL) && (h->th == NULL))
{
- GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
- h->client = NULL;
+ timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
+ h->th =
+ GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
+ timeout, GNUNET_YES,
+ &transmit_action, h);
+ GNUNET_assert (NULL != h->th);
}
+ if (h->th != NULL)
+ return;
+ }
+ if (NULL != h->th)
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
+ if (h->current != NULL)
+ free_action_item (h->current);
+ while (NULL != (pos = h->action_head))
+ {
+ h->action_head = pos->next;
+ free_action_item (pos);
+ }
+ if (h->client != NULL)
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
+ h->client = NULL;
+ }
for (i = 0; i < h->watches_size; i++)
- {
- GNUNET_free (h->watches[i]->subsystem);
- GNUNET_free (h->watches[i]->name);
- GNUNET_free (h->watches[i]);
- }
+ {
+ GNUNET_free (h->watches[i]->subsystem);
+ GNUNET_free (h->watches[i]->name);
+ GNUNET_free (h->watches[i]);
+ }
GNUNET_array_grow (h->watches, h->watches_size, 0);
GNUNET_free (h->subsystem);
GNUNET_free (h);
struct GNUNET_TIME_Relative timeout;
if (h->current != NULL)
- return; /* action already pending */
+ return; /* action already pending */
if (GNUNET_YES != try_connect (h))
- {
- h->backoff_task =
- GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h);
- h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
- h->backoff =
- GNUNET_TIME_relative_min (h->backoff,
- GNUNET_CONSTANTS_SERVICE_TIMEOUT);
- return;
- }
+ {
+ h->backoff_task =
+ GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h);
+ h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
+ h->backoff =
+ GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
+ return;
+ }
/* schedule next action */
h->current = h->action_head;
if (NULL == h->current)
+ {
+ if (h->do_destroy)
{
- if (h->do_destroy)
- {
- h->do_destroy = GNUNET_NO;
- GNUNET_STATISTICS_destroy (h, GNUNET_YES);
- }
- return;
+ h->do_destroy = GNUNET_NO;
+ GNUNET_STATISTICS_destroy (h, GNUNET_YES);
}
+ return;
+ }
GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current);
timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
if (NULL ==
(h->th =
GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
- timeout, GNUNET_YES,
- &transmit_action, h)))
- {
+ timeout, GNUNET_YES,
+ &transmit_action, h)))
+ {
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to transmit request to statistics service.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to transmit request to statistics service.\n");
#endif
- finish (h, GNUNET_SYSERR);
- }
+ finish (h, GNUNET_SYSERR);
+ }
}
*/
struct GNUNET_STATISTICS_GetHandle *
GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
- const char *subsystem, const char *name,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_STATISTICS_Callback cont,
- GNUNET_STATISTICS_Iterator proc, void *cls)
+ const char *subsystem, const char *name,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_STATISTICS_Callback cont,
+ GNUNET_STATISTICS_Iterator proc, void *cls)
{
size_t slen1;
size_t slen2;
GNUNET_assert (proc != NULL);
GNUNET_assert (GNUNET_NO == handle->do_destroy);
if (GNUNET_YES != try_connect (handle))
- {
+ {
#if DEBUG_STATISTICS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect to statistics service, can not get value `%s:%s'.\n",
- strlen (subsystem) ? subsystem : "*", strlen (name) ? name : "*");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect to statistics service, can not get value `%s:%s'.\n",
+ strlen (subsystem) ? subsystem : "*", strlen (name) ? name : "*");
#endif
- return NULL;
- }
+ return NULL;
+ }
if (subsystem == NULL)
subsystem = "";
if (name == NULL)
slen1 = strlen (subsystem) + 1;
slen2 = strlen (name) + 1;
GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) <
- GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ GNUNET_SERVER_MAX_MESSAGE_SIZE);
ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
ai->sh = handle;
ai->subsystem = GNUNET_strdup (subsystem);
GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
{
if (gh->sh->current == gh)
- {
- gh->aborted = GNUNET_YES;
- }
+ {
+ gh->aborted = GNUNET_YES;
+ }
else
- {
- GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail,
- gh);
- GNUNET_free (gh->name);
- GNUNET_free (gh->subsystem);
- GNUNET_free (gh);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, gh);
+ GNUNET_free (gh->name);
+ GNUNET_free (gh->subsystem);
+ GNUNET_free (gh);
+ }
}
*/
int
GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
- const char *subsystem, const char *name,
- GNUNET_STATISTICS_Iterator proc, void *proc_cls)
+ const char *subsystem, const char *name,
+ GNUNET_STATISTICS_Iterator proc, void *proc_cls)
{
struct GNUNET_STATISTICS_WatchEntry *w;
static void
add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
- int make_persistent, uint64_t value, enum ActionType type)
+ int make_persistent, uint64_t value, enum ActionType type)
{
struct GNUNET_STATISTICS_GetHandle *ai;
size_t slen;
nlen = strlen (name) + 1;
nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
ai = h->action_head;
while (ai != NULL)
+ {
+ if ((0 == strcmp (ai->subsystem, h->subsystem)) &&
+ (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) ||
+ (ai->type == ACTION_SET)))
{
- if ((0 == strcmp (ai->subsystem, h->subsystem)) &&
- (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) ||
- (ai->type == ACTION_SET)))
- {
- if (ai->type == ACTION_SET)
- {
- if (type == ACTION_UPDATE)
- {
- delta = (int64_t) value;
- if (delta > 0)
- {
- ai->value += delta;
- }
- else
- {
- if (ai->value < -delta)
- ai->value = 0;
- else
- ai->value += delta;
- }
- }
- else
- {
- ai->value = value;
- }
- }
- else
- {
- if (type == ACTION_UPDATE)
- {
- delta = (int64_t) value;
- ai->value += delta;
- }
- else
- {
- ai->value = value;
- ai->type = type;
- }
- }
- ai->timeout =
- GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
- ai->make_persistent = make_persistent;
- return;
- }
- ai = ai->next;
+ if (ai->type == ACTION_SET)
+ {
+ if (type == ACTION_UPDATE)
+ {
+ delta = (int64_t) value;
+ if (delta > 0)
+ {
+ ai->value += delta;
+ }
+ else
+ {
+ if (ai->value < -delta)
+ ai->value = 0;
+ else
+ ai->value += delta;
+ }
+ }
+ else
+ {
+ ai->value = value;
+ }
+ }
+ else
+ {
+ if (type == ACTION_UPDATE)
+ {
+ delta = (int64_t) value;
+ ai->value += delta;
+ }
+ else
+ {
+ ai->value = value;
+ ai->type = type;
+ }
+ }
+ ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
+ ai->make_persistent = make_persistent;
+ return;
}
+ ai = ai->next;
+ }
ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
ai->sh = h;
ai->subsystem = GNUNET_strdup (h->subsystem);
*/
void
GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
- const char *name, uint64_t value, int make_persistent)
+ const char *name, uint64_t value, int make_persistent)
{
if (handle == NULL)
return;
*/
void
GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
- const char *name, int64_t delta,
- int make_persistent)
+ const char *name, int64_t delta, int make_persistent)
{
if (handle == NULL)
return;
return;
GNUNET_assert (GNUNET_NO == handle->do_destroy);
add_setter_action (handle, name, make_persistent, (uint64_t) delta,
- ACTION_UPDATE);
+ ACTION_UPDATE);
}
#endif
c1 = GNUNET_CONFIGURATION_create ();
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_load (c1, "test_testing_connect_peer1.conf"));
+ GNUNET_CONFIGURATION_load (c1,
+ "test_testing_connect_peer1.conf"));
c2 = GNUNET_CONFIGURATION_create ();
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_load (c2, "test_testing_connect_peer2.conf"));
+ GNUNET_CONFIGURATION_load (c2,
+ "test_testing_connect_peer2.conf"));
d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
NULL, NULL, &my_cb1, NULL);
GNUNET_assert (d1 != NULL);
if (d2 != NULL)
{
GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL,
- (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
- GNUNET_NO);
+ (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
+ GNUNET_NO);
d2 = NULL;
}
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
#endif
c1 = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (c1, "test_testing_connect_peer1.conf"));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load (c1,
+ "test_testing_connect_peer1.conf"));
c2 = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (c2, "test_testing_connect_peer2.conf"));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load (c2,
+ "test_testing_connect_peer2.conf"));
run_phase ();
}
process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
char *dotOutFileNameFinished;
FILE *dotOutFileFinished;
static void
connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct TestMessageContext *pos = cls;
*/
pos->peer2handle =
GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
- NULL, NULL, GNUNET_YES, NULL, GNUNET_YES,
- handlers);
+ NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, handlers);
}
*/
pos->peer1handle =
GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
- &connect_notify_peers, NULL, NULL, GNUNET_NO,
- NULL, GNUNET_NO, no_handlers);
+ &connect_notify_peers, NULL, NULL, GNUNET_NO, NULL,
+ GNUNET_NO, no_handlers);
GNUNET_assert (pos->peer1handle != NULL);
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_TESTING_ConnectContext *ctx = cls;
if (connect_ctx->send_hello == GNUNET_NO)
{
- GNUNET_TRANSPORT_try_connect (connect_ctx->d1th,
- &connect_ctx->d2->id);
+ GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, &connect_ctx->d2->id);
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending connect request to TRANSPORT of %s for peer %s\n",
static void
core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct GNUNET_TESTING_ConnectContext *ctx = cls;
return connect_attempts;
}
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found %u total peers in topology\n", total_peers);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u total peers in topology\n",
+ total_peers);
#endif
GNUNET_assert (total_peers == pg->total);
curr_state = PEER_INDEX;
while (conn != NULL)
{
GNUNET_TRANSPORT_try_connect (send_hello_context->peer->daemon->th,
- &send_hello_context->pg->peers[conn->index].daemon->id);
+ &send_hello_context->pg->peers[conn->
+ index].daemon->
+ id);
conn = conn->next;
}
send_hello_context->core_connect_task =
*/
void
core_init (void *cls, struct GNUNET_CORE_Handle *server,
- struct GNUNET_PeerIdentity *my_identity)
+ struct GNUNET_PeerIdentity *my_identity)
{
struct SendHelloContext *send_hello_context = cls;
static void
internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct CoreContext *core_ctx = cls;
struct TopologyIterateContext *iter_ctx = core_ctx->iter_context;
"peerStartHelper.pl", tempdir, NULL);
GNUNET_assert (helper->proc != NULL);
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "starting peers with cmd ssh %s %s %s\n", arg,
- "peerStartHelper.pl", tempdir);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting peers with cmd ssh %s %s %s\n",
+ arg, "peerStartHelper.pl", tempdir);
#endif
GNUNET_SCHEDULER_add_now (&check_peers_started, helper);
GNUNET_free (tempdir);
fs = 0;
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found file size %llu for hostkeys\n",
- fs);
+ "Found file size %llu for hostkeys\n", fs);
#endif
if (0 != (fs % HOSTKEYFILESIZE))
{
for (i = 0; i < pg->total; i++)
{
#if DEBUG_START
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting up service %s on peer %d!\n", service,
- stopped_arr[stopped_permute[i]]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting up service %s on peer %d!\n",
+ service, stopped_arr[stopped_permute[i]]);
#endif
peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext));
peer_start_ctx->start_ctx = start_ctx;
GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
GNUNET_free_non_null (pg_start_ctx->fail_reason);
- pg_start_ctx->fail_reason =
- GNUNET_strdup ("from continue startup (timeout)");
+ pg_start_ctx->fail_reason =
+ GNUNET_strdup ("from continue startup (timeout)");
pg_start_ctx->die_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
(pg_start_ctx->timeout), &end_badly,
/* Make compilers happy */
reset_meter (pg_start_ctx->peer_start_meter);
pg_start_ctx->fail_reason =
- GNUNET_strdup ("didn't generate all hostkeys within allowed startup time!");
+ GNUNET_strdup
+ ("didn't generate all hostkeys within allowed startup time!");
pg_start_ctx->die_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
(pg_start_ctx->timeout), &end_badly,
GNUNET_i2s (&pos->pid));
#endif
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connect requests issued to transport"),
- 1, GNUNET_NO);
+ gettext_noop
+ ("# connect requests issued to transport"), 1,
+ GNUNET_NO);
GNUNET_TRANSPORT_try_connect (transport, &pos->pid);
}
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct Peer *pos;
handle_encrypted_hello (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+ unsigned int atsi_count)
{
struct Peer *peer;
struct GNUNET_PeerIdentity pid;
transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
handle =
GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_notify,
- &disconnect_notify, NULL, GNUNET_NO, NULL,
- GNUNET_NO, handlers);
+ &disconnect_notify, NULL, GNUNET_NO, NULL, GNUNET_NO,
+ handlers);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
NULL);
if (NULL == transport)
static void
transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target,
const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count,
- const char * transport,
- const void * addr,
+ uint32_t ats_count, const char *transport, const void *addr,
size_t addrlen)
{
const struct GNUNET_MessageHeader *hello = cls;
/**
- * We received some payload. Prepare to pass it on to our clients.
+ * We received some payload. Prepare to pass it on to our clients.
*
* @param peer (claimed) identity of the other peer
* @param message the message, never NULL
*/
static struct GNUNET_TIME_Relative
process_payload (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
struct GNUNET_TIME_Relative ret;
int do_forward;
struct InboundMessage *im;
size_t msg_size = ntohs (message->size);
- size_t size = sizeof (struct InboundMessage) + msg_size + sizeof (struct GNUNET_ATS_Information) * ats_count;
+ size_t size =
+ sizeof (struct InboundMessage) + msg_size +
+ sizeof (struct GNUNET_ATS_Information) * ats_count;
char buf[size];
struct GNUNET_ATS_Information *ap;
-
+
ret = GNUNET_TIME_UNIT_ZERO;
do_forward = GNUNET_SYSERR;
- ret =
- GST_neighbours_calculate_receive_delay (peer,
- msg_size,
- &do_forward);
+ ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward);
if (!GST_neighbours_test_connected (peer))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Discarded %u bytes type %u payload from peer `%s'\n",
- msg_size,
- ntohs (message->type),
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Discarded %u bytes type %u payload from peer `%s'\n", msg_size,
+ ntohs (message->type), GNUNET_i2s (peer));
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# bytes payload discarded due to not connected peer "),
- msg_size,
- GNUNET_NO);
+ gettext_noop
+ ("# bytes payload discarded due to not connected peer "),
+ msg_size, GNUNET_NO);
return ret;
}
if (do_forward != GNUNET_YES)
return ret;
- im = (struct InboundMessage*) buf;
+ im = (struct InboundMessage *) buf;
im->header.size = htons (size);
im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
im->ats_count = htonl (ats_count);
im->peer = *peer;
- ap = (struct GNUNET_ATS_Information*) &im[1];
+ ap = (struct GNUNET_ATS_Information *) &im[1];
memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
memcpy (&ap[ats_count], message, ntohs (message->size));
const char *plugin_name = cls;
struct GNUNET_TIME_Relative ret;
uint16_t type;
-
+
ret = GNUNET_TIME_UNIT_ZERO;
if (NULL == message)
goto end;
case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Processing `%s' from `%s'\n", "PING",
- (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
- sender_address,
- sender_address_len)
- : "<inbound>");
+ "Processing `%s' from `%s'\n", "PING",
+ (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
+ sender_address,
+ sender_address_len)
+ : "<inbound>");
#endif
GST_validation_handle_ping (peer, message, plugin_name, session,
- sender_address, sender_address_len);
+ sender_address, sender_address_len);
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Processing `%s' from `%s'\n", "PONG",
- (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
- sender_address,
- sender_address_len)
- : "<inbound>");
+ "Processing `%s' from `%s'\n", "PONG",
+ (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
+ sender_address,
+ sender_address_len)
+ : "<inbound>");
#endif
GST_validation_handle_pong (peer, message);
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
- GST_neighbours_handle_connect (message,
- peer,
- plugin_name, sender_address, sender_address_len,
- session, ats, ats_count);
+ GST_neighbours_handle_connect (message, peer, plugin_name, sender_address,
+ sender_address_len, session, ats, ats_count);
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK:
- GST_neighbours_handle_connect_ack (message,
- peer,
- plugin_name, sender_address, sender_address_len,
- session, ats, ats_count);
+ GST_neighbours_handle_connect_ack (message, peer, plugin_name,
+ sender_address, sender_address_len,
+ session, ats, ats_count);
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
- GST_neighbours_handle_ack (message,
- peer,
- plugin_name, sender_address, sender_address_len,
- session, ats, ats_count);
+ GST_neighbours_handle_ack (message, peer, plugin_name, sender_address,
+ sender_address_len, session, ats, ats_count);
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
GST_neighbours_handle_disconnect_message (peer, message);
break;
default:
/* should be payload */
- ret = process_payload (peer,
- message,
- ats, ats_count);
+ ret = process_payload (peer, message, ats, ats_count);
break;
}
- end:
+end:
#if 1
/* FIXME: this should not be needed, and not sure it's good to have it, but without
- this connections seem to go extra-slow */
- GNUNET_ATS_address_update (GST_ats, peer,
- plugin_name, sender_address, sender_address_len,
- session,
- ats, ats_count);
+ * this connections seem to go extra-slow */
+ GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
+ sender_address_len, session, ats, ats_count);
#endif
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Allowing receive from peer %s to continue in %llu ms\n",
- GNUNET_i2s (peer),
- (unsigned long long) ret.rel_value);
+ "Allowing receive from peer %s to continue in %llu ms\n",
+ GNUNET_i2s (peer), (unsigned long long) ret.rel_value);
#endif
return ret;
}
struct Session *session)
{
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X to peer `%s' ended \n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n",
session, GNUNET_i2s (peer));
#endif
if (NULL != session)
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
- "transport-ats",
- "Telling ATS to destroy session %p from peer %s\n",
- session,
- GNUNET_i2s (peer));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
+ "transport-ats",
+ "Telling ATS to destroy session %p from peer %s\n",
+ session, GNUNET_i2s (peer));
GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session);
GST_neighbours_session_terminated (peer, session);
}
*/
static void
ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- struct Session *session,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, struct Session *session,
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- const struct GNUNET_ATS_Information * ats,
+ const struct GNUNET_ATS_Information *ats,
uint32_t ats_count)
{
uint32_t bw_in = ntohl (bandwidth_in.value__);
uint32_t bw_out = ntohl (bandwidth_out.value__);
- /* ATS tells me to disconnect from peer*/
+ /* ATS tells me to disconnect from peer */
if ((bw_in == 0) && (bw_out == 0))
{
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ATS tells me to disconnect from peer `%s'\n",
- GNUNET_i2s (peer));
+ "ATS tells me to disconnect from peer `%s'\n",
+ GNUNET_i2s (peer));
#endif
- GST_neighbours_force_disconnect(peer);
+ GST_neighbours_force_disconnect (peer);
return;
}
/* will never return GNUNET_YES since connection is to be established */
GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr,
- plugin_addr_len, session, ats, ats_count,
- bandwidth_in, bandwidth_out);
+ plugin_addr_len, session, ats,
+ ats_count, bandwidth_in,
+ bandwidth_out);
}
static void
neighbours_connect_notification (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information
- *ats, uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count)
{
- size_t len = sizeof (struct ConnectInfoMessage) +
+ size_t len =
+ sizeof (struct ConnectInfoMessage) +
ats_count * sizeof (struct GNUNET_ATS_Information);
char buf[len];
struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
connect_msg->ats_count = htonl (ats_count);
connect_msg->id = *peer;
ap = (struct GNUNET_ATS_Information *) &connect_msg[1];
- memcpy (ap, ats,
- ats_count * sizeof (struct GNUNET_ATS_Information));
+ memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
}
GST_plugins_load (&plugin_env_receive_callback,
&plugin_env_address_change_notification,
&plugin_env_session_end);
- GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
+ GST_ats =
+ GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
GST_neighbours_start (NULL, &neighbours_connect_notification,
&neighbours_disconnect_notification);
GST_clients_start (server);
static void
test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour,
const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count,
- const char * transport,
- const void * addr,
+ uint32_t ats_count, const char *transport, const void *addr,
size_t addrlen)
{
struct TestConnectionContext *tcc = cls;
GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %X connected\n", tc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %X connected\n", tc);
#endif
return tc;
}
static void
notify_client_about_neighbour (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information
- *ats, uint32_t ats_count,
- const char * transport,
- const void * addr,
- size_t addrlen)
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count, const char *transport,
+ const void *addr, size_t addrlen)
{
struct TransportClient *tc = cls;
struct ConnectInfoMessage *cim;
struct GNUNET_ATS_Information *ap;
size_t size =
- sizeof (struct ConnectInfoMessage) +
- ats_count * sizeof (struct GNUNET_ATS_Information);
+ sizeof (struct ConnectInfoMessage) +
+ ats_count * sizeof (struct GNUNET_ATS_Information);
char buf[size];
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
- cim = (struct ConnectInfoMessage*) buf;
+ cim = (struct ConnectInfoMessage *) buf;
cim->header.size = htons (size);
cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
cim->ats_count = htonl (ats_count);
cim->id = *peer;
ap = (struct GNUNET_ATS_Information *) &cim[1];
- memcpy (ap, ats,
- ats_count * sizeof (struct GNUNET_ATS_Information));
+ memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
unicast (tc, &cim->header, GNUNET_NO);
}
}
start = (const struct StartMessage *) message;
options = ntohl (start->options);
- if ((0 != (1 & options) ) &&
+ if ((0 != (1 & options)) &&
(0 !=
memcmp (&start->self, &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity))))
+ sizeof (struct GNUNET_PeerIdentity))))
{
/* client thinks this is a different peer, reject */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
*/
static void
output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count,
- const char * transport,
- const void * addr,
- size_t addrlen)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
+ const char *transport, const void *addr, size_t addrlen)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
- struct AddressIterateResponseMessage * msg;
+ struct AddressIterateResponseMessage *msg;
size_t size;
size =
- (sizeof (struct AddressIterateResponseMessage) + strlen(transport) + 1);
+ (sizeof (struct AddressIterateResponseMessage) + strlen (transport) + 1);
msg = GNUNET_malloc (size);
memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity));
- memcpy (&msg[0], transport, strlen(transport)+1);
+ memcpy (&msg[0], transport, strlen (transport) + 1);
msg->addrlen = ntohs (addrlen);
- msg->pluginlen = ntohs (strlen(transport)+1);
+ msg->pluginlen = ntohs (strlen (transport) + 1);
transmit_binary_to_client (tc, msg, size);
- GNUNET_free(msg);
+ GNUNET_free (msg);
}
for (tc = clients_head; tc != NULL; tc = tc->next)
{
- if ( (GNUNET_YES == may_drop) &&
- (GNUNET_YES != tc->send_payload) )
- continue; /* skip, this client does not care about payload */
+ if ((GNUNET_YES == may_drop) && (GNUNET_YES != tc->send_payload))
+ continue; /* skip, this client does not care about payload */
unicast (tc, msg, may_drop);
}
}
hello_task = GNUNET_SCHEDULER_NO_TASK;
gc.addr_pos = oal_head;
gc.expiration =
- GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION);
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION);
GNUNET_free (our_hello);
our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc);
#if DEBUG_TRANSPORT
* Public key of the sender.
*/
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
-
+
/**
* Signature of the peer that sends us the disconnect. Only
* valid if the timestamp is AFTER the timestamp from the
enum State
{
- /* fresh peer or completely disconnected */
- S_NOT_CONNECTED = 0,
- /* sent CONNECT message to other peer, waiting for CONNECT_ACK */
- S_CONNECT_SENT = 1,
- /* received CONNECT message to other peer, sending CONNECT_ACK */
- S_CONNECT_RECV = 4,
- /* sent CONNECT_ACK message to other peer, wait for ACK or payload */
- S_CONNECT_RECV_ACK_SENT = 8,
- /* received ACK or payload */
- S_CONNECTED = 16,
- /* Disconnect in progress */
- S_DISCONNECT = 32
+ /* fresh peer or completely disconnected */
+ S_NOT_CONNECTED = 0,
+ /* sent CONNECT message to other peer, waiting for CONNECT_ACK */
+ S_CONNECT_SENT = 1,
+ /* received CONNECT message to other peer, sending CONNECT_ACK */
+ S_CONNECT_RECV = 4,
+ /* sent CONNECT_ACK message to other peer, wait for ACK or payload */
+ S_CONNECT_RECV_ACK_SENT = 8,
+ /* received ACK or payload */
+ S_CONNECTED = 16,
+ /* Disconnect in progress */
+ S_DISCONNECT = 32
};
/**
#define change_state(n, state, ...) change (n, state, __LINE__)
static int
-is_connecting (struct NeighbourMapEntry * n)
+is_connecting (struct NeighbourMapEntry *n)
{
if ((n->state > S_NOT_CONNECTED) && (n->state < S_CONNECTED))
return GNUNET_YES;
}
static int
-is_connected (struct NeighbourMapEntry * n)
+is_connected (struct NeighbourMapEntry *n)
{
if (n->state == S_CONNECTED)
return GNUNET_YES;
}
static int
-is_disconnecting (struct NeighbourMapEntry * n)
+is_disconnecting (struct NeighbourMapEntry *n)
{
if (n->state == S_DISCONNECT)
return GNUNET_YES;
static const char *
print_state (int state)
{
- switch (state) {
- case S_CONNECTED:
- return "S_CONNECTED";
- break;
- case S_CONNECT_RECV:
- return "S_CONNECT_RECV";
- break;
- case S_CONNECT_RECV_ACK_SENT:
- return"S_CONNECT_RECV_ACK_SENT";
- break;
- case S_CONNECT_SENT:
- return "S_CONNECT_SENT";
- break;
- case S_DISCONNECT:
- return "S_DISCONNECT";
- break;
- case S_NOT_CONNECTED:
- return "S_NOT_CONNECTED";
- break;
- default:
- GNUNET_break (0);
- break;
+ switch (state)
+ {
+ case S_CONNECTED:
+ return "S_CONNECTED";
+ break;
+ case S_CONNECT_RECV:
+ return "S_CONNECT_RECV";
+ break;
+ case S_CONNECT_RECV_ACK_SENT:
+ return "S_CONNECT_RECV_ACK_SENT";
+ break;
+ case S_CONNECT_SENT:
+ return "S_CONNECT_SENT";
+ break;
+ case S_DISCONNECT:
+ return "S_DISCONNECT";
+ break;
+ case S_NOT_CONNECTED:
+ return "S_NOT_CONNECTED";
+ break;
+ default:
+ GNUNET_break (0);
+ break;
}
return NULL;
}
static int
-change (struct NeighbourMapEntry * n, int state, int line);
+change (struct NeighbourMapEntry *n, int state, int line);
static void
-ats_suggest_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
-reset_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct NeighbourMapEntry * n = cls;
+ struct NeighbourMapEntry *n = cls;
n->state_reset = GNUNET_SCHEDULER_NO_TASK;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n",
- GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state));
+ "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n",
+ GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, n->addr,
+ n->addrlen),
+ print_state (n->state));
#endif
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# failed connection attempts due to timeout"),
- 1,
+ gettext_noop
+ ("# failed connection attempts due to timeout"), 1,
GNUNET_NO);
/* resetting state */
n->state = S_NOT_CONNECTED;
/* destroying address */
- GNUNET_ATS_address_destroyed (GST_ats,
- &n->id,
- n->plugin_name,
- n->addr,
- n->addrlen,
- NULL);
+ GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
+ n->addrlen, NULL);
/* request new address */
if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(n->ats_suggest);
- n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n);
- GNUNET_ATS_suggest_address(GST_ats, &n->id);
+ GNUNET_SCHEDULER_cancel (n->ats_suggest);
+ n->ats_suggest =
+ GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
+ n);
+ GNUNET_ATS_suggest_address (GST_ats, &n->id);
}
static int
-change (struct NeighbourMapEntry * n, int state, int line)
+change (struct NeighbourMapEntry *n, int state, int line)
{
- char * old = strdup(print_state(n->state));
- char * new = strdup(print_state(state));
+ char *old = strdup (print_state (n->state));
+ char *new = strdup (print_state (state));
/* allowed transitions */
int allowed = GNUNET_NO;
- switch (n->state) {
+
+ switch (n->state)
+ {
case S_NOT_CONNECTED:
if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) ||
(state == S_DISCONNECT))
allowed = GNUNET_YES;
/* Schedule reset task */
- if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) )
+ if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT))
{
GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK);
- n->state_reset = GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, n);
+ n->state_reset =
+ GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task,
+ n);
}
break;
break;
case S_CONNECT_RECV:
if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) ||
- (state == S_CONNECTED) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_SENT))
+ (state == S_CONNECTED) ||
+ /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_SENT))
{
- if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED))
+ if ((state == S_CONNECTED) || (state == S_DISCONNECT) ||
+ (state == S_NOT_CONNECTED))
{
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
- GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state));
+ "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
+ GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name,
+ n->addr, n->addrlen),
+ print_state (n->state), print_state (state));
#endif
GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
GNUNET_SCHEDULER_cancel (n->state_reset);
break;
case S_CONNECT_SENT:
if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) ||
- (state == S_DISCONNECT) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_RECV))
+ (state == S_DISCONNECT) ||
+ /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_RECV))
{
- if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED))
+ if ((state == S_CONNECTED) || (state == S_DISCONNECT) ||
+ (state == S_NOT_CONNECTED))
{
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
- GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state));
+ "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
+ GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name,
+ n->addr, n->addrlen),
+ print_state (n->state), print_state (state));
#endif
GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
GNUNET_SCHEDULER_cancel (n->state_reset);
break;
case S_DISCONNECT:
/*
- if (state == S_NOT_CONNECTED)
- {
- allowed = GNUNET_YES;
- break;
- }*/
+ * if (state == S_NOT_CONNECTED)
+ * {
+ * allowed = GNUNET_YES;
+ * break;
+ * } */
break;
default:
GNUNET_break (0);
if (allowed == GNUNET_NO)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Illegal state transition from `%s' to `%s' in line %u \n",
- old, new, line);
+ "Illegal state transition from `%s' to `%s' in line %u \n", old,
+ new, line);
GNUNET_break (0);
GNUNET_free (old);
GNUNET_free (new);
n->state = state;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n",
- GNUNET_i2s (&n->id), n, old, new, line);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n",
+ GNUNET_i2s (&n->id), n, old, new, line);
#endif
GNUNET_free (old);
GNUNET_free (new);
}
static ssize_t
-send_with_plugin ( const struct GNUNET_PeerIdentity * target,
- const char *msgbuf,
- size_t msgbuf_size,
- uint32_t priority,
- struct GNUNET_TIME_Relative timeout,
- struct Session * session,
- const char * plugin_name,
- const void *addr,
- size_t addrlen,
- int force_address,
- GNUNET_TRANSPORT_TransmitContinuation cont,
- void *cont_cls)
-
+send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
+ size_t msgbuf_size, uint32_t priority,
+ struct GNUNET_TIME_Relative timeout, struct Session *session,
+ const char *plugin_name, const void *addr, size_t addrlen,
+ int force_address, GNUNET_TRANSPORT_TransmitContinuation cont,
+ void *cont_cls)
{
struct GNUNET_TRANSPORT_PluginFunctions *papi;
size_t ret = GNUNET_SYSERR;
return GNUNET_SYSERR;
}
- ret = papi->send (papi->cls,
- target,
- msgbuf, msgbuf_size,
- 0,
- timeout,
- session,
- addr, addrlen,
- GNUNET_YES,
- cont, cont_cls);
+ ret =
+ papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session,
+ addr, addrlen, GNUNET_YES, cont, cont_cls);
if (ret == -1)
{
n->is_active = mq;
mq->n = n;
- if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0))
+ if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n",
GNUNET_i2s (&n->id));
return;
}
- ret = send_with_plugin (&n->id,
- mq->message_buf, mq->message_buf_size, 0,
- timeout,
- n->session, n->plugin_name, n->addr, n->addrlen,
- GNUNET_YES,
- &transmit_send_continuation, mq);
+ ret =
+ send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0,
+ timeout, n->session, n->plugin_name, n->addr,
+ n->addrlen, GNUNET_YES, &transmit_send_continuation,
+ mq);
if (ret == -1)
{
/* failure, but 'send' would not call continuation in this case,
transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighbourMapEntry *n = cls;
- GNUNET_assert (NULL != lookup_neighbour(&n->id));
+
+ GNUNET_assert (NULL != lookup_neighbour (&n->id));
n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
try_transmission_to_peer (n);
}
static void
-send_disconnect_cont (void *cls,
- const struct GNUNET_PeerIdentity * target,
- int result)
+send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target,
+ int result)
{
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s': %i\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending DISCONNECT message to peer `%4s': %i\n",
GNUNET_i2s (target), result);
#endif
}
static int
-send_disconnect (const struct GNUNET_PeerIdentity * target,
- const char *plugin_name,
- const char *sender_address, uint16_t sender_address_len,
- struct Session *session)
+send_disconnect (const struct GNUNET_PeerIdentity *target,
+ const char *plugin_name, const char *sender_address,
+ uint16_t sender_address_len, struct Session *session)
{
size_t ret;
struct SessionDisconnectMessage disconnect_msg;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending DISCONNECT message to peer `%4s'\n",
GNUNET_i2s (target));
#endif
disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
disconnect_msg.reserved = htonl (0);
- disconnect_msg.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
- sizeof (struct GNUNET_TIME_AbsoluteNBO) );
- disconnect_msg.purpose.purpose = htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
- disconnect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
+ disconnect_msg.purpose.size =
+ htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
+ sizeof (struct GNUNET_TIME_AbsoluteNBO));
+ disconnect_msg.purpose.purpose =
+ htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
+ disconnect_msg.timestamp =
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
disconnect_msg.public_key = GST_my_public_key;
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
&disconnect_msg.purpose,
&disconnect_msg.signature));
- ret = send_with_plugin(target,
- (const char *) &disconnect_msg, sizeof (disconnect_msg),
- UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
- session, plugin_name, sender_address, sender_address_len,
- GNUNET_YES, &send_disconnect_cont, NULL);
+ ret =
+ send_with_plugin (target, (const char *) &disconnect_msg,
+ sizeof (disconnect_msg), UINT32_MAX,
+ GNUNET_TIME_UNIT_FOREVER_REL, session, plugin_name,
+ sender_address, sender_address_len, GNUNET_YES,
+ &send_disconnect_cont, NULL);
if (ret == GNUNET_SYSERR)
return GNUNET_SYSERR;
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# peers disconnected due to external request"), 1,
+ gettext_noop
+ ("# peers disconnected due to external request"), 1,
GNUNET_NO);
return GNUNET_OK;
}
disconnect_neighbour (struct NeighbourMapEntry *n)
{
struct MessageQueue *mq;
- int was_connected = is_connected(n);
+ int was_connected = is_connected (n);
/* send DISCONNECT MESSAGE */
- if (is_connected(n) || is_connecting(n))
+ if (is_connected (n) || is_connecting (n))
{
- if (GNUNET_OK == send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session))
+ if (GNUNET_OK ==
+ send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen,
+ n->session))
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n",
GNUNET_i2s (&n->id));
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send DISCONNECT_MSG to `%s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not send DISCONNECT_MSG to `%s'\n",
GNUNET_i2s (&n->id));
}
- if (is_disconnecting(n))
+ if (is_disconnecting (n))
return;
change_state (n, S_DISCONNECT);
{
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task);
GNUNET_SCHEDULER_cancel (n->keepalive_task);
- n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
+ n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (neighbours_connected > 0);
neighbours_connected--;
GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1,
n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# peers disconnected due to timeout"), 1,
+ gettext_noop
+ ("# peers disconnected due to timeout"), 1,
GNUNET_NO);
disconnect_neighbour (n);
}
*/
static void
neighbour_keepalive_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighbourMapEntry *n = cls;
struct GNUNET_MessageHeader m;
- n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
- &neighbour_keepalive_task,
- n);
- GNUNET_assert (is_connected(n));
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# keepalives sent"), 1,
- GNUNET_NO);
+ n->keepalive_task =
+ GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
+ &neighbour_keepalive_task, n);
+ GNUNET_assert (is_connected (n));
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1,
+ GNUNET_NO);
m.size = htons (sizeof (struct GNUNET_MessageHeader));
m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
- send_with_plugin(&n->id, (const void *) &m,
- sizeof (m),
- UINT32_MAX /* priority */ ,
- GNUNET_TIME_UNIT_FOREVER_REL,
- n->session, n->plugin_name, n->addr, n->addrlen,
- GNUNET_YES, NULL, NULL);
+ send_with_plugin (&n->id, (const void *) &m, sizeof (m),
+ UINT32_MAX /* priority */ ,
+ GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name,
+ n->addr, n->addrlen, GNUNET_YES, NULL, NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
#endif
- if (is_connected(n))
+ if (is_connected (n))
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# peers disconnected due to global disconnect"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# peers disconnected due to global disconnect"),
+ 1, GNUNET_NO);
disconnect_neighbour (n);
return GNUNET_OK;
}
static void
-ats_suggest_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct NeighbourMapEntry *n = cls;
" ATS did not suggested address to connect to peer `%s'\n",
GNUNET_i2s (&n->id));
- disconnect_neighbour(n);
+ disconnect_neighbour (n);
}
/**
* @param success GNUNET_OK on success
*/
static void
-send_connect_continuation (void *cls,
- const struct GNUNET_PeerIdentity * target,
- int success)
-
+send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
+ int success)
{
struct NeighbourMapEntry *n = cls;
GNUNET_assert (n != NULL);
- GNUNET_assert (!is_connected(n));
+ GNUNET_assert (!is_connected (n));
- if (is_disconnecting(n))
- return; /* neighbour is going away */
+ if (is_disconnecting (n))
+ return; /* neighbour is going away */
if (GNUNET_YES != success)
{
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
- GNUNET_i2s (&n->id), n->plugin_name,
- (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
- n->addr,
- n->addrlen),
- n->session);
+ "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
+ GNUNET_i2s (&n->id), n->plugin_name,
+ (n->addrlen ==
+ 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
+ n->addrlen), n->session);
#endif
- GNUNET_ATS_address_destroyed (GST_ats,
- &n->id,
- n->plugin_name,
- n->addr,
- n->addrlen,
- NULL);
+ GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
+ n->addrlen, NULL);
- change_state(n, S_NOT_CONNECTED);
+ change_state (n, S_NOT_CONNECTED);
- if (n->ats_suggest!= GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(n->ats_suggest);
- n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n);
- GNUNET_ATS_suggest_address(GST_ats, &n->id);
+ if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->ats_suggest);
+ n->ats_suggest =
+ GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
+ n);
+ GNUNET_ATS_suggest_address (GST_ats, &n->id);
return;
}
*/
static void
send_switch_address_continuation (void *cls,
- const struct GNUNET_PeerIdentity * target,
- int success)
-
+ const struct GNUNET_PeerIdentity *target,
+ int success)
{
struct NeighbourMapEntry *n = cls;
GNUNET_assert (n != NULL);
- if (is_disconnecting(n))
- return; /* neighbour is going away */
+ if (is_disconnecting (n))
+ return; /* neighbour is going away */
GNUNET_assert (n->state == S_CONNECTED);
if (GNUNET_YES != success)
{
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n",
- GNUNET_i2s (&n->id), n->plugin_name,
- (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
- n->addr,
- n->addrlen),
- n->session);
+ "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n",
+ GNUNET_i2s (&n->id), n->plugin_name,
+ (n->addrlen ==
+ 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
+ n->addrlen), n->session);
#endif
- GNUNET_ATS_address_destroyed (GST_ats,
- &n->id,
- n->plugin_name,
- n->addr,
- n->addrlen,
- NULL);
+ GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
+ n->addrlen, NULL);
if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(n->ats_suggest);
- n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n);
- GNUNET_ATS_suggest_address(GST_ats, &n->id);
+ GNUNET_SCHEDULER_cancel (n->ats_suggest);
+ n->ats_suggest =
+ GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
+ n);
+ GNUNET_ATS_suggest_address (GST_ats, &n->id);
return;
}
}
*/
static void
send_connect_ack_continuation (void *cls,
- const struct GNUNET_PeerIdentity * target,
- int success)
-
+ const struct GNUNET_PeerIdentity *target,
+ int success)
{
struct NeighbourMapEntry *n = cls;
GNUNET_assert (n != NULL);
if (GNUNET_YES == success)
- return; /* sending successful */
+ return; /* sending successful */
/* sending failed, ask for next address */
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
GNUNET_i2s (&n->id), n->plugin_name,
(n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
- n->addr,
- n->addrlen),
+ n->addr,
+ n->addrlen),
n->session);
#endif
- change_state(n, S_NOT_CONNECTED);
+ change_state (n, S_NOT_CONNECTED);
- GNUNET_ATS_address_destroyed (GST_ats,
- &n->id,
- n->plugin_name,
- n->addr,
- n->addrlen,
- NULL);
+ GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
+ n->addrlen, NULL);
- if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(n->ats_suggest);
- n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n);
- GNUNET_ATS_suggest_address(GST_ats, &n->id);
+ if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->ats_suggest);
+ n->ats_suggest =
+ GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
+ n);
+ GNUNET_ATS_suggest_address (GST_ats, &n->id);
}
/**
*/
int
GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name, const void *address,
- size_t address_len, struct Session *session,
- const struct GNUNET_ATS_Information
- *ats, uint32_t ats_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
+ const char *plugin_name,
+ const void *address, size_t address_len,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out)
{
struct NeighbourMapEntry *n;
struct SessionConnectMessage connect_msg;
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"ATS offered suggested us empty address: plugin NULL");
- GNUNET_break_op(0);
+ GNUNET_break_op (0);
checks_failed = GNUNET_YES;
}
- if ((address == NULL) && (address_len == 0 ) && (session == NULL))
+ if ((address == NULL) && (address_len == 0) && (session == NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"ATS offered suggested us empty address: address NULL & session NULL");
- GNUNET_break_op(0);
+ GNUNET_break_op (0);
checks_failed = GNUNET_YES;
}
if (checks_failed == GNUNET_YES)
{
- GNUNET_ATS_address_destroyed (GST_ats,
- peer,
- plugin_name, address,
- address_len, session);
+ GNUNET_ATS_address_destroyed (GST_ats, peer, plugin_name, address,
+ address_len, session);
if (n != NULL)
- GNUNET_ATS_suggest_address(GST_ats, peer);
+ GNUNET_ATS_suggest_address (GST_ats, peer);
return GNUNET_NO;
}
(address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name,
address,
address_len),
- session, (is_connected(n) ? "CONNECTED" : "NOT CONNECTED"),
+ session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"),
GNUNET_i2s (peer));
#endif
if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(n->ats_suggest);
+ GNUNET_SCHEDULER_cancel (n->ats_suggest);
n->ats_suggest = GNUNET_SCHEDULER_NO_TASK;
}
// do not switch addresses just update quotas
- if ((is_connected(n)) && (address_len == n->addrlen))
+ if ((is_connected (n)) && (address_len == n->addrlen))
{
if ((0 == memcmp (address, n->addr, address_len)) &&
(n->session == session))
struct QuotaSetMessage q_msg;
#if DEBUG_TRANSPORT
-GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n",
- ntohl (n->bandwidth_out.value__),
- ntohl (n->bandwidth_in.value__),
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n",
+ ntohl (n->bandwidth_out.value__),
+ ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer));
#endif
n->bandwidth_in = bandwidth_in;
n->bandwidth_out = bandwidth_out;
- GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in);
+ GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
change_state (n, S_CONNECT_SENT);
- ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
- session, plugin_name, address, address_len,
- GNUNET_YES, &send_connect_continuation, n);
+ ret =
+ send_with_plugin (peer, (const char *) &connect_msg, msg_len,
+ UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
+ plugin_name, address, address_len, GNUNET_YES,
+ &send_connect_continuation, n);
return GNUNET_NO;
}
msg_len = sizeof (struct SessionConnectMessage);
connect_msg.header.size = htons (msg_len);
connect_msg.header.type =
- htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK);
+ htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK);
connect_msg.reserved = htonl (0);
- connect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
+ connect_msg.timestamp =
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
- ret = send_with_plugin(&n->id, (const void *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
- session, plugin_name, address, address_len,
- GNUNET_YES, &send_connect_ack_continuation, n);
+ ret =
+ send_with_plugin (&n->id, (const void *) &connect_msg, msg_len,
+ UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
+ plugin_name, address, address_len, GNUNET_YES,
+ &send_connect_ack_continuation, n);
return GNUNET_NO;
}
/* connected peer is switching addresses */
connect_msg.timestamp =
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
- ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
- session, plugin_name, address, address_len,
- GNUNET_YES, &send_switch_address_continuation, n);
+ ret =
+ send_with_plugin (peer, (const char *) &connect_msg, msg_len,
+ UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
+ plugin_name, address, address_len, GNUNET_YES,
+ &send_switch_address_continuation, n);
if (ret == GNUNET_SYSERR)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n",
- GNUNET_i2s (peer), plugin_name,
- (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name,
- address,
- address_len),
- session);
+ "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n",
+ GNUNET_i2s (peer), plugin_name,
+ (address_len ==
+ 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, address,
+ address_len), session);
}
return GNUNET_NO;
}
else if (n->state == S_CONNECT_SENT)
{
- return GNUNET_NO;
+ return GNUNET_NO;
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid connection state to switch addresses %u \n", n->state);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid connection state to switch addresses %u \n", n->state);
GNUNET_break_op (0);
return GNUNET_NO;
}
/**
* Create an entry in the neighbour map for the given peer
- *
+ *
* @param peer peer to create an entry for
* @return new neighbour map entry
*/
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Unknown peer `%s', creating new neighbour\n",
- GNUNET_i2s (peer));
+ "Unknown peer `%s', creating new neighbour\n", GNUNET_i2s (peer));
#endif
n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
n->id = *peer;
n->state = S_NOT_CONNECTED;
GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
- GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
- MAX_BANDWIDTH_CARRY_S);
+ GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
+ MAX_BANDWIDTH_CARRY_S);
n->timeout_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &neighbour_timeout_task, n);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &neighbour_timeout_task, n);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (neighbours,
- &n->id.hashPubKey, n,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (neighbours,
+ &n->id.hashPubKey, n,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return n;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n",
GNUNET_i2s (target));
#endif
- if (0 == memcmp (target, &GST_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 ==
+ memcmp (target, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
{
/* my own hello */
return;
if (NULL != n)
{
- if ((is_connected(n)) || (is_connecting(n)))
- return; /* already connecting or connected */
- if (is_disconnecting(n))
+ if ((is_connected (n)) || (is_connecting (n)))
+ return; /* already connecting or connected */
+ if (is_disconnecting (n))
change_state (n, S_NOT_CONNECTED);
}
GNUNET_i2s (&n->id));
#endif
- GNUNET_ATS_suggest_address (GST_ats, &n->id);
+ GNUNET_ATS_suggest_address (GST_ats, &n->id);
}
/**
n = lookup_neighbour (target);
- if ((NULL == n) || (!is_connected(n)))
+ if ((NULL == n) || (!is_connected (n)))
return GNUNET_NO; /* not connected */
return GNUNET_YES;
}
}
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %X to peer `%s' ended \n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n",
session, GNUNET_i2s (peer));
#endif
n->addrlen = 0;
/* not connected anymore anyway, shouldn't matter */
- if ((!is_connected(n)) && (!is_connecting(n)))
+ if ((!is_connected (n)) && (!is_connecting (n)))
return;
/* We are connected, so ask ATS to switch addresses */
&neighbour_timeout_task, n);
/* try QUICKLY to re-establish a connection, reduce timeout! */
if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(n->ats_suggest);
- n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n);
+ GNUNET_SCHEDULER_cancel (n->ats_suggest);
+ n->ats_suggest =
+ GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
+ n);
GNUNET_ATS_suggest_address (GST_ats, peer);
}
}
n = lookup_neighbour (target);
- if ((n == NULL) || (!is_connected(n)))
+ if ((n == NULL) || (!is_connected (n)))
{
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Could not send message to peer `%s': unknown neighbour",
GNUNET_i2s (target));
- else if (!is_connected(n))
+ else if (!is_connected (n))
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Could not send message to peer `%s': not connected\n",
GNUNET_i2s (target));
return;
}
- if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen ==0))
+ if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0))
{
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
("# messages not sent (no such peer or not connected)"),
1, GNUNET_NO);
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not send message to peer `%s': no address available\n",
- GNUNET_i2s (target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not send message to peer `%s': no address available\n",
+ GNUNET_i2s (target));
#endif
if (NULL != cont)
if (NULL == n)
{
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop
- ("# messages discarded due to lack of neighbour record"),
- 1, GNUNET_NO);
+ gettext_noop
+ ("# messages discarded due to lack of neighbour record"),
+ 1, GNUNET_NO);
*do_forward = GNUNET_NO;
return GNUNET_TIME_UNIT_ZERO;
}
}
- if (!is_connected(n))
+ if (!is_connected (n))
{
*do_forward = GNUNET_SYSERR;
return GNUNET_TIME_UNIT_ZERO;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n",
GNUNET_i2s (&n->id), "SET_QUOTA");
#endif
- if (is_connected(n))
+ if (is_connected (n))
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# disconnects due to quota of 0"), 1,
- GNUNET_NO);
+ gettext_noop ("# disconnects due to quota of 0"),
+ 1, GNUNET_NO);
disconnect_neighbour (n);
}
struct IteratorContext *ic = cls;
struct NeighbourMapEntry *n = value;
- if (!is_connected(n))
+ if (!is_connected (n))
return GNUNET_OK;
ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen);
n = lookup_neighbour (target);
if (NULL == n)
return; /* not active */
- if (is_connected(n))
+ if (is_connected (n))
{
- send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session);
+ send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, n->session);
n = lookup_neighbour (target);
if (NULL == n)
- return; /* gone already */
+ return; /* gone already */
}
disconnect_neighbour (n);
}
/**
* We received a disconnect message from the given peer,
* validate and process.
- *
+ *
* @param peer sender of the message
* @param msg the disconnect message
*/
void
-GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *msg)
+GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
+ *peer,
+ const struct GNUNET_MessageHeader
+ *msg)
{
struct NeighbourMapEntry *n;
const struct SessionDisconnectMessage *sdm;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received DISCONNECT message from peer `%s'\n", GNUNET_i2s (peer));
+ "Received DISCONNECT message from peer `%s'\n",
+ GNUNET_i2s (peer));
#endif
if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage))
{
// GNUNET_break_op (0);
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# disconnect messages ignored (old format)"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# disconnect messages ignored (old format)"), 1,
+ GNUNET_NO);
return;
}
- sdm = (const struct SessionDisconnectMessage* ) msg;
+ sdm = (const struct SessionDisconnectMessage *) msg;
n = lookup_neighbour (peer);
if (NULL == n)
return; /* gone already */
n->connect_ts.abs_value)
{
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# disconnect messages ignored (timestamp)"), 1,
- GNUNET_NO);
+ gettext_noop
+ ("# disconnect messages ignored (timestamp)"), 1,
+ GNUNET_NO);
return;
}
GNUNET_CRYPTO_hash (&sdm->public_key,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &hc);
- if (0 != memcmp (peer,
- &hc,
- sizeof (struct GNUNET_PeerIdentity)))
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &hc);
+ if (0 != memcmp (peer, &hc, sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break_op (0);
return;
}
- if (ntohl (sdm->purpose.size) !=
+ if (ntohl (sdm->purpose.size) !=
sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
sizeof (struct GNUNET_TIME_AbsoluteNBO))
return;
}
if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT,
- &sdm->purpose,
- &sdm->signature,
- &sdm->public_key))
+ GNUNET_CRYPTO_rsa_verify
+ (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, &sdm->purpose,
+ &sdm->signature, &sdm->public_key))
{
GNUNET_break_op (0);
return;
*/
void
GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const char *sender_address, uint16_t sender_address_len,
- struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ const char *sender_address,
+ uint16_t sender_address_len,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count)
{
const struct SessionConnectMessage *scm;
struct QuotaSetMessage q_msg;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received CONNECT_ACK message from peer `%s'\n", GNUNET_i2s (peer));
+ "Received CONNECT_ACK message from peer `%s'\n",
+ GNUNET_i2s (peer));
#endif
if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"transport-ats",
"Giving ATS session %p of plugin %s for peer %s\n",
- session,
- plugin_name,
- GNUNET_i2s (peer));
- GNUNET_ATS_address_update (GST_ats,
- peer,
- plugin_name, sender_address, sender_address_len,
- session, ats, ats_count);
-
- was_connected = is_connected(n);
- if (!is_connected(n))
+ session, plugin_name, GNUNET_i2s (peer));
+ GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
+ sender_address_len, session, ats, ats_count);
+
+ was_connected = is_connected (n);
+ if (!is_connected (n))
change_state (n, S_CONNECTED);
- GNUNET_ATS_address_in_use (GST_ats,
- peer,
- plugin_name,
- sender_address,
- sender_address_len,
- session,
- GNUNET_YES);
+ GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address,
+ sender_address_len, session, GNUNET_YES);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Setting inbound quota of %u for peer `%s' to \n",
ntohl (n->bandwidth_in.value__), GNUNET_i2s (&n->id));
#endif
- GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in);
+ GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
- /* send ACK (ACK)*/
- msg_len = sizeof (msg);
+ /* send ACK (ACK) */
+ msg_len = sizeof (msg);
msg.size = htons (msg_len);
msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
- ret = send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX,
- GNUNET_TIME_UNIT_FOREVER_REL,
- n->session, n->plugin_name, n->addr, n->addrlen,
- GNUNET_YES, NULL, NULL);
+ ret =
+ send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX,
+ GNUNET_TIME_UNIT_FOREVER_REL, n->session,
+ n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL,
+ NULL);
if (ret == GNUNET_SYSERR)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n",
- GNUNET_i2s (&n->id), n->plugin_name,
- (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
- n->addr,
- n->addrlen),
- n->session);
+ "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n",
+ GNUNET_i2s (&n->id), n->plugin_name,
+ (n->addrlen ==
+ 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
+ n->addrlen), n->session);
if (!was_connected)
{
if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
- n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
- &neighbour_keepalive_task,
- n);
+ n->keepalive_task =
+ GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
+ &neighbour_keepalive_task, n);
neighbours_connected++;
GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
GNUNET_NO);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
- GNUNET_i2s (&n->id), n->plugin_name,
- (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
- n->addr,
- n->addrlen),
- n->session, __LINE__);
+ "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
+ GNUNET_i2s (&n->id), n->plugin_name,
+ (n->addrlen ==
+ 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
+ n->addrlen), n->session,
+ __LINE__);
#endif
connect_notify_cb (callback_cls, &n->id, ats, ats_count);
}
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
- ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
+ ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer));
#endif
- q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
- q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
- q_msg.quota = n->bandwidth_out;
- q_msg.peer = (*peer);
- GST_clients_broadcast (&q_msg.header, GNUNET_NO);
+ q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
+ q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
+ q_msg.quota = n->bandwidth_out;
+ q_msg.peer = (*peer);
+ GST_clients_broadcast (&q_msg.header, GNUNET_NO);
}
void
GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const char *sender_address, uint16_t sender_address_len,
- struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const char *sender_address,
+ uint16_t sender_address_len, struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count)
{
struct NeighbourMapEntry *n;
struct QuotaSetMessage q_msg;
int was_connected;
#if DEBUG_TRANSPORT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received ACK message from peer `%s'\n", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ACK message from peer `%s'\n",
+ GNUNET_i2s (peer));
#endif
if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
n = lookup_neighbour (peer);
if (NULL == n)
{
- send_disconnect(peer, plugin_name, sender_address, sender_address_len, session);
+ send_disconnect (peer, plugin_name, sender_address, sender_address_len,
+ session);
GNUNET_break (0);
return;
}
- if (is_connected(n))
+ if (is_connected (n))
return;
if (NULL != session)
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"transport-ats",
"Giving ATS session %p of plugin %s for peer %s\n",
- session,
- plugin_name,
- GNUNET_i2s (peer));
- GNUNET_ATS_address_update (GST_ats,
- peer,
- plugin_name, sender_address, sender_address_len,
- session, ats, ats_count);
-
- was_connected = is_connected(n);
+ session, plugin_name, GNUNET_i2s (peer));
+ GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
+ sender_address_len, session, ats, ats_count);
+
+ was_connected = is_connected (n);
change_state (n, S_CONNECTED);
- GNUNET_ATS_address_in_use (GST_ats,
- peer,
- plugin_name,
- sender_address,
- sender_address_len,
- session,
- GNUNET_YES);
+ GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address,
+ sender_address_len, session, GNUNET_YES);
- GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in);
+ GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
- n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
- &neighbour_keepalive_task,
- n);
+ n->keepalive_task =
+ GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
+ &neighbour_keepalive_task, n);
if (!was_connected)
{
- neighbours_connected++;
- GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
- GNUNET_NO);
+ neighbours_connected++;
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
+ GNUNET_NO);
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
- GNUNET_i2s (&n->id), n->plugin_name,
- (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
- n->addr,
- n->addrlen),
- n->session, __LINE__);
+ "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
+ GNUNET_i2s (&n->id), n->plugin_name,
+ (n->addrlen ==
+ 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
+ n->addrlen), n->session,
+ __LINE__);
#endif
- connect_notify_cb (callback_cls, &n->id, ats, ats_count);
+ connect_notify_cb (callback_cls, &n->id, ats, ats_count);
}
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static void
handle_connect_blacklist_cont (void *cls,
- const struct GNUNET_PeerIdentity
- * peer, int result)
+ const struct GNUNET_PeerIdentity *peer,
+ int result)
{
struct NeighbourMapEntry *n;
- struct BlackListCheckContext * bcc = cls;
+ struct BlackListCheckContext *bcc = cls;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist check due to CONNECT message: `%s'\n", GNUNET_i2s (peer), (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN");
+ "Blacklist check due to CONNECT message: `%s'\n",
+ GNUNET_i2s (peer),
+ (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN");
#endif
/* not allowed */
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"transport-ats",
"Giving ATS session %p of plugin %s address `%s' for peer %s\n",
- bcc->session,
- bcc->plugin_name,
- GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, bcc->sender_address_len),
+ bcc->session, bcc->plugin_name,
+ GST_plugins_a2s (bcc->plugin_name, bcc->sender_address,
+ bcc->sender_address_len),
GNUNET_i2s (peer));
- GNUNET_ATS_address_update (GST_ats,
- peer,
- bcc->plugin_name, bcc->sender_address, bcc->sender_address_len,
+ GNUNET_ATS_address_update (GST_ats, peer, bcc->plugin_name,
+ bcc->sender_address, bcc->sender_address_len,
bcc->session, bcc->ats, bcc->ats_count);
n->connect_ts = bcc->ts;
}
GNUNET_free (bcc);
if (n->state != S_CONNECT_RECV)
- change_state (n, S_CONNECT_RECV);
+ change_state (n, S_CONNECT_RECV);
/* Ask ATS for an address to connect via that address */
if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(n->ats_suggest);
- n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n);
- GNUNET_ATS_suggest_address(GST_ats, peer);
+ GNUNET_SCHEDULER_cancel (n->ats_suggest);
+ n->ats_suggest =
+ GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
+ n);
+ GNUNET_ATS_suggest_address (GST_ats, peer);
}
/**
*/
void
GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const char *sender_address, uint16_t sender_address_len,
- struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ const char *sender_address,
+ uint16_t sender_address_len,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count)
{
const struct SessionConnectMessage *scm;
- struct NeighbourMapEntry * n;
- struct BlackListCheckContext * bcc = NULL;
+ struct NeighbourMapEntry *n;
+ struct BlackListCheckContext *bcc = NULL;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer));
+ "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer));
#endif
if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
scm = (const struct SessionConnectMessage *) message;
GNUNET_break_op (ntohl (scm->reserved) == 0);
- n = lookup_neighbour(peer);
+ n = lookup_neighbour (peer);
if (n != NULL)
{
/* connected peer switches addresses */
- if (is_connected(n))
+ if (is_connected (n))
{
- GNUNET_ATS_address_update(GST_ats, peer, plugin_name, sender_address, sender_address_len, session, ats, ats_count);
+ GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
+ sender_address_len, session, ats, ats_count);
return;
}
}
/* we are not connected to this peer */
- /* do blacklist check*/
- bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext) +
- sizeof (struct GNUNET_ATS_Information) * ats_count +
- sender_address_len +
- strlen (plugin_name)+1);
+ /* do blacklist check */
+ bcc =
+ GNUNET_malloc (sizeof (struct BlackListCheckContext) +
+ sizeof (struct GNUNET_ATS_Information) * ats_count +
+ sender_address_len + strlen (plugin_name) + 1);
bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
bcc->session = session;
bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1];
- memcpy (bcc->ats, ats,sizeof (struct GNUNET_ATS_Information) * ats_count );
+ memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count);
bcc->sender_address = (char *) &bcc->ats[ats_count];
- memcpy (bcc->sender_address, sender_address , sender_address_len);
+ memcpy (bcc->sender_address, sender_address, sender_address_len);
bcc->plugin_name = &bcc->sender_address[sender_address_len];
strcpy (bcc->plugin_name, plugin_name);
- GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont, bcc);
+ GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont,
+ bcc);
}
typedef void (*GST_NeighbourIterator) (void *cls,
const struct GNUNET_PeerIdentity *
neighbour,
- const struct
- GNUNET_ATS_Information * ats,
- uint32_t ats_count,
- const char * transport,
- const void * addr,
+ const struct GNUNET_ATS_Information *
+ ats, uint32_t ats_count,
+ const char *transport, const void *addr,
size_t addrlen);
GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
const char *plugin_name, const void *address,
size_t address_len, struct Session *session,
- const struct GNUNET_ATS_Information
- *ats, uint32_t ats_count);
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count);
int
GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name, const void *address,
- size_t address_len, struct Session *session,
- const struct GNUNET_ATS_Information
- *ats, uint32_t ats_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
+ const char *plugin_name,
+ const void *address, size_t address_len,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out);
/**
*/
void
GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const char *sender_address, uint16_t sender_address_len,
- struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count);
-
-void
-GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
const char *plugin_name,
- const char *sender_address, uint16_t sender_address_len,
+ const char *sender_address,
+ uint16_t sender_address_len,
struct Session *session,
const struct GNUNET_ATS_Information *ats,
uint32_t ats_count);
+void
+GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ const char *sender_address,
+ uint16_t sender_address_len,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count);
+
void
GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const char *sender_address, uint16_t sender_address_len,
- struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count);
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const char *sender_address,
+ uint16_t sender_address_len, struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count);
/**
* We received a disconnect message from the given peer,
* validate and process.
- *
+ *
* @param peer sender of the message
* @param msg the disconnect message
*/
void
-GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *msg);
+GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
+ *peer,
+ const struct GNUNET_MessageHeader
+ *msg);
#endif
}
ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
- GNUNET_ATS_address_update (GST_ats, &pid, tname, addr,
- addrlen, NULL, NULL, 0);
+ GNUNET_ATS_address_update (GST_ats, &pid, tname, addr, addrlen, NULL, NULL,
+ 0);
return GNUNET_OK;
}
sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_STATISTICS_update (GST_stats,
- gettext_noop ("# PING message for different peer received"), 1,
+ gettext_noop
+ ("# PING message for different peer received"), 1,
GNUNET_NO);
return;
}
{
addrend = memchr (addr, '\0', alen);
if (NULL == addrend)
- {
- GNUNET_break_op (0);
- return;
- }
+ {
+ GNUNET_break_op (0);
+ return;
+ }
addrend++;
slen = strlen (addr) + 1;
alen -= slen;
-
+
if (GNUNET_YES !=
- GST_hello_test_address (addr, addrend, alen, &sig_cache, &sig_cache_exp))
+ GST_hello_test_address (addr, addrend, alen, &sig_cache,
+ &sig_cache_exp))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
- GST_plugins_a2s (addr, addrend, alen));
+ _
+ ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
+ GST_plugins_a2s (addr, addrend, alen));
return;
}
- }
+ }
else
{
- addrend = NULL; /* make gcc happy */
+ addrend = NULL; /* make gcc happy */
slen = 0;
static struct GNUNET_CRYPTO_RsaSignature no_address_signature;
static struct GNUNET_TIME_Absolute no_address_signature_expiration;
ve->bc = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s\n",
- GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr, ve->addrlen));
+ GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr,
+ ve->addrlen));
slen = strlen (ve->transport_name) + 1;
hello = GST_hello_get ();
struct GNUNET_ATS_Information ats;
ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
- ats.value = htonl ((uint32_t) GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value);
- GNUNET_ATS_address_update (GST_ats, &ve->pid,
- ve->transport_name,ve->addr, ve->addrlen, NULL,
- &ats, 1);
+ ats.value =
+ htonl ((uint32_t)
+ GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value);
+ GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->transport_name, ve->addr,
+ ve->addrlen, NULL, &ats, 1);
}
-
+
/* build HELLO to store in PEERINFO */
ve->copied = GNUNET_NO;
hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve);
GNUNET_break (0);
return;
}
- if (0 == memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity)))
+ if (0 ==
+ memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity)))
return;
/* Add peer identity without addresses to peerinfo service */
h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL);
GNUNET_PEERINFO_add_peer (GST_peerinfo, h);
#if VERBOSE_VALIDATION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Adding `%s' without addresses for peer `%s'\n"),
- "HELLO",
- GNUNET_i2s(&vac.pid));
+ _("Adding `%s' without addresses for peer `%s'\n"), "HELLO",
+ GNUNET_i2s (&vac.pid));
#endif
GNUNET_free (h);
"Press <q> to quit or <1> to send from p1 to p2, <2> to send from p2 to p1, <enter> repeat\n");
read:
- t = getchar();
+ t = getchar ();
if (t == '1')
{
- th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, TIMEOUT,
- ¬ify_ready, p1);
+ th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0,
+ TIMEOUT, ¬ify_ready, p1);
return;
}
if (t == '2')
{
- th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, TIMEOUT,
- ¬ify_ready, p2);
+ th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0,
+ TIMEOUT, ¬ify_ready, p2);
return;
}
if (t == 'q')
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Exiting %c!\n", t);
- GNUNET_SCHEDULER_add_now(&end, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Exiting %c!\n", t);
+ GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
goto read;
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received message of type %d from peer %s!\n",
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Successfully received message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully received message\n");
send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
}
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
GNUNET_i2s (peer), cls);
6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100
};
- return ( (channel > 0) && (channel < sizeof(frequencies) / sizeof(int)) ) ? frequencies[channel] : -1;
+ return ((channel > 0) &&
+ (channel <
+ sizeof (frequencies) / sizeof (int))) ? frequencies[channel] : -1;
}
/**
{
if (GNUNET_YES != result)
{
- fprintf (stderr,
- "Configuration for plugin `%s' did not work!\n",
- tc->name);
+ fprintf (stderr, "Configuration for plugin `%s' did not work!\n", tc->name);
}
else
{
- fprintf (stderr,
- "Configuration for plugin `%s' is working!\n",
- tc->name);
+ fprintf (stderr, "Configuration for plugin `%s' is working!\n", tc->name);
}
if (GNUNET_SCHEDULER_NO_TASK != tc->tsk)
{
}
GNUNET_free (tc);
resolver_users--;
- if ( (0 == resolver_users) &&
- (NULL != resolver) )
+ if ((0 == resolver_users) && (NULL != resolver))
{
GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
GNUNET_OS_process_close (resolver);
struct TestContext *tc;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "transport",
- "plugins",
- &plugins))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
+ &plugins))
{
fprintf (stderr,
- _("No transport plugins configured, peer will never communicate\n"));
+ _
+ ("No transport plugins configured, peer will never communicate\n"));
ret = 4;
return;
}
for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " "))
- {
- char section[12+strlen(tok)];
-
- GNUNET_snprintf (section,
- sizeof (section),
- "transport-%s",
- tok);
+ {
+ char section[12 + strlen (tok)];
+
+ GNUNET_snprintf (section, sizeof (section), "transport-%s", tok);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT",
- &bnd_port))
- {
- fprintf (stderr,
- _("No port configured for plugin `%s', cannot test it\n"),
- tok);
- continue;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port))
+ {
+ fprintf (stderr,
+ _("No port configured for plugin `%s', cannot test it\n"), tok);
+ continue;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, section,
- "ADVERTISED_PORT", &adv_port))
+ GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT",
+ &adv_port))
adv_port = bnd_port;
if (NULL == resolver)
resolver =
- GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver",
- "gnunet-service-resolver", NULL);
+ GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver",
+ "gnunet-service-resolver", NULL);
resolver_users++;
GNUNET_RESOLVER_connect (cfg);
tc = GNUNET_malloc (sizeof (struct TestContext));
tc->name = GNUNET_strdup (tok);
tc->tst =
- GNUNET_NAT_test_start (cfg,
- (0 == strcasecmp (tok, "udp"))
- ? GNUNET_NO
- : GNUNET_YES,
- (uint16_t) bnd_port,
- (uint16_t) adv_port, &result_callback, tc);
+ GNUNET_NAT_test_start (cfg,
+ (0 ==
+ strcasecmp (tok,
+ "udp")) ? GNUNET_NO : GNUNET_YES,
+ (uint16_t) bnd_port, (uint16_t) adv_port,
+ &result_callback, tc);
if (NULL == tc->tst)
{
display_test_result (tc, GNUNET_SYSERR);
* Shutdown, print statistics.
*/
static void
-do_disconnect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TIME_Relative duration;
if (benchmark_receive)
{
duration = GNUNET_TIME_absolute_get_duration (start_time);
- fprintf (stdout,
- _("Received %llu bytes/s (%llu bytes in %llu ms)\n"),
- 1000 * traffic_received / (1+duration.rel_value),
- traffic_received,
- (unsigned long long) duration.rel_value);
+ fprintf (stdout, _("Received %llu bytes/s (%llu bytes in %llu ms)\n"),
+ 1000 * traffic_received / (1 + duration.rel_value),
+ traffic_received, (unsigned long long) duration.rel_value);
}
if (benchmark_send)
{
duration = GNUNET_TIME_absolute_get_duration (start_time);
- fprintf (stdout,
- _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"),
- 1000 * traffic_sent / (1+duration.rel_value),
- traffic_sent,
- (unsigned long long) duration.rel_value);
+ fprintf (stdout, _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"),
+ 1000 * traffic_sent / (1 + duration.rel_value), traffic_sent,
+ (unsigned long long) duration.rel_value);
}
}
* @return number of bytes written to buf
*/
static size_t
-transmit_data (void *cls, size_t size,
- void *buf)
+transmit_data (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *m = buf;
m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader));
traffic_sent += size;
- th = GNUNET_TRANSPORT_notify_transmit_ready (handle,
- &pid,
- 32 * 1024,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_data, NULL);
+ th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, 32 * 1024, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_data, NULL);
if (verbosity > 0)
- fprintf (stdout,
- _("Transmitting %u bytes to %s\n"),
- (unsigned int) size,
- GNUNET_i2s (&pid));
+ fprintf (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
+ GNUNET_i2s (&pid));
return size;
}
* @param ats_count number of entries in ats (excluding 0-termination)
*/
static void
-notify_connect (void *cls,
- const struct GNUNET_PeerIdentity
- * peer,
- const struct
- GNUNET_ATS_Information
- * ats, uint32_t ats_count)
+notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
if (verbosity > 0)
- fprintf (stdout,
- _("Connected to %s\n"),
- GNUNET_i2s (peer));
- if (0 != memcmp (&pid,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ fprintf (stdout, _("Connected to %s\n"), GNUNET_i2s (peer));
+ if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
ret = 0;
- if (benchmark_send)
+ if (benchmark_send)
{
start_time = GNUNET_TIME_absolute_get ();
- th = GNUNET_TRANSPORT_notify_transmit_ready (handle,
- peer,
- 32 * 1024,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_data, NULL);
+ th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_data, NULL);
}
else
{
/* all done, terminate instantly */
GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&do_disconnect,
- NULL);
- }
+ end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
+ }
}
* @param peer the peer that disconnected
*/
static void
-notify_disconnect (void *cls,
- const struct
- GNUNET_PeerIdentity * peer)
+notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
if (verbosity > 0)
- fprintf (stdout,
- _("Disconnected from %s\n"),
- GNUNET_i2s (peer));
- if ( (0 == memcmp (&pid,
- peer,
- sizeof (struct GNUNET_PeerIdentity))) &&
- (NULL != th) )
+ fprintf (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer));
+ if ((0 == memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) &&
+ (NULL != th))
{
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&do_disconnect,
- NULL);
+ end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
}
}
* @param peer (claimed) identity of the other peer
* @param message the message
* @param ats performance data
- * @param ats_count number of entries in ats
+ * @param ats_count number of entries in ats
*/
static void
-notify_receive (void *cls,
- const struct
- GNUNET_PeerIdentity * peer,
- const struct
- GNUNET_MessageHeader *
- message,
- const struct
- GNUNET_ATS_Information
- * ats, uint32_t ats_count)
+notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
- if (! benchmark_receive)
+ if (!benchmark_receive)
return;
if (verbosity > 0)
- fprintf (stdout,
- _("Received %u bytes from %s\n"),
- (unsigned int) ntohs (message->size),
- GNUNET_i2s (peer));
+ fprintf (stdout, _("Received %u bytes from %s\n"),
+ (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
if (traffic_received == 0)
start_time = GNUNET_TIME_absolute_get ();
traffic_received += ntohs (message->size);
{
if ((peer != NULL) || (transport != NULL) ||
((addr != NULL) && (addrlen > 0)))
- fprintf (stdout,
- _("Peer `%s' plugin: `%s' address `%s'\n"),
+ fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"),
(peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
- (transport != NULL) ? transport : "<unknown>",
- ((addr != NULL) && (addrlen > 0) && (transport != NULL)) ?
+ (transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
+ (addrlen > 0) &&
+ (transport !=
+ NULL)) ?
"how do i resolve the name without transport service?" :
"<unknown>");
}
if (benchmark_send && (NULL == cpid))
{
fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
- "-s", "-C");
+ "-s", "-C");
return;
}
if (NULL != cpid)
{
ret = 1;
- if (GNUNET_OK !=
- GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
+ if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
{
- fprintf (stderr,
- _("Failed to parse peer identity `%s'\n"),
- cpid);
+ fprintf (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
return;
}
- handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect);
+ handle =
+ GNUNET_TRANSPORT_connect (cfg, NULL, NULL, ¬ify_receive,
+ ¬ify_connect, ¬ify_disconnect);
GNUNET_TRANSPORT_try_connect (handle, &pid);
- end = GNUNET_SCHEDULER_add_delayed (benchmark_send
- ? GNUNET_TIME_UNIT_FOREVER_REL
- : GNUNET_TIME_UNIT_SECONDS,
- &do_disconnect,
- NULL);
- } else if (benchmark_receive)
+ end =
+ GNUNET_SCHEDULER_add_delayed (benchmark_send ?
+ GNUNET_TIME_UNIT_FOREVER_REL :
+ GNUNET_TIME_UNIT_SECONDS, &do_disconnect,
+ NULL);
+ }
+ else if (benchmark_receive)
{
- handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect);
+ handle =
+ GNUNET_TRANSPORT_connect (cfg, NULL, NULL, ¬ify_receive,
+ ¬ify_connect, ¬ify_disconnect);
GNUNET_TRANSPORT_try_connect (handle, &pid);
- end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_disconnect,
- NULL);
+ end =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &do_disconnect, NULL);
}
if (iterate_connections)
{
GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
- &process_address, NULL);
+ &process_address, NULL);
}
}
1, &GNUNET_GETOPT_set_string, &cpid},
{'i', "information", NULL,
gettext_noop ("provide information about all current connections (once)"),
- 0, &GNUNET_GETOPT_set_one, &iterate_connections},
+ 0, &GNUNET_GETOPT_set_one, &iterate_connections},
{'s', "send", NULL,
- gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"),
- 0, &GNUNET_GETOPT_set_one, &benchmark_send},
+ gettext_noop
+ ("send data for benchmarking to the other peer (until CTRL-C)"),
+ 0, &GNUNET_GETOPT_set_one, &benchmark_send},
{'t', "test", NULL,
gettext_noop ("test transport configuration (involves external server)"),
- 0, &GNUNET_GETOPT_set_one, &test_configuration},
- GNUNET_GETOPT_OPTION_VERBOSE(&verbosity),
+ 0, &GNUNET_GETOPT_set_one, &test_configuration},
+ GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
GNUNET_GETOPT_OPTION_END
};
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-transport",
- gettext_noop ("Direct access to transport service."),
- options, &run, NULL)) ? ret : 1;
+ gettext_noop
+ ("Direct access to transport service."), options,
+ &run, NULL)) ? ret : 1;
}
* @return GNUNET_YES at success
*/
static int
-getRadiotapHeader ( struct Radiotap_Send *header)
+getRadiotapHeader (struct Radiotap_Send *header)
{
- header->rate = 255;
- header->tx_power = 0;
- header->antenna = 0;
+ header->rate = 255;
+ header->tx_power = 0;
+ header->antenna = 0;
return GNUNET_YES;
}
* @return GNUNET_YES if there was no error
*/
static int
-getWlanHeader (struct ieee80211_frame *Header,
- const char *to_mac_addr, const char *mac,
- unsigned int size)
+getWlanHeader (struct ieee80211_frame *Header, const char *to_mac_addr,
+ const char *mac, unsigned int size)
{
uint16_t *tmp16;
const int rate = 11000000;
Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
Header->i_fc[1] = 0x00;
memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
- memcpy (&Header->i_addr2, mac,
- sizeof (mac_bssid));
+ memcpy (&Header->i_addr2, mac, sizeof (mac_bssid));
memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid));
tmp16 = (uint16_t *) Header->i_dur;
return GNUNET_YES;
}
-int main(int argc, char *argv[]){
+int
+main (int argc, char *argv[])
+{
char msg_buf[WLAN_MTU];
- struct GNUNET_MessageHeader *msg;
- struct ieee80211_frame *wlan_header;
- struct Radiotap_Send *radiotap;
-
- unsigned int temp[6];
- char inmac[6];
- char outmac[6];
- int pos;
- long long count;
- double bytes_per_s;
- time_t start;
- time_t akt;
- int i;
-
- if (4 != argc) {
- fprintf(
- stderr,
- "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n",
- __TIMESTAMP__);
- fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
- return 1;
- }
- if (6 !=
- sscanf(argv[3], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5]))
- {
- fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
- return 1;
- }
- if (6 !=
- sscanf(argv[2], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5]))
- {
- fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
- return 1;
- }
- for (i = 0; i < 6; i++)
- {
- inmac[i] = temp[i];
- }
- for (i = 0; i < 6; i++)
- {
- outmac[i] = temp[i];
- }
-
-
- pid_t pid;
- int commpipe[2]; /* This holds the fd for the input & output of the pipe */
-
- /* Setup communication pipeline first */
- if(pipe(commpipe)){
- fprintf(stderr,"Pipe error!\n");
- exit(1);
- }
-
- /* Attempt to fork and check for errors */
- if( (pid=fork()) == -1){
- fprintf(stderr,"Fork error. Exiting.\n"); /* something went wrong */
- exit(1);
- }
-
- if(pid){
- /* A positive (non-negative) PID indicates the parent process */
- close(commpipe[0]); /* Close unused side of pipe (in side) */
- setvbuf(stdout,(char*)NULL,_IONBF,0); /* Set non-buffered output on stdout */
-
-
- msg = (struct GNUNET_MessageHeader*) msg_buf;
- msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
- msg->size = htons (WLAN_MTU);
- radiotap = (struct Radiotap_Send *) &msg[1];
- wlan_header = (struct ieee80211_frame *) &radiotap[1];
- pos = 0;
-
- getRadiotapHeader(radiotap);
- getWlanHeader(wlan_header, outmac, inmac, WLAN_MTU - sizeof(struct GNUNET_MessageHeader));
-
- start = time(NULL);
- count = 0;
- while (1){
- pos += write(commpipe[1], msg, WLAN_MTU - pos);
- if (pos % WLAN_MTU == 0){
- pos = 0;
- count ++;
-
- if (count % 1000 == 0){
- akt = time(NULL);
- bytes_per_s = count * WLAN_MTU / (akt - start);
- bytes_per_s /= 1024;
- printf("send %f kbytes/s\n", bytes_per_s);
- }
- }
-
- }
- }
- else{
- /* A zero PID indicates that this is the child process */
- (void) close(0);
- if (-1 == dup2(commpipe[0],0)) /* Replace stdin with the in side of the pipe */
- fprintf (stderr,
- "dup2 failed: %s\n",
- strerror (errno));
- (void) close(commpipe[1]); /* Close unused side of pipe (out side) */
- /* Replace the child fork with a new process */
- if (execl("gnunet-transport-wlan-helper","gnunet-transport-wlan-helper", argv[1], NULL) == -1)
- {
- fprintf(stderr,"Could not start gnunet-transport-wlan-helper!");
- _exit(1);
- }
- }
- return 0;
+ struct GNUNET_MessageHeader *msg;
+ struct ieee80211_frame *wlan_header;
+ struct Radiotap_Send *radiotap;
+
+ unsigned int temp[6];
+ char inmac[6];
+ char outmac[6];
+ int pos;
+ long long count;
+ double bytes_per_s;
+ time_t start;
+ time_t akt;
+ int i;
+
+ if (4 != argc)
+ {
+ fprintf (stderr,
+ "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n",
+ __TIMESTAMP__);
+ fprintf (stderr,
+ "Usage: interface-name mac-target mac-source\n"
+ "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
+ return 1;
+ }
+ if (6 !=
+ sscanf (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2],
+ &temp[3], &temp[4], &temp[5]))
+ {
+ fprintf (stderr,
+ "Usage: interface-name mac-target mac-source\n"
+ "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
+ return 1;
+ }
+ if (6 !=
+ sscanf (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2],
+ &temp[3], &temp[4], &temp[5]))
+ {
+ fprintf (stderr,
+ "Usage: interface-name mac-target mac-source\n"
+ "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
+ return 1;
+ }
+ for (i = 0; i < 6; i++)
+ {
+ inmac[i] = temp[i];
+ }
+ for (i = 0; i < 6; i++)
+ {
+ outmac[i] = temp[i];
+ }
+
+
+ pid_t pid;
+ int commpipe[2]; /* This holds the fd for the input & output of the pipe */
+
+ /* Setup communication pipeline first */
+ if (pipe (commpipe))
+ {
+ fprintf (stderr, "Pipe error!\n");
+ exit (1);
+ }
+
+ /* Attempt to fork and check for errors */
+ if ((pid = fork ()) == -1)
+ {
+ fprintf (stderr, "Fork error. Exiting.\n"); /* something went wrong */
+ exit (1);
+ }
+
+ if (pid)
+ {
+ /* A positive (non-negative) PID indicates the parent process */
+ close (commpipe[0]); /* Close unused side of pipe (in side) */
+ setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */
+
+
+ msg = (struct GNUNET_MessageHeader *) msg_buf;
+ msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
+ msg->size = htons (WLAN_MTU);
+ radiotap = (struct Radiotap_Send *) &msg[1];
+ wlan_header = (struct ieee80211_frame *) &radiotap[1];
+ pos = 0;
+
+ getRadiotapHeader (radiotap);
+ getWlanHeader (wlan_header, outmac, inmac,
+ WLAN_MTU - sizeof (struct GNUNET_MessageHeader));
+
+ start = time (NULL);
+ count = 0;
+ while (1)
+ {
+ pos += write (commpipe[1], msg, WLAN_MTU - pos);
+ if (pos % WLAN_MTU == 0)
+ {
+ pos = 0;
+ count++;
+
+ if (count % 1000 == 0)
+ {
+ akt = time (NULL);
+ bytes_per_s = count * WLAN_MTU / (akt - start);
+ bytes_per_s /= 1024;
+ printf ("send %f kbytes/s\n", bytes_per_s);
+ }
+ }
+
+ }
+ }
+ else
+ {
+ /* A zero PID indicates that this is the child process */
+ (void) close (0);
+ if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
+ fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
+ (void) close (commpipe[1]); /* Close unused side of pipe (out side) */
+ /* Replace the child fork with a new process */
+ if (execl
+ ("gnunet-transport-wlan-helper", "gnunet-transport-wlan-helper",
+ argv[1], NULL) == -1)
+ {
+ fprintf (stderr, "Could not start gnunet-transport-wlan-helper!");
+ _exit (1);
+ }
+ }
+ return 0;
}
struct PrettyPrinterContext *ppc;
const void *sb;
size_t sbs;
- uint16_t port = 0 ;
+ uint16_t port = 0;
if (addrlen == sizeof (struct IPv6HttpAddress))
{
- struct IPv6HttpAddress * a6 = (struct IPv6HttpAddress *) addr;
+ struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
+
sb = &a6->ipv6_addr;
sbs = sizeof (struct in6_addr);
port = ntohs (a6->u6_port);
}
else if (addrlen == sizeof (struct IPv4HttpAddress))
{
- struct IPv4HttpAddress * a4 = (struct IPv4HttpAddress *) addr;
+ struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
+
sb = &a4->ipv4_addr;
sbs = sizeof (struct in_addr);
port = ntohs (a4->u4_port);
if (addrlen == sizeof (struct IPv4HttpAddress))
{
struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
+
while (w_tv4 != NULL)
{
- if ((0 == memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr, sizeof (struct in_addr))) &&
+ if ((0 ==
+ memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr,
+ sizeof (struct in_addr))) &&
(w_tv4->addr.u4_port == a4->u4_port))
break;
w_tv4 = w_tv4->next;
if (addrlen == sizeof (struct sockaddr_in6))
{
struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
+
while (w_tv6 != NULL)
{
- if ((0 == memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr, sizeof (struct in6_addr))) &&
+ if ((0 ==
+ memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr,
+ sizeof (struct in6_addr))) &&
(w_tv6->addr6.u6_port == a6->u6_port))
break;
w_tv6 = w_tv6->next;
}
struct GNUNET_TIME_Relative
-http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- struct Session * session,
- const char *sender_address,
- uint16_t sender_address_len)
+http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ struct Session *session, const char *sender_address,
+ uint16_t sender_address_len)
{
struct Session *s = cls;
struct Plugin *plugin = s->plugin;
distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
distance.value = htonl (1);
- delay = plugin->env->receive (plugin->env->cls, &s->target, message, (const struct GNUNET_ATS_Information*) &distance, 1, s, s->addr, s->addrlen);
+ delay =
+ plugin->env->receive (plugin->env->cls, &s->target, message,
+ (const struct GNUNET_ATS_Information *) &distance,
+ 1, s, s->addr, s->addrlen);
return delay;
}
{
a6 = (struct IPv6HttpAddress *) addr;
address = GNUNET_malloc (INET6_ADDRSTRLEN);
- GNUNET_assert(NULL != inet_ntop (AF_INET6, &a6->ipv6_addr, address, INET6_ADDRSTRLEN));
+ GNUNET_assert (NULL !=
+ inet_ntop (AF_INET6, &a6->ipv6_addr, address,
+ INET6_ADDRSTRLEN));
port = ntohs (a6->u6_port);
}
else if (addrlen == sizeof (struct IPv4HttpAddress))
{
a4 = (struct IPv4HttpAddress *) addr;
address = GNUNET_malloc (INET_ADDRSTRLEN);
- GNUNET_assert(NULL != inet_ntop (AF_INET, &(a4->ipv4_addr), address, INET_ADDRSTRLEN));
+ GNUNET_assert (NULL !=
+ inet_ntop (AF_INET, &(a4->ipv4_addr), address,
+ INET_ADDRSTRLEN));
port = ntohs (a4->u4_port);
}
else
GNUNET_break (0);
return NULL;
}
-#if !BUILD_HTTPS
- char * protocol = "http";
+#if !BUILD_HTTPS
+ char *protocol = "http";
#else
- char * protocol = "https";
+ char *protocol = "https";
#endif
GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13));
if (addrlen == sizeof (struct IPv6HttpAddress))
- res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, address, port);
+ res =
+ GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol,
+ address, port);
else if (addrlen == sizeof (struct IPv4HttpAddress))
- res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address, port);
+ res =
+ GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address,
+ port);
GNUNET_free (address);
GNUNET_assert (res != 0);
struct Session *
lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
- struct Session * session,
- const void *addr, size_t addrlen, int force_address)
+ struct Session *session, const void *addr, size_t addrlen,
+ int force_address)
{
struct Session *s = NULL;
struct Session *t = NULL;
{
#if 0
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Comparing peer `%s' address `%s' len %i session %X to \n", GNUNET_i2s(target), GNUNET_a2s(addr,addrlen), addrlen, session);
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"peer `%s' address `%s' len %i session %X \n\n", GNUNET_i2s(&t->target), GNUNET_a2s(t->addr,t->addrlen), t->addrlen, t);
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"memcmp %i \n", memcmp (addr, t->addr, addrlen));
+ "Comparing peer `%s' address `%s' len %i session %X to \n",
+ GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen,
+ session);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "peer `%s' address `%s' len %i session %X \n\n",
+ GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen),
+ t->addrlen, t);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n",
+ memcmp (addr, t->addr, addrlen));
#endif
e_peer = GNUNET_NO;
e_addr = GNUNET_NO;
}
if ((t == session))
{
- if(t->addrlen == session->addrlen)
- {
- if (0 == memcmp (session->addr, t->addr, t->addrlen))
+ if (t->addrlen == session->addrlen)
{
- e_addr = GNUNET_YES;
+ if (0 == memcmp (session->addr, t->addr, t->addrlen))
+ {
+ e_addr = GNUNET_YES;
+ }
}
- }
}
}
s = t;
break;
}
- if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES))
+ if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) &&
+ (e_addr == GNUNET_YES))
{
s = t;
break;
s->msg_tk = NULL;
}
GNUNET_free (s->addr);
- GNUNET_free_non_null(s->server_recv);
- GNUNET_free_non_null(s->server_send);
+ GNUNET_free_non_null (s->server_recv);
+ GNUNET_free_non_null (s->server_send);
GNUNET_free (s);
}
GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Session *s = NULL;
- GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) || (addrlen == sizeof (struct IPv4HttpAddress)));
+
+ GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
+ (addrlen == sizeof (struct IPv4HttpAddress)));
s = GNUNET_malloc (sizeof (struct Session));
memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity));
s->plugin = plugin;
memcpy (s->addr, addr, addrlen);
s->addrlen = addrlen;
s->next = NULL;
- s->next_receive = GNUNET_TIME_absolute_get_zero();
+ s->next_receive = GNUNET_TIME_absolute_get_zero ();
return s;
}
void
-notify_session_end (void *cls,
- const struct GNUNET_PeerIdentity *
- peer, struct Session * s)
+notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
+ struct Session *s)
{
struct Plugin *plugin = cls;
{
struct Plugin *plugin = cls;
struct HTTP_Message *msg;
+
GNUNET_assert (plugin != NULL);
int res = GNUNET_SYSERR;
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Sending %u bytes to peer `%s' on address `%s' %X %i\n", msgbuf_size,
- GNUNET_i2s (target), ((addr != NULL) && (addrlen != 0)) ? http_plugin_address_to_string(plugin, addr, addrlen) : "<inbound>", session, force_address);
+ "Sending %u bytes to peer `%s' on address `%s' %X %i\n",
+ msgbuf_size, GNUNET_i2s (target), ((addr != NULL) &&
+ (addrlen !=
+ 0)) ?
+ http_plugin_address_to_string (plugin, addr,
+ addrlen) : "<inbound>",
+ session, force_address);
#endif
struct Session *s = NULL;
if (addrlen != 0)
- GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) ||
- (addrlen == sizeof (struct IPv6HttpAddress)));
+ GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) ||
+ (addrlen == sizeof (struct IPv6HttpAddress)));
/* look for existing connection */
s = lookup_session (plugin, target, session, addr, addrlen, 1);
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "%s existing session: %s\n", (s!=NULL) ? "Found" : "NOT Found", ((s != NULL) && (s->inbound == GNUNET_YES)) ? "inbound" : "outbound");
+ "%s existing session: %s\n",
+ (s != NULL) ? "Found" : "NOT Found", ((s != NULL) &&
+ (s->inbound ==
+ GNUNET_YES)) ?
+ "inbound" : "outbound");
#endif
/* create new outbound connection */
{
GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
"Maximum number of connections reached, "
- "cannot connect to peer `%s'\n",
- GNUNET_i2s (target));
+ "cannot connect to peer `%s'\n", GNUNET_i2s (target));
return res;
}
"Using outbound client session to send to `%s'\n",
GNUNET_i2s (target));
#endif
- client_send (s, msg);
- res = msgbuf_size;
+ client_send (s, msg);
+ res = msgbuf_size;
}
if (s->inbound == GNUNET_YES)
{
case AF_INET:
w_t4 = plugin->ipv4_addr_head;
struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
+
while (w_t4 != NULL)
{
int res = memcmp (&w_t4->addr.ipv4_addr,
&a4->sin_addr,
sizeof (struct in_addr));
+
if (res == 0)
{
- if (a4->sin_port!= w_t4->addr.u4_port)
+ if (a4->sin_port != w_t4->addr.u4_port)
res = -1;
}
if (w_t4 == NULL)
{
w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
- memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr,
- sizeof (struct in_addr));
+ memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
w_t4->addr.u4_port = a4->sin_port;
GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"Notifying transport to add IPv4 address `%s'\n",
- http_plugin_address_to_string(NULL, &w_t4->addr, sizeof (struct IPv4HttpAddress)));
+ http_plugin_address_to_string (NULL, &w_t4->addr,
+ sizeof (struct
+ IPv4HttpAddress)));
#endif
- plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr, sizeof (struct IPv4HttpAddress));
+ plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
+ sizeof (struct IPv4HttpAddress));
break;
case AF_INET6:
w_t6 = plugin->ipv6_addr_head;
struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
+
while (w_t6)
{
int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
sizeof (struct in6_addr));
+
if (res == 0)
{
if (a6->sin6_port != w_t6->addr6.u6_port)
{
w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
- memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
- sizeof (struct in6_addr));
+ memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
w_t6->addr6.u6_port = a6->sin6_port;
GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"Notifying transport to add IPv6 address `%s'\n",
- http_plugin_address_to_string(NULL, &w_t6->addr6, sizeof (struct IPv6HttpAddress)));
+ http_plugin_address_to_string (NULL, &w_t6->addr6,
+ sizeof (struct
+ IPv6HttpAddress)));
#endif
- plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6, sizeof (struct IPv6HttpAddress));
+ plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
+ sizeof (struct IPv6HttpAddress));
break;
default:
return;
case AF_INET:
w_t4 = plugin->ipv4_addr_head;
struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
+
while (w_t4 != NULL)
{
int res = memcmp (&w_t4->addr.ipv4_addr,
&a4->sin_addr,
sizeof (struct in_addr));
+
if (res == 0)
{
- if (a4->sin_port!= w_t4->addr.u4_port)
+ if (a4->sin_port != w_t4->addr.u4_port)
res = -1;
}
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"Notifying transport to remove IPv4 address `%s'\n",
- http_plugin_address_to_string(NULL, &w_t4->addr, sizeof (struct IPv4HttpAddress)));
+ http_plugin_address_to_string (NULL, &w_t4->addr,
+ sizeof (struct
+ IPv4HttpAddress)));
#endif
plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
sizeof (struct IPv4HttpAddress));
case AF_INET6:
w_t6 = plugin->ipv6_addr_head;
struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
+
while (w_t6)
{
int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
sizeof (struct in6_addr));
+
if (res == 0)
{
if (a6->sin6_port != w_t6->addr6.u6_port)
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"Notifying transport to remove IPv6 address `%s'\n",
- http_plugin_address_to_string(NULL, &w_t6->addr6, sizeof (struct IPv6HttpAddress)));
+ http_plugin_address_to_string (NULL, &w_t6->addr6,
+ sizeof (struct
+ IPv6HttpAddress)));
#endif
plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
sizeof (struct IPv6HttpAddress));
switch (add_remove)
{
case GNUNET_YES:
- nat_add_address (cls, add_remove, addr, addrlen);
+ nat_add_address (cls, add_remove, addr, addrlen);
break;
case GNUNET_NO:
nat_remove_address (cls, add_remove, addr, addrlen);
http_check_ipv6 (struct Plugin *plugin)
{
struct GNUNET_NETWORK_Handle *desc = NULL;
+
if (plugin->ipv6 == GNUNET_YES)
{
/* probe IPv6 support */
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
}
GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
- _
- ("Disabling IPv6 since it is not supported on this system!\n"));
+ _
+ ("Disabling IPv6 since it is not supported on this system!\n"));
plugin->ipv6 = GNUNET_NO;
}
else
desc = NULL;
}
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Testing IPv6 on this system: %s\n", (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Testing IPv6 on this system: %s\n",
+ (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed");
}
}
int
-http_get_addresses (struct Plugin *plugin,
- const char *serviceName,
- const struct GNUNET_CONFIGURATION_Handle
- *cfg, struct sockaddr ***addrs,
- socklen_t ** addr_lens)
+http_get_addresses (struct Plugin *plugin, const char *serviceName,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct sockaddr ***addrs, socklen_t ** addr_lens)
{
int disablev6;
unsigned long long port;
if (hostname != NULL)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Resolving `%s' since that is where `%s' will bind to.\n",
- hostname, serviceName);
+ "Resolving `%s' since that is where `%s' will bind to.\n",
+ hostname, serviceName);
memset (&hints, 0, sizeof (struct addrinfo));
if (disablev6)
hints.ai_family = AF_INET;
if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
continue; /* huh? */
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Service will bind to `%s'\n",
- GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
+ "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr,
+ pos->ai_addrlen));
if (pos->ai_family == AF_INET)
{
GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
socklen_t *addrlens;
res =
- http_get_addresses (plugin, plugin->name, plugin->env->cfg,
- &addrs, &addrlens);
+ http_get_addresses (plugin, plugin->name, plugin->env->cfg, &addrs,
+ &addrlens);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- _("Found %u addresses to report to NAT service\n"),res);
+ _("Found %u addresses to report to NAT service\n"), res);
if (res != GNUNET_SYSERR)
{
GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port,
(unsigned int) res,
(const struct sockaddr **) addrs, addrlens,
- &nat_port_map_callback, NULL,
- plugin);
+ &nat_port_map_callback, NULL, plugin);
while (res > 0)
{
res--;
#if 0
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- _("FREEING %s\n"),
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, _("FREEING %s\n"),
GNUNET_a2s (addrs[res], addrlens[res]));
#endif
GNUNET_assert (addrs[res] != NULL);
if (plugin->port == 0)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- _("Port 0, client only mode\n"));
+ _("Port 0, client only mode\n"));
plugin->client_only = GNUNET_YES;
}
- char * bind4_address = NULL;
- if ((plugin->ipv4 == GNUNET_YES) && (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
- "BINDTO", &bind4_address)))
+ char *bind4_address = NULL;
+
+ if ((plugin->ipv4 == GNUNET_YES) &&
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
+ "BINDTO", &bind4_address)))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Binding %s plugin to specific IPv4 address: `%s'\n",
- plugin->protocol, bind4_address);
+ "Binding %s plugin to specific IPv4 address: `%s'\n",
+ plugin->protocol, bind4_address);
plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
- if (1 != inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr))
+ if (1 !=
+ inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- _("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
- bind4_address, plugin->protocol);
+ _
+ ("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
+ bind4_address, plugin->protocol);
GNUNET_free (plugin->server_addr_v4);
plugin->server_addr_v4 = NULL;
}
}
- char * bind6_address = NULL;
- if ((plugin->ipv6 == GNUNET_YES) && (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
- "BINDTO6", &bind6_address)))
+ char *bind6_address = NULL;
+
+ if ((plugin->ipv6 == GNUNET_YES) &&
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
+ "BINDTO6", &bind6_address)))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Binding %s plugin to specific IPv6 address: `%s'\n",
- plugin->protocol, bind6_address);
+ "Binding %s plugin to specific IPv6 address: `%s'\n",
+ plugin->protocol, bind6_address);
plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
- if (1 != inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
+ if (1 !=
+ inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- _("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
- bind6_address, plugin->protocol);
+ _
+ ("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
+ bind6_address, plugin->protocol);
GNUNET_free (plugin->server_addr_v6);
plugin->server_addr_v6 = NULL;
}
/* Optional parameters */
unsigned long long maxneigh;
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
"MAX_CONNECTIONS", &maxneigh))
while (s != NULL)
{
#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
#endif
if (s->inbound == GNUNET_NO)
GNUNET_assert (GNUNET_OK == client_disconnect (s));
}
#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Stopping server\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n");
#endif
/* Stop server */
server_stop (plugin);
#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Stopping client\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping client\n");
#endif
/* Stop client */
client_stop (plugin);
while (s != NULL)
{
struct Session *t = s->next;
+
GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
delete_session (s);
s = t;
/**
* IPv4 server socket to bind to
*/
- struct sockaddr_in * server_addr_v4;
+ struct sockaddr_in *server_addr_v4;
/**
* IPv6 server socket to bind to
*/
- struct sockaddr_in6 * server_addr_v6;
+ struct sockaddr_in6 *server_addr_v6;
/**
* Server semi connections
GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls);
struct GNUNET_TIME_Relative
-http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- struct Session * session,
- const char *sender_address,
- uint16_t sender_address_len);
+http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ struct Session *session, const char *sender_address,
+ uint16_t sender_address_len);
const char *
http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen);
server_disconnect (struct Session *s);
int
-server_send (struct Session *s, struct HTTP_Message * msg);
+server_send (struct Session *s, struct HTTP_Message *msg);
int
server_start (struct Plugin *plugin);
server_stop (struct Plugin *plugin);
void
-notify_session_end (void *cls,
- const struct GNUNET_PeerIdentity *
- peer, struct Session * s);
+notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
+ struct Session *s);
/* end of plugin_transport_http.h */
text[size + 1] = '\0';
}
#if BUILD_HTTPS
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "transport-https", "Client: %X - %s", cls, text);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https",
+ "Client: %X - %s", cls, text);
#else
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "transport-http", "Client: %X - %s", cls, text);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http",
+ "Client: %X - %s", cls, text);
#endif
}
return 0;
struct GNUNET_TIME_Relative timeout;
/* Cancel previous scheduled task */
- if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK)
+ if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
plugin->client_perform_task =
GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- timeout,
- grs,
- gws,
- &client_run,
- plugin);
+ GNUNET_SCHEDULER_NO_TASK, timeout, grs, gws,
+ &client_run, plugin);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
return GNUNET_OK;
{
#if VERBOSE_CLIENT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
- "Client: %X was suspended, unpausing\n", s->client_put);
+ "Client: %X was suspended, unpausing\n", s->client_put);
#endif
s->client_put_paused = GNUNET_NO;
- curl_easy_pause(s->client_put, CURLPAUSE_CONT);
+ curl_easy_pause (s->client_put, CURLPAUSE_CONT);
}
client_schedule (s->plugin, GNUNET_YES);
running = 0;
mret = curl_multi_perform (plugin->client_mh, &running);
- CURLMsg * msg;
+ CURLMsg *msg;
int msgs_left;
- while ((msg = curl_multi_info_read(plugin->client_mh, &msgs_left)))
+
+ while ((msg = curl_multi_info_read (plugin->client_mh, &msgs_left)))
{
- CURL *easy_h = msg->easy_handle;
- struct Session *s = NULL;
- char * d = (char *) s;
-
-
- //GNUNET_assert (easy_h != NULL);
- if (easy_h == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: connection to ended with reason %i: `%s', %i handles running\n",
- msg->data.result,
- curl_easy_strerror(msg->data.result),
- running);
- continue;
- }
-
- GNUNET_assert (CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d));
- s = (struct Session *) d;
- GNUNET_assert (s != NULL);
-
- if (msg->msg == CURLMSG_DONE)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X connection to '%s' %s ended with reason %i: `%s'\n",
- msg->easy_handle, GNUNET_i2s(&s->target),
- http_plugin_address_to_string (NULL, s->addr, s->addrlen),
- msg->data.result,
- curl_easy_strerror(msg->data.result));
-
- client_disconnect(s);
- //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen));
- notify_session_end (plugin, &s->target, s);
- }
+ CURL *easy_h = msg->easy_handle;
+ struct Session *s = NULL;
+ char *d = (char *) s;
+
+
+ //GNUNET_assert (easy_h != NULL);
+ if (easy_h == NULL)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Client: connection to ended with reason %i: `%s', %i handles running\n",
+ msg->data.result,
+ curl_easy_strerror (msg->data.result), running);
+ continue;
+ }
+
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d));
+ s = (struct Session *) d;
+ GNUNET_assert (s != NULL);
+
+ if (msg->msg == CURLMSG_DONE)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Client: %X connection to '%s' %s ended with reason %i: `%s'\n",
+ msg->easy_handle, GNUNET_i2s (&s->target),
+ http_plugin_address_to_string (NULL, s->addr,
+ s->addrlen),
+ msg->data.result,
+ curl_easy_strerror (msg->data.result));
+
+ client_disconnect (s);
+ //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen));
+ notify_session_end (plugin, &s->target, s);
+ }
}
}
while (mret == CURLM_CALL_MULTI_PERFORM);
int res = GNUNET_OK;
CURLMcode mret;
struct Plugin *plugin = s->plugin;
- struct HTTP_Message * msg;
- struct HTTP_Message * t;
+ struct HTTP_Message *msg;
+ struct HTTP_Message *t;
if (s->client_put != NULL)
{
#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Deleting outbound PUT session to peer `%s'\n",
- s->client_put,
- GNUNET_i2s (&s->target));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Client: %X Deleting outbound PUT session to peer `%s'\n",
+ s->client_put, GNUNET_i2s (&s->target));
#endif
mret = curl_multi_remove_handle (plugin->client_mh, s->client_put);
if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
- s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
+ s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
}
if (s->client_get != NULL)
{
#if DEBUG_HTTP
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Deleting outbound GET session to peer `%s'\n",
- s->client_get,
- GNUNET_i2s (&s->target));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Client: %X Deleting outbound GET session to peer `%s'\n",
+ s->client_get, GNUNET_i2s (&s->target));
#endif
mret = curl_multi_remove_handle (plugin->client_mh, s->client_get);
t = msg->next;
if (NULL != msg->transmit_cont)
msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
- GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg);
+ GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
GNUNET_free (msg);
msg = t;
}
static void
client_receive_mst_cb (void *cls, void *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
struct Session *s = cls;
struct GNUNET_TIME_Relative delay;
delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
- s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
+ s->next_receive =
+ GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
- if (GNUNET_TIME_absolute_get().abs_value < s->next_receive.abs_value)
+ if (GNUNET_TIME_absolute_get ().abs_value < s->next_receive.abs_value)
{
#if VERBOSE_CLIENT
struct Plugin *plugin = s->plugin;
+
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: peer `%s' address `%s' next read delayed for %llu ms\n",
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay);
+ "Client: peer `%s' address `%s' next read delayed for %llu ms\n",
+ GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen),
+ delay);
#endif
}
}
+
static void
client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
return;
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
- "Client: %X Waking up receive handle\n",
- s->client_get);
+ "Client: %X Waking up receive handle\n", s->client_get);
if (s->client_get != NULL)
- curl_easy_pause(s->client_get, CURLPAUSE_CONT);
+ curl_easy_pause (s->client_get, CURLPAUSE_CONT);
}
#if VERBOSE_CLIENT
struct Plugin *plugin = s->plugin;
+
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: Received %Zu bytes from peer `%s'\n",
- len,
+ "Client: Received %Zu bytes from peer `%s'\n", len,
GNUNET_i2s (&s->target));
#endif
- now = GNUNET_TIME_absolute_get();
+ now = GNUNET_TIME_absolute_get ();
if (now.abs_value < s->next_receive.abs_value)
{
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
- struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->next_receive);
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+ struct GNUNET_TIME_Relative delta =
+ GNUNET_TIME_absolute_get_difference (now, s->next_receive);
#if DEBUG_CLIENT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n",
- s->client_get, delta.rel_value);
+ "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n",
+ s->client_get, delta.rel_value);
#endif
if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
}
- s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
+ s->recv_wakeup_task =
+ GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
return CURLPAUSE_ALL;
}
if (s->msg_tk == NULL)
- s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
+ s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
- GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO,
- GNUNET_NO);
+ GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO);
return len;
}
client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
{
struct Session *s = cls;
+
#if VERBOSE_CLIENT
struct Plugin *plugin = s->plugin;
#endif
{
#if VERBOSE_CLIENT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Nothing to send! Suspending PUT handle!\n", s->client_put);
+ "Client: %X Nothing to send! Suspending PUT handle!\n",
+ s->client_put);
#endif
s->client_put_paused = GNUNET_YES;
return CURL_READFUNC_PAUSE;
{
#if VERBOSE_CLIENT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Message with %u bytes sent, removing message from queue\n",
- s->client_put, msg->size, msg->pos);
+ "Client: %X Message with %u bytes sent, removing message from queue\n",
+ s->client_put, msg->size, msg->pos);
#endif
/* Calling transmit continuation */
if (NULL != msg->transmit_cont)
msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
- GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg);
+ GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
GNUNET_free (msg);
}
return bytes_sent;
plugin->last_tag++;
/* create url */
GNUNET_asprintf (&url, "%s%s;%u",
- http_plugin_address_to_string (plugin, s->addr, s->addrlen),
- GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag);
+ http_plugin_address_to_string (plugin, s->addr, s->addrlen),
+ GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),
+ plugin->last_tag);
#if 0
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "URL `%s'\n",
- url);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "URL `%s'\n", url);
#endif
/* create get connection */
s->client_get = curl_easy_init ();
plugin->cur_connections += 2;
/* Re-schedule since handles have changed */
- if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK)
+ if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
int disconnect;
struct Session *session;
- struct MHD_Connection * mhd_conn;
+ struct MHD_Connection *mhd_conn;
};
/**
* @return gnunet task identifier
*/
static GNUNET_SCHEDULER_TaskIdentifier
-server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now);
+server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle,
+ int now);
static void
server_log (void *arg, const char *fmt, va_list ap)
static int
server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
{
- struct Plugin * plugin = cls;
+ struct Plugin *plugin = cls;
if (plugin->cur_connections <= plugin->max_connections)
return MHD_YES;
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Cannot accept new connections\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server: Cannot accept new connections\n");
return MHD_NO;
}
}
/* Get crypto init string from config
* If not present just use default values */
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
- "CRYPTO_INIT", &plugin->crypto_init));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
+ plugin->name,
+ "CRYPTO_INIT",
+ &plugin->crypto_init));
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
"CERT_FILE", &cert_file))
{
- GNUNET_asprintf(&cert_file, "%s", "https_cert.crt");
+ GNUNET_asprintf (&cert_file, "%s", "https_cert.crt");
}
/* read key & certificates from file */
{
if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(plugin->server_v4_task);
+ GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
}
plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now);
if (plugin->server_v6 != NULL)
{
- if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(plugin->server_v6_task);
- plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
- }
- plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now);
+ if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
+ plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now);
}
}
*/
static void
server_receive_mst_cb (void *cls, void *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
struct Session *s = cls;
+
#if VERBOSE_SERVER
struct Plugin *plugin = s->plugin;
#endif
delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
- s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
+ s->next_receive =
+ GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
if (delay.rel_value > 0)
{
#if VERBOSE_CLIENT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: peer `%s' address `%s' next read delayed for %llu ms\n",
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Server: peer `%s' address `%s' next read delayed for %llu ms\n",
+ GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen),
+ delay);
#endif
}
}
struct HTTP_Message *msg;
int bytes_read = 0;
+
//static int c = 0;
msg = s->msg_head;
if (msg != NULL)
{
if (NULL != msg->transmit_cont)
msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
- GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg);
+ GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
GNUNET_free (msg);
}
}
#if VERBOSE_CLIENT
struct Plugin *plugin = s->plugin;
+
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: %X: sent %u bytes\n",
- s, bytes_read);
+ "Server: %X: sent %u bytes\n", s, bytes_read);
#endif
return bytes_read;
}
static struct ServerConnection *
server_lookup_session (struct Plugin *plugin,
- struct MHD_Connection *mhd_connection,
- const char * url,
- const char *method)
+ struct MHD_Connection *mhd_connection, const char *url,
+ const char *method)
{
struct Session *s = NULL;
- struct Session * t;
+ struct Session *t;
struct ServerConnection *sc = NULL;
const union MHD_ConnectionInfo *conn_info;
struct IPv4HttpAddress a4;
struct IPv6HttpAddress a6;
- struct sockaddr_in * s4;
- struct sockaddr_in6 * s6;
- void * a;
+ struct sockaddr_in *s4;
+ struct sockaddr_in6 *s6;
+ void *a;
size_t a_len;
struct GNUNET_PeerIdentity target;
int check = GNUNET_NO;
uint32_t tag = 0;
int direction;
- conn_info = MHD_get_connection_info (mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS);
- if ((conn_info->client_addr->sa_family != AF_INET) && (conn_info->client_addr->sa_family != AF_INET6))
+ conn_info =
+ MHD_get_connection_info (mhd_connection,
+ MHD_CONNECTION_INFO_CLIENT_ADDRESS);
+ if ((conn_info->client_addr->sa_family != AF_INET) &&
+ (conn_info->client_addr->sa_family != AF_INET6))
return MHD_NO;
- if ((strlen(&url[1]) >= 105) && (url[104] == ';'))
+ if ((strlen (&url[1]) >= 105) && (url[104] == ';'))
{
char hash[104];
- char * tagc = (char *) &url[105];
- memcpy(&hash, &url[1], 103);
- hash [103] = '\0';
- if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string ((const char *) &hash,
- &(target.hashPubKey)))
+ char *tagc = (char *) &url[105];
+
+ memcpy (&hash, &url[1], 103);
+ hash[103] = '\0';
+ if (GNUNET_OK ==
+ GNUNET_CRYPTO_hash_from_string ((const char *) &hash,
+ &(target.hashPubKey)))
{
tag = strtoul (tagc, NULL, 10);
if (tagc > 0)
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: New inbound connection from %s with tag %u\n", GNUNET_i2s(&target), tag);
+ "Server: New inbound connection from %s with tag %u\n",
+ GNUNET_i2s (&target), tag);
#endif
/* find duplicate session */
while (t != NULL)
{
- if ((t->inbound) && (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) &&
+ if ((t->inbound) &&
+ (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity)))
+ &&
/* FIXME add source address comparison */
(t->tag == tag))
- break;
+ break;
t = t->next;
}
if (t != NULL)
{
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
+ "Server: Duplicate session, dismissing new connection from peer `%s'\n",
+ GNUNET_i2s (&target));
#endif
goto error;
}
while (t != NULL)
{
/* FIXME add source address comparison */
- if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) &&
- (t->tag == tag))
+ if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity)))
+ && (t->tag == tag))
{
break;
}
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target));
+ "Server: Found existing semi-session for `%s'\n",
+ GNUNET_i2s (&target));
#endif
if ((direction == _SEND) && (t->server_send != NULL))
{
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
+ "Server: Duplicate GET session, dismissing new connection from peer `%s'\n",
+ GNUNET_i2s (&target));
#endif
goto error;
}
else
{
s = t;
- GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s);
- GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s);
+ GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head,
+ plugin->server_semi_tail, s);
+ GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
+ "Server: Found matching semi-session, merging session for peer `%s'\n",
+ GNUNET_i2s (&target));
#endif
goto found;
{
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
+ "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n",
+ GNUNET_i2s (&target));
#endif
goto error;
}
else
{
s = t;
- GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s);
- GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s);
+ GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head,
+ plugin->server_semi_tail, s);
+ GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
+ "Server: Found matching semi-session, merging session for peer `%s'\n",
+ GNUNET_i2s (&target));
#endif
goto found;
}
/* create new session */
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Creating new session for peer `%s' \n", GNUNET_i2s (&target));
+ "Server: Creating new session for peer `%s' \n",
+ GNUNET_i2s (&target));
#endif
switch (conn_info->client_addr->sa_family)
{
case (AF_INET):
- s4 = ((struct sockaddr_in * ) conn_info->client_addr);
- a4.u4_port = s4->sin_port;
- memcpy (&a4.ipv4_addr, &s4->sin_addr,
- sizeof (struct in_addr));
- a = &a4;
- a_len = sizeof (struct IPv4HttpAddress);
- break;
+ s4 = ((struct sockaddr_in *) conn_info->client_addr);
+ a4.u4_port = s4->sin_port;
+ memcpy (&a4.ipv4_addr, &s4->sin_addr, sizeof (struct in_addr));
+ a = &a4;
+ a_len = sizeof (struct IPv4HttpAddress);
+ break;
case (AF_INET6):
- s6 = ((struct sockaddr_in6 * ) conn_info->client_addr);
- a6.u6_port = s6->sin6_port;
- memcpy (&a6.ipv6_addr, &s6->sin6_addr,
- sizeof (struct in6_addr));
- a = &a6;
- a_len = sizeof (struct IPv6HttpAddress);
- break;
+ s6 = ((struct sockaddr_in6 *) conn_info->client_addr);
+ a6.u6_port = s6->sin6_port;
+ memcpy (&a6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
+ a = &a6;
+ a_len = sizeof (struct IPv6HttpAddress);
+ break;
default:
GNUNET_break (0);
goto error;
}
- s = create_session (plugin,
- &target,
- a,
- a_len,
- NULL,
- NULL);
+ s = create_session (plugin, &target, a, a_len, NULL, NULL);
s->inbound = GNUNET_YES;
- s->next_receive = GNUNET_TIME_absolute_get_zero();
- s->tag= tag;
+ s->next_receive = GNUNET_TIME_absolute_get_zero ();
+ s->tag = tag;
if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
s->server_recv = s;
if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
s->server_send = s;
- GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, plugin->server_semi_tail, s);
+ GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head,
+ plugin->server_semi_tail, s);
goto found;
error:
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Invalid connection request\n");
+ "Server: Invalid connection request\n");
#endif
return NULL;
#if MHD_VERSION >= 0x00090E00
int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
+
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"Server: Setting timeout for %X to %u sec.\n", sc, to);
/* new connection */
if (sc == NULL)
{
- sc = server_lookup_session(plugin, mhd_connection, url, method);
+ sc = server_lookup_session (plugin, mhd_connection, url, method);
if (sc != NULL)
(*httpSessionCache) = sc;
else
{
- response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
+ response =
+ MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),
+ HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
MHD_destroy_response (response);
return res;
sc = (*httpSessionCache);
s = sc->session;
- /* connection is to be disconnected*/
+ /* connection is to be disconnected */
if (sc->disconnect == GNUNET_YES)
{
- response = MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!", MHD_NO, MHD_NO);
+ response =
+ MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!",
+ MHD_NO, MHD_NO);
res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
#if VERBOSE_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_assert (s != NULL);
if (sc->direction == _SEND)
{
- response = MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback,
+ response =
+ MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback,
s, NULL);
res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
if (*upload_data_size == 0)
{
#if VERBOSE_SERVER
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Peer `%s' PUT on address `%s' connected\n",
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Server: Peer `%s' PUT on address `%s' connected\n",
+ GNUNET_i2s (&s->target), GNUNET_a2s (s->addr,
+ s->addrlen));
#endif
return MHD_YES;
}
if ((*upload_data_size > 0))
{
#if VERBOSE_SERVER
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: peer `%s' PUT on address `%s' received %Zu bytes\n",
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), *upload_data_size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Server: peer `%s' PUT on address `%s' received %Zu bytes\n",
+ GNUNET_i2s (&s->target), GNUNET_a2s (s->addr,
+ s->addrlen),
+ *upload_data_size);
#endif
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
- if (( s->next_receive.abs_value <= now.abs_value))
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+
+ if ((s->next_receive.abs_value <= now.abs_value))
{
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: %X: PUT with %u bytes forwarded to MST\n", s,
- *upload_data_size);
+ "Server: %X: PUT with %u bytes forwarded to MST\n", s,
+ *upload_data_size);
#endif
if (s->msg_tk == NULL)
{
s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s);
}
- res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO);
+ res =
+ GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data,
+ *upload_data_size, GNUNET_NO, GNUNET_NO);
#if MHD_VERSION >= 0x00090E00
int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
t = s->server_recv;
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Setting timeout for %X to %u sec.\n", t, to);
+ "Server: Setting timeout for %X to %u sec.\n", t,
+ to);
#endif
- MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to);
+ MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
+ to);
}
if (s->server_send != NULL)
{
t = s->server_send;
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Setting timeout for %X to %u sec.\n", t, to);
+ "Server: Setting timeout for %X to %u sec.\n", t,
+ to);
#endif
- MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to);
+ MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
+ to);
}
server_reschedule (plugin, GNUNET_NO);
#endif
else
{
#if DEBUG_HTTP
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", s, now.abs_value - s->next_receive.abs_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n",
+ s, now.abs_value - s->next_receive.abs_value);
#endif
}
return MHD_YES;
{
struct ServerConnection *sc = *httpSessionCache;
struct ServerConnection *tc = *httpSessionCache;
- struct Session * s = NULL;
- struct Session * t = NULL;
- struct Plugin * plugin = NULL;
+ struct Session *s = NULL;
+ struct Session *t = NULL;
+ struct Plugin *plugin = NULL;
if (sc == NULL)
return;
s = sc->session;
- plugin = s-> plugin;
+ plugin = s->plugin;
if (sc->direction == _SEND)
{
#if VERBOSE_SERVER
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Server: %X peer `%s' GET on address `%s' disconnected\n",
- s->server_send,
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Server: %X peer `%s' GET on address `%s' disconnected\n",
+ s->server_send, GNUNET_i2s (&s->target),
+ GNUNET_a2s (s->addr, s->addrlen));
#endif
s->server_send = NULL;
tc = s->server_recv;
tc->disconnect = GNUNET_YES;
#if MHD_VERSION >= 0x00090E00
- MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1);
+ MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
+ 1);
#endif
}
}
if (sc->direction == _RECEIVE)
{
#if VERBOSE_SERVER
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Server: %X peer `%s' PUT on address `%s' disconnected\n",
- s->server_recv,
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Server: %X peer `%s' PUT on address `%s' disconnected\n",
+ s->server_recv, GNUNET_i2s (&s->target),
+ GNUNET_a2s (s->addr, s->addrlen));
#endif
s->server_recv = NULL;
if (s->server_send != NULL)
tc = s->server_send;
tc->disconnect = GNUNET_YES;
#if MHD_VERSION >= 0x00090E00
- MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1);
+ MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
+ 1);
#endif
}
if (s->msg_tk != NULL)
{
- GNUNET_SERVER_mst_destroy(s->msg_tk);
- s->msg_tk = NULL;
+ GNUNET_SERVER_mst_destroy (s->msg_tk);
+ s->msg_tk = NULL;
}
}
GNUNET_free (sc);
{
if (t == s)
{
- GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s);
- GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s);
+ GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head,
+ plugin->server_semi_tail, s);
+ GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
break;
}
t = t->next;
if ((s->server_send == NULL) && (s->server_recv == NULL))
{
#if VERBOSE_SERVER
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: peer `%s' on address `%s' disconnected\n",
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+ "Server: peer `%s' on address `%s' disconnected\n",
+ GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
#endif
if (s->msg_tk != NULL)
{
- GNUNET_SERVER_mst_destroy(s->msg_tk);
- s->msg_tk = NULL;
+ GNUNET_SERVER_mst_destroy (s->msg_tk);
+ s->msg_tk = NULL;
}
- notify_session_end(s->plugin, &s->target, s);
+ notify_session_end (s->plugin, &s->target, s);
}
}
}
int
-server_send (struct Session *s, struct HTTP_Message * msg)
+server_send (struct Session *s, struct HTTP_Message *msg)
{
GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg);
server_reschedule (s->plugin, GNUNET_YES);
* @param tc task context
*/
static void
-server_v4_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+server_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
+
GNUNET_assert (cls != NULL);
plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
if (plugin->server_v4 != NULL)
- plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, GNUNET_NO);
+ plugin->server_v4_task =
+ server_schedule (plugin, plugin->server_v4, GNUNET_NO);
}
* @param tc task context
*/
static void
-server_v6_run (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
+
GNUNET_assert (cls != NULL);
plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
if (plugin->server_v6 != NULL)
- plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, GNUNET_NO);
+ plugin->server_v6_task =
+ server_schedule (plugin, plugin->server_v6, GNUNET_NO);
}
/**
* @return gnunet task identifier
*/
static GNUNET_SCHEDULER_TaskIdentifier
-server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now)
+server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle,
+ int now)
{
GNUNET_SCHEDULER_TaskIdentifier ret;
fd_set rs;
GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
haveto = MHD_get_timeout (daemon_handle, &timeout);
if (haveto == MHD_YES)
- {
+ {
if (timeout != last_timeout)
{
#if VERBOSE_SERVER
last_timeout = timeout;
}
tv.rel_value = (uint64_t) timeout;
- }
+ }
else
tv = GNUNET_TIME_UNIT_SECONDS;
/* Force immediate run, since we have outbound data to send */
if (res == GNUNET_SYSERR)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Could not load or create server certificate! Loading plugin failed!\n");
+ "Could not load or create server certificate! Loading plugin failed!\n");
return res;
}
#endif
#if MHD_VERSION >= 0x00090E00
timeout = GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT.rel_value / 1000;
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "MHD can set timeout per connection! Default time out %u sec.\n", timeout);
+ "MHD can set timeout per connection! Default time out %u sec.\n",
+ timeout);
#else
timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000;
GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
- "MHD cannot set timeout per connection! Default time out %u sec.\n", timeout);
+ "MHD cannot set timeout per connection! Default time out %u sec.\n",
+ timeout);
#endif
plugin->server_v4 = NULL;
if (plugin->ipv4 == GNUNET_YES)
plugin->cert,
#endif
MHD_OPTION_CONNECTION_TIMEOUT,
- timeout ,
+ timeout,
MHD_OPTION_CONNECTION_MEMORY_LIMIT,
(size_t) (2 *
GNUNET_SERVER_MAX_MESSAGE_SIZE),
if ((plugin->ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Failed to start %s IPv4 server component on port %u\n", plugin->name,
- plugin->port);
+ "Failed to start %s IPv4 server component on port %u\n",
+ plugin->name, plugin->port);
return GNUNET_SYSERR;
}
if ((plugin->ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Failed to start %s IPv6 server component on port %u\n", plugin->name,
- plugin->port);
+ "Failed to start %s IPv6 server component on port %u\n",
+ plugin->name, plugin->port);
return GNUNET_SYSERR;
}
struct Session *t = NULL;
struct MHD_Daemon *server_v4_tmp = plugin->server_v4;
+
plugin->server_v4 = NULL;
struct MHD_Daemon *server_v6_tmp = plugin->server_v6;
+
plugin->server_v6 = NULL;
if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
typedef struct MacAdress
{
- uint8_t mac[6];
-}MacAdress;
+ uint8_t mac[6];
+} MacAdress;
//praeamble
-static const struct char praeambel[56] =
-{{1,0,1,0,10,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}};
+static const struct char praeambel[56] =
+ { {1, 0, 1, 0, 10, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
+ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
+ 0, 1, 0, 1, 0, 1, 0}
+};
//start of frame
-static const struct char sof[8]=
-{{1,0,1,0,1,0,1,1}}
+static const struct char sof[8] = { {1, 0, 1, 0, 1, 0, 1, 1} }
// broadcast mac
static const struct MacAddress bc_all_mac =
- { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } };
+ { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
//crc polynom
static const struct char ploynom[32] =
- {{1,1,1,0,1,1,0,1,1,0,1,1,1,0,0,0,1,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1}};
+ { {1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1,
+ 0, 0, 1, 0, 0, 0, 0, 1}
+};
#endif
GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
session->pending_messages_tail, pos);
GNUNET_assert (size >= pos->message_size);
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "tcp",
- "Transmitting message of type %u\n",
- ntohs (((struct GNUNET_MessageHeader*)pos->msg)->type));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
+ "Transmitting message of type %u\n",
+ ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type));
/* FIXME: this memcpy can be up to 7% of our total runtime */
memcpy (cbuf, pos->msg, pos->message_size);
cbuf += pos->message_size;
{
if (addrlen == sizeof (struct IPv6TcpAddress))
{
- GNUNET_assert (NULL != addr); /* make static analysis happy */
+ GNUNET_assert (NULL != addr); /* make static analysis happy */
t6 = addr;
af = AF_INET6;
memset (&a6, 0, sizeof (a6));
}
else if (addrlen == sizeof (struct IPv4TcpAddress))
{
- GNUNET_assert (NULL != addr); /* make static analysis happy */
+ GNUNET_assert (NULL != addr); /* make static analysis happy */
t4 = addr;
af = AF_INET;
memset (&a4, 0, sizeof (a4));
/* append pm to pending_messages list */
GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
- session->pending_messages_tail, pm);
+ session->pending_messages_tail, pm);
GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
(plugin->nat_wait_conns, &target->hashPubKey, session,
/* check if session is valid */
struct Session *ses = plugin->sessions;
- if (0 != memcmp (target,
- &session->target,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 !=
+ memcmp (target, &session->target, sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Got session %p for `%s', but should be for peer `%s'!\n",
- session,
- GNUNET_i2s (&session->target),
- GNUNET_h2s (&target->hashPubKey));
+ "Got session %p for `%s', but should be for peer `%s'!\n",
+ session, GNUNET_i2s (&session->target),
+ GNUNET_h2s (&target->hashPubKey));
return -1;
}
/* append pm to pending_messages list */
GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
- session->pending_messages_tail, pm);
+ session->pending_messages_tail, pm);
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
"Asked to transmit %u bytes to `%s', added message to list.\n",
distance.value = htonl (1);
delay =
plugin->env->receive (plugin->env->cls, &session->target, message,
- (const struct GNUNET_ATS_Information *)
- &distance, 1, session,
+ (const struct GNUNET_ATS_Information *) &distance,
+ 1, session,
(GNUNET_YES ==
session->inbound) ? NULL : session->connect_addr,
(GNUNET_YES ==
/**
* Message header.
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_MessageHeader header;
/**
* What is the identity of the sender
*/
- struct GNUNET_PeerIdentity sender;
+ struct GNUNET_PeerIdentity sender;
};
struct PeerSessionIteratorContext
{
- struct Session * result;
- const void * addr;
+ struct Session *result;
+ const void *addr;
size_t addrlen;
};
}
-static int
-inbound_session_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+inbound_session_iterator (void *cls, const GNUNET_HashCode * key, void *value)
{
struct PeerSessionIteratorContext *psc = cls;
struct Session *s = value;
+
if (s->addrlen == psc->addrlen)
{
if (0 == memcmp (&s[1], psc->addr, s->addrlen))
*/
static struct Session *
find_inbound_session (struct Plugin *plugin,
- const struct GNUNET_PeerIdentity *peer,
- const void * addr, size_t addrlen)
+ const struct GNUNET_PeerIdentity *peer, const void *addr,
+ size_t addrlen)
{
struct PeerSessionIteratorContext psc;
+
psc.result = NULL;
psc.addrlen = addrlen;
psc.addr = addr;
- GNUNET_CONTAINER_multihashmap_get_multiple(plugin->inbound_sessions, &peer->hashPubKey, &inbound_session_iterator, &psc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (plugin->inbound_sessions,
+ &peer->hashPubKey,
+ &inbound_session_iterator, &psc);
return psc.result;
}
-static int
-inbound_session_by_addr_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+inbound_session_by_addr_iterator (void *cls, const GNUNET_HashCode * key,
+ void *value)
{
struct PeerSessionIteratorContext *psc = cls;
struct Session *s = value;
+
if (s->addrlen == psc->addrlen)
{
if (0 == memcmp (&s[1], psc->addr, s->addrlen))
* @return NULL if we have no session
*/
static struct Session *
-find_inbound_session_by_addr (struct Plugin *plugin, const void * addr, size_t addrlen)
+find_inbound_session_by_addr (struct Plugin *plugin, const void *addr,
+ size_t addrlen)
{
struct PeerSessionIteratorContext psc;
+
psc.result = NULL;
psc.addrlen = addrlen;
psc.addr = addr;
- GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &inbound_session_by_addr_iterator, &psc);
+ GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions,
+ &inbound_session_by_addr_iterator,
+ &psc);
return psc.result;
}
struct Session *s = value;
if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(s->invalidation_task);
+ GNUNET_SCHEDULER_cancel (s->invalidation_task);
if (GNUNET_SCHEDULER_NO_TASK != s->delayed_cont_task)
GNUNET_SCHEDULER_cancel (s->delayed_cont_task);
GNUNET_free (s);
session));
GNUNET_CONTAINER_multihashmap_get_multiple (plugin->inbound_sessions,
- &target->hashPubKey,
- &destroy_inbound_session, NULL);
+ &target->hashPubKey,
+ &destroy_inbound_session, NULL);
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "UDP DISCONNECT\n");
+ LOG (GNUNET_ERROR_TYPE_ERROR, "UDP DISCONNECT\n");
plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag);
if (GNUNET_SCHEDULER_NO_TASK != session->delayed_cont_task)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
LOG (GNUNET_ERROR_TYPE_ERROR,
- "UDP transmited %u-byte message to %s (%d: %s)\n",
- (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen),
- (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
+ "UDP transmited %u-byte message to %s (%d: %s)\n",
+ (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
+ (sent < 0) ? STRERROR (errno) : "ok");
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP transmited %u-byte message to %s (%d: %s)\n",
- (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen),
- (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
+ "UDP transmited %u-byte message to %s (%d: %s)\n",
+ (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
+ (sent < 0) ? STRERROR (errno) : "ok");
return sent;
}
static struct Session *
create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
- const void *addr, size_t addrlen,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
+ const void *addr, size_t addrlen,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
- struct Session * peer_session;
+ struct Session *peer_session;
const struct IPv4UdpAddress *t4;
const struct IPv6UdpAddress *t6;
struct sockaddr_in *v4;
}
t4 = addr;
peer_session =
- GNUNET_malloc (sizeof (struct Session) +
- sizeof (struct sockaddr_in));
+ GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in));
len = sizeof (struct sockaddr_in);
v4 = (struct sockaddr_in *) &peer_session[1];
v4->sin_family = AF_INET;
}
t6 = addr;
peer_session =
- GNUNET_malloc (sizeof (struct Session) +
- sizeof (struct sockaddr_in6));
+ GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6));
len = sizeof (struct sockaddr_in6);
v6 = (struct sockaddr_in6 *) &peer_session[1];
v6->sin6_family = AF_INET6;
static void
-udp_call_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+udp_call_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Session *s = cls;
GNUNET_TRANSPORT_TransmitContinuation cont = s->cont;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n",
- msgbuf_size, GNUNET_i2s (target),
- udp_address_to_string (NULL, addr, addrlen),
- session, force_address);
+ "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n",
+ msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr,
+ addrlen),
+ session, force_address);
if ((force_address == GNUNET_SYSERR) && (session == NULL))
return GNUNET_SYSERR;
if ((session != NULL) && (addr != NULL) && (addrlen != 0))
{
s = session;
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value (
- plugin->inbound_sessions, &target->hashPubKey, s));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_contains_value
+ (plugin->inbound_sessions, &target->hashPubKey, s));
- if (0 != memcmp (&s->target, target, sizeof (struct GNUNET_PeerIdentity)))
+ if (0 != memcmp (&s->target, target, sizeof (struct GNUNET_PeerIdentity)))
return GNUNET_SYSERR;
switch (addrlen)
{
if (s->addrlen != (sizeof (struct sockaddr_in)))
return GNUNET_SYSERR;
struct sockaddr_in *a4 = (struct sockaddr_in *) s->sock_addr;
+
GNUNET_assert (a4->sin_port == t4->u4_port);
- GNUNET_assert (0 == memcmp(&a4->sin_addr, &t4->ipv4_addr, sizeof (struct in_addr)));
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Session 0x%X successfully checked!\n", session);
+ GNUNET_assert (0 ==
+ memcmp (&a4->sin_addr, &t4->ipv4_addr,
+ sizeof (struct in_addr)));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Session 0x%X successfully checked!\n",
+ session);
break;
case sizeof (struct IPv6UdpAddress):
if (NULL == plugin->sockv6)
t6 = addr;
GNUNET_assert (s->addrlen == sizeof (struct sockaddr_in6));
struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) s->sock_addr;
+
GNUNET_assert (a6->sin6_port == t6->u6_port);
- GNUNET_assert (0 == memcmp(&a6->sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)));
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Session 0x%X successfully checked!\n", session);
+ GNUNET_assert (0 ==
+ memcmp (&a6->sin6_addr, &t6->ipv6_addr,
+ sizeof (struct in6_addr)));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Session 0x%X successfully checked!\n",
+ session);
break;
default:
/* Must have a valid address to send to */
udp->sender = *plugin->env->my_identity;
memcpy (&udp[1], msgbuf, msgbuf_size);
- if (s != NULL)
+ if (s != NULL)
delta = GNUNET_TIME_absolute_get_remaining (s->flow_delay_from_other_peer);
else
delta = GNUNET_TIME_UNIT_ZERO;
mlen = udp_send (plugin, peer_session->sock_addr, &udp->header);
if (cont != NULL)
{
- if ( (delta.rel_value > 0) &&
- (mlen > 0) )
+ if ((delta.rel_value > 0) && (mlen > 0))
{
- s->cont = cont;
- s->cont_cls = cont_cls;
- s->delayed_cont_task = GNUNET_SCHEDULER_add_delayed (delta,
- &udp_call_continuation,
- s);
+ s->cont = cont;
+ s->cont_cls = cont_cls;
+ s->delayed_cont_task =
+ GNUNET_SCHEDULER_add_delayed (delta, &udp_call_continuation, s);
}
else
- cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR);
+ cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR);
}
GNUNET_free_non_null (peer_session);
}
*/
size_t args;
- struct Session * session;
+ struct Session *session;
};
distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
distance.value = htonl (1);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Giving Session %X %s to transport\n", si->session, GNUNET_i2s(&si->session->target));
- delay = plugin->env->receive (plugin->env->cls, &si->sender, hdr, &distance, 1, si->session,
- si->arg, si->args);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving Session %X %s to transport\n",
+ si->session, GNUNET_i2s (&si->session->target));
+ delay =
+ plugin->env->receive (plugin->env->cls, &si->sender, hdr, &distance, 1,
+ si->session, si->arg, si->args);
si->session->flow_delay_for_other_peer = delay;
}
static void
invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Session * s = cls;
- s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Session %X (`%s') is now invalid\n", s, GNUNET_a2s (s->sock_addr,s->addrlen));
+ struct Session *s = cls;
- s->plugin->env->session_end(s->plugin->env->cls, &s->target, s);
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(s->plugin->inbound_sessions, &s->target.hashPubKey, s));
+ s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Session %X (`%s') is now invalid\n", s,
+ GNUNET_a2s (s->sock_addr, s->addrlen));
+
+ s->plugin->env->session_end (s->plugin->env->cls, &s->target, s);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (s->
+ plugin->inbound_sessions,
+ &s->target.hashPubKey,
+ s));
GNUNET_free (s);
}
}
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received message with %u bytes from peer `%s' at `%s'\n",
- (unsigned int) ntohs (msg->header.size),
- GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr,
- sender_addr_len));
+ "Received message with %u bytes from peer `%s' at `%s'\n",
+ (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
+ GNUNET_a2s (sender_addr, sender_addr_len));
#endif
/* create a session for inbound connections */
- const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg;
+ const struct UDPMessage *udp_msg = (const struct UDPMessage *) msg;
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Lookup inbound UDP sessions for peer `%s' address `%s'\n",
- GNUNET_i2s (&udp_msg->sender),
- udp_address_to_string(NULL, arg, args));
+ "Lookup inbound UDP sessions for peer `%s' address `%s'\n",
+ GNUNET_i2s (&udp_msg->sender), udp_address_to_string (NULL, arg, args));
- struct Session * s = NULL;
- s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len);
+ struct Session *s = NULL;
+
+ s = find_inbound_session (plugin, &udp_msg->sender, sender_addr,
+ sender_addr_len);
if (s != NULL)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
- s,
- GNUNET_i2s (&s->target),
- udp_address_to_string(NULL, arg, args));
+ "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
+ s, GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
}
else
{
s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
- s,
- GNUNET_i2s (&s->target),
- udp_address_to_string(NULL, arg, args));
-
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->inbound_sessions,
- &s->target.hashPubKey,
- s,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", s,
+ GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (plugin->inbound_sessions,
+ &s->target.hashPubKey, s,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
}
- s->valid_until = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ s->valid_until =
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(s->invalidation_task);
+ GNUNET_SCHEDULER_cancel (s->invalidation_task);
s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Rescheduling %X' `%s'\n",
- s, udp_address_to_string(NULL, arg, args));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Rescheduling %X' `%s'\n", s,
+ udp_address_to_string (NULL, arg, args));
}
- s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, s);
+ s->invalidation_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &invalidation_task, s);
/* iterate over all embedded messages */
si.sender = msg->sender;
si.arg = arg;
uint32_t delay = 0;
struct Session *s;
+
s = find_inbound_session_by_addr (rc->plugin, rc->src_addr, rc->addr_len);
if (s != NULL)
{
#if DEBUG_UDP
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK to `%s' including delay of %u ms\n",
- GNUNET_a2s (rc->src_addr,
- (rc->src_addr->sa_family ==
- AF_INET) ? sizeof (struct sockaddr_in) :
- sizeof (struct sockaddr_in6)),
- delay);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending ACK to `%s' including delay of %u ms\n",
+ GNUNET_a2s (rc->src_addr,
+ (rc->src_addr->sa_family ==
+ AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct
+ sockaddr_in6)),
+ delay);
#endif
udp_ack = (struct UDP_ACK_Message *) buf;
udp_ack->header.size = htons ((uint16_t) msize);
*/
socklen_t addr_len;
- struct Session * session;
+ struct Session *session;
};
struct ReceiveContext *rc;
struct GNUNET_TIME_Absolute now;
struct FindReceiveContext frc;
- struct Session * s = NULL;
+ struct Session *s = NULL;
struct GNUNET_TIME_Relative flow_delay;
fromlen = sizeof (addr);
msg = (const struct GNUNET_MessageHeader *) buf;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret,
- GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs(msg->type));
+ "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret,
+ GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type));
if (ret != ntohs (msg->size))
{
return;
}
udp_ack = (const struct UDP_ACK_Message *) msg;
- s = find_inbound_session(plugin, &udp_ack->sender, addr, fromlen);
+ s = find_inbound_session (plugin, &udp_ack->sender, addr, fromlen);
if (s != NULL)
{
- flow_delay.rel_value = (uint64_t) ntohl(udp_ack->delay);
+ flow_delay.rel_value = (uint64_t) ntohl (udp_ack->delay);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "We received a sending delay of %llu\n", flow_delay.rel_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "We received a sending delay of %llu\n",
+ flow_delay.rel_value);
- s->flow_delay_from_other_peer = GNUNET_TIME_relative_to_absolute (flow_delay);
+ s->flow_delay_from_other_peer =
+ GNUNET_TIME_relative_to_absolute (flow_delay);
}
ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
- if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message))
+ if (ntohs (ack->size) !=
+ ntohs (msg->size) - sizeof (struct UDP_ACK_Message))
{
GNUNET_break_op (0);
return;
}
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
- (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender),
- GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
+ "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
+ (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender),
+ GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
#endif
peer_session = find_session (plugin, &udp_ack->sender);
{
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Session for ACK not found, dropping ACK!\n");
+ "Session for ACK not found, dropping ACK!\n");
#endif
return;
}
now.abs_value);
}
#if DEBUG_UDP
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP processes %u-byte fragment from `%s'\n",
- (unsigned int) ntohs (msg->size),
- GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n",
+ (unsigned int) ntohs (msg->size),
+ GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
#endif
if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg))
struct MstContext
{
- struct Plugin * plugin;
+ struct Plugin *plugin;
struct IPv4UdpAddress addr;
};
-void udp_broadcast_mst_cb (void *cls, void *client,
- const struct
- GNUNET_MessageHeader *
- message)
+void
+udp_broadcast_mst_cb (void *cls, void *client,
+ const struct GNUNET_MessageHeader *message)
{
- struct Plugin * plugin = cls;
- struct MstContext * mc = client;
- const struct GNUNET_MessageHeader* hello;
- struct UDP_Beacon_Message * msg;
+ struct Plugin *plugin = cls;
+ struct MstContext *mc = client;
+ const struct GNUNET_MessageHeader *hello;
+ struct UDP_Beacon_Message *msg;
+
msg = (struct UDP_Beacon_Message *) message;
- if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON != ntohs(msg->header.type))
+ if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON !=
+ ntohs (msg->header.type))
return;
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Received beacon with %u bytes from peer `%s' via address `%s'\n",
- ntohs(msg->header.size),
- GNUNET_i2s (&msg->sender),
- udp_address_to_string(NULL, &mc->addr, sizeof (mc->addr)));
+ "Received beacon with %u bytes from peer `%s' via address `%s'\n",
+ ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
+ udp_address_to_string (NULL, &mc->addr, sizeof (mc->addr)));
struct GNUNET_ATS_Information ats;
+
ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
ats.value = htonl (1);
hello = (struct GNUNET_MessageHeader *) &msg[1];
- plugin->env->receive (plugin->env->cls, &msg->sender, hello, &ats, 1, NULL, (const char *) &mc->addr, sizeof (mc->addr));
+ plugin->env->receive (plugin->env->cls, &msg->sender, hello, &ats, 1, NULL,
+ (const char *) &mc->addr, sizeof (mc->addr));
- GNUNET_STATISTICS_update(plugin->env->stats,
- _("# HELLO beacons received via udp"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# HELLO beacons received via udp"), 1,
+ GNUNET_NO);
GNUNET_free (mc);
}
char addr[32];
char buf[65536];
ssize_t ret;
- struct MstContext * mc;
+ struct MstContext *mc;
fromlen = sizeof (addr);
memset (&addr, 0, sizeof (addr));
- ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), (struct sockaddr *) &addr, &fromlen);
+ ret =
+ GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf),
+ (struct sockaddr *) &addr, &fromlen);
if (ret < sizeof (struct GNUNET_MessageHeader))
{
/* malformed beacon, just throw it away */
return;
}
- mc = GNUNET_malloc(sizeof (struct MstContext));
+ mc = GNUNET_malloc (sizeof (struct MstContext));
+
+ struct sockaddr_in *av4 = (struct sockaddr_in *) &addr;
- struct sockaddr_in * av4 = (struct sockaddr_in *) &addr;
mc->addr.ipv4_addr = av4->sin_addr.s_addr;
mc->addr.u4_port = av4->sin_port;
- if (GNUNET_OK != GNUNET_SERVER_mst_receive(plugin->broadcast_mst, mc, buf, ret, GNUNET_NO, GNUNET_NO))
+ if (GNUNET_OK !=
+ GNUNET_SERVER_mst_receive (plugin->broadcast_mst, mc, buf, ret, GNUNET_NO,
+ GNUNET_NO))
GNUNET_free (mc);
}
static void
-udp_broadcast_send (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+udp_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Plugin * plugin = cls;
+ struct Plugin *plugin = cls;
int sent;
uint16_t msg_size;
uint16_t hello_size;
char buf[65536];
+
// /ssize_t ret;
const struct GNUNET_MessageHeader *hello;
- struct UDP_Beacon_Message * msg;
+ struct UDP_Beacon_Message *msg;
plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
struct sockaddr_in baddr;
+
baddr.sin_family = AF_INET;
baddr.sin_port = htons (plugin->broadcast_port);
- baddr.sin_addr.s_addr=htonl(-1); /* send message to 255.255.255.255 */
+ baddr.sin_addr.s_addr = htonl (-1); /* send message to 255.255.255.255 */
hello = plugin->env->get_our_hello ();
hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
msg_size = hello_size + sizeof (struct UDP_Beacon_Message);
- if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||(msg_size > (UDP_MTU)))
+ if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||
+ (msg_size > (UDP_MTU)))
return;
msg = (struct UDP_Beacon_Message *) buf;
msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
memcpy (&msg[1], hello, hello_size);
- sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size,
- (const struct sockaddr *) &baddr, sizeof (struct sockaddr_in));
+ sent =
+ GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size,
+ (const struct sockaddr *) &baddr,
+ sizeof (struct sockaddr_in));
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sent HELLO beacon broadcast with %i bytes\n", sent);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent HELLO beacon broadcast with %i bytes\n",
+ sent);
- plugin->send_broadcast_task = GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, &udp_broadcast_send, plugin);
+ plugin->send_broadcast_task =
+ GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
+ &udp_broadcast_send, plugin);
}
* @param tc the scheduling context (for rescheduling this function again)
*/
static void
-udp_plugin_broadcast_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+udp_plugin_broadcast_select (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
plugin->select_broadcast_task =
GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs,
- NULL, &udp_plugin_broadcast_select, plugin);
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->broadcast_rs, NULL,
+ &udp_plugin_broadcast_select, plugin);
}
}
inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
- buf, port);
+ buf, port);
return rbuf;
}
&port))
port = 2086;
- broadcast = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", "BROADCAST");
- if (broadcast == GNUNET_SYSERR)
- broadcast = GNUNET_NO;
+ broadcast =
+ GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp",
+ "BROADCAST");
+ if (broadcast == GNUNET_SYSERR)
+ broadcast = GNUNET_NO;
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp", "BROADCAST_INTERVAL", &interval))
- interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp",
+ "BROADCAST_INTERVAL", &interval))
+ interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "BROADCAST_PORT",
- &bport))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
+ "BROADCAST_PORT", &bport))
bport = 20086;
if (GNUNET_OK !=
if (port > 65535)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Given `%s' option is out of range: %llu > %u\n"), "PORT",
- port, 65535);
+ _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port,
+ 65535);
return NULL;
}
memset (&serverAddrv6, 0, sizeof (serverAddrv6));
"BINDTO", &plugin->bind4_address))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Binding udp plugin to specific address: `%s'\n",
- plugin->bind4_address);
+ "Binding udp plugin to specific address: `%s'\n",
+ plugin->bind4_address);
if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr))
{
GNUNET_free (plugin->bind4_address);
"BINDTO6", &plugin->bind6_address))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Binding udp plugin to specific address: `%s'\n",
- plugin->bind6_address);
+ "Binding udp plugin to specific address: `%s'\n",
+ plugin->bind6_address);
if (1 !=
inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr))
{
LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
- plugin->bind6_address);
+ plugin->bind6_address);
GNUNET_free_non_null (plugin->bind4_address);
GNUNET_free (plugin->bind6_address);
GNUNET_free (plugin);
serverAddr = (struct sockaddr *) &serverAddrv6;
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
- ntohs (serverAddrv6.sin6_port));
+ ntohs (serverAddrv6.sin6_port));
#endif
tries = 0;
while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) !=
serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "IPv6 Binding failed, trying new port %d\n",
- ntohs (serverAddrv6.sin6_port));
+ "IPv6 Binding failed, trying new port %d\n",
+ ntohs (serverAddrv6.sin6_port));
#endif
tries++;
if (tries > 10)
serverAddr = (struct sockaddr *) &serverAddrv4;
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
- ntohs (serverAddrv4.sin_port));
+ ntohs (serverAddrv4.sin_port));
#endif
tries = 0;
while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
{
serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
#if DEBUG_UDP
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "IPv4 Binding failed, trying new port %d\n",
- ntohs (serverAddrv4.sin_port));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n",
+ ntohs (serverAddrv4.sin_port));
#endif
tries++;
if (tries > 10)
/* create broadcast socket */
if (broadcast)
{
- plugin->sockv4_broadcast = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
+ plugin->sockv4_broadcast =
+ GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
if (NULL == plugin->sockv4_broadcast)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
}
else
{
- #if HAVE_SOCKADDR_IN_SIN_LEN
+#if HAVE_SOCKADDR_IN_SIN_LEN
serverAddrv4.sin_len = sizeof (serverAddrv4);
- #endif
+#endif
serverAddrv4.sin_family = AF_INET;
serverAddrv4.sin_addr.s_addr = INADDR_ANY;
serverAddrv4.sin_port = htons (plugin->broadcast_port);
addrlen = sizeof (serverAddrv4);
serverAddr = (struct sockaddr *) &serverAddrv4;
- #if DEBUG_UDP
- #endif
+#if DEBUG_UDP
+#endif
LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding Broadcast to IPv4 port %d\n",
- ntohs (serverAddrv4.sin_port));
+ ntohs (serverAddrv4.sin_port));
- if (GNUNET_NETWORK_socket_bind (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK)
+ if (GNUNET_NETWORK_socket_bind
+ (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to create IPv4 broadcast socket on port %d\n"),
- ntohs (serverAddrv4.sin_port));
- GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast);
- plugin->sockv4_broadcast = NULL;
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to create IPv4 broadcast socket on port %d\n"),
+ ntohs (serverAddrv4.sin_port));
+ GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast);
+ plugin->sockv4_broadcast = NULL;
}
if (plugin->sockv4_broadcast != NULL)
{
int yes = 1;
- if (GNUNET_NETWORK_socket_setsockopt (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(int)) != GNUNET_OK)
+
+ if (GNUNET_NETWORK_socket_setsockopt
+ (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes,
+ sizeof (int)) != GNUNET_OK)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
- ntohs (serverAddrv4.sin_port));
- GNUNET_NETWORK_socket_close(plugin->sockv4_broadcast);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
+ ntohs (serverAddrv4.sin_port));
+ GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast);
plugin->sockv4_broadcast = NULL;
}
else
{
plugin->broadcast_rs = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_set (plugin->broadcast_rs, plugin->sockv4_broadcast);
+ GNUNET_NETWORK_fdset_set (plugin->broadcast_rs,
+ plugin->sockv4_broadcast);
}
}
}
if (plugin->sockv4_broadcast != NULL)
{
plugin->broadcast = GNUNET_YES;
- plugin->broadcast_mst = GNUNET_SERVER_mst_create (udp_broadcast_mst_cb, plugin);
- GNUNET_STATISTICS_update(plugin->env->stats,
- _("# HELLO beacons received via udp"), 1, GNUNET_NO);
+ plugin->broadcast_mst =
+ GNUNET_SERVER_mst_create (udp_broadcast_mst_cb, plugin);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# HELLO beacons received via udp"), 1,
+ GNUNET_NO);
plugin->select_broadcast_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs,
- NULL, &udp_plugin_broadcast_select, plugin);
-
- plugin->send_broadcast_task = GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->broadcast_rs, NULL,
+ &udp_plugin_broadcast_select, plugin);
+
+ plugin->send_broadcast_task =
+ GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin);
}
else
plugin->broadcast = GNUNET_NO;
NULL);
GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
plugin->sessions = NULL;
- GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_inbound_session,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions,
+ &destroy_inbound_session, NULL);
GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions);
plugin->inbound_sessions = NULL;
while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
GNUNET_SCHEDULER_cancel (plugin->select_broadcast_task);
plugin->select_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
}
- if (plugin->send_broadcast_task != GNUNET_SCHEDULER_NO_TASK)
+ if (plugin->send_broadcast_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel (plugin->send_broadcast_task );
- plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_cancel (plugin->send_broadcast_task);
+ plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
}
if (plugin->broadcast_mst != NULL)
- GNUNET_SERVER_mst_destroy(plugin->broadcast_mst);
+ GNUNET_SERVER_mst_destroy (plugin->broadcast_mst);
if (plugin->sockv4_broadcast != NULL)
{
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast));
plugin->sockv4_broadcast = NULL;
}
GNUNET_NETWORK_fdset_destroy (plugin->broadcast_rs);
};
-int delete_session_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+int
+delete_session_iterator (void *cls, const GNUNET_HashCode * key, void *value)
{
struct Session *s = (struct Session *) value;
+
if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(s->invalidation_task);
+ GNUNET_SCHEDULER_cancel (s->invalidation_task);
s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
}
- GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, key, s);
+ GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions, key, s);
GNUNET_free (s);
return GNUNET_YES;
}
+
/**
* Disconnect from a remote node. Clean up session if we have one for this peer
*
{
struct Plugin *plugin = cls;
- GNUNET_CONTAINER_multihashmap_get_multiple(plugin, &target->hashPubKey, &delete_session_iterator, NULL);
+ GNUNET_CONTAINER_multihashmap_get_multiple (plugin, &target->hashPubKey,
+ &delete_session_iterator, NULL);
}
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
LOG (GNUNET_ERROR_TYPE_ERROR,
- "UDP transmited %u-byte message to %s (%d: %s)\n",
- (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen),
- (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
+ "UDP transmited %u-byte message to %s (%d: %s)\n",
+ (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
+ (sent < 0) ? STRERROR (errno) : "ok");
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP transmited %u-byte message to %s (%d: %s)\n",
- (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen),
- (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
+ "UDP transmited %u-byte message to %s (%d: %s)\n",
+ (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
+ (sent < 0) ? STRERROR (errno) : "ok");
return sent;
}
static struct Session *
create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
- const void *addr, size_t addrlen,
- GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
+ const void *addr, size_t addrlen,
+ GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
- struct Session * s;
+ struct Session *s;
const struct IPv4UdpAddress *t4;
const struct IPv6UdpAddress *t6;
struct sockaddr_in *v4;
return NULL;
}
t4 = addr;
- s =
- GNUNET_malloc (sizeof (struct Session) +
- sizeof (struct sockaddr_in));
+ s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in));
len = sizeof (struct sockaddr_in);
v4 = (struct sockaddr_in *) &s[1];
v4->sin_family = AF_INET;
return NULL;
}
t6 = addr;
- s =
- GNUNET_malloc (sizeof (struct Session) +
- sizeof (struct sockaddr_in6));
+ s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6));
len = sizeof (struct sockaddr_in6);
v6 = (struct sockaddr_in6 *) &s[1];
v6->sin6_family = AF_INET6;
static void
invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct Session * s = cls;
- s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Session %X (`%s') is now invalid\n", s, GNUNET_a2s (s->sock_addr,s->addrlen));
+ struct Session *s = cls;
- s->plugin->env->session_end(s->plugin->env->cls, &s->target, s);
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, &s->target.hashPubKey, s));
+ s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Session %X (`%s') is now invalid\n", s,
+ GNUNET_a2s (s->sock_addr, s->addrlen));
+
+ s->plugin->env->session_end (s->plugin->env->cls, &s->target, s);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions,
+ &s->target.hashPubKey,
+ s));
GNUNET_free (s);
}
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n",
- msgbuf_size, GNUNET_i2s (target),
- udp_address_to_string (NULL, addr, addrlen),
- session, force_address);
+ "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n",
+ msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr,
+ addrlen),
+ session, force_address);
/* no valid address given */
if ((addr = NULL) || (addrlen == 0))
if (force_address == GNUNET_SYSERR)
return GNUNET_SYSERR;
/* create new session */
- s = create_session(plugin, target, addr, addrlen, cont, cont_cls);
- GNUNET_CONTAINER_multihashmap_put(plugin->sessions, &target->hashPubKey, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ s = create_session (plugin, target, addr, addrlen, cont, cont_cls);
+ GNUNET_CONTAINER_multihashmap_put (plugin->sessions, &target->hashPubKey, s,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
/* schedule invalidation task */
- s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, NULL);
+ s->invalidation_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &invalidation_task, NULL);
}
/* Message */
udp->sender = *plugin->env->my_identity;
memcpy (&udp[1], msgbuf, msgbuf_size);
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+
if (s->flow_delay_from_other_peer.abs_value > now.abs_value)
{
- struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->flow_delay_from_other_peer);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "We try to send to early! Should in %llu!\n", delta.rel_value);
+ struct GNUNET_TIME_Relative delta =
+ GNUNET_TIME_absolute_get_difference (now,
+ s->flow_delay_from_other_peer);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "We try to send to early! Should in %llu!\n",
+ delta.rel_value);
}
else
LOG (GNUNET_ERROR_TYPE_DEBUG, "We can send!\n");
/* send with fragmentation */
else
{
- s->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU,
+ s->frag =
+ GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU,
&plugin->tracker,
plugin->last_expected_delay,
- &udp->header, &send_fragment,
- s);
+ &udp->header, &send_fragment, s);
}
return mlen;
}
const struct GNUNET_MessageHeader *hdr)
{
struct Plugin *plugin = cls;
- struct Session * s = client;
+ struct Session *s = client;
struct GNUNET_ATS_Information distance;
struct GNUNET_TIME_Relative delay;
distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
distance.value = htonl (1);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Giving Session %X %s to transport\n", s->session, GNUNET_i2s(&s->target));
- delay = plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s,
- // FIXME: USE UDP ADDRESSES!!!!
- s->sock_addr, s->addrlen);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving Session %X %s to transport\n",
+ s->session, GNUNET_i2s (&s->target));
+ delay =
+ plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s,
+ // FIXME: USE UDP ADDRESSES!!!!
+ s->sock_addr, s->addrlen);
s->flow_delay_for_other_peer = delay;
}
}
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received message with %u bytes from peer `%s' at `%s'\n",
- (unsigned int) ntohs (msg->header.size),
- GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr,
- sender_addr_len));
+ "Received message with %u bytes from peer `%s' at `%s'\n",
+ (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
+ GNUNET_a2s (sender_addr, sender_addr_len));
#endif
- const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg;
+ const struct UDPMessage *udp_msg = (const struct UDPMessage *) msg;
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Lookup inbound UDP sessions for peer `%s' address `%s'\n",
- GNUNET_i2s (&udp_msg->sender),
- udp_address_to_string(NULL, arg, args));
+ "Lookup inbound UDP sessions for peer `%s' address `%s'\n",
+ GNUNET_i2s (&udp_msg->sender), udp_address_to_string (NULL, arg, args));
/* create a session for inbound connections */
- struct Session * s = NULL;
- s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len);
+ struct Session *s = NULL;
+
+ s = find_inbound_session (plugin, &udp_msg->sender, sender_addr,
+ sender_addr_len);
if (s != NULL)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
- s,
- GNUNET_i2s (&s->target),
- udp_address_to_string(NULL, arg, args));
+ "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
+ s, GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
}
else
{
s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
- s,
- GNUNET_i2s (&s->target),
- udp_address_to_string(NULL, arg, args));
-
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->sessions,
- &s->target.hashPubKey,
- s,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", s,
+ GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (plugin->sessions,
+ &s->target.hashPubKey, s,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
}
- s->valid_until = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ s->valid_until =
+ GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(s->invalidation_task);
+ GNUNET_SCHEDULER_cancel (s->invalidation_task);
s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Rescheduling %X' `%s'\n",
- s, udp_address_to_string(NULL, arg, args));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Rescheduling %X' `%s'\n", s,
+ udp_address_to_string (NULL, arg, args));
}
- s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, s);
+ s->invalidation_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &invalidation_task, s);
/* we received from peer, so session is bidirectional and reliable */
s->bidirectional = GNUNET_YES;
struct ReceiveContext *rc;
struct GNUNET_TIME_Absolute now;
struct FindReceiveContext frc;
- struct Session * s = NULL;
+ struct Session *s = NULL;
struct GNUNET_TIME_Relative flow_delay;
fromlen = sizeof (addr);
msg = (const struct GNUNET_MessageHeader *) buf;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret,
- GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs(msg->type));
+ "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret,
+ GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type));
if (ret != ntohs (msg->size))
{
}
udp_ack = (const struct UDP_ACK_Message *) msg;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
- (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender),
- GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
+ "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
+ (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender),
+ GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
// TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right
s = guess_session (plugin->sessions, addr, addrlen);
if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack))
- // ... other stuff
- return;
+ // ... other stuff
+ return;
case GNUNET_MESSAGE_TYPE_FRAGMENT:
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP processes %u-byte fragment from `%s'\n",
- (unsigned int) ntohs (msg->size),
- GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n",
+ (unsigned int) ntohs (msg->size),
+ GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
// TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right
s = guess_session (plugin->sessions, addr, addrlen);
if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg))
- // other stuff
- return;
+ // other stuff
+ return;
default:
GNUNET_break_op (0);
return;
}
inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
- buf, port);
+ buf, port);
return rbuf;
}
if (port > 65535)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Given `%s' option is out of range: %llu > %u\n"), "PORT",
- port, 65535);
+ _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port,
+ 65535);
return NULL;
}
memset (&serverAddrv6, 0, sizeof (serverAddrv6));
"BINDTO", &plugin->bind4_address))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Binding udp plugin to specific address: `%s'\n",
- plugin->bind4_address);
+ "Binding udp plugin to specific address: `%s'\n",
+ plugin->bind4_address);
if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr))
{
GNUNET_free (plugin->bind4_address);
"BINDTO6", &plugin->bind6_address))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Binding udp plugin to specific address: `%s'\n",
- plugin->bind6_address);
+ "Binding udp plugin to specific address: `%s'\n",
+ plugin->bind6_address);
if (1 !=
inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr))
{
LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
- plugin->bind6_address);
+ plugin->bind6_address);
GNUNET_free_non_null (plugin->bind4_address);
GNUNET_free (plugin->bind6_address);
GNUNET_free (plugin);
serverAddr = (struct sockaddr *) &serverAddrv6;
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
- ntohs (serverAddrv6.sin6_port));
+ ntohs (serverAddrv6.sin6_port));
#endif
tries = 0;
while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) !=
serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "IPv6 Binding failed, trying new port %d\n",
- ntohs (serverAddrv6.sin6_port));
+ "IPv6 Binding failed, trying new port %d\n",
+ ntohs (serverAddrv6.sin6_port));
#endif
tries++;
if (tries > 10)
serverAddr = (struct sockaddr *) &serverAddrv4;
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
- ntohs (serverAddrv4.sin_port));
+ ntohs (serverAddrv4.sin_port));
#endif
tries = 0;
while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
{
serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
#if DEBUG_UDP
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "IPv4 Binding failed, trying new port %d\n",
- ntohs (serverAddrv4.sin_port));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n",
+ ntohs (serverAddrv4.sin_port));
#endif
tries++;
if (tries > 10)
NULL);
GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
plugin->sessions = NULL;
- GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_inbound_session,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions,
+ &destroy_inbound_session, NULL);
GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions);
plugin->inbound_sessions = NULL;
while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
un->sun_path);
#endif
plugin->env->receive (plugin->env->cls, sender, currhdr,
- (const struct GNUNET_ATS_Information *)
- &distance, 1, NULL, un->sun_path,
- strlen (un->sun_path) + 1);
+ (const struct GNUNET_ATS_Information *) &distance, 1,
+ NULL, un->sun_path, strlen (un->sun_path) + 1);
}
struct Sessionqueue *queue = cls;
GNUNET_assert (queue != NULL);
- GNUNET_assert(queue->content != NULL);
+ GNUNET_assert (queue->content != NULL);
queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
{
(queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
{
- GNUNET_assert(queue->content->mac != NULL);
- GNUNET_assert(queue->content->mac->plugin != NULL);
- GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats, _("# wlan session timeouts"), 1, GNUNET_NO);
+ GNUNET_assert (queue->content->mac != NULL);
+ GNUNET_assert (queue->content->mac->plugin != NULL);
+ GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats,
+ _("# wlan session timeouts"), 1, GNUNET_NO);
free_session (queue->content->mac->plugin, queue, GNUNET_YES);
}
else
{
GNUNET_assert (endpoint != NULL);
GNUNET_assert (plugin != NULL);
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1,
+ GNUNET_NO);
struct Sessionqueue *queue =
GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
plugin->pending_Sessions_tail, queue);
plugin->pendingsessions++;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
+ plugin->pendingsessions, GNUNET_NO);
}
}
pm = session->pending_message_head;
if (pm == NULL)
- {
+ {
#if DEBUG_wlan
- GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- "pending message is empty, should not happen. session %p\n",
- session);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ "pending message is empty, should not happen. session %p\n",
+ session);
#endif
- sessionqueue_alt = sessionqueue;
- sessionqueue = sessionqueue->next;
- plugin->pendingsessions--;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
- plugin->pending_Sessions_tail,
- sessionqueue_alt);
+ sessionqueue_alt = sessionqueue;
+ sessionqueue = sessionqueue->next;
+ plugin->pendingsessions--;
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
+ plugin->pendingsessions, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
+ plugin->pending_Sessions_tail,
+ sessionqueue_alt);
- GNUNET_free (sessionqueue_alt);
- continue;
+ GNUNET_free (sessionqueue_alt);
+ continue;
- }
+ }
//check for message timeout
if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
{
plugin->pendingsessions--;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
+ plugin->pendingsessions, GNUNET_NO);
GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
plugin->pending_Sessions_tail,
sessionqueue);
sessionqueue_alt = sessionqueue;
sessionqueue = sessionqueue->next;
plugin->pendingsessions--;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
+ plugin->pendingsessions, GNUNET_NO);
GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
plugin->pending_Sessions_tail,
sessionqueue_alt);
struct FragmentMessage_queue *fmq;
struct FragmentMessage_queue *fmq_next;
- fmq = plugin->sending_messages_head;
- while (fmq != NULL)
+ fmq = plugin->sending_messages_head;
+ while (fmq != NULL)
+ {
+ fmq_next = fmq->next;
+ if (fmq->content == fm)
{
- fmq_next = fmq->next;
- if (fmq->content == fm)
- {
- GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
- plugin->sending_messages_tail, fmq);
- GNUNET_free (fmq);
- }
- fmq = fmq_next;
+ GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
+ plugin->sending_messages_tail, fmq);
+ GNUNET_free (fmq);
}
+ fmq = fmq_next;
+ }
- (session->mac->fragment_messages_out_count)--;
- session->fragment_messages_out_count--;
- plugin->pending_Fragment_Messages--;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
- endpoint->sending_messages_tail, fm);
- GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
- if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK){
- GNUNET_SCHEDULER_cancel (fm->timeout_task);
- fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ (session->mac->fragment_messages_out_count)--;
+ session->fragment_messages_out_count--;
+ plugin->pending_Fragment_Messages--;
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
+ plugin->pending_Fragment_Messages, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
+ endpoint->sending_messages_tail, fm);
+ GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
+ if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (fm->timeout_task);
+ fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
- GNUNET_free (fm);
+ GNUNET_free (fm);
- queue_session (plugin, session);
+ queue_session (plugin, session);
#if DEBUG_wlan
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Free pending fragment messages %p, session %p\n", fm,
- session);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Free pending fragment messages %p, session %p\n", fm,
+ session);
#endif
}
else
{
char cwd[FILENAME_MAX];
- GNUNET_assert (getcwd(cwd, sizeof(cwd)) != NULL);
- GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR, filenameloopback);
+ GNUNET_assert (getcwd (cwd, sizeof (cwd)) != NULL);
+
+ GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR,
+ filenameloopback);
if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
"Helper `%s' not found! %i\n", absolute_filename);
- GNUNET_break(0);
+ GNUNET_break (0);
}
}
}
"Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
absolute_filename, plugin->interface, plugin->testmode);
#endif
- plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
- absolute_filename, absolute_filename, "1",
- NULL);
+ plugin->server_proc =
+ GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
+ absolute_filename, absolute_filename, "1",
+ NULL);
if (plugin->server_proc == NULL)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename);
- GNUNET_break (0);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ "`%s' not found, please look if it exists and is in the $PATH variable!\n",
+ absolute_filename);
+ GNUNET_break (0);
}
}
else if (plugin->testmode == 2)
absolute_filename, plugin->interface, plugin->testmode);
#endif
- plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
- absolute_filename, absolute_filename, "2",
- NULL);
- if (plugin->server_proc == NULL)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename);
+ plugin->server_proc =
+ GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
+ absolute_filename, absolute_filename, "2",
+ NULL);
+ if (plugin->server_proc == NULL)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ "`%s' not found, please look if it exists and is in the $PATH variable!\n",
+ absolute_filename);
GNUNET_break (0);
- }
+ }
}
if (absolute_filename != NULL)
- GNUNET_free(absolute_filename);
+ GNUNET_free (absolute_filename);
if (plugin->server_proc == NULL)
{
#if DEBUG_wlan
wlan_transport_stop_wlan_helper (struct Plugin *plugin)
{
#if DEBUG_wlan
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Stoping WLAN helper process\n");
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Stoping WLAN helper process\n");
#endif
if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_DISK_pipe_close (plugin->server_stdout);
GNUNET_DISK_pipe_close (plugin->server_stdin);
GNUNET_OS_process_kill (plugin->server_proc, SIGKILL);
- GNUNET_OS_process_wait(plugin->server_proc);
+ GNUNET_OS_process_wait (plugin->server_proc);
GNUNET_OS_process_close (plugin->server_proc);
return GNUNET_YES;
{
struct Finish_send *finish = cls;
struct Plugin *plugin;
+
plugin = finish->plugin;
plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
{
- GNUNET_free_non_null(finish->msgstart);
+ GNUNET_free_non_null (finish->msgstart);
GNUNET_free (finish);
return;
}
- wlan_transport_start_wlan_helper(plugin);
+ wlan_transport_start_wlan_helper (plugin);
if (finish->size != 0)
- {
- plugin->server_write_task =
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- plugin->server_stdin_handle,
- &finish_sending, finish);
- }
+ {
+ plugin->server_write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->server_stdin_handle,
+ &finish_sending, finish);
+ }
else
- {
- set_next_send (plugin);
- GNUNET_free_non_null(finish->msgstart);
- GNUNET_free (finish);
- }
+ {
+ set_next_send (plugin);
+ GNUNET_free_non_null (finish->msgstart);
+ GNUNET_free (finish);
+ }
}
* @param finish pointer to the Finish_send struct to finish
*/
static void
-restart_helper(struct Plugin *plugin, struct Finish_send *finish)
+restart_helper (struct Plugin *plugin, struct Finish_send *finish)
{
- static struct GNUNET_TIME_Relative next_try = {1000};
- GNUNET_assert(finish != NULL);
+ static struct GNUNET_TIME_Relative next_try = { 1000 };
+ GNUNET_assert (finish != NULL);
- wlan_transport_stop_wlan_helper(plugin);
- plugin->server_write_task = GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
- GNUNET_TIME_relative_multiply(next_try, HELPER_RESTART_SCALING_FACTOR);
+ wlan_transport_stop_wlan_helper (plugin);
+ plugin->server_write_task =
+ GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
+ GNUNET_TIME_relative_multiply (next_try, HELPER_RESTART_SCALING_FACTOR);
}
return;
}
bytes =
- GNUNET_DISK_file_write (plugin->server_stdin_handle, finish->head_of_next_write,
- finish->size);
+ GNUNET_DISK_file_write (plugin->server_stdin_handle,
+ finish->head_of_next_write, finish->size);
if (bytes != finish->size)
{
if (bytes != GNUNET_SYSERR)
- {
+ {
finish->head_of_next_write += bytes;
finish->size -= bytes;
plugin->server_write_task =
GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
plugin->server_stdin_handle,
&finish_sending, finish);
- }
+ }
else
- {
- restart_helper(plugin, finish);
- }
+ {
+ restart_helper (plugin, finish);
+ }
}
else
{
struct Radiotap_Send *radioHeader;
struct GNUNET_MessageHeader *msgheader2;
const struct GNUNET_MessageHeader *hello;
- struct Finish_send * finish;
+ struct Finish_send *finish;
GNUNET_assert (plugin != NULL);
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"),
+ 1, GNUNET_NO);
hello = plugin->env->get_our_hello ();
hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
/*msgheader2->size =
- htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
- sizeof (struct GNUNET_MessageHeader));
-
- msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);*/
+ * htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
+ * sizeof (struct GNUNET_MessageHeader));
+ *
+ * msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); */
memcpy (msgheader2, hello, hello_size);
bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
finish->head_of_next_write = NULL;
finish->size = 0;
finish->msgstart = NULL;
- restart_helper(plugin, finish);
+ restart_helper (plugin, finish);
set_next_beacon_time (plugin);
}
else
- {
+ {
GNUNET_assert (bytes == size);
set_next_beacon_time (plugin);
set_next_send (plugin);
- }
+ }
GNUNET_free (msgheader);
session->mac->fragment_messages_out_count++;
session->fragment_messages_out_count++;
plugin->pending_Fragment_Messages++;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
+ plugin->pending_Fragment_Messages, GNUNET_NO);
fm = GNUNET_malloc (sizeof (struct FragmentMessage));
fm->session = session;
ssize_t bytes;
struct AckSendQueue *ack;
- struct Finish_send * finish;
+ struct Finish_send *finish;
ack = plugin->ack_send_queue_head;
#endif
GNUNET_assert (plugin != NULL);
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1,
+ GNUNET_NO);
getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
finish->head_of_next_write = NULL;
finish->size = 0;
finish->msgstart = NULL;
- restart_helper(plugin, finish);
+ restart_helper (plugin, finish);
}
else
{
do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Plugin *plugin = cls;
+
GNUNET_assert (plugin != NULL);
plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
if (plugin->sending_messages_head != NULL)
{
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1,
+ GNUNET_NO);
fmq = plugin->sending_messages_head;
fm = fmq->content;
finish->head_of_next_write = fm->frag;
finish->size = fm->size;
- restart_helper(plugin, finish);
+ restart_helper (plugin, finish);
}
else
{
finish->head_of_next_write = fm->frag + bytes;
finish->size = fm->size - bytes;
plugin->server_write_task =
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- plugin->server_stdin_handle,
- &finish_sending, finish);
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->server_stdin_handle,
+ &finish_sending, finish);
}
fm->frag = NULL;
/* TODO check for bad addresses like multicast, broadcast, etc */
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "wlan_plugin_address_suggested got good address, size %u!\n", addrlen);
+ "wlan_plugin_address_suggested got good address, size %u!\n",
+ addrlen);
#endif
return GNUNET_OK;
}
#if DEBUG_wlan
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "wlan_plugin_address_suggested got bad address, size %u!\n", addrlen);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "wlan_plugin_address_suggested got bad address, size %u!\n",
+ addrlen);
#endif
return GNUNET_SYSERR;
}
struct Plugin *plugin = cls;
struct PendingMessage *newmsg;
struct WlanHeader *wlanheader;
+
GNUNET_assert (plugin != NULL);
//check if msglen > 0
GNUNET_assert (msgbuf_size > 0);
}
}
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1,
+ GNUNET_NO);
//queue message:
endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
plugin->mac_count--;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
+ plugin->mac_count, GNUNET_NO);
GNUNET_free (endpoint);
}
if (pendingsession_tmp->content == queue->content)
{
plugin->pendingsessions--;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
+ plugin->pendingsessions, GNUNET_NO);
GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
plugin->pending_Sessions_tail,
pendingsession_tmp);
GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
queue);
//Check that no ohter session on this endpoint for this session exits
- GNUNET_assert(search_session(plugin, endpoint, &queue->content->target) == NULL);
+ GNUNET_assert (search_session (plugin, endpoint, &queue->content->target) ==
+ NULL);
if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
{
free_macendpoint (plugin, endpoint);
//check if no endpoint with the same address exists
- GNUNET_assert(get_macendpoint(plugin, &endpoint->addr, GNUNET_NO) == NULL);
+ GNUNET_assert (get_macendpoint (plugin, &endpoint->addr, GNUNET_NO) ==
+ NULL);
}
if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
const unsigned char *input;
//GNUNET_assert(cls !=NULL);
- if (addrlen != sizeof(struct MacAddress))
+ if (addrlen != sizeof (struct MacAddress))
{
/* invalid address (MAC addresses have 6 bytes) */
//GNUNET_break (0);
#if DEBUG_wlan
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
- addrlen);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
+ "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
+ addrlen);
#endif
- asc(asc_cls, NULL);
+ asc (asc_cls, NULL);
return;
}
input = (const unsigned char *) addr;
GNUNET_asprintf (&ret,
- "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",type,
- PROTOCOL_PREFIX, input[0], input[1], input[2], input[3],
- input[4], input[5]);
+ "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
+ type, PROTOCOL_PREFIX, input[0], input[1], input[2],
+ input[3], input[4], input[5]);
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
addrlen, numeric, type, ret);
#endif
- asc ( asc_cls, ret);
+ asc (asc_cls, ret);
//only one mac address per plugin
- asc ( asc_cls, NULL);
+ asc (asc_cls, NULL);
}
return;
}
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan whole messages received"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# wlan whole messages received"), 1,
+ GNUNET_NO);
wlanheader = (struct WlanHeader *) hdr;
session = search_session (plugin, endpoint, &wlanheader->source);
#endif
plugin->env->receive (plugin->env->cls, &(session->target), hdr,
- (const struct GNUNET_ATS_Information *)
- &distance, 1, session,
- (const char *) &session->mac->addr,
+ (const struct GNUNET_ATS_Information *) &distance, 1,
+ session, (const char *) &session->mac->addr,
sizeof (session->mac->addr));
}
struct FragmentMessage *fm2;
struct GNUNET_PeerIdentity tmpsource;
- GNUNET_assert(plugin != NULL);
+ GNUNET_assert (plugin != NULL);
//ADVERTISEMENT
if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
if (GNUNET_HELLO_get_id
- ((const struct GNUNET_HELLO_Message *) hdr,
- &tmpsource) == GNUNET_OK)
+ ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK)
{
- session_light->session = search_session (plugin, session_light->macendpoint, &tmpsource);
+ session_light->session =
+ search_session (plugin, session_light->macendpoint, &tmpsource);
if (session_light->session == NULL)
- {
- session_light->session = create_session (plugin, session_light->macendpoint, &tmpsource);
- }
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello messages received"), 1, GNUNET_NO);
- plugin->env->receive(plugin->env->cls,&session_light->session->target,hdr, NULL, 0, session_light->session,
- (const char *) &session_light->session->mac->addr,
- sizeof (session_light->session->mac->addr));
+ {
+ session_light->session =
+ create_session (plugin, session_light->macendpoint, &tmpsource);
+ }
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# wlan hello messages received"), 1,
+ GNUNET_NO);
+ plugin->env->receive (plugin->env->cls, &session_light->session->target,
+ hdr, NULL, 0, session_light->session,
+ (const char *) &session_light->session->mac->addr,
+ sizeof (session_light->session->mac->addr));
}
else
{
6));
#endif
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments received"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# wlan fragments received"), 1, GNUNET_NO);
int ret =
GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
hdr);
while (fm != NULL)
{
fm2 = fm->next;
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"),
+ 1, GNUNET_NO);
int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
if (ret == GNUNET_OK)
(GNUNET_TIME_absolute_add
(endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
{
- GNUNET_assert(endpoint->plugin != NULL);
- GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
+ GNUNET_assert (endpoint->plugin != NULL);
+ GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
+ _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
free_macendpoint (endpoint->plugin, endpoint);
}
else
{
struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
- GNUNET_assert(plugin != NULL);
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan mac endpoints created"), 1, GNUNET_NO);
+ GNUNET_assert (plugin != NULL);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# wlan mac endpoints created"), 1, GNUNET_NO);
newend->addr = *addr;
newend->plugin = plugin;
newend->addr = *addr;
newend);
plugin->mac_count++;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
+ plugin->mac_count, GNUNET_NO);
GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
int datasize = 0;
int pos;
- GNUNET_assert(plugin != NULL);
+ GNUNET_assert (plugin != NULL);
switch (ntohs (hdr->type))
{
case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
ntohs (hdr->size));
#endif
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan WLAN_HELPER_DATA received"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# wlan WLAN_HELPER_DATA received"), 1,
+ GNUNET_NO);
//call wlan_process_helper with the message inside, later with wlan: analyze signal
if (ntohs (hdr->size) <
- sizeof (struct ieee80211_frame) + 2*sizeof (struct GNUNET_MessageHeader) +
- sizeof (struct Radiotap_rx))
+ sizeof (struct ieee80211_frame) +
+ 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
{
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
{
//check for broadcast or mac
if ((memcmp
- (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
- sizeof (struct MacAddress)) == 0) ||
- (memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
- sizeof (struct MacAddress)) == 0))
+ (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
+ sizeof (struct MacAddress)) == 0) ||
+ (memcmp
+ (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
+ sizeof (struct MacAddress)) == 0))
{
- //if packet is from us return
- if ((memcmp (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
- sizeof (struct MacAddress)) == 0)){
- return;
- }
+ //if packet is from us return
+ if ((memcmp
+ (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
+ sizeof (struct MacAddress)) == 0))
+ {
+ return;
+ }
// process the inner data
memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
sizeof (struct MacAddress));
//session_light->session = search_session(plugin,session_light->addr);
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages for this client received"), 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _("# wlan messages for this client received"),
+ 1, GNUNET_NO);
pos = 0;
while (pos < datasize)
{
temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
- if (ntohs(temp_hdr->size) <= datasize + pos)
- {
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages inside WLAN_HELPER_DATA received"), 1, GNUNET_NO);
- wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
- }
+ if (ntohs (temp_hdr->size) <= datasize + pos)
+ {
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ _
+ ("# wlan messages inside WLAN_HELPER_DATA received"),
+ 1, GNUNET_NO);
+ wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
+ }
else
- {
+ {
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Size of packet is too small; size: %u > size of packet: %u\n",
- ntohs(temp_hdr->size),datasize + pos);
+ "Size of packet is too small; size: %u > size of packet: %u\n",
+ ntohs (temp_hdr->size), datasize + pos);
#endif
- }
+ }
pos += ntohs (temp_hdr->size);
}
"libgnunet_plugin_transport_wlan_done started\n");
#endif
- wlan_transport_stop_wlan_helper(plugin);
+ wlan_transport_stop_wlan_helper (plugin);
GNUNET_assert (cls != NULL);
//free sessions
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
plugin->pendingsessions = 0;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
+ plugin->pendingsessions, GNUNET_NO);
plugin->mac_count = 0;
- GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO);
+ GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
+ plugin->mac_count, GNUNET_NO);
plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
"TESTMODE", &(plugin->testmode)))
- plugin->testmode = 0; //default value
+ plugin->testmode = 0; //default value
}
if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
//start the plugin
wlan_transport_start_wlan_helper (plugin);
set_next_beacon_time (plugin);
- set_next_send(plugin);
+ set_next_send (plugin);
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan init finished\n");
struct PeerContext *p2;
-struct PeerContext * sender;
+struct PeerContext *sender;
-struct PeerContext * receiver;
+struct PeerContext *receiver;
struct GNUNET_TRANSPORT_TransmitHandle *th;
unsigned long long quota_in_p2;
unsigned long long quota_out_p2;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
datarate = (total_bytes_sent * 1000) / delta;
- fprintf (stderr, "Throughput was %llu b/s\n",
- datarate);
+ fprintf (stderr, "Throughput was %llu b/s\n", datarate);
test_failed = GNUNET_NO;
if (datarate > quota_in_p2)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", datarate, quota_in_p2);
+ "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n",
+ datarate, quota_in_p2);
test_failed = GNUNET_YES;
}
if (datarate > quota_out_p1)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", datarate, quota_out_p1);
+ "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n",
+ datarate, quota_out_p1);
test_failed = GNUNET_YES;
}
if (test_failed == GNUNET_NO)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", datarate, quota_out_p1, quota_in_p2);
+ "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n",
+ datarate, quota_out_p1, quota_in_p2);
}
if (die_task != GNUNET_SCHEDULER_NO_TASK)
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
if (p1 != NULL)
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
static int n;
unsigned int s;
if (die_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (die_task);
test_failed = GNUNET_YES;
- die_task = GNUNET_SCHEDULER_add_now (&end_badly,
- NULL);
+ die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
return;
}
#if VERBOSE
if (ntohl (hdr->num) % 5000 == 0)
{
struct PeerContext *p = cls;
- char * ps = strdup(GNUNET_i2s(&p->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
- p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer));
+ char *ps = strdup (GNUNET_i2s (&p->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
+ p->no, ps, ntohl (hdr->num), ntohs (message->size),
+ GNUNET_i2s (peer));
GNUNET_free (ps);
}
#endif
if (buf == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS);
+ "Timeout occurred while waiting for transmit_ready for message %u of %u\n",
+ msg_scheduled, TOTAL_MSGS);
if (GNUNET_SCHEDULER_NO_TASK != die_task)
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
if (n % 5000 == 0)
{
- char * receiver_s = strdup(GNUNET_i2s (&receiver->id));
+ char *receiver_s = strdup (GNUNET_i2s (&receiver->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
- n,
- sender->no,
- GNUNET_i2s (&sender->id), receiver->no, receiver_s);
+ n, sender->no, GNUNET_i2s (&sender->id), receiver->no,
+ receiver_s);
GNUNET_free (receiver_s);
}
#endif
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
struct PeerContext *p = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n",
p->no, GNUNET_i2s (peer));
}
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n",
- p->no, GNUNET_i2s (peer));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no,
+ GNUNET_i2s (peer));
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
static int counter;
+
measure_task = GNUNET_SCHEDULER_NO_TASK;
counter++;
- if ((DURATION.rel_value / 1000) < counter )
+ if ((DURATION.rel_value / 1000) < counter)
{
fprintf (stderr, ".\n");
GNUNET_SCHEDULER_add_now (&end, NULL);
else
{
fprintf (stderr, ".");
- measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
+ measure_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
}
}
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
char *p1_c = strdup (GNUNET_i2s (&p1->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
- p1->no, p1_c,
- p2->no, GNUNET_i2s (&p2->id));
+ p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
cc = NULL;
test_connected = GNUNET_YES;
- measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
+ measure_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
GNUNET_SCHEDULER_add_now (&sendtask, NULL);
}
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
receiver = p1;
char *sender_c = strdup (GNUNET_i2s (&sender->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to send from %u (%s) -> peer %u (%s)\n",
- sender->no, sender_c,
- receiver->no, GNUNET_i2s (&receiver->id));
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test tries to send from %u (%s) -> peer %u (%s)\n", sender->no,
+ sender_c, receiver->no, GNUNET_i2s (&receiver->id));
+
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
}
static char *
-generate_config (char * cfg_file, unsigned long long quota_in, unsigned long long quota_out)
+generate_config (char *cfg_file, unsigned long long quota_in,
+ unsigned long long quota_out)
{
- char * fname = NULL;
- struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create();
+ char *fname = NULL;
+ struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
+
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file));
- GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, cfg_file);
- GNUNET_CONFIGURATION_set_value_string(cfg, "PATHS", "DEFAULTCONFIG", fname);
- GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_OUT", quota_out);
- GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_IN", quota_in);
- GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_IN", quota_in);
- GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_OUT", quota_out);
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write(cfg, fname));
- GNUNET_CONFIGURATION_destroy(cfg);
+ GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out,
+ cfg_file);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname);
+ GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_OUT",
+ quota_out);
+ GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_IN",
+ quota_in);
+ GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_IN",
+ quota_in);
+ GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_OUT",
+ quota_out);
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname));
+ GNUNET_CONFIGURATION_destroy (cfg);
return fname;
}
static void
-run_measurement (unsigned long long p1_quota_in, unsigned long long p1_quota_out,
- unsigned long long p2_quota_in, unsigned long long p2_quota_out)
+run_measurement (unsigned long long p1_quota_in,
+ unsigned long long p1_quota_out,
+ unsigned long long p2_quota_in,
+ unsigned long long p2_quota_out)
{
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
/* setting ATS quota */
quota_out_p1 = p1_quota_out;
- gen_cfg_p1 = generate_config(cfg_file_p1, p1_quota_in, p1_quota_out);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Generated config file `%s'\n",
- gen_cfg_p1);
+ gen_cfg_p1 = generate_config (cfg_file_p1, p1_quota_in, p1_quota_out);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
+ gen_cfg_p1);
quota_in_p2 = p2_quota_in;
- gen_cfg_p2 = generate_config(cfg_file_p2, p2_quota_in, p2_quota_out);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Generated config file `%s'\n",
- gen_cfg_p2);
+ gen_cfg_p2 = generate_config (cfg_file_p2, p2_quota_in, p2_quota_out);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
+ gen_cfg_p2);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1,
- ¬ify_receive,
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, ¬ify_receive,
¬ify_connect, ¬ify_disconnect,
- &start_cb,
- NULL);
+ &start_cb, NULL);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2,
- ¬ify_receive,
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, ¬ify_receive,
¬ify_connect, ¬ify_disconnect,
- &start_cb,
- NULL);
+ &start_cb, NULL);
if ((p1 == NULL) || (p2 == NULL))
{
unsigned long long p2_quota_in = 10000;
unsigned long long p2_quota_out = 10000;
- if (NULL != strstr (test_name,"asymmetric"))
+ if (NULL != strstr (test_name, "asymmetric"))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n",
- p2_quota_in, p2_quota_out);
+ "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n",
+ p2_quota_in, p2_quota_out);
p1_quota_out = 1024 * 1024 * 1024;
p1_quota_in = 1024 * 1024 * 1024;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running symmetric test with (in/out) %llu/%llu b/s \n",
- p2_quota_in, p2_quota_out);
+ "Running symmetric test with (in/out) %llu/%llu b/s \n",
+ p2_quota_in, p2_quota_out);
}
run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out);
}
struct GNUNET_TRANSPORT_TransmitHandle *th;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
char *cfg_file_p1;
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
- struct PeerContext * p = cls;
+ struct PeerContext *p = cls;
struct PeerContext *t = NULL;
if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
t = p2;
GNUNET_assert (t != NULL);
- char * ps = strdup (GNUNET_i2s(&p->id));
+ char *ps = strdup (GNUNET_i2s (&p->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
- p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id));
+ p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
+ GNUNET_i2s (&t->id));
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
hdr->type = htons (MTYPE);
}
- char * ps = strdup (GNUNET_i2s(&p2->id));
+ char *ps = strdup (GNUNET_i2s (&p2->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
- p2->no,
- ps,
- ntohs (hdr->type),
- ntohs (hdr->size), p->no, GNUNET_i2s (&p->id));
+ p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
+ GNUNET_i2s (&p->id));
GNUNET_free (ps);
return sizeof (struct GNUNET_MessageHeader);
}
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- char * receiver_s = strdup(GNUNET_i2s (&p1->id));
+ char *receiver_s = strdup (GNUNET_i2s (&p1->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
- p2->no,
- GNUNET_i2s (&p2->id), p1->no, receiver_s);
+ p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
GNUNET_free (receiver_s);
th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0,
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
static int c;
+
c++;
struct PeerContext *p = cls;
struct PeerContext *t = NULL;
t = p1;
if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
t = p2;
- GNUNET_assert (t!=NULL);
+ GNUNET_assert (t != NULL);
+
+ char *ps = strdup (GNUNET_i2s (&p->id));
- char * ps = strdup (GNUNET_i2s(&p->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
- p->no, ps,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
t->no, GNUNET_i2s (peer));
GNUNET_free (ps);
}
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
- char * ps = strdup (GNUNET_i2s(&p->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
- p->no, ps, GNUNET_i2s (peer));
+ char *ps = strdup (GNUNET_i2s (&p->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
+ GNUNET_i2s (peer));
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
char *p1_c = strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
- p1->no, p1_c,
- p2->no, GNUNET_i2s (&p2->id));
+ p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
char *sender_c = strdup (GNUNET_i2s (&p1->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
- p1->no, sender_c,
- p2->no, GNUNET_i2s (&p2->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
+ p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
NULL);
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- NULL);
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
+ NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
struct GNUNET_TRANSPORT_TransmitHandle *th;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
int shutdown_;
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
- char * ps = strdup (GNUNET_i2s(&p->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
- p->no, ps, GNUNET_i2s (peer));
+ char *ps = strdup (GNUNET_i2s (&p->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
+ GNUNET_i2s (peer));
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
if (shutdown_ == GNUNET_YES)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n");
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n");
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
}
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- struct PeerContext * p = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n",
- p->no,
- GNUNET_i2s (&p->id));
+ struct PeerContext *p = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", p->no,
+ GNUNET_i2s (&p->id));
shutdown_ = GNUNET_YES;
- GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
p2 = NULL;
GNUNET_assert (p2 == NULL);
}
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
- struct PeerContext * p = cls;
+ struct PeerContext *p = cls;
struct PeerContext *t = NULL;
if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
t = p2;
GNUNET_assert (t != NULL);
- char * ps = strdup (GNUNET_i2s(&p->id));
+ char *ps = strdup (GNUNET_i2s (&p->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
- p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id));
+ p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
+ GNUNET_i2s (&t->id));
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
{
ok = 1;
- GNUNET_SCHEDULER_add_now(stop_peer, p2);
+ GNUNET_SCHEDULER_add_now (stop_peer, p2);
return;
}
}
hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
hdr->type = htons (MTYPE);
}
- char * ps = strdup (GNUNET_i2s(&p2->id));
+ char *ps = strdup (GNUNET_i2s (&p2->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
- p2->no,
- ps,
- ntohs (hdr->type),
- ntohs (hdr->size), p->no, GNUNET_i2s (&p->id));
+ p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
+ GNUNET_i2s (&p->id));
GNUNET_free (ps);
return sizeof (struct GNUNET_MessageHeader);
}
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- char * receiver_s = strdup(GNUNET_i2s (&p1->id));
+ char *receiver_s = strdup (GNUNET_i2s (&p1->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
- p2->no,
- GNUNET_i2s (&p2->id), p1->no, receiver_s);
+ p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
GNUNET_free (receiver_s);
th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0,
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
static int c;
+
c++;
struct PeerContext *p = cls;
struct PeerContext *t = NULL;
t = p1;
if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
t = p2;
- GNUNET_assert (t!=NULL);
+ GNUNET_assert (t != NULL);
+
+ char *ps = strdup (GNUNET_i2s (&p->id));
- char * ps = strdup (GNUNET_i2s(&p->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
- p->no, ps,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
t->no, GNUNET_i2s (peer));
GNUNET_free (ps);
}
char *p1_c = strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
- p1->no, p1_c,
- p2->no, GNUNET_i2s (&p2->id));
+ p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
char *sender_c = strdup (GNUNET_i2s (&p1->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
- p1->no, sender_c,
- p2->no, GNUNET_i2s (&p2->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
+ p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
NULL);
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- NULL);
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
+ NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
struct GNUNET_TRANSPORT_TransmitHandle *th;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
char *cfg_file_p1;
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received message of type %d from peer %s!\n",
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
GNUNET_i2s (peer), cls);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
}
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
tth = GNUNET_TRANSPORT_TESTING_init ();
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
{
struct PeerContext *p2;
-struct PeerContext * sender;
+struct PeerContext *sender;
-struct PeerContext * receiver;
+struct PeerContext *receiver;
struct GNUNET_TRANSPORT_TransmitHandle *th;
char *cfg_file_p2;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
if (p1 != NULL)
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
static int n;
unsigned int s;
if (ntohl (hdr->num) % 5000 == 0)
{
struct PeerContext *p = cls;
- char * ps = strdup(GNUNET_i2s(&p->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
- p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer));
+ char *ps = strdup (GNUNET_i2s (&p->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
+ p->no, ps, ntohl (hdr->num), ntohs (message->size),
+ GNUNET_i2s (peer));
GNUNET_free (ps);
}
#endif
if (buf == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS);
+ "Timeout occurred while waiting for transmit_ready for message %u of %u\n",
+ msg_scheduled, TOTAL_MSGS);
if (GNUNET_SCHEDULER_NO_TASK != die_task)
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
if (n % 5000 == 0)
{
- char * receiver_s = strdup(GNUNET_i2s (&receiver->id));
+ char *receiver_s = strdup (GNUNET_i2s (&receiver->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
- n,
- sender->no,
- GNUNET_i2s (&sender->id), receiver->no, receiver_s);
+ n, sender->no, GNUNET_i2s (&sender->id), receiver->no,
+ receiver_s);
GNUNET_free (receiver_s);
}
#endif
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
struct PeerContext *p = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n",
p->no, GNUNET_i2s (peer));
}
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n",
- p->no, GNUNET_i2s (peer));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no,
+ GNUNET_i2s (peer));
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
char *p1_c = strdup (GNUNET_i2s (&p1->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
- p1->no, p1_c,
- p2->no, GNUNET_i2s (&p2->id));
+ p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
cc = NULL;
}
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
test_connected = GNUNET_NO;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n",
- p1->no,
- GNUNET_i2s (&p1->id), cfg_file_p1);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n",
- p2->no,
- GNUNET_i2s (&p2->id), cfg_file_p2);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u: `%s' using configuration file `%s'\n", p1->no,
+ GNUNET_i2s (&p1->id), cfg_file_p1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u: `%s' using configuration file `%s'\n", p2->no,
+ GNUNET_i2s (&p2->id), cfg_file_p2);
sender = p2;
receiver = p1;
char *sender_c = strdup (GNUNET_i2s (&sender->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test triest to send from %u (%s) -> peer %u (%s)\n",
- sender->no, sender_c,
- receiver->no, GNUNET_i2s (&receiver->id));
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test triest to send from %u (%s) -> peer %u (%s)\n", sender->no,
+ sender_c, receiver->no, GNUNET_i2s (&receiver->id));
+
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
}
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
static GNUNET_SCHEDULER_TaskIdentifier timer_task;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
struct PeerContext *p1;
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received message of type %d from peer %s!\n",
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
GNUNET_i2s (peer), cls);
timer_task = GNUNET_SCHEDULER_add_now (&timer, NULL);
}
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
char *sender_c = strdup (GNUNET_i2s (&p1->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
- p1->no, sender_c,
- p2->no, GNUNET_i2s (&p2->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
+ p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
NULL);
{
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
- "test-transport-api-timeout", "nohelp", options,
- &run, &ok);
+ "test-transport-api-timeout", "nohelp", options, &run,
+ &ok);
return ok;
}
uint32_t max_bps_p1;
uint32_t max_bps_p2;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
/*
* Testcase specific declarations
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
cc = NULL;
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n");
if (test_sending == GNUNET_NO)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase did not send any messages timeout\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Testcase did not send any messages timeout\n");
else
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
msg_sent, msg_scheduled, msg_recv, msg_recv_expected);
if (test_send_timeout == GNUNET_YES)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test had timeout while waiting to send data\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Test had timeout while waiting to send data\n");
if (th != NULL)
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
cc = NULL;
if (p1 != NULL)
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
static int n;
else
{
fprintf (stderr, "\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All messages scheduled to be sent\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n");
if (GNUNET_SCHEDULER_NO_TASK != die_task)
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
char *p1_c = strdup (GNUNET_i2s (&p1->id));
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c,
GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
GNUNET_SCHEDULER_add_now (&sendtask, NULL);
}
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
test_connected = GNUNET_NO;
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
}
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
struct GNUNET_TRANSPORT_TransmitHandle *th;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
char *cfg_file_p1;
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
cc = NULL;
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
ok = 0;
if (test_failed == GNUNET_NO)
ok = GNUNET_SYSERR;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GOT %u of %u messages\n", msg_recv, TOTAL_MSGS);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GOT %u of %u messages\n", msg_recv,
+ TOTAL_MSGS);
}
static void
th = NULL;
if (cc != NULL)
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
cc = NULL;
if (p1 != NULL)
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
static int n;
msg_recv = ntohl (hdr->num);
if (msg_recv_expected != msg_recv)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message no %u, got %u\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected message no %u, got %u\n",
msg_recv_expected, msg_recv);
if (GNUNET_SCHEDULER_NO_TASK != die_task)
GNUNET_SCHEDULER_cancel (die_task);
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
GNUNET_SCHEDULER_add_now (&sendtask, NULL);
}
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
- cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+ cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
+ NULL);
}
static void
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
- ¬ify_receive,
- ¬ify_connect, ¬ify_disconnect,
- &start_cb,
+ ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb,
NULL);
if ((p1 == NULL) || (p2 == NULL))
static struct PeerContext *p1;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
static int connected = GNUNET_NO;
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
GNUNET_i2s (peer));
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
}
while (i <= ITERATIONS)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_startonly.conf", 1,
- ¬ify_receive, ¬ify_connect,
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
+ "test_transport_startonly.conf",
+ 1, ¬ify_receive,
+ ¬ify_connect,
¬ify_disconnect, NULL, p1);
static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
-struct GNUNET_TRANSPORT_TESTING_handle * tth;
+struct GNUNET_TRANSPORT_TESTING_handle *tth;
static int connected = GNUNET_NO;
static void
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
- char * ps = strdup (GNUNET_i2s(&p1->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to peer %u (`%s')!\n",
- p1->no, ps,
+ char *ps = strdup (GNUNET_i2s (&p1->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps,
p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (ps);
GNUNET_SCHEDULER_add_now (&end, NULL);
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
GNUNET_i2s (peer));
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
}
-void start_cb (struct PeerContext * p,
- void *cls)
+void
+start_cb (struct PeerContext *p, void *cls)
{
static int started;
+
started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+ GNUNET_i2s (&p->id));
if (started != 2)
return;
char *sender_c = strdup (GNUNET_i2s (&p1->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
- p1->no, sender_c,
- p2->no, GNUNET_i2s (&p2->id));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
+ p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
- p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer1.conf",
- 1,
- ¬ify_receive, ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- p1);
- p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer2.conf",
- 2,
- ¬ify_receive, ¬ify_connect,
- ¬ify_disconnect,
- &start_cb,
- p2);
+ p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
+ "test_transport_api_tcp_peer1.conf",
+ 1, ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb, p1);
+ p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
+ "test_transport_api_tcp_peer2.conf",
+ 2, ¬ify_receive, ¬ify_connect,
+ ¬ify_disconnect, &start_cb, p2);
if (p1 == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was not started successfully\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer1 was not started successfully\n");
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(timeout_task);
- timeout_task =
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
}
if (p2 == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was not started successfully\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer2 was not started successfully\n");
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(timeout_task);
- timeout_task =
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
}
}
static struct PeerContext *
-find_peer_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth,
- const struct GNUNET_PeerIdentity *peer)
+find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth,
+ const struct GNUNET_PeerIdentity *peer)
{
GNUNET_assert (tth != NULL);
- struct PeerContext * t = tth->p_head;
+ struct PeerContext *t = tth->p_head;
while (t != NULL)
{
}
struct ConnectingContext *
-find_connecting_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth,
- struct PeerContext *p1,
- struct PeerContext * p2)
+find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth,
+ struct PeerContext *p1, struct PeerContext *p2)
{
GNUNET_assert (tth != NULL);
- struct ConnectingContext * cc = tth->cc_head;
+ struct ConnectingContext *cc = tth->cc_head;
while (cc != NULL)
{
if ((cc->p1 == p1) && (cc->p2 == p2))
- break;
+ break;
if ((cc->p1 == p2) && (cc->p2 == p1))
break;
cc = cc->next;
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
struct PeerContext *p = cls;
+
/* Find PeerContext */
GNUNET_assert (p != 0);
GNUNET_assert (p->tth != NULL);
- struct PeerContext * p2 = find_peer_context (p->tth, peer);
+ struct PeerContext *p2 = find_peer_context (p->tth, peer);
if (p == NULL)
return;
p->nc (p->cb_cls, peer, ats, ats_count);
#if VERBOSE
- char * p2_s;
+ char *p2_s;
+
if (p2 != NULL)
- GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
+ GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
else
- GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer));
+ GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer));
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
- "Peers %s connected to peer %u (`%s')\n",
- p2_s,
- p->no, GNUNET_i2s (&p->id));
+ "Peers %s connected to peer %u (`%s')\n", p2_s, p->no,
+ GNUNET_i2s (&p->id));
GNUNET_free (p2_s);
#endif
/* Find ConnectingContext */
- struct ConnectingContext * cc = find_connecting_context(p->tth, p, p2);
+ struct ConnectingContext *cc = find_connecting_context (p->tth, p, p2);
+
if (cc == NULL)
return;
cc->p1_c = GNUNET_YES;
if (p == cc->p2)
- cc->p2_c = GNUNET_YES;
+ cc->p2_c = GNUNET_YES;
if ((cc->p1_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
{
cc->cb (cc->p1, cc->p2, cc->cb_cls);
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(p->tth, cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (p->tth, cc);
}
}
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
+
/* Find PeerContext */
int no = 0;
- struct PeerContext * p2 = NULL;
+ struct PeerContext *p2 = NULL;
if (p != NULL)
{
no = p->no;
}
- char * p2_s;
+ char *p2_s;
+
if (p2 != NULL)
- GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
+ GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
else
- GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer));
+ GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer));
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
- "Peers %s disconnected from peer %u (`%s')\n",
- p2_s,
- no , GNUNET_i2s (&p->id));
+ "Peers %s disconnected from peer %u (`%s')\n", p2_s, no,
+ GNUNET_i2s (&p->id));
GNUNET_free (p2_s);
if (p == NULL)
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
struct PeerContext *p = cls;
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
message, &p->id));
- size_t size = GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *) message);
+ size_t size =
+ GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) message);
GNUNET_free_non_null (p->hello);
- p->hello = (struct GNUNET_HELLO_Message*) GNUNET_copy_message (message);
+ p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message);
#if VERBOSE
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "transport-testing",
- "New HELLO for peer %u (`%s') with size %u\n",
- p->no, GNUNET_i2s (&p->id), size);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+ "New HELLO for peer %u (`%s') with size %u\n", p->no,
+ GNUNET_i2s (&p->id), size);
#endif
if (p->start_cb != NULL)
{
#if VERBOSE
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
- "Peer %u (`%s') successfully started\n",
- p->no, GNUNET_i2s (&p->id));
+ "Peer %u (`%s') successfully started\n", p->no,
+ GNUNET_i2s (&p->id));
#endif
- p->start_cb(p, p->cb_cls);
+ p->start_cb (p, p->cb_cls);
p->start_cb = NULL;
}
}
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
- char * p2_s = GNUNET_strdup(GNUNET_i2s (&p2->id));
+ char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
+
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
- "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
- p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s,
- GNUNET_HELLO_size (cc->p2->hello));
+ "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
+ p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s,
+ GNUNET_HELLO_size (cc->p2->hello));
GNUNET_free (p2_s);
GNUNET_TRANSPORT_offer_hello (cc->th_p1,
- (const struct GNUNET_MessageHeader *) cc->p2->hello, NULL, NULL);
+ (const struct GNUNET_MessageHeader *) cc->
+ p2->hello, NULL, NULL);
GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id);
cc->tct =
* @return the peer context
*/
struct PeerContext *
-GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth,
- const char *cfgname,
- int peer_id,
+GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
+ *tth, const char *cfgname, int peer_id,
GNUNET_TRANSPORT_ReceiveCallback rec,
GNUNET_TRANSPORT_NotifyConnect nc,
GNUNET_TRANSPORT_NotifyDisconnect nd,
if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
- "File not found: `%s' \n", cfgname);
+ "File not found: `%s' \n", cfgname);
return NULL;
}
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
- GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
- &p->servicehome));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS",
+ "SERVICEHOME",
+ &p->servicehome));
if (NULL != p->servicehome)
GNUNET_DISK_directory_remove (p->servicehome);
p->arm_proc =
p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p);
GNUNET_assert (p->ghh != NULL);
- GNUNET_CONTAINER_DLL_insert(tth->p_head, tth->p_tail, p);
+ GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p);
return p;
}
* @param p the peer
*/
void
-GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth,
+GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
struct PeerContext *p)
{
GNUNET_assert (p != NULL);
* @return connect context
*/
GNUNET_TRANSPORT_TESTING_ConnectRequest
-GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * tth,
- struct PeerContext *p1,
+GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
+ *tth, struct PeerContext *p1,
struct PeerContext *p2,
GNUNET_TRANSPORT_TESTING_connect_cb cb,
void *cb_cls)
-
{
GNUNET_assert (tth != NULL);
cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
- "New connect request %X\n", cc);
+ "New connect request %X\n", cc);
return cc;
}
* Tou MUST cancel the request if you stop the peers before the peers connected succesfully
* @param cc a connect request handle
*/
-void GNUNET_TRANSPORT_TESTING_connect_peers_cancel
- (struct GNUNET_TRANSPORT_TESTING_handle * tth,
- GNUNET_TRANSPORT_TESTING_ConnectRequest ccr)
+void
+GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
+ GNUNET_TRANSPORT_TESTING_handle
+ *tth,
+ GNUNET_TRANSPORT_TESTING_ConnectRequest
+ ccr)
{
struct ConnectingContext *cc = ccr;
GNUNET_assert (tth != NULL);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
- "Canceling connect request %X!\n", cc);
+ "Canceling connect request %X!\n", cc);
if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (cc->tct);
* @param tth transport testing handle
*/
void
-GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth)
+GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth)
{
struct ConnectingContext *cc = tth->cc_head;
struct ConnectingContext *ct = NULL;
{
ct = cc->next;
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
- "Developer forgot to cancel connect request %X!\n", cc);
- GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc);
+ "Developer forgot to cancel connect request %X!\n", cc);
+ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
cc = ct;
}
{
t = p->next;
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
- "Developer forgot to stop peer!\n");
+ "Developer forgot to stop peer!\n");
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p);
p = t;
}
struct GNUNET_TRANSPORT_TESTING_handle *
GNUNET_TRANSPORT_TESTING_init ()
{
- struct GNUNET_TRANSPORT_TESTING_handle * tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle));
+ struct GNUNET_TRANSPORT_TESTING_handle *tth =
+ GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle));
return tth;
}
*/
struct PeerContext
{
- struct PeerContext * next;
- struct PeerContext * prev;
+ struct PeerContext *next;
+ struct PeerContext *prev;
- struct GNUNET_TRANSPORT_TESTING_handle * tth;
+ struct GNUNET_TRANSPORT_TESTING_handle *tth;
struct GNUNET_CONFIGURATION_Handle *cfg;
struct ConnectingContext
{
- struct ConnectingContext * next;
- struct ConnectingContext * prev;
+ struct ConnectingContext *next;
+ struct ConnectingContext *prev;
struct PeerContext *p1;
struct PeerContext *p2;
GNUNET_SCHEDULER_TaskIdentifier tct;
struct GNUNET_TRANSPORT_TESTING_handle
{
- struct ConnectingContext * cc_head;
- struct ConnectingContext * cc_tail;
+ struct ConnectingContext *cc_head;
+ struct ConnectingContext *cc_tail;
- struct PeerContext * p_head;
- struct PeerContext * p_tail;
+ struct PeerContext *p_head;
+ struct PeerContext *p_tail;
};
* @return the peer context
*/
struct PeerContext *
-GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth,
- const char *cfgname,
- int peer_id,
+GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
+ *tth, const char *cfgname, int peer_id,
GNUNET_TRANSPORT_ReceiveCallback rec,
GNUNET_TRANSPORT_NotifyConnect nc,
GNUNET_TRANSPORT_NotifyDisconnect nd,
*/
void
-GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth,
+GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
struct PeerContext *pc);
* @return a connect request handle
*/
GNUNET_TRANSPORT_TESTING_ConnectRequest
-GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * tth,
- struct PeerContext *p1,
+GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
+ *tth, struct PeerContext *p1,
struct PeerContext *p2,
GNUNET_TRANSPORT_TESTING_connect_cb cb,
void *cls);
* @param cc a connect request handle
*/
void
-GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *,
- void *cc);
+GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
+ GNUNET_TRANSPORT_TESTING_handle
+ *, void *cc);
/**
* Clean up the transport testing
* @param tth transport testing handle
*/
void
-GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth);
+GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
/**
* Initialize the transport testing
GNUNET_break (0);
break;
}
- ats = (const struct GNUNET_ATS_Information*) &cim[1];
+ ats = (const struct GNUNET_ATS_Information *) &cim[1];
#if DEBUG_TRANSPORT_API
LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
"CONNECT", GNUNET_i2s (&cim->id));
}
im = (const struct InboundMessage *) msg;
ats_count = ntohl (im->ats_count);
- ats = (const struct GNUNET_ATS_Information*) &im[1];
+ ats = (const struct GNUNET_ATS_Information *) &im[1];
imm = (const struct GNUNET_MessageHeader *) &ats[ats_count];
if (ntohs (imm->size) + sizeof (struct InboundMessage) +
ats_count * sizeof (struct GNUNET_ATS_Information) != size)
struct AddressLookupCtx *alucb = cls;
struct AddressIterateResponseMessage *address;
uint16_t size;
- char * transport;
+ char *transport;
+
//size_t transport_len;
//void * addr;
size_t addrlen;
transport = (char *) &address[0];
//transport_len = ntohs(address->pluginlen);
- addrlen = ntohs(address->addrlen);
+ addrlen = ntohs (address->addrlen);
/* expect more replies */
GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb,
*/
struct GNUNET_BANDWIDTH_Value32NBO
GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1,
- struct GNUNET_BANDWIDTH_Value32NBO b2)
+ struct GNUNET_BANDWIDTH_Value32NBO b2)
{
return
- GNUNET_BANDWIDTH_value_init (GNUNET_MIN
- (ntohl (b1.value__), ntohl (b2.value__)));
+ GNUNET_BANDWIDTH_value_init (GNUNET_MIN
+ (ntohl (b1.value__), ntohl (b2.value__)));
}
*/
uint64_t
GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
- bps,
- struct GNUNET_TIME_Relative
- deadline)
+ bps,
+ struct GNUNET_TIME_Relative
+ deadline)
{
uint64_t b;
*/
struct GNUNET_TIME_Relative
GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps,
- uint64_t size)
+ uint64_t size)
{
uint64_t b;
struct GNUNET_TIME_Relative ret;
b = ntohl (bps.value__);
if (b == 0)
- {
+ {
#if DEBUG_BANDWIDTH
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Bandwidth suggests delay of infinity (zero bandwidth)\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Bandwidth suggests delay of infinity (zero bandwidth)\n");
#endif
- return GNUNET_TIME_UNIT_FOREVER_REL;
- }
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
ret.rel_value = size * 1000LL / b;
#if DEBUG_BANDWIDTH
LOG (GNUNET_ERROR_TYPE_DEBUG,
*/
void
GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
- struct GNUNET_BANDWIDTH_Value32NBO
- bytes_per_second_limit, uint32_t max_carry_s)
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bytes_per_second_limit, uint32_t max_carry_s)
{
av->consumption_since_last_update__ = 0;
av->last_update__ = GNUNET_TIME_absolute_get ();
#if DEBUG_BANDWIDTH
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Tracker %p initialized with %u Bps and max carry %u\n", av,
- (unsigned int) av->available_bytes_per_s__,
- (unsigned int) max_carry_s);
+ (unsigned int) av->available_bytes_per_s__, (unsigned int) max_carry_s);
#endif
}
now = GNUNET_TIME_absolute_get ();
delta_time = now.abs_value - av->last_update__.abs_value;
delta_avail =
- (delta_time * ((unsigned long long) av->available_bytes_per_s__) +
- 500LL) / 1000LL;
+ (delta_time * ((unsigned long long) av->available_bytes_per_s__) +
+ 500LL) / 1000LL;
av->consumption_since_last_update__ -= delta_avail;
av->last_update__ = now;
if (av->consumption_since_last_update__ < 0)
- {
- left_bytes = -av->consumption_since_last_update__;
- max_carry = av->available_bytes_per_s__ * av->max_carry_s__;
- if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE)
- max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE;
- if (max_carry > left_bytes)
- av->consumption_since_last_update__ = -left_bytes;
- else
- av->consumption_since_last_update__ = -max_carry;
- }
+ {
+ left_bytes = -av->consumption_since_last_update__;
+ max_carry = av->available_bytes_per_s__ * av->max_carry_s__;
+ if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE;
+ if (max_carry > left_bytes)
+ av->consumption_since_last_update__ = -left_bytes;
+ else
+ av->consumption_since_last_update__ = -max_carry;
+ }
#if DEBUG_BANDWIDTH
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p updated, have %u Bps, last update was %llu ms ago\n",
- av, (unsigned int) av->available_bytes_per_s__,
+ "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", av,
+ (unsigned int) av->available_bytes_per_s__,
(unsigned long long) delta_time);
#endif
*/
int
GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
- ssize_t size)
+ ssize_t size)
{
int64_t nc;
(int) size);
#endif
if (size > 0)
+ {
+ nc = av->consumption_since_last_update__ + size;
+ if (nc < av->consumption_since_last_update__)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ av->consumption_since_last_update__ = nc;
+ update_tracker (av);
+ if (av->consumption_since_last_update__ > 0)
{
- nc = av->consumption_since_last_update__ + size;
- if (nc < av->consumption_since_last_update__)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- av->consumption_since_last_update__ = nc;
- update_tracker (av);
- if (av->consumption_since_last_update__ > 0)
- {
#if DEBUG_BANDWIDTH
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p consumption %llu bytes above limit\n", av,
- (unsigned long long) av->consumption_since_last_update__);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Tracker %p consumption %llu bytes above limit\n", av,
+ (unsigned long long) av->consumption_since_last_update__);
#endif
- return GNUNET_YES;
- }
+ return GNUNET_YES;
}
+ }
else
- {
- av->consumption_since_last_update__ += size;
- }
+ {
+ av->consumption_since_last_update__ += size;
+ }
return GNUNET_NO;
}
*/
struct GNUNET_TIME_Relative
GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av,
- size_t size)
+ size_t size)
{
struct GNUNET_TIME_Relative ret;
int64_t bytes_needed;
if (av->available_bytes_per_s__ == 0)
- {
+ {
#if DEBUG_BANDWIDTH
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av);
#endif
- return GNUNET_TIME_UNIT_FOREVER_REL;
- }
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
update_tracker (av);
bytes_needed = size + av->consumption_since_last_update__;
if (bytes_needed <= 0)
- {
+ {
#if DEBUG_BANDWIDTH
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p delay for %u bytes is zero\n", av,
- (unsigned int) size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is zero\n", av,
+ (unsigned int) size);
#endif
- return GNUNET_TIME_UNIT_ZERO;
- }
+ return GNUNET_TIME_UNIT_ZERO;
+ }
ret.rel_value =
- (1000LL * bytes_needed) / (unsigned long long) av->available_bytes_per_s__;
+ (1000LL * bytes_needed) /
+ (unsigned long long) av->available_bytes_per_s__;
#if DEBUG_BANDWIDTH
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p delay for %u bytes is %llu ms\n", av,
- (unsigned int) size, (unsigned long long) ret.rel_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is %llu ms\n",
+ av, (unsigned int) size, (unsigned long long) ret.rel_value);
#endif
return ret;
}
update_tracker (av);
bps = GNUNET_BANDWIDTH_value_init (av->available_bytes_per_s__);
avail =
- GNUNET_BANDWIDTH_value_get_available_until (bps,
- GNUNET_TIME_absolute_get_duration
- (av->last_update__));
+ GNUNET_BANDWIDTH_value_get_available_until (bps,
+ GNUNET_TIME_absolute_get_duration
+ (av->last_update__));
used = av->consumption_since_last_update__;
#if DEBUG_BANDWIDTH
LOG (GNUNET_ERROR_TYPE_DEBUG,
*/
void
GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av,
- struct GNUNET_BANDWIDTH_Value32NBO
- bytes_per_second_limit)
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bytes_per_second_limit)
{
uint32_t old_limit;
uint32_t new_limit;
new_limit = ntohl (bytes_per_second_limit.value__);
#if DEBUG_BANDWIDTH
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Tracker %p bandwidth changed to %u Bps\n", av,
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p bandwidth changed to %u Bps\n", av,
(unsigned int) new_limit);
#endif
update_tracker (av);
old_limit = av->available_bytes_per_s__;
av->available_bytes_per_s__ = new_limit;
if (old_limit > new_limit)
- update_tracker (av); /* maximum excess might be less now */
+ update_tracker (av); /* maximum excess might be less now */
}
struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_BIO_ReadHandle *h;
- fd =
- GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
+ fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
if (NULL == fd)
return NULL;
h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE);
*/
int
GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
- void *result, size_t len)
+ void *result, size_t len)
{
char *dst = result;
size_t min;
return GNUNET_SYSERR;
pos = 0;
do
+ {
+ /* first, use buffer */
+ min = h->have - h->pos;
+ if (min > 0)
{
- /* first, use buffer */
- min = h->have - h->pos;
- if (min > 0)
- {
- if (min > len - pos)
- min = len - pos;
- memcpy (&dst[pos], &h->buffer[h->pos], min);
- h->pos += min;
- pos += min;
- }
- if (pos == len)
- return GNUNET_OK; /* done! */
- GNUNET_assert (h->have == h->pos);
- /* fill buffer */
- ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
- if (ret == -1)
- {
- GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
- STRERROR (errno));
- return GNUNET_SYSERR;
- }
- if (ret == 0)
- {
- GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
- _("End of file"));
- return GNUNET_SYSERR;
- }
- h->pos = 0;
- h->have = ret;
+ if (min > len - pos)
+ min = len - pos;
+ memcpy (&dst[pos], &h->buffer[h->pos], min);
+ h->pos += min;
+ pos += min;
+ }
+ if (pos == len)
+ return GNUNET_OK; /* done! */
+ GNUNET_assert (h->have == h->pos);
+ /* fill buffer */
+ ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
+ if (ret == -1)
+ {
+ GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
+ STRERROR (errno));
+ return GNUNET_SYSERR;
+ }
+ if (ret == 0)
+ {
+ GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
+ _("End of file"));
+ return GNUNET_SYSERR;
}
- while (pos < len); /* should always be true */
+ h->pos = 0;
+ h->have = ret;
+ }
+ while (pos < len); /* should always be true */
return GNUNET_OK;
}
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
int
-GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file,
- int line, void *result, size_t len)
+GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line,
+ void *result, size_t len)
{
char what[1024];
*/
int
GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
- char **result, size_t maxLen)
+ char **result, size_t maxLen)
{
char *buf;
uint32_t big;
if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
- {
- GNUNET_free_non_null (h->emsg);
- GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"),
- what);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free_non_null (h->emsg);
+ GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what);
+ return GNUNET_SYSERR;
+ }
if (big == 0)
- {
- *result = NULL;
- return GNUNET_OK;
- }
+ {
+ *result = NULL;
+ return GNUNET_OK;
+ }
if (big > maxLen)
- {
- GNUNET_asprintf (&h->emsg,
- _("String `%s' longer than allowed (%u > %u)"), what,
- big, maxLen);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_asprintf (&h->emsg, _("String `%s' longer than allowed (%u > %u)"),
+ what, big, maxLen);
+ return GNUNET_SYSERR;
+ }
buf = GNUNET_malloc (big);
*result = buf;
buf[--big] = '\0';
if (big == 0)
return GNUNET_OK;
if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
- {
- GNUNET_free (buf);
- *result = NULL;
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (buf);
+ *result = NULL;
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
*/
int
GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
- struct GNUNET_CONTAINER_MetaData **result)
+ struct GNUNET_CONTAINER_MetaData **result)
{
uint32_t size;
char *buf;
if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK)
return GNUNET_SYSERR;
if (size == 0)
- {
- *result = NULL;
- return GNUNET_OK;
- }
+ {
+ *result = NULL;
+ return GNUNET_OK;
+ }
if (size > MAX_META_DATA)
- {
- GNUNET_asprintf (&h->emsg,
- _
- ("Serialized metadata `%s' larger than allowed (%u>%u)"),
- what, size, MAX_META_DATA);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_asprintf (&h->emsg,
+ _("Serialized metadata `%s' larger than allowed (%u>%u)"),
+ what, size, MAX_META_DATA);
+ return GNUNET_SYSERR;
+ }
buf = GNUNET_malloc (size);
if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
- {
- GNUNET_free (buf);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (buf);
+ return GNUNET_SYSERR;
+ }
meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
if (meta == NULL)
- {
- GNUNET_free (buf);
- GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"),
- what);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (buf);
+ GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (buf);
*result = meta;
return GNUNET_OK;
*/
int
GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
- int line, int32_t * i)
+ int line, int32_t * i)
{
int32_t big;
*/
int
GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
- int line, int64_t * i)
+ int line, int64_t * i)
{
int64_t big;
struct GNUNET_BIO_WriteHandle *h;
fd = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_WRITE |
- GNUNET_DISK_OPEN_TRUNCATE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
+ | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
return NULL;
- h =
- GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
+ h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
h->buffer = (char *) &h[1];
h->size = BIO_BUFFER_SIZE;
h->fd = fd;
int ret;
if (NULL == h->fd)
- {
- ret = GNUNET_SYSERR;
- }
+ {
+ ret = GNUNET_SYSERR;
+ }
else
- {
- wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
- if (wrt == h->have)
- ret = GNUNET_OK;
- else
- ret = GNUNET_SYSERR;
- GNUNET_DISK_file_close (h->fd);
- }
+ {
+ wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
+ if (wrt == h->have)
+ ret = GNUNET_OK;
+ else
+ ret = GNUNET_SYSERR;
+ GNUNET_DISK_file_close (h->fd);
+ }
GNUNET_free (h);
return ret;
}
*/
int
GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
- size_t n)
+ size_t n)
{
const char *src = buffer;
size_t min;
return GNUNET_SYSERR;
pos = 0;
do
+ {
+ /* first, just use buffer */
+ min = h->size - h->have;
+ if (min > n - pos)
+ min = n - pos;
+ memcpy (&h->buffer[h->have], &src[pos], min);
+ pos += min;
+ h->have += min;
+ if (pos == n)
+ return GNUNET_OK; /* done */
+ GNUNET_assert (h->have == h->size);
+ ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size);
+ if (ret != h->size)
{
- /* first, just use buffer */
- min = h->size - h->have;
- if (min > n - pos)
- min = n - pos;
- memcpy (&h->buffer[h->have], &src[pos], min);
- pos += min;
- h->have += min;
- if (pos == n)
- return GNUNET_OK; /* done */
- GNUNET_assert (h->have == h->size);
- ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size);
- if (ret != h->size)
- {
- GNUNET_DISK_file_close (h->fd);
- h->fd = NULL;
- return GNUNET_SYSERR; /* error */
- }
- h->have = 0;
+ GNUNET_DISK_file_close (h->fd);
+ h->fd = NULL;
+ return GNUNET_SYSERR; /* error */
}
- while (pos < n); /* should always be true */
+ h->have = 0;
+ }
+ while (pos < n); /* should always be true */
GNUNET_break (0);
return GNUNET_OK;
}
*/
int
GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
- const struct GNUNET_CONTAINER_MetaData *m)
+ const struct GNUNET_CONTAINER_MetaData *m)
{
ssize_t size;
char *buf;
return GNUNET_BIO_write_int32 (h, 0);
buf = NULL;
size =
- GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA,
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (size == -1)
- {
- GNUNET_free (buf);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (buf);
+ return GNUNET_SYSERR;
+ }
if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) ||
(GNUNET_OK != GNUNET_BIO_write (h, buf, size)))
- {
- GNUNET_free (buf);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (buf);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (buf);
return GNUNET_OK;
}
*/
static struct GNUNET_CONNECTION_Handle *
do_connect (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int attempt)
+ const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int attempt)
{
struct GNUNET_CONNECTION_Handle *sock;
char *hostname;
sock = NULL;
#if AF_UNIX
if (0 == (attempt % 2))
+ {
+ /* on even rounds, try UNIX */
+ unixpath = NULL;
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */
{
- /* on even rounds, try UNIX */
- unixpath = NULL;
- if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */
- {
- sock =
- GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
- if (sock != NULL)
- {
+ sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
+ if (sock != NULL)
+ {
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n",
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n",
+ unixpath);
#endif
- GNUNET_free (unixpath);
- return sock;
- }
- }
- GNUNET_free_non_null (unixpath);
+ GNUNET_free (unixpath);
+ return sock;
+ }
}
+ GNUNET_free_non_null (unixpath);
+ }
#endif
if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT",
- &port)) || (port > 65535)
- || (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, service_name,
- "HOSTNAME", &hostname)))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
- service_name);
- return NULL;
- }
+ GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port))
+ || (port > 65535) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME",
+ &hostname)))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
+ service_name);
+ return NULL;
+ }
if (0 == strlen (hostname))
- {
- GNUNET_free (hostname);
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Need a non-empty hostname for service `%s'.\n"), service_name);
- return NULL;
- }
+ {
+ GNUNET_free (hostname);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Need a non-empty hostname for service `%s'.\n"), service_name);
+ return NULL;
+ }
if (port == 0)
- {
+ {
#if AF_UNIX
- if (0 != (attempt % 2))
- {
- /* try UNIX */
- unixpath = NULL;
- if ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, service_name,
- "UNIXPATH", &unixpath))
- && (0 < strlen (unixpath)))
- {
- sock =
- GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg,
- unixpath);
- if (sock != NULL)
- {
- GNUNET_free (unixpath);
- GNUNET_free (hostname);
- return sock;
- }
- }
- GNUNET_free_non_null (unixpath);
- }
+ if (0 != (attempt % 2))
+ {
+ /* try UNIX */
+ unixpath = NULL;
+ if ((GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH",
+ &unixpath)) &&
+ (0 < strlen (unixpath)))
+ {
+ sock =
+ GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
+ if (sock != NULL)
+ {
+ GNUNET_free (unixpath);
+ GNUNET_free (hostname);
+ return sock;
+ }
+ }
+ GNUNET_free_non_null (unixpath);
+ }
#endif
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n",
- service_name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n",
+ service_name);
#endif
- GNUNET_free (hostname);
- return NULL;
- }
+ GNUNET_free (hostname);
+ return NULL;
+ }
sock = GNUNET_CONNECTION_create_from_connect (cfg, hostname, port);
GNUNET_free (hostname);
*/
struct GNUNET_CLIENT_Connection *
GNUNET_CLIENT_connect (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CLIENT_Connection *ret;
struct GNUNET_CONNECTION_Handle *sock;
*/
void
GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock,
- int finish_pending_write)
+ int finish_pending_write)
{
if (sock->in_receive == GNUNET_YES)
- {
- GNUNET_CONNECTION_receive_cancel (sock->sock);
- sock->in_receive = GNUNET_NO;
- }
+ {
+ GNUNET_CONNECTION_receive_cancel (sock->sock);
+ sock->in_receive = GNUNET_NO;
+ }
if (sock->th != NULL)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th);
- sock->th = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th);
+ sock->th = NULL;
+ }
if (NULL != sock->sock)
- {
- GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write);
- sock->sock = NULL;
- }
+ {
+ GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write);
+ sock->sock = NULL;
+ }
if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sock->receive_task);
- sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (sock->receive_task);
+ sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (sock->tag != NULL)
- {
- GNUNET_free (sock->tag);
- sock->tag = NULL;
- }
+ {
+ GNUNET_free (sock->tag);
+ sock->tag = NULL;
+ }
sock->receiver_handler = NULL;
GNUNET_array_grow (sock->received_buf, sock->received_size, 0);
GNUNET_free (sock->service_name);
if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) &&
(conn->received_pos >=
ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)->
- size)))
+ size)))
conn->msg_complete = GNUNET_YES;
}
*/
static void
receive_helper (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+ const struct sockaddr *addr, socklen_t addrlen, int errCode)
{
struct GNUNET_CLIENT_Connection *conn = cls;
struct GNUNET_TIME_Relative remaining;
GNUNET_assert (conn->msg_complete == GNUNET_NO);
conn->in_receive = GNUNET_NO;
if ((available == 0) || (conn->sock == NULL) || (errCode != 0))
- {
- /* signal timeout! */
+ {
+ /* signal timeout! */
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n",
- (unsigned int) available,
- conn->sock == NULL ? "NULL" : "non-NULL", STRERROR (errCode));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n",
+ (unsigned int) available, conn->sock == NULL ? "NULL" : "non-NULL",
+ STRERROR (errCode));
#endif
- if (NULL != (receive_handler = conn->receiver_handler))
- {
- receive_handler_cls = conn->receiver_handler_cls;
- conn->receiver_handler = NULL;
- receive_handler (receive_handler_cls, NULL);
- }
- return;
+ if (NULL != (receive_handler = conn->receiver_handler))
+ {
+ receive_handler_cls = conn->receiver_handler_cls;
+ conn->receiver_handler = NULL;
+ receive_handler (receive_handler_cls, NULL);
}
+ return;
+ }
/* FIXME: optimize for common fast case where buf contains the
* entire message and we need no copying... */
/* slow path: append to array */
if (conn->received_size < conn->received_pos + available)
GNUNET_array_grow (conn->received_buf, conn->received_size,
- conn->received_pos + available);
+ conn->received_pos + available);
memcpy (&conn->received_buf[conn->received_pos], buf, available);
conn->received_pos += available;
check_complete (conn);
/* check for timeout */
remaining = GNUNET_TIME_absolute_get_remaining (conn->receive_timeout);
if (remaining.rel_value == 0)
- {
- /* signal timeout! */
- if (NULL != conn->receiver_handler)
- conn->receiver_handler (conn->receiver_handler_cls, NULL);
- return;
- }
+ {
+ /* signal timeout! */
+ if (NULL != conn->receiver_handler)
+ conn->receiver_handler (conn->receiver_handler_cls, NULL);
+ return;
+ }
/* back to receive -- either for more data or to call callback! */
GNUNET_CLIENT_receive (conn, conn->receiver_handler,
- conn->receiver_handler_cls, remaining);
+ conn->receiver_handler_cls, remaining);
}
struct GNUNET_CLIENT_Connection *sock = cls;
GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler;
const struct GNUNET_MessageHeader *cmsg =
- (const struct GNUNET_MessageHeader *) sock->received_buf;
+ (const struct GNUNET_MessageHeader *) sock->received_buf;
void *handler_cls = sock->receiver_handler_cls;
uint16_t msize = ntohs (cmsg->size);
char mbuf[msize];
struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u\n", ntohs (cmsg->type),
- msize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u\n",
+ ntohs (cmsg->type), msize);
#endif
sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (GNUNET_YES == sock->msg_complete);
GNUNET_assert (sock->received_pos >= msize);
memcpy (msg, cmsg, msize);
memmove (sock->received_buf, &sock->received_buf[msize],
- sock->received_pos - msize);
+ sock->received_pos - msize);
sock->received_pos -= msize;
sock->msg_complete = GNUNET_NO;
sock->receiver_handler = NULL;
*/
void
GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
- GNUNET_CLIENT_MessageHandler handler,
- void *handler_cls, struct GNUNET_TIME_Relative timeout)
+ GNUNET_CLIENT_MessageHandler handler, void *handler_cls,
+ struct GNUNET_TIME_Relative timeout)
{
if (sock->sock == NULL)
- {
- /* already disconnected, fail instantly! */
- GNUNET_break (0); /* this should not happen in well-written code! */
- if (NULL != handler)
- handler (handler_cls, NULL);
- return;
- }
+ {
+ /* already disconnected, fail instantly! */
+ GNUNET_break (0); /* this should not happen in well-written code! */
+ if (NULL != handler)
+ handler (handler_cls, NULL);
+ return;
+ }
sock->receiver_handler = handler;
sock->receiver_handler_cls = handler_cls;
sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
if (GNUNET_YES == sock->msg_complete)
- {
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task);
- sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock);
- }
+ {
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task);
+ sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock);
+ }
else
- {
- GNUNET_assert (sock->in_receive == GNUNET_NO);
- sock->in_receive = GNUNET_YES;
+ {
+ GNUNET_assert (sock->in_receive == GNUNET_NO);
+ sock->in_receive = GNUNET_YES;
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n");
#endif
- GNUNET_CONNECTION_receive (sock->sock,
- GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, timeout,
- &receive_helper, sock);
- }
+ GNUNET_CONNECTION_receive (sock->sock, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
+ timeout, &receive_helper, sock);
+ }
}
service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls)
{
GNUNET_SCHEDULER_add_continuation (task, task_cls,
- GNUNET_SCHEDULER_REASON_TIMEOUT);
+ GNUNET_SCHEDULER_REASON_TIMEOUT);
}
* detail in the future, for example, is this the
* correct service? FIXME! */
if (msg != NULL)
- {
+ {
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received confirmation that service is running.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received confirmation that service is running.\n");
#endif
- GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- }
+ GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ }
else
- {
- service_test_error (conn->test_cb, conn->test_cb_cls);
- }
+ {
+ service_test_error (conn->test_cb, conn->test_cb_cls);
+ }
GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
}
struct GNUNET_MessageHeader *msg;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
+ {
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n"));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n"));
#endif
- service_test_error (conn->test_cb, conn->test_cb_cls);
- GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
- return 0; /* client disconnected */
- }
+ service_test_error (conn->test_cb, conn->test_cb_cls);
+ GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
+ return 0; /* client disconnected */
+ }
#if DEBUG_CLIENT
LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST");
#endif
msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_CLIENT_receive (conn, &confirm_handler, conn,
- GNUNET_TIME_absolute_get_remaining
- (conn->test_deadline));
+ GNUNET_TIME_absolute_get_remaining
+ (conn->test_deadline));
return sizeof (struct GNUNET_MessageHeader);
}
*/
void
GNUNET_CLIENT_service_test (const char *service,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
char *hostname;
unsigned long long port;
char *unixpath;
unixpath = NULL;
- if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */
+ {
+ if (strlen (unixpath) >= sizeof (s_un.sun_path))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
+ sizeof (s_un.sun_path));
+ }
+ else
{
- if (strlen (unixpath) >= sizeof (s_un.sun_path))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"),
- unixpath, sizeof (s_un.sun_path));
- }
- else
- {
- sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
- if (sock != NULL)
- {
- memset (&s_un, 0, sizeof (s_un));
- s_un.sun_family = AF_UNIX;
- slen = strlen (unixpath) + 1;
- if (slen >= sizeof (s_un.sun_path))
- slen = sizeof (s_un.sun_path) - 1;
- memcpy (s_un.sun_path, unixpath, slen);
- s_un.sun_path[slen] = '\0';
- slen = sizeof (struct sockaddr_un);
+ sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
+ if (sock != NULL)
+ {
+ memset (&s_un, 0, sizeof (s_un));
+ s_un.sun_family = AF_UNIX;
+ slen = strlen (unixpath) + 1;
+ if (slen >= sizeof (s_un.sun_path))
+ slen = sizeof (s_un.sun_path) - 1;
+ memcpy (s_un.sun_path, unixpath, slen);
+ s_un.sun_path[slen] = '\0';
+ slen = sizeof (struct sockaddr_un);
#if LINUX
- s_un.sun_path[0] = '\0';
+ s_un.sun_path[0] = '\0';
#endif
#if HAVE_SOCKADDR_IN_SIN_LEN
- s_un.sun_len = (u_char) slen;
+ s_un.sun_len = (u_char) slen;
#endif
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (sock,
- (const struct sockaddr *)
- &s_un, slen))
- {
- /* failed to bind => service must be running */
- GNUNET_free (unixpath);
- (void) GNUNET_NETWORK_socket_close (sock);
- GNUNET_SCHEDULER_add_continuation (task, task_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- }
- (void) GNUNET_NETWORK_socket_close (sock);
- }
- /* let's try IP */
- }
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un,
+ slen))
+ {
+ /* failed to bind => service must be running */
+ GNUNET_free (unixpath);
+ (void) GNUNET_NETWORK_socket_close (sock);
+ GNUNET_SCHEDULER_add_continuation (task, task_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
+ (void) GNUNET_NETWORK_socket_close (sock);
+ }
+ /* let's try IP */
}
+ }
GNUNET_free_non_null (unixpath);
}
#endif
(port > 65535) ||
(GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, service, "HOSTNAME",
- &hostname)))
- {
- /* UNIXPATH failed (if possible) AND IP failed => error */
- service_test_error (task, task_cls);
- return;
- }
+ &hostname)))
+ {
+ /* UNIXPATH failed (if possible) AND IP failed => error */
+ service_test_error (task, task_cls);
+ return;
+ }
if (0 == strcmp ("localhost", hostname)
#if !LINUX
&& 0
#endif
- )
- {
- /* can test using 'bind' */
- struct sockaddr_in s_in;
+ )
+ {
+ /* can test using 'bind' */
+ struct sockaddr_in s_in;
- memset (&s_in, 0, sizeof (s_in));
+ memset (&s_in, 0, sizeof (s_in));
#if HAVE_SOCKADDR_IN_SIN_LEN
- s_in.sin_len = sizeof (struct sockaddr_in);
+ s_in.sin_len = sizeof (struct sockaddr_in);
#endif
- s_in.sin_family = AF_INET;
- s_in.sin_port = htons (port);
+ s_in.sin_family = AF_INET;
+ s_in.sin_port = htons (port);
- sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
- if (sock != NULL)
- {
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (sock,
- (const struct sockaddr *) &s_in,
- sizeof (s_in)))
- {
- /* failed to bind => service must be running */
- GNUNET_free (hostname);
- (void) GNUNET_NETWORK_socket_close (sock);
- GNUNET_SCHEDULER_add_continuation (task, task_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- }
- (void) GNUNET_NETWORK_socket_close (sock);
- }
+ sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
+ if (sock != NULL)
+ {
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in,
+ sizeof (s_in)))
+ {
+ /* failed to bind => service must be running */
+ GNUNET_free (hostname);
+ (void) GNUNET_NETWORK_socket_close (sock);
+ GNUNET_SCHEDULER_add_continuation (task, task_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
+ (void) GNUNET_NETWORK_socket_close (sock);
}
+ }
if (0 == strcmp ("ip6-localhost", hostname)
#if !LINUX
&& 0
#endif
- )
- {
- /* can test using 'bind' */
- struct sockaddr_in6 s_in6;
+ )
+ {
+ /* can test using 'bind' */
+ struct sockaddr_in6 s_in6;
- memset (&s_in6, 0, sizeof (s_in6));
+ memset (&s_in6, 0, sizeof (s_in6));
#if HAVE_SOCKADDR_IN_SIN_LEN
- s_in6.sin6_len = sizeof (struct sockaddr_in6);
+ s_in6.sin6_len = sizeof (struct sockaddr_in6);
#endif
- s_in6.sin6_family = AF_INET6;
- s_in6.sin6_port = htons (port);
+ s_in6.sin6_family = AF_INET6;
+ s_in6.sin6_port = htons (port);
- sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0);
- if (sock != NULL)
- {
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (sock,
- (const struct sockaddr *) &s_in6,
- sizeof (s_in6)))
- {
- /* failed to bind => service must be running */
- GNUNET_free (hostname);
- (void) GNUNET_NETWORK_socket_close (sock);
- GNUNET_SCHEDULER_add_continuation (task, task_cls,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- return;
- }
- (void) GNUNET_NETWORK_socket_close (sock);
- }
+ sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0);
+ if (sock != NULL)
+ {
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6,
+ sizeof (s_in6)))
+ {
+ /* failed to bind => service must be running */
+ GNUNET_free (hostname);
+ (void) GNUNET_NETWORK_socket_close (sock);
+ GNUNET_SCHEDULER_add_continuation (task, task_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
+ (void) GNUNET_NETWORK_socket_close (sock);
}
+ }
if (((0 == strcmp ("localhost", hostname)) ||
(0 == strcmp ("ip6-localhost", hostname)))
#if !LINUX
&& 0
#endif
- )
- {
- /* all binds succeeded => claim service not running right now */
- GNUNET_free_non_null (hostname);
- service_test_error (task, task_cls);
- return;
- }
+ )
+ {
+ /* all binds succeeded => claim service not running right now */
+ GNUNET_free_non_null (hostname);
+ service_test_error (task, task_cls);
+ return;
+ }
GNUNET_free_non_null (hostname);
/* non-localhost, try 'connect' method */
conn = GNUNET_CLIENT_connect (service, cfg);
if (conn == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Could not connect to service `%s', must not be running.\n"),
- service);
- service_test_error (task, task_cls);
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Could not connect to service `%s', must not be running.\n"),
+ service);
+ service_test_error (task, task_cls);
+ return;
+ }
conn->test_cb = task;
conn->test_cb_cls = task_cls;
conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout);
if (NULL ==
GNUNET_CLIENT_notify_transmit_ready (conn,
- sizeof (struct
- GNUNET_MessageHeader),
- timeout, GNUNET_YES, &write_test,
- conn))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failure to transmit request to service `%s'\n"), service);
- service_test_error (task, task_cls);
- GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
- return;
- }
+ sizeof (struct GNUNET_MessageHeader),
+ timeout, GNUNET_YES, &write_test,
+ conn))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure to transmit request to service `%s'\n"), service);
+ service_test_error (task, task_cls);
+ GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
+ return;
+ }
}
* @param buf where to write them
* @return number of bytes written to buf
*/
-static size_t client_notify (void *cls, size_t size, void *buf);
+static size_t
+client_notify (void *cls, size_t size, void *buf);
/**
* @param tc unused
*/
static void
-client_delayed_retry (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CLIENT_TransmitHandle *th = cls;
struct GNUNET_TIME_Relative delay;
th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
+ {
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed due to shutdown.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed due to shutdown.\n");
#endif
- th->sock->th = NULL;
- th->notify (th->notify_cls, 0, NULL);
- GNUNET_free (th);
- return;
- }
+ th->sock->th = NULL;
+ th->notify (th->notify_cls, 0, NULL);
+ GNUNET_free (th);
+ return;
+ }
th->sock->sock =
- do_connect (th->sock->service_name, th->sock->cfg, th->sock->attempts++);
+ do_connect (th->sock->service_name, th->sock->cfg, th->sock->attempts++);
if (NULL == th->sock->sock)
- {
- /* could happen if we're out of sockets */
- delay =
- GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining
- (th->timeout), th->sock->back_off);
- th->sock->back_off =
- GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply
- (th->sock->back_off, 2),
- GNUNET_TIME_UNIT_SECONDS);
+ {
+ /* could happen if we're out of sockets */
+ delay =
+ GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining
+ (th->timeout), th->sock->back_off);
+ th->sock->back_off =
+ GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply
+ (th->sock->back_off, 2),
+ GNUNET_TIME_UNIT_SECONDS);
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed %u times, trying again in %llums.\n",
- MAX_ATTEMPTS - th->attempts_left,
- (unsigned long long) delay.rel_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed %u times, trying again in %llums.\n",
+ MAX_ATTEMPTS - th->attempts_left,
+ (unsigned long long) delay.rel_value);
#endif
- th->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
- return;
- }
+ th->reconnect_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+ return;
+ }
th->th =
- GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size,
- GNUNET_TIME_absolute_get_remaining
- (th->timeout), &client_notify,
- th);
+ GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size,
+ GNUNET_TIME_absolute_get_remaining
+ (th->timeout), &client_notify,
+ th);
if (th->th == NULL)
- {
- GNUNET_break (0);
- th->sock->th = NULL;
- th->notify (th->notify_cls, 0, NULL);
- GNUNET_free (th);
- return;
- }
+ {
+ GNUNET_break (0);
+ th->sock->th = NULL;
+ th->notify (th->notify_cls, 0, NULL);
+ GNUNET_free (th);
+ return;
+ }
}
th->th = NULL;
th->sock->th = NULL;
if (buf == NULL)
+ {
+ delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
+ delay.rel_value /= 2;
+ if ((0 !=
+ (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ())) ||
+ (GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) ||
+ (delay.rel_value < 1))
{
- delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
- delay.rel_value /= 2;
- if ((0 !=
- (GNUNET_SCHEDULER_REASON_SHUTDOWN &
- GNUNET_SCHEDULER_get_reason ())) || (GNUNET_YES != th->auto_retry)
- || (0 == --th->attempts_left) || (delay.rel_value < 1))
- {
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed %u times, giving up.\n",
- MAX_ATTEMPTS - th->attempts_left);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed %u times, giving up.\n",
+ MAX_ATTEMPTS - th->attempts_left);
#endif
- GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL));
- GNUNET_free (th);
- return 0;
- }
- /* auto-retry */
+ GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL));
+ GNUNET_free (th);
+ return 0;
+ }
+ /* auto-retry */
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect to `%s', automatically trying again.\n",
- th->sock->service_name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect to `%s', automatically trying again.\n",
+ th->sock->service_name);
#endif
- GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO);
- th->sock->sock = NULL;
- delay = GNUNET_TIME_relative_min (delay, th->sock->back_off);
- th->sock->back_off =
- GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply
- (th->sock->back_off, 2),
- GNUNET_TIME_UNIT_SECONDS);
+ GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO);
+ th->sock->sock = NULL;
+ delay = GNUNET_TIME_relative_min (delay, th->sock->back_off);
+ th->sock->back_off =
+ GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply
+ (th->sock->back_off, 2),
+ GNUNET_TIME_UNIT_SECONDS);
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed %u times, trying again in %llums.\n",
- MAX_ATTEMPTS - th->attempts_left,
- (unsigned long long) delay.rel_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed %u times, trying again in %llums.\n",
+ MAX_ATTEMPTS - th->attempts_left,
+ (unsigned long long) delay.rel_value);
#endif
- th->sock->th = th;
- th->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
- return 0;
- }
+ th->sock->th = th;
+ th->reconnect_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+ return 0;
+ }
GNUNET_assert (size >= th->size);
ret = th->notify (th->notify_cls, size, buf);
GNUNET_free (th);
*/
struct GNUNET_CLIENT_TransmitHandle *
GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
- size_t size,
- struct GNUNET_TIME_Relative timeout,
- int auto_retry,
- GNUNET_CONNECTION_TransmitReadyNotify
- notify, void *notify_cls)
+ size_t size,
+ struct GNUNET_TIME_Relative timeout,
+ int auto_retry,
+ GNUNET_CONNECTION_TransmitReadyNotify
+ notify, void *notify_cls)
{
struct GNUNET_CLIENT_TransmitHandle *th;
if (NULL != sock->th)
- {
- /* If this breaks, you most likley called this function twice without waiting
- * for completion or canceling the request */
- GNUNET_break (0);
- return NULL;
- }
+ {
+ /* If this breaks, you most likley called this function twice without waiting
+ * for completion or canceling the request */
+ GNUNET_break (0);
+ return NULL;
+ }
th = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_TransmitHandle));
th->sock = sock;
th->size = size;
th->attempts_left = MAX_ATTEMPTS;
sock->th = th;
if (sock->sock == NULL)
- {
- th->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (sock->back_off, &client_delayed_retry,
- th);
+ {
+ th->reconnect_task =
+ GNUNET_SCHEDULER_add_delayed (sock->back_off, &client_delayed_retry,
+ th);
- }
+ }
else
+ {
+ th->th =
+ GNUNET_CONNECTION_notify_transmit_ready (sock->sock, size, timeout,
+ &client_notify, th);
+ if (NULL == th->th)
{
- th->th =
- GNUNET_CONNECTION_notify_transmit_ready (sock->sock, size, timeout,
- &client_notify, th);
- if (NULL == th->th)
- {
- GNUNET_break (0);
- GNUNET_free (th);
- sock->th = NULL;
- return NULL;
- }
+ GNUNET_break (0);
+ GNUNET_free (th);
+ sock->th = NULL;
+ return NULL;
}
+ }
return th;
}
* @param th handle from the original request.
*/
void
-GNUNET_CLIENT_notify_transmit_ready_cancel (struct
- GNUNET_CLIENT_TransmitHandle *th)
+GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle
+ *th)
{
if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_assert (NULL == th->th);
- GNUNET_SCHEDULER_cancel (th->reconnect_task);
- th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_assert (NULL == th->th);
+ GNUNET_SCHEDULER_cancel (th->reconnect_task);
+ th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
else
- {
- GNUNET_assert (NULL != th->th);
- GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th);
- }
+ {
+ GNUNET_assert (NULL != th->th);
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th);
+ }
th->sock->th = NULL;
GNUNET_free (th);
}
tc->sock->tag = NULL;
msize = ntohs (tc->hdr->size);
if (NULL == buf)
- {
+ {
#if DEBUG_CLIENT
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Could not submit request, not expecting to receive a response.\n"));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ _("Could not submit request, not expecting to receive a response.\n"));
#endif
- if (NULL != tc->rn)
- tc->rn (tc->rn_cls, NULL);
- GNUNET_free (tc);
- return 0;
- }
+ if (NULL != tc->rn)
+ tc->rn (tc->rn_cls, NULL);
+ GNUNET_free (tc);
+ return 0;
+ }
GNUNET_assert (size >= msize);
memcpy (buf, tc->hdr, msize);
GNUNET_CLIENT_receive (tc->sock, tc->rn, tc->rn_cls,
- GNUNET_TIME_absolute_get_remaining (tc->timeout));
+ GNUNET_TIME_absolute_get_remaining (tc->timeout));
GNUNET_free (tc);
return msize;
}
* is already pending
*/
int
-GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection
- *sock,
- const struct GNUNET_MessageHeader
- *hdr,
- struct GNUNET_TIME_Relative timeout,
- int auto_retry,
- GNUNET_CLIENT_MessageHandler rn,
- void *rn_cls)
+GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock,
+ const struct GNUNET_MessageHeader *hdr,
+ struct GNUNET_TIME_Relative timeout,
+ int auto_retry,
+ GNUNET_CLIENT_MessageHandler rn,
+ void *rn_cls)
{
struct TransmitGetResponseContext *tc;
uint16_t msize;
tc->rn_cls = rn_cls;
if (NULL ==
GNUNET_CLIENT_notify_transmit_ready (sock, msize, timeout, auto_retry,
- &transmit_for_response, tc))
- {
- GNUNET_break (0);
- GNUNET_free (tc);
- return GNUNET_SYSERR;
- }
+ &transmit_for_response, tc))
+ {
+ GNUNET_break (0);
+ GNUNET_free (tc);
+ return GNUNET_SYSERR;
+ }
sock->tag = tc;
return GNUNET_OK;
}
GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
if (ret == NULL)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
- abort ();
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
+ abort ();
+ }
return ret;
}
*/
void *
GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename,
- int linenumber)
+ int linenumber)
{
void *ret;
GNUNET_assert_at (size < INT_MAX, filename, linenumber);
ret = malloc (size);
if (ret == NULL)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
- abort ();
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
+ abort ();
+ }
#ifdef W32_MEM_LIMIT
*((size_t *) ret) = size;
ret = &((size_t *) ret)[1];
#endif
ptr = realloc (ptr, n);
if ((NULL == ptr) && (n > 0))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
- abort ();
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
+ abort ();
+ }
#ifdef W32_MEM_LIMIT
ptr = &((size_t *) ptr)[1];
#endif
*/
char *
GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
- int linenumber)
+ int linenumber)
{
char *res;
*/
void
GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
- unsigned int newCount, const char *filename, int linenumber)
+ unsigned int newCount, const char *filename, int linenumber)
{
void *tmp;
size_t size;
GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber);
size = newCount * elementSize;
if (size == 0)
- {
- tmp = NULL;
- }
+ {
+ tmp = NULL;
+ }
else
- {
- tmp = GNUNET_xmalloc_ (size, filename, linenumber);
- memset (tmp, 0, size); /* client code should not rely on this, though... */
- if (*oldCount > newCount)
- *oldCount = newCount; /* shrink is also allowed! */
- memcpy (tmp, *old, elementSize * (*oldCount));
- }
+ {
+ tmp = GNUNET_xmalloc_ (size, filename, linenumber);
+ memset (tmp, 0, size); /* client code should not rely on this, though... */
+ if (*oldCount > newCount)
+ *oldCount = newCount; /* shrink is also allowed! */
+ memcpy (tmp, *old, elementSize * (*oldCount));
+ }
if (*old != NULL)
- {
- GNUNET_xfree_ (*old, filename, linenumber);
- }
+ {
+ GNUNET_xfree_ (*old, filename, linenumber);
+ }
*old = tmp;
*oldCount = newCount;
}
*/
static void
add_definition (char *component, char *file, char *function, int from_line,
- int to_line, int level, int force)
+ int to_line, int level, int force)
{
if (logdefs_size == logdefs_len)
resize_logdefs ();
struct LogDef n;
+
memset (&n, 0, sizeof (n));
if (strlen (component) > 0 && component[0] != '*')
n.component = GNUNET_strdup (component);
if (strlen (file) > 0 && file[0] != '*')
- {
- n.file = GNUNET_strdup (file);
- n.strlen_file = strlen (file);
- }
- if ( (NULL != function) &&
- (strlen (function) > 0) &&
- (function[0] != '*') )
+ {
+ n.file = GNUNET_strdup (file);
+ n.strlen_file = strlen (file);
+ }
+ if ((NULL != function) && (strlen (function) > 0) && (function[0] != '*'))
n.function = GNUNET_strdup (function);
n.from_line = from_line;
n.to_line = to_line;
*/
int
GNUNET_get_log_call_status (int caller_level, const char *comp,
- const char *file, const char *function, int line)
+ const char *file, const char *function, int line)
{
struct LogDef *ld;
int i;
force_only = min_level >= 0;
strlen_file = strlen (file);
for (i = 0; i < logdefs_len; i++)
+ {
+ ld = &logdefs[i];
+ if ((!force_only || ld->force) &&
+ (line >= ld->from_line && line <= ld->to_line) && (ld->component == NULL
+ || strcmp (comp,
+ ld->component)
+ == 0) &&
+ (ld->file == NULL ||
+ (ld->strlen_file <= strlen_file &&
+ strcmp (&file[strlen_file - ld->strlen_file], ld->file) == 0)) &&
+ (ld->function == NULL || strcmp (function, ld->function) == 0))
{
- ld = &logdefs[i];
- if ((!force_only || ld->force) &&
- (line >= ld->from_line && line <= ld->to_line) &&
- (ld->component == NULL || strcmp (comp, ld->component) == 0) &&
- (ld->file == NULL ||
- (ld->strlen_file <= strlen_file &&
- strcmp (&file[strlen_file - ld->strlen_file], ld->file) == 0)) &&
- (ld->function == NULL || strcmp (function, ld->function) == 0))
- {
- /* We're finished */
- return caller_level <= ld->level;
- }
+ /* We're finished */
+ return caller_level <= ld->level;
}
+ }
/* No matches - use global level, if defined */
if (min_level >= 0)
return caller_level <= min_level;
int from_line, to_line;
int counter = 0;
int keep_looking = 1;
+
tmp = getenv (constname);
if (tmp == NULL)
return 0;
from_line = 0;
to_line = INT_MAX;
for (p = def, state = 0, start = def; keep_looking; p++)
+ {
+ switch (p[0])
{
- switch (p[0])
- {
- case ';': /* found a field separator */
- p[0] = '\0';
- switch (state)
- {
- case 0: /* within a component name */
- comp = start;
- break;
- case 1: /* within a file name */
- file = start;
- break;
- case 2: /* within a function name */
- /* after a file name there must be a function name */
- function = start;
- break;
- case 3: /* within a from-to line range */
- if (strlen (start) > 0)
- {
- errno = 0;
- from_line = strtol (start, &t, 10);
- if (errno != 0 || from_line < 0)
- {
- free (def);
- return counter;
- }
- if (t < p && t[0] == '-')
- {
- errno = 0;
- start = t + 1;
- to_line = strtol (start, &t, 10);
- if (errno != 0 || to_line < 0 || t != p)
- {
- free (def);
- return counter;
- }
- }
- else /* one number means "match this line only" */
- to_line = from_line;
- }
- else /* default to 0-max */
- {
- from_line = 0;
- to_line = INT_MAX;
- }
- break;
- }
- start = p + 1;
- state += 1;
- break;
- case '\0': /* found EOL */
- keep_looking = 0;
- /* fall through to '/' */
- case '/': /* found a definition separator */
- switch (state)
- {
- case 4: /* within a log level */
- p[0] = '\0';
- state = 0;
- level = get_type ((const char *) start);
- if (level == GNUNET_ERROR_TYPE_INVALID
- || level == GNUNET_ERROR_TYPE_UNSPECIFIED)
- {
- free (def);
- return counter;
- }
- add_definition (comp, file, function, from_line, to_line, level,
- force);
- counter += 1;
- start = p + 1;
- break;
- default:
- break;
- }
- default:
- break;
- }
+ case ';': /* found a field separator */
+ p[0] = '\0';
+ switch (state)
+ {
+ case 0: /* within a component name */
+ comp = start;
+ break;
+ case 1: /* within a file name */
+ file = start;
+ break;
+ case 2: /* within a function name */
+ /* after a file name there must be a function name */
+ function = start;
+ break;
+ case 3: /* within a from-to line range */
+ if (strlen (start) > 0)
+ {
+ errno = 0;
+ from_line = strtol (start, &t, 10);
+ if (errno != 0 || from_line < 0)
+ {
+ free (def);
+ return counter;
+ }
+ if (t < p && t[0] == '-')
+ {
+ errno = 0;
+ start = t + 1;
+ to_line = strtol (start, &t, 10);
+ if (errno != 0 || to_line < 0 || t != p)
+ {
+ free (def);
+ return counter;
+ }
+ }
+ else /* one number means "match this line only" */
+ to_line = from_line;
+ }
+ else /* default to 0-max */
+ {
+ from_line = 0;
+ to_line = INT_MAX;
+ }
+ break;
+ }
+ start = p + 1;
+ state += 1;
+ break;
+ case '\0': /* found EOL */
+ keep_looking = 0;
+ /* fall through to '/' */
+ case '/': /* found a definition separator */
+ switch (state)
+ {
+ case 4: /* within a log level */
+ p[0] = '\0';
+ state = 0;
+ level = get_type ((const char *) start);
+ if (level == GNUNET_ERROR_TYPE_INVALID ||
+ level == GNUNET_ERROR_TYPE_UNSPECIFIED)
+ {
+ free (def);
+ return counter;
+ }
+ add_definition (comp, file, function, from_line, to_line, level, force);
+ counter += 1;
+ start = p + 1;
+ break;
+ default:
+ break;
+ }
+ default:
+ break;
}
+ }
free (def);
return counter;
}
gnunet_log_parsed = GNUNET_YES;
if (gnunet_force_log_parsed == GNUNET_NO)
gnunet_force_log_present =
- parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO;
+ parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO;
gnunet_force_log_parsed = GNUNET_YES;
}
#endif
dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
altlog = FOPEN (fn, "a");
if (altlog == NULL)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
- if (dirwarn)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Failed to create or access directory for log file `%s'\n"),
- fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
+ if (dirwarn)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to create or access directory for log file `%s'\n"),
+ fn);
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (fn);
if (GNUNET_stderr != NULL)
fclose (GNUNET_stderr);
prev = NULL;
pos = loggers;
while ((pos != NULL) &&
- ((pos->logger != logger) || (pos->logger_cls != logger_cls)))
- {
- prev = pos;
- pos = pos->next;
- }
+ ((pos->logger != logger) || (pos->logger_cls != logger_cls)))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
GNUNET_assert (pos != NULL);
if (prev == NULL)
loggers = pos->next;
*/
static void
output_message (enum GNUNET_ErrorType kind, const char *comp,
- const char *datestr, const char *msg)
+ const char *datestr, const char *msg)
{
struct CustomLogger *pos;
if (GNUNET_stderr != NULL)
- {
- fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp,
- GNUNET_error_type_to_string (kind), msg);
- fflush (GNUNET_stderr);
- }
+ {
+ fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp,
+ GNUNET_error_type_to_string (kind), msg);
+ fflush (GNUNET_stderr);
+ }
pos = loggers;
while (pos != NULL)
- {
- pos->logger (pos->logger_cls, kind, comp, datestr, msg);
- pos = pos->next;
- }
+ {
+ pos->logger (pos->logger_cls, kind, comp, datestr, msg);
+ pos = pos->next;
+ }
}
else if (last != last_bulk)
last--;
if (last[0] == '\n')
- {
- rev = 1;
- last[0] = '\0';
- }
- ft =
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
- (last_bulk_time));
+ {
+ rev = 1;
+ last[0] = '\0';
+ }
+ ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
+ (last_bulk_time));
snprintf (msg, sizeof (msg),
- _("Message `%.*s' repeated %u times in the last %s\n"),
- BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft);
+ _("Message `%.*s' repeated %u times in the last %s\n"),
+ BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft);
GNUNET_free (ft);
if (rev == 1)
last[0] = '\n';
GNUNET_log_skip (unsigned int n, int check_reset)
{
if (n == 0)
- {
- int ok;
+ {
+ int ok;
- ok = (0 == skip_log);
- skip_log = 0;
- if (check_reset)
- GNUNET_assert (ok);
- }
+ ok = (0 == skip_log);
+ skip_log = 0;
+ if (check_reset)
+ GNUNET_assert (ok);
+ }
else
skip_log += n;
}
tmptr = localtime (&timetmp);
gettimeofday (&timeofday, NULL);
if (NULL != tmptr)
- {
+ {
#ifdef WINDOWS
- LARGE_INTEGER pc;
-
- pc.QuadPart = 0;
- QueryPerformanceCounter (&pc);
- strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr);
- snprintf (date, sizeof (date), date2,
- (long long) (pc.QuadPart /
- (performance_frequency.QuadPart / 1000)));
+ LARGE_INTEGER pc;
+
+ pc.QuadPart = 0;
+ QueryPerformanceCounter (&pc);
+ strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr);
+ snprintf (date, sizeof (date), date2,
+ (long long) (pc.QuadPart /
+ (performance_frequency.QuadPart / 1000)));
#else
- strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr);
- snprintf (date, sizeof (date), date2, timeofday.tv_usec);
+ strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr);
+ snprintf (date, sizeof (date), date2, timeofday.tv_usec);
#endif
- }
+ }
else
strcpy (date, "localtime error");
- if ((0 != (kind & GNUNET_ERROR_TYPE_BULK))
- && (last_bulk_time.abs_value != 0)
- && (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
- {
- last_bulk_repeat++;
- if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value >
- BULK_DELAY_THRESHOLD)
- || (last_bulk_repeat > BULK_REPEAT_THRESHOLD))
- flush_bulk (date);
- return;
- }
+ if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) &&
+ (last_bulk_time.abs_value != 0) &&
+ (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
+ {
+ last_bulk_repeat++;
+ if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value >
+ BULK_DELAY_THRESHOLD) || (last_bulk_repeat > BULK_REPEAT_THRESHOLD))
+ flush_bulk (date);
+ return;
+ }
flush_bulk (date);
strncpy (last_bulk, buf, sizeof (last_bulk));
last_bulk_repeat = 0;
*/
void
GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
- const char *message, ...)
+ const char *message, ...)
{
va_list va;
char comp_w_pid[128];
if (addr == NULL)
return _("unknown address");
switch (addr->sa_family)
- {
- case AF_INET:
- if (addrlen != sizeof (struct sockaddr_in))
- return "<invalid v4 address>";
- v4 = (const struct sockaddr_in *) addr;
- inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
- if (0 == ntohs (v4->sin_port))
- return buf;
- strcat (buf, ":");
- GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port));
- strcat (buf, b2);
- return buf;
- case AF_INET6:
- if (addrlen != sizeof (struct sockaddr_in6))
- return "<invalid v4 address>";
- v6 = (const struct sockaddr_in6 *) addr;
- buf[0] = '[';
- inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
- if (0 == ntohs (v6->sin6_port))
- return &buf[1];
- strcat (buf, "]:");
- GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port));
- strcat (buf, b2);
- return buf;
- case AF_UNIX:
- if (addrlen <= sizeof (sa_family_t))
- return "<unbound UNIX client>";
- un = (const struct sockaddr_un *) addr;
- off = 0;
- if (un->sun_path[0] == '\0')
- off++;
- snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "",
- (int) (addrlen - sizeof (sa_family_t) - 1 - off),
- &un->sun_path[off]);
+ {
+ case AF_INET:
+ if (addrlen != sizeof (struct sockaddr_in))
+ return "<invalid v4 address>";
+ v4 = (const struct sockaddr_in *) addr;
+ inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
+ if (0 == ntohs (v4->sin_port))
return buf;
- default:
- return _("invalid address");
- }
+ strcat (buf, ":");
+ GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port));
+ strcat (buf, b2);
+ return buf;
+ case AF_INET6:
+ if (addrlen != sizeof (struct sockaddr_in6))
+ return "<invalid v4 address>";
+ v6 = (const struct sockaddr_in6 *) addr;
+ buf[0] = '[';
+ inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
+ if (0 == ntohs (v6->sin6_port))
+ return &buf[1];
+ strcat (buf, "]:");
+ GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port));
+ strcat (buf, b2);
+ return buf;
+ case AF_UNIX:
+ if (addrlen <= sizeof (sa_family_t))
+ return "<unbound UNIX client>";
+ un = (const struct sockaddr_un *) addr;
+ off = 0;
+ if (un->sun_path[0] == '\0')
+ off++;
+ snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "",
+ (int) (addrlen - sizeof (sa_family_t) - 1 - off),
+ &un->sun_path[off]);
+ return buf;
+ default:
+ return _("invalid address");
+ }
}
*/
int
GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *filename)
+ const char *filename)
{
int dirty;
char line[256];
fn = GNUNET_STRINGS_filename_expand (filename);
if (fn == NULL)
return GNUNET_SYSERR;
- dirty = cfg->dirty; /* back up value! */
+ dirty = cfg->dirty; /* back up value! */
if (NULL == (fp = FOPEN (fn, "r")))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (fn);
ret = GNUNET_OK;
section = GNUNET_strdup ("");
memset (line, 0, 256);
nr = 0;
while (NULL != fgets (line, 255, fp))
+ {
+ nr++;
+ for (i = 0; i < 255; i++)
+ if (line[i] == '\t')
+ line[i] = ' ';
+ if (line[0] == '\n' || line[0] == '#' || line[0] == '%' || line[0] == '\r')
+ continue;
+ emptyline = 1;
+ for (i = 0; (i < 255 && line[i] != 0); i++)
+ if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r')
+ emptyline = 0;
+ if (emptyline == 1)
+ continue;
+ /* remove tailing whitespace */
+ for (i = strlen (line) - 1; (i >= 0) && (isspace ((unsigned char) line[i]));
+ i--)
+ line[i] = '\0';
+ if (1 == sscanf (line, "@INLINE@ %191[^\n]", value))
{
- nr++;
- for (i = 0; i < 255; i++)
- if (line[i] == '\t')
- line[i] = ' ';
- if (line[0] == '\n' || line[0] == '#' || line[0] == '%'
- || line[0] == '\r')
- continue;
- emptyline = 1;
- for (i = 0; (i < 255 && line[i] != 0); i++)
- if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r')
- emptyline = 0;
- if (emptyline == 1)
- continue;
- /* remove tailing whitespace */
- for (i = strlen (line) - 1;
- (i >= 0) && (isspace ((unsigned char) line[i])); i--)
- line[i] = '\0';
- if (1 == sscanf (line, "@INLINE@ %191[^\n]", value))
- {
- /* @INLINE@ value */
- if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
- ret = GNUNET_SYSERR; /* failed to parse included config */
- }
- else if (1 == sscanf (line, "[%99[^]]]", value))
- {
- /* [value] */
- GNUNET_free (section);
- section = GNUNET_strdup (value);
- }
- else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value))
- {
- /* tag = value */
- /* Strip LF */
- i = strlen (value) - 1;
- while ((i >= 0) && (isspace ((unsigned char) value[i])))
- value[i--] = '\0';
- /* remove quotes */
- i = 0;
- if (value[0] == '"')
- {
- i = 1;
- while ((value[i] != '\0') && (value[i] != '"'))
- i++;
- if (value[i] == '"')
- {
- value[i] = '\0';
- i = 1;
- }
- else
- i = 0;
- }
- GNUNET_CONFIGURATION_set_value_string (cfg, section, tag,
- &value[i]);
- }
- else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
- {
- /* tag = */
- GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, "");
- }
- else
- {
- /* parse error */
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error in configuration file `%s' at line %u.\n"),
- filename, nr);
- ret = GNUNET_SYSERR;
- break;
- }
+ /* @INLINE@ value */
+ if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
+ ret = GNUNET_SYSERR; /* failed to parse included config */
+ }
+ else if (1 == sscanf (line, "[%99[^]]]", value))
+ {
+ /* [value] */
+ GNUNET_free (section);
+ section = GNUNET_strdup (value);
+ }
+ else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value))
+ {
+ /* tag = value */
+ /* Strip LF */
+ i = strlen (value) - 1;
+ while ((i >= 0) && (isspace ((unsigned char) value[i])))
+ value[i--] = '\0';
+ /* remove quotes */
+ i = 0;
+ if (value[0] == '"')
+ {
+ i = 1;
+ while ((value[i] != '\0') && (value[i] != '"'))
+ i++;
+ if (value[i] == '"')
+ {
+ value[i] = '\0';
+ i = 1;
+ }
+ else
+ i = 0;
+ }
+ GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
+ }
+ else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
+ {
+ /* tag = */
+ GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, "");
+ }
+ else
+ {
+ /* parse error */
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Syntax error in configuration file `%s' at line %u.\n"), filename,
+ nr);
+ ret = GNUNET_SYSERR;
+ break;
}
+ }
GNUNET_assert (0 == fclose (fp));
/* restore dirty flag - anything we set in the meantime
* came from disk */
*/
int
GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *filename)
+ const char *filename)
{
struct ConfigSection *sec;
struct ConfigEntry *ent;
if (fn == NULL)
return GNUNET_SYSERR;
if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))
- {
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
if (NULL == (fp = FOPEN (fn, "w")))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (fn);
error = 0;
sec = cfg->sections;
while (sec != NULL)
+ {
+ if (0 > fprintf (fp, "[%s]\n", sec->name))
{
- if (0 > fprintf (fp, "[%s]\n", sec->name))
- {
- error = 1;
- break;
- }
- ent = sec->entries;
- while (ent != NULL)
- {
- if (ent->val != NULL)
- {
- val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
- strcpy (val, ent->val);
- while (NULL != (pos = strstr (val, "\n")))
- {
- memmove (&pos[2], &pos[1], strlen (&pos[1]));
- pos[0] = '\\';
- pos[1] = 'n';
- }
- if (0 > fprintf (fp, "%s = %s\n", ent->key, val))
- {
- error = 1;
- GNUNET_free (val);
- break;
- }
- GNUNET_free (val);
- }
- ent = ent->next;
- }
- if (error != 0)
- break;
- if (0 > fprintf (fp, "\n"))
- {
- error = 1;
- break;
- }
- sec = sec->next;
+ error = 1;
+ break;
}
+ ent = sec->entries;
+ while (ent != NULL)
+ {
+ if (ent->val != NULL)
+ {
+ val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
+ strcpy (val, ent->val);
+ while (NULL != (pos = strstr (val, "\n")))
+ {
+ memmove (&pos[2], &pos[1], strlen (&pos[1]));
+ pos[0] = '\\';
+ pos[1] = 'n';
+ }
+ if (0 > fprintf (fp, "%s = %s\n", ent->key, val))
+ {
+ error = 1;
+ GNUNET_free (val);
+ break;
+ }
+ GNUNET_free (val);
+ }
+ ent = ent->next;
+ }
+ if (error != 0)
+ break;
+ if (0 > fprintf (fp, "\n"))
+ {
+ error = 1;
+ break;
+ }
+ sec = sec->next;
+ }
if (error != 0)
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename);
GNUNET_assert (0 == fclose (fp));
if (error != 0)
- {
- cfg->dirty = GNUNET_SYSERR; /* last write failed */
- return GNUNET_SYSERR;
- }
- cfg->dirty = GNUNET_NO; /* last write succeeded */
+ {
+ cfg->dirty = GNUNET_SYSERR; /* last write failed */
+ return GNUNET_SYSERR;
+ }
+ cfg->dirty = GNUNET_NO; /* last write succeeded */
return GNUNET_OK;
}
*/
void
GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_CONFIGURATION_Iterator iter,
- void *iter_cls)
+ GNUNET_CONFIGURATION_Iterator iter,
+ void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigEntry *epos;
spos = cfg->sections;
while (spos != NULL)
+ {
+ epos = spos->entries;
+ while (epos != NULL)
{
- epos = spos->entries;
- while (epos != NULL)
- {
- iter (iter_cls, spos->name, epos->key, epos->val);
- epos = epos->next;
- }
- spos = spos->next;
+ iter (iter_cls, spos->name, epos->key, epos->val);
+ epos = epos->next;
}
+ spos = spos->next;
+ }
}
*/
void
GNUNET_CONFIGURATION_iterate_section_values (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- GNUNET_CONFIGURATION_Iterator
- iter, void *iter_cls)
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ GNUNET_CONFIGURATION_Iterator iter,
+ void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigEntry *epos;
epos = spos->entries;
while (epos != NULL)
- {
- iter (iter_cls, spos->name, epos->key, epos->val);
- epos = epos->next;
- }
+ {
+ iter (iter_cls, spos->name, epos->key, epos->val);
+ epos = epos->next;
+ }
}
* @param iter_cls closure for iter
*/
void
-GNUNET_CONFIGURATION_iterate_sections (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_CONFIGURATION_Section_Iterator
- iter, void *iter_cls)
+GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
+ *cfg,
+ GNUNET_CONFIGURATION_Section_Iterator
+ iter, void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigSection *next;
next = cfg->sections;
while (next != NULL)
- {
- spos = next;
- next = spos->next;
- iter (iter_cls, spos->name);
- }
+ {
+ spos = next;
+ next = spos->next;
+ iter (iter_cls, spos->name);
+ }
}
/**
*/
void
GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section)
+ const char *section)
{
struct ConfigSection *spos;
struct ConfigSection *prev;
prev = NULL;
spos = cfg->sections;
while (spos != NULL)
+ {
+ if (0 == strcmp (section, spos->name))
{
- if (0 == strcmp (section, spos->name))
- {
- if (prev == NULL)
- cfg->sections = spos->next;
- else
- prev->next = spos->next;
- while (NULL != (ent = spos->entries))
- {
- spos->entries = ent->next;
- GNUNET_free (ent->key);
- GNUNET_free_non_null (ent->val);
- GNUNET_free (ent);
- cfg->dirty = GNUNET_YES;
- }
- GNUNET_free (spos->name);
- GNUNET_free (spos);
- return;
- }
- prev = spos;
- spos = spos->next;
+ if (prev == NULL)
+ cfg->sections = spos->next;
+ else
+ prev->next = spos->next;
+ while (NULL != (ent = spos->entries))
+ {
+ spos->entries = ent->next;
+ GNUNET_free (ent->key);
+ GNUNET_free_non_null (ent->val);
+ GNUNET_free (ent);
+ cfg->dirty = GNUNET_YES;
+ }
+ GNUNET_free (spos->name);
+ GNUNET_free (spos);
+ return;
}
+ prev = spos;
+ spos = spos->next;
+ }
}
*/
static void
copy_entry (void *cls, const char *section, const char *option,
- const char *value)
+ const char *value)
{
struct GNUNET_CONFIGURATION_Handle *dst = cls;
* @return matching entry, NULL if not found
*/
static struct ConfigSection *
-findSection (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section)
+findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
{
struct ConfigSection *pos;
*/
static struct ConfigEntry *
findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
- const char *key)
+ const char *key)
{
struct ConfigSection *sec;
struct ConfigEntry *pos;
*/
static void
compareEntries (void *cls, const char *section, const char *option,
- const char *value)
+ const char *value)
{
struct DiffHandle *dh = cls;
struct ConfigEntry *entNew;
*/
int
GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
- *cfgDefault,
- const struct GNUNET_CONFIGURATION_Handle
- *cfgNew, const char *filename)
+ *cfgDefault,
+ const struct GNUNET_CONFIGURATION_Handle
+ *cfgNew, const char *filename)
{
int ret;
struct DiffHandle diffHandle;
* @param value value to set
*/
void
-GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option, const char *value)
+GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section, const char *option,
+ const char *value)
{
struct ConfigSection *sec;
struct ConfigEntry *e;
e = findEntry (cfg, section, option);
if (e != NULL)
- {
- GNUNET_free_non_null (e->val);
- e->val = GNUNET_strdup (value);
- return;
- }
+ {
+ GNUNET_free_non_null (e->val);
+ e->val = GNUNET_strdup (value);
+ return;
+ }
sec = findSection (cfg, section);
if (sec == NULL)
- {
- sec = GNUNET_malloc (sizeof (struct ConfigSection));
- sec->name = GNUNET_strdup (section);
- sec->next = cfg->sections;
- cfg->sections = sec;
- }
+ {
+ sec = GNUNET_malloc (sizeof (struct ConfigSection));
+ sec->name = GNUNET_strdup (section);
+ sec->next = cfg->sections;
+ cfg->sections = sec;
+ }
e = GNUNET_malloc (sizeof (struct ConfigEntry));
e->key = GNUNET_strdup (option);
e->val = GNUNET_strdup (value);
* @param number value to set
*/
void
-GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- unsigned long long number)
+GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section, const char *option,
+ unsigned long long number)
{
char s[64];
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_number (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- unsigned long long *number)
+GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *section,
+ const char *option,
+ unsigned long long *number)
{
struct ConfigEntry *e;
*/
int
GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- struct GNUNET_TIME_Relative *time)
+ *cfg, const char *section,
+ const char *option,
+ struct GNUNET_TIME_Relative *time)
{
struct ConfigEntry *e;
if (e == NULL)
return GNUNET_SYSERR;
- return GNUNET_STRINGS_fancy_time_to_relative (e->val,
- time);
+ return GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
}
e = findEntry (cfg, section, option);
if (e == NULL)
return GNUNET_SYSERR;
- return GNUNET_STRINGS_fancy_size_to_bytes (e->val,
- size);
+ return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
}
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_string (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option, char **value)
+GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *section,
+ const char *option, char **value)
{
struct ConfigEntry *e;
e = findEntry (cfg, section, option);
if ((e == NULL) || (e->val == NULL))
- {
- *value = NULL;
- return GNUNET_SYSERR;
- }
+ {
+ *value = NULL;
+ return GNUNET_SYSERR;
+ }
*value = GNUNET_strdup (e->val);
return GNUNET_OK;
}
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_choice (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- const char **choices,
- const char **value)
+GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *section,
+ const char *option, const char **choices,
+ const char **value)
{
struct ConfigEntry *e;
int i;
return GNUNET_SYSERR;
i = 0;
while (choices[i] != NULL)
- {
- if (0 == strcasecmp (choices[i], e->val))
- break;
- i++;
- }
+ {
+ if (0 == strcasecmp (choices[i], e->val))
+ break;
+ i++;
+ }
if (choices[i] == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration value '%s' for '%s'"
- " in section '%s' is not in set of legal choices\n"), e->val,
- option, section);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Configuration value '%s' for '%s'"
+ " in section '%s' is not in set of legal choices\n"), e->val, option,
+ section);
+ return GNUNET_SYSERR;
+ }
*value = choices[i];
return GNUNET_OK;
}
* @return GNUNET_YES if so, GNUNET_NO if not.
*/
int
-GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option)
+GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section, const char *option)
{
struct ConfigEntry *e;
*/
char *
GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
- *cfg, char *orig)
+ *cfg, char *orig)
{
int i;
char *prefix;
while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0'))
i++;
if (orig[i] == '\0')
- {
- post = "";
- }
+ {
+ post = "";
+ }
else
- {
- orig[i] = '\0';
- post = &orig[i + 1];
- }
+ {
+ orig[i] = '\0';
+ post = &orig[i + 1];
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1],
- &prefix))
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], &prefix))
+ {
+ if (NULL == (env = getenv (&orig[1])))
{
- if (NULL == (env = getenv (&orig[1])))
- {
- orig[i] = DIR_SEPARATOR;
- return orig;
- }
- prefix = GNUNET_strdup (env);
+ orig[i] = DIR_SEPARATOR;
+ return orig;
}
+ prefix = GNUNET_strdup (env);
+ }
result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2);
strcpy (result, prefix);
if ((strlen (prefix) == 0) ||
*/
int
GNUNET_CONFIGURATION_get_value_filename (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option, char **value)
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option, char **value)
{
char *tmp;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
- {
- *value = NULL;
- return GNUNET_SYSERR;
- }
+ {
+ *value = NULL;
+ return GNUNET_SYSERR;
+ }
tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
*value = GNUNET_STRINGS_filename_expand (tmp);
GNUNET_free (tmp);
*/
int
GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option)
+ *cfg, const char *section,
+ const char *option)
{
static const char *yesno[] = { "YES", "NO", NULL };
const char *val;
int ret;
ret =
- GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
+ GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
if (ret == GNUNET_SYSERR)
return ret;
if (val == yesno[0])
*/
int
GNUNET_CONFIGURATION_iterate_value_filenames (const struct
- GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- GNUNET_FileNameCallback cb,
- void *cb_cls)
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ GNUNET_FileNameCallback cb,
+ void *cb_cls)
{
char *list;
char *pos;
ret = 0;
pos = list;
while (1)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ if (strlen (pos) == 0)
+ break;
+ end = pos + 1;
+ while ((end[0] != ' ') && (end[0] != '\0'))
{
- while (pos[0] == ' ')
- pos++;
- if (strlen (pos) == 0)
- break;
- end = pos + 1;
- while ((end[0] != ' ') && (end[0] != '\0'))
- {
- if (end[0] == '\\')
- {
- switch (end[1])
- {
- case '\\':
- case ' ':
- memmove (end, &end[1], strlen (&end[1]) + 1);
- case '\0':
- /* illegal, but just keep it */
- break;
- default:
- /* illegal, but just ignore that there was a '/' */
- break;
- }
- }
- end++;
- }
- old = end[0];
- end[0] = '\0';
- if (strlen (pos) > 0)
- {
- ret++;
- if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
- {
- ret = GNUNET_SYSERR;
- break;
- }
- }
- if (old == '\0')
- break;
- pos = end + 1;
+ if (end[0] == '\\')
+ {
+ switch (end[1])
+ {
+ case '\\':
+ case ' ':
+ memmove (end, &end[1], strlen (&end[1]) + 1);
+ case '\0':
+ /* illegal, but just keep it */
+ break;
+ default:
+ /* illegal, but just ignore that there was a '/' */
+ break;
+ }
+ }
+ end++;
}
+ old = end[0];
+ end[0] = '\0';
+ if (strlen (pos) > 0)
+ {
+ ret++;
+ if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
+ {
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ }
+ if (old == '\0')
+ break;
+ pos = end + 1;
+ }
GNUNET_free (list);
return ret;
}
rpos = value;
wpos = escaped;
while (rpos[0] != '\0')
+ {
+ switch (rpos[0])
{
- switch (rpos[0])
- {
- case '\\':
- case ' ':
- wpos[0] = '\\';
- wpos[1] = rpos[0];
- wpos += 2;
- break;
- default:
- wpos[0] = rpos[0];
- wpos++;
- }
- rpos++;
+ case '\\':
+ case ' ':
+ wpos[0] = '\\';
+ wpos[1] = rpos[0];
+ wpos += 2;
+ break;
+ default:
+ wpos[0] = rpos[0];
+ wpos++;
}
+ rpos++;
+ }
return escaped;
}
*/
int
GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- const char *value)
+ *cfg, const char *section,
+ const char *option,
+ const char *value)
{
char *escaped;
char *old;
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
- &test_match,
- (void *) value))
- return GNUNET_NO; /* already exists */
+ &test_match,
+ (void *) value))
+ return GNUNET_NO; /* already exists */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
old = GNUNET_strdup ("");
*/
int
GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- const char *value)
+ *cfg, const char *section,
+ const char *option,
+ const char *value)
{
char *list;
char *pos;
match = escape_name (value);
pos = list;
while (1)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ if (strlen (pos) == 0)
+ break;
+ end = pos + 1;
+ while ((end[0] != ' ') && (end[0] != '\0'))
+ {
+ if (end[0] == '\\')
+ {
+ switch (end[1])
+ {
+ case '\\':
+ case ' ':
+ end++;
+ break;
+ case '\0':
+ /* illegal, but just keep it */
+ break;
+ default:
+ /* illegal, but just ignore that there was a '/' */
+ break;
+ }
+ }
+ end++;
+ }
+ old = end[0];
+ end[0] = '\0';
+ if (0 == strcmp (pos, match))
{
- while (pos[0] == ' ')
- pos++;
- if (strlen (pos) == 0)
- break;
- end = pos + 1;
- while ((end[0] != ' ') && (end[0] != '\0'))
- {
- if (end[0] == '\\')
- {
- switch (end[1])
- {
- case '\\':
- case ' ':
- end++;
- break;
- case '\0':
- /* illegal, but just keep it */
- break;
- default:
- /* illegal, but just ignore that there was a '/' */
- break;
- }
- }
- end++;
- }
- old = end[0];
- end[0] = '\0';
- if (0 == strcmp (pos, match))
- {
- if (old != '\0')
- memmove (pos, &end[1], strlen (&end[1]) + 1);
- else
- {
- if (pos != list)
- pos[-1] = '\0';
- else
- pos[0] = '\0';
- }
- GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
- GNUNET_free (list);
- GNUNET_free (match);
- return GNUNET_OK;
- }
- if (old == '\0')
- break;
- end[0] = old;
- pos = end + 1;
+ if (old != '\0')
+ memmove (pos, &end[1], strlen (&end[1]) + 1);
+ else
+ {
+ if (pos != list)
+ pos[-1] = '\0';
+ else
+ pos[0] = '\0';
+ }
+ GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
+ GNUNET_free (list);
+ GNUNET_free (match);
+ return GNUNET_OK;
}
+ if (old == '\0')
+ break;
+ end[0] = old;
+ pos = end + 1;
+ }
GNUNET_free (list);
GNUNET_free (match);
return GNUNET_NO;
* @return GNUNET_OK on success
*/
static int
-parse_configuration_file (void *cls,
- const char *filename)
+parse_configuration_file (void *cls, const char *filename)
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
int ret;
*/
int
GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *filename)
+ const char *filename)
{
char *baseconfig;
char *ipath;
if (ipath == NULL)
return GNUNET_SYSERR;
baseconfig = NULL;
- GNUNET_asprintf (&baseconfig, "%s%s", ipath,
- "config.d");
+ GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
GNUNET_free (ipath);
if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_scan (baseconfig,
- &parse_configuration_file,
- cfg))
+ GNUNET_DISK_directory_scan (baseconfig, &parse_configuration_file, cfg))
{
GNUNET_free (baseconfig);
- return GNUNET_SYSERR; /* no configuration at all found */
+ return GNUNET_SYSERR; /* no configuration at all found */
}
- GNUNET_free (baseconfig);
- if ( (filename != NULL) &&
- (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)) )
+ GNUNET_free (baseconfig);
+ if ((filename != NULL) &&
+ (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)))
{
/* specified configuration not found */
return GNUNET_SYSERR;
}
if (((GNUNET_YES !=
- GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
+ GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
(filename != NULL))
GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
- filename);
+ filename);
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
(GNUNET_YES ==
* @return the boxed socket handle
*/
struct GNUNET_CONNECTION_Handle *
-GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle
- *osSocket)
+GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket)
{
struct GNUNET_CONNECTION_Handle *ret;
*/
struct GNUNET_CONNECTION_Handle *
GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
- void *access_cls,
- struct GNUNET_NETWORK_Handle *lsock)
+ void *access_cls,
+ struct GNUNET_NETWORK_Handle *lsock)
{
struct GNUNET_CONNECTION_Handle *ret;
char addr[128];
addrlen = sizeof (addr);
sock =
- GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
+ GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
if (NULL == sock)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept");
- return NULL;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept");
+ return NULL;
+ }
if ((addrlen > sizeof (addr)) || (addrlen < sizeof (sa_family_t)))
- {
- GNUNET_break (0);
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ return NULL;
+ }
sa = (struct sockaddr *) addr;
v6 = (struct sockaddr_in6 *) addr;
if ((sa->sa_family == AF_INET6) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
- {
- /* convert to V4 address */
- v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
- memset (v4, 0, sizeof (struct sockaddr_in));
- v4->sin_family = AF_INET;
+ {
+ /* convert to V4 address */
+ v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
+ memset (v4, 0, sizeof (struct sockaddr_in));
+ v4->sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- v4->sin_len = (u_char) sizeof (struct sockaddr_in);
+ v4->sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
- memcpy (&v4->sin_addr,
- &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
- sizeof (struct in_addr)],
- sizeof (struct in_addr));
- v4->sin_port = v6->sin6_port;
- uaddr = v4;
- addrlen = sizeof (struct sockaddr_in);
- }
+ memcpy (&v4->sin_addr,
+ &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
+ sizeof (struct in_addr)],
+ sizeof (struct in_addr));
+ v4->sin_port = v6->sin6_port;
+ uaddr = v4;
+ addrlen = sizeof (struct sockaddr_in);
+ }
else
- {
- uaddr = GNUNET_malloc (addrlen);
- memcpy (uaddr, addr, addrlen);
- }
+ {
+ uaddr = GNUNET_malloc (addrlen);
+ memcpy (uaddr, addr, addrlen);
+ }
gcp = NULL;
gc.uid = 0;
gc.gid = 0;
if (sa->sa_family == AF_UNIX)
- {
+ {
#if HAVE_GETPEEREID
- /* most BSDs */
- if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
- gcp = &gc;
+ /* most BSDs */
+ if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
+ gcp = &gc;
#else
#ifdef SO_PEERCRED
- /* largely traditional GNU/Linux */
- olen = sizeof (uc);
- if ((0 ==
- getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED,
- &uc, &olen)) && (olen == sizeof (uc)))
- {
- gc.uid = uc.uid;
- gc.gid = uc.gid;
- gcp = &gc;
- }
+ /* largely traditional GNU/Linux */
+ olen = sizeof (uc);
+ if ((0 ==
+ getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc,
+ &olen)) && (olen == sizeof (uc)))
+ {
+ gc.uid = uc.uid;
+ gc.gid = uc.gid;
+ gcp = &gc;
+ }
#else
#if HAVE_GETPEERUCRED
- /* this is for Solaris 10 */
- ucred_t *uc;
-
- uc = NULL;
- if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc))
- {
- gc.uid = ucred_geteuid (uc);
- gc.gid = ucred_getegid (uc);
- gcp = &gc;
- }
- ucred_free (uc);
+ /* this is for Solaris 10 */
+ ucred_t *uc;
+
+ uc = NULL;
+ if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc))
+ {
+ gc.uid = ucred_geteuid (uc);
+ gc.gid = ucred_getegid (uc);
+ gcp = &gc;
+ }
+ ucred_free (uc);
#endif
#endif
#endif
- }
+ }
if ((access != NULL) &&
(GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen))))
- {
- if (aret == GNUNET_NO)
- LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"),
- GNUNET_a2s (uaddr, addrlen));
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- GNUNET_free (uaddr);
- return NULL;
- }
+ {
+ if (aret == GNUNET_NO)
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"),
+ GNUNET_a2s (uaddr, addrlen));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ GNUNET_free (uaddr);
+ return NULL;
+ }
ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
ret->write_buffer = GNUNET_malloc (ret->write_buffer_size);
*/
int
GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock,
- void **addr, size_t * addrlen)
+ void **addr, size_t * addrlen)
{
if ((sock->addr == NULL) || (sock->addrlen == 0))
return GNUNET_NO;
* @param tc unused
*/
static void
-destroy_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CONNECTION_Handle *sock = cls;
GNUNET_CONNECTION_TransmitReadyNotify notify;
sock->destroy_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (sock->dns_active == NULL);
if (0 != (sock->ccs & COCO_TRANSMIT_READY))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Destroy waits for CCS-TR to be done (%p)\n", sock);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy waits for CCS-TR to be done (%p)\n",
+ sock);
#endif
- sock->ccs |= COCO_DESTROY_CONTINUATION;
- return;
- }
+ sock->ccs |= COCO_DESTROY_CONTINUATION;
+ return;
+ }
if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Destroy waits for write_task to be done (%p)\n", sock);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroy waits for write_task to be done (%p)\n", sock);
#endif
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
- sock->destroy_task =
- GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation,
- sock);
- return;
- }
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
+ sock->destroy_task =
+ GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation,
+ sock);
+ return;
+ }
if (0 != (sock->ccs & COCO_RECEIVE_AGAIN))
- {
- sock->ccs |= COCO_DESTROY_CONTINUATION;
- return;
- }
+ {
+ sock->ccs |= COCO_DESTROY_CONTINUATION;
+ return;
+ }
if (sock->sock != NULL)
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock);
#endif
- if (sock->persist != GNUNET_YES)
- {
- if ((GNUNET_YES !=
- GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR))
- && (errno != ENOTCONN) && (errno != ECONNRESET))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
- }
- }
- if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
+ if (sock->persist != GNUNET_YES)
{
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
- sock->destroy_task =
- GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation,
- sock);
- return;
+ if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR))
+ && (errno != ENOTCONN) && (errno != ECONNRESET))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
}
+ }
+ if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
+ sock->destroy_task =
+ GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation,
+ sock);
+ return;
+ }
#if DEBUG_CONNECTION
LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock);
#endif
while (NULL != (pos = sock->ap_head))
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
- GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos);
- GNUNET_free (pos);
- }
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
+ GNUNET_SCHEDULER_cancel (pos->task);
+ GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos);
+ GNUNET_free (pos);
+ }
GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
GNUNET_assert (sock->ccs == COCO_NONE);
if (NULL != (notify = sock->nth.notify_ready))
- {
- sock->nth.notify_ready = NULL;
- notify (sock->nth.notify_ready_cls, 0, NULL);
- }
+ {
+ sock->nth.notify_ready = NULL;
+ notify (sock->nth.notify_ready_cls, 0, NULL);
+ }
if (sock->sock != NULL)
- {
- if (sock->persist != GNUNET_YES)
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock));
- else
- GNUNET_free (sock->sock); /* at least no memory leak (we deliberately
- * leak the socket in this special case) ... */
- }
+ {
+ if (sock->persist != GNUNET_YES)
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock));
+ else
+ GNUNET_free (sock->sock); /* at least no memory leak (we deliberately
+ * leak the socket in this special case) ... */
+ }
GNUNET_free_non_null (sock->addr);
GNUNET_free_non_null (sock->hostname);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
{
#if DEBUG_CONNECTION
LOG ((0 !=
- strncmp (h->hostname, "localhost:",
- 10)) ? GNUNET_ERROR_TYPE_INFO :
- GNUNET_ERROR_TYPE_WARNING,
+ strncmp (h->hostname, "localhost:",
+ 10)) ? GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
_
("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"),
h->hostname, h->port);
/* trigger jobs that used to wait on "connect_task" */
if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "connect_fail_continuation triggers receive_again (%p)\n", h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "connect_fail_continuation triggers receive_again (%p)\n", h);
#endif
- h->ccs -= COCO_RECEIVE_AGAIN;
- h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h);
- }
+ h->ccs -= COCO_RECEIVE_AGAIN;
+ h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h);
+ }
if (0 != (h->ccs & COCO_TRANSMIT_READY))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n",
- h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n",
+ h);
#endif
- GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
- GNUNET_SCHEDULER_cancel (h->nth.timeout_task);
- h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
- h->ccs -= COCO_TRANSMIT_READY;
- GNUNET_assert (h->nth.notify_ready != NULL);
- GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK);
- h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h);
- }
+ GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_SCHEDULER_cancel (h->nth.timeout_task);
+ h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ h->ccs -= COCO_TRANSMIT_READY;
+ GNUNET_assert (h->nth.notify_ready != NULL);
+ GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK);
+ h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h);
+ }
if (0 != (h->ccs & COCO_DESTROY_CONTINUATION))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "connect_fail_continuation runs destroy_continuation (%p)\n", h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "connect_fail_continuation runs destroy_continuation (%p)\n", h);
#endif
- h->ccs -= COCO_DESTROY_CONTINUATION;
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task);
- h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h);
- }
+ h->ccs -= COCO_DESTROY_CONTINUATION;
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task);
+ h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h);
+ }
}
#endif
/* trigger jobs that waited for the connection */
if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "connect_success_continuation runs receive_again (%p)\n", h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "connect_success_continuation runs receive_again (%p)\n", h);
#endif
- h->ccs -= COCO_RECEIVE_AGAIN;
- h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h);
- }
+ h->ccs -= COCO_RECEIVE_AGAIN;
+ h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h);
+ }
if (0 != (h->ccs & COCO_TRANSMIT_READY))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n",
- h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n",
+ h);
#endif
- GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
- GNUNET_SCHEDULER_cancel (h->nth.timeout_task);
- h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
- h->ccs -= COCO_TRANSMIT_READY;
- GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK);
- GNUNET_assert (h->nth.notify_ready != NULL);
- h->write_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
- (h->nth.transmit_timeout), h->sock,
- &transmit_ready, h);
- }
+ GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_SCHEDULER_cancel (h->nth.timeout_task);
+ h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ h->ccs -= COCO_TRANSMIT_READY;
+ GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK);
+ GNUNET_assert (h->nth.notify_ready != NULL);
+ h->write_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
+ (h->nth.transmit_timeout), h->sock,
+ &transmit_ready, h);
+ }
if (0 != (h->ccs & COCO_DESTROY_CONTINUATION))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "connect_success_continuation runs destroy_continuation (%p)\n",
- h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "connect_success_continuation runs destroy_continuation (%p)\n", h);
#endif
- h->ccs -= COCO_DESTROY_CONTINUATION;
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task);
- h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h);
- }
+ h->ccs -= COCO_DESTROY_CONTINUATION;
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task);
+ h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h);
+ }
}
*/
static void
connect_probe_continuation (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct AddressProbe *ap = cls;
struct GNUNET_CONNECTION_Handle *h = ap->h;
error = 0;
if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
(GNUNET_OK !=
- GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR,
- &error, &len)) || (error != 0))
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
- GNUNET_free (ap);
- if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO))
- connect_fail_continuation (h);
- return;
- }
+ GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error,
+ &len)) || (error != 0))
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
+ GNUNET_free (ap);
+ if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO))
+ connect_fail_continuation (h);
+ return;
+ }
GNUNET_assert (h->sock == NULL);
h->sock = ap->sock;
GNUNET_assert (h->addr == NULL);
GNUNET_free (ap);
/* cancel all other attempts */
while (NULL != (pos = h->ap_head))
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
- GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos);
- GNUNET_free (pos);
- }
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
+ GNUNET_SCHEDULER_cancel (pos->task);
+ GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos);
+ GNUNET_free (pos);
+ }
connect_success_continuation (h);
}
*/
static void
try_connect_using_address (void *cls, const struct sockaddr *addr,
- socklen_t addrlen)
+ socklen_t addrlen)
{
struct GNUNET_CONNECTION_Handle *h = cls;
struct AddressProbe *ap;
struct GNUNET_TIME_Relative delay;
if (addr == NULL)
- {
- h->dns_active = NULL;
- if ((NULL == h->ap_head) && (NULL == h->sock))
- connect_fail_continuation (h);
- return;
- }
+ {
+ h->dns_active = NULL;
+ if ((NULL == h->ap_head) && (NULL == h->sock))
+ connect_fail_continuation (h);
+ return;
+ }
if (h->sock != NULL)
- return; /* already connected */
+ return; /* already connected */
GNUNET_assert (h->addr == NULL);
/* try to connect */
#if DEBUG_CONNECTION
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname,
- h->port, GNUNET_a2s (addr, addrlen), h->port);
+ "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, h->port,
+ GNUNET_a2s (addr, addrlen), h->port);
#endif
ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen);
ap->addr = (const struct sockaddr *) &ap[1];
ap->h = h;
switch (ap->addr->sa_family)
- {
- case AF_INET:
- ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port);
- break;
- case AF_INET6:
- ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port);
- break;
- default:
- GNUNET_break (0);
- GNUNET_free (ap);
- return; /* not supported by us */
- }
- ap->sock =
- GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
+ {
+ case AF_INET:
+ ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port);
+ break;
+ case AF_INET6:
+ ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port);
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_free (ap);
+ return; /* not supported by us */
+ }
+ ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
if (ap->sock == NULL)
- {
- GNUNET_free (ap);
- return; /* not supported by OS */
- }
+ {
+ GNUNET_free (ap);
+ return; /* not supported by OS */
+ }
#if DEBUG_CONNECTION
LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"),
GNUNET_a2s (ap->addr, ap->addrlen), h);
if ((GNUNET_OK !=
GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
(errno != EINPROGRESS))
- {
- /* maybe refused / unsupported address, try next */
- LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
+ {
+ /* maybe refused / unsupported address, try next */
+ LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
#if 0
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Failed to connect to `%s' (%p)\n"),
- GNUNET_a2s (ap->addr, ap->addrlen), h);
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to `%s' (%p)\n"),
+ GNUNET_a2s (ap->addr, ap->addrlen), h);
#endif
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
- GNUNET_free (ap);
- return;
- }
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
+ GNUNET_free (ap);
+ return;
+ }
GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap);
delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT;
if (h->nth.notify_ready != NULL)
delay =
- GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining (h->
- nth.transmit_timeout));
+ GNUNET_TIME_relative_min (delay,
+ GNUNET_TIME_absolute_get_remaining (h->
+ nth.transmit_timeout));
if (h->receiver != NULL)
delay =
- GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining
- (h->receive_timeout));
+ GNUNET_TIME_relative_min (delay,
+ GNUNET_TIME_absolute_get_remaining
+ (h->receive_timeout));
ap->task =
- GNUNET_SCHEDULER_add_write_net (delay, ap->sock,
- &connect_probe_continuation, ap);
+ GNUNET_SCHEDULER_add_write_net (delay, ap->sock,
+ &connect_probe_continuation, ap);
}
* @return the socket handle
*/
struct GNUNET_CONNECTION_Handle *
-GNUNET_CONNECTION_create_from_connect (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *hostname, uint16_t port)
+GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
+ *cfg, const char *hostname,
+ uint16_t port)
{
struct GNUNET_CONNECTION_Handle *ret;
- GNUNET_assert (0 < strlen (hostname)); /* sanity check */
+ GNUNET_assert (0 < strlen (hostname)); /* sanity check */
ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
ret->cfg = cfg;
ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
ret->port = port;
ret->hostname = GNUNET_strdup (hostname);
ret->dns_active =
- GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC,
- GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
- &try_connect_using_address, ret);
+ GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC,
+ GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
+ &try_connect_using_address, ret);
return ret;
}
*/
struct GNUNET_CONNECTION_Handle *
GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
- GNUNET_CONFIGURATION_Handle
- *cfg, const char *unixpath)
+ GNUNET_CONFIGURATION_Handle
+ *cfg, const char *unixpath)
{
#ifdef AF_UNIX
struct GNUNET_CONNECTION_Handle *ret;
struct sockaddr_un *un;
size_t slen;
- GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
+ GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
un = GNUNET_malloc (sizeof (struct sockaddr_un));
un->sun_family = AF_UNIX;
slen = strlen (unixpath);
ret->addrlen = slen;
ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == ret->sock)
- {
- GNUNET_free (ret->addr);
- GNUNET_free (ret->write_buffer);
- GNUNET_free (ret);
- return NULL;
- }
+ {
+ GNUNET_free (ret->addr);
+ GNUNET_free (ret->write_buffer);
+ GNUNET_free (ret);
+ return NULL;
+ }
if (GNUNET_OK !=
GNUNET_NETWORK_socket_connect (ret->sock, ret->addr, ret->addrlen))
- {
- /* Just return; we expect everything to work eventually so don't fail HARD */
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock));
- ret->sock = NULL;
- return ret;
- }
+ {
+ /* Just return; we expect everything to work eventually so don't fail HARD */
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock));
+ ret->sock = NULL;
+ return ret;
+ }
connect_success_continuation (ret);
return ret;
#else
*/
struct GNUNET_CONNECTION_Handle *
GNUNET_CONNECTION_create_from_sockaddr (int af_family,
- const struct sockaddr *serv_addr,
- socklen_t addrlen)
+ const struct sockaddr *serv_addr,
+ socklen_t addrlen)
{
struct GNUNET_NETWORK_Handle *s;
struct GNUNET_CONNECTION_Handle *ret;
s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
if (s == NULL)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- "socket");
- return NULL;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
+ return NULL;
+ }
if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
(errno != EINPROGRESS))
- {
- /* maybe refused / unsupported address, try next */
- LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Attempt to connect to `%s' failed\n"), GNUNET_a2s (serv_addr,
- addrlen));
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
- return NULL;
- }
+ {
+ /* maybe refused / unsupported address, try next */
+ LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Attempt to connect to `%s' failed\n"),
+ GNUNET_a2s (serv_addr, addrlen));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
+ return NULL;
+ }
ret = GNUNET_CONNECTION_create_from_existing (s);
ret->addr = GNUNET_malloc (addrlen);
memcpy (ret->addr, serv_addr, addrlen);
GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock)
{
if ((sock->ap_head != NULL) || (sock->dns_active != NULL))
- return GNUNET_YES; /* still trying to connect */
+ return GNUNET_YES; /* still trying to connect */
return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES;
}
*/
void
GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
- int finish_pending_write)
+ int finish_pending_write)
{
if (GNUNET_NO == finish_pending_write)
+ {
+ if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
{
- if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sock->write_task);
- sock->write_task = GNUNET_SCHEDULER_NO_TASK;
- sock->write_buffer_off = 0;
- }
- sock->nth.notify_ready = NULL;
+ GNUNET_SCHEDULER_cancel (sock->write_task);
+ sock->write_task = GNUNET_SCHEDULER_NO_TASK;
+ sock->write_buffer_off = 0;
}
+ sock->nth.notify_ready = NULL;
+ }
if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL))
- {
- GNUNET_RESOLVER_request_cancel (sock->dns_active);
- sock->dns_active = NULL;
- }
+ {
+ GNUNET_RESOLVER_request_cancel (sock->dns_active);
+ sock->dns_active = NULL;
+ }
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock);
GNUNET_CONNECTION_Receiver receiver;
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Network signals time out to receiver (%p)!\n", sh);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Network signals time out to receiver (%p)!\n",
+ sh);
#endif
GNUNET_assert (NULL != (receiver = sh->receiver));
sh->receiver = NULL;
sh->read_task = GNUNET_SCHEDULER_NO_TASK;
if ((GNUNET_YES == sh->ignore_shutdown) &&
(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
- {
- /* ignore shutdown request, go again immediately */
+ {
+ /* ignore shutdown request, go again immediately */
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring shutdown signal per configuration\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Ignoring shutdown signal per configuration\n");
#endif
- sh->read_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (sh->receive_timeout), sh->sock,
- &receive_ready, sh);
- return;
- }
+ sh->read_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
+ (sh->receive_timeout), sh->sock,
+ &receive_ready, sh);
+ return;
+ }
now = GNUNET_TIME_absolute_get ();
if ((now.abs_value > sh->receive_timeout.abs_value) ||
(0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) ||
(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
- {
+ {
#if DEBUG_CONNECTION
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Receive from `%s' encounters error: time out by %llums... (%p)\n",
- GNUNET_a2s (sh->addr, sh->addrlen),
- GNUNET_TIME_absolute_get_duration (sh->receive_timeout).
- rel_value, sh);
+ if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Receive from `%s' encounters error: time out by %llums... (%p)\n",
+ GNUNET_a2s (sh->addr, sh->addrlen),
+ GNUNET_TIME_absolute_get_duration (sh->receive_timeout).rel_value,
+ sh);
#endif
- signal_timeout (sh);
- return;
- }
+ signal_timeout (sh);
+ return;
+ }
if (sh->sock == NULL)
- {
- /* connect failed for good */
+ {
+ /* connect failed for good */
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error, socket closed... (%p)\n", sh);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Receive encounters error, socket closed... (%p)\n", sh);
#endif
- signal_error (sh, ECONNREFUSED);
- return;
- }
+ signal_error (sh, ECONNREFUSED);
+ return;
+ }
GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock));
RETRY:
ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max);
if (ret == -1)
- {
- if (errno == EINTR)
- goto RETRY;
+ {
+ if (errno == EINTR)
+ goto RETRY;
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n",
- STRERROR (errno));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", STRERROR (errno));
#endif
- signal_error (sh, errno);
- return;
- }
+ signal_error (sh, errno);
+ return;
+ }
#if DEBUG_CONNECTION
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "receive_ready read %u/%u bytes from `%s' (%p)!\n",
- (unsigned int) ret, sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh);
+ "receive_ready read %u/%u bytes from `%s' (%p)!\n", (unsigned int) ret,
+ sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh);
#endif
GNUNET_assert (NULL != (receiver = sh->receiver));
sh->receiver = NULL;
sh->read_task = GNUNET_SCHEDULER_NO_TASK;
if (sh->sock == NULL)
- {
- /* not connected and no longer trying */
+ {
+ /* not connected and no longer trying */
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error, socket closed (%p)...\n", sh);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Receive encounters error, socket closed (%p)...\n", sh);
#endif
- signal_error (sh, ECONNREFUSED);
- return;
- }
+ signal_error (sh, ECONNREFUSED);
+ return;
+ }
now = GNUNET_TIME_absolute_get ();
if ((now.abs_value > sh->receive_timeout.abs_value) ||
(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error: time out (%p)...\n", sh);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Receive encounters error: time out (%p)...\n", sh);
#endif
- signal_timeout (sh);
- return;
- }
+ signal_timeout (sh);
+ return;
+ }
GNUNET_assert (sh->sock != NULL);
/* connect succeeded, wait for data! */
sh->read_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (sh->receive_timeout), sh->sock,
- &receive_ready, sh);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
+ (sh->receive_timeout), sh->sock,
+ &receive_ready, sh);
}
*/
void
GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_Receiver receiver,
- void *receiver_cls)
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CONNECTION_Receiver receiver,
+ void *receiver_cls)
{
struct GNUNET_SCHEDULER_TaskContext tc;
GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) &&
- (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) &&
- (sock->receiver == NULL));
+ (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) &&
+ (sock->receiver == NULL));
sock->receiver = receiver;
sock->receiver_cls = receiver_cls;
sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
sock->max = max;
if (sock->sock != NULL)
- {
- memset (&tc, 0, sizeof (tc));
- tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE;
- receive_again (sock, &tc);
- return;
- }
+ {
+ memset (&tc, 0, sizeof (tc));
+ tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE;
+ receive_again (sock, &tc);
+ return;
+ }
if ((sock->dns_active == NULL) && (sock->ap_head == NULL))
- {
- receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
- return;
- }
+ {
+ receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
+ return;
+ }
sock->ccs += COCO_RECEIVE_AGAIN;
}
*/
void
GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
- int do_ignore)
+ int do_ignore)
{
sock->ignore_shutdown = do_ignore;
}
GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock)
{
if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task));
- sock->read_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task));
+ sock->read_task = GNUNET_SCHEDULER_NO_TASK;
+ }
else
- {
- GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN));
- sock->ccs -= COCO_RECEIVE_AGAIN;
- }
+ {
+ GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN));
+ sock->ccs -= COCO_RECEIVE_AGAIN;
+ }
sock->receiver = NULL;
return sock->receiver_cls;
}
return GNUNET_NO;
sock->nth.notify_ready = NULL;
if (sock->write_buffer_size - sock->write_buffer_off < size)
- {
- /* need to compact */
- memmove (sock->write_buffer,
- &sock->write_buffer[sock->write_buffer_pos], used);
- sock->write_buffer_off -= sock->write_buffer_pos;
- sock->write_buffer_pos = 0;
- }
+ {
+ /* need to compact */
+ memmove (sock->write_buffer, &sock->write_buffer[sock->write_buffer_pos],
+ used);
+ sock->write_buffer_off -= sock->write_buffer_pos;
+ sock->write_buffer_pos = 0;
+ }
avail = sock->write_buffer_size - sock->write_buffer_off;
GNUNET_assert (avail >= size);
size =
- notify (sock->nth.notify_ready_cls, avail,
- &sock->write_buffer[sock->write_buffer_off]);
+ notify (sock->nth.notify_ready_cls, avail,
+ &sock->write_buffer[sock->write_buffer_off]);
GNUNET_assert (size <= avail);
sock->write_buffer_off += size;
return GNUNET_YES;
sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
#if DEBUG_CONNECTION
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
- sock->hostname, sock->port, GNUNET_a2s (sock->addr,
- sock->addrlen), sock);
+ "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", sock->hostname,
+ sock->port, GNUNET_a2s (sock->addr, sock->addrlen), sock);
#endif
GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY));
- sock->ccs -= COCO_TRANSMIT_READY; /* remove request */
+ sock->ccs -= COCO_TRANSMIT_READY; /* remove request */
notify = sock->nth.notify_ready;
sock->nth.notify_ready = NULL;
notify (sock->nth.notify_ready_cls, 0, NULL);
GNUNET_CONNECTION_TransmitReadyNotify notify;
if (NULL != sock->sock)
- {
- GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR);
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock));
- sock->sock = NULL;
- }
+ {
+ GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock));
+ sock->sock = NULL;
+ }
if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (sock->read_task);
- sock->read_task = GNUNET_SCHEDULER_NO_TASK;
- signal_timeout (sock);
- return;
- }
+ {
+ GNUNET_SCHEDULER_cancel (sock->read_task);
+ sock->read_task = GNUNET_SCHEDULER_NO_TASK;
+ signal_timeout (sock);
+ return;
+ }
if (sock->nth.notify_ready == NULL)
- return; /* nobody to tell about it */
+ return; /* nobody to tell about it */
notify = sock->nth.notify_ready;
sock->nth.notify_ready = NULL;
notify (sock->nth.notify_ready_cls, 0, NULL);
sock->write_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- if ( (sock->ignore_shutdown == GNUNET_YES) &&
- (NULL != sock->sock) )
- goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
+ {
+ if ((sock->ignore_shutdown == GNUNET_YES) && (NULL != sock->sock))
+ goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmit to `%s' fails, shutdown happened (%p).\n",
- GNUNET_a2s (sock->addr, sock->addrlen), sock);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmit to `%s' fails, shutdown happened (%p).\n",
+ GNUNET_a2s (sock->addr, sock->addrlen), sock);
#endif
- notify = sock->nth.notify_ready;
- if (NULL != notify)
- {
- sock->nth.notify_ready = NULL;
- notify (sock->nth.notify_ready_cls, 0, NULL);
- }
- return;
- }
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
+ notify = sock->nth.notify_ready;
+ if (NULL != notify)
{
-#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmit to `%s' fails, time out reached (%p).\n",
- GNUNET_a2s (sock->addr, sock->addrlen), sock);
-#endif
- notify = sock->nth.notify_ready;
- GNUNET_assert (NULL != notify);
sock->nth.notify_ready = NULL;
notify (sock->nth.notify_ready_cls, 0, NULL);
- return;
}
+ return;
+ }
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
+ {
+#if DEBUG_CONNECTION
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmit to `%s' fails, time out reached (%p).\n",
+ GNUNET_a2s (sock->addr, sock->addrlen), sock);
+#endif
+ notify = sock->nth.notify_ready;
+ GNUNET_assert (NULL != notify);
+ sock->nth.notify_ready = NULL;
+ notify (sock->nth.notify_ready_cls, 0, NULL);
+ return;
+ }
GNUNET_assert (NULL != sock->sock);
if (tc->write_ready == NULL)
- {
- /* special circumstances (in particular,
- * PREREQ_DONE after connect): not yet ready to write,
- * but no "fatal" error either. Hence retry. */
- goto SCHEDULE_WRITE;
- }
+ {
+ /* special circumstances (in particular,
+ * PREREQ_DONE after connect): not yet ready to write,
+ * but no "fatal" error either. Hence retry. */
+ goto SCHEDULE_WRITE;
+ }
if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_INFO,
- _
- ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"),
- sock);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"),
+ sock);
#endif
- transmit_error (sock);
- return; /* connect failed for good, we're finished */
- }
+ transmit_error (sock);
+ return; /* connect failed for good, we're finished */
+ }
GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos);
if ((sock->nth.notify_ready != NULL) &&
(sock->write_buffer_size < sock->nth.notify_size))
- {
- sock->write_buffer =
- GNUNET_realloc (sock->write_buffer, sock->nth.notify_size);
- sock->write_buffer_size = sock->nth.notify_size;
- }
+ {
+ sock->write_buffer =
+ GNUNET_realloc (sock->write_buffer, sock->nth.notify_size);
+ sock->write_buffer_size = sock->nth.notify_size;
+ }
process_notify (sock);
have = sock->write_buffer_off - sock->write_buffer_pos;
if (have == 0)
- {
- /* no data ready for writing, terminate write loop */
- return;
- }
+ {
+ /* no data ready for writing, terminate write loop */
+ return;
+ }
GNUNET_assert (have <= sock->write_buffer_size);
GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size);
GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size);
RETRY:
ret =
- GNUNET_NETWORK_socket_send (sock->sock,
- &sock->write_buffer[sock->write_buffer_pos],
- have);
+ GNUNET_NETWORK_socket_send (sock->sock,
+ &sock->write_buffer[sock->write_buffer_pos],
+ have);
if (ret == -1)
- {
- if (errno == EINTR)
- goto RETRY;
+ {
+ if (errno == EINTR)
+ goto RETRY;
#if 0
- int en = errno;
+ int en = errno;
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"),
- GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en));
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"),
+ GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en));
#endif
#if DEBUG_CONNECTION
- LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send");
#endif
- transmit_error (sock);
- return;
- }
+ transmit_error (sock);
+ return;
+ }
#if DEBUG_CONNECTION
LOG (GNUNET_ERROR_TYPE_DEBUG,
"transmit_ready transmitted %u/%u bytes to `%s' (%p)\n",
- (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen),
- sock);
+ (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), sock);
#endif
sock->write_buffer_pos += ret;
if (sock->write_buffer_pos == sock->write_buffer_off)
- {
- /* transmitted all pending data */
- sock->write_buffer_pos = 0;
- sock->write_buffer_off = 0;
- }
+ {
+ /* transmitted all pending data */
+ sock->write_buffer_pos = 0;
+ sock->write_buffer_off = 0;
+ }
if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready))
- return; /* all data sent! */
+ return; /* all data sent! */
/* not done writing, schedule more */
SCHEDULE_WRITE:
#if DEBUG_CONNECTION
GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0));
if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
sock->write_task =
- GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready ==
- NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
- GNUNET_TIME_absolute_get_remaining
- (sock->nth.transmit_timeout),
- sock->sock, &transmit_ready, sock);
+ GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready ==
+ NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
+ GNUNET_TIME_absolute_get_remaining
+ (sock->nth.transmit_timeout),
+ sock->sock, &transmit_ready, sock);
}
* NULL if we are already going to notify someone else (busy)
*/
struct GNUNET_CONNECTION_TransmitHandle *
-GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
- *sock, size_t size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify
- notify, void *notify_cls)
+GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock,
+ size_t size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CONNECTION_TransmitReadyNotify
+ notify, void *notify_cls)
{
if (sock->nth.notify_ready != NULL)
- {
- GNUNET_assert (0);
- return NULL;
- }
+ {
+ GNUNET_assert (0);
+ return NULL;
+ }
GNUNET_assert (notify != NULL);
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task);
if ((sock->sock == NULL) && (sock->ap_head == NULL) &&
(sock->dns_active == NULL))
- {
- if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (sock->write_task);
- sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock);
- return &sock->nth;
- }
+ {
+ if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (sock->write_task);
+ sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock);
+ return &sock->nth;
+ }
if (GNUNET_SCHEDULER_NO_TASK != sock->write_task)
return &sock->nth;
if (sock->sock != NULL)
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n",
- sock);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", sock);
#endif
- sock->write_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
- (sock->nth.transmit_timeout),
- sock->sock, &transmit_ready, sock);
- }
+ sock->write_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
+ (sock->nth.transmit_timeout),
+ sock->sock, &transmit_ready, sock);
+ }
else
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "CCS-Scheduling transmit_ready, adding timeout task (%p).\n",
- sock);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", sock);
#endif
- sock->ccs |= COCO_TRANSMIT_READY;
- sock->nth.timeout_task =
- GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock);
- }
+ sock->ccs |= COCO_TRANSMIT_READY;
+ sock->nth.timeout_task =
+ GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock);
+ }
return &sock->nth;
}
*/
void
GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
- GNUNET_CONNECTION_TransmitHandle
- *th)
+ GNUNET_CONNECTION_TransmitHandle
+ *th)
{
GNUNET_assert (th->notify_ready != NULL);
if (0 != (th->sh->ccs & COCO_TRANSMIT_READY))
- {
+ {
#if DEBUG_CONNECTION
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th);
#endif
- GNUNET_SCHEDULER_cancel (th->timeout_task);
- th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- th->sh->ccs -= COCO_TRANSMIT_READY;
- }
+ GNUNET_SCHEDULER_cancel (th->timeout_task);
+ th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ th->sh->ccs -= COCO_TRANSMIT_READY;
+ }
else
+ {
+ if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK)
{
- if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (th->sh->write_task);
- th->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ GNUNET_SCHEDULER_cancel (th->sh->write_task);
+ th->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
}
+ }
th->notify_ready = NULL;
}
* @return number of bytes used for the data of the bloom filter
*/
size_t
-GNUNET_CONTAINER_bloomfilter_get_size (const struct
- GNUNET_CONTAINER_BloomFilter *bf)
+GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
+ *bf)
{
if (bf == NULL)
return 0;
*/
struct GNUNET_CONTAINER_BloomFilter *
GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
- *bf)
+ *bf)
{
return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize,
- bf->addressesPerElement);
+ bf->addressesPerElement);
}
*/
static void
incrementBit (char *bitArray, unsigned int bitIdx,
- const struct GNUNET_DISK_FileHandle *fh)
+ const struct GNUNET_DISK_FileHandle *fh)
{
off_t fileSlot;
unsigned char value;
targetLoc = bitIdx % 2;
GNUNET_assert (fileSlot ==
- GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
+ GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
if (1 != GNUNET_DISK_file_read (fh, &value, 1))
value = 0;
low = value & 0xF;
high = (value & (~0xF)) >> 4;
if (targetLoc == 0)
- {
- if (low < 0xF)
- low++;
- }
+ {
+ if (low < 0xF)
+ low++;
+ }
else
- {
- if (high < 0xF)
- high++;
- }
+ {
+ if (high < 0xF)
+ high++;
+ }
value = ((high << 4) | low);
GNUNET_assert (fileSlot ==
- GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
+ GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
}
*/
static void
decrementBit (char *bitArray, unsigned int bitIdx,
- const struct GNUNET_DISK_FileHandle *fh)
+ const struct GNUNET_DISK_FileHandle *fh)
{
off_t fileSlot;
unsigned char value;
unsigned int targetLoc;
if (GNUNET_DISK_handle_invalid (fh))
- return; /* cannot decrement! */
+ return; /* cannot decrement! */
/* Each char slot in the counter file holds two 4 bit counters */
fileSlot = bitIdx / 2;
targetLoc = bitIdx % 2;
/* decrement, but once we have reached the max, never go back! */
if (targetLoc == 0)
+ {
+ if ((low > 0) && (low < 0xF))
+ low--;
+ if (low == 0)
{
- if ((low > 0) && (low < 0xF))
- low--;
- if (low == 0)
- {
- clearBit (bitArray, bitIdx);
- }
+ clearBit (bitArray, bitIdx);
}
+ }
else
+ {
+ if ((high > 0) && (high < 0xF))
+ high--;
+ if (high == 0)
{
- if ((high > 0) && (high < 0xF))
- high--;
- if (high == 0)
- {
- clearBit (bitArray, bitIdx);
- }
+ clearBit (bitArray, bitIdx);
}
+ }
value = ((high << 4) | low);
GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET);
GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET);
while (bytesleft > 0)
+ {
+ if (bytesleft > BUFFSIZE)
{
- if (bytesleft > BUFFSIZE)
- {
- res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE);
- bytesleft -= BUFFSIZE;
- }
- else
- {
- res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
- bytesleft = 0;
- }
- GNUNET_assert (res != GNUNET_SYSERR);
+ res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE);
+ bytesleft -= BUFFSIZE;
}
+ else
+ {
+ res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
+ bytesleft = 0;
+ }
+ GNUNET_assert (res != GNUNET_SYSERR);
+ }
GNUNET_free (buffer);
return GNUNET_OK;
}
* @return GNUNET_YES to continue, GNUNET_NO to stop early
*/
typedef int (*BitIterator) (void *cls,
- const struct GNUNET_CONTAINER_BloomFilter * bf,
- unsigned int bit);
+ const struct GNUNET_CONTAINER_BloomFilter * bf,
+ unsigned int bit);
/**
*/
static void
iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
- BitIterator callback, void *arg, const GNUNET_HashCode * key)
+ BitIterator callback, void *arg, const GNUNET_HashCode * key)
{
GNUNET_HashCode tmp[2];
int bitCount;
tmp[0] = *key;
round = 0;
while (bitCount > 0)
+ {
+ while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
{
- while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
- {
- if (GNUNET_YES !=
- callback (arg, bf,
- (((uint32_t *) & tmp[round & 1])[slot]) &
- ((bf->bitArraySize * 8) - 1)))
- return;
- slot++;
- bitCount--;
- if (bitCount == 0)
- break;
- }
- if (bitCount > 0)
- {
- GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode),
- &tmp[(round + 1) & 1]);
- round++;
- slot = 0;
- }
+ if (GNUNET_YES !=
+ callback (arg, bf,
+ (((uint32_t *) & tmp[round & 1])[slot]) &
+ ((bf->bitArraySize * 8) - 1)))
+ return;
+ slot++;
+ bitCount--;
+ if (bitCount == 0)
+ break;
}
+ if (bitCount > 0)
+ {
+ GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode),
+ &tmp[(round + 1) & 1]);
+ round++;
+ slot = 0;
+ }
+ }
}
* @return GNUNET_YES
*/
static int
-incrementBitCallback (void *cls,
- const struct GNUNET_CONTAINER_BloomFilter *bf,
- unsigned int bit)
+incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+ unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
* @return GNUNET_YES
*/
static int
-decrementBitCallback (void *cls,
- const struct GNUNET_CONTAINER_BloomFilter *bf,
- unsigned int bit)
+decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+ unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
*/
static int
testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
- unsigned int bit)
+ unsigned int bit)
{
int *arg = cls;
if (GNUNET_NO == testBit (bf->bitArray, bit))
- {
- *arg = GNUNET_NO;
- return GNUNET_NO;
- }
+ {
+ *arg = GNUNET_NO;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
*/
struct GNUNET_CONTAINER_BloomFilter *
GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
- unsigned int k)
+ unsigned int k)
{
struct GNUNET_CONTAINER_BloomFilter *bf;
char *rbuff;
ui = 1;
while (ui < size)
ui *= 2;
- size = ui; /* make sure it's a power of 2 */
+ size = ui; /* make sure it's a power of 2 */
bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter));
/* Try to open a bloomfilter file */
bf->fh =
- GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == bf->fh)
- {
- GNUNET_free (bf);
- return NULL;
- }
+ {
+ GNUNET_free (bf);
+ return NULL;
+ }
bf->filename = GNUNET_strdup (filename);
/* Alloc block */
bf->bitArray = GNUNET_malloc_large (size);
if (bf->bitArray == NULL)
- {
- if (bf->fh != NULL)
- GNUNET_DISK_file_close (bf->fh);
- GNUNET_free (bf->filename);
- GNUNET_free (bf);
- return NULL;
- }
+ {
+ if (bf->fh != NULL)
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf->filename);
+ GNUNET_free (bf);
+ return NULL;
+ }
bf->bitArraySize = size;
bf->addressesPerElement = k;
memset (bf->bitArray, 0, bf->bitArraySize);
rbuff = GNUNET_malloc (BUFFSIZE);
pos = 0;
while (pos < size * 8)
+ {
+ int res;
+
+ res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
+ if (res == -1)
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
+ }
+ if (res == 0)
+ break; /* is ok! we just did not use that many bits yet */
+ for (i = 0; i < res; i++)
{
- int res;
-
- res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
- if (res == -1)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
- }
- if (res == 0)
- break; /* is ok! we just did not use that many bits yet */
- for (i = 0; i < res; i++)
- {
- if ((rbuff[i] & 0x0F) != 0)
- setBit (bf->bitArray, pos + i * 2);
- if ((rbuff[i] & 0xF0) != 0)
- setBit (bf->bitArray, pos + i * 2 + 1);
- }
- if (res < BUFFSIZE)
- break;
- pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
+ if ((rbuff[i] & 0x0F) != 0)
+ setBit (bf->bitArray, pos + i * 2);
+ if ((rbuff[i] & 0xF0) != 0)
+ setBit (bf->bitArray, pos + i * 2 + 1);
}
+ if (res < BUFFSIZE)
+ break;
+ pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
+ }
GNUNET_free (rbuff);
return bf;
}
*/
struct GNUNET_CONTAINER_BloomFilter *
GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
- unsigned int k)
+ unsigned int k)
{
struct GNUNET_CONTAINER_BloomFilter *bf;
size_t ui;
while (ui < size)
ui *= 2;
if (size != ui)
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter));
bf->filename = NULL;
bf->fh = NULL;
bf->bitArray = GNUNET_malloc_large (size);
if (bf->bitArray == NULL)
- {
- GNUNET_free (bf);
- return NULL;
- }
+ {
+ GNUNET_free (bf);
+ return NULL;
+ }
bf->bitArraySize = size;
bf->addressesPerElement = k;
if (data != NULL)
*/
int
GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
- GNUNET_CONTAINER_BloomFilter *bf,
- char *data, size_t size)
+ GNUNET_CONTAINER_BloomFilter *bf,
+ char *data, size_t size)
{
if (NULL == bf)
return GNUNET_SYSERR;
*/
int
GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
- *bf, const GNUNET_HashCode * e)
+ *bf, const GNUNET_HashCode * e)
{
int res;
*/
void
GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
- const GNUNET_HashCode * e)
+ const GNUNET_HashCode * e)
{
if (NULL == bf)
return;
*/
int
GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
- const char *data, size_t size)
+ const char *data, size_t size)
{
unsigned int i;
unsigned int n;
*/
int
GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_CONTAINER_BloomFilter
- *to_or, size_t size)
+ const struct GNUNET_CONTAINER_BloomFilter
+ *to_or, size_t size)
{
unsigned int i;
unsigned int n;
*/
void
GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
- const GNUNET_HashCode * e)
+ const GNUNET_HashCode * e)
{
if (NULL == bf)
return;
*/
void
GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
- GNUNET_HashCodeIterator iterator,
- void *iterator_cls, size_t size,
- unsigned int k)
+ GNUNET_HashCodeIterator iterator,
+ void *iterator_cls, size_t size,
+ unsigned int k)
{
GNUNET_HashCode hc;
unsigned int i;
i = 1;
while (i < size)
i *= 2;
- size = i; /* make sure it's a power of 2 */
+ size = i; /* make sure it's a power of 2 */
bf->bitArraySize = size;
bf->bitArray = GNUNET_malloc (size);
if (NULL == node)
return;
GNUNET_assert (node->tree_size ==
- ((node->left_child ==
- NULL) ? 0 : 1 + node->left_child->tree_size) +
- ((node->right_child ==
- NULL) ? 0 : 1 + node->right_child->tree_size));
+ ((node->left_child ==
+ NULL) ? 0 : 1 + node->left_child->tree_size) +
+ ((node->right_child ==
+ NULL) ? 0 : 1 + node->right_child->tree_size));
check (node->left_child);
check (node->right_child);
}
*/
GNUNET_CONTAINER_HeapCostType
GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
- * node)
+ *node)
{
return node->cost;
}
*/
static int
node_iterator (const struct GNUNET_CONTAINER_Heap *heap,
- struct GNUNET_CONTAINER_HeapNode *node,
- GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls)
+ struct GNUNET_CONTAINER_HeapNode *node,
+ GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls)
{
if (node == NULL)
return GNUNET_YES;
*/
void
GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
- GNUNET_CONTAINER_HeapIterator iterator,
- void *iterator_cls)
+ GNUNET_CONTAINER_HeapIterator iterator,
+ void *iterator_cls)
{
(void) node_iterator (heap, heap->root, iterator, iterator_cls);
}
pos = heap->root;
element = pos->element;
heap->walk_pos =
- (0 ==
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 2)) ? pos->right_child : pos->left_child;
+ (0 ==
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ 2)) ? pos->right_child : pos->left_child;
return element;
}
*/
static void
insert_node (struct GNUNET_CONTAINER_Heap *heap,
- struct GNUNET_CONTAINER_HeapNode *pos,
- struct GNUNET_CONTAINER_HeapNode *node)
+ struct GNUNET_CONTAINER_HeapNode *pos,
+ struct GNUNET_CONTAINER_HeapNode *node)
{
struct GNUNET_CONTAINER_HeapNode *parent;
GNUNET_assert (node->parent == NULL);
while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) ? (pos->cost >=
- node->cost)
- : (pos->cost <= node->cost))
+ node->cost)
+ : (pos->cost <= node->cost))
+ {
+ /* node is descendent of pos */
+ pos->tree_size += (1 + node->tree_size);
+ if (pos->left_child == NULL)
{
- /* node is descendent of pos */
- pos->tree_size += (1 + node->tree_size);
- if (pos->left_child == NULL)
- {
- pos->left_child = node;
- node->parent = pos;
- return;
- }
- if (pos->right_child == NULL)
- {
- pos->right_child = node;
- node->parent = pos;
- return;
- }
- /* keep it balanced by descending into smaller subtree */
- if (pos->left_child->tree_size < pos->right_child->tree_size)
- pos = pos->left_child;
- else
- pos = pos->right_child;
+ pos->left_child = node;
+ node->parent = pos;
+ return;
}
+ if (pos->right_child == NULL)
+ {
+ pos->right_child = node;
+ node->parent = pos;
+ return;
+ }
+ /* keep it balanced by descending into smaller subtree */
+ if (pos->left_child->tree_size < pos->right_child->tree_size)
+ pos = pos->left_child;
+ else
+ pos = pos->right_child;
+ }
/* make 'node' parent of 'pos' */
parent = pos->parent;
pos->parent = NULL;
node->parent = parent;
if (NULL == parent)
- {
- heap->root = node;
- }
+ {
+ heap->root = node;
+ }
else
- {
- if (parent->left_child == pos)
- parent->left_child = node;
- else
- parent->right_child = node;
- }
+ {
+ if (parent->left_child == pos)
+ parent->left_child = node;
+ else
+ parent->right_child = node;
+ }
/* insert 'pos' below 'node' */
insert_node (heap, node, pos);
CHECK (pos);
* @return node for the new element
*/
struct GNUNET_CONTAINER_HeapNode *
-GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
- void *element,
- GNUNET_CONTAINER_HeapCostType cost)
+GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element,
+ GNUNET_CONTAINER_HeapCostType cost)
{
struct GNUNET_CONTAINER_HeapNode *node;
heap->size--;
ret = root->element;
if (root->left_child == NULL)
- {
- heap->root = root->right_child;
- if (root->right_child != NULL)
- root->right_child->parent = NULL;
- }
+ {
+ heap->root = root->right_child;
+ if (root->right_child != NULL)
+ root->right_child->parent = NULL;
+ }
else if (root->right_child == NULL)
- {
- heap->root = root->left_child;
- root->left_child->parent = NULL;
- }
+ {
+ heap->root = root->left_child;
+ root->left_child->parent = NULL;
+ }
else
- {
- root->left_child->parent = NULL;
- root->right_child->parent = NULL;
- heap->root = root->left_child;
- insert_node (heap, heap->root, root->right_child);
- }
+ {
+ root->left_child->parent = NULL;
+ root->right_child->parent = NULL;
+ heap->root = root->left_child;
+ insert_node (heap, heap->root, root->right_child);
+ }
GNUNET_free (root);
#if DEBUG
GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
- (heap->size == heap->root->tree_size + 1));
+ (heap->size == heap->root->tree_size + 1));
CHECK (heap->root);
#endif
return ret;
/* unlink 'node' itself and insert children in its place */
if (node->parent == NULL)
+ {
+ if (node->left_child != NULL)
{
- if (node->left_child != NULL)
- {
- heap->root = node->left_child;
- node->left_child->parent = NULL;
- if (node->right_child != NULL)
- {
- node->right_child->parent = NULL;
- insert_node (heap, heap->root, node->right_child);
- }
- }
- else
- {
- heap->root = node->right_child;
- if (node->right_child != NULL)
- node->right_child->parent = NULL;
- }
+ heap->root = node->left_child;
+ node->left_child->parent = NULL;
+ if (node->right_child != NULL)
+ {
+ node->right_child->parent = NULL;
+ insert_node (heap, heap->root, node->right_child);
+ }
}
- else
+ else
{
- if (node->parent->left_child == node)
- node->parent->left_child = NULL;
- else
- node->parent->right_child = NULL;
- if (node->left_child != NULL)
- {
- node->left_child->parent = NULL;
- node->parent->tree_size -= (1 + node->left_child->tree_size);
- insert_node (heap, node->parent, node->left_child);
- }
+ heap->root = node->right_child;
if (node->right_child != NULL)
- {
- node->right_child->parent = NULL;
- node->parent->tree_size -= (1 + node->right_child->tree_size);
- insert_node (heap, node->parent, node->right_child);
- }
+ node->right_child->parent = NULL;
+ }
+ }
+ else
+ {
+ if (node->parent->left_child == node)
+ node->parent->left_child = NULL;
+ else
+ node->parent->right_child = NULL;
+ if (node->left_child != NULL)
+ {
+ node->left_child->parent = NULL;
+ node->parent->tree_size -= (1 + node->left_child->tree_size);
+ insert_node (heap, node->parent, node->left_child);
+ }
+ if (node->right_child != NULL)
+ {
+ node->right_child->parent = NULL;
+ node->parent->tree_size -= (1 + node->right_child->tree_size);
+ insert_node (heap, node->parent, node->right_child);
}
+ }
node->parent = NULL;
node->left_child = NULL;
node->right_child = NULL;
#if DEBUG
CHECK (heap->root);
GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
- (heap->size == heap->root->tree_size + 1));
+ (heap->size == heap->root->tree_size + 1));
#endif
return ret;
}
*/
void
GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
- struct GNUNET_CONTAINER_HeapNode *node,
- GNUNET_CONTAINER_HeapCostType new_cost)
+ struct GNUNET_CONTAINER_HeapNode *node,
+ GNUNET_CONTAINER_HeapCostType new_cost)
{
#if DEBUG
GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
- (heap->size == heap->root->tree_size + 1));
+ (heap->size == heap->root->tree_size + 1));
CHECK (heap->root);
#endif
remove_node (node);
#if DEBUG
CHECK (heap->root);
GNUNET_assert (((heap->size == 1) && (heap->root == NULL)) ||
- (heap->size == heap->root->tree_size + 2));
+ (heap->size == heap->root->tree_size + 2));
#endif
node->cost = new_cost;
if (heap->root == NULL)
#if DEBUG
CHECK (heap->root);
GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
- (heap->size == heap->root->tree_size + 1));
+ (heap->size == heap->root->tree_size + 1));
#endif
}
if (md == NULL)
return;
while (NULL != (item = md->items))
- {
- md->items = item->next;
- meta_item_free (item);
- }
+ {
+ md->items = item->next;
+ meta_item_free (item);
+ }
GNUNET_free_non_null (md->sbuf);
GNUNET_free (md);
}
if (md == NULL)
return;
while (NULL != (item = md->items))
- {
- md->items = item->next;
- meta_item_free (item);
- }
+ {
+ md->items = item->next;
+ meta_item_free (item);
+ }
GNUNET_free_non_null (md->sbuf);
memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData));
}
*/
int
GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
- *md1,
- const struct GNUNET_CONTAINER_MetaData
- *md2)
+ *md1,
+ const struct GNUNET_CONTAINER_MetaData
+ *md2)
{
struct MetaItem *i;
struct MetaItem *j;
i = md1->items;
while (NULL != i)
+ {
+ found = GNUNET_NO;
+ j = md2->items;
+ while (NULL != j)
{
- found = GNUNET_NO;
- j = md2->items;
- while (NULL != j)
- {
- if ((i->type == j->type) && (i->format == j->format) &&
- (i->data_size == j->data_size) &&
- (0 == memcmp (i->data, j->data, i->data_size)))
- {
- found = GNUNET_YES;
- break;
- }
- j = j->next;
- }
- if (found == GNUNET_NO)
- return GNUNET_NO;
- i = i->next;
+ if ((i->type == j->type) && (i->format == j->format) &&
+ (i->data_size == j->data_size) &&
+ (0 == memcmp (i->data, j->data, i->data_size)))
+ {
+ found = GNUNET_YES;
+ break;
+ }
+ j = j->next;
}
+ if (found == GNUNET_NO)
+ return GNUNET_NO;
+ i = i->next;
+ }
return GNUNET_YES;
}
*/
int
GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
- const char *plugin_name,
- enum EXTRACTOR_MetaType type,
- enum EXTRACTOR_MetaFormat format,
- const char *data_mime_type,
- const char *data, size_t data_len)
+ const char *plugin_name,
+ enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type, const char *data,
+ size_t data_len)
{
struct MetaItem *prev;
struct MetaItem *pos;
prev = NULL;
pos = md->items;
while (NULL != pos)
+ {
+ if (pos->data_size < data_len)
+ break;
+ if ((pos->type == type) && (pos->data_size == data_len) &&
+ (0 == memcmp (pos->data, data, data_len)))
{
- if (pos->data_size < data_len)
- break;
- if ((pos->type == type) && (pos->data_size == data_len) &&
- (0 == memcmp (pos->data, data, data_len)))
- {
- if ((pos->mime_type == NULL) && (data_mime_type != NULL))
- {
- pos->mime_type = GNUNET_strdup (data_mime_type);
- invalidate_sbuf (md);
- }
- if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) &&
- (format == EXTRACTOR_METAFORMAT_UTF8))
- {
- pos->format = EXTRACTOR_METAFORMAT_UTF8;
- invalidate_sbuf (md);
- }
- return GNUNET_SYSERR;
- }
- prev = pos;
- pos = pos->next;
+ if ((pos->mime_type == NULL) && (data_mime_type != NULL))
+ {
+ pos->mime_type = GNUNET_strdup (data_mime_type);
+ invalidate_sbuf (md);
+ }
+ if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) &&
+ (format == EXTRACTOR_METAFORMAT_UTF8))
+ {
+ pos->format = EXTRACTOR_METAFORMAT_UTF8;
+ invalidate_sbuf (md);
+ }
+ return GNUNET_SYSERR;
}
+ prev = pos;
+ pos = pos->next;
+ }
md->item_count++;
i = GNUNET_malloc (sizeof (struct MetaItem));
i->type = type;
else
prev->next = i;
i->mime_type =
- (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type);
+ (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type);
i->plugin_name = (plugin_name == NULL) ? NULL : GNUNET_strdup (plugin_name);
i->data = GNUNET_malloc (data_len);
memcpy (i->data, data, data_len);
/* change OS native dir separators to unix '/' and others to '_' */
if (type == EXTRACTOR_METATYPE_FILENAME)
+ {
+ p = i->data;
+ while ((*p != '\0') && (p < i->data + data_len))
{
- p = i->data;
- while ((*p != '\0') && (p < i->data + data_len))
- {
- if (*p == DIR_SEPARATOR)
- *p = '/';
- else if (*p == '\\')
- *p = '_';
- p++;
- }
+ if (*p == DIR_SEPARATOR)
+ *p = '/';
+ else if (*p == '\\')
+ *p = '_';
+ p++;
}
+ }
invalidate_sbuf (md);
return GNUNET_OK;
}
* @return 0 (to continue)
*/
static int
-merge_helper (void *cls, const char *plugin_name,
- enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
- const char *data_mime_type, const char *data, size_t data_len)
+merge_helper (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
+ const char *data, size_t data_len)
{
struct GNUNET_CONTAINER_MetaData *md = cls;
(void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
- data_mime_type, data, data_len);
+ data_mime_type, data, data_len);
return 0;
}
*/
void
GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
- const struct GNUNET_CONTAINER_MetaData *in)
+ const struct GNUNET_CONTAINER_MetaData *in)
{
GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md);
}
*/
int
GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
- enum EXTRACTOR_MetaType type,
- const char *data, size_t data_len)
+ enum EXTRACTOR_MetaType type,
+ const char *data, size_t data_len)
{
struct MetaItem *pos;
struct MetaItem *prev;
prev = NULL;
pos = md->items;
while (NULL != pos)
+ {
+ if ((pos->type == type) &&
+ ((data == NULL) ||
+ ((pos->data_size == data_len) &&
+ (0 == memcmp (pos->data, data, data_len)))))
{
- if ((pos->type == type) &&
- ((data == NULL) ||
- ((pos->data_size == data_len) &&
- (0 == memcmp (pos->data, data, data_len)))))
- {
- if (prev == NULL)
- md->items = pos->next;
- else
- prev->next = pos->next;
- meta_item_free (pos);
- md->item_count--;
- invalidate_sbuf (md);
- return GNUNET_OK;
- }
- prev = pos;
- pos = pos->next;
+ if (prev == NULL)
+ md->items = pos->next;
+ else
+ prev->next = pos->next;
+ meta_item_free (pos);
+ md->item_count--;
+ invalidate_sbuf (md);
+ return GNUNET_OK;
}
+ prev = pos;
+ pos = pos->next;
+ }
return GNUNET_SYSERR;
}
*/
void
GNUNET_CONTAINER_meta_data_add_publication_date (struct
- GNUNET_CONTAINER_MetaData
- *md)
+ GNUNET_CONTAINER_MetaData *md)
{
char *dat;
struct GNUNET_TIME_Absolute t;
t = GNUNET_TIME_absolute_get ();
GNUNET_CONTAINER_meta_data_delete (md, EXTRACTOR_METATYPE_PUBLICATION_DATE,
- NULL, 0);
+ NULL, 0);
dat = GNUNET_STRINGS_absolute_time_to_string (t);
GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>",
- EXTRACTOR_METATYPE_PUBLICATION_DATE,
- EXTRACTOR_METAFORMAT_UTF8, "text/plain",
- dat, strlen (dat) + 1);
+ EXTRACTOR_METATYPE_PUBLICATION_DATE,
+ EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+ dat, strlen (dat) + 1);
GNUNET_free (dat);
}
* @return number of entries
*/
int
-GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData
- *md, EXTRACTOR_MetaDataProcessor iter,
- void *iter_cls)
+GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
+ EXTRACTOR_MetaDataProcessor iter,
+ void *iter_cls)
{
struct MetaItem *pos;
return md->item_count;
pos = md->items;
while (NULL != pos)
- {
- if (0 !=
- iter (iter_cls, pos->plugin_name, pos->type, pos->format,
- pos->mime_type, pos->data, pos->data_size))
- return md->item_count;
- pos = pos->next;
- }
+ {
+ if (0 !=
+ iter (iter_cls, pos->plugin_name, pos->type, pos->format,
+ pos->mime_type, pos->data, pos->data_size))
+ return md->item_count;
+ pos = pos->next;
+ }
return md->item_count;
}
*/
char *
GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData
- *md, enum EXTRACTOR_MetaType type)
+ *md, enum EXTRACTOR_MetaType type)
{
struct MetaItem *pos;
return NULL;
pos = md->items;
while (NULL != pos)
- {
- if ((type == pos->type) &&
- ((pos->format == EXTRACTOR_METAFORMAT_UTF8) ||
- (pos->format == EXTRACTOR_METAFORMAT_C_STRING)))
- return GNUNET_strdup (pos->data);
- pos = pos->next;
- }
+ {
+ if ((type == pos->type) &&
+ ((pos->format == EXTRACTOR_METAFORMAT_UTF8) ||
+ (pos->format == EXTRACTOR_METAFORMAT_C_STRING)))
+ return GNUNET_strdup (pos->data);
+ pos = pos->next;
+ }
return NULL;
}
*/
char *
GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
- GNUNET_CONTAINER_MetaData *md,
- ...)
+ GNUNET_CONTAINER_MetaData *md,
+ ...)
{
char *ret;
va_list args;
ret = NULL;
va_start (args, md);
while (1)
- {
- type = va_arg (args, enum EXTRACTOR_MetaType);
-
- if (type == -1)
- break;
- ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type);
- if (ret != NULL)
- break;
- }
+ {
+ type = va_arg (args, enum EXTRACTOR_MetaType);
+
+ if (type == -1)
+ break;
+ ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type);
+ if (ret != NULL)
+ break;
+ }
va_end (args);
return ret;
}
* @return number of bytes in thumbnail, 0 if not available
*/
size_t
-GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
- GNUNET_CONTAINER_MetaData * md,
- unsigned char **thumb)
+GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData
+ * md, unsigned char **thumb)
{
struct MetaItem *pos;
struct MetaItem *match;
match = NULL;
pos = md->items;
while (NULL != pos)
+ {
+ if ((NULL != pos->mime_type) &&
+ (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) &&
+ (pos->format == EXTRACTOR_METAFORMAT_BINARY))
{
- if ((NULL != pos->mime_type) &&
- (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) &&
- (pos->format == EXTRACTOR_METAFORMAT_BINARY))
- {
- if (match == NULL)
- match = pos;
- else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
- (pos->type == EXTRACTOR_METATYPE_THUMBNAIL))
- match = pos;
- }
- pos = pos->next;
+ if (match == NULL)
+ match = pos;
+ else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
+ (pos->type == EXTRACTOR_METATYPE_THUMBNAIL))
+ match = pos;
}
+ pos = pos->next;
+ }
if ((match == NULL) || (match->data_size == 0))
return 0;
*thumb = GNUNET_malloc (match->data_size);
*/
struct GNUNET_CONTAINER_MetaData *
GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
- *md)
+ *md)
{
struct GNUNET_CONTAINER_MetaData *ret;
struct MetaItem *pos;
ret = GNUNET_CONTAINER_meta_data_create ();
pos = md->items;
while (NULL != pos)
- {
- GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type,
- pos->format, pos->mime_type,
- pos->data, pos->data_size);
- pos = pos->next;
- }
+ {
+ GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type,
+ pos->format, pos->mime_type, pos->data,
+ pos->data_size);
+ pos = pos->next;
+ }
return ret;
}
*/
static int
try_compression (const char *data, size_t oldSize, char **result,
- size_t * newSize)
+ size_t * newSize)
{
char *tmp;
uLongf dlen;
tmp = GNUNET_malloc (dlen);
if (Z_OK ==
compress2 ((Bytef *) tmp, &dlen, (const Bytef *) data, oldSize, 9))
+ {
+ if (dlen < oldSize)
{
- if (dlen < oldSize)
- {
- *result = tmp;
- *newSize = dlen;
- return GNUNET_YES;
- }
+ *result = tmp;
+ *newSize = dlen;
+ return GNUNET_YES;
}
+ }
GNUNET_free (tmp);
return GNUNET_NO;
}
*/
ssize_t
GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
- *md, char **target, size_t max,
- enum
- GNUNET_CONTAINER_MetaDataSerializationOptions
- opt)
+ *md, char **target, size_t max,
+ enum
+ GNUNET_CONTAINER_MetaDataSerializationOptions
+ opt)
{
struct GNUNET_CONTAINER_MetaData *vmd;
struct MetaItem *pos;
int comp;
if (max < sizeof (struct MetaDataHeader))
- return GNUNET_SYSERR; /* far too small */
+ return GNUNET_SYSERR; /* far too small */
if (md == NULL)
return 0;
if (md->sbuf != NULL)
+ {
+ /* try to use serialization cache */
+ if (md->sbuf_size <= max)
{
- /* try to use serialization cache */
- if (md->sbuf_size <= max)
- {
- if (NULL == *target)
- *target = GNUNET_malloc (md->sbuf_size);
- memcpy (*target, md->sbuf, md->sbuf_size);
- return md->sbuf_size;
- }
- if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
- return GNUNET_SYSERR; /* can say that this will fail */
- /* need to compute a partial serialization, sbuf useless ... */
+ if (NULL == *target)
+ *target = GNUNET_malloc (md->sbuf_size);
+ memcpy (*target, md->sbuf, md->sbuf_size);
+ return md->sbuf_size;
}
+ if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
+ return GNUNET_SYSERR; /* can say that this will fail */
+ /* need to compute a partial serialization, sbuf useless ... */
+ }
dst = NULL;
msize = 0;
pos = md->items;
while (NULL != pos)
- {
- msize += sizeof (struct MetaDataEntry);
- msize += pos->data_size;
- if (pos->plugin_name != NULL)
- msize += strlen (pos->plugin_name) + 1;
- if (pos->mime_type != NULL)
- msize += strlen (pos->mime_type) + 1;
- pos = pos->next;
- }
+ {
+ msize += sizeof (struct MetaDataEntry);
+ msize += pos->data_size;
+ if (pos->plugin_name != NULL)
+ msize += strlen (pos->plugin_name) + 1;
+ if (pos->mime_type != NULL)
+ msize += strlen (pos->mime_type) + 1;
+ pos = pos->next;
+ }
size = (size_t) msize;
if (size != msize)
- {
- GNUNET_break (0); /* integer overflow */
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0); /* integer overflow */
+ return GNUNET_SYSERR;
+ }
if (size >= GNUNET_MAX_MALLOC_CHECKED)
- {
- /* too large to be processed */
- return GNUNET_SYSERR;
- }
+ {
+ /* too large to be processed */
+ return GNUNET_SYSERR;
+ }
ent = GNUNET_malloc (size);
mdata = (char *) &ent[md->item_count];
off = size - (md->item_count * sizeof (struct MetaDataEntry));
i = 0;
pos = md->items;
while (NULL != pos)
- {
- ent[i].type = htonl ((uint32_t) pos->type);
- ent[i].format = htonl ((uint32_t) pos->format);
- ent[i].data_size = htonl ((uint32_t) pos->data_size);
- if (pos->plugin_name == NULL)
- plen = 0;
- else
- plen = strlen (pos->plugin_name) + 1;
- ent[i].plugin_name_len = htonl ((uint32_t) plen);
- if (pos->mime_type == NULL)
- mlen = 0;
- else
- mlen = strlen (pos->mime_type) + 1;
- ent[i].mime_type_len = htonl ((uint32_t) mlen);
- off -= pos->data_size;
- memcpy (&mdata[off], pos->data, pos->data_size);
- off -= plen;
- if (pos->plugin_name != NULL)
- memcpy (&mdata[off], pos->plugin_name, plen);
- off -= mlen;
- if (pos->mime_type != NULL)
- memcpy (&mdata[off], pos->mime_type, mlen);
- i++;
- pos = pos->next;
- }
+ {
+ ent[i].type = htonl ((uint32_t) pos->type);
+ ent[i].format = htonl ((uint32_t) pos->format);
+ ent[i].data_size = htonl ((uint32_t) pos->data_size);
+ if (pos->plugin_name == NULL)
+ plen = 0;
+ else
+ plen = strlen (pos->plugin_name) + 1;
+ ent[i].plugin_name_len = htonl ((uint32_t) plen);
+ if (pos->mime_type == NULL)
+ mlen = 0;
+ else
+ mlen = strlen (pos->mime_type) + 1;
+ ent[i].mime_type_len = htonl ((uint32_t) mlen);
+ off -= pos->data_size;
+ memcpy (&mdata[off], pos->data, pos->data_size);
+ off -= plen;
+ if (pos->plugin_name != NULL)
+ memcpy (&mdata[off], pos->plugin_name, plen);
+ off -= mlen;
+ if (pos->mime_type != NULL)
+ memcpy (&mdata[off], pos->mime_type, mlen);
+ i++;
+ pos = pos->next;
+ }
GNUNET_assert (off == 0);
clen = 0;
i = 0;
pos = md->items;
while (pos != NULL)
+ {
+ comp = GNUNET_NO;
+ if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS))
+ comp = try_compression ((const char *) &ent[i], left, &cdata, &clen);
+
+ if ((md->sbuf == NULL) && (i == 0))
+ {
+ /* fill 'sbuf'; this "modifies" md, but since this is only
+ * an internal cache we will cast away the 'const' instead
+ * of making the API look strange. */
+ vmd = (struct GNUNET_CONTAINER_MetaData *) md;
+ hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
+ hdr->size = htonl (left);
+ hdr->entries = htonl (md->item_count);
+ if (GNUNET_YES == comp)
+ {
+ GNUNET_assert (clen < left);
+ hdr->version = htonl (2 | HEADER_COMPRESSED);
+ memcpy (&hdr[1], cdata, clen);
+ vmd->sbuf_size = clen + sizeof (struct MetaDataHeader);
+ }
+ else
+ {
+ hdr->version = htonl (2);
+ memcpy (&hdr[1], &ent[0], left);
+ vmd->sbuf_size = left + sizeof (struct MetaDataHeader);
+ }
+ vmd->sbuf = (char *) hdr;
+ }
+
+ if (((left + sizeof (struct MetaDataHeader)) <= max) ||
+ ((comp == GNUNET_YES) && (clen <= max)))
+ {
+ /* success, this now fits! */
+ if (GNUNET_YES == comp)
+ {
+ if (dst == NULL)
+ dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader));
+ hdr = (struct MetaDataHeader *) dst;
+ hdr->version = htonl (2 | HEADER_COMPRESSED);
+ hdr->size = htonl (left);
+ hdr->entries = htonl (md->item_count - i);
+ memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen);
+ GNUNET_free (cdata);
+ GNUNET_free (ent);
+ rlen = clen + sizeof (struct MetaDataHeader);
+ }
+ else
+ {
+ if (dst == NULL)
+ dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
+ hdr = (struct MetaDataHeader *) dst;
+ hdr->version = htonl (2);
+ hdr->entries = htonl (md->item_count - i);
+ hdr->size = htonl (left);
+ memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left);
+ GNUNET_free (ent);
+ rlen = left + sizeof (struct MetaDataHeader);
+ }
+ if (NULL != *target)
+ {
+ memcpy (*target, dst, clen + sizeof (struct MetaDataHeader));
+ GNUNET_free (dst);
+ }
+ else
+ {
+ *target = dst;
+ }
+ return rlen;
+ }
+
+ if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
{
- comp = GNUNET_NO;
- if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS))
- comp = try_compression ((const char *) &ent[i], left, &cdata, &clen);
-
- if ((md->sbuf == NULL) && (i == 0))
- {
- /* fill 'sbuf'; this "modifies" md, but since this is only
- * an internal cache we will cast away the 'const' instead
- * of making the API look strange. */
- vmd = (struct GNUNET_CONTAINER_MetaData *) md;
- hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
- hdr->size = htonl (left);
- hdr->entries = htonl (md->item_count);
- if (GNUNET_YES == comp)
- {
- GNUNET_assert (clen < left);
- hdr->version = htonl (2 | HEADER_COMPRESSED);
- memcpy (&hdr[1], cdata, clen);
- vmd->sbuf_size = clen + sizeof (struct MetaDataHeader);
- }
- else
- {
- hdr->version = htonl (2);
- memcpy (&hdr[1], &ent[0], left);
- vmd->sbuf_size = left + sizeof (struct MetaDataHeader);
- }
- vmd->sbuf = (char *) hdr;
- }
-
- if (((left + sizeof (struct MetaDataHeader)) <= max) ||
- ((comp == GNUNET_YES) && (clen <= max)))
- {
- /* success, this now fits! */
- if (GNUNET_YES == comp)
- {
- if (dst == NULL)
- dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader));
- hdr = (struct MetaDataHeader *) dst;
- hdr->version = htonl (2 | HEADER_COMPRESSED);
- hdr->size = htonl (left);
- hdr->entries = htonl (md->item_count - i);
- memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen);
- GNUNET_free (cdata);
- GNUNET_free (ent);
- rlen = clen + sizeof (struct MetaDataHeader);
- }
- else
- {
- if (dst == NULL)
- dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
- hdr = (struct MetaDataHeader *) dst;
- hdr->version = htonl (2);
- hdr->entries = htonl (md->item_count - i);
- hdr->size = htonl (left);
- memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left);
- GNUNET_free (ent);
- rlen = left + sizeof (struct MetaDataHeader);
- }
- if (NULL != *target)
- {
- memcpy (*target, dst, clen + sizeof (struct MetaDataHeader));
- GNUNET_free (dst);
- }
- else
- {
- *target = dst;
- }
- return rlen;
- }
-
- if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
- {
- /* does not fit! */
- GNUNET_free (ent);
- return GNUNET_SYSERR;
- }
-
- /* next iteration: ignore the corresponding meta data at the
- * end and try again without it */
- left -= sizeof (struct MetaDataEntry);
- left -= pos->data_size;
- if (pos->plugin_name != NULL)
- left -= strlen (pos->plugin_name) + 1;
- if (pos->mime_type != NULL)
- left -= strlen (pos->mime_type) + 1;
- pos = pos->next;
- i++;
+ /* does not fit! */
+ GNUNET_free (ent);
+ return GNUNET_SYSERR;
}
+
+ /* next iteration: ignore the corresponding meta data at the
+ * end and try again without it */
+ left -= sizeof (struct MetaDataEntry);
+ left -= pos->data_size;
+ if (pos->plugin_name != NULL)
+ left -= strlen (pos->plugin_name) + 1;
+ if (pos->mime_type != NULL)
+ left -= strlen (pos->mime_type) + 1;
+ pos = pos->next;
+ i++;
+ }
GNUNET_free (ent);
/* nothing fit, only write header! */
*/
ssize_t
GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
- GNUNET_CONTAINER_MetaData *md)
+ GNUNET_CONTAINER_MetaData *md)
{
ssize_t ret;
char *ptr;
return md->sbuf_size;
ptr = NULL;
ret =
- GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
+ GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED,
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
if (ret != -1)
GNUNET_free (ptr);
return ret;
output = GNUNET_malloc (olen);
if (Z_OK ==
uncompress ((Bytef *) output, &olen, (const Bytef *) input, inputSize))
- {
- return output;
- }
+ {
+ return output;
+ }
else
- {
- GNUNET_free (output);
- return NULL;
- }
+ {
+ GNUNET_free (output);
+ return NULL;
+ }
}
compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0;
if (version == 1)
- return NULL; /* null pointer */
+ return NULL; /* null pointer */
if (version != 2)
- {
- GNUNET_break_op (0); /* unsupported version */
- return NULL;
- }
+ {
+ GNUNET_break_op (0); /* unsupported version */
+ return NULL;
+ }
ic = ntohl (hdr.entries);
dataSize = ntohl (hdr.size);
if ((sizeof (struct MetaDataEntry) * ic) > dataSize)
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+
+ if (compressed)
+ {
+ if (dataSize >= GNUNET_MAX_MALLOC_CHECKED)
{
+ /* make sure we don't blow our memory limit because of a mal-formed
+ * message... */
GNUNET_break_op (0);
return NULL;
}
-
- if (compressed)
+ data =
+ decompress ((const char *) &input[sizeof (struct MetaDataHeader)],
+ size - sizeof (struct MetaDataHeader), dataSize);
+ if (data == NULL)
{
- if (dataSize >= GNUNET_MAX_MALLOC_CHECKED)
- {
- /* make sure we don't blow our memory limit because of a mal-formed
- * message... */
- GNUNET_break_op (0);
- return NULL;
- }
- data =
- decompress ((const char *) &input[sizeof (struct MetaDataHeader)],
- size - sizeof (struct MetaDataHeader), dataSize);
- if (data == NULL)
- {
- GNUNET_break_op (0);
- return NULL;
- }
- cdata = data;
+ GNUNET_break_op (0);
+ return NULL;
}
+ cdata = data;
+ }
else
+ {
+ data = NULL;
+ cdata = (const char *) &input[sizeof (struct MetaDataHeader)];
+ if (dataSize != size - sizeof (struct MetaDataHeader))
{
- data = NULL;
- cdata = (const char *) &input[sizeof (struct MetaDataHeader)];
- if (dataSize != size - sizeof (struct MetaDataHeader))
- {
- GNUNET_break_op (0);
- return NULL;
- }
+ GNUNET_break_op (0);
+ return NULL;
}
+ }
md = GNUNET_CONTAINER_meta_data_create ();
left = dataSize - ic * sizeof (struct MetaDataEntry);
mdata = &cdata[ic * sizeof (struct MetaDataEntry)];
for (i = 0; i < ic; i++)
+ {
+ memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)],
+ sizeof (struct MetaDataEntry));
+ format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format);
+ if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
+ (format != EXTRACTOR_METAFORMAT_C_STRING) &&
+ (format != EXTRACTOR_METAFORMAT_BINARY))
{
- memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)],
- sizeof (struct MetaDataEntry));
- format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format);
- if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
- (format != EXTRACTOR_METAFORMAT_C_STRING) &&
- (format != EXTRACTOR_METAFORMAT_BINARY))
- {
- GNUNET_break_op (0);
- break;
- }
- dlen = ntohl (ent.data_size);
- plen = ntohl (ent.plugin_name_len);
- mlen = ntohl (ent.mime_type_len);
- if (dlen > left)
- {
- GNUNET_break_op (0);
- break;
- }
- left -= dlen;
- meta_data = &mdata[left];
- if ((format == EXTRACTOR_METAFORMAT_UTF8) ||
- (format == EXTRACTOR_METAFORMAT_C_STRING))
- {
- if ((dlen == 0) || (mdata[left + dlen - 1] != '\0'))
- {
- GNUNET_break_op (0);
- break;
- }
- }
- if (plen > left)
- {
- GNUNET_break_op (0);
- break;
- }
- left -= plen;
- if ((plen > 0) && (mdata[left + plen - 1] != '\0'))
- {
- GNUNET_break_op (0);
- break;
- }
- if (plen == 0)
- plugin_name = NULL;
- else
- plugin_name = &mdata[left];
-
- if (mlen > left)
- {
- GNUNET_break_op (0);
- break;
- }
- left -= mlen;
- if ((mlen > 0) && (mdata[left + mlen - 1] != '\0'))
- {
- GNUNET_break_op (0);
- break;
- }
- if (mlen == 0)
- mime_type = NULL;
- else
- mime_type = &mdata[left];
- GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
- (enum EXTRACTOR_MetaType)
- ntohl (ent.type), format, mime_type,
- meta_data, dlen);
+ GNUNET_break_op (0);
+ break;
+ }
+ dlen = ntohl (ent.data_size);
+ plen = ntohl (ent.plugin_name_len);
+ mlen = ntohl (ent.mime_type_len);
+ if (dlen > left)
+ {
+ GNUNET_break_op (0);
+ break;
+ }
+ left -= dlen;
+ meta_data = &mdata[left];
+ if ((format == EXTRACTOR_METAFORMAT_UTF8) ||
+ (format == EXTRACTOR_METAFORMAT_C_STRING))
+ {
+ if ((dlen == 0) || (mdata[left + dlen - 1] != '\0'))
+ {
+ GNUNET_break_op (0);
+ break;
+ }
+ }
+ if (plen > left)
+ {
+ GNUNET_break_op (0);
+ break;
+ }
+ left -= plen;
+ if ((plen > 0) && (mdata[left + plen - 1] != '\0'))
+ {
+ GNUNET_break_op (0);
+ break;
+ }
+ if (plen == 0)
+ plugin_name = NULL;
+ else
+ plugin_name = &mdata[left];
+
+ if (mlen > left)
+ {
+ GNUNET_break_op (0);
+ break;
+ }
+ left -= mlen;
+ if ((mlen > 0) && (mdata[left + mlen - 1] != '\0'))
+ {
+ GNUNET_break_op (0);
+ break;
}
+ if (mlen == 0)
+ mime_type = NULL;
+ else
+ mime_type = &mdata[left];
+ GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
+ (enum EXTRACTOR_MetaType)
+ ntohl (ent.type), format, mime_type,
+ meta_data, dlen);
+ }
GNUNET_free_non_null (data);
return md;
}
*/
void
GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap
- *map)
+ *map)
{
unsigned int i;
struct MapEntry *e;
for (i = 0; i < map->map_length; i++)
+ {
+ while (NULL != (e = map->map[i]))
{
- while (NULL != (e = map->map[i]))
- {
- map->map[i] = e->next;
- GNUNET_free (e);
- }
+ map->map[i] = e->next;
+ GNUNET_free (e);
}
+ }
GNUNET_free (map->map);
GNUNET_free (map);
}
*/
static unsigned int
idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m,
- const GNUNET_HashCode * key)
+ const GNUNET_HashCode * key)
{
GNUNET_assert (m != NULL);
return (*(unsigned int *) key) % m->map_length;
*/
unsigned int
GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap
- *map)
+ *map)
{
return map->size;
}
*/
void *
GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap
- *map, const GNUNET_HashCode * key)
+ *map, const GNUNET_HashCode * key)
{
struct MapEntry *e;
e = map->map[idx_of (map, key)];
while (e != NULL)
- {
- if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
- return e->value;
- e = e->next;
- }
+ {
+ if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
+ return e->value;
+ e = e->next;
+ }
return NULL;
}
*/
int
GNUNET_CONTAINER_multihashmap_iterate (const struct
- GNUNET_CONTAINER_MultiHashMap *map,
- GNUNET_CONTAINER_HashMapIterator it,
- void *it_cls)
+ GNUNET_CONTAINER_MultiHashMap *map,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls)
{
int count;
unsigned int i;
count = 0;
GNUNET_assert (map != NULL);
for (i = 0; i < map->map_length; i++)
+ {
+ n = map->map[i];
+ while (NULL != (e = n))
{
- n = map->map[i];
- while (NULL != (e = n))
- {
- n = e->next;
- if (NULL != it)
- {
- kc = e->key;
- if (GNUNET_OK != it (it_cls, &kc, e->value))
- return GNUNET_SYSERR;
- }
- count++;
- }
+ n = e->next;
+ if (NULL != it)
+ {
+ kc = e->key;
+ if (GNUNET_OK != it (it_cls, &kc, e->value))
+ return GNUNET_SYSERR;
+ }
+ count++;
}
+ }
return count;
}
* is not in the map
*/
int
-GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap
- *map, const GNUNET_HashCode * key,
- void *value)
+GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
+ const GNUNET_HashCode * key, void *value)
{
struct MapEntry *e;
struct MapEntry *p;
p = NULL;
e = map->map[i];
while (e != NULL)
+ {
+ if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) &&
+ (value == e->value))
{
- if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) &&
- (value == e->value))
- {
- if (p == NULL)
- map->map[i] = e->next;
- else
- p->next = e->next;
- GNUNET_free (e);
- map->size--;
- return GNUNET_YES;
- }
- p = e;
- e = e->next;
+ if (p == NULL)
+ map->map[i] = e->next;
+ else
+ p->next = e->next;
+ GNUNET_free (e);
+ map->size--;
+ return GNUNET_YES;
}
+ p = e;
+ e = e->next;
+ }
return GNUNET_NO;
}
*/
int
GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap
- *map, const GNUNET_HashCode * key)
+ *map, const GNUNET_HashCode * key)
{
struct MapEntry *e;
struct MapEntry *p;
p = NULL;
e = map->map[i];
while (e != NULL)
+ {
+ if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
{
- if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
- {
- if (p == NULL)
- map->map[i] = e->next;
- else
- p->next = e->next;
- GNUNET_free (e);
- map->size--;
- if (p == NULL)
- e = map->map[i];
- else
- e = p->next;
- ret++;
- }
+ if (p == NULL)
+ map->map[i] = e->next;
else
- {
- p = e;
- e = e->next;
- }
+ p->next = e->next;
+ GNUNET_free (e);
+ map->size--;
+ if (p == NULL)
+ e = map->map[i];
+ else
+ e = p->next;
+ ret++;
+ }
+ else
+ {
+ p = e;
+ e = e->next;
}
+ }
return ret;
}
*/
int
GNUNET_CONTAINER_multihashmap_contains (const struct
- GNUNET_CONTAINER_MultiHashMap *map,
- const GNUNET_HashCode * key)
+ GNUNET_CONTAINER_MultiHashMap *map,
+ const GNUNET_HashCode * key)
{
struct MapEntry *e;
e = map->map[idx_of (map, key)];
while (e != NULL)
- {
- if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
- return GNUNET_YES;
- e = e->next;
- }
+ {
+ if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
+ return GNUNET_YES;
+ e = e->next;
+ }
return GNUNET_NO;
}
*/
int
GNUNET_CONTAINER_multihashmap_contains_value (const struct
- GNUNET_CONTAINER_MultiHashMap
- *map,
- const GNUNET_HashCode * key,
- const void *value)
+ GNUNET_CONTAINER_MultiHashMap
+ *map, const GNUNET_HashCode * key,
+ const void *value)
{
struct MapEntry *e;
e = map->map[idx_of (map, key)];
while (e != NULL)
- {
- if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) &&
- (e->value == value))
- return GNUNET_YES;
- e = e->next;
- }
+ {
+ if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) &&
+ (e->value == value))
+ return GNUNET_YES;
+ e = e->next;
+ }
return GNUNET_NO;
}
map->map_length = new_len;
map->map = new_map;
for (i = 0; i < old_len; i++)
+ {
+ while (NULL != (e = old_map[i]))
{
- while (NULL != (e = old_map[i]))
- {
- old_map[i] = e->next;
- idx = idx_of (map, &e->key);
- e->next = new_map[idx];
- new_map[idx] = e;
- }
+ old_map[i] = e->next;
+ idx = idx_of (map, &e->key);
+ e->next = new_map[idx];
+ new_map[idx] = e;
}
+ }
GNUNET_free (old_map);
}
*/
int
GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
- const GNUNET_HashCode * key, void *value,
- enum GNUNET_CONTAINER_MultiHashMapOption
- opt)
+ const GNUNET_HashCode * key, void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt)
{
struct MapEntry *e;
unsigned int i;
i = idx_of (map, key);
if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) &&
(opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+ {
+ e = map->map[i];
+ while (e != NULL)
{
- e = map->map[i];
- while (e != NULL)
- {
- if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
- {
- if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
- return GNUNET_SYSERR;
- e->value = value;
- return GNUNET_NO;
- }
- e = e->next;
- }
+ if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ e->value = value;
+ return GNUNET_NO;
+ }
+ e = e->next;
}
+ }
if (map->size / 3 >= map->map_length / 4)
- {
- grow (map);
- i = idx_of (map, key);
- }
+ {
+ grow (map);
+ i = idx_of (map, key);
+ }
e = GNUNET_malloc (sizeof (struct MapEntry));
e->key = *key;
e->value = value;
*/
int
GNUNET_CONTAINER_multihashmap_get_multiple (const struct
- GNUNET_CONTAINER_MultiHashMap
- *map, const GNUNET_HashCode * key,
- GNUNET_CONTAINER_HashMapIterator
- it, void *it_cls)
+ GNUNET_CONTAINER_MultiHashMap *map,
+ const GNUNET_HashCode * key,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls)
{
int count;
struct MapEntry *e;
count = 0;
n = map->map[idx_of (map, key)];
while (NULL != (e = n))
- {
- n = e->next;
- if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
- continue;
- if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value)))
- return GNUNET_SYSERR;
- count++;
- }
+ {
+ n = e->next;
+ if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
+ continue;
+ if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value)))
+ return GNUNET_SYSERR;
+ count++;
+ }
return count;
}
*/
static struct GNUNET_CONTAINER_SList_Elem *
create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf,
- size_t len)
+ size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
if (disp == GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT)
- {
- e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len);
- memcpy (&e[1], buf, len);
- e->elem = (void *) &e[1];
- }
+ {
+ e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len);
+ memcpy (&e[1], buf, len);
+ e->elem = (void *) &e[1];
+ }
else
- {
- e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem));
- e->elem = (void *) buf;
- }
+ {
+ e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem));
+ e->elem = (void *) buf;
+ }
e->disp = disp;
e->len = len;
return e;
*/
void
GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf, size_t len)
+ enum GNUNET_CONTAINER_SListDisposition disp,
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void
GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf, size_t len)
+ enum GNUNET_CONTAINER_SListDisposition disp,
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void
GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
- struct GNUNET_CONTAINER_SList *src)
+ struct GNUNET_CONTAINER_SList *src)
{
struct GNUNET_CONTAINER_SList_Iterator i;
GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
GNUNET_CONTAINER_slist_next (&i))
- {
- GNUNET_CONTAINER_slist_add (dst,
- (i.elem->disp ==
- GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC)
- ? GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC
- :
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- i.elem->elem, i.elem->len);
- }
+ {
+ GNUNET_CONTAINER_slist_add (dst,
+ (i.elem->disp ==
+ GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) ?
+ GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC :
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ i.elem->elem, i.elem->len);
+ }
GNUNET_CONTAINER_slist_iter_destroy (&i);
}
e = l->head;
while (e != NULL)
- {
- n = e->next;
- if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC)
- GNUNET_free (e->elem);
- GNUNET_free (e);
- e = n;
- }
+ {
+ n = e->next;
+ if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC)
+ GNUNET_free (e->elem);
+ GNUNET_free (e);
+ e = n;
+ }
l->head = NULL;
l->tail = NULL;
l->length = 0;
*/
int
GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
- const void *buf, size_t len)
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void
GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
- enum GNUNET_CONTAINER_SListDisposition disp,
- const void *buf, size_t len)
+ enum GNUNET_CONTAINER_SListDisposition disp,
+ const void *buf, size_t len)
{
struct GNUNET_CONTAINER_SList_Elem *e;
*/
void *
GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
- size_t * len)
+ size_t * len)
{
if (len)
*len = i->elem->len;
* @param i iterator
*/
void
-GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator
- *i)
+GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i)
{
}
GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key)
{
gcry_randomize (&key->key[0], GNUNET_CRYPTO_AES_KEY_LENGTH,
- GCRY_STRONG_RANDOM);
+ GCRY_STRONG_RANDOM);
key->crc32 =
- htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH));
+ htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH));
}
/**
*/
int
GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey
- *key)
+ *key)
{
uint32_t crc;
*/
ssize_t
GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
- const struct GNUNET_CRYPTO_AesSessionKey *
- sessionkey,
- const struct GNUNET_CRYPTO_AesInitializationVector
- * iv, void *result)
+ const struct GNUNET_CRYPTO_AesSessionKey *
+ sessionkey,
+ const struct GNUNET_CRYPTO_AesInitializationVector *
+ iv, void *result)
{
gcry_cipher_hd_t handle;
int rc;
if (sessionkey->crc32 !=
- htonl (GNUNET_CRYPTO_crc32_n
- (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
- {
- GNUNET_break (0);
- return -1;
- }
+ htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
GNUNET_assert (0 ==
- gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
- GCRY_CIPHER_MODE_CFB, 0));
+ gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
+ GCRY_CIPHER_MODE_CFB, 0));
rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
rc = gcry_cipher_setiv (handle, iv,
- sizeof (struct
- GNUNET_CRYPTO_AesInitializationVector));
+ sizeof (struct
+ GNUNET_CRYPTO_AesInitializationVector));
GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, len, block, len));
gcry_cipher_close (handle);
*/
ssize_t
GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
- const struct GNUNET_CRYPTO_AesSessionKey *
- sessionkey,
- const struct GNUNET_CRYPTO_AesInitializationVector
- * iv, void *result)
+ const struct GNUNET_CRYPTO_AesSessionKey *
+ sessionkey,
+ const struct GNUNET_CRYPTO_AesInitializationVector *
+ iv, void *result)
{
gcry_cipher_hd_t handle;
int rc;
if (sessionkey->crc32 !=
- htonl (GNUNET_CRYPTO_crc32_n
- (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
- {
- GNUNET_break (0);
- return -1;
- }
+ htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
GNUNET_assert (0 ==
- gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
- GCRY_CIPHER_MODE_CFB, 0));
+ gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
+ GCRY_CIPHER_MODE_CFB, 0));
rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
rc = gcry_cipher_setiv (handle, iv,
- sizeof (struct
- GNUNET_CRYPTO_AesInitializationVector));
+ sizeof (struct
+ GNUNET_CRYPTO_AesInitializationVector));
GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
- GNUNET_assert (0 ==
- gcry_cipher_decrypt (handle, result, size, block, size));
+ GNUNET_assert (0 == gcry_cipher_decrypt (handle, result, size, block, size));
gcry_cipher_close (handle);
return size;
}
*/
void
GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
- const struct GNUNET_CRYPTO_AesSessionKey *skey,
- const void *salt, size_t salt_len, ...)
+ const struct GNUNET_CRYPTO_AesSessionKey *skey,
+ const void *salt, size_t salt_len, ...)
{
va_list argp;
* @param argp pairs of void * & size_t for context chunks, terminated by NULL
*/
void
-GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector
- *iv,
- const struct GNUNET_CRYPTO_AesSessionKey *skey,
- const void *salt, size_t salt_len,
- va_list argp)
+GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv,
+ const struct GNUNET_CRYPTO_AesSessionKey *skey,
+ const void *salt, size_t salt_len, va_list argp)
{
GNUNET_CRYPTO_kdf_v (iv->iv, sizeof (iv->iv), salt, salt_len, skey->key,
- sizeof (skey->key), argp);
+ sizeof (skey->key), argp);
}
/* end of crypto_aes.c */
once = 1;
crc_table[0] = 0;
for (i = 128; i; i >>= 1)
- {
- h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0);
- /* h is now crc_table[i] */
- for (j = 0; j < 256; j += 2 * i)
- crc_table[i + j] = crc_table[j] ^ h;
- }
+ {
+ h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0);
+ /* h is now crc_table[i] */
+ for (j = 0; j < 256; j += 2 * i)
+ crc_table[i + j] = crc_table[j] ^ h;
+ }
}
/*
*/
static void
file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc,
- const GNUNET_HashCode * res)
+ const GNUNET_HashCode * res)
{
fhc->callback (fhc->callback_cls, res);
GNUNET_free (fhc->filename);
if (!GNUNET_DISK_handle_invalid (fhc->fh))
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
gcry_md_close (fhc->md);
- GNUNET_free (fhc); /* also frees fhc->buffer */
+ GNUNET_free (fhc); /* also frees fhc->buffer */
}
if (fhc->fsize - fhc->offset < delta)
delta = fhc->fsize - fhc->offset;
if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename);
- file_hash_finish (fhc, NULL);
- return;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename);
+ file_hash_finish (fhc, NULL);
+ return;
+ }
gcry_md_write (fhc->md, fhc->buffer, delta);
fhc->offset += delta;
if (fhc->offset == fhc->fsize)
- {
- res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
- file_hash_finish (fhc, res);
- return;
- }
+ {
+ res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
+ file_hash_finish (fhc, res);
+ return;
+ }
fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc);
}
*/
struct GNUNET_CRYPTO_FileHashContext *
GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
- const char *filename, size_t blocksize,
- GNUNET_CRYPTO_HashCompletedCallback callback,
- void *callback_cls)
+ const char *filename, size_t blocksize,
+ GNUNET_CRYPTO_HashCompletedCallback callback,
+ void *callback_cls)
{
struct GNUNET_CRYPTO_FileHashContext *fhc;
GNUNET_assert (blocksize > 0);
fhc =
- GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize);
+ GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize);
fhc->callback = callback;
fhc->callback_cls = callback_cls;
fhc->buffer = (unsigned char *) &fhc[1];
fhc->filename = GNUNET_strdup (filename);
if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0))
- {
- GNUNET_break (0);
- GNUNET_free (fhc);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_free (fhc);
+ return NULL;
+ }
fhc->bsize = blocksize;
if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO))
- {
- GNUNET_free (fhc->filename);
- GNUNET_free (fhc);
- return NULL;
- }
+ {
+ GNUNET_free (fhc->filename);
+ GNUNET_free (fhc);
+ return NULL;
+ }
fhc->fh =
- GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (!fhc->fh)
- {
- GNUNET_free (fhc->filename);
- GNUNET_free (fhc);
- return NULL;
- }
+ {
+ GNUNET_free (fhc->filename);
+ GNUNET_free (fhc);
+ return NULL;
+ }
fhc->task =
- GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
+ GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
return fhc;
}
*/
void
GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
- struct GNUNET_CRYPTO_HashAsciiEncoded *result)
+ struct GNUNET_CRYPTO_HashAsciiEncoded *result)
{
/**
* 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters)
rpos = 0;
bits = 0;
while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0))
+ {
+ if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5))
+ {
+ bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */
+ vbit += 8;
+ }
+ if (vbit < 5)
{
- if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5))
- {
- bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */
- vbit += 8;
- }
- if (vbit < 5)
- {
- bits <<= (5 - vbit); /* zero-padding */
- GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */
- vbit = 5;
- }
- GNUNET_assert (wpos <
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
- result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
- vbit -= 5;
+ bits <<= (5 - vbit); /* zero-padding */
+ GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */
+ vbit = 5;
}
+ GNUNET_assert (wpos < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
+ result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
+ vbit -= 5;
+ }
GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
GNUNET_assert (vbit == 0);
result->encoding[wpos] = '\0';
if (strlen (enc) != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1)
return GNUNET_SYSERR;
- vbit = 2; /* padding! */
+ vbit = 2; /* padding! */
wpos = sizeof (GNUNET_HashCode);
rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1;
bits = getValue__ (enc[--rpos]) >> 3;
while (wpos > 0)
+ {
+ GNUNET_assert (rpos > 0);
+ bits = (getValue__ (enc[--rpos]) << vbit) | bits;
+ vbit += 5;
+ if (vbit >= 8)
{
- GNUNET_assert (rpos > 0);
- bits = (getValue__ (enc[--rpos]) << vbit) | bits;
- vbit += 5;
- if (vbit >= 8)
- {
- ((unsigned char *) result)[--wpos] = (unsigned char) bits;
- bits >>= 8;
- vbit -= 8;
- }
+ ((unsigned char *) result)[--wpos] = (unsigned char) bits;
+ bits >>= 8;
+ vbit -= 8;
}
+ }
GNUNET_assert (rpos == 0);
GNUNET_assert (vbit == 0);
return GNUNET_OK;
*/
unsigned int
GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
- const GNUNET_HashCode * b)
+ const GNUNET_HashCode * b)
{
unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16;
unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16;
void
GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
- GNUNET_HashCode * result)
+ GNUNET_HashCode * result)
{
int i;
void
GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
- const GNUNET_HashCode * b,
- GNUNET_HashCode * result)
+ const GNUNET_HashCode * b,
+ GNUNET_HashCode * result)
{
int i;
- for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
- i--)
+ for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
result->bits[i] = b->bits[i] - a->bits[i];
}
void
GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
- const GNUNET_HashCode * delta,
- GNUNET_HashCode * result)
+ const GNUNET_HashCode * delta, GNUNET_HashCode * result)
{
int i;
- for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
- i--)
+ for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
result->bits[i] = delta->bits[i] + a->bits[i];
}
void
GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
- GNUNET_HashCode * result)
+ GNUNET_HashCode * result)
{
int i;
- for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
- i--)
+ for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
result->bits[i] = a->bits[i] ^ b->bits[i];
}
*/
void
GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
- struct GNUNET_CRYPTO_AesSessionKey *skey,
- struct GNUNET_CRYPTO_AesInitializationVector
- *iv)
+ struct GNUNET_CRYPTO_AesSessionKey *skey,
+ struct GNUNET_CRYPTO_AesInitializationVector *iv)
{
GNUNET_assert (sizeof (GNUNET_HashCode) >=
- GNUNET_CRYPTO_AES_KEY_LENGTH +
- sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
+ GNUNET_CRYPTO_AES_KEY_LENGTH +
+ sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH);
skey->crc32 =
- htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH));
+ htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH));
memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH],
- sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
+ sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
}
*/
unsigned int
GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
- const GNUNET_HashCode * second)
+ const GNUNET_HashCode * second)
{
unsigned int i;
for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++)
if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
- GNUNET_CRYPTO_hash_get_bit (second, i))
+ GNUNET_CRYPTO_hash_get_bit (second, i))
return i;
return sizeof (GNUNET_HashCode) * 8;
}
* @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
*/
int
-GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
- const GNUNET_HashCode * h2)
+GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2)
{
unsigned int *i1;
unsigned int *i2;
i1 = (unsigned int *) h1;
i2 = (unsigned int *) h2;
- for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
- i--)
- {
- if (i1[i] > i2[i])
- return 1;
- if (i1[i] < i2[i])
- return -1;
- }
+ for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
+ {
+ if (i1[i] > i2[i])
+ return 1;
+ if (i1[i] < i2[i])
+ return -1;
+ }
return 0;
}
*/
int
GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
- const GNUNET_HashCode * h2,
- const GNUNET_HashCode * target)
+ const GNUNET_HashCode * h2,
+ const GNUNET_HashCode * target)
{
int i;
unsigned int d1;
unsigned int d2;
for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--)
- {
- d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i];
- d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i];
- if (d1 > d2)
- return 1;
- else if (d1 < d2)
- return -1;
- }
+ {
+ d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i];
+ d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i];
+ if (d1 > d2)
+ return 1;
+ else if (d1 < d2)
+ return -1;
+ }
return 0;
}
*/
void
GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
- const struct GNUNET_CRYPTO_AesSessionKey *rkey,
- const void *salt, size_t salt_len, ...)
+ const struct GNUNET_CRYPTO_AesSessionKey *rkey,
+ const void *salt, size_t salt_len, ...)
{
va_list argp;
*/
void
GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
- const struct GNUNET_CRYPTO_AesSessionKey
- *rkey, const void *salt, size_t salt_len,
- va_list argp)
+ const struct GNUNET_CRYPTO_AesSessionKey *rkey,
+ const void *salt, size_t salt_len,
+ va_list argp)
{
GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), salt, salt_len, rkey->key,
- sizeof (rkey->key), argp);
+ sizeof (rkey->key), argp);
}
*/
void
GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
- const void *plaintext, size_t plaintext_len,
- GNUNET_HashCode * hmac)
+ const void *plaintext, size_t plaintext_len,
+ GNUNET_HashCode * hmac)
{
gcry_md_hd_t md;
const unsigned char *mc;
GNUNET_assert (GPG_ERR_NO_ERROR ==
- gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
+ gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
gcry_md_setkey (md, key->key, sizeof (key->key));
gcry_md_write (md, plaintext, plaintext_len);
mc = gcry_md_read (md, GCRY_MD_SHA512);
*/
static const void *
doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf,
- size_t buf_len)
+ size_t buf_len)
{
gcry_md_setkey (mac, key, key_len);
gcry_md_write (mac, buf, buf_len);
*/
static int
getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm,
- size_t skm_len, void *prk)
+ size_t skm_len, void *prk)
{
const void *ret;
printf ("\n%s: ", src);
for (i = 0; i < l; i++)
- {
- printf ("%2x", (int) ((const unsigned char *) p)[i]);
- }
+ {
+ printf ("%2x", (int) ((const unsigned char *) p)[i]);
+ }
printf ("\n");
}
#endif
* @return GNUNET_YES on success
*/
int
-GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo,
- int prf_algo, const void *xts, size_t xts_len,
- const void *skm, size_t skm_len, va_list argp)
+GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
+ const void *xts, size_t xts_len, const void *skm,
+ size_t skm_len, va_list argp)
{
const void *hc;
unsigned long i, t, d;
return GNUNET_SYSERR;
if (gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
- {
- gcry_md_close (xtr);
- return GNUNET_SYSERR;
- }
+ {
+ gcry_md_close (xtr);
+ return GNUNET_SYSERR;
+ }
va_copy (args, argp);
ctx_len = 0;
while (NULL != va_arg (args, void *))
- ctx_len += va_arg (args, size_t);
+ ctx_len += va_arg (args, size_t);
va_end (args);
dst = plain + k;
va_copy (args, argp);
while ((ctx = va_arg (args, void *)))
- {
- size_t len;
+ {
+ size_t len;
- len = va_arg (args, size_t);
- memcpy (dst, ctx, len);
- dst += len;
- }
+ len = va_arg (args, size_t);
+ memcpy (dst, ctx, len);
+ dst += len;
+ }
va_end (args);
if (t > 0)
- {
- memset (plain + k + ctx_len, 1, 1);
+ {
+ memset (plain + k + ctx_len, 1, 1);
#if DEBUG_HKDF
- dump ("K(1)", plain, plain_len);
+ dump ("K(1)", plain, plain_len);
#endif
- hc = doHMAC (prf, prk, xtr_len, &plain[k], ctx_len + 1);
- if (hc == NULL)
- goto hkdf_error;
- memcpy (result, hc, k);
- result += k;
- }
+ hc = doHMAC (prf, prk, xtr_len, &plain[k], ctx_len + 1);
+ if (hc == NULL)
+ goto hkdf_error;
+ memcpy (result, hc, k);
+ result += k;
+ }
/* K(i+1) */
for (i = 1; i < t; i++)
- {
- memcpy (plain, result - k, k);
- memset (plain + k + ctx_len, i + 1, 1);
- gcry_md_reset (prf);
+ {
+ memcpy (plain, result - k, k);
+ memset (plain + k + ctx_len, i + 1, 1);
+ gcry_md_reset (prf);
#if DEBUG_HKDF
- dump ("K(i+1)", plain, plain_len);
+ dump ("K(i+1)", plain, plain_len);
#endif
- hc = doHMAC (prf, prk, xtr_len, plain, plain_len);
- if (hc == NULL)
- goto hkdf_error;
- memcpy (result, hc, k);
- result += k;
- }
+ hc = doHMAC (prf, prk, xtr_len, plain, plain_len);
+ if (hc == NULL)
+ goto hkdf_error;
+ memcpy (result, hc, k);
+ result += k;
+ }
/* K(t):d */
if (d > 0)
+ {
+ if (t > 0)
{
- if (t > 0)
- {
- memcpy (plain, result - k, k);
- i++;
- }
- memset (plain + k + ctx_len, i, 1);
- gcry_md_reset (prf);
+ memcpy (plain, result - k, k);
+ i++;
+ }
+ memset (plain + k + ctx_len, i, 1);
+ gcry_md_reset (prf);
#if DEBUG_HKDF
- dump ("K(t):d", plain, plain_len);
+ dump ("K(t):d", plain, plain_len);
#endif
- if (t > 0)
- hc = doHMAC (prf, prk, xtr_len, plain, plain_len);
- else
- hc = doHMAC (prf, prk, xtr_len, plain + k, plain_len - k);
- if (hc == NULL)
- goto hkdf_error;
- memcpy (result, hc, d);
- }
+ if (t > 0)
+ hc = doHMAC (prf, prk, xtr_len, plain, plain_len);
+ else
+ hc = doHMAC (prf, prk, xtr_len, plain + k, plain_len - k);
+ if (hc == NULL)
+ goto hkdf_error;
+ memcpy (result, hc, d);
+ }
#if DEBUG_HKDF
dump ("result", result - k, out_len);
#endif
*/
int
GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
- const void *xts, size_t xts_len, const void *skm,
- size_t skm_len, ...)
+ const void *xts, size_t xts_len, const void *skm,
+ size_t skm_len, ...)
{
va_list argp;
int ret;
va_start (argp, skm_len);
ret =
- GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len,
- skm, skm_len, argp);
+ GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len,
+ skm, skm_len, argp);
va_end (argp);
return ret;
*/
int
GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
- size_t xts_len, const void *skm, size_t skm_len,
- va_list argp)
+ size_t xts_len, const void *skm, size_t skm_len,
+ va_list argp)
{
/*
* "Finally, we point out to a particularly advantageous instantiation using
* http://eprint.iacr.org/2010/264
*/
- return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512,
- GCRY_MD_SHA256, xts, xts_len, skm, skm_len,
- argp);
+ return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512, GCRY_MD_SHA256,
+ xts, xts_len, skm, skm_len, argp);
}
/**
*/
int
GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
- size_t xts_len, const void *skm, size_t skm_len, ...)
+ size_t xts_len, const void *skm, size_t skm_len, ...)
{
va_list argp;
int ret;
va_start (argp, skm_len);
- ret =
- GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp);
+ ret = GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp);
va_end (argp);
return ret;
typedef struct
{
- gcry_mpi_t n; /* public modulus */
- gcry_mpi_t e; /* public exponent */
- gcry_mpi_t d; /* exponent */
- gcry_mpi_t p; /* prime p. */
- gcry_mpi_t q; /* prime q. */
- gcry_mpi_t u; /* inverse of p mod q. */
+ gcry_mpi_t n; /* public modulus */
+ gcry_mpi_t e; /* public exponent */
+ gcry_mpi_t d; /* exponent */
+ gcry_mpi_t p; /* prime p. */
+ gcry_mpi_t q; /* prime q. */
+ gcry_mpi_t u; /* inverse of p mod q. */
} KBlock_secret_key;
/**
tmp = *rnd;
for (i = 0; i < cnt; i++)
- {
- int j;
+ {
+ int j;
- if (i > 0)
- GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp);
- for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); j++)
- {
+ if (i > 0)
+ GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp);
+ for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); j++)
+ {
#if HAVE_GCRY_MPI_LSHIFT
- gcry_mpi_lshift (n, n, sizeof (uint32_t) * 8);
+ gcry_mpi_lshift (n, n, sizeof (uint32_t) * 8);
#else
- gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4));
- gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4));
+ gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4));
+ gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4));
#endif
- gcry_mpi_add_ui (n, n, ntohl (((uint32_t *) & tmp)[j]));
- }
- hc = tmp;
+ gcry_mpi_add_ui (n, n, ntohl (((uint32_t *) & tmp)[j]));
}
+ hc = tmp;
+ }
GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), rnd);
i = gcry_mpi_get_nbits (n);
while (i > nbits)
cnt = gcry_mpi_get_nbits (n);
for (idx = 0; idx < cnt; idx++)
- {
- if (gcry_mpi_test_bit (n, idx) == 0)
- return idx;
- }
+ {
+ if (gcry_mpi_test_bit (n, idx) == 0)
+ return idx;
+ }
return ULONG_MAX;
}
mpz_tdiv_q_2exp (q, q, k);
for (i = 0; i < steps; i++)
+ {
+ if (!i)
{
- if (!i)
- {
- gcry_mpi_set_ui (x, 2);
- }
- else
- {
- mpz_randomize (x, nbits - 1, hc);
- GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0);
- GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0);
- }
- gcry_mpi_powm (y, x, q, n);
- if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1))
- {
- for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++)
- {
- gcry_mpi_powm (y, y, a2, n);
- if (!gcry_mpi_cmp_ui (y, 1))
- goto leave; /* Not a prime. */
- }
- if (gcry_mpi_cmp (y, nminus1))
- goto leave; /* Not a prime. */
- }
+ gcry_mpi_set_ui (x, 2);
}
- rc = 1; /* May be a prime. */
+ else
+ {
+ mpz_randomize (x, nbits - 1, hc);
+ GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0);
+ GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0);
+ }
+ gcry_mpi_powm (y, x, q, n);
+ if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1))
+ {
+ for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++)
+ {
+ gcry_mpi_powm (y, y, a2, n);
+ if (!gcry_mpi_cmp_ui (y, 1))
+ goto leave; /* Not a prime. */
+ }
+ if (gcry_mpi_cmp (y, nminus1))
+ goto leave; /* Not a prime. */
+ }
+ }
+ rc = 1; /* May be a prime. */
leave:
gcry_mpi_release (x);
adjust (unsigned char *buf, size_t size, size_t target)
{
if (size < target)
- {
- memmove (&buf[target - size], buf, size);
- memset (buf, 0, target - size);
- }
+ {
+ memmove (&buf[target - size], buf, size);
+ memset (buf, 0, target - size);
+ }
}
tmp = gcry_mpi_new (0);
sp = gcry_mpi_new (0);
while (1)
+ {
+ /* generate a random number */
+ mpz_randomize (prime, nbits, hc);
+ /* Set high order bit to 1, set low order bit to 1. If we are
+ * generating a secret prime we are most probably doing that
+ * for RSA, to make sure that the modulus does have the
+ * requested key size we set the 2 high order bits. */
+ gcry_mpi_set_bit (prime, nbits - 1);
+ gcry_mpi_set_bit (prime, nbits - 2);
+ gcry_mpi_set_bit (prime, 0);
+
+ /* Calculate all remainders. */
+ for (i = 0; i < no_of_small_prime_numbers; i++)
{
- /* generate a random number */
- mpz_randomize (prime, nbits, hc);
- /* Set high order bit to 1, set low order bit to 1. If we are
- * generating a secret prime we are most probably doing that
- * for RSA, to make sure that the modulus does have the
- * requested key size we set the 2 high order bits. */
- gcry_mpi_set_bit (prime, nbits - 1);
- gcry_mpi_set_bit (prime, nbits - 2);
- gcry_mpi_set_bit (prime, 0);
-
- /* Calculate all remainders. */
+ size_t written;
+
+ gcry_mpi_set_ui (sp, small_prime_numbers[i]);
+ gcry_mpi_div (NULL, tmp, prime, sp, -1);
+ mods[i] = 0;
+ written = sizeof (unsigned int);
+ GNUNET_assert (0 ==
+ gcry_mpi_print (GCRYMPI_FMT_USG,
+ (unsigned char *) &mods[i], written,
+ &written, tmp));
+ adjust ((unsigned char *) &mods[i], written, sizeof (unsigned int));
+ mods[i] = ntohl (mods[i]);
+ }
+ /* Now try some primes starting with prime. */
+ for (step = 0; step < 20000; step += 2)
+ {
+ /* Check against all the small primes we have in mods. */
for (i = 0; i < no_of_small_prime_numbers; i++)
- {
- size_t written;
-
- gcry_mpi_set_ui (sp, small_prime_numbers[i]);
- gcry_mpi_div (NULL, tmp, prime, sp, -1);
- mods[i] = 0;
- written = sizeof (unsigned int);
- GNUNET_assert (0 ==
- gcry_mpi_print (GCRYMPI_FMT_USG,
- (unsigned char *) &mods[i], written,
- &written, tmp));
- adjust ((unsigned char *) &mods[i], written, sizeof (unsigned int));
- mods[i] = ntohl (mods[i]);
- }
- /* Now try some primes starting with prime. */
- for (step = 0; step < 20000; step += 2)
- {
- /* Check against all the small primes we have in mods. */
- for (i = 0; i < no_of_small_prime_numbers; i++)
- {
- uint16_t x = small_prime_numbers[i];
-
- while (mods[i] + step >= x)
- mods[i] -= x;
- if (!(mods[i] + step))
- break;
- }
- if (i < no_of_small_prime_numbers)
- continue; /* Found a multiple of an already known prime. */
-
- gcry_mpi_add_ui (*ptest, prime, step);
- if (!gcry_mpi_test_bit (*ptest, nbits - 2))
- break;
-
- /* Do a fast Fermat test now. */
- gcry_mpi_sub_ui (pminus1, *ptest, 1);
- gcry_mpi_powm (result, val_2, pminus1, *ptest);
- if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc)))
- {
- /* Got it. */
- gcry_mpi_release (sp);
- gcry_mpi_release (tmp);
- gcry_mpi_release (val_2);
- gcry_mpi_release (val_3);
- gcry_mpi_release (result);
- gcry_mpi_release (pminus1);
- gcry_mpi_release (prime);
- return;
- }
- }
+ {
+ uint16_t x = small_prime_numbers[i];
+
+ while (mods[i] + step >= x)
+ mods[i] -= x;
+ if (!(mods[i] + step))
+ break;
+ }
+ if (i < no_of_small_prime_numbers)
+ continue; /* Found a multiple of an already known prime. */
+
+ gcry_mpi_add_ui (*ptest, prime, step);
+ if (!gcry_mpi_test_bit (*ptest, nbits - 2))
+ break;
+
+ /* Do a fast Fermat test now. */
+ gcry_mpi_sub_ui (pminus1, *ptest, 1);
+ gcry_mpi_powm (result, val_2, pminus1, *ptest);
+ if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc)))
+ {
+ /* Got it. */
+ gcry_mpi_release (sp);
+ gcry_mpi_release (tmp);
+ gcry_mpi_release (val_2);
+ gcry_mpi_release (val_3);
+ gcry_mpi_release (result);
+ gcry_mpi_release (pminus1);
+ gcry_mpi_release (prime);
+ return;
+ }
}
+ }
}
/**
* @param hc the HC to use for PRNG (modified!)
*/
static void
-generate_kblock_key (KBlock_secret_key * sk, unsigned int nbits,
- GNUNET_HashCode * hc)
+generate_kblock_key (KBlock_secret_key *sk, unsigned int nbits,
+ GNUNET_HashCode * hc)
{
gcry_mpi_t t1, t2;
- gcry_mpi_t phi; /* helper: (p-1)(q-1) */
+ gcry_mpi_t phi; /* helper: (p-1)(q-1) */
gcry_mpi_t g;
gcry_mpi_t f;
f = gcry_mpi_new (0);
do
+ {
+ do
{
- do
- {
- gcry_mpi_release (sk->p);
- gcry_mpi_release (sk->q);
- gen_prime (&sk->p, nbits / 2, hc);
- gen_prime (&sk->q, nbits / 2, hc);
-
- if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */
- gcry_mpi_swap (sk->p, sk->q);
- /* calculate the modulus */
- gcry_mpi_mul (sk->n, sk->p, sk->q);
- }
- while (gcry_mpi_get_nbits (sk->n) != nbits);
-
- /* calculate Euler totient: phi = (p-1)(q-1) */
- gcry_mpi_sub_ui (t1, sk->p, 1);
- gcry_mpi_sub_ui (t2, sk->q, 1);
- gcry_mpi_mul (phi, t1, t2);
- gcry_mpi_gcd (g, t1, t2);
- gcry_mpi_div (f, NULL, phi, g, 0);
- while (0 == gcry_mpi_gcd (t1, sk->e, phi))
- { /* (while gcd is not 1) */
- gcry_mpi_add_ui (sk->e, sk->e, 2);
- }
-
- /* calculate the secret key d = e^1 mod phi */
+ gcry_mpi_release (sk->p);
+ gcry_mpi_release (sk->q);
+ gen_prime (&sk->p, nbits / 2, hc);
+ gen_prime (&sk->q, nbits / 2, hc);
+
+ if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */
+ gcry_mpi_swap (sk->p, sk->q);
+ /* calculate the modulus */
+ gcry_mpi_mul (sk->n, sk->p, sk->q);
+ }
+ while (gcry_mpi_get_nbits (sk->n) != nbits);
+
+ /* calculate Euler totient: phi = (p-1)(q-1) */
+ gcry_mpi_sub_ui (t1, sk->p, 1);
+ gcry_mpi_sub_ui (t2, sk->q, 1);
+ gcry_mpi_mul (phi, t1, t2);
+ gcry_mpi_gcd (g, t1, t2);
+ gcry_mpi_div (f, NULL, phi, g, 0);
+ while (0 == gcry_mpi_gcd (t1, sk->e, phi))
+ { /* (while gcd is not 1) */
+ gcry_mpi_add_ui (sk->e, sk->e, 2);
}
+
+ /* calculate the secret key d = e^1 mod phi */
+ }
while ((0 == gcry_mpi_invm (sk->d, sk->e, f)) ||
- (0 == gcry_mpi_invm (sk->u, sk->p, sk->q)));
+ (0 == gcry_mpi_invm (sk->u, sk->p, sk->q)));
gcry_mpi_release (t1);
gcry_mpi_release (t2);
* Total size of the structure, in bytes, in big-endian!
*/
uint16_t len GNUNET_PACKED;
- uint16_t sizen GNUNET_PACKED; /* in big-endian! */
- uint16_t sizee GNUNET_PACKED; /* in big-endian! */
- uint16_t sized GNUNET_PACKED; /* in big-endian! */
- uint16_t sizep GNUNET_PACKED; /* in big-endian! */
- uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
- uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
- uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizen GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizee GNUNET_PACKED; /* in big-endian! */
+ uint16_t sized GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizep GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
/* followed by the actual values */
};
size_t size;
hx = *hc;
- generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits
- * -- we simply cannot afford 2048 bits
- * even on modern hardware, and especially
- * not since clearly a dictionary attack
- * will still be much cheaper
- * than breaking a 1024 bit RSA key.
- * If an adversary can spend the time to
- * break a 1024 bit RSA key just to forge
- * a signature -- SO BE IT. [ CG, 6/2005 ] */
- &hx);
+ generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits
+ * -- we simply cannot afford 2048 bits
+ * even on modern hardware, and especially
+ * not since clearly a dictionary attack
+ * will still be much cheaper
+ * than breaking a 1024 bit RSA key.
+ * If an adversary can spend the time to
+ * break a 1024 bit RSA key just to forge
+ * a signature -- SO BE IT. [ CG, 6/2005 ] */
+ &hx);
pkv[0] = &sk.n;
pkv[1] = &sk.e;
pkv[2] = &sk.d;
pkv[5] = &sk.u;
size = sizeof (struct KskRsaPrivateKeyBinaryEncoded);
for (i = 0; i < 6; i++)
- {
- gcry_mpi_aprint (GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]);
- size += sizes[i];
- }
+ {
+ gcry_mpi_aprint (GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]);
+ size += sizes[i];
+ }
GNUNET_assert (size < 65536);
retval = GNUNET_malloc (size);
retval->len = htons (size);
retval->sizedmq1 = htons (0);
memcpy (&((char *) &retval[1])[i], pbu[5], sizes[5]);
for (i = 0; i < 6; i++)
- {
- gcry_mpi_release (*pkv[i]);
- free (pbu[i]);
- }
+ {
+ gcry_mpi_release (*pkv[i]);
+ free (pbu[i]);
+ }
return retval;
}
pos = 0;
size = ntohs (encoding->sizen);
rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos], size,
- &size);
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
pos += ntohs (encoding->sizen);
if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ return NULL;
+ }
size = ntohs (encoding->sizee);
rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos], size,
- &size);
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
pos += ntohs (encoding->sizee);
if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ return NULL;
+ }
size = ntohs (encoding->sized);
rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos], size,
- &size);
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
pos += ntohs (encoding->sized);
if (rc)
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ gcry_mpi_release (e);
+ return NULL;
+ }
+ /* swap p and q! */
+ size = ntohs (encoding->sizep);
+ if (size > 0)
+ {
+ rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
+ pos += ntohs (encoding->sizep);
+ if (rc)
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
gcry_mpi_release (n);
gcry_mpi_release (e);
+ gcry_mpi_release (d);
return NULL;
}
- /* swap p and q! */
- size = ntohs (encoding->sizep);
- if (size > 0)
- {
- rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos],
- size, &size);
- pos += ntohs (encoding->sizep);
- if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- gcry_mpi_release (e);
- gcry_mpi_release (d);
- return NULL;
- }
- }
+ }
else
q = NULL;
size = ntohs (encoding->sizeq);
if (size > 0)
+ {
+ rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
+ pos += ntohs (encoding->sizeq);
+ if (rc)
{
- rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos],
- size, &size);
- pos += ntohs (encoding->sizeq);
- if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- gcry_mpi_release (e);
- gcry_mpi_release (d);
- if (q != NULL)
- gcry_mpi_release (q);
- return NULL;
- }
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ gcry_mpi_release (e);
+ gcry_mpi_release (d);
+ if (q != NULL)
+ gcry_mpi_release (q);
+ return NULL;
}
+ }
else
p = NULL;
pos += ntohs (encoding->sizedmp1);
pos += ntohs (encoding->sizedmq1);
size =
- ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) -
- pos;
+ ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) -
+ pos;
if (size > 0)
+ {
+ rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
+ if (rc)
{
- rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos],
- size, &size);
- if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- gcry_mpi_release (e);
- gcry_mpi_release (d);
- if (p != NULL)
- gcry_mpi_release (p);
- if (q != NULL)
- gcry_mpi_release (q);
- return NULL;
- }
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ gcry_mpi_release (e);
+ gcry_mpi_release (d);
+ if (p != NULL)
+ gcry_mpi_release (p);
+ if (q != NULL)
+ gcry_mpi_release (q);
+ return NULL;
}
+ }
else
u = NULL;
if ((p != NULL) && (q != NULL) && (u != NULL))
+ {
+ rc = gcry_sexp_build (&res, &size, /* erroff */
+ "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))",
+ n, e, d, p, q, u);
+ }
+ else
+ {
+ if ((p != NULL) && (q != NULL))
{
- rc = gcry_sexp_build (&res, &size, /* erroff */
- "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))",
- n, e, d, p, q, u);
+ rc = gcry_sexp_build (&res, &size, /* erroff */
+ "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
+ n, e, d, p, q);
}
- else
+ else
{
- if ((p != NULL) && (q != NULL))
- {
- rc = gcry_sexp_build (&res, &size, /* erroff */
- "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
- n, e, d, p, q);
- }
- else
- {
- rc = gcry_sexp_build (&res, &size, /* erroff */
- "(private-key(rsa(n %m)(e %m)(d %m)))", n, e,
- d);
- }
+ rc = gcry_sexp_build (&res, &size, /* erroff */
+ "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d);
}
+ }
gcry_mpi_release (n);
gcry_mpi_release (e);
gcry_mpi_release (d);
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
#if EXTRA_CHECKS
if (gcry_pk_testkey (res))
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
+ return NULL;
+ }
#endif
ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
ret->sexp = res;
unsigned int i;
for (i = 0; i < cacheSize; i++)
+ {
+ if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode)))
{
- if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode)))
- {
- ret = ksk_decode_key (cache[i]->pke);
- return ret;
- }
+ ret = ksk_decode_key (cache[i]->pke);
+ return ret;
}
+ }
line = GNUNET_malloc (sizeof (struct KBlockKeyCacheLine));
line->hc = *hc;
unsigned int i;
for (i = 0; i < cacheSize; i++)
- {
- GNUNET_free (cache[i]->pke);
- GNUNET_free (cache[i]);
- }
+ {
+ GNUNET_free (cache[i]->pke);
+ GNUNET_free (cache[i]);
+ }
GNUNET_array_grow (cache, cacheSize, 0);
}
GNUNET_assert (i > 0);
switch (mode)
- {
- case GNUNET_CRYPTO_QUALITY_STRONG:
- /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */
+ {
+ case GNUNET_CRYPTO_QUALITY_STRONG:
+ /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */
#ifdef gcry_fast_random_poll
- if ((invokeCount++ % 256) == 0)
- gcry_fast_random_poll ();
+ if ((invokeCount++ % 256) == 0)
+ gcry_fast_random_poll ();
#endif
- ul = UINT32_MAX - (UINT32_MAX % i);
- do
- {
- gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t),
- GCRY_STRONG_RANDOM);
- }
- while (ret >= ul);
- return ret % i;
- case GNUNET_CRYPTO_QUALITY_NONCE:
- ul = UINT32_MAX - (UINT32_MAX % i);
- do
- {
- gcry_create_nonce (&ret, sizeof (ret));
- }
- while (ret >= ul);
- return ret % i;
- case GNUNET_CRYPTO_QUALITY_WEAK:
- ret = i * weak_random ();
- if (ret >= i)
- ret = i - 1;
- return ret;
- default:
- GNUNET_assert (0);
+ ul = UINT32_MAX - (UINT32_MAX % i);
+ do
+ {
+ gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t),
+ GCRY_STRONG_RANDOM);
+ }
+ while (ret >= ul);
+ return ret % i;
+ case GNUNET_CRYPTO_QUALITY_NONCE:
+ ul = UINT32_MAX - (UINT32_MAX % i);
+ do
+ {
+ gcry_create_nonce (&ret, sizeof (ret));
}
+ while (ret >= ul);
+ return ret % i;
+ case GNUNET_CRYPTO_QUALITY_WEAK:
+ ret = i * weak_random ();
+ if (ret >= i)
+ ret = i - 1;
+ return ret;
+ default:
+ GNUNET_assert (0);
+ }
return 0;
}
for (i = 0; i < n; i++)
ret[i] = i;
for (i = n - 1; i > 0; i--)
- {
- x = GNUNET_CRYPTO_random_u32 (mode, i + 1);
- tmp = ret[x];
- ret[x] = ret[i];
- ret[i] = tmp;
- }
+ {
+ x = GNUNET_CRYPTO_random_u32 (mode, i + 1);
+ tmp = ret[x];
+ ret[x] = ret[i];
+ ret[i] = tmp;
+ }
return ret;
}
GNUNET_assert (max > 0);
switch (mode)
+ {
+ case GNUNET_CRYPTO_QUALITY_STRONG:
+ ul = UINT64_MAX - (UINT64_MAX % max);
+ do
{
- case GNUNET_CRYPTO_QUALITY_STRONG:
- ul = UINT64_MAX - (UINT64_MAX % max);
- do
- {
- gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t),
- GCRY_STRONG_RANDOM);
- }
- while (ret >= ul);
- return ret % max;
- case GNUNET_CRYPTO_QUALITY_NONCE:
- ul = UINT64_MAX - (UINT64_MAX % max);
- do
- {
- gcry_create_nonce (&ret, sizeof (ret));
- }
- while (ret >= ul);
-
- return ret % max;
- case GNUNET_CRYPTO_QUALITY_WEAK:
- ret = max * weak_random ();
- if (ret >= max)
- ret = max - 1;
- return ret;
- default:
- GNUNET_assert (0);
+ gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t),
+ GCRY_STRONG_RANDOM);
}
+ while (ret >= ul);
+ return ret % max;
+ case GNUNET_CRYPTO_QUALITY_NONCE:
+ ul = UINT64_MAX - (UINT64_MAX % max);
+ do
+ {
+ gcry_create_nonce (&ret, sizeof (ret));
+ }
+ while (ret >= ul);
+
+ return ret % max;
+ case GNUNET_CRYPTO_QUALITY_WEAK:
+ ret = max * weak_random ();
+ if (ret >= max)
+ ret = max - 1;
+ return ret;
+ default:
+ GNUNET_assert (0);
+ }
return 0;
}
*/
static void
entropy_generator (void *cls, const char *what, int printchar, int current,
- int total)
+ int total)
{
unsigned long code;
enum GNUNET_OS_ProcessStatusType type;
if (0 != strcmp (what, "need_entropy"))
return;
if (current == total)
+ {
+ if (genproc != NULL)
{
- if (genproc != NULL)
- {
- if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill");
- GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
- GNUNET_OS_process_close (genproc);
- genproc = NULL;
- }
- return;
- }
- if (genproc != NULL)
- {
- ret = GNUNET_OS_process_status (genproc, &type, &code);
- if (ret == GNUNET_NO)
- return; /* still running */
- if (ret == GNUNET_SYSERR)
- {
- GNUNET_break (0);
- return;
- }
if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill");
GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
GNUNET_OS_process_close (genproc);
genproc = NULL;
}
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Starting `%s' process to generate entropy\n"), "find");
+ return;
+ }
+ if (genproc != NULL)
+ {
+ ret = GNUNET_OS_process_status (genproc, &type, &code);
+ if (ret == GNUNET_NO)
+ return; /* still running */
+ if (ret == GNUNET_SYSERR)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill");
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
+ GNUNET_OS_process_close (genproc);
+ genproc = NULL;
+ }
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Starting `%s' process to generate entropy\n"),
+ "find");
genproc =
- GNUNET_OS_start_process (NULL, NULL, "sh", "sh", "-c",
- "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null",
- NULL);
+ GNUNET_OS_start_process (NULL, NULL, "sh", "sh", "-c",
+ "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null",
+ NULL);
}
killfind ()
{
if (genproc != NULL)
- {
- GNUNET_OS_process_kill (genproc, SIGKILL);
- GNUNET_OS_process_close (genproc);
- genproc = NULL;
- }
+ {
+ GNUNET_OS_process_kill (genproc, SIGKILL);
+ GNUNET_OS_process_close (genproc);
+ genproc = NULL;
+ }
}
{
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
if (!gcry_check_version (GCRYPT_VERSION))
- {
- fprintf (stderr,
- _
- ("libgcrypt has not the expected version (version %s is required).\n"),
- GCRYPT_VERSION);
- abort ();
- }
+ {
+ fprintf (stderr,
+ _
+ ("libgcrypt has not the expected version (version %s is required).\n"),
+ GCRYPT_VERSION);
+ abort ();
+ }
#ifdef gcry_fast_random_poll
gcry_fast_random_poll ();
#endif
gcry_set_progress_handler (&entropy_generator, NULL);
atexit (&killfind);
SRANDOM (time (NULL) ^
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- UINT32_MAX));
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
}
* Total size of the structure, in bytes, in big-endian!
*/
uint16_t len GNUNET_PACKED;
- uint16_t sizen GNUNET_PACKED; /* in big-endian! */
- uint16_t sizee GNUNET_PACKED; /* in big-endian! */
- uint16_t sized GNUNET_PACKED; /* in big-endian! */
- uint16_t sizep GNUNET_PACKED; /* in big-endian! */
- uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
- uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
- uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizen GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizee GNUNET_PACKED; /* in big-endian! */
+ uint16_t sized GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizep GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
+ uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
/* followed by the actual values */
};
adjust (unsigned char *buf, size_t size, size_t target)
{
if (size < target)
- {
- memmove (&buf[target - size], buf, size);
- memset (buf, 0, target - size);
- }
+ {
+ memmove (&buf[target - size], buf, size);
+ memset (buf, 0, target - size);
+ }
}
/**
gcry_sexp_t s_keyparam;
GNUNET_assert (0 ==
- gcry_sexp_build (&s_keyparam, NULL,
- "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))",
- HOSTKEY_LEN));
+ gcry_sexp_build (&s_keyparam, NULL,
+ "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))",
+ HOSTKEY_LEN));
GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam));
gcry_sexp_release (s_keyparam);
#if EXTRA_CHECKS
static int
key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname,
- const char *elems)
+ const char *elems)
{
gcry_sexp_t list, l2;
const char *s;
list = gcry_sexp_find_token (sexp, topname, 0);
if (!list)
- {
- return 1;
- }
+ {
+ return 1;
+ }
l2 = gcry_sexp_cadr (list);
gcry_sexp_release (list);
list = l2;
if (!list)
- {
- return 2;
- }
+ {
+ return 2;
+ }
idx = 0;
for (s = elems; *s; s++, idx++)
+ {
+ l2 = gcry_sexp_find_token (list, s, 1);
+ if (!l2)
{
- l2 = gcry_sexp_find_token (list, s, 1);
- if (!l2)
- {
- for (i = 0; i < idx; i++)
- {
- gcry_free (array[i]);
- array[i] = NULL;
- }
- gcry_sexp_release (list);
- return 3; /* required parameter not found */
- }
- array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
- gcry_sexp_release (l2);
- if (!array[idx])
- {
- for (i = 0; i < idx; i++)
- {
- gcry_free (array[i]);
- array[i] = NULL;
- }
- gcry_sexp_release (list);
- return 4; /* required parameter is invalid */
- }
+ for (i = 0; i < idx; i++)
+ {
+ gcry_free (array[i]);
+ array[i] = NULL;
+ }
+ gcry_sexp_release (list);
+ return 3; /* required parameter not found */
}
+ array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
+ gcry_sexp_release (l2);
+ if (!array[idx])
+ {
+ for (i = 0; i < idx; i++)
+ {
+ gcry_free (array[i]);
+ array[i] = NULL;
+ }
+ gcry_sexp_release (list);
+ return 4; /* required parameter is invalid */
+ }
+ }
gcry_sexp_release (list);
return 0;
}
*/
void
GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
- *priv,
- struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
- *pub)
+ *priv,
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *pub)
{
gcry_mpi_t skey[2];
size_t size;
rc = key_from_sexp (skey, priv->sexp, "rsa", "ne");
GNUNET_assert (0 == rc);
pub->len =
- htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) -
- sizeof (pub->padding));
+ htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) -
+ sizeof (pub->padding));
pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
pub->padding = 0;
size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
GNUNET_assert (0 ==
- gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size,
- skey[0]));
+ gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size,
+ skey[0]));
adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
- size =
- GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
+ size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
GNUNET_assert (0 ==
- gcry_mpi_print (GCRYMPI_FMT_USG,
- &pub->key
- [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH],
- size, &size, skey[1]));
+ gcry_mpi_print (GCRYMPI_FMT_USG,
+ &pub->key
+ [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size,
+ &size, skey[1]));
adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size,
- GNUNET_CRYPTO_RSA_KEY_LENGTH -
- GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
+ GNUNET_CRYPTO_RSA_KEY_LENGTH -
+ GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
gcry_mpi_release (skey[0]);
gcry_mpi_release (skey[1]);
}
*/
static struct GNUNET_CRYPTO_RsaPrivateKey *
public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
- *publicKey)
+ *publicKey)
{
struct GNUNET_CRYPTO_RsaPrivateKey *ret;
gcry_sexp_t result;
(ntohs (publicKey->len) !=
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) -
sizeof (publicKey->padding)))
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, &publicKey->key[0], size, &size);
if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- return NULL;
- }
- size =
- GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
- rc =
- gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
- &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH],
- size, &size);
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ return NULL;
+ }
+ size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
+ rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
+ &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH],
+ size, &size);
if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ return NULL;
+ }
rc = gcry_sexp_build (&result, &erroff, "(public-key(rsa(n %m)(e %m)))", n,
- e);
+ e);
gcry_mpi_release (n);
gcry_mpi_release (e);
if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */
+ return NULL;
+ }
ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
ret->sexp = result;
return ret;
#if EXTRA_CHECKS
if (gcry_pk_testkey (hostkey->sexp))
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
#endif
memset (pkv, 0, sizeof (gcry_mpi_t) * 6);
GNUNET_assert (0 == rc);
size = sizeof (struct RsaPrivateKeyBinaryEncoded);
for (i = 0; i < 6; i++)
+ {
+ if (pkv[i] != NULL)
{
- if (pkv[i] != NULL)
- {
- GNUNET_assert (0 ==
- gcry_mpi_aprint (GCRYMPI_FMT_USG,
- (unsigned char **) &pbu[i],
- &sizes[i], pkv[i]));
- size += sizes[i];
- }
- else
- {
- pbu[i] = NULL;
- sizes[i] = 0;
- }
+ GNUNET_assert (0 ==
+ gcry_mpi_aprint (GCRYMPI_FMT_USG,
+ (unsigned char **) &pbu[i], &sizes[i],
+ pkv[i]));
+ size += sizes[i];
}
+ else
+ {
+ pbu[i] = NULL;
+ sizes[i] = 0;
+ }
+ }
GNUNET_assert (size < 65536);
retval = GNUNET_malloc (size);
retval->len = htons (size);
retval->sizedmq1 = htons (0);
memcpy (&((char *) (&retval[1]))[i], pbu[5], sizes[5]);
for (i = 0; i < 6; i++)
- {
- if (pkv[i] != NULL)
- gcry_mpi_release (pkv[i]);
- if (pbu[i] != NULL)
- free (pbu[i]);
- }
+ {
+ if (pkv[i] != NULL)
+ gcry_mpi_release (pkv[i]);
+ if (pbu[i] != NULL)
+ free (pbu[i]);
+ }
return retval;
}
{
struct GNUNET_CRYPTO_RsaPrivateKey *ret;
const struct RsaPrivateKeyBinaryEncoded *encoding =
- (const struct RsaPrivateKeyBinaryEncoded *) buf;
+ (const struct RsaPrivateKeyBinaryEncoded *) buf;
gcry_sexp_t res;
gcry_mpi_t n, e, d, p, q, u;
int rc;
pos = 0;
size = ntohs (encoding->sizen);
rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos], size,
- &size);
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
pos += ntohs (encoding->sizen);
if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ return NULL;
+ }
size = ntohs (encoding->sizee);
rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos], size,
- &size);
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
pos += ntohs (encoding->sizee);
if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ return NULL;
+ }
size = ntohs (encoding->sized);
rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos], size,
- &size);
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
pos += ntohs (encoding->sized);
if (rc)
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ gcry_mpi_release (e);
+ return NULL;
+ }
+ /* swap p and q! */
+ size = ntohs (encoding->sizep);
+ if (size > 0)
+ {
+ rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
+ pos += ntohs (encoding->sizep);
+ if (rc)
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
gcry_mpi_release (n);
gcry_mpi_release (e);
+ gcry_mpi_release (d);
return NULL;
}
- /* swap p and q! */
- size = ntohs (encoding->sizep);
- if (size > 0)
- {
- rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos],
- size, &size);
- pos += ntohs (encoding->sizep);
- if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- gcry_mpi_release (e);
- gcry_mpi_release (d);
- return NULL;
- }
- }
+ }
else
q = NULL;
size = ntohs (encoding->sizeq);
if (size > 0)
+ {
+ rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
+ pos += ntohs (encoding->sizeq);
+ if (rc)
{
- rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos],
- size, &size);
- pos += ntohs (encoding->sizeq);
- if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- gcry_mpi_release (e);
- gcry_mpi_release (d);
- if (q != NULL)
- gcry_mpi_release (q);
- return NULL;
- }
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ gcry_mpi_release (e);
+ gcry_mpi_release (d);
+ if (q != NULL)
+ gcry_mpi_release (q);
+ return NULL;
}
+ }
else
p = NULL;
pos += ntohs (encoding->sizedmp1);
pos += ntohs (encoding->sizedmq1);
size =
- ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos;
+ ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos;
if (size > 0)
+ {
+ rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
+ &((const unsigned char *) (&encoding[1]))[pos], size,
+ &size);
+ if (rc)
{
- rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
- &((const unsigned char *) (&encoding[1]))[pos],
- size, &size);
- if (rc)
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
- gcry_mpi_release (n);
- gcry_mpi_release (e);
- gcry_mpi_release (d);
- if (p != NULL)
- gcry_mpi_release (p);
- if (q != NULL)
- gcry_mpi_release (q);
- return NULL;
- }
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+ gcry_mpi_release (n);
+ gcry_mpi_release (e);
+ gcry_mpi_release (d);
+ if (p != NULL)
+ gcry_mpi_release (p);
+ if (q != NULL)
+ gcry_mpi_release (q);
+ return NULL;
}
+ }
else
u = NULL;
if ((p != NULL) && (q != NULL) && (u != NULL))
+ {
+ rc = gcry_sexp_build (&res, &size, /* erroff */
+ "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))",
+ n, e, d, p, q, u);
+ }
+ else
+ {
+ if ((p != NULL) && (q != NULL))
{
- rc = gcry_sexp_build (&res, &size, /* erroff */
- "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))",
- n, e, d, p, q, u);
+ rc = gcry_sexp_build (&res, &size, /* erroff */
+ "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
+ n, e, d, p, q);
}
- else
+ else
{
- if ((p != NULL) && (q != NULL))
- {
- rc = gcry_sexp_build (&res, &size, /* erroff */
- "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
- n, e, d, p, q);
- }
- else
- {
- rc = gcry_sexp_build (&res, &size, /* erroff */
- "(private-key(rsa(n %m)(e %m)(d %m)))", n, e,
- d);
- }
+ rc = gcry_sexp_build (&res, &size, /* erroff */
+ "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d);
}
+ }
gcry_mpi_release (n);
gcry_mpi_release (e);
gcry_mpi_release (d);
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
#if EXTRA_CHECKS
if (gcry_pk_testkey (res))
- {
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
- return NULL;
- }
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
+ return NULL;
+ }
#endif
ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
ret->sexp = res;
if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
return NULL;
while (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ {
+ fd = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
+ | GNUNET_DISK_OPEN_FAILIFEXISTS,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ if (NULL == fd)
{
- fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE |
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == fd)
- {
- if (errno == EEXIST)
- {
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- /* must exist but not be accessible, fail for good! */
- if (0 != ACCESS (filename, R_OK))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access",
- filename);
- else
- GNUNET_break (0); /* what is going on!? */
- return NULL;
- }
- continue;
- }
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
- return NULL;
- }
- cnt = 0;
-
- while (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
- sizeof (struct
- RsaPrivateKeyBinaryEncoded),
- GNUNET_YES))
- {
- sleep (1);
- if (0 == ++cnt % 10)
- {
- ec = errno;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not aquire lock on file `%s': %s...\n"), filename,
- STRERROR (ec));
- }
- }
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Creating a new private key. This may take a while.\n"));
- ret = GNUNET_CRYPTO_rsa_key_create ();
- GNUNET_assert (ret != NULL);
- enc = rsa_encode_key (ret);
- GNUNET_assert (enc != NULL);
- GNUNET_assert (ntohs (enc->len) ==
- GNUNET_DISK_file_write (fd, enc, ntohs (enc->len)));
- GNUNET_free (enc);
-
- GNUNET_DISK_file_sync (fd);
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct
- RsaPrivateKeyBinaryEncoded)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
- GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
- GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("I am host `%s'. Stored new private key in `%s'.\n"),
- GNUNET_i2s (&pid), filename);
- return ret;
+ if (errno == EEXIST)
+ {
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ {
+ /* must exist but not be accessible, fail for good! */
+ if (0 != ACCESS (filename, R_OK))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
+ else
+ GNUNET_break (0); /* what is going on!? */
+ return NULL;
+ }
+ continue;
+ }
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
+ return NULL;
+ }
+ cnt = 0;
+
+ while (GNUNET_YES !=
+ GNUNET_DISK_file_lock (fd, 0,
+ sizeof (struct RsaPrivateKeyBinaryEncoded),
+ GNUNET_YES))
+ {
+ sleep (1);
+ if (0 == ++cnt % 10)
+ {
+ ec = errno;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not aquire lock on file `%s': %s...\n"), filename,
+ STRERROR (ec));
+ }
}
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Creating a new private key. This may take a while.\n"));
+ ret = GNUNET_CRYPTO_rsa_key_create ();
+ GNUNET_assert (ret != NULL);
+ enc = rsa_encode_key (ret);
+ GNUNET_assert (enc != NULL);
+ GNUNET_assert (ntohs (enc->len) ==
+ GNUNET_DISK_file_write (fd, enc, ntohs (enc->len)));
+ GNUNET_free (enc);
+
+ GNUNET_DISK_file_sync (fd);
+ if (GNUNET_YES !=
+ GNUNET_DISK_file_unlock (fd, 0,
+ sizeof (struct RsaPrivateKeyBinaryEncoded)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
+ GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
+ GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("I am host `%s'. Stored new private key in `%s'.\n"),
+ GNUNET_i2s (&pid), filename);
+ return ret;
+ }
/* hostkey file exists already, read it! */
fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_PERM_NONE);
if (NULL == fd)
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
+ return NULL;
+ }
+ cnt = 0;
+ while (1)
+ {
+ if (GNUNET_YES !=
+ GNUNET_DISK_file_lock (fd, 0,
+ sizeof (struct RsaPrivateKeyBinaryEncoded),
+ GNUNET_NO))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
+ if (0 == ++cnt % 60)
+ {
+ ec = errno;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not aquire lock on file `%s': %s...\n"), filename,
+ STRERROR (ec));
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("This may be ok if someone is currently generating a hostkey.\n"));
+ }
+ sleep (1);
+ continue;
+ }
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ {
+ /* eh, what!? File we opened is now gone!? */
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
+ if (GNUNET_YES !=
+ GNUNET_DISK_file_unlock (fd, 0,
+ sizeof (struct RsaPrivateKeyBinaryEncoded)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
+
return NULL;
}
- cnt = 0;
- while (1)
+ if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES))
+ fs = 0;
+ if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded))
{
+ /* maybe we got the read lock before the hostkey generating
+ * process had a chance to get the write lock; give it up! */
if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
- sizeof (struct RsaPrivateKeyBinaryEncoded),
- GNUNET_NO))
- {
- if (0 == ++cnt % 60)
- {
- ec = errno;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not aquire lock on file `%s': %s...\n"), filename,
- STRERROR (ec));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("This may be ok if someone is currently generating a hostkey.\n"));
- }
- sleep (1);
- continue;
- }
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- /* eh, what!? File we opened is now gone!? */
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct
- RsaPrivateKeyBinaryEncoded)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
-
- return NULL;
- }
- if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES))
- fs = 0;
- if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded))
- {
- /* maybe we got the read lock before the hostkey generating
- * process had a chance to get the write lock; give it up! */
- if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct
- RsaPrivateKeyBinaryEncoded)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
- if (0 == ++cnt % 10)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"),
- filename, (unsigned int) fs,
- (unsigned int) sizeof (struct RsaPrivateKeyBinaryEncoded));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("This may be ok if someone is currently generating a hostkey.\n"));
- }
- sleep (2); /* wait a bit longer! */
- continue;
- }
- break;
+ GNUNET_DISK_file_unlock (fd, 0,
+ sizeof (struct RsaPrivateKeyBinaryEncoded)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ if (0 == ++cnt % 10)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"),
+ filename, (unsigned int) fs,
+ (unsigned int) sizeof (struct RsaPrivateKeyBinaryEncoded));
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("This may be ok if someone is currently generating a hostkey.\n"));
+ }
+ sleep (2); /* wait a bit longer! */
+ continue;
}
+ break;
+ }
enc = GNUNET_malloc (fs);
GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs));
len = ntohs (enc->len);
ret = NULL;
if ((len != fs) ||
(NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *) enc, len))))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("File `%s' does not contain a valid private key. Deleting it.\n"),
+ filename);
+ if (0 != UNLINK (filename))
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("File `%s' does not contain a valid private key. Deleting it.\n"),
- filename);
- if (0 != UNLINK (filename))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
- }
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
}
+ }
GNUNET_free (enc);
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct RsaPrivateKeyBinaryEncoded)))
+ sizeof (struct RsaPrivateKeyBinaryEncoded)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
if (ret != NULL)
- {
- GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
- GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("I am host `%s'. Read private key from `%s'.\n"),
- GNUNET_i2s (&pid), filename);
- }
+ {
+ GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
+ GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("I am host `%s'. Read private key from `%s'.\n"), GNUNET_i2s (&pid),
+ filename);
+ }
return ret;
}
*/
int
GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
- const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey,
- struct GNUNET_CRYPTO_RsaEncryptedData *target)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *publicKey,
+ struct GNUNET_CRYPTO_RsaEncryptedData *target)
{
gcry_sexp_t result;
gcry_sexp_t data;
return GNUNET_SYSERR;
isize = size;
GNUNET_assert (0 ==
- gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize));
+ gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize));
GNUNET_assert (0 ==
- gcry_sexp_build (&data, &erroff,
- "(data (flags pkcs1)(value %m))", val));
+ gcry_sexp_build (&data, &erroff,
+ "(data (flags pkcs1)(value %m))", val));
gcry_mpi_release (val);
GNUNET_assert (0 == gcry_pk_encrypt (&result, data, pubkey->sexp));
gcry_sexp_release (data);
gcry_sexp_release (result);
isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData);
GNUNET_assert (0 ==
- gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target,
- isize, &isize, rval));
+ gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target,
+ isize, &isize, rval));
gcry_mpi_release (rval);
adjust (&target->encoding[0], isize,
- sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
+ sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
return GNUNET_OK;
}
*/
ssize_t
GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
- const struct GNUNET_CRYPTO_RsaEncryptedData *
- block, void *result, size_t max)
+ const struct GNUNET_CRYPTO_RsaEncryptedData * block,
+ void *result, size_t max)
{
gcry_sexp_t resultsexp;
gcry_sexp_t data;
#endif
size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData);
GNUNET_assert (0 ==
- gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0],
- size, &size));
+ gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0],
+ size, &size));
GNUNET_assert (0 ==
- gcry_sexp_build (&data, &erroff,
- "(enc-val(flags)(rsa(a %m)))", val));
+ gcry_sexp_build (&data, &erroff, "(enc-val(flags)(rsa(a %m)))",
+ val));
gcry_mpi_release (val);
GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp));
gcry_sexp_release (data);
/* resultsexp has format "(value %m)" */
GNUNET_assert (NULL !=
- (val = gcry_sexp_nth_mpi (resultsexp, 1, GCRYMPI_FMT_USG)));
+ (val = gcry_sexp_nth_mpi (resultsexp, 1, GCRYMPI_FMT_USG)));
gcry_sexp_release (resultsexp);
tmp = GNUNET_malloc (max + HOSTKEY_LEN / 8);
size = max + HOSTKEY_LEN / 8;
- GNUNET_assert (0 ==
- gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val));
+ GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val));
gcry_mpi_release (val);
endp = tmp;
endp += (size - max);
*/
int
GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
- const struct GNUNET_CRYPTO_RsaSignaturePurpose
- *purpose, struct GNUNET_CRYPTO_RsaSignature *sig)
+ const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose,
+ struct GNUNET_CRYPTO_RsaSignature *sig)
{
gcry_sexp_t result;
gcry_sexp_t data;
buff = GNUNET_malloc (bufSize);
memcpy (buff, FORMATSTRING, bufSize);
memcpy (&buff
- [bufSize -
- strlen
- ("0123456789012345678901234567890123456789012345678901234567890123))")
- - 1], &hc, sizeof (GNUNET_HashCode));
+ [bufSize -
+ strlen
+ ("0123456789012345678901234567890123456789012345678901234567890123))")
+ - 1], &hc, sizeof (GNUNET_HashCode));
GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
GNUNET_free (buff);
GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp));
gcry_sexp_release (result);
ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature);
GNUNET_assert (0 ==
- gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig,
- ssize, &ssize, rval));
+ gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig, ssize,
+ &ssize, rval));
gcry_mpi_release (rval);
adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature));
return GNUNET_OK;
*/
int
GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
- const struct GNUNET_CRYPTO_RsaSignaturePurpose
- *validate,
- const struct GNUNET_CRYPTO_RsaSignature *sig,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
- *publicKey)
+ const struct GNUNET_CRYPTO_RsaSignaturePurpose
+ *validate,
+ const struct GNUNET_CRYPTO_RsaSignature *sig,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *publicKey)
{
gcry_sexp_t data;
gcry_sexp_t sigdata;
int rc;
if (purpose != ntohl (validate->purpose))
- return GNUNET_SYSERR; /* purpose mismatch */
+ return GNUNET_SYSERR; /* purpose mismatch */
GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc);
size = sizeof (struct GNUNET_CRYPTO_RsaSignature);
GNUNET_assert (0 ==
- gcry_mpi_scan (&val, GCRYMPI_FMT_USG,
- (const unsigned char *) sig, size, &size));
+ gcry_mpi_scan (&val, GCRYMPI_FMT_USG,
+ (const unsigned char *) sig, size, &size));
GNUNET_assert (0 ==
- gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))",
- val));
+ gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))",
+ val));
gcry_mpi_release (val);
bufSize = strlen (FORMATSTRING) + 1;
buff = GNUNET_malloc (bufSize);
memcpy (buff, FORMATSTRING, bufSize);
memcpy (&buff
- [strlen (FORMATSTRING) -
- strlen
- ("0123456789012345678901234567890123456789012345678901234567890123))")],
- &hc, sizeof (GNUNET_HashCode));
+ [strlen (FORMATSTRING) -
+ strlen
+ ("0123456789012345678901234567890123456789012345678901234567890123))")],
+ &hc, sizeof (GNUNET_HashCode));
GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
GNUNET_free (buff);
hostkey = public2PrivateKey (publicKey);
if (hostkey == NULL)
- {
- gcry_sexp_release (data);
- gcry_sexp_release (sigdata);
- return GNUNET_SYSERR;
- }
+ {
+ gcry_sexp_release (data);
+ gcry_sexp_release (sigdata);
+ return GNUNET_SYSERR;
+ }
rc = gcry_pk_verify (sigdata, data, hostkey->sexp);
GNUNET_CRYPTO_rsa_key_free (hostkey);
gcry_sexp_release (data);
gcry_sexp_release (sigdata);
if (rc)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("RSA signature verification failed at %s:%d: %s\n"), __FILE__,
- __LINE__, gcry_strerror (rc));
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("RSA signature verification failed at %s:%d: %s\n"), __FILE__,
+ __LINE__, gcry_strerror (rc));
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
#define PIPE_BUF 512
ULONG PipeSerialNumber;
#endif
-#define _IFMT 0170000 /* type of file */
-#define _IFLNK 0120000 /* symbolic link */
+#define _IFMT 0170000 /* type of file */
+#define _IFLNK 0120000 /* symbolic link */
#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
#else
#error PORT-ME: need to port statfs (how much space is left on the drive?)
#ifdef HAVE_STAT64
if (0 != STAT64 (fn, &buf))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat64", fn);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat64", fn);
+ return GNUNET_SYSERR;
+ }
#else
if (0 != STAT (fn, &buf))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fn);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fn);
+ return GNUNET_SYSERR;
+ }
#endif
if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
gfsd->total += buf.st_size;
if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) &&
((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
- {
- if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
- return GNUNET_SYSERR;
- }
+ {
+ if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
*/
off_t
GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
- enum GNUNET_DISK_Seek whence)
+ enum GNUNET_DISK_Seek whence)
{
if (h == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifdef MINGW
DWORD ret;
ret = SetFilePointer (h->h, offset, NULL, t[whence]);
if (ret == INVALID_SET_FILE_POINTER)
- {
- SetErrnoFromWinError (GetLastError ());
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
return ret;
#else
static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET,
*/
int
GNUNET_DISK_file_size (const char *filename, uint64_t * size,
- int includeSymLinks)
+ int includeSymLinks)
{
struct GetFileSizeData gfsd;
int ret;
*/
int
GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
- uint64_t * ino)
+ uint64_t * ino)
{
#if LINUX
struct stat sbuf;
struct statvfs fbuf;
if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf)))
- {
- *dev = (uint64_t) fbuf.f_fsid;
- *ino = (uint64_t) sbuf.st_ino;
- return GNUNET_OK;
- }
+ {
+ *dev = (uint64_t) fbuf.f_fsid;
+ *ino = (uint64_t) sbuf.st_ino;
+ return GNUNET_OK;
+ }
#elif SOMEBSD
struct stat sbuf;
struct statfs fbuf;
if ((0 == stat (filename, &sbuf)) && (0 == statfs (filename, &fbuf)))
- {
- *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 ||
- ((uint64_t) fbuf.f_fsid.val[1]);
- *ino = (uint64_t) sbuf.st_ino;
- return GNUNET_OK;
- }
+ {
+ *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 ||
+ ((uint64_t) fbuf.f_fsid.val[1]);
+ *ino = (uint64_t) sbuf.st_ino;
+ return GNUNET_OK;
+ }
#elif WINDOWS
// FIXME NILS: test this
struct GNUNET_DISK_FileHandle *fh;
succ = GetFileInformationByHandle (fh->h, &info);
GNUNET_DISK_file_close (fh);
if (succ)
- {
- *dev = info.dwVolumeSerialNumber;
- *ino = ((info.nFileIndexHigh << sizeof (DWORD)) | info.nFileIndexLow);
- return GNUNET_OK;
- }
+ {
+ *dev = info.dwVolumeSerialNumber;
+ *ino = ((info.nFileIndexHigh << sizeof (DWORD)) | info.nFileIndexLow);
+ return GNUNET_OK;
+ }
else
return GNUNET_SYSERR;
#if WINDOWS
&& !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
#endif
- )
- {
- tmpdir = getenv ("TMPDIR");
- tmpdir = tmpdir ? tmpdir : "/tmp";
- GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
- }
+ )
+ {
+ tmpdir = getenv ("TMPDIR");
+ tmpdir = tmpdir ? tmpdir : "/tmp";
+ GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
+ }
else
- {
- GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX");
- }
+ {
+ GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX");
+ }
#ifdef MINGW
fn = (char *) GNUNET_malloc (MAX_PATH + 1);
if (ERROR_SUCCESS != plibc_conv_to_win_path (tmpl, fn))
- {
- GNUNET_free (fn);
- GNUNET_free (tmpl);
- return NULL;
- }
+ {
+ GNUNET_free (fn);
+ GNUNET_free (tmpl);
+ return NULL;
+ }
GNUNET_free (tmpl);
#else
fn = tmpl;
#endif
fd = mkstemp (fn);
if (fd == -1)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
- GNUNET_free (fn);
- return NULL;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
+ GNUNET_free (fn);
+ return NULL;
+ }
if (0 != CLOSE (fd))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
return fn;
struct statvfs buf;
if (0 != statvfs (part, &buf))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
- return -1;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
+ return -1;
+ }
return buf.f_bavail;
#elif MINGW
DWORD dwDummy;
GNUNET_free (path);
szDrive[3] = 0;
if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' failed for drive `%s': %u\n"), "GetDiskFreeSpace",
- szDrive, GetLastError ());
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("`%s' failed for drive `%s': %u\n"),
+ "GetDiskFreeSpace", szDrive, GetLastError ());
- return -1;
- }
+ return -1;
+ }
return dwBlocks;
#else
struct statfs s;
if (0 != statfs (part, &s))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
- return -1;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
+ return -1;
+ }
return s.f_bavail;
#endif
}
ret = STAT (fil, &filestat);
if (ret != 0)
+ {
+ if (errno != ENOENT)
{
- if (errno != ENOENT)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
- return GNUNET_SYSERR;
- }
- return GNUNET_NO;
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
+ return GNUNET_SYSERR;
}
+ return GNUNET_NO;
+ }
if (!S_ISDIR (filestat.st_mode))
return GNUNET_NO;
if (ACCESS (fil, R_OK | X_OK) < 0)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil);
+ return GNUNET_SYSERR;
+ }
return GNUNET_YES;
}
ret = STAT (rdir, &filestat);
if (ret != 0)
+ {
+ if (errno != ENOENT)
{
- if (errno != ENOENT)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", rdir);
- GNUNET_free (rdir);
- return GNUNET_SYSERR;
- }
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", rdir);
GNUNET_free (rdir);
- return GNUNET_NO;
+ return GNUNET_SYSERR;
}
+ GNUNET_free (rdir);
+ return GNUNET_NO;
+ }
if (!S_ISREG (filestat.st_mode))
- {
- GNUNET_free (rdir);
- return GNUNET_NO;
- }
+ {
+ GNUNET_free (rdir);
+ return GNUNET_NO;
+ }
if (ACCESS (rdir, R_OK) < 0)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
- GNUNET_free (rdir);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
+ GNUNET_free (rdir);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (rdir);
return GNUNET_YES;
}
len = strlen (rdir);
#ifndef MINGW
- pos = 1; /* skip heading '/' */
+ pos = 1; /* skip heading '/' */
#else
/* Local or Network path? */
if (strncmp (rdir, "\\\\", 2) == 0)
+ {
+ pos = 2;
+ while (rdir[pos])
{
- pos = 2;
- while (rdir[pos])
- {
- if (rdir[pos] == '\\')
- {
- pos++;
- break;
- }
- pos++;
- }
+ if (rdir[pos] == '\\')
+ {
+ pos++;
+ break;
+ }
+ pos++;
}
+ }
else
- {
- pos = 3; /* strlen("C:\\") */
- }
+ {
+ pos = 3; /* strlen("C:\\") */
+ }
#endif
while (pos <= len)
+ {
+ if ((rdir[pos] == DIR_SEPARATOR) || (pos == len))
{
- if ((rdir[pos] == DIR_SEPARATOR) || (pos == len))
- {
- rdir[pos] = '\0';
- ret = GNUNET_DISK_directory_test (rdir);
- if (ret == GNUNET_SYSERR)
- {
- GNUNET_free (rdir);
- return GNUNET_SYSERR;
- }
- if (ret == GNUNET_NO)
- {
+ rdir[pos] = '\0';
+ ret = GNUNET_DISK_directory_test (rdir);
+ if (ret == GNUNET_SYSERR)
+ {
+ GNUNET_free (rdir);
+ return GNUNET_SYSERR;
+ }
+ if (ret == GNUNET_NO)
+ {
#ifndef MINGW
- ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */
+ ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */
#else
- ret = mkdir (rdir);
+ ret = mkdir (rdir);
#endif
- if ((ret != 0) && (errno != EEXIST))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir);
- GNUNET_free (rdir);
- return GNUNET_SYSERR;
- }
- }
- rdir[pos] = DIR_SEPARATOR;
- }
- pos++;
+ if ((ret != 0) && (errno != EEXIST))
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir);
+ GNUNET_free (rdir);
+ return GNUNET_SYSERR;
+ }
+ }
+ rdir[pos] = DIR_SEPARATOR;
}
+ pos++;
+ }
GNUNET_free (rdir);
return GNUNET_OK;
}
*/
ssize_t
GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result,
- size_t len)
+ size_t len)
{
if (h == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifdef MINGW
DWORD bytesRead;
if (h->type != GNUNET_PIPE)
+ {
+ if (!ReadFile (h->h, result, len, &bytesRead, NULL))
{
- if (!ReadFile (h->h, result, len, &bytesRead, NULL))
- {
- SetErrnoFromWinError (GetLastError ());
- return GNUNET_SYSERR;
- }
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
}
+ }
else
+ {
+ if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead))
{
- if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead))
- {
- if (GetLastError () != ERROR_IO_PENDING)
- {
- SetErrnoFromWinError (GetLastError ());
- return GNUNET_SYSERR;
- }
- }
- GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE);
+ if (GetLastError () != ERROR_IO_PENDING)
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
}
+ GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE);
+ }
return bytesRead;
#else
return read (h->fd, result, len);
struct GNUNET_DISK_FileHandle *fh;
ssize_t ret;
- fh =
- GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
+ fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
if (!fh)
return GNUNET_SYSERR;
ret = GNUNET_DISK_file_read (fh, result, len);
*/
ssize_t
GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
- const void *buffer, size_t n)
+ const void *buffer, size_t n)
{
if (h == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifdef MINGW
DWORD bytesWritten;
if (h->type != GNUNET_PIPE)
+ {
+ if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL))
{
- if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL))
- {
- SetErrnoFromWinError (GetLastError ());
- return GNUNET_SYSERR;
- }
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
}
+ }
else
- {
+ {
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n");
#endif
- if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite))
- {
- if (GetLastError () != ERROR_IO_PENDING)
- {
- SetErrnoFromWinError (GetLastError ());
+ if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite))
+ {
+ if (GetLastError () != ERROR_IO_PENDING)
+ {
+ SetErrnoFromWinError (GetLastError ());
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n");
#endif
- return GNUNET_SYSERR;
- }
- }
+ return GNUNET_SYSERR;
+ }
+ }
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
#endif
- GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE);
- }
+ GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE);
+ }
return bytesWritten;
#else
return write (h->fd, buffer, n);
*/
ssize_t
GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
- enum GNUNET_DISK_AccessPermissions mode)
+ enum GNUNET_DISK_AccessPermissions mode)
{
struct GNUNET_DISK_FileHandle *fh;
ssize_t ret;
fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_WRITE |
- GNUNET_DISK_OPEN_TRUNCATE |
- GNUNET_DISK_OPEN_CREATE, mode);
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
+ | GNUNET_DISK_OPEN_CREATE, mode);
if (!fh)
return GNUNET_SYSERR;
ret = GNUNET_DISK_file_write (fh, buffer, n);
*/
int
GNUNET_DISK_directory_scan (const char *dirName,
- GNUNET_FileNameCallback callback,
- void *callback_cls)
+ GNUNET_FileNameCallback callback,
+ void *callback_cls)
{
DIR *dinfo;
struct dirent *finfo;
while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR))
dname[strlen (dname) - 1] = '\0';
if (0 != STAT (dname, &istat))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
- GNUNET_free (dname);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
+ GNUNET_free (dname);
+ return GNUNET_SYSERR;
+ }
if (!S_ISDIR (istat.st_mode))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Expected `%s' to be a directory!\n"), dirName);
- GNUNET_free (dname);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Expected `%s' to be a directory!\n"),
+ dirName);
+ GNUNET_free (dname);
+ return GNUNET_SYSERR;
+ }
errno = 0;
dinfo = OPENDIR (dname);
if ((errno == EACCES) || (dinfo == NULL))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
- if (dinfo != NULL)
- closedir (dinfo);
- GNUNET_free (dname);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
+ if (dinfo != NULL)
+ closedir (dinfo);
+ GNUNET_free (dname);
+ return GNUNET_SYSERR;
+ }
name_len = 256;
n_size = strlen (dname) + name_len + 2;
name = GNUNET_malloc (n_size);
while ((finfo = readdir (dinfo)) != NULL)
+ {
+ if ((0 == strcmp (finfo->d_name, ".")) ||
+ (0 == strcmp (finfo->d_name, "..")))
+ continue;
+ if (callback != NULL)
{
- if ((0 == strcmp (finfo->d_name, ".")) ||
- (0 == strcmp (finfo->d_name, "..")))
- continue;
- if (callback != NULL)
- {
- if (name_len < strlen (finfo->d_name))
- {
- GNUNET_free (name);
- name_len = strlen (finfo->d_name);
- n_size = strlen (dname) + name_len + 2;
- name = GNUNET_malloc (n_size);
- }
- /* dname can end in "/" only if dname == "/";
- * if dname does not end in "/", we need to add
- * a "/" (otherwise, we must not!) */
- GNUNET_snprintf (name, n_size, "%s%s%s", dname,
- (strcmp (dname, DIR_SEPARATOR_STR) ==
- 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name);
- if (GNUNET_OK != callback (callback_cls, name))
- {
- closedir (dinfo);
- GNUNET_free (name);
- GNUNET_free (dname);
- return GNUNET_SYSERR;
- }
- }
- count++;
+ if (name_len < strlen (finfo->d_name))
+ {
+ GNUNET_free (name);
+ name_len = strlen (finfo->d_name);
+ n_size = strlen (dname) + name_len + 2;
+ name = GNUNET_malloc (n_size);
+ }
+ /* dname can end in "/" only if dname == "/";
+ * if dname does not end in "/", we need to add
+ * a "/" (otherwise, we must not!) */
+ GNUNET_snprintf (name, n_size, "%s%s%s", dname,
+ (strcmp (dname, DIR_SEPARATOR_STR) ==
+ 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name);
+ if (GNUNET_OK != callback (callback_cls, name))
+ {
+ closedir (dinfo);
+ GNUNET_free (name);
+ GNUNET_free (dname);
+ return GNUNET_SYSERR;
+ }
}
+ count++;
+ }
closedir (dinfo);
GNUNET_free (name);
GNUNET_free (dname);
*/
static void
directory_iterator_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DISK_DirectoryIterator *iter = cls;
char *name;
* GNUNET_SYSERR if abort was YES
*/
int
-GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator
- *iter, int can)
+GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
+ int can)
{
struct dirent *finfo;
GNUNET_assert (iter->next_name == NULL);
if (can == GNUNET_YES)
- {
- closedir (iter->directory);
- GNUNET_free (iter->dirname);
- GNUNET_free (iter);
- return GNUNET_SYSERR;
- }
+ {
+ closedir (iter->directory);
+ GNUNET_free (iter->dirname);
+ GNUNET_free (iter);
+ return GNUNET_SYSERR;
+ }
while (NULL != (finfo = readdir (iter->directory)))
- {
- if ((0 == strcmp (finfo->d_name, ".")) ||
- (0 == strcmp (finfo->d_name, "..")))
- continue;
- GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname,
- DIR_SEPARATOR_STR, finfo->d_name);
- break;
- }
+ {
+ if ((0 == strcmp (finfo->d_name, ".")) ||
+ (0 == strcmp (finfo->d_name, "..")))
+ continue;
+ GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname,
+ DIR_SEPARATOR_STR, finfo->d_name);
+ break;
+ }
if (finfo == NULL)
- {
- GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES);
- return GNUNET_NO;
- }
- GNUNET_SCHEDULER_add_with_priority (iter->priority,
- &directory_iterator_task, iter);
+ {
+ GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES);
+ return GNUNET_NO;
+ }
+ GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task,
+ iter);
return GNUNET_YES;
}
*/
void
GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio,
- const char *dirName,
- GNUNET_DISK_DirectoryIteratorCallback
- callback, void *callback_cls)
+ const char *dirName,
+ GNUNET_DISK_DirectoryIteratorCallback
+ callback, void *callback_cls)
{
struct GNUNET_DISK_DirectoryIterator *di;
di->callback_cls = callback_cls;
di->directory = OPENDIR (dirName);
if (di->directory == NULL)
- {
- GNUNET_free (di);
- callback (callback_cls, NULL, NULL, NULL);
- return;
- }
+ {
+ GNUNET_free (di);
+ callback (callback_cls, NULL, NULL, NULL);
+ return;
+ }
di->dirname = GNUNET_strdup (dirName);
di->priority = prio;
GNUNET_DISK_directory_iterator_next (di, GNUNET_NO);
struct stat istat;
if (0 != LSTAT (fileName, &istat))
- return GNUNET_NO; /* file may not exist... */
+ return GNUNET_NO; /* file may not exist... */
CHMOD (fileName, S_IWUSR | S_IRUSR | S_IXUSR);
if (UNLINK (fileName) == 0)
return GNUNET_OK;
* sticky /tmp directory may result in EPERM on BSD.
* So we also explicitly check "isDirectory" */
(GNUNET_YES != GNUNET_DISK_directory_test (fileName)))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
+ return GNUNET_SYSERR;
+ }
if (GNUNET_SYSERR ==
GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL))
return GNUNET_SYSERR;
if (0 != RMDIR (fileName))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
return GNUNET_SYSERR;
pos = 0;
in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_PERM_NONE);
if (!in)
return GNUNET_SYSERR;
out =
- GNUNET_DISK_file_open (dst,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_GROUP_WRITE);
+ GNUNET_DISK_file_open (dst,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_FAILIFEXISTS,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_GROUP_WRITE);
if (!out)
- {
- GNUNET_DISK_file_close (in);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_DISK_file_close (in);
+ return GNUNET_SYSERR;
+ }
buf = GNUNET_malloc (COPY_BLK_SIZE);
while (pos < size)
- {
- len = COPY_BLK_SIZE;
- if (len > size - pos)
- len = size - pos;
- if (len != GNUNET_DISK_file_read (in, buf, len))
- goto FAIL;
- if (len != GNUNET_DISK_file_write (out, buf, len))
- goto FAIL;
- pos += len;
- }
+ {
+ len = COPY_BLK_SIZE;
+ if (len > size - pos)
+ len = size - pos;
+ if (len != GNUNET_DISK_file_read (in, buf, len))
+ goto FAIL;
+ if (len != GNUNET_DISK_file_write (out, buf, len))
+ goto FAIL;
+ pos += len;
+ }
GNUNET_free (buf);
GNUNET_DISK_file_close (in);
GNUNET_DISK_file_close (out);
idx = fn;
while (*idx)
- {
- c = *idx;
-
- if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?'
- || c == '"' || c == '<' || c == '>' || c == '|')
- {
- *idx = '_';
- }
+ {
+ c = *idx;
- idx++;
+ if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' ||
+ c == '<' || c == '>' || c == '|')
+ {
+ *idx = '_';
}
+
+ idx++;
+ }
}
pws = getpwnam (user);
if (pws == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"), user,
- STRERROR (errno));
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Cannot obtain information about user `%s': %s\n"), user,
+ STRERROR (errno));
+ return GNUNET_SYSERR;
+ }
if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "chown", filename);
#endif
*/
int
GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
- off_t lockEnd, int excl)
+ off_t lockEnd, int excl)
{
if (fh == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifndef MINGW
struct flock fl;
o.Offset = lockStart;
if (!LockFileEx
- (fh->h,
- (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY, 0,
- lockEnd - lockStart, 0, &o))
- {
- SetErrnoFromWinError (GetLastError ());
- return GNUNET_SYSERR;
- }
+ (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY,
+ 0, lockEnd - lockStart, 0, &o))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
#endif
*/
int
GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
- off_t unlockEnd)
+ off_t unlockEnd)
{
if (fh == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifndef MINGW
struct flock fl;
o.Offset = unlockStart;
if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o))
- {
- SetErrnoFromWinError (GetLastError ());
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
#endif
*/
struct GNUNET_DISK_FileHandle *
GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
- enum GNUNET_DISK_AccessPermissions perm)
+ enum GNUNET_DISK_AccessPermissions perm)
{
char *expfn;
struct GNUNET_DISK_FileHandle *ret;
#ifndef MINGW
mode = 0;
if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
- oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
+ oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
else if (flags & GNUNET_DISK_OPEN_READ)
oflags = O_RDONLY;
else if (flags & GNUNET_DISK_OPEN_WRITE)
oflags = O_WRONLY;
else
- {
- GNUNET_break (0);
- GNUNET_free (expfn);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_free (expfn);
+ return NULL;
+ }
if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
oflags |= (O_CREAT | O_EXCL);
if (flags & GNUNET_DISK_OPEN_TRUNCATE)
if (flags & GNUNET_DISK_OPEN_APPEND)
oflags |= O_APPEND;
if (flags & GNUNET_DISK_OPEN_CREATE)
- {
- (void) GNUNET_DISK_directory_create_for_file (expfn);
- oflags |= O_CREAT;
- mode = translate_unix_perms (perm);
- }
+ {
+ (void) GNUNET_DISK_directory_create_for_file (expfn);
+ oflags |= O_CREAT;
+ mode = translate_unix_perms (perm);
+ }
fd = open (expfn, oflags | O_LARGEFILE, mode);
if (fd == -1)
- {
- if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
- else
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "open", expfn);
- GNUNET_free (expfn);
- return NULL;
- }
+ {
+ if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
+ else
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "open", expfn);
+ GNUNET_free (expfn);
+ return NULL;
+ }
#else
access = 0;
disp = OPEN_ALWAYS;
access = FILE_WRITE_DATA;
if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
- {
- disp = CREATE_NEW;
- }
+ {
+ disp = CREATE_NEW;
+ }
else if (flags & GNUNET_DISK_OPEN_CREATE)
- {
- (void) GNUNET_DISK_directory_create_for_file (expfn);
- if (flags & GNUNET_DISK_OPEN_TRUNCATE)
- disp = CREATE_ALWAYS;
- else
- disp = OPEN_ALWAYS;
- }
+ {
+ (void) GNUNET_DISK_directory_create_for_file (expfn);
+ if (flags & GNUNET_DISK_OPEN_TRUNCATE)
+ disp = CREATE_ALWAYS;
+ else
+ disp = OPEN_ALWAYS;
+ }
else if (flags & GNUNET_DISK_OPEN_TRUNCATE)
- {
- disp = TRUNCATE_EXISTING;
- }
+ {
+ disp = TRUNCATE_EXISTING;
+ }
else
- {
- disp = OPEN_EXISTING;
- }
+ {
+ disp = OPEN_EXISTING;
+ }
/* TODO: access priviledges? */
h = CreateFile (expfn, access,
- FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL);
+ FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+ disp, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE)
+ {
+ SetErrnoFromWinError (GetLastError ());
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
+ GNUNET_free (expfn);
+ return NULL;
+ }
+
+ if (flags & GNUNET_DISK_OPEN_APPEND)
+ if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
{
SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", expfn);
+ CloseHandle (h);
GNUNET_free (expfn);
return NULL;
}
-
- if (flags & GNUNET_DISK_OPEN_APPEND)
- if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
- {
- SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer",
- expfn);
- CloseHandle (h);
- GNUNET_free (expfn);
- return NULL;
- }
#endif
ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle));
GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
{
if (h == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#if MINGW
if (!CloseHandle (h->h))
- {
- SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
- GNUNET_free (h->oOverlapRead);
- GNUNET_free (h->oOverlapWrite);
- GNUNET_free (h);
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
+ GNUNET_free (h->oOverlapRead);
+ GNUNET_free (h->oOverlapWrite);
+ GNUNET_free (h);
+ return GNUNET_SYSERR;
+ }
#else
if (close (h->fd) != 0)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
- GNUNET_free (h);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
+ GNUNET_free (h);
+ return GNUNET_SYSERR;
+ }
#endif
GNUNET_free (h);
return GNUNET_OK;
*/
char *
GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *serviceName, ...)
+ const char *serviceName, ...)
{
const char *c;
char *pfx;
unsigned int needed;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME",
- &pfx))
+ GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME", &pfx))
return NULL;
if (pfx == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("No `%s' specified for service `%s' in configuration.\n"),
- "HOME", serviceName);
- return NULL;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("No `%s' specified for service `%s' in configuration.\n"), "HOME",
+ serviceName);
+ return NULL;
+ }
needed = strlen (pfx) + 2;
if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\'))
needed++;
va_start (ap, serviceName);
while (1)
- {
- c = va_arg (ap, const char *);
+ {
+ c = va_arg (ap, const char *);
- if (c == NULL)
- break;
- needed += strlen (c);
- if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
- needed++;
- }
+ if (c == NULL)
+ break;
+ needed += strlen (c);
+ if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
+ needed++;
+ }
va_end (ap);
ret = GNUNET_malloc (needed);
strcpy (ret, pfx);
GNUNET_free (pfx);
va_start (ap, serviceName);
while (1)
- {
- c = va_arg (ap, const char *);
+ {
+ c = va_arg (ap, const char *);
- if (c == NULL)
- break;
- if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
- strcat (ret, DIR_SEPARATOR_STR);
- strcat (ret, c);
- }
+ if (c == NULL)
+ break;
+ if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
+ strcat (ret, DIR_SEPARATOR_STR);
+ strcat (ret, c);
+ }
va_end (ap);
if ((ret[strlen (ret) - 1] != '/') && (ret[strlen (ret) - 1] != '\\'))
(void) GNUNET_DISK_directory_create_for_file (ret);
*/
void *
GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
- struct GNUNET_DISK_MapHandle **m,
- enum GNUNET_DISK_MapType access, size_t len)
+ struct GNUNET_DISK_MapHandle **m,
+ enum GNUNET_DISK_MapType access, size_t len)
{
if (h == NULL)
- {
- errno = EINVAL;
- return NULL;
- }
+ {
+ errno = EINVAL;
+ return NULL;
+ }
#ifdef MINGW
DWORD mapAccess, protect;
if ((access & GNUNET_DISK_MAP_TYPE_READ) &&
(access & GNUNET_DISK_MAP_TYPE_WRITE))
- {
- protect = PAGE_READWRITE;
- mapAccess = FILE_MAP_ALL_ACCESS;
- }
+ {
+ protect = PAGE_READWRITE;
+ mapAccess = FILE_MAP_ALL_ACCESS;
+ }
else if (access & GNUNET_DISK_MAP_TYPE_READ)
- {
- protect = PAGE_READONLY;
- mapAccess = FILE_MAP_READ;
- }
+ {
+ protect = PAGE_READONLY;
+ mapAccess = FILE_MAP_READ;
+ }
else if (access & GNUNET_DISK_MAP_TYPE_WRITE)
- {
- protect = PAGE_READWRITE;
- mapAccess = FILE_MAP_WRITE;
- }
+ {
+ protect = PAGE_READWRITE;
+ mapAccess = FILE_MAP_WRITE;
+ }
else
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
*m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle));
(*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL);
if ((*m)->h == INVALID_HANDLE_VALUE)
- {
- SetErrnoFromWinError (GetLastError ());
- GNUNET_free (*m);
- return NULL;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ GNUNET_free (*m);
+ return NULL;
+ }
(*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len);
if (!(*m)->addr)
- {
- SetErrnoFromWinError (GetLastError ());
- CloseHandle ((*m)->h);
- GNUNET_free (*m);
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ CloseHandle ((*m)->h);
+ GNUNET_free (*m);
+ }
return (*m)->addr;
#else
(*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0);
GNUNET_assert (NULL != (*m)->addr);
if (MAP_FAILED == (*m)->addr)
- {
- GNUNET_free (*m);
- return NULL;
- }
+ {
+ GNUNET_free (*m);
+ return NULL;
+ }
(*m)->len = len;
return (*m)->addr;
#endif
int ret;
if (h == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifdef MINGW
ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR;
if (ret != GNUNET_OK)
SetErrnoFromWinError (GetLastError ());
if (!CloseHandle (h->h) && (ret == GNUNET_OK))
- {
- ret = GNUNET_SYSERR;
- SetErrnoFromWinError (GetLastError ());
- }
+ {
+ ret = GNUNET_SYSERR;
+ SetErrnoFromWinError (GetLastError ());
+ }
#else
ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
#endif
GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
{
if (h == NULL)
- {
- errno = EINVAL;
- return GNUNET_SYSERR;
- }
+ {
+ errno = EINVAL;
+ return GNUNET_SYSERR;
+ }
#ifdef MINGW
int ret;
unlike CreatePipe, which returns a bool for success or failure. */
static int
create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
- LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize,
- DWORD dwReadMode, DWORD dwWriteMode)
+ LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize,
+ DWORD dwReadMode, DWORD dwWriteMode)
{
/* Default to error. */
*read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
* Retrying will probably never be necessary, but we want
* to be as robust as possible. */
while (1)
- {
- static volatile LONG pipe_unique_id;
+ {
+ static volatile LONG pipe_unique_id;
- snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld",
- getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id));
+ snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld",
+ getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id));
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "CreateNamedPipe: name = %s, size = %lu\n", pipename, psize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n",
+ pipename, psize);
#endif
- /* Use CreateNamedPipe instead of CreatePipe, because the latter
- * returns a write handle that does not permit FILE_READ_ATTRIBUTES
- * access, on versions of win32 earlier than WinXP SP2.
- * CreatePipe also stupidly creates a full duplex pipe, which is
- * a waste, since only a single direction is actually used.
- * It's important to only allow a single instance, to ensure that
- * the pipe was not created earlier by some other process, even if
- * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE
- * because that is only available for Win2k SP2 and WinXP. */
- read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */
- psize, /* output buffer size */
- psize, /* input buffer size */
- NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
-
- if (read_pipe != INVALID_HANDLE_VALUE)
- {
+ /* Use CreateNamedPipe instead of CreatePipe, because the latter
+ * returns a write handle that does not permit FILE_READ_ATTRIBUTES
+ * access, on versions of win32 earlier than WinXP SP2.
+ * CreatePipe also stupidly creates a full duplex pipe, which is
+ * a waste, since only a single direction is actually used.
+ * It's important to only allow a single instance, to ensure that
+ * the pipe was not created earlier by some other process, even if
+ * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE
+ * because that is only available for Win2k SP2 and WinXP. */
+ read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */
+ psize, /* output buffer size */
+ psize, /* input buffer size */
+ NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
+
+ if (read_pipe != INVALID_HANDLE_VALUE)
+ {
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe);
#endif
- break;
- }
+ break;
+ }
- DWORD err = GetLastError ();
+ DWORD err = GetLastError ();
- switch (err)
- {
- case ERROR_PIPE_BUSY:
- /* The pipe is already open with compatible parameters.
- * Pick a new name and retry. */
+ switch (err)
+ {
+ case ERROR_PIPE_BUSY:
+ /* The pipe is already open with compatible parameters.
+ * Pick a new name and retry. */
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n");
#endif
- continue;
- case ERROR_ACCESS_DENIED:
- /* The pipe is already open with incompatible parameters.
- * Pick a new name and retry. */
+ continue;
+ case ERROR_ACCESS_DENIED:
+ /* The pipe is already open with incompatible parameters.
+ * Pick a new name and retry. */
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n");
#endif
- continue;
- case ERROR_CALL_NOT_IMPLEMENTED:
- /* We are on an older Win9x platform without named pipes.
- * Return an anonymous pipe as the best approximation. */
+ continue;
+ case ERROR_CALL_NOT_IMPLEMENTED:
+ /* We are on an older Win9x platform without named pipes.
+ * Return an anonymous pipe as the best approximation. */
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "CreateNamedPipe not implemented, resorting to "
- "CreatePipe: size = %lu\n", psize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "CreateNamedPipe not implemented, resorting to "
+ "CreatePipe: size = %lu\n", psize);
#endif
- if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
- {
+ if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
+ {
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n",
- *read_pipe_ptr);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n",
- *write_pipe_ptr);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n",
+ *read_pipe_ptr);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n",
+ *write_pipe_ptr);
#endif
- return GNUNET_OK;
- }
- err = GetLastError ();
- LOG (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err);
- return err;
- default:
- LOG (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err);
- return err;
- }
- /* NOTREACHED */
+ return GNUNET_OK;
+ }
+ err = GetLastError ();
+ LOG (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err);
+ return err;
+ default:
+ LOG (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err);
+ return err;
}
+ /* NOTREACHED */
+ }
#if DEBUG_PIPE
LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename);
#endif
/* Open the named pipe for writing.
* Be sure to permit FILE_READ_ATTRIBUTES access. */
- write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */
- sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */
- 0); /* handle to template file */
+ write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */
+ sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */
+ 0); /* handle to template file */
if (write_pipe == INVALID_HANDLE_VALUE)
- {
- /* Failure. */
- DWORD err = GetLastError ();
+ {
+ /* Failure. */
+ DWORD err = GetLastError ();
#if DEBUG_PIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err);
#endif
- CloseHandle (read_pipe);
- return err;
- }
+ CloseHandle (read_pipe);
+ return err;
+ }
#if DEBUG_PIPE
LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe);
#endif
struct GNUNET_DISK_FileHandle *fds;
p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) +
- 2 * sizeof (struct GNUNET_DISK_FileHandle));
+ 2 * sizeof (struct GNUNET_DISK_FileHandle));
fds = (struct GNUNET_DISK_FileHandle *) &p[1];
p->fd[0] = &fds[0];
p->fd[1] = &fds[1];
ret = pipe (fd);
if (ret == -1)
- {
- eno = errno;
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
- GNUNET_free (p);
- errno = eno;
- return NULL;
- }
+ {
+ eno = errno;
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
+ GNUNET_free (p);
+ errno = eno;
+ return NULL;
+ }
p->fd[0]->fd = fd[0];
p->fd[1]->fd = fd[1];
ret = 0;
if (0 > fcntl (fd[1], F_SETFD, flags))
ret = -1;
if (ret == -1)
- {
- eno = errno;
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl");
- GNUNET_break (0 == close (p->fd[0]->fd));
- GNUNET_break (0 == close (p->fd[1]->fd));
- GNUNET_free (p);
- errno = eno;
- return NULL;
- }
+ {
+ eno = errno;
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl");
+ GNUNET_break (0 == close (p->fd[0]->fd));
+ GNUNET_break (0 == close (p->fd[1]->fd));
+ GNUNET_free (p);
+ errno = eno;
+ return NULL;
+ }
#else
BOOL ret;
HANDLE tmp_handle;
ret =
- create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0,
- FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED);
+ create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0,
+ FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED);
if (!ret)
- {
- GNUNET_free (p);
- SetErrnoFromWinError (GetLastError ());
- return NULL;
- }
+ {
+ GNUNET_free (p);
+ SetErrnoFromWinError (GetLastError ());
+ return NULL;
+ }
if (!DuplicateHandle
- (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle,
- 0, inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
- {
- SetErrnoFromWinError (GetLastError ());
- CloseHandle (p->fd[0]->h);
- CloseHandle (p->fd[1]->h);
- GNUNET_free (p);
- return NULL;
- }
+ (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0,
+ inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ CloseHandle (p->fd[0]->h);
+ CloseHandle (p->fd[1]->h);
+ GNUNET_free (p);
+ return NULL;
+ }
CloseHandle (p->fd[0]->h);
p->fd[0]->h = tmp_handle;
if (!DuplicateHandle
- (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle,
- 0, inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
- {
- SetErrnoFromWinError (GetLastError ());
- CloseHandle (p->fd[0]->h);
- CloseHandle (p->fd[1]->h);
- GNUNET_free (p);
- return NULL;
- }
+ (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0,
+ inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ CloseHandle (p->fd[0]->h);
+ CloseHandle (p->fd[1]->h);
+ GNUNET_free (p);
+ return NULL;
+ }
CloseHandle (p->fd[1]->h);
p->fd[1]->h = tmp_handle;
if (!blocking)
- {
- DWORD mode;
-
- mode = PIPE_NOWAIT;
- SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
- SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
- /* this always fails on Windows 95, so we don't care about error handling */
- }
+ {
+ DWORD mode;
+
+ mode = PIPE_NOWAIT;
+ SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
+ SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
+ /* this always fails on Windows 95, so we don't care about error handling */
+ }
p->fd[0]->type = GNUNET_PIPE;
p->fd[1]->type = GNUNET_PIPE;
*/
int
GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
- enum GNUNET_DISK_PipeEnd end)
+ enum GNUNET_DISK_PipeEnd end)
{
int ret = GNUNET_OK;
int save;
#ifdef MINGW
if (end == GNUNET_DISK_PIPE_END_READ)
+ {
+ if (!CloseHandle (p->fd[0]->h))
{
- if (!CloseHandle (p->fd[0]->h))
- {
- SetErrnoFromWinError (GetLastError ());
- ret = GNUNET_SYSERR;
- }
- p->fd[0]->h = INVALID_HANDLE_VALUE;
+ SetErrnoFromWinError (GetLastError ());
+ ret = GNUNET_SYSERR;
}
+ p->fd[0]->h = INVALID_HANDLE_VALUE;
+ }
else if (end == GNUNET_DISK_PIPE_END_WRITE)
+ {
+ if (!CloseHandle (p->fd[1]->h))
{
- if (!CloseHandle (p->fd[1]->h))
- {
- SetErrnoFromWinError (GetLastError ());
- ret = GNUNET_SYSERR;
- }
- p->fd[1]->h = INVALID_HANDLE_VALUE;
+ SetErrnoFromWinError (GetLastError ());
+ ret = GNUNET_SYSERR;
}
+ p->fd[1]->h = INVALID_HANDLE_VALUE;
+ }
save = errno;
#else
save = 0;
if (end == GNUNET_DISK_PIPE_END_READ)
+ {
+ if (0 != close (p->fd[0]->fd))
{
- if (0 != close (p->fd[0]->fd))
- {
- ret = GNUNET_SYSERR;
- save = errno;
- }
- p->fd[0]->fd = -1;
+ ret = GNUNET_SYSERR;
+ save = errno;
}
+ p->fd[0]->fd = -1;
+ }
else if (end == GNUNET_DISK_PIPE_END_WRITE)
+ {
+ if (0 != close (p->fd[1]->fd))
{
- if (0 != close (p->fd[1]->fd))
- {
- ret = GNUNET_SYSERR;
- save = errno;
- }
- p->fd[1]->fd = -1;
+ ret = GNUNET_SYSERR;
+ save = errno;
}
+ p->fd[1]->fd = -1;
+ }
#endif
errno = save;
return ret;
#ifdef MINGW
if (!CloseHandle (p->fd[0]->h))
- {
- SetErrnoFromWinError (GetLastError ());
- ret = GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ ret = GNUNET_SYSERR;
+ }
if (!CloseHandle (p->fd[1]->h))
- {
- SetErrnoFromWinError (GetLastError ());
- ret = GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ ret = GNUNET_SYSERR;
+ }
save = errno;
#else
save = 0;
if (p->fd[0]->fd != -1)
+ {
+ if (0 != close (p->fd[0]->fd))
{
- if (0 != close (p->fd[0]->fd))
- {
- ret = GNUNET_SYSERR;
- save = errno;
- }
+ ret = GNUNET_SYSERR;
+ save = errno;
}
+ }
if (p->fd[1]->fd != -1)
+ {
+ if (0 != close (p->fd[1]->fd))
{
- if (0 != close (p->fd[1]->fd))
- {
- ret = GNUNET_SYSERR;
- save = errno;
- }
+ ret = GNUNET_SYSERR;
+ save = errno;
}
+ }
#endif
GNUNET_free (p);
errno = save;
*/
struct GNUNET_DISK_FileHandle *
GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
- enum GNUNET_DISK_AccessPermissions perm)
+ enum GNUNET_DISK_AccessPermissions perm)
{
#ifdef MINGW
struct GNUNET_DISK_FileHandle *ret;
openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE;
while (h == NULL)
- {
- DWORD error_code;
+ {
+ DWORD error_code;
- name = NULL;
- if (*fn != NULL)
- {
- GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn);
+ name = NULL;
+ if (*fn != NULL)
+ {
+ GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn);
#if DEBUG_NPIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to create an instance of named pipe `%s'\n", name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to create an instance of named pipe `%s'\n", name);
#endif
- h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED,
- PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1,
- 0, NULL);
- }
- else
- {
- GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu",
- GNUNET_CRYPTO_random_u64
- (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
+ h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED,
+ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0,
+ NULL);
+ }
+ else
+ {
+ GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu",
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT64_MAX));
#if DEBUG_NPIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to create unique named pipe `%s'\n", *fn);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to create unique named pipe `%s'\n",
+ *fn);
#endif
- h = CreateNamedPipe (*fn,
- openMode | FILE_FLAG_OVERLAPPED |
- FILE_FLAG_FIRST_PIPE_INSTANCE,
- PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1,
- 0, NULL);
- }
- error_code = GetLastError ();
- if (name)
- GNUNET_free (name);
- /* don't re-set name to NULL yet */
- if (h == INVALID_HANDLE_VALUE)
- {
- SetErrnoFromWinError (error_code);
+ h = CreateNamedPipe (*fn,
+ openMode | FILE_FLAG_OVERLAPPED |
+ FILE_FLAG_FIRST_PIPE_INSTANCE,
+ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0,
+ NULL);
+ }
+ error_code = GetLastError ();
+ if (name)
+ GNUNET_free (name);
+ /* don't re-set name to NULL yet */
+ if (h == INVALID_HANDLE_VALUE)
+ {
+ SetErrnoFromWinError (error_code);
#if DEBUG_NPIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Pipe creation have failed because of %d, errno is %d\n",
- error_code, errno);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Pipe creation have failed because of %d, errno is %d\n", error_code,
+ errno);
#endif
- if (name == NULL)
- {
+ if (name == NULL)
+ {
#if DEBUG_NPIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Pipe was to be unique, considering re-creation\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Pipe was to be unique, considering re-creation\n");
#endif
- GNUNET_free (*fn);
- *fn = NULL;
- if (error_code != ERROR_ACCESS_DENIED
- && error_code != ERROR_PIPE_BUSY)
- {
- return NULL;
- }
+ GNUNET_free (*fn);
+ *fn = NULL;
+ if (error_code != ERROR_ACCESS_DENIED && error_code != ERROR_PIPE_BUSY)
+ {
+ return NULL;
+ }
#if DEBUG_NPIPE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Pipe name was not unique, trying again\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Pipe name was not unique, trying again\n");
#endif
- h = NULL;
- }
- else
- return NULL;
- }
+ h = NULL;
+ }
+ else
+ return NULL;
}
+ }
errno = 0;
ret = GNUNET_malloc (sizeof (*ret));
return ret;
#else
if (*fn == NULL)
+ {
+ char dir[] = "/tmp/gnunet-pipe-XXXXXX";
+
+ if (mkdtemp (dir) == NULL)
{
- char dir[] = "/tmp/gnunet-pipe-XXXXXX";
-
- if (mkdtemp (dir) == NULL)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp");
- return NULL;
- }
- GNUNET_asprintf (fn, "%s/child-control", dir);
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp");
+ return NULL;
}
+ GNUNET_asprintf (fn, "%s/child-control", dir);
+ }
if (mkfifo (*fn, translate_unix_perms (perm)) == -1)
- {
- if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)))
- return NULL;
- }
+ {
+ if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)))
+ return NULL;
+ }
flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS);
return GNUNET_DISK_file_open (*fn, flags, perm);
*/
struct GNUNET_DISK_FileHandle *
GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
- enum GNUNET_DISK_AccessPermissions perm)
+ enum GNUNET_DISK_AccessPermissions perm)
{
#ifdef MINGW
struct GNUNET_DISK_FileHandle *ret;
openMode = GENERIC_WRITE;
h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING,
- FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL);
+ FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL);
if (h == INVALID_HANDLE_VALUE)
- {
- SetErrnoFromWinError (GetLastError ());
- return NULL;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return NULL;
+ }
ret = GNUNET_malloc (sizeof (*ret));
ret->h = h;
ret = CloseHandle (pipe->h);
if (!ret)
- {
- SetErrnoFromWinError (GetLastError ());
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
else
return GNUNET_OK;
#endif
*/
const struct GNUNET_DISK_FileHandle *
GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
- enum GNUNET_DISK_PipeEnd n)
+ enum GNUNET_DISK_PipeEnd n)
{
switch (n)
- {
- case GNUNET_DISK_PIPE_END_READ:
- case GNUNET_DISK_PIPE_END_WRITE:
- return p->fd[n];
- default:
- GNUNET_break (0);
- return NULL;
- }
+ {
+ case GNUNET_DISK_PIPE_END_READ:
+ case GNUNET_DISK_PIPE_END_WRITE:
+ return p->fd[n];
+ default:
+ GNUNET_break (0);
+ return NULL;
+ }
}
*/
int
GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
- void *dst, size_t dst_len)
+ void *dst, size_t dst_len)
{
#ifdef MINGW
if (dst_len < sizeof (HANDLE))
/* Avoid depending on library functions or files
whose names are inconsistent. */
-char *getenv ();
+char *
+getenv ();
static char *
my_index (str, chr)
- const char *str;
- int chr;
+ const char *str;
+ int chr;
{
while (*str)
- {
- if (*str == chr)
- return (char *) str;
- str++;
- }
+ {
+ if (*str == chr)
+ return (char *) str;
+ str++;
+ }
return 0;
}
#if !defined (__STDC__) || !__STDC__
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
-extern int strlen (const char *);
+extern int
+strlen (const char *);
#endif /* not __STDC__ */
#endif /* __GNUC__ */
is valid for the getopt call we must make sure that the ARGV passed
to getopt is that one passed to the process. */
static void
- __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv)
+ __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv)
{
/* XXX This is no good solution. We should rather copy the args so
* that we can compare them later. But we must not use malloc(3). */
the new indices of the non-options in ARGV after they are moved. */
#if defined (__STDC__) && __STDC__
-static void exchange (char **);
+static void
+exchange (char **);
#endif
static void
exchange (argv)
- char **argv;
+ char **argv;
{
int bottom = first_nonopt;
int middle = last_nonopt;
* string can work normally. Our top argument must be in the range
* of the string. */
if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
- {
- /* We must extend the array. The user plays games with us and
- * presents new arguments. */
- char *new_str = malloc (top + 1);
+ {
+ /* We must extend the array. The user plays games with us and
+ * presents new arguments. */
+ char *new_str = malloc (top + 1);
- if (new_str == NULL)
- nonoption_flags_len = nonoption_flags_max_len = 0;
- else
- {
- memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len);
- memset (&new_str[nonoption_flags_max_len], '\0',
- top + 1 - nonoption_flags_max_len);
- nonoption_flags_max_len = top + 1;
- __getopt_nonoption_flags = new_str;
- }
+ if (new_str == NULL)
+ nonoption_flags_len = nonoption_flags_max_len = 0;
+ else
+ {
+ memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len);
+ memset (&new_str[nonoption_flags_max_len], '\0',
+ top + 1 - nonoption_flags_max_len);
+ nonoption_flags_max_len = top + 1;
+ __getopt_nonoption_flags = new_str;
}
+ }
#endif
while (top > middle && middle > bottom)
+ {
+ if (top - middle > middle - bottom)
{
- if (top - middle > middle - bottom)
- {
- /* Bottom segment is the short one. */
- int len = middle - bottom;
- register int i;
-
- /* Swap it with the top part of the top segment. */
- for (i = 0; i < len; i++)
- {
- tem = argv[bottom + i];
- argv[bottom + i] = argv[top - (middle - bottom) + i];
- argv[top - (middle - bottom) + i] = tem;
- SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
- }
- /* Exclude the moved bottom segment from further swapping. */
- top -= len;
- }
- else
- {
- /* Top segment is the short one. */
- int len = top - middle;
- register int i;
-
- /* Swap it with the bottom part of the bottom segment. */
- for (i = 0; i < len; i++)
- {
- tem = argv[bottom + i];
- argv[bottom + i] = argv[middle + i];
- argv[middle + i] = tem;
- SWAP_FLAGS (bottom + i, middle + i);
- }
- /* Exclude the moved top segment from further swapping. */
- bottom += len;
- }
+ /* Bottom segment is the short one. */
+ int len = middle - bottom;
+ register int i;
+
+ /* Swap it with the top part of the top segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[top - (middle - bottom) + i];
+ argv[top - (middle - bottom) + i] = tem;
+ SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
+ }
+ /* Exclude the moved bottom segment from further swapping. */
+ top -= len;
+ }
+ else
+ {
+ /* Top segment is the short one. */
+ int len = top - middle;
+ register int i;
+
+ /* Swap it with the bottom part of the bottom segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[middle + i];
+ argv[middle + i] = tem;
+ SWAP_FLAGS (bottom + i, middle + i);
+ }
+ /* Exclude the moved top segment from further swapping. */
+ bottom += len;
}
+ }
/* Update records for the slots the non-options now occupy. */
/* Initialize the internal data when the first call is made. */
#if defined (__STDC__) && __STDC__
-static const char *_getopt_initialize (int, char *const *, const char *);
+static const char *
+_getopt_initialize (int, char *const *, const char *);
#endif
static const char *
_getopt_initialize (argc, argv, optstring)
- int argc;
- char *const *argv;
- const char *optstring;
+ int argc;
+ char *const *argv;
+ const char *optstring;
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
* is the program name); the sequence of previously skipped
/* Determine how to handle the ordering of options and nonoptions. */
if (optstring[0] == '-')
- {
- ordering = RETURN_IN_ORDER;
- ++optstring;
- }
+ {
+ ordering = RETURN_IN_ORDER;
+ ++optstring;
+ }
else if (optstring[0] == '+')
- {
- ordering = REQUIRE_ORDER;
- ++optstring;
- }
+ {
+ ordering = REQUIRE_ORDER;
+ ++optstring;
+ }
else if (posixly_correct != NULL)
ordering = REQUIRE_ORDER;
else
ordering = PERMUTE;
#ifdef _LIBC
- if (posixly_correct == NULL && argc == original_argc
- && argv == original_argv)
+ if (posixly_correct == NULL && argc == original_argc && argv == original_argv)
+ {
+ if (nonoption_flags_max_len == 0)
{
- if (nonoption_flags_max_len == 0)
- {
- if (__getopt_nonoption_flags == NULL ||
- __getopt_nonoption_flags[0] == '\0')
- nonoption_flags_max_len = -1;
- else
- {
- const char *orig_str = __getopt_nonoption_flags;
- int len = nonoption_flags_max_len = strlen (orig_str);
-
- if (nonoption_flags_max_len < argc)
- nonoption_flags_max_len = argc;
- __getopt_nonoption_flags =
- (char *) malloc (nonoption_flags_max_len);
- if (__getopt_nonoption_flags == NULL)
- nonoption_flags_max_len = -1;
- else
- {
- memcpy (__getopt_nonoption_flags, orig_str, len);
- memset (&__getopt_nonoption_flags[len], '\0',
- nonoption_flags_max_len - len);
- }
- }
- }
- nonoption_flags_len = nonoption_flags_max_len;
+ if (__getopt_nonoption_flags == NULL ||
+ __getopt_nonoption_flags[0] == '\0')
+ nonoption_flags_max_len = -1;
+ else
+ {
+ const char *orig_str = __getopt_nonoption_flags;
+ int len = nonoption_flags_max_len = strlen (orig_str);
+
+ if (nonoption_flags_max_len < argc)
+ nonoption_flags_max_len = argc;
+ __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len);
+ if (__getopt_nonoption_flags == NULL)
+ nonoption_flags_max_len = -1;
+ else
+ {
+ memcpy (__getopt_nonoption_flags, orig_str, len);
+ memset (&__getopt_nonoption_flags[len], '\0',
+ nonoption_flags_max_len - len);
+ }
+ }
}
+ nonoption_flags_len = nonoption_flags_max_len;
+ }
else
nonoption_flags_len = 0;
#endif
static int
GN_getopt_internal (int argc, char *const *argv, const char *optstring,
- const struct GNoption *longopts, int *longind,
- int long_only)
+ const struct GNoption *longopts, int *longind,
+ int long_only)
{
static int __getopt_initialized = 0;
static int GNopterr = 1;
GNoptarg = NULL;
if (GNoptind == 0 || !__getopt_initialized)
- {
- if (GNoptind == 0)
- GNoptind = 1; /* Don't scan ARGV[0], the program name. */
- optstring = _getopt_initialize (argc, argv, optstring);
- __getopt_initialized = 1;
- }
+ {
+ if (GNoptind == 0)
+ GNoptind = 1; /* Don't scan ARGV[0], the program name. */
+ optstring = _getopt_initialize (argc, argv, optstring);
+ __getopt_initialized = 1;
+ }
/* Test whether ARGV[GNoptind] points to a non-option argument.
* Either it does not have option syntax, or there is an environment flag
#endif
if (nextchar == NULL || *nextchar == '\0')
+ {
+ /* Advance to the next ARGV-element. */
+
+ /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been
+ * moved back by the user (who may also have changed the arguments). */
+ if (last_nonopt > GNoptind)
+ last_nonopt = GNoptind;
+ if (first_nonopt > GNoptind)
+ first_nonopt = GNoptind;
+
+ if (ordering == PERMUTE)
{
- /* Advance to the next ARGV-element. */
-
- /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been
- * moved back by the user (who may also have changed the arguments). */
- if (last_nonopt > GNoptind)
- last_nonopt = GNoptind;
- if (first_nonopt > GNoptind)
- first_nonopt = GNoptind;
-
- if (ordering == PERMUTE)
- {
- /* If we have just processed some options following some non-options,
- * exchange them so that the options come first. */
-
- if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
- exchange ((char **) argv);
- else if (last_nonopt != GNoptind)
- first_nonopt = GNoptind;
-
- /* Skip any additional non-options
- * and extend the range of non-options previously skipped. */
-
- while (GNoptind < argc && NONOPTION_P)
- GNoptind++;
- last_nonopt = GNoptind;
- }
-
- /* The special ARGV-element `--' means premature end of options.
- * Skip it like a null option,
- * then exchange with previous non-options as if it were an option,
- * then skip everything else like a non-option. */
- if (GNoptind != argc && !strcmp (argv[GNoptind], "--"))
- {
- GNoptind++;
-
- if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
- exchange ((char **) argv);
- else if (first_nonopt == last_nonopt)
- first_nonopt = GNoptind;
- last_nonopt = argc;
-
- GNoptind = argc;
- }
-
- /* If we have done all the ARGV-elements, stop the scan
- * and back over any non-options that we skipped and permuted. */
-
- if (GNoptind == argc)
- {
- /* Set the next-arg-index to point at the non-options
- * that we previously skipped, so the caller will digest them. */
- if (first_nonopt != last_nonopt)
- GNoptind = first_nonopt;
- return -1;
- }
-
- /* If we have come to a non-option and did not permute it,
- * either stop the scan or describe it to the caller and pass it by. */
-
- if (NONOPTION_P)
- {
- if (ordering == REQUIRE_ORDER)
- return -1;
- GNoptarg = argv[GNoptind++];
- return 1;
- }
-
- /* We have found another option-ARGV-element.
- * Skip the initial punctuation. */
-
- nextchar =
- (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
+ /* If we have just processed some options following some non-options,
+ * exchange them so that the options come first. */
+
+ if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
+ exchange ((char **) argv);
+ else if (last_nonopt != GNoptind)
+ first_nonopt = GNoptind;
+
+ /* Skip any additional non-options
+ * and extend the range of non-options previously skipped. */
+
+ while (GNoptind < argc && NONOPTION_P)
+ GNoptind++;
+ last_nonopt = GNoptind;
+ }
+
+ /* The special ARGV-element `--' means premature end of options.
+ * Skip it like a null option,
+ * then exchange with previous non-options as if it were an option,
+ * then skip everything else like a non-option. */
+ if (GNoptind != argc && !strcmp (argv[GNoptind], "--"))
+ {
+ GNoptind++;
+
+ if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
+ exchange ((char **) argv);
+ else if (first_nonopt == last_nonopt)
+ first_nonopt = GNoptind;
+ last_nonopt = argc;
+
+ GNoptind = argc;
}
+ /* If we have done all the ARGV-elements, stop the scan
+ * and back over any non-options that we skipped and permuted. */
+
+ if (GNoptind == argc)
+ {
+ /* Set the next-arg-index to point at the non-options
+ * that we previously skipped, so the caller will digest them. */
+ if (first_nonopt != last_nonopt)
+ GNoptind = first_nonopt;
+ return -1;
+ }
+
+ /* If we have come to a non-option and did not permute it,
+ * either stop the scan or describe it to the caller and pass it by. */
+
+ if (NONOPTION_P)
+ {
+ if (ordering == REQUIRE_ORDER)
+ return -1;
+ GNoptarg = argv[GNoptind++];
+ return 1;
+ }
+
+ /* We have found another option-ARGV-element.
+ * Skip the initial punctuation. */
+
+ nextchar =
+ (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
+ }
+
/* Decode the current option-ARGV-element. */
/* Check whether the ARGV-element is a long option.
if (longopts != NULL &&
(argv[GNoptind][1] == '-' ||
(long_only &&
- (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
- {
- char *nameend;
- const struct GNoption *p;
- const struct GNoption *pfound = NULL;
- int exact = 0;
- int ambig = 0;
- int indfound = -1;
- int option_index;
-
- for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
- /* Do nothing. */ ;
+ (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
+ {
+ char *nameend;
+ const struct GNoption *p;
+ const struct GNoption *pfound = NULL;
+ int exact = 0;
+ int ambig = 0;
+ int indfound = -1;
+ int option_index;
+
+ for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
+ /* Do nothing. */ ;
+
+ /* Test all long options for either exact match
+ * or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, nextchar, nameend - nextchar))
+ {
+ if ((unsigned int) (nameend - nextchar) ==
+ (unsigned int) strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else
+ /* Second or later nonexact match found. */
+ ambig = 1;
+ }
- /* Test all long options for either exact match
- * or abbreviated matches. */
- for (p = longopts, option_index = 0; p->name; p++, option_index++)
- if (!strncmp (p->name, nextchar, nameend - nextchar))
- {
- if ((unsigned int) (nameend - nextchar) ==
- (unsigned int) strlen (p->name))
- {
- /* Exact match found. */
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- }
- else if (pfound == NULL)
- {
- /* First nonexact match found. */
- pfound = p;
- indfound = option_index;
- }
- else
- /* Second or later nonexact match found. */
- ambig = 1;
- }
+ if (ambig && !exact)
+ {
+ if (GNopterr)
+ fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0],
+ argv[GNoptind]);
+ nextchar += strlen (nextchar);
+ GNoptind++;
+ return '?';
+ }
- if (ambig && !exact)
- {
- if (GNopterr)
- fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0],
- argv[GNoptind]);
- nextchar += strlen (nextchar);
- GNoptind++;
- return '?';
- }
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ GNoptind++;
+ if (*nameend)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ * allow it to be used on enums. */
+ if (pfound->has_arg)
+ GNoptarg = nameend + 1;
+ else
+ {
+ if (GNopterr)
+ {
+ if (argv[GNoptind - 1][1] == '-')
+ /* --option */
+ fprintf (stderr,
+ _("%s: option `--%s' does not allow an argument\n"),
+ argv[0], pfound->name);
+ else
+ /* +option or -option */
+ fprintf (stderr,
+ _("%s: option `%c%s' does not allow an argument\n"),
+ argv[0], argv[GNoptind - 1][0], pfound->name);
+ }
+ nextchar += strlen (nextchar);
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (GNoptind < argc)
+ {
+ GNoptarg = argv[GNoptind++];
+ }
+ else
+ {
+ if (GNopterr)
+ {
+ fprintf (stderr, _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[GNoptind - 1]);
+ }
+ nextchar += strlen (nextchar);
+ return (optstring[0] == ':') ? ':' : '?';
+ }
+ }
+ nextchar += strlen (nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
- if (pfound != NULL)
- {
- option_index = indfound;
- GNoptind++;
- if (*nameend)
- {
- /* Don't test has_arg with >, because some C compilers don't
- * allow it to be used on enums. */
- if (pfound->has_arg)
- GNoptarg = nameend + 1;
- else
- {
- if (GNopterr)
- {
- if (argv[GNoptind - 1][1] == '-')
- /* --option */
- fprintf (stderr,
- _
- ("%s: option `--%s' does not allow an argument\n"),
- argv[0], pfound->name);
- else
- /* +option or -option */
- fprintf (stderr,
- _
- ("%s: option `%c%s' does not allow an argument\n"),
- argv[0], argv[GNoptind - 1][0],
- pfound->name);
- }
- nextchar += strlen (nextchar);
- return '?';
- }
- }
- else if (pfound->has_arg == 1)
- {
- if (GNoptind < argc)
- {
- GNoptarg = argv[GNoptind++];
- }
- else
- {
- if (GNopterr)
- {
- fprintf (stderr,
- _("%s: option `%s' requires an argument\n"),
- argv[0], argv[GNoptind - 1]);
- }
- nextchar += strlen (nextchar);
- return (optstring[0] == ':') ? ':' : '?';
- }
- }
- nextchar += strlen (nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag)
- {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
-
- /* Can't find it as a long option. If this is not getopt_long_only,
- * or the option starts with '--' or is not a valid short
- * option, then it's an error.
- * Otherwise interpret it as a short option. */
- if (!long_only || argv[GNoptind][1] == '-' ||
- my_index (optstring, *nextchar) == NULL)
- {
- if (GNopterr)
- {
- if (argv[GNoptind][1] == '-')
- /* --option */
- fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
- argv[0], nextchar);
- else
- /* +option or -option */
- fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
- argv[0], argv[GNoptind][0], nextchar);
- }
- nextchar = (char *) "";
- GNoptind++;
- return '?';
- }
+ /* Can't find it as a long option. If this is not getopt_long_only,
+ * or the option starts with '--' or is not a valid short
+ * option, then it's an error.
+ * Otherwise interpret it as a short option. */
+ if (!long_only || argv[GNoptind][1] == '-' ||
+ my_index (optstring, *nextchar) == NULL)
+ {
+ if (GNopterr)
+ {
+ if (argv[GNoptind][1] == '-')
+ /* --option */
+ fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0],
+ nextchar);
+ else
+ /* +option or -option */
+ fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0],
+ argv[GNoptind][0], nextchar);
+ }
+ nextchar = (char *) "";
+ GNoptind++;
+ return '?';
}
+ }
/* Look at and handle the next short option-character. */
++GNoptind;
if (temp == NULL || c == ':')
+ {
+ if (GNopterr)
{
- if (GNopterr)
- {
- if (posixly_correct)
- /* 1003.2 specifies the format of this message. */
- fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
- else
- fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
- }
- return '?';
+ if (posixly_correct)
+ /* 1003.2 specifies the format of this message. */
+ fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
+ else
+ fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
}
+ return '?';
+ }
/* Convenience. Treat POSIX -W foo same as long option --foo */
if (temp[0] == 'W' && temp[1] == ';')
+ {
+ char *nameend;
+ const struct GNoption *p;
+ const struct GNoption *pfound = NULL;
+ int exact = 0;
+ int ambig = 0;
+ int indfound = 0;
+ int option_index;
+
+ /* This is an option that requires an argument. */
+ if (*nextchar != '\0')
{
- char *nameend;
- const struct GNoption *p;
- const struct GNoption *pfound = NULL;
- int exact = 0;
- int ambig = 0;
- int indfound = 0;
- int option_index;
-
- /* This is an option that requires an argument. */
- if (*nextchar != '\0')
- {
- GNoptarg = nextchar;
- /* If we end this ARGV-element by taking the rest as an arg,
- * we must advance to the next element now. */
- GNoptind++;
- }
- else if (GNoptind == argc)
- {
- if (GNopterr)
- {
- /* 1003.2 specifies the format of this message. */
- fprintf (stderr, _("%s: option requires an argument -- %c\n"),
- argv[0], c);
- }
- if (optstring[0] == ':')
- c = ':';
- else
- c = '?';
- return c;
- }
- else
- /* We already incremented `GNoptind' once;
- * increment it again when taking next ARGV-elt as argument. */
- GNoptarg = argv[GNoptind++];
-
- /* GNoptarg is now the argument, see if it's in the
- * table of longopts. */
-
- for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
- nameend++)
- /* Do nothing. */ ;
-
- /* Test all long options for either exact match
- * or abbreviated matches. */
- if (longopts != NULL)
- for (p = longopts, option_index = 0; p->name; p++, option_index++)
- if (!strncmp (p->name, nextchar, nameend - nextchar))
- {
- if ((unsigned int) (nameend - nextchar) == strlen (p->name))
- {
- /* Exact match found. */
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- }
- else if (pfound == NULL)
- {
- /* First nonexact match found. */
- pfound = p;
- indfound = option_index;
- }
- else
- /* Second or later nonexact match found. */
- ambig = 1;
- }
- if (ambig && !exact)
- {
- if (GNopterr)
- fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
- argv[0], argv[GNoptind]);
- nextchar += strlen (nextchar);
- GNoptind++;
- return '?';
- }
- if (pfound != NULL)
- {
- option_index = indfound;
- if (*nameend)
- {
- /* Don't test has_arg with >, because some C compilers don't
- * allow it to be used on enums. */
- if (pfound->has_arg)
- GNoptarg = nameend + 1;
- else
- {
- if (GNopterr)
- fprintf (stderr, _("\
+ GNoptarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ * we must advance to the next element now. */
+ GNoptind++;
+ }
+ else if (GNoptind == argc)
+ {
+ if (GNopterr)
+ {
+ /* 1003.2 specifies the format of this message. */
+ fprintf (stderr, _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
+ }
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = '?';
+ return c;
+ }
+ else
+ /* We already incremented `GNoptind' once;
+ * increment it again when taking next ARGV-elt as argument. */
+ GNoptarg = argv[GNoptind++];
+
+ /* GNoptarg is now the argument, see if it's in the
+ * table of longopts. */
+
+ for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
+ nameend++)
+ /* Do nothing. */ ;
+
+ /* Test all long options for either exact match
+ * or abbreviated matches. */
+ if (longopts != NULL)
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, nextchar, nameend - nextchar))
+ {
+ if ((unsigned int) (nameend - nextchar) == strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else
+ /* Second or later nonexact match found. */
+ ambig = 1;
+ }
+ if (ambig && !exact)
+ {
+ if (GNopterr)
+ fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0],
+ argv[GNoptind]);
+ nextchar += strlen (nextchar);
+ GNoptind++;
+ return '?';
+ }
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ if (*nameend)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ * allow it to be used on enums. */
+ if (pfound->has_arg)
+ GNoptarg = nameend + 1;
+ else
+ {
+ if (GNopterr)
+ fprintf (stderr, _("\
%s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name);
- nextchar += strlen (nextchar);
- return '?';
- }
- }
- else if (pfound->has_arg == 1)
- {
- if (GNoptind < argc)
- GNoptarg = argv[GNoptind++];
- else
- {
- if (GNopterr)
- fprintf (stderr,
- _("%s: option `%s' requires an argument\n"),
- argv[0], argv[GNoptind - 1]);
- nextchar += strlen (nextchar);
- return optstring[0] == ':' ? ':' : '?';
- }
- }
- nextchar += strlen (nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag)
- {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
- nextchar = NULL;
- return 'W'; /* Let the application handle it. */
+ nextchar += strlen (nextchar);
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (GNoptind < argc)
+ GNoptarg = argv[GNoptind++];
+ else
+ {
+ if (GNopterr)
+ fprintf (stderr, _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[GNoptind - 1]);
+ nextchar += strlen (nextchar);
+ return optstring[0] == ':' ? ':' : '?';
+ }
+ }
+ nextchar += strlen (nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
}
+ nextchar = NULL;
+ return 'W'; /* Let the application handle it. */
+ }
if (temp[1] == ':')
+ {
+ if (temp[2] == ':')
{
- if (temp[2] == ':')
- {
- /* This is an option that accepts an argument optionally. */
- if (*nextchar != '\0')
- {
- GNoptarg = nextchar;
- GNoptind++;
- }
- else
- GNoptarg = NULL;
- nextchar = NULL;
- }
- else
- {
- /* This is an option that requires an argument. */
- if (*nextchar != '\0')
- {
- GNoptarg = nextchar;
- /* If we end this ARGV-element by taking the rest as an arg,
- * we must advance to the next element now. */
- GNoptind++;
- }
- else if (GNoptind == argc)
- {
- if (GNopterr)
- {
- /* 1003.2 specifies the format of this message. */
- fprintf (stderr,
- _("%s: option requires an argument -- %c\n"),
- argv[0], c);
- }
- if (optstring[0] == ':')
- c = ':';
- else
- c = '?';
- }
- else
- /* We already incremented `GNoptind' once;
- * increment it again when taking next ARGV-elt as argument. */
- GNoptarg = argv[GNoptind++];
- nextchar = NULL;
- }
+ /* This is an option that accepts an argument optionally. */
+ if (*nextchar != '\0')
+ {
+ GNoptarg = nextchar;
+ GNoptind++;
+ }
+ else
+ GNoptarg = NULL;
+ nextchar = NULL;
}
+ else
+ {
+ /* This is an option that requires an argument. */
+ if (*nextchar != '\0')
+ {
+ GNoptarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ * we must advance to the next element now. */
+ GNoptind++;
+ }
+ else if (GNoptind == argc)
+ {
+ if (GNopterr)
+ {
+ /* 1003.2 specifies the format of this message. */
+ fprintf (stderr, _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
+ }
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = '?';
+ }
+ else
+ /* We already incremented `GNoptind' once;
+ * increment it again when taking next ARGV-elt as argument. */
+ GNoptarg = argv[GNoptind++];
+ nextchar = NULL;
+ }
+ }
return c;
}
}
static int
GNgetopt_long (int argc, char *const *argv, const char *options,
- const struct GNoption *long_options, int *opt_index)
+ const struct GNoption *long_options, int *opt_index)
{
return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
*/
int
GNUNET_GETOPT_run (const char *binaryOptions,
- const struct GNUNET_GETOPT_CommandLineOption *allOptions,
- unsigned int argc, char *const *argv)
+ const struct GNUNET_GETOPT_CommandLineOption *allOptions,
+ unsigned int argc, char *const *argv)
{
struct GNoption *long_options;
struct GNUNET_GETOPT_CommandLineProcessorContext clpc;
shorts = GNUNET_malloc (count * 2 + 1);
spos = 0;
for (i = 0; i < count; i++)
- {
- long_options[i].name = allOptions[i].name;
- long_options[i].has_arg = allOptions[i].require_argument;
- long_options[i].flag = NULL;
- long_options[i].val = allOptions[i].shortName;
- shorts[spos++] = allOptions[i].shortName;
- if (allOptions[i].require_argument != 0)
- shorts[spos++] = ':';
- }
+ {
+ long_options[i].name = allOptions[i].name;
+ long_options[i].has_arg = allOptions[i].require_argument;
+ long_options[i].flag = NULL;
+ long_options[i].val = allOptions[i].shortName;
+ shorts[spos++] = allOptions[i].shortName;
+ if (allOptions[i].require_argument != 0)
+ shorts[spos++] = ':';
+ }
long_options[count].name = NULL;
long_options[count].has_arg = 0;
long_options[count].flag = NULL;
cont = GNUNET_OK;
/* main getopt loop */
while (cont == GNUNET_OK)
+ {
+ int option_index = 0;
+
+ c = GNgetopt_long (argc, argv, shorts, long_options, &option_index);
+
+ if (c == GNUNET_SYSERR)
+ break; /* No more flags to process */
+
+ for (i = 0; i < count; i++)
+ {
+ clpc.currentArgument = GNoptind - 1;
+ if ((char) c == allOptions[i].shortName)
+ {
+ cont =
+ allOptions[i].processor (&clpc, allOptions[i].scls,
+ allOptions[i].name, GNoptarg);
+ break;
+ }
+ }
+ if (i == count)
{
- int option_index = 0;
-
- c = GNgetopt_long (argc, argv, shorts, long_options, &option_index);
-
- if (c == GNUNET_SYSERR)
- break; /* No more flags to process */
-
- for (i = 0; i < count; i++)
- {
- clpc.currentArgument = GNoptind - 1;
- if ((char) c == allOptions[i].shortName)
- {
- cont =
- allOptions[i].processor (&clpc, allOptions[i].scls,
- allOptions[i].name, GNoptarg);
- break;
- }
- }
- if (i == count)
- {
- fprintf (stderr, _("Use --help to get a list of options.\n"));
- cont = GNUNET_SYSERR;
- }
+ fprintf (stderr, _("Use --help to get a list of options.\n"));
+ cont = GNUNET_SYSERR;
}
+ }
GNUNET_free (shorts);
GNUNET_free (long_options);
*/
int
GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext
- *ctx, void *scls, const char *option,
- const char *value)
+ *ctx, void *scls, const char *option,
+ const char *value)
{
const char *version = scls;
*/
int
GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
- *ctx, void *scls, const char *option,
- const char *value)
+ *ctx, void *scls, const char *option,
+ const char *value)
{
const char *about = scls;
size_t slen;
printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
printf (_
- ("Arguments mandatory for long options are also mandatory for short options.\n"));
+ ("Arguments mandatory for long options are also mandatory for short options.\n"));
i = 0;
opt = ctx->allOptions;
while (opt[i].description != NULL)
+ {
+ if (opt[i].shortName == '\0')
+ printf (" ");
+ else
+ printf (" -%c, ", opt[i].shortName);
+ printf ("--%s", opt[i].name);
+ slen = 8 + strlen (opt[i].name);
+ if (opt[i].argumentHelp != NULL)
{
- if (opt[i].shortName == '\0')
- printf (" ");
- else
- printf (" -%c, ", opt[i].shortName);
- printf ("--%s", opt[i].name);
- slen = 8 + strlen (opt[i].name);
- if (opt[i].argumentHelp != NULL)
- {
- printf ("=%s", opt[i].argumentHelp);
- slen += 1 + strlen (opt[i].argumentHelp);
- }
- if (slen > BORDER)
- {
- printf ("\n%*s", BORDER, "");
- slen = BORDER;
- }
- if (slen < BORDER)
- {
- printf ("%*s", (int) (BORDER - slen), "");
- slen = BORDER;
- }
- if (0 < strlen (opt[i].description))
- trans = gettext (opt[i].description);
- else
- trans = "";
- ml = strlen (trans);
- p = 0;
- OUTER:
- while (ml - p > 78 - slen)
- {
- for (j = p + 78 - slen; j > p; j--)
- {
- if (isspace ((unsigned char) trans[j]))
- {
- scp = GNUNET_malloc (j - p + 1);
- memcpy (scp, &trans[p], j - p);
- scp[j - p] = '\0';
- printf ("%s\n%*s", scp, BORDER + 2, "");
- GNUNET_free (scp);
- p = j + 1;
- slen = BORDER + 2;
- goto OUTER;
- }
- }
- /* could not find space to break line */
- scp = GNUNET_malloc (78 - slen + 1);
- memcpy (scp, &trans[p], 78 - slen);
- scp[78 - slen] = '\0';
- printf ("%s\n%*s", scp, BORDER + 2, "");
- GNUNET_free (scp);
- slen = BORDER + 2;
- p = p + 78 - slen;
- }
- /* print rest */
- if (p < ml)
- printf ("%s\n", &trans[p]);
- if (strlen (trans) == 0)
- printf ("\n");
- i++;
+ printf ("=%s", opt[i].argumentHelp);
+ slen += 1 + strlen (opt[i].argumentHelp);
}
+ if (slen > BORDER)
+ {
+ printf ("\n%*s", BORDER, "");
+ slen = BORDER;
+ }
+ if (slen < BORDER)
+ {
+ printf ("%*s", (int) (BORDER - slen), "");
+ slen = BORDER;
+ }
+ if (0 < strlen (opt[i].description))
+ trans = gettext (opt[i].description);
+ else
+ trans = "";
+ ml = strlen (trans);
+ p = 0;
+OUTER:
+ while (ml - p > 78 - slen)
+ {
+ for (j = p + 78 - slen; j > p; j--)
+ {
+ if (isspace ((unsigned char) trans[j]))
+ {
+ scp = GNUNET_malloc (j - p + 1);
+ memcpy (scp, &trans[p], j - p);
+ scp[j - p] = '\0';
+ printf ("%s\n%*s", scp, BORDER + 2, "");
+ GNUNET_free (scp);
+ p = j + 1;
+ slen = BORDER + 2;
+ goto OUTER;
+ }
+ }
+ /* could not find space to break line */
+ scp = GNUNET_malloc (78 - slen + 1);
+ memcpy (scp, &trans[p], 78 - slen);
+ scp[78 - slen] = '\0';
+ printf ("%s\n%*s", scp, BORDER + 2, "");
+ GNUNET_free (scp);
+ slen = BORDER + 2;
+ p = p + 78 - slen;
+ }
+ /* print rest */
+ if (p < ml)
+ printf ("%s\n", &trans[p]);
+ if (strlen (trans) == 0)
+ printf ("\n");
+ i++;
+ }
printf ("Report bugs to gnunet-developers@gnu.org.\n"
- "GNUnet home page: http://www.gnu.org/software/gnunet/\n"
- "General help using GNU software: http://www.gnu.org/gethelp/\n");
+ "GNUnet home page: http://www.gnu.org/software/gnunet/\n"
+ "General help using GNU software: http://www.gnu.org/gethelp/\n");
return GNUNET_SYSERR;
}
* @return GNUNET_OK
*/
int
-GNUNET_GETOPT_increment_value (struct
- GNUNET_GETOPT_CommandLineProcessorContext *ctx,
- void *scls, const char *option,
- const char *value)
+GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext
+ *ctx, void *scls, const char *option,
+ const char *value)
{
int *val = scls;
*/
int
GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
- void *scls, const char *option, const char *value)
+ void *scls, const char *option, const char *value)
{
int *val = scls;
* @return GNUNET_OK
*/
int
-GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext
- *ctx, void *scls, const char *option,
- const char *value)
+GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+ void *scls, const char *option, const char *value)
{
char **val = scls;
* @return GNUNET_OK if parsing the value worked
*/
int
-GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext
- *ctx, void *scls, const char *option,
- const char *value)
+GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+ void *scls, const char *option, const char *value)
{
unsigned long long *val = scls;
if (1 != SSCANF (value, "%llu", val))
- {
- fprintf (stderr, _("You must pass a number to the `%s' option.\n"),
- option);
- return GNUNET_SYSERR;
- }
+ {
+ fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
*/
int
GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
- void *scls, const char *option, const char *value)
+ void *scls, const char *option, const char *value)
{
unsigned int *val = scls;
if (1 != SSCANF (value, "%u", val))
- {
- fprintf (stderr, _("You must pass a number to the `%s' option.\n"),
- option);
- return GNUNET_SYSERR;
- }
+ {
+ fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
struct GNUNET_CONFIGURATION_Handle *i2;
if (argc != 3)
- {
- fprintf (stderr, "Invoke using `%s DEFAULTS-IN DIFFS'\n", argv[0]);
- return 1;
- }
+ {
+ fprintf (stderr, "Invoke using `%s DEFAULTS-IN DIFFS'\n", argv[0]);
+ return 1;
+ }
i1 = GNUNET_CONFIGURATION_create ();
i2 = GNUNET_CONFIGURATION_create ();
if ((GNUNET_OK != GNUNET_CONFIGURATION_load (i1, argv[1])) ||
GNUNET_GETOPT_OPTION_END
};
return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]",
- gettext_noop ("Test GNUnet DNS resolver code."),
- options, &run, NULL)) ? 0 : 1;
+ GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]",
+ gettext_noop ("Test GNUnet DNS resolver code."),
+ options, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-resolver.c */
if (0 ==
getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL,
- 0, 0))
+ 0, 0))
cache->addr = GNUNET_strdup (hostname);
}
#endif
struct hostent *ent;
switch (cache->sa->sa_family)
- {
- case AF_INET:
- ent =
- gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr,
- sizeof (struct in_addr), AF_INET);
- break;
- case AF_INET6:
- ent =
- gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr,
- sizeof (struct in6_addr), AF_INET6);
- break;
- default:
- ent = NULL;
- }
+ {
+ case AF_INET:
+ ent =
+ gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr,
+ sizeof (struct in_addr), AF_INET);
+ break;
+ case AF_INET6:
+ ent =
+ gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr,
+ sizeof (struct in6_addr), AF_INET6);
+ break;
+ default:
+ ent = NULL;
+ }
if (ent != NULL)
cache->addr = GNUNET_strdup (ent->h_name);
}
*/
static void
get_ip_as_string (struct GNUNET_SERVER_Client *client,
- const struct sockaddr *sa, socklen_t salen)
+ const struct sockaddr *sa, socklen_t salen)
{
struct IPCache *cache;
struct IPCache *prev;
struct GNUNET_SERVER_TransmitContext *tc;
if (salen < sizeof (struct sockaddr))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
now = GNUNET_TIME_absolute_get ();
cache = head;
prev = NULL;
while ((cache != NULL) &&
- ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen))))
+ ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen))))
+ {
+ if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value <
+ 60 * 60 * 1000)
{
- if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value <
- 60 * 60 * 1000)
- {
- if (prev != NULL)
- {
- prev->next = cache->next;
- GNUNET_free_non_null (cache->addr);
- GNUNET_free (cache->sa);
- GNUNET_free (cache);
- cache = prev->next;
- }
- else
- {
- head = cache->next;
- GNUNET_free_non_null (cache->addr);
- GNUNET_free (cache->sa);
- GNUNET_free (cache);
- cache = head;
- }
- continue;
- }
- prev = cache;
- cache = cache->next;
+ if (prev != NULL)
+ {
+ prev->next = cache->next;
+ GNUNET_free_non_null (cache->addr);
+ GNUNET_free (cache->sa);
+ GNUNET_free (cache);
+ cache = prev->next;
+ }
+ else
+ {
+ head = cache->next;
+ GNUNET_free_non_null (cache->addr);
+ GNUNET_free (cache->sa);
+ GNUNET_free (cache);
+ cache = head;
+ }
+ continue;
}
+ prev = cache;
+ cache = cache->next;
+ }
if (cache != NULL)
+ {
+ cache->last_request = now;
+ if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value <
+ 60 * 60 * 1000)
{
- cache->last_request = now;
- if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value <
- 60 * 60 * 1000)
- {
- GNUNET_free_non_null (cache->addr);
- cache->addr = NULL;
- cache->salen = 0;
- cache_resolve (cache);
- }
- }
- else
- {
- cache = GNUNET_malloc (sizeof (struct IPCache));
- cache->next = head;
- cache->salen = salen;
- cache->sa = GNUNET_malloc (salen);
- memcpy (cache->sa, sa, salen);
- cache->last_request = GNUNET_TIME_absolute_get ();
- cache->last_refresh = GNUNET_TIME_absolute_get ();
+ GNUNET_free_non_null (cache->addr);
cache->addr = NULL;
+ cache->salen = 0;
cache_resolve (cache);
- head = cache;
}
+ }
+ else
+ {
+ cache = GNUNET_malloc (sizeof (struct IPCache));
+ cache->next = head;
+ cache->salen = salen;
+ cache->sa = GNUNET_malloc (salen);
+ memcpy (cache->sa, sa, salen);
+ cache->last_request = GNUNET_TIME_absolute_get ();
+ cache->last_refresh = GNUNET_TIME_absolute_get ();
+ cache->addr = NULL;
+ cache_resolve (cache);
+ head = cache;
+ }
tc = GNUNET_SERVER_transmit_context_create (client);
if (cache->addr != NULL)
GNUNET_SERVER_transmit_context_append_data (tc, cache->addr,
- strlen (cache->addr) + 1,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ strlen (cache->addr) + 1,
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
#if HAVE_GETADDRINFO
static int
getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
- const char *hostname, int domain)
+ const char *hostname, int domain)
{
int s;
struct addrinfo hints;
#else
hints.ai_family = AF_INET;
#endif
- hints.ai_socktype = SOCK_STREAM; /* go for TCP */
+ hints.ai_socktype = SOCK_STREAM; /* go for TCP */
if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Could not resolve `%s' (%s): %s\n"), hostname,
- (domain ==
- AF_INET) ? "IPv4" : ((domain ==
- AF_INET6) ? "IPv6" : "any"),
- gai_strerror (s));
- if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"),
+ hostname,
+ (domain ==
+ AF_INET) ? "IPv4" : ((domain == AF_INET6) ? "IPv6" : "any"),
+ gai_strerror (s));
+ if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
#ifndef MINGW
- || (s == EAI_SYSTEM)
+ || (s == EAI_SYSTEM)
#else
- // FIXME NILS
- || 1
+ // FIXME NILS
+ || 1
#endif
- )
- return GNUNET_NO; /* other function may still succeed */
- return GNUNET_SYSERR;
- }
+ )
+ return GNUNET_NO; /* other function may still succeed */
+ return GNUNET_SYSERR;
+ }
if (result == NULL)
return GNUNET_SYSERR;
pos = result;
while (pos != NULL)
- {
- GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr,
- pos->ai_addrlen,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
- pos = pos->ai_next;
- }
+ {
+ GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr,
+ pos->ai_addrlen,
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ pos = pos->ai_next;
+ }
freeaddrinfo (result);
return GNUNET_OK;
}
#if HAVE_GETHOSTBYNAME2
static int
gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
- const char *hostname, int domain)
+ const char *hostname, int domain)
{
struct hostent *hp;
struct sockaddr_in a4;
int ret2;
if (domain == AF_UNSPEC)
- {
- ret1 = gethostbyname2_resolve (tc, hostname, AF_INET);
- ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6);
- if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK))
- return GNUNET_OK;
- if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR))
- return GNUNET_SYSERR;
- return GNUNET_NO;
- }
+ {
+ ret1 = gethostbyname2_resolve (tc, hostname, AF_INET);
+ ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6);
+ if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK))
+ return GNUNET_OK;
+ if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR))
+ return GNUNET_SYSERR;
+ return GNUNET_NO;
+ }
hp = gethostbyname2 (hostname, domain);
if (hp == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Could not find IP of host `%s': %s\n"), hostname,
- hstrerror (h_errno));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Could not find IP of host `%s': %s\n"), hostname,
+ hstrerror (h_errno));
+ return GNUNET_SYSERR;
+ }
GNUNET_assert (hp->h_addrtype == domain);
if (domain == AF_INET)
- {
- GNUNET_assert (hp->h_length == sizeof (struct in_addr));
- memset (&a4, 0, sizeof (a4));
- a4.sin_family = AF_INET;
+ {
+ GNUNET_assert (hp->h_length == sizeof (struct in_addr));
+ memset (&a4, 0, sizeof (a4));
+ a4.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- a4.sin_len = (u_char) sizeof (struct sockaddr_in);
+ a4.sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
- memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
- GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4),
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
- }
+ memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
+ GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4),
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ }
else
- {
- GNUNET_assert (hp->h_length == sizeof (struct in6_addr));
- memset (&a6, 0, sizeof (a6));
- a6.sin6_family = AF_INET6;
+ {
+ GNUNET_assert (hp->h_length == sizeof (struct in6_addr));
+ memset (&a6, 0, sizeof (a6));
+ a6.sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
- a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
+ a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
#endif
- memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
- GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6),
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
- }
+ memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
+ GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6),
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ }
return GNUNET_OK;
}
#endif
#if HAVE_GETHOSTBYNAME
static int
gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
- const char *hostname)
+ const char *hostname)
{
struct hostent *hp;
struct sockaddr_in addr;
hp = GETHOSTBYNAME (hostname);
if (hp == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Could not find IP of host `%s': %s\n"), hostname,
- hstrerror (h_errno));
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Could not find IP of host `%s': %s\n"), hostname,
+ hstrerror (h_errno));
+ return GNUNET_SYSERR;
+ }
if (hp->h_addrtype != AF_INET)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_assert (hp->h_length == sizeof (struct in_addr));
memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
#endif
memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr),
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
return GNUNET_OK;
}
#endif
* @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
*/
static void
-get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
- const char *hostname, int domain)
+get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname,
+ int domain)
{
int ret;
struct GNUNET_SERVER_TransmitContext *tc;
gethostbyname_resolve (tc, hostname);
#endif
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
*/
static void
handle_get (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
uint16_t msize;
const struct GNUNET_RESOLVER_GetMessage *msg;
msize = ntohs (message->size);
if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
msg = (const struct GNUNET_RESOLVER_GetMessage *) message;
size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage);
direction = ntohl (msg->direction);
domain = ntohl (msg->domain);
if (direction == GNUNET_NO)
+ {
+ /* IP from hostname */
+ hostname = (const char *) &msg[1];
+ if (hostname[size - 1] != '\0')
{
- /* IP from hostname */
- hostname = (const char *) &msg[1];
- if (hostname[size - 1] != '\0')
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Resolver asked to look up `%s'.\n"), hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver asked to look up `%s'.\n"),
+ hostname);
#endif
- get_ip_from_hostname (client, hostname, domain);
- }
+ get_ip_from_hostname (client, hostname, domain);
+ }
else
- {
+ {
#if DEBUG_RESOLVER
- char buf[INET6_ADDRSTRLEN];
+ char buf[INET6_ADDRSTRLEN];
#endif
- if (size < sizeof (struct sockaddr))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- sa = (const struct sockaddr *) &msg[1];
- switch (sa->sa_family)
- {
- case AF_INET:
- if (size != sizeof (struct sockaddr_in))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if (size < sizeof (struct sockaddr))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ sa = (const struct sockaddr *) &msg[1];
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ if (size != sizeof (struct sockaddr_in))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_RESOLVER
- inet_ntop (AF_INET, sa, buf, size);
+ inet_ntop (AF_INET, sa, buf, size);
#endif
- break;
- case AF_INET6:
- if (size != sizeof (struct sockaddr_in6))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ break;
+ case AF_INET6:
+ if (size != sizeof (struct sockaddr_in6))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_RESOLVER
- inet_ntop (AF_INET6, sa, buf, size);
+ inet_ntop (AF_INET6, sa, buf, size);
#endif
- break;
- default:
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Resolver asked to look up IP address `%s'.\n"), buf);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Resolver asked to look up IP address `%s'.\n"), buf);
#endif
- get_ip_as_string (client, sa, size);
- }
+ get_ip_as_string (client, sa, size);
+ }
}
struct IPCache *pos;
ret =
- (GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ (GNUNET_OK ==
+ GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE,
+ &run, NULL)) ? 0 : 1;
while (head != NULL)
- {
- pos = head->next;
- GNUNET_free_non_null (head->addr);
- GNUNET_free (head->sa);
- GNUNET_free (head);
- head = pos;
- }
+ {
+ pos = head->next;
+ GNUNET_free_non_null (head->addr);
+ GNUNET_free (head->sa);
+ GNUNET_free (head);
+ head = pos;
+ }
return ret;
}
if (delta.rel_value < load->autodecline.rel_value)
return;
if (load->autodecline.rel_value == 0)
- {
- load->runavg_delay = 0.0;
- load->load = 0;
- return;
- }
+ {
+ load->runavg_delay = 0.0;
+ load->load = 0;
+ return;
+ }
n = delta.rel_value / load->autodecline.rel_value;
if (n > 16)
- {
- load->runavg_delay = 0.0;
- load->load = 0;
- return;
- }
+ {
+ load->runavg_delay = 0.0;
+ load->load = 0;
+ return;
+ }
while (n > 0)
- {
- n--;
- load->runavg_delay = (load->runavg_delay * 7.0) / 8.0;
- }
+ {
+ n--;
+ load->runavg_delay = (load->runavg_delay * 7.0) / 8.0;
+ }
}
*/
void
GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load,
- struct GNUNET_TIME_Relative autodecline)
+ struct GNUNET_TIME_Relative autodecline)
{
internal_update (load);
load->autodecline = autodecline;
nm1 = n - 1.0;
avgdel = sum_val_i / n;
stddev =
- (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i +
- n * avgdel * avgdel) / nm1;
+ (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i +
+ n * avgdel * avgdel) / nm1;
if (stddev <= 0)
- stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */
+ stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */
/* now calculate load based on how far out we are from
* std dev; or if we are below average, simply assume load zero */
if (load->runavg_delay < avgdel)
internal_update (load);
load->last_update = GNUNET_TIME_absolute_get ();
if (data > 64 * 1024)
- {
- /* very large */
- load->load = 100.0;
- return;
- }
+ {
+ /* very large */
+ load->load = 100.0;
+ return;
+ }
dv = (uint32_t) data;
load->cummulative_delay += dv;
load->cummulative_squared_delay += dv * dv;
mode = !doBlock;
if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR)
- {
- SetErrnoFromWinsockError (WSAGetLastError ());
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinsockError (WSAGetLastError ());
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
#else
if (flags == -1)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
+ return GNUNET_SYSERR;
+ }
if (doBlock)
flags &= ~O_NONBLOCK;
flags |= O_NONBLOCK;
if (0 != fcntl (fd->fd, F_SETFL, flags))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
#endif
}
if (0 !=
setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value,
- sizeof (abs_value)))
+ sizeof (abs_value)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
}
#endif
#ifndef WINDOWS
int value = 1;
- if (0 !=
- setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
+ if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
#else
const char *abs_value = "1";
if (0 !=
setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value,
- sizeof (abs_value)))
+ sizeof (abs_value)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
#endif
}
*/
struct GNUNET_NETWORK_Handle *
GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
- struct sockaddr *address,
- socklen_t * address_len)
+ struct sockaddr *address, socklen_t * address_len)
{
struct GNUNET_NETWORK_Handle *ret;
if (gsn == 0)
LOG (GNUNET_ERROR_TYPE_DEBUG, "Accepting connection on `%s'\n",
- GNUNET_a2s (&name, namelen));
+ GNUNET_a2s (&name, namelen));
}
#endif
ret->fd = accept (desc->fd, address, address_len);
else
ret->af = desc->af;
if (ret->fd == INVALID_SOCKET)
- {
+ {
#ifdef MINGW
- SetErrnoFromWinsockError (WSAGetLastError ());
+ SetErrnoFromWinsockError (WSAGetLastError ());
#endif
- GNUNET_free (ret);
- return NULL;
- }
+ GNUNET_free (ret);
+ return NULL;
+ }
#ifndef MINGW
if (ret->fd >= FD_SETSIZE)
- {
- GNUNET_break (0 == close (ret->fd));
- GNUNET_free (ret);
- errno = EMFILE;
- return NULL;
- }
+ {
+ GNUNET_break (0 == close (ret->fd));
+ GNUNET_free (ret);
+ errno = EMFILE;
+ return NULL;
+ }
#endif
if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
- {
+ {
- /* we might want to treat this one as fatal... */
- GNUNET_break (0);
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
- return NULL;
- }
+ /* we might want to treat this one as fatal... */
+ GNUNET_break (0);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
+ return NULL;
+ }
#ifndef MINGW
if (GNUNET_OK != socket_set_inheritable (ret))
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "socket_set_inheritable");
+ "socket_set_inheritable");
#endif
#ifdef DARWIN
socket_set_nosigpipe (ret);
*/
int
GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
- const struct sockaddr *address,
- socklen_t address_len)
+ const struct sockaddr *address,
+ socklen_t address_len)
{
int ret;
const int on = 1;
if (desc->af == AF_INET6)
- if (0 !=
- setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
+ if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt");
#endif
#endif
#ifndef LINUX
#ifndef MINGW
if (address->sa_family == AF_UNIX)
- {
- const struct sockaddr_un *un = (const struct sockaddr_un *) address;
+ {
+ const struct sockaddr_un *un = (const struct sockaddr_un *) address;
- (void) unlink (un->sun_path);
- }
+ (void) unlink (un->sun_path);
+ }
#endif
#endif
ret = bind (desc->fd, address, address_len);
DWORD error = 0;
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
- "Closing 0x%x\n", desc->fd);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closing 0x%x\n",
+ desc->fd);
#endif
SetLastError (0);
ret = closesocket (desc->fd);
SetErrnoFromWinsockError (error);
#if DEBUG_NETWORK
LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
- "Closed 0x%x, closesocket() returned %d, GLE is %u\n",
- desc->fd, ret, error);
+ "Closed 0x%x, closesocket() returned %d, GLE is %u\n", desc->fd, ret,
+ error);
#endif
#else
ret = close (desc->fd);
#ifndef LINUX
#ifndef MINGW
if ((desc->af == AF_UNIX) && (NULL != desc->addr))
- {
- const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
+ {
+ const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
- if (0 != unlink (un->sun_path))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path);
- }
+ if (0 != unlink (un->sun_path))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path);
+ }
#endif
#endif
GNUNET_free_non_null (desc->addr);
struct GNUNET_NETWORK_Handle *ret;
if (fcntl (fd, F_GETFD) < 0)
- return NULL; /* invalid FD */
+ return NULL; /* invalid FD */
ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
ret->fd = fd;
ret->af = AF_UNSPEC;
*/
int
GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
- const struct sockaddr *address,
- socklen_t address_len)
+ const struct sockaddr *address,
+ socklen_t address_len)
{
int ret;
#ifdef MINGW
if (SOCKET_ERROR == ret)
- {
- SetErrnoFromWinsockError (WSAGetLastError ());
- if (errno == EWOULDBLOCK)
- errno = EINPROGRESS;
- }
+ {
+ SetErrnoFromWinsockError (WSAGetLastError ());
+ if (errno == EWOULDBLOCK)
+ errno = EINPROGRESS;
+ }
#endif
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
*/
int
GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
- int level, int optname, void *optval,
- socklen_t * optlen)
+ int level, int optname, void *optval,
+ socklen_t * optlen)
{
int ret;
*/
int
GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
- int backlog)
+ int backlog)
{
int ret;
*/
ssize_t
GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *
- desc)
+ desc)
{
int error;
*/
ssize_t
GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
- void *buffer, size_t length,
- struct sockaddr * src_addr,
- socklen_t * addrlen)
+ void *buffer, size_t length,
+ struct sockaddr * src_addr, socklen_t * addrlen)
{
int ret;
int flags;
*/
ssize_t
GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
- void *buffer, size_t length)
+ void *buffer, size_t length)
{
int ret;
int flags;
*/
ssize_t
GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
- const void *buffer, size_t length)
+ const void *buffer, size_t length)
{
int ret;
int flags;
*/
ssize_t
GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
- const void *message, size_t length,
- const struct sockaddr * dest_addr,
- socklen_t dest_len)
+ const void *message, size_t length,
+ const struct sockaddr * dest_addr,
+ socklen_t dest_len)
{
int ret;
int flags;
*/
int
GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level,
- int option_name, const void *option_value,
- socklen_t option_len)
+ int option_name, const void *option_value,
+ socklen_t option_len)
{
int ret;
ret->af = domain;
ret->fd = socket (domain, type, protocol);
if (INVALID_SOCKET == ret->fd)
- {
+ {
#ifdef MINGW
- SetErrnoFromWinsockError (WSAGetLastError ());
+ SetErrnoFromWinsockError (WSAGetLastError ());
#endif
- GNUNET_free (ret);
- return NULL;
- }
+ GNUNET_free (ret);
+ return NULL;
+ }
#ifndef MINGW
if (ret->fd >= FD_SETSIZE)
- {
- GNUNET_break (0 == close (ret->fd));
- GNUNET_free (ret);
- errno = EMFILE;
- return NULL;
- }
+ {
+ GNUNET_break (0 == close (ret->fd));
+ GNUNET_free (ret);
+ errno = EMFILE;
+ return NULL;
+ }
#endif
if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
- {
- /* we might want to treat this one as fatal... */
- GNUNET_break (0);
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
- return NULL;
- }
+ {
+ /* we might want to treat this one as fatal... */
+ GNUNET_break (0);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
+ return NULL;
+ }
#ifndef MINGW
if (GNUNET_OK != socket_set_inheritable (ret))
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "socket_set_inheritable");
+ "socket_set_inheritable");
#endif
#ifdef DARWIN
socket_set_nosigpipe (ret);
#ifdef AF_UNIX
&& (domain != AF_UNIX)
#endif
- )
+ )
socket_set_nodelay (ret);
return ret;
}
GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc)
{
int ret = 0;
+
#if WINDOWS
int value = 0;
if (0 !=
(ret =
setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value,
- sizeof (value))))
+ sizeof (value))))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
if (0 !=
(ret =
setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value,
- sizeof (value))))
+ sizeof (value))))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
#elif LINUX
int value = 0;
*/
void
GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
- const struct GNUNET_NETWORK_Handle *desc)
+ const struct GNUNET_NETWORK_Handle *desc)
{
FD_SET (desc->fd, &fds->sds);
if (desc->fd + 1 > fds->nsds)
*/
int
GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
- const struct GNUNET_NETWORK_Handle *desc)
+ const struct GNUNET_NETWORK_Handle *desc)
{
return FD_ISSET (desc->fd, &fds->sds);
}
*/
void
GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
- const struct GNUNET_NETWORK_FDSet *src)
+ const struct GNUNET_NETWORK_FDSet *src)
{
int nfds;
for (nfds = src->nsds; nfds > 0; nfds--)
if (FD_ISSET (nfds, &src->sds))
- {
- FD_SET (nfds, &dst->sds);
- if (nfds + 1 > dst->nsds)
- dst->nsds = nfds + 1;
- }
+ {
+ FD_SET (nfds, &dst->sds);
+ if (nfds + 1 > dst->nsds)
+ dst->nsds = nfds + 1;
+ }
#ifdef MINGW
GNUNET_CONTAINER_slist_append (dst->handles, src->handles);
#endif
*/
void
GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
- const struct GNUNET_NETWORK_FDSet *from)
+ const struct GNUNET_NETWORK_FDSet *from)
{
FD_COPY (&from->sds, &to->sds);
to->nsds = from->nsds;
*/
void
GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
- const fd_set * from, int nfds)
+ const fd_set * from, int nfds)
{
FD_COPY (from, &to->sds);
to->nsds = nfds;
*/
int
GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
- int nfd)
+ int nfd)
{
if ((nfd == -1) || (to == NULL))
return GNUNET_NO;
*/
void
GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
- const struct GNUNET_DISK_FileHandle *h)
+ const struct GNUNET_DISK_FileHandle *h)
{
#ifdef MINGW
GNUNET_CONTAINER_slist_add (fds->handles,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h,
- sizeof (struct GNUNET_DISK_FileHandle));
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h,
+ sizeof (struct GNUNET_DISK_FileHandle));
#else
int fd;
*/
int
GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
- const struct GNUNET_DISK_FileHandle *h)
+ const struct GNUNET_DISK_FileHandle *h)
{
#ifdef MINGW
return GNUNET_CONTAINER_slist_contains (fds->handles, h,
- sizeof (struct
- GNUNET_DISK_FileHandle));
+ sizeof (struct
+ GNUNET_DISK_FileHandle));
#else
return FD_ISSET (h->fd, &fds->sds);
#endif
*/
int
GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
- const struct GNUNET_NETWORK_FDSet *fds2)
+ const struct GNUNET_NETWORK_FDSet *fds2)
{
#ifndef MINGW
int nfds;
if (nfds > fds2->nsds)
nfds = fds2->nsds;
while (nfds > 0)
- {
- nfds--;
- if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
- return GNUNET_YES;
- }
+ {
+ nfds--;
+ if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
+ return GNUNET_YES;
+ }
#else
struct GNUNET_CONTAINER_SList_Iterator it;
struct GNUNET_DISK_FileHandle *h;
* inside of fd_set; also the O(n^2) is really bad... */
for (i = 0; i < fds1->sds.fd_count; i++)
+ {
+ for (j = 0; j < fds2->sds.fd_count; j++)
{
- for (j = 0; j < fds2->sds.fd_count; j++)
- {
- if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
- return GNUNET_YES;
- }
+ if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
+ return GNUNET_YES;
}
+ }
it = GNUNET_CONTAINER_slist_begin (fds1->handles);
while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES)
- {
+ {
#if DEBUG_NETWORK
- struct GNUNET_CONTAINER_SList_Iterator t;
+ struct GNUNET_CONTAINER_SList_Iterator t;
#endif
- h =
- (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it,
- NULL);
+ h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it,
+ NULL);
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Checking that FD 0x%x is in another set:\n", h->h);
- for (t = GNUNET_CONTAINER_slist_begin (fds2->handles);
- GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
- GNUNET_CONTAINER_slist_next (&t))
- {
- struct GNUNET_DISK_FileHandle *fh;
-
- fh =
- (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
- NULL);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h);
- }
-#endif
- if (GNUNET_CONTAINER_slist_contains
- (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle)))
- {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking that FD 0x%x is in another set:\n",
+ h->h);
+ for (t = GNUNET_CONTAINER_slist_begin (fds2->handles);
+ GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (&t))
+ {
+ struct GNUNET_DISK_FileHandle *fh;
+
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
+ NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h);
+ }
+#endif
+ if (GNUNET_CONTAINER_slist_contains
+ (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle)))
+ {
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n");
#endif
- return GNUNET_YES;
- }
- GNUNET_CONTAINER_slist_next (&it);
+ return GNUNET_YES;
}
+ GNUNET_CONTAINER_slist_next (&it);
+ }
#endif
return GNUNET_NO;
}
*/
int
GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
- struct GNUNET_NETWORK_FDSet *wfds,
- struct GNUNET_NETWORK_FDSet *efds,
- const struct GNUNET_TIME_Relative timeout)
+ struct GNUNET_NETWORK_FDSet *wfds,
+ struct GNUNET_NETWORK_FDSet *efds,
+ const struct GNUNET_TIME_Relative timeout)
{
int nfds = 0;
DWORD newretcode = 0;
int returnedpos = 0;
- struct GNUNET_CONTAINER_SList *handles_read, *handles_write,
- *handles_except;
+ struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except;
fd_set aread, awrite, aexcept;
struct timeval tv;
#endif
if (NULL != rfds)
- {
- nfds = rfds->nsds;
+ {
+ nfds = rfds->nsds;
#ifdef MINGW
- handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles);
+ handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles);
#if DEBUG_NETWORK
+ {
+ struct GNUNET_CONTAINER_SList_Iterator t;
+
+ for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
+ GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (&t))
{
- struct GNUNET_CONTAINER_SList_Iterator t;
-
- for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
- GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
- GNUNET_CONTAINER_slist_next (&t))
- {
- struct GNUNET_DISK_FileHandle *fh;
-
- fh =
- (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
- NULL);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n",
- fh->h, fh);
- }
+ struct GNUNET_DISK_FileHandle *fh;
+
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
+ NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", fh->h,
+ fh);
}
+ }
#endif
#endif
- }
+ }
if (NULL != wfds)
- {
- nfds = GNUNET_MAX (nfds, wfds->nsds);
+ {
+ nfds = GNUNET_MAX (nfds, wfds->nsds);
#ifdef MINGW
- handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles);
+ handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles);
#endif
- }
+ }
if (NULL != efds)
- {
- nfds = GNUNET_MAX (nfds, efds->nsds);
+ {
+ nfds = GNUNET_MAX (nfds, efds->nsds);
#ifdef MINGW
- handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles);
+ handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles);
#endif
- }
+ }
if ((nfds == 0) &&
(timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
#ifdef MINGW
&& handles == 0
#endif
- )
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
- "select");
- GNUNET_break (0);
- }
+ )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
+ "select");
+ GNUNET_break (0);
+ }
#ifndef MINGW
tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value;
tv.tv_usec =
- 1000 * (timeout.rel_value -
- (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value));
+ 1000 * (timeout.rel_value -
+ (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value));
return select (nfds, (rfds != NULL) ? &rfds->sds : NULL,
- (wfds != NULL) ? &wfds->sds : NULL,
- (efds != NULL) ? &efds->sds : NULL,
- (timeout.rel_value ==
- GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv);
+ (wfds != NULL) ? &wfds->sds : NULL,
+ (efds != NULL) ? &efds->sds : NULL,
+ (timeout.rel_value ==
+ GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv);
#else
#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value;
/* select() may be used as a portable way to sleep */
if (!(rfds || wfds || efds))
- {
- Sleep (ms_total);
- return 0;
- }
+ {
+ Sleep (ms_total);
+ return 0;
+ }
/* Events for sockets */
if (!hEventRead)
FD_ZERO (&bexcept);
#endif
if (rfds)
- {
- FD_COPY (&rfds->sds, &aread);
+ {
+ FD_COPY (&rfds->sds, &aread);
#if DEBUG_NETWORK
- FD_COPY (&rfds->sds, &bread);
+ FD_COPY (&rfds->sds, &bread);
#endif
- }
+ }
if (wfds)
- {
- FD_COPY (&wfds->sds, &awrite);
+ {
+ FD_COPY (&wfds->sds, &awrite);
#if DEBUG_NETWORK
- FD_COPY (&wfds->sds, &bwrite);
+ FD_COPY (&wfds->sds, &bwrite);
#endif
- }
+ }
if (efds)
- {
- FD_COPY (&efds->sds, &aexcept);
+ {
+ FD_COPY (&efds->sds, &aexcept);
#if DEBUG_NETWORK
- FD_COPY (&efds->sds, &bexcept);
+ FD_COPY (&efds->sds, &bexcept);
#endif
- }
+ }
/* We will first Add the PIPES to the events */
/* Read Pipes */
if (rfds && read_handles)
+ {
+ struct GNUNET_CONTAINER_SList_Iterator i;
+
+ for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
+ GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (&i))
{
- struct GNUNET_CONTAINER_SList_Iterator i;
-
- for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
- GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
- GNUNET_CONTAINER_slist_next (&i))
- {
- struct GNUNET_DISK_FileHandle *fh;
-
- fh =
- (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
- NULL);
- if (fh->type == GNUNET_PIPE)
- {
- /* Read zero bytes to check the status of the pipe */
+ struct GNUNET_DISK_FileHandle *fh;
+
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
+ NULL);
+ if (fh->type == GNUNET_PIPE)
+ {
+ /* Read zero bytes to check the status of the pipe */
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Reading 0 bytes from the pipe 0x%x\n", fh->h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Reading 0 bytes from the pipe 0x%x\n",
+ fh->h);
#endif
- if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead))
- {
- DWORD error_code = GetLastError ();
+ if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead))
+ {
+ DWORD error_code = GetLastError ();
- if (error_code == ERROR_IO_PENDING)
- {
+ if (error_code == ERROR_IO_PENDING)
+ {
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding the pipe's 0x%x overlapped event to the array as %d\n",
- fh->h, nhandles);
-#endif
- handle_array[nhandles++] = fh->oOverlapRead->hEvent;
- readArray[readPipes++] = fh;
- }
- /*
- * else
- * {
- * SetErrnoFromWinError (error_code);
- * }
- */
- }
- else
- {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the pipe's 0x%x overlapped event to the array as %d\n",
+ fh->h, nhandles);
+#endif
+ handle_array[nhandles++] = fh->oOverlapRead->hEvent;
+ readArray[readPipes++] = fh;
+ }
+ /*
+ * else
+ * {
+ * SetErrnoFromWinError (error_code);
+ * }
+ */
+ }
+ else
+ {
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding the read ready event to the array as %d\n",
- nhandles);
-#endif
- handle_array[nhandles++] = hEventReadReady;
- readArray[readPipes++] = fh;
- }
- }
- else
- {
- GNUNET_CONTAINER_slist_add (handles_read,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- fh,
- sizeof (struct
- GNUNET_DISK_FileHandle));
- }
- }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the read ready event to the array as %d\n", nhandles);
+#endif
+ handle_array[nhandles++] = hEventReadReady;
+ readArray[readPipes++] = fh;
+ }
+ }
+ else
+ {
+ GNUNET_CONTAINER_slist_add (handles_read,
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ fh, sizeof (struct GNUNET_DISK_FileHandle));
+ }
}
+ }
if (wfds && write_handles)
- {
+ {
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding the write ready event to the array as %d\n", nhandles);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the write ready event to the array as %d\n", nhandles);
#endif
- handle_array[nhandles++] = hEventPipeWrite;
- writePipePos = nhandles;
- }
+ handle_array[nhandles++] = hEventPipeWrite;
+ writePipePos = nhandles;
+ }
if (efds && ex_handles)
+ {
+ struct GNUNET_CONTAINER_SList_Iterator i;
+
+ for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
+ GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (&i))
{
- struct GNUNET_CONTAINER_SList_Iterator i;
-
- for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
- GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
- GNUNET_CONTAINER_slist_next (&i))
- {
- struct GNUNET_DISK_FileHandle *fh;
- DWORD dwBytes;
-
- fh =
- (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
- NULL);
- if (fh->type == GNUNET_PIPE)
- {
- if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL))
- {
- GNUNET_CONTAINER_slist_add (handles_except,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- fh,
- sizeof (struct
- GNUNET_DISK_FileHandle));
- newretcode++;
- }
- }
- }
+ struct GNUNET_DISK_FileHandle *fh;
+ DWORD dwBytes;
+
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
+ NULL);
+ if (fh->type == GNUNET_PIPE)
+ {
+ if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL))
+ {
+ GNUNET_CONTAINER_slist_add (handles_except,
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ fh,
+ sizeof (struct GNUNET_DISK_FileHandle));
+ newretcode++;
+ }
+ }
}
+ }
if (nfds > 0)
+ {
+ if (rfds)
{
- if (rfds)
- {
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding the socket read event to the array as %d\n", nhandles);
-#endif
- handle_array[nhandles++] = hEventRead;
- nSockEvents++;
- for (i = 0; i < rfds->sds.fd_count; i++)
- {
- WSAEventSelect (rfds->sds.fd_array[i], hEventRead,
- FD_ACCEPT | FD_READ | FD_CLOSE);
- nsock++;
- }
- }
- if (wfds)
- {
- int wakeup = 0;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the socket read event to the array as %d\n", nhandles);
+#endif
+ handle_array[nhandles++] = hEventRead;
+ nSockEvents++;
+ for (i = 0; i < rfds->sds.fd_count; i++)
+ {
+ WSAEventSelect (rfds->sds.fd_array[i], hEventRead,
+ FD_ACCEPT | FD_READ | FD_CLOSE);
+ nsock++;
+ }
+ }
+ if (wfds)
+ {
+ int wakeup = 0;
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding the socket write event to the array as %d\n",
- nhandles);
-#endif
- handle_array[nhandles++] = hEventWrite;
- nSockEvents++;
- for (i = 0; i < wfds->sds.fd_count; i++)
- {
- DWORD error;
- int status;
-
- status = send (wfds->sds.fd_array[i], NULL, 0, 0);
- error = GetLastError ();
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the socket write event to the array as %d\n", nhandles);
+#endif
+ handle_array[nhandles++] = hEventWrite;
+ nSockEvents++;
+ for (i = 0; i < wfds->sds.fd_count; i++)
+ {
+ DWORD error;
+ int status;
+
+ status = send (wfds->sds.fd_array[i], NULL, 0, 0);
+ error = GetLastError ();
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "pre-send to the socket %d returned %d (%u)\n", i, status,
- error);
-#endif
- if (status == 0
- || (error != WSAEWOULDBLOCK && error != WSAENOTCONN))
- wakeup = 1;
- WSAEventSelect (wfds->sds.fd_array[i], hEventWrite,
- FD_WRITE | FD_CONNECT | FD_CLOSE);
- nsock++;
- }
- if (wakeup)
- SetEvent (hEventWrite);
- }
- if (efds)
- {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "pre-send to the socket %d returned %d (%u)\n", i, status, error);
+#endif
+ if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN))
+ wakeup = 1;
+ WSAEventSelect (wfds->sds.fd_array[i], hEventWrite,
+ FD_WRITE | FD_CONNECT | FD_CLOSE);
+ nsock++;
+ }
+ if (wakeup)
+ SetEvent (hEventWrite);
+ }
+ if (efds)
+ {
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding the socket error event to the array as %d\n",
- nhandles);
-#endif
- handle_array[nhandles++] = hEventException;
- nSockEvents++;
- for (i = 0; i < efds->sds.fd_count; i++)
- {
- WSAEventSelect (efds->sds.fd_array[i], hEventException,
- FD_OOB | FD_CLOSE);
- nsock++;
- }
- }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding the socket error event to the array as %d\n", nhandles);
+#endif
+ handle_array[nhandles++] = hEventException;
+ nSockEvents++;
+ for (i = 0; i < efds->sds.fd_count; i++)
+ {
+ WSAEventSelect (efds->sds.fd_array[i], hEventException,
+ FD_OOB | FD_CLOSE);
+ nsock++;
+ }
}
+ }
handle_array[nhandles] = NULL;
if (nhandles)
returncode =
- WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total);
+ WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total);
#if DEBUG_NETWORK
LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n",
returncode);
* GNUNET_CONTAINER_slist_append (handles_read, rfds->handles);
*/
if (nhandles && (returnedpos < nhandles))
+ {
+ DWORD waitstatus;
+
+ /* Do the select */
+ if (nfds)
{
- DWORD waitstatus;
-
- /* Do the select */
- if (nfds)
- {
- struct timeval tvslice;
-
- tvslice.tv_sec = 0;
- tvslice.tv_usec = 10;
- retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice);
- if (retcode == -1)
- retcode = 0;
+ struct timeval tvslice;
+
+ tvslice.tv_sec = 0;
+ tvslice.tv_usec = 10;
+ retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice);
+ if (retcode == -1)
+ retcode = 0;
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode);
-#endif
- }
- /* FIXME: <= writePipePos? Really? */
- if ((writePipePos != -1) && (returnedpos <= writePipePos))
- {
- GNUNET_CONTAINER_slist_append (handles_write, wfds->handles);
- retcode += write_handles;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode);
+#endif
+ }
+ /* FIXME: <= writePipePos? Really? */
+ if ((writePipePos != -1) && (returnedpos <= writePipePos))
+ {
+ GNUNET_CONTAINER_slist_append (handles_write, wfds->handles);
+ retcode += write_handles;
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n");
#endif
- }
+ }
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes);
-#endif
- /* We have some pipes ready for read. */
- /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */
-
- if (returnedpos < readPipes)
- {
- /*
- * for (i = 0; i < readPipes; i++)
- * {
- * waitstatus = WaitForSingleObject (handle_array[i], 0);
- * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus);
- * if (waitstatus != WAIT_OBJECT_0)
- * continue;
- * GNUNET_CONTAINER_slist_add (handles_read,
- * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- * readArray[i], sizeof (struct GNUNET_DISK_FileHandle));
- * retcode++;
- * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n");
- * }
- */
- for (i = 0; i < readPipes; i++)
- {
- DWORD error;
- BOOL bret;
-
- SetLastError (0);
- waitstatus = 0;
- bret =
- PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus,
- NULL);
- error = GetLastError ();
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes);
+#endif
+ /* We have some pipes ready for read. */
+ /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */
+
+ if (returnedpos < readPipes)
+ {
+ /*
+ * for (i = 0; i < readPipes; i++)
+ * {
+ * waitstatus = WaitForSingleObject (handle_array[i], 0);
+ * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus);
+ * if (waitstatus != WAIT_OBJECT_0)
+ * continue;
+ * GNUNET_CONTAINER_slist_add (handles_read,
+ * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ * readArray[i], sizeof (struct GNUNET_DISK_FileHandle));
+ * retcode++;
+ * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n");
+ * }
+ */
+ for (i = 0; i < readPipes; i++)
+ {
+ DWORD error;
+ BOOL bret;
+
+ SetLastError (0);
+ waitstatus = 0;
+ bret =
+ PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL);
+ error = GetLastError ();
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n",
- i, readArray[i]->h, bret, waitstatus, error);
-#endif
- if (bret == 0)
- {
- if (error != ERROR_BROKEN_PIPE)
- continue;
- }
- else if (waitstatus <= 0)
- continue;
- GNUNET_CONTAINER_slist_add (handles_read,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- readArray[i],
- sizeof (struct
- GNUNET_DISK_FileHandle));
- retcode++;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n",
+ i, readArray[i]->h, bret, waitstatus, error);
+#endif
+ if (bret == 0)
+ {
+ if (error != ERROR_BROKEN_PIPE)
+ continue;
+ }
+ else if (waitstatus <= 0)
+ continue;
+ GNUNET_CONTAINER_slist_add (handles_read,
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ readArray[i],
+ sizeof (struct GNUNET_DISK_FileHandle));
+ retcode++;
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n",
- readArray[i], readArray[i]->h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n",
+ readArray[i], readArray[i]->h);
#endif
- }
- }
- waitstatus = WaitForSingleObject (hEventWrite, 0);
+ }
+ }
+ waitstatus = WaitForSingleObject (hEventWrite, 0);
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Wait for the write event returned %d\n", waitstatus);
-#endif
- if (waitstatus == WAIT_OBJECT_0)
- {
- for (i = 0; i < wfds->sds.fd_count; i++)
- {
- DWORD error;
- int status;
- int so_error = 0;
- int sizeof_so_error = sizeof (so_error);
- int gso_result =
- getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR,
- (char *) &so_error, &sizeof_so_error);
-
- status = send (wfds->sds.fd_array[i], NULL, 0, 0);
- error = GetLastError ();
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n",
+ waitstatus);
+#endif
+ if (waitstatus == WAIT_OBJECT_0)
+ {
+ for (i = 0; i < wfds->sds.fd_count; i++)
+ {
+ DWORD error;
+ int status;
+ int so_error = 0;
+ int sizeof_so_error = sizeof (so_error);
+ int gso_result =
+ getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR,
+ (char *) &so_error, &sizeof_so_error);
+
+ status = send (wfds->sds.fd_array[i], NULL, 0, 0);
+ error = GetLastError ();
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "send to the socket %d returned %d (%u)\n", i, status,
- error);
-#endif
- if (status == 0
- || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)
- || (status == -1 && gso_result == 0 && error == WSAENOTCONN
- && so_error == WSAECONNREFUSED))
- {
- FD_SET (wfds->sds.fd_array[i], &awrite);
- retcode += 1;
- }
- }
- }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "send to the socket %d returned %d (%u)\n", i, status, error);
+#endif
+ if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) ||
+ (status == -1 && gso_result == 0 && error == WSAENOTCONN &&
+ so_error == WSAECONNREFUSED))
+ {
+ FD_SET (wfds->sds.fd_array[i], &awrite);
+ retcode += 1;
+ }
+ }
}
+ }
#if DEBUG_NETWORK
if (!nhandles || (returnedpos >= nhandles))
LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n");
#endif
if (rfds)
+ {
+ struct GNUNET_CONTAINER_SList_Iterator t;
+
+ for (i = 0; i < rfds->sds.fd_count; i++)
{
- struct GNUNET_CONTAINER_SList_Iterator t;
+ WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0);
+ nsock++;
+ }
+ for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
+ GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (&t))
+ {
+ struct GNUNET_DISK_FileHandle *fh;
- for (i = 0; i < rfds->sds.fd_count; i++)
- {
- WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0);
- nsock++;
- }
- for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
- GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
- GNUNET_CONTAINER_slist_next (&t))
- {
- struct GNUNET_DISK_FileHandle *fh;
-
- fh =
- (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
- NULL);
- if (fh->type == GNUNET_PIPE)
- {
- CancelIo (fh->h);
- }
- }
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
+ NULL);
+ if (fh->type == GNUNET_PIPE)
+ {
+ CancelIo (fh->h);
+ }
+ }
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n");
#endif
- GNUNET_NETWORK_fdset_zero (rfds);
- if (retcode != -1 && nhandles && (returnedpos < nhandles))
- GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
- GNUNET_CONTAINER_slist_append (rfds->handles, handles_read);
- }
+ GNUNET_NETWORK_fdset_zero (rfds);
+ if (retcode != -1 && nhandles && (returnedpos < nhandles))
+ GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
+ GNUNET_CONTAINER_slist_append (rfds->handles, handles_read);
+ }
if (wfds)
+ {
+ for (i = 0; i < wfds->sds.fd_count; i++)
{
- for (i = 0; i < wfds->sds.fd_count; i++)
- {
- WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0);
- nsock++;
- }
+ WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0);
+ nsock++;
+ }
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n");
#endif
- GNUNET_NETWORK_fdset_zero (wfds);
- if (retcode != -1 && nhandles && (returnedpos < nhandles))
- GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
- GNUNET_CONTAINER_slist_append (wfds->handles, handles_write);
- }
+ GNUNET_NETWORK_fdset_zero (wfds);
+ if (retcode != -1 && nhandles && (returnedpos < nhandles))
+ GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
+ GNUNET_CONTAINER_slist_append (wfds->handles, handles_write);
+ }
if (efds)
+ {
+ for (i = 0; i < efds->sds.fd_count; i++)
{
- for (i = 0; i < efds->sds.fd_count; i++)
- {
- WSAEventSelect (efds->sds.fd_array[i], hEventException, 0);
- nsock++;
- }
+ WSAEventSelect (efds->sds.fd_array[i], hEventException, 0);
+ nsock++;
+ }
#if DEBUG_NETWORK
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n");
#endif
- GNUNET_NETWORK_fdset_zero (efds);
- if (retcode != -1 && nhandles && (returnedpos < nhandles))
- GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
- GNUNET_CONTAINER_slist_append (efds->handles, handles_except);
- }
+ GNUNET_NETWORK_fdset_zero (efds);
+ if (retcode != -1 && nhandles && (returnedpos < nhandles))
+ GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
+ GNUNET_CONTAINER_slist_append (efds->handles, handles_except);
+ }
GNUNET_CONTAINER_slist_destroy (handles_read);
GNUNET_CONTAINER_slist_destroy (handles_write);
GNUNET_CONTAINER_slist_destroy (handles_except);
#if DEBUG_NETWORK
if (rfds)
+ {
+ struct GNUNET_CONTAINER_SList_Iterator t;
+
+ for (i = 0; i < bread.fd_count; i++)
{
- struct GNUNET_CONTAINER_SList_Iterator t;
+ if (bread.fd_array[i] != 0)
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n",
+ bread.fd_array[i],
+ (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : "NOT SET");
+ }
+ for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
+ GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (&t))
+ {
+ struct GNUNET_DISK_FileHandle *fh;
- for (i = 0; i < bread.fd_count; i++)
- {
- if (bread.fd_array[i] != 0)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n",
- bread.fd_array[i],
- (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" :
- "NOT SET");
- }
- for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
- GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
- GNUNET_CONTAINER_slist_next (&t))
- {
- struct GNUNET_DISK_FileHandle *fh;
-
- fh =
- (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
- NULL);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
- }
+ fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
+ NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
}
+ }
if (wfds)
+ {
+ for (i = 0; i < bwrite.fd_count; i++)
{
- for (i = 0; i < bwrite.fd_count; i++)
- {
- if (bwrite.fd_array[i] != 0)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n",
- bwrite.fd_array[i],
- (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" :
- "NOT SET");
- }
+ if (bwrite.fd_array[i] != 0)
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n",
+ bwrite.fd_array[i],
+ (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : "NOT SET");
}
+ }
if (efds)
+ {
+ for (i = 0; i < bexcept.fd_count; i++)
{
- for (i = 0; i < bexcept.fd_count; i++)
- {
- if (bexcept.fd_array[i] != 0)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n",
- bexcept.fd_array[i],
- (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" :
- "NOT SET");
- }
+ if (bexcept.fd_array[i] != 0)
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n",
+ bexcept.fd_array[i],
+ (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : "NOT SET");
}
+ }
LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode);
#endif
if (nhandles && (returnedpos < nhandles))
if (f == NULL)
return NULL;
while (NULL != fgets (line, sizeof (line), f))
+ {
+ if ((1 ==
+ sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) &&
+ (NULL != (lgu = strstr (dir, "libgnunetutil"))))
{
- if ((1 ==
- sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s",
- dir)) && (NULL != (lgu = strstr (dir, "libgnunetutil"))))
- {
- lgu[0] = '\0';
- fclose (f);
- return GNUNET_strdup (dir);
- }
+ lgu[0] = '\0';
+ fclose (f);
+ return GNUNET_strdup (dir);
}
+ }
fclose (f);
return NULL;
}
GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ());
size = readlink (fn, lnk, sizeof (lnk) - 1);
if (size <= 0)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
- return NULL;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
+ return NULL;
+ }
GNUNET_assert (size < sizeof (lnk));
lnk[size] = '\0';
while ((lnk[size] != '/') && (size > 0))
size--;
if ((size < 4) || (lnk[size - 4] != '/'))
- {
- /* not installed in "/bin/" -- binary path probably useless */
- return NULL;
- }
+ {
+ /* not installed in "/bin/" -- binary path probably useless */
+ return NULL;
+ }
lnk[size] = '\0';
return GNUNET_strdup (lnk);
}
path = NULL;
func =
- (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath");
+ (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath");
if (!func)
return NULL;
path = &zero;
path = GNUNET_malloc (len);
ret = func (path, &len);
if (ret != 0)
- {
- GNUNET_free (path);
- return NULL;
- }
+ {
+ GNUNET_free (path);
+ return NULL;
+ }
len = strlen (path);
while ((path[len] != '/') && (len > 0))
len--;
p = NULL;
c = _dyld_image_count ();
for (i = 0; i < c; i++)
+ {
+ if (_dyld_get_image_header (i) == &_mh_dylib_header)
{
- if (_dyld_get_image_header (i) == &_mh_dylib_header)
- {
- path = _dyld_get_image_name (i);
- if (path != NULL && strlen (path) > 0)
- {
- p = GNUNET_strdup (path);
- s = p + strlen (p);
- while ((s > p) && (*s != '/'))
- s--;
- s++;
- *s = '\0';
- }
- break;
- }
+ path = _dyld_get_image_name (i);
+ if (path != NULL && strlen (path) > 0)
+ {
+ p = GNUNET_strdup (path);
+ s = p + strlen (p);
+ while ((s > p) && (*s != '/'))
+ s--;
+ s++;
+ *s = '\0';
+ }
+ break;
}
+ }
return p;
}
#endif
p = getenv ("PATH");
if (p == NULL)
return NULL;
- path = GNUNET_strdup (p); /* because we write on it */
+ path = GNUNET_strdup (p); /* because we write on it */
buf = GNUNET_malloc (strlen (path) + 20);
pos = path;
while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
- {
- *end = '\0';
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
- {
- pos = GNUNET_strdup (pos);
- GNUNET_free (buf);
- GNUNET_free (path);
- return pos;
- }
- pos = end + 1;
- }
- sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
+ {
+ *end = '\0';
+ sprintf (buf, "%s/%s", pos, binary);
+ if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
{
pos = GNUNET_strdup (pos);
GNUNET_free (buf);
GNUNET_free (path);
return pos;
}
+ pos = end + 1;
+ }
+ sprintf (buf, "%s/%s", pos, binary);
+ if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
+ {
+ pos = GNUNET_strdup (pos);
+ GNUNET_free (buf);
+ GNUNET_free (path);
+ return pos;
+ }
GNUNET_free (buf);
GNUNET_free (path);
return NULL;
n = strlen (execpath);
if (n == 0)
- {
- /* should never happen, but better safe than sorry */
- GNUNET_free (execpath);
- return NULL;
- }
+ {
+ /* should never happen, but better safe than sorry */
+ GNUNET_free (execpath);
+ return NULL;
+ }
/* remove filename itself */
while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
execpath[--n] = '\0';
if ((n > 5) &&
((0 == strcasecmp (&execpath[n - 5], "lib32")) ||
(0 == strcasecmp (&execpath[n - 5], "lib64"))))
+ {
+ if (dirkind != GNUNET_OS_IPK_LIBDIR)
{
- if (dirkind != GNUNET_OS_IPK_LIBDIR)
- {
- /* strip '/lib32' or '/lib64' */
- execpath[n - 5] = '\0';
- n -= 5;
- }
- else
- isbasedir = 0;
+ /* strip '/lib32' or '/lib64' */
+ execpath[n - 5] = '\0';
+ n -= 5;
}
+ else
+ isbasedir = 0;
+ }
else if ((n > 3) &&
- ((0 == strcasecmp (&execpath[n - 3], "bin")) ||
- (0 == strcasecmp (&execpath[n - 3], "lib"))))
- {
- /* strip '/bin' or '/lib' */
- execpath[n - 3] = '\0';
- n -= 3;
- }
+ ((0 == strcasecmp (&execpath[n - 3], "bin")) ||
+ (0 == strcasecmp (&execpath[n - 3], "lib"))))
+ {
+ /* strip '/bin' or '/lib' */
+ execpath[n - 3] = '\0';
+ n -= 3;
+ }
/* in case this was a directory named foo-bin, remove "foo-" */
while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
execpath[--n] = '\0';
switch (dirkind)
- {
- case GNUNET_OS_IPK_PREFIX:
- case GNUNET_OS_IPK_SELF_PREFIX:
- dirname = DIR_SEPARATOR_STR;
- break;
- case GNUNET_OS_IPK_BINDIR:
- dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR;
- break;
- case GNUNET_OS_IPK_LIBDIR:
- if (isbasedir)
- dirname =
- DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet"
- DIR_SEPARATOR_STR;
- else
- dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
- break;
- case GNUNET_OS_IPK_DATADIR:
- dirname =
- DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet"
- DIR_SEPARATOR_STR;
- break;
- case GNUNET_OS_IPK_LOCALEDIR:
- dirname =
- DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale"
- DIR_SEPARATOR_STR;
- break;
- case GNUNET_OS_IPK_ICONDIR:
+ {
+ case GNUNET_OS_IPK_PREFIX:
+ case GNUNET_OS_IPK_SELF_PREFIX:
+ dirname = DIR_SEPARATOR_STR;
+ break;
+ case GNUNET_OS_IPK_BINDIR:
+ dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR;
+ break;
+ case GNUNET_OS_IPK_LIBDIR:
+ if (isbasedir)
dirname =
- DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR;
- break;
- default:
- GNUNET_free (execpath);
- return NULL;
- }
+ DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
+ else
+ dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
+ break;
+ case GNUNET_OS_IPK_DATADIR:
+ dirname =
+ DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
+ break;
+ case GNUNET_OS_IPK_LOCALEDIR:
+ dirname =
+ DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR;
+ break;
+ case GNUNET_OS_IPK_ICONDIR:
+ dirname =
+ DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR;
+ break;
+ default:
+ GNUNET_free (execpath);
+ return NULL;
+ }
tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1);
sprintf (tmp, "%s%s", execpath, dirname);
GNUNET_free (execpath);
GNUNET_asprintf (&binaryexe, "%s.exe", binary);
p = get_path_from_PATH (binaryexe);
if (p != NULL)
- {
- GNUNET_asprintf (&pf, "%s/%s", p, binaryexe);
- GNUNET_free (p);
- p = pf;
- }
+ {
+ GNUNET_asprintf (&pf, "%s/%s", p, binaryexe);
+ GNUNET_free (p);
+ p = pf;
+ }
free (binaryexe);
#else
p = get_path_from_PATH (binary);
if (p != NULL)
- {
- GNUNET_asprintf (&pf, "%s/%s", p, binary);
- GNUNET_free (p);
- p = pf;
- }
+ {
+ GNUNET_asprintf (&pf, "%s/%s", p, binary);
+ GNUNET_free (p);
+ p = pf;
+ }
#endif
if (p == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Could not find binary `%s' in PATH!\n"), binary);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Could not find binary `%s' in PATH!\n"),
+ binary);
+ return GNUNET_SYSERR;
+ }
if (0 != STAT (p, &statbuf))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
- STRERROR (errno));
- GNUNET_free (p);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
+ STRERROR (errno));
+ GNUNET_free (p);
+ return GNUNET_SYSERR;
+ }
#ifndef MINGW
if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
- {
- GNUNET_free (p);
- return GNUNET_YES;
- }
+ {
+ GNUNET_free (p);
+ return GNUNET_YES;
+ }
if (0 == ACCESS (p, X_OK))
- {
- GNUNET_free (p);
- return GNUNET_NO;
- }
+ {
+ GNUNET_free (p);
+ return GNUNET_NO;
+ }
GNUNET_free (p);
return GNUNET_SYSERR;
#else
GNUNET_free (p);
rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (INVALID_SOCKET == rawsock)
- {
- DWORD err = GetLastError ();
+ {
+ DWORD err = GetLastError ();
- LOG (GNUNET_ERROR_TYPE_INFO,
- "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n",
- err);
- return GNUNET_NO; /* not running as administrator */
- }
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err);
+ return GNUNET_NO; /* not running as administrator */
+ }
closesocket (rawsock);
return GNUNET_YES;
#endif
*/
void
GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
- void *proc_cls)
+ void *proc_cls)
{
#ifdef MINGW
PMIB_IFTABLE pTable;
IPAddr theIP;
/* Determine our external NIC */
- theIP = inet_addr ("192.0.34.166"); /* www.example.com */
+ theIP = inet_addr ("192.0.34.166"); /* www.example.com */
if ((!GNGetBestInterface) ||
(GNGetBestInterface (theIP, &dwExternalNIC) != NO_ERROR))
- {
- dwExternalNIC = 0;
- }
+ {
+ dwExternalNIC = 0;
+ }
/* Enumerate NICs */
EnumNICs (&pTable, &pAddrTable);
if (pTable)
+ {
+ for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++)
{
- for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++)
- {
- char szEntry[1001];
- DWORD dwIP = 0;
- PIP_ADAPTER_INFO pAdapterInfo;
- PIP_ADAPTER_INFO pAdapter = NULL;
- DWORD dwRetVal = 0;
-
- /* Get IP-Address */
- int i;
-
- for (i = 0; i < pAddrTable->dwNumEntries; i++)
- {
- if (pAddrTable->table[i].dwIndex ==
- pTable->table[dwIfIdx].dwIndex)
- {
- dwIP = pAddrTable->table[i].dwAddr;
- break;
- }
- }
-
- if (dwIP)
- {
- BYTE bPhysAddr[MAXLEN_PHYSADDR];
- char *pszIfName = NULL;
- char dst[INET_ADDRSTRLEN];
- struct sockaddr_in sa;
-
- /* Get friendly interface name */
- pAdapterInfo =
- (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO));
- ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
-
- /* Make an initial call to GetAdaptersInfo to get
- * the necessary size into the ulOutBufLen variable */
- if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) ==
- ERROR_BUFFER_OVERFLOW)
- {
- free (pAdapterInfo);
- pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
- }
-
- if ((dwRetVal =
- GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
- {
- pAdapter = pAdapterInfo;
- while (pAdapter)
- {
- if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index)
- {
- char szKey[251];
- long lLen = 250;
-
- sprintf (szKey,
- "SYSTEM\\CurrentControlSet\\Control\\Network\\"
- "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",
- pAdapter->AdapterName);
- pszIfName = (char *) malloc (251);
- if (QueryRegistry
- (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName,
- &lLen) != ERROR_SUCCESS)
- {
- free (pszIfName);
- pszIfName = NULL;
- }
- }
- pAdapter = pAdapter->Next;
- }
- }
- free (pAdapterInfo);
-
- /* Set entry */
- memset (bPhysAddr, 0, MAXLEN_PHYSADDR);
- memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr,
- pTable->table[dwIfIdx].dwPhysAddrLen);
-
- snprintf (szEntry, 1000, "%s (%s - %I64u)",
- pszIfName ? pszIfName : (char *)
- pTable->table[dwIfIdx].bDescr, inet_ntop (AF_INET,
- &dwIP, dst,
- INET_ADDRSTRLEN),
- *((unsigned long long *) bPhysAddr));
- szEntry[1000] = 0;
-
- if (pszIfName)
- free (pszIfName);
-
- sa.sin_family = AF_INET;
+ char szEntry[1001];
+ DWORD dwIP = 0;
+ PIP_ADAPTER_INFO pAdapterInfo;
+ PIP_ADAPTER_INFO pAdapter = NULL;
+ DWORD dwRetVal = 0;
+
+ /* Get IP-Address */
+ int i;
+
+ for (i = 0; i < pAddrTable->dwNumEntries; i++)
+ {
+ if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex)
+ {
+ dwIP = pAddrTable->table[i].dwAddr;
+ break;
+ }
+ }
+
+ if (dwIP)
+ {
+ BYTE bPhysAddr[MAXLEN_PHYSADDR];
+ char *pszIfName = NULL;
+ char dst[INET_ADDRSTRLEN];
+ struct sockaddr_in sa;
+
+ /* Get friendly interface name */
+ pAdapterInfo = (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO));
+ ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
+
+ /* Make an initial call to GetAdaptersInfo to get
+ * the necessary size into the ulOutBufLen variable */
+ if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) ==
+ ERROR_BUFFER_OVERFLOW)
+ {
+ free (pAdapterInfo);
+ pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
+ }
+
+ if ((dwRetVal =
+ GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
+ {
+ pAdapter = pAdapterInfo;
+ while (pAdapter)
+ {
+ if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index)
+ {
+ char szKey[251];
+ long lLen = 250;
+
+ sprintf (szKey,
+ "SYSTEM\\CurrentControlSet\\Control\\Network\\"
+ "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",
+ pAdapter->AdapterName);
+ pszIfName = (char *) malloc (251);
+ if (QueryRegistry
+ (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName,
+ &lLen) != ERROR_SUCCESS)
+ {
+ free (pszIfName);
+ pszIfName = NULL;
+ }
+ }
+ pAdapter = pAdapter->Next;
+ }
+ }
+ free (pAdapterInfo);
+
+ /* Set entry */
+ memset (bPhysAddr, 0, MAXLEN_PHYSADDR);
+ memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr,
+ pTable->table[dwIfIdx].dwPhysAddrLen);
+
+ snprintf (szEntry, 1000, "%s (%s - %I64u)",
+ pszIfName ? pszIfName : (char *) pTable->
+ table[dwIfIdx].bDescr, inet_ntop (AF_INET, &dwIP, dst,
+ INET_ADDRSTRLEN),
+ *((unsigned long long *) bPhysAddr));
+ szEntry[1000] = 0;
+
+ if (pszIfName)
+ free (pszIfName);
+
+ sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- sa.sin_len = (u_char) sizeof (struct sockaddr_in);
+ sa.sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
- sa.sin_addr.S_un.S_addr = dwIP;
-
- if (GNUNET_OK !=
- proc (proc_cls, szEntry,
- pTable->table[dwIfIdx].dwIndex == dwExternalNIC,
- (const struct sockaddr *) &sa, sizeof (sa)))
- break;
- }
- }
- GlobalFree (pAddrTable);
- GlobalFree (pTable);
+ sa.sin_addr.S_un.S_addr = dwIP;
+
+ if (GNUNET_OK !=
+ proc (proc_cls, szEntry,
+ pTable->table[dwIfIdx].dwIndex == dwExternalNIC,
+ (const struct sockaddr *) &sa, sizeof (sa)))
+ break;
+ }
}
+ GlobalFree (pAddrTable);
+ GlobalFree (pTable);
+ }
return;
socklen_t alen;
if (getifaddrs (&ifa_first) == 0)
+ {
+ for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
{
- for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
- {
- if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL &&
- (ifa_ptr->ifa_flags & IFF_UP) != 0)
- {
- if ((ifa_ptr->ifa_addr->sa_family != AF_INET) &&
- (ifa_ptr->ifa_addr->sa_family != AF_INET6))
- continue;
- if (ifa_ptr->ifa_addr->sa_family == AF_INET)
- alen = sizeof (struct sockaddr_in);
- else
- alen = sizeof (struct sockaddr_in6);
- if (GNUNET_OK !=
- proc (proc_cls, ifa_ptr->ifa_name,
- 0 == strcmp (ifa_ptr->ifa_name,
- GNUNET_DEFAULT_INTERFACE),
- ifa_ptr->ifa_addr, alen))
- break;
- }
- }
- freeifaddrs (ifa_first);
+ if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL &&
+ (ifa_ptr->ifa_flags & IFF_UP) != 0)
+ {
+ if ((ifa_ptr->ifa_addr->sa_family != AF_INET) &&
+ (ifa_ptr->ifa_addr->sa_family != AF_INET6))
+ continue;
+ if (ifa_ptr->ifa_addr->sa_family == AF_INET)
+ alen = sizeof (struct sockaddr_in);
+ else
+ alen = sizeof (struct sockaddr_in6);
+ if (GNUNET_OK !=
+ proc (proc_cls, ifa_ptr->ifa_name,
+ 0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE),
+ ifa_ptr->ifa_addr, alen))
+ break;
+ }
}
+ freeifaddrs (ifa_first);
+ }
#else
char line[1024];
const char *start;
else
f = popen ("ifconfig -a 2> /dev/null", "r");
if (!f)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "popen", "ifconfig");
- return;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ "popen", "ifconfig");
+ return;
+ }
have_ifc = GNUNET_NO;
ifc[11] = '\0';
while (NULL != fgets (line, sizeof (line), f))
+ {
+ if (strlen (line) == 0)
+ {
+ have_ifc = GNUNET_NO;
+ continue;
+ }
+ if (!isspace (line[0]))
+ {
+ have_ifc = (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO;
+ /* would end with ':' on OSX, fix it! */
+ if (ifc[strlen (ifc) - 1] == ':')
+ ifc[strlen (ifc) - 1] = '\0';
+ continue;
+ }
+ if (!have_ifc)
+ continue; /* strange input, hope for the best */
+ start = line;
+ while (('\0' != *start) && (isspace (*start)))
+ start++;
+ if ( /* Linux */
+ (1 == SSCANF (start, "inet addr:%127s", addrstr)) ||
+ (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) ||
+ /* Solaris, OS X */
+ (1 == SSCANF (start, "inet %127s", addrstr)) ||
+ (1 == SSCANF (start, "inet6 %127s", addrstr)))
{
- if (strlen (line) == 0)
- {
- have_ifc = GNUNET_NO;
- continue;
- }
- if (!isspace (line[0]))
- {
- have_ifc =
- (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO;
- /* would end with ':' on OSX, fix it! */
- if (ifc[strlen (ifc) - 1] == ':')
- ifc[strlen (ifc) - 1] = '\0';
- continue;
- }
- if (!have_ifc)
- continue; /* strange input, hope for the best */
- start = line;
- while (('\0' != *start) && (isspace (*start)))
- start++;
- if ( /* Linux */
- (1 == SSCANF (start, "inet addr:%127s", addrstr)) ||
- (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) ||
- /* Solaris, OS X */
- (1 == SSCANF (start, "inet %127s", addrstr)) ||
- (1 == SSCANF (start, "inet6 %127s", addrstr)))
- {
- /* IPv4 */
- if (1 == inet_pton (AF_INET, addrstr, &v4))
- {
- memset (&a4, 0, sizeof (a4));
- a4.sin_family = AF_INET;
+ /* IPv4 */
+ if (1 == inet_pton (AF_INET, addrstr, &v4))
+ {
+ memset (&a4, 0, sizeof (a4));
+ a4.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- a4.sin_len = (u_char) sizeof (struct sockaddr_in);
+ a4.sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
- a4.sin_addr = v4;
- if (GNUNET_OK !=
- proc (proc_cls, ifc,
- 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
- (const struct sockaddr *) &a4, sizeof (a4)))
- break;
- continue;
- }
- /* IPv6 */
- if (1 == inet_pton (AF_INET6, addrstr, &v6))
- {
- memset (&a6, 0, sizeof (a6));
- a6.sin6_family = AF_INET6;
+ a4.sin_addr = v4;
+ if (GNUNET_OK !=
+ proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
+ (const struct sockaddr *) &a4, sizeof (a4)))
+ break;
+ continue;
+ }
+ /* IPv6 */
+ if (1 == inet_pton (AF_INET6, addrstr, &v6))
+ {
+ memset (&a6, 0, sizeof (a6));
+ a6.sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
- a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
+ a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
#endif
- a6.sin6_addr = v6;
- if (GNUNET_OK !=
- proc (proc_cls, ifc,
- 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
- (const struct sockaddr *) &a6, sizeof (a6)))
- break;
- continue;
- }
- }
+ a6.sin6_addr = v6;
+ if (GNUNET_OK !=
+ proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
+ (const struct sockaddr *) &a6, sizeof (a6)))
+ break;
+ continue;
+ }
}
+ }
pclose (f);
#endif
}
*/
static void
parent_control_handler (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_DISK_FileHandle *control_pipe =
- (struct GNUNET_DISK_FileHandle *) cls;
+ (struct GNUNET_DISK_FileHandle *) cls;
int sig;
#if DEBUG_OS
- LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n",
- __FUNCTION__, tc->reason);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", __FUNCTION__,
+ tc->reason);
#endif
if (tc->reason &
(GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT |
GNUNET_SCHEDULER_REASON_PREREQ_DONE))
+ {
+ GNUNET_DISK_npipe_close (control_pipe);
+ }
+ else
+ {
+ if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) !=
+ sizeof (sig))
{
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
GNUNET_DISK_npipe_close (control_pipe);
}
- else
+ else
{
- if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) !=
- sizeof (sig))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
- GNUNET_DISK_npipe_close (control_pipe);
- }
- else
- {
#if DEBUG_OS
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n",
- sig);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", sig);
#endif
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe,
- &parent_control_handler,
- control_pipe);
- raise (sig);
- }
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ control_pipe, &parent_control_handler,
+ control_pipe);
+ raise (sig);
}
+ }
}
*/
void
GNUNET_OS_install_parent_control_handler (void *cls,
- const struct
- GNUNET_SCHEDULER_TaskContext *tc)
+ const struct
+ GNUNET_SCHEDULER_TaskContext *tc)
{
const char *env_buf;
struct GNUNET_DISK_FileHandle *control_pipe;
env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
if ((env_buf == NULL) || (strlen (env_buf) <= 0))
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Not installing a handler because $%s=%s\n"),
- GNUNET_OS_CONTROL_PIPE, env_buf);
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Not installing a handler because $%s=%s\n"),
+ GNUNET_OS_CONTROL_PIPE, env_buf);
+ return;
+ }
control_pipe =
- GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
- return;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
+ return;
+ }
#if DEBUG_OS
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding parent control handler pipe `%s' to the scheduler\n", env_buf);
#endif
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
- &parent_control_handler, control_pipe);
+ &parent_control_handler, control_pipe);
}
ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof (sig));
if (ret != sizeof (sig))
+ {
+ if (errno == ECOMM)
{
- if (errno == ECOMM)
- {
- /* Child process is not controllable via pipe */
+ /* Child process is not controllable via pipe */
#if DEBUG_OS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Child process is not controllable, will kill it directly\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Child process is not controllable, will kill it directly\n");
#endif
- }
- else if (errno == EPIPE)
- {
+ }
+ else if (errno == EPIPE)
+ {
#if DEBUG_OS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n");
#endif
- }
- else
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Failed to write into control pipe , errno is %d\n", errno);
+ }
+ else
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to write into control pipe , errno is %d\n", errno);
#if WINDOWS && !defined(__CYGWIN__)
- TerminateProcess (proc->handle, 0);
+ TerminateProcess (proc->handle, 0);
#else
- PLIBC_KILL (proc->pid, sig);
+ PLIBC_KILL (proc->pid, sig);
#endif
- }
+ }
else
- {
+ {
#if DEBUG_OS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Wrote control code into control pipe, now waiting\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Wrote control code into control pipe, now waiting\n");
#endif
#if WINDOWS
- /* Give it 3 seconds to die, then kill it in a nice Windows-specific way */
- if (WaitForSingleObject (proc->handle, 3000) != WAIT_OBJECT_0)
- TerminateProcess (proc->handle, 0);
- res = 0;
+ /* Give it 3 seconds to die, then kill it in a nice Windows-specific way */
+ if (WaitForSingleObject (proc->handle, 3000) != WAIT_OBJECT_0)
+ TerminateProcess (proc->handle, 0);
+ res = 0;
#else
- struct GNUNET_NETWORK_FDSet *rfds;
- struct GNUNET_NETWORK_FDSet *efds;
-
- rfds = GNUNET_NETWORK_fdset_create ();
- efds = GNUNET_NETWORK_fdset_create ();
-
- GNUNET_NETWORK_fdset_handle_set (rfds, proc->control_pipe);
- GNUNET_NETWORK_fdset_handle_set (efds, proc->control_pipe);
-
- /* Ndurner thought this up, and i have no idea what it does.
- * There's have never been any code to answer the shutdown call
- * (write a single int into the pipe, so that this function can read it).
- * On *nix select() will probably tell that pipe is ready
- * for reading, once the other process shuts down,
- * but the read () call will fail, triggering a kill ()
- * on the pid that is already dead. This will probably result in non-0
- * return from kill(), and therefore from this function.
- */
- while (1)
- {
- ret =
- GNUNET_NETWORK_socket_select (rfds, NULL, efds,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_relative_get_unit (),
- 5000));
-
- if (ret < 1 ||
- GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe))
- {
- /* Just to be sure */
- PLIBC_KILL (proc->pid, sig);
- res = 0;
- break;
- }
- else
- {
- if (GNUNET_DISK_file_read
- (proc->control_pipe, &ret, sizeof (ret)) != GNUNET_OK)
- res = PLIBC_KILL (proc->pid, sig);
-
- /* Child signaled shutdown is in progress */
- continue;
- }
- }
-#endif
+ struct GNUNET_NETWORK_FDSet *rfds;
+ struct GNUNET_NETWORK_FDSet *efds;
+
+ rfds = GNUNET_NETWORK_fdset_create ();
+ efds = GNUNET_NETWORK_fdset_create ();
+
+ GNUNET_NETWORK_fdset_handle_set (rfds, proc->control_pipe);
+ GNUNET_NETWORK_fdset_handle_set (efds, proc->control_pipe);
+
+ /* Ndurner thought this up, and i have no idea what it does.
+ * There's have never been any code to answer the shutdown call
+ * (write a single int into the pipe, so that this function can read it).
+ * On *nix select() will probably tell that pipe is ready
+ * for reading, once the other process shuts down,
+ * but the read () call will fail, triggering a kill ()
+ * on the pid that is already dead. This will probably result in non-0
+ * return from kill(), and therefore from this function.
+ */
+ while (1)
+ {
+ ret =
+ GNUNET_NETWORK_socket_select (rfds, NULL, efds,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_relative_get_unit (),
+ 5000));
+
+ if (ret < 1 ||
+ GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe))
+ {
+ /* Just to be sure */
+ PLIBC_KILL (proc->pid, sig);
+ res = 0;
+ break;
+ }
+ else
+ {
+ if (GNUNET_DISK_file_read (proc->control_pipe, &ret, sizeof (ret)) !=
+ GNUNET_OK)
+ res = PLIBC_KILL (proc->pid, sig);
+
+ /* Child signaled shutdown is in progress */
+ continue;
+ }
}
+#endif
+ }
return res;
#else
*/
int
GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
- enum GNUNET_SCHEDULER_Priority prio)
+ enum GNUNET_SCHEDULER_Priority prio)
{
int rprio;
/* convert to MINGW/Unix values */
switch (prio)
- {
- case GNUNET_SCHEDULER_PRIORITY_UI:
- case GNUNET_SCHEDULER_PRIORITY_URGENT:
+ {
+ case GNUNET_SCHEDULER_PRIORITY_UI:
+ case GNUNET_SCHEDULER_PRIORITY_URGENT:
#ifdef MINGW
- rprio = HIGH_PRIORITY_CLASS;
+ rprio = HIGH_PRIORITY_CLASS;
#else
- rprio = 0;
+ rprio = 0;
#endif
- break;
+ break;
- case GNUNET_SCHEDULER_PRIORITY_HIGH:
+ case GNUNET_SCHEDULER_PRIORITY_HIGH:
#ifdef MINGW
- rprio = ABOVE_NORMAL_PRIORITY_CLASS;
+ rprio = ABOVE_NORMAL_PRIORITY_CLASS;
#else
- rprio = 5;
+ rprio = 5;
#endif
- break;
+ break;
- case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
+ case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
#ifdef MINGW
- rprio = NORMAL_PRIORITY_CLASS;
+ rprio = NORMAL_PRIORITY_CLASS;
#else
- rprio = 7;
+ rprio = 7;
#endif
- break;
+ break;
- case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
+ case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
#ifdef MINGW
- rprio = BELOW_NORMAL_PRIORITY_CLASS;
+ rprio = BELOW_NORMAL_PRIORITY_CLASS;
#else
- rprio = 10;
+ rprio = 10;
#endif
- break;
+ break;
- case GNUNET_SCHEDULER_PRIORITY_IDLE:
+ case GNUNET_SCHEDULER_PRIORITY_IDLE:
#ifdef MINGW
- rprio = IDLE_PRIORITY_CLASS;
+ rprio = IDLE_PRIORITY_CLASS;
#else
- rprio = 19;
+ rprio = 19;
#endif
- break;
- default:
- GNUNET_assert (0);
- return GNUNET_SYSERR;
- }
+ break;
+ default:
+ GNUNET_assert (0);
+ return GNUNET_SYSERR;
+ }
/* Set process priority */
#ifdef MINGW
pid = proc->pid;
if ((0 == pid) || (pid == getpid ()))
+ {
+ int have = nice (0);
+ int delta = rprio - have;
+
+ errno = 0;
+ if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
{
- int have = nice (0);
- int delta = rprio - have;
-
- errno = 0;
- if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- "nice");
- return GNUNET_SYSERR;
- }
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "nice");
+ return GNUNET_SYSERR;
}
+ }
else
+ {
+ if (0 != setpriority (PRIO_PROCESS, pid, rprio))
{
- if (0 != setpriority (PRIO_PROCESS, pid, rprio))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- "setpriority");
- return GNUNET_SYSERR;
- }
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ "setpriority");
+ return GNUNET_SYSERR;
}
+ }
#else
#if DEBUG_OS
LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
win32_env_table = GetEnvironmentStringsA ();
if (win32_env_table == NULL)
return NULL;
- for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++);
+ for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ;
n_var = c;
index = GNUNET_malloc (sizeof (char *) * n_var);
for (c = 0; c < n_var; c++)
index[c] = 0;
for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++)
+ {
+ size_t len = strlen (ptr);
+ int found = 0;
+
+ for (var_ptr = vars; *var_ptr; var_ptr++)
{
- size_t len = strlen (ptr);
- int found = 0;
-
- for (var_ptr = vars; *var_ptr; var_ptr++)
- {
- var = *var_ptr++;
- val = *var_ptr;
- var_len = strlen (var);
- if (strncmp (var, ptr, var_len) == 0)
- {
- found = 1;
- index[c] = 1;
- tablesize += var_len + strlen (val) + 1;
- break;
- }
- }
- if (!found)
- tablesize += len + 1;
- ptr += len + 1;
+ var = *var_ptr++;
+ val = *var_ptr;
+ var_len = strlen (var);
+ if (strncmp (var, ptr, var_len) == 0)
+ {
+ found = 1;
+ index[c] = 1;
+ tablesize += var_len + strlen (val) + 1;
+ break;
+ }
}
+ if (!found)
+ tablesize += len + 1;
+ ptr += len + 1;
+ }
for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
+ {
+ var = *var_ptr++;
+ val = *var_ptr;
+ if (index[c] != 1)
+ n_found += strlen (var) + strlen (val) + 1;
+ }
+ result = GNUNET_malloc (tablesize + n_found + 1);
+ for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
+ {
+ size_t len = strlen (ptr);
+ int found = 0;
+
+ for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
{
var = *var_ptr++;
val = *var_ptr;
- if (index[c] != 1)
- n_found += strlen (var) + strlen (val) + 1;
+ var_len = strlen (var);
+ if (strncmp (var, ptr, var_len) == 0)
+ {
+ found = 1;
+ break;
+ }
}
- result = GNUNET_malloc (tablesize + n_found + 1);
- for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
+ if (!found)
{
- size_t len = strlen (ptr);
- int found = 0;
-
- for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
- {
- var = *var_ptr++;
- val = *var_ptr;
- var_len = strlen (var);
- if (strncmp (var, ptr, var_len) == 0)
- {
- found = 1;
- break;
- }
- }
- if (!found)
- {
- strcpy (result_ptr, ptr);
- result_ptr += len + 1;
- }
- else
- {
- strcpy (result_ptr, var);
- result_ptr += var_len;
- strcpy (result_ptr, val);
- result_ptr += strlen (val) + 1;
- }
- ptr += len + 1;
+ strcpy (result_ptr, ptr);
+ result_ptr += len + 1;
+ }
+ else
+ {
+ strcpy (result_ptr, var);
+ result_ptr += var_len;
+ strcpy (result_ptr, val);
+ result_ptr += strlen (val) + 1;
}
+ ptr += len + 1;
+ }
for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
+ {
+ var = *var_ptr++;
+ val = *var_ptr;
+ var_len = strlen (var);
+ if (index[c] != 1)
{
- var = *var_ptr++;
- val = *var_ptr;
- var_len = strlen (var);
- if (index[c] != 1)
- {
- strcpy (result_ptr, var);
- result_ptr += var_len;
- strcpy (result_ptr, val);
- result_ptr += strlen (val) + 1;
- }
+ strcpy (result_ptr, var);
+ result_ptr += var_len;
+ strcpy (result_ptr, val);
+ result_ptr += strlen (val) + 1;
}
+ }
FreeEnvironmentStrings (win32_env_table);
GNUNET_free (index);
*result_ptr = 0;
*/
struct GNUNET_OS_Process *
GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
- struct GNUNET_DISK_PipeHandle *pipe_stdout,
- const char *filename, va_list va)
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ const char *filename, va_list va)
{
va_list ap;
#if ENABLE_WINDOWS_WORKAROUNDS
control_pipe =
- GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
return NULL;
#endif
argc = 0;
va_copy (ap, va);
while (NULL != va_arg (ap, char *))
- argc++;
+ argc++;
va_end (ap);
argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
argc = 0;
va_copy (ap, va);
while (NULL != (argv[argc] = va_arg (ap, char *)))
- argc++;
+ argc++;
va_end (ap);
if (pipe_stdout != NULL)
- {
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE),
- &fd_stdout_write, sizeof (int));
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_READ),
- &fd_stdout_read, sizeof (int));
- }
+ {
+ GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
+ (pipe_stdout,
+ GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stdout_write, sizeof (int));
+ GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
+ (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
+ &fd_stdout_read, sizeof (int));
+ }
if (pipe_stdin != NULL)
- {
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin,
- GNUNET_DISK_PIPE_END_READ),
- &fd_stdin_read, sizeof (int));
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin,
- GNUNET_DISK_PIPE_END_WRITE),
- &fd_stdin_write, sizeof (int));
- }
+ {
+ GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
+ (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
+ &fd_stdin_read, sizeof (int));
+ GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
+ (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stdin_write, sizeof (int));
+ }
#if HAVE_WORKING_VFORK
ret = vfork ();
ret = fork ();
#endif
if (ret != 0)
+ {
+ if (ret == -1)
{
- if (ret == -1)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
#if ENABLE_WINDOWS_WORKAROUNDS
- GNUNET_DISK_npipe_close (control_pipe);
+ GNUNET_DISK_npipe_close (control_pipe);
#endif
- }
- else
- {
+ }
+ else
+ {
#if HAVE_WORKING_VFORK
- /* let's hope vfork actually works; for some extreme cases (including
- * a testcase) we need 'execvp' to have run before we return, since
- * we may send a signal to the process next and we don't want it
- * to be caught by OUR signal handler (but either by the default
- * handler or the actual handler as installed by the process itself). */
+ /* let's hope vfork actually works; for some extreme cases (including
+ * a testcase) we need 'execvp' to have run before we return, since
+ * we may send a signal to the process next and we don't want it
+ * to be caught by OUR signal handler (but either by the default
+ * handler or the actual handler as installed by the process itself). */
#else
- /* let's give the child process a chance to run execvp, 1s should
- * be plenty in practice */
- if (pipe_stdout != NULL)
- GNUNET_DISK_pipe_close_end (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE);
- if (pipe_stdin != NULL)
- GNUNET_DISK_pipe_close_end (pipe_stdin,
- GNUNET_DISK_PIPE_END_READ);
- sleep (1);
+ /* let's give the child process a chance to run execvp, 1s should
+ * be plenty in practice */
+ if (pipe_stdout != NULL)
+ GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
+ if (pipe_stdin != NULL)
+ GNUNET_DISK_pipe_close_end (pipe_stdin, GNUNET_DISK_PIPE_END_READ);
+ sleep (1);
#endif
- gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
- gnunet_proc->pid = ret;
+ gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
+ gnunet_proc->pid = ret;
#if ENABLE_WINDOWS_WORKAROUNDS
- gnunet_proc->control_pipe = control_pipe;
+ gnunet_proc->control_pipe = control_pipe;
#endif
- }
- GNUNET_free (argv);
+ }
+ GNUNET_free (argv);
#if ENABLE_WINDOWS_WORKAROUNDS
- GNUNET_free (childpipename);
+ GNUNET_free (childpipename);
#endif
- return gnunet_proc;
- }
+ return gnunet_proc;
+ }
#if ENABLE_WINDOWS_WORKAROUNDS
setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1);
#endif
if (pipe_stdout != NULL)
- {
- GNUNET_break (0 == close (fd_stdout_read));
- if (-1 == dup2 (fd_stdout_write, 1))
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
- GNUNET_break (0 == close (fd_stdout_write));
- }
+ {
+ GNUNET_break (0 == close (fd_stdout_read));
+ if (-1 == dup2 (fd_stdout_write, 1))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ GNUNET_break (0 == close (fd_stdout_write));
+ }
if (pipe_stdin != NULL)
- {
+ {
- GNUNET_break (0 == close (fd_stdin_write));
- if (-1 == dup2 (fd_stdin_read, 0))
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
- GNUNET_break (0 == close (fd_stdin_read));
- }
+ GNUNET_break (0 == close (fd_stdin_write));
+ if (-1 == dup2 (fd_stdin_read, 0))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ GNUNET_break (0 == close (fd_stdin_read));
+ }
execvp (filename, argv);
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
_exit (1);
pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
alloc_len =
- pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
- strlen (libdir);
+ pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
+ strlen (libdir);
pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
if (non_const_filename[1] == ':')
snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
else if (!SearchPathA
- (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
- path, NULL))
- {
- SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
- non_const_filename);
- GNUNET_free (non_const_filename);
- GNUNET_free (pathbuf);
- return NULL;
- }
+ (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
+ path, NULL))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
+ non_const_filename);
+ GNUNET_free (non_const_filename);
+ GNUNET_free (pathbuf);
+ return NULL;
+ }
GNUNET_free (pathbuf);
GNUNET_free (non_const_filename);
cmdlen = 0;
va_copy (ap, va);
while (NULL != (arg = va_arg (ap, char *)))
- {
- if (cmdlen == 0)
- cmdlen = cmdlen + strlen (path) + 3;
- else
- cmdlen = cmdlen + strlen (arg) + 3;
- }
+ {
+ if (cmdlen == 0)
+ cmdlen = cmdlen + strlen (path) + 3;
+ else
+ cmdlen = cmdlen + strlen (arg) + 3;
+ }
va_end (ap);
cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1));
va_copy (ap, va);
while (NULL != (arg = va_arg (ap, char *)))
- {
- if (idx == cmd)
- idx += sprintf (idx, "\"%s\" ", path);
- else
- idx += sprintf (idx, "\"%s\" ", arg);
- }
+ {
+ if (idx == cmd)
+ idx += sprintf (idx, "\"%s\" ", path);
+ else
+ idx += sprintf (idx, "\"%s\" ", arg);
+ }
va_end (ap);
memset (&start, 0, sizeof (start));
start.dwFlags |= STARTF_USESTDHANDLES;
if (pipe_stdin != NULL)
- {
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin,
- GNUNET_DISK_PIPE_END_READ),
- &stdin_handle, sizeof (HANDLE));
- start.hStdInput = stdin_handle;
- }
+ {
+ GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
+ (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
+ &stdin_handle, sizeof (HANDLE));
+ start.hStdInput = stdin_handle;
+ }
if (pipe_stdout != NULL)
- {
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE),
- &stdout_handle, sizeof (HANDLE));
- start.hStdOutput = stdout_handle;
- }
+ {
+ GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
+ (pipe_stdout,
+ GNUNET_DISK_PIPE_END_WRITE),
+ &stdout_handle, sizeof (HANDLE));
+ start.hStdOutput = stdout_handle;
+ }
control_pipe =
- GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
- {
- GNUNET_free (cmd);
- GNUNET_free (path);
- return NULL;
- }
+ {
+ GNUNET_free (cmd);
+ GNUNET_free (path);
+ return NULL;
+ }
#if DEBUG_OS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Opened the parent end of the pipe `%s'\n", childpipename);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n",
+ childpipename);
#endif
GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE);
if (!CreateProcessA
(path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED,
env_block, NULL, &start, &proc))
- {
- SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
- GNUNET_free (env_block);
- GNUNET_free (cmd);
- return NULL;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ return NULL;
+ }
GNUNET_free (env_block);
*/
struct GNUNET_OS_Process *
GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
- struct GNUNET_DISK_PipeHandle *pipe_stdout,
- const char *filename, ...)
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ const char *filename, ...)
{
struct GNUNET_OS_Process *ret;
va_list ap;
*/
struct GNUNET_OS_Process *
GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
- char *const argv[])
+ char *const argv[])
{
#if ENABLE_WINDOWS_WORKAROUNDS
struct GNUNET_DISK_FileHandle *control_pipe = NULL;
#if ENABLE_WINDOWS_WORKAROUNDS
control_pipe =
- GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
return NULL;
#endif
lscp = NULL;
ls = 0;
if (lsocks != NULL)
- {
- i = 0;
- while (-1 != (k = lsocks[i++]))
- GNUNET_array_append (lscp, ls, k);
- GNUNET_array_append (lscp, ls, -1);
- }
+ {
+ i = 0;
+ while (-1 != (k = lsocks[i++]))
+ GNUNET_array_append (lscp, ls, k);
+ GNUNET_array_append (lscp, ls, -1);
+ }
#if HAVE_WORKING_VFORK
ret = vfork ();
#else
ret = fork ();
#endif
if (ret != 0)
+ {
+ if (ret == -1)
{
- if (ret == -1)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
#if ENABLE_WINDOWS_WORKAROUNDS
- GNUNET_DISK_npipe_close (control_pipe);
+ GNUNET_DISK_npipe_close (control_pipe);
#endif
- }
- else
- {
+ }
+ else
+ {
#if HAVE_WORKING_VFORK
- /* let's hope vfork actually works; for some extreme cases (including
- * a testcase) we need 'execvp' to have run before we return, since
- * we may send a signal to the process next and we don't want it
- * to be caught by OUR signal handler (but either by the default
- * handler or the actual handler as installed by the process itself). */
+ /* let's hope vfork actually works; for some extreme cases (including
+ * a testcase) we need 'execvp' to have run before we return, since
+ * we may send a signal to the process next and we don't want it
+ * to be caught by OUR signal handler (but either by the default
+ * handler or the actual handler as installed by the process itself). */
#else
- /* let's give the child process a chance to run execvp, 1s should
- * be plenty in practice */
- sleep (1);
+ /* let's give the child process a chance to run execvp, 1s should
+ * be plenty in practice */
+ sleep (1);
#endif
- gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
- gnunet_proc->pid = ret;
+ gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
+ gnunet_proc->pid = ret;
#if ENABLE_WINDOWS_WORKAROUNDS
- gnunet_proc->control_pipe = control_pipe;
+ gnunet_proc->control_pipe = control_pipe;
#endif
- }
- GNUNET_array_grow (lscp, ls, 0);
+ }
+ GNUNET_array_grow (lscp, ls, 0);
#if ENABLE_WINDOWS_WORKAROUNDS
- GNUNET_free (childpipename);
+ GNUNET_free (childpipename);
#endif
- return gnunet_proc;
- }
+ return gnunet_proc;
+ }
#if ENABLE_WINDOWS_WORKAROUNDS
setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1);
#endif
if (lscp != NULL)
+ {
+ /* read systemd documentation... */
+ GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ());
+ setenv ("LISTEN_PID", lpid, 1);
+ i = 0;
+ tgt = 3;
+ while (-1 != lscp[i])
{
- /* read systemd documentation... */
- GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ());
- setenv ("LISTEN_PID", lpid, 1);
- i = 0;
- tgt = 3;
- while (-1 != lscp[i])
- {
- j = i + 1;
- while (-1 != lscp[j])
- {
- if (lscp[j] == tgt)
- {
- /* dup away */
- k = dup (lscp[j]);
- GNUNET_assert (-1 != k);
- GNUNET_assert (0 == close (lscp[j]));
- lscp[j] = k;
- break;
- }
- j++;
- }
- if (lscp[i] != tgt)
- {
- /* Bury any existing FD, no matter what; they should all be closed
- * on exec anyway and the important onces have been dup'ed away */
- (void) close (tgt);
- GNUNET_assert (-1 != dup2 (lscp[i], tgt));
- }
- /* unset close-on-exec flag */
- flags = fcntl (tgt, F_GETFD);
- GNUNET_assert (flags >= 0);
- flags &= ~FD_CLOEXEC;
- fflush (stderr);
- (void) fcntl (tgt, F_SETFD, flags);
- tgt++;
- i++;
- }
- GNUNET_snprintf (fds, sizeof (fds), "%u", i);
- setenv ("LISTEN_FDS", fds, 1);
+ j = i + 1;
+ while (-1 != lscp[j])
+ {
+ if (lscp[j] == tgt)
+ {
+ /* dup away */
+ k = dup (lscp[j]);
+ GNUNET_assert (-1 != k);
+ GNUNET_assert (0 == close (lscp[j]));
+ lscp[j] = k;
+ break;
+ }
+ j++;
+ }
+ if (lscp[i] != tgt)
+ {
+ /* Bury any existing FD, no matter what; they should all be closed
+ * on exec anyway and the important onces have been dup'ed away */
+ (void) close (tgt);
+ GNUNET_assert (-1 != dup2 (lscp[i], tgt));
+ }
+ /* unset close-on-exec flag */
+ flags = fcntl (tgt, F_GETFD);
+ GNUNET_assert (flags >= 0);
+ flags &= ~FD_CLOEXEC;
+ fflush (stderr);
+ (void) fcntl (tgt, F_SETFD, flags);
+ tgt++;
+ i++;
}
+ GNUNET_snprintf (fds, sizeof (fds), "%u", i);
+ setenv ("LISTEN_FDS", fds, 1);
+ }
GNUNET_array_grow (lscp, ls, 0);
execvp (filename, argv);
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
alloc_len =
- pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
- strlen (libdir);
+ pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
+ strlen (libdir);
pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len);
if (alloc_len != pathbuf_len - 1)
- {
- GNUNET_free (pathbuf);
- errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
- return NULL;
- }
+ {
+ GNUNET_free (pathbuf);
+ errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
+ return NULL;
+ }
cmdlen = strlen (filename);
if (cmdlen < 5 || strcmp (&filename[cmdlen - 4], ".exe") != 0)
if (non_const_filename[1] == ':')
snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
else if (!SearchPathA
- (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
- path, NULL))
- {
- SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
- non_const_filename);
- GNUNET_free (non_const_filename);
- GNUNET_free (pathbuf);
- return NULL;
- }
+ (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
+ path, NULL))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
+ non_const_filename);
+ GNUNET_free (non_const_filename);
+ GNUNET_free (pathbuf);
+ return NULL;
+ }
GNUNET_free (pathbuf);
GNUNET_free (non_const_filename);
/* Count the number of arguments */
arg = (char **) argv;
while (*arg)
- {
- arg++;
- argcount++;
- }
+ {
+ arg++;
+ argcount++;
+ }
/* Allocate a copy argv */
non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1));
argcount = 0;
arg = (char **) argv;
while (*arg)
- {
- if (arg == argv)
- non_const_argv[argcount] = GNUNET_strdup (path);
- else
- non_const_argv[argcount] = GNUNET_strdup (*arg);
- arg++;
- argcount++;
- }
+ {
+ if (arg == argv)
+ non_const_argv[argcount] = GNUNET_strdup (path);
+ else
+ non_const_argv[argcount] = GNUNET_strdup (*arg);
+ arg++;
+ argcount++;
+ }
non_const_argv[argcount] = NULL;
/* Count cmd len */
cmdlen = 1;
arg = non_const_argv;
while (*arg)
- {
- cmdlen = cmdlen + strlen (*arg) + 3;
- arg++;
- }
+ {
+ cmdlen = cmdlen + strlen (*arg) + 3;
+ arg++;
+ }
/* Allocate and create cmd */
cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
arg = non_const_argv;
while (*arg)
- {
- idx += sprintf (idx, "\"%s\" ", *arg);
- arg++;
- }
+ {
+ idx += sprintf (idx, "\"%s\" ", *arg);
+ arg++;
+ }
while (argcount > 0)
GNUNET_free (non_const_argv[--argcount]);
start.cb = sizeof (start);
control_pipe =
- GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
- {
- GNUNET_free (cmd);
- GNUNET_free (path);
- return NULL;
- }
+ {
+ GNUNET_free (cmd);
+ GNUNET_free (path);
+ return NULL;
+ }
#if DEBUG_OS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Opened the parent end of the pipe `%s'\n", childpipename);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n",
+ childpipename);
#endif
GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE);
if (!CreateProcess
(path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS | CREATE_SUSPENDED,
env_block, NULL, &start, &proc))
- {
- SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
- GNUNET_free (env_block);
- GNUNET_free (cmd);
- return NULL;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
+ GNUNET_free (env_block);
+ GNUNET_free (cmd);
+ return NULL;
+ }
GNUNET_free (env_block);
*/
int
GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
- enum GNUNET_OS_ProcessStatusType *type,
- unsigned long *code)
+ enum GNUNET_OS_ProcessStatusType *type,
+ unsigned long *code)
{
#ifndef MINGW
int status;
GNUNET_assert (0 != proc);
ret = waitpid (proc->pid, &status, WNOHANG);
if (ret < 0)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ return GNUNET_SYSERR;
+ }
if (0 == ret)
- {
- *type = GNUNET_OS_PROCESS_RUNNING;
- *code = 0;
- return GNUNET_NO;
- }
+ {
+ *type = GNUNET_OS_PROCESS_RUNNING;
+ *code = 0;
+ return GNUNET_NO;
+ }
if (proc->pid != ret)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ return GNUNET_SYSERR;
+ }
if (WIFEXITED (status))
- {
- *type = GNUNET_OS_PROCESS_EXITED;
- *code = WEXITSTATUS (status);
- }
+ {
+ *type = GNUNET_OS_PROCESS_EXITED;
+ *code = WEXITSTATUS (status);
+ }
else if (WIFSIGNALED (status))
- {
- *type = GNUNET_OS_PROCESS_SIGNALED;
- *code = WTERMSIG (status);
- }
+ {
+ *type = GNUNET_OS_PROCESS_SIGNALED;
+ *code = WTERMSIG (status);
+ }
else if (WIFSTOPPED (status))
- {
- *type = GNUNET_OS_PROCESS_SIGNALED;
- *code = WSTOPSIG (status);
- }
+ {
+ *type = GNUNET_OS_PROCESS_SIGNALED;
+ *code = WSTOPSIG (status);
+ }
#ifdef WIFCONTINUED
else if (WIFCONTINUED (status))
- {
- *type = GNUNET_OS_PROCESS_RUNNING;
- *code = 0;
- }
+ {
+ *type = GNUNET_OS_PROCESS_RUNNING;
+ *code = 0;
+ }
#endif
else
- {
- *type = GNUNET_OS_PROCESS_UNKNOWN;
- *code = 0;
- }
+ {
+ *type = GNUNET_OS_PROCESS_UNKNOWN;
+ *code = 0;
+ }
#else
HANDLE h;
DWORD c, error_code, ret;
h = proc->handle;
ret = proc->pid;
if (h == NULL || ret == 0)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Invalid process information {%d, %08X}\n", ret, h);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
+ ret, h);
+ return GNUNET_SYSERR;
+ }
if (h == NULL)
h = GetCurrentProcess ();
ret = GetExitCodeProcess (h, &c);
error_code = GetLastError ();
if (ret == 0 || error_code != NO_ERROR)
- {
- SetErrnoFromWinError (error_code);
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
- return GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (error_code);
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
+ return GNUNET_SYSERR;
+ }
if (STILL_ACTIVE == c)
- {
- *type = GNUNET_OS_PROCESS_RUNNING;
- *code = 0;
- return GNUNET_NO;
- }
+ {
+ *type = GNUNET_OS_PROCESS_RUNNING;
+ *code = 0;
+ return GNUNET_NO;
+ }
*type = GNUNET_OS_PROCESS_EXITED;
*code = c;
#endif
h = proc->handle;
if (NULL == h)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Invalid process information {%d, %08X}\n", proc->pid, h);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
+ proc->pid, h);
+ return GNUNET_SYSERR;
+ }
if (h == NULL)
h = GetCurrentProcess ();
if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
- {
- SetErrnoFromWinError (GetLastError ());
- ret = GNUNET_SYSERR;
- }
+ {
+ SetErrnoFromWinError (GetLastError ());
+ ret = GNUNET_SYSERR;
+ }
else
ret = GNUNET_OK;
{
if (cmd->proc != NULL)
- {
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask);
- GNUNET_SCHEDULER_cancel (cmd->rtask);
- }
+ {
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask);
+ GNUNET_SCHEDULER_cancel (cmd->rtask);
+ }
(void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip));
GNUNET_OS_process_close (cmd->eip);
ssize_t ret;
cmd->rtask = GNUNET_SCHEDULER_NO_TASK;
- if (GNUNET_YES !=
- GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
- {
- /* timeout, shutdown, etc. */
- proc = cmd->proc;
- cmd->proc = NULL;
- proc (cmd->proc_cls, NULL);
- return;
- }
+ if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
+ {
+ /* timeout, shutdown, etc. */
+ proc = cmd->proc;
+ cmd->proc = NULL;
+ proc (cmd->proc_cls, NULL);
+ return;
+ }
ret =
- GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
- sizeof (cmd->buf) - cmd->off);
+ GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
+ sizeof (cmd->buf) - cmd->off);
if (ret <= 0)
+ {
+ if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
{
- if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
- {
- cmd->buf[cmd->off] = '\0';
- cmd->proc (cmd->proc_cls, cmd->buf);
- }
- proc = cmd->proc;
- cmd->proc = NULL;
- proc (cmd->proc_cls, NULL);
- return;
+ cmd->buf[cmd->off] = '\0';
+ cmd->proc (cmd->proc_cls, cmd->buf);
}
+ proc = cmd->proc;
+ cmd->proc = NULL;
+ proc (cmd->proc_cls, NULL);
+ return;
+ }
end = memchr (&cmd->buf[cmd->off], '\n', ret);
cmd->off += ret;
while (end != NULL)
- {
- *end = '\0';
- cmd->proc (cmd->proc_cls, cmd->buf);
- memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf));
- cmd->off -= (end + 1 - cmd->buf);
- end = memchr (cmd->buf, '\n', cmd->off);
- }
+ {
+ *end = '\0';
+ cmd->proc (cmd->proc_cls, cmd->buf);
+ memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf));
+ cmd->off -= (end + 1 - cmd->buf);
+ end = memchr (cmd->buf, '\n', cmd->off);
+ }
cmd->rtask =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
- (cmd->timeout), cmd->r, &cmd_read, cmd);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
+ (cmd->timeout), cmd->r, &cmd_read, cmd);
}
*/
struct GNUNET_OS_CommandHandle *
GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
- struct GNUNET_TIME_Relative timeout,
- const char *binary, ...)
+ struct GNUNET_TIME_Relative timeout, const char *binary,
+ ...)
{
struct GNUNET_OS_CommandHandle *cmd;
struct GNUNET_OS_Process *eip;
eip = GNUNET_OS_start_process_va (NULL, opipe, binary, ap);
va_end (ap);
if (NULL == eip)
- {
- GNUNET_DISK_pipe_close (opipe);
- return NULL;
- }
+ {
+ GNUNET_DISK_pipe_close (opipe);
+ return NULL;
+ }
GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE);
cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle));
cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout);
cmd->proc = proc;
cmd->proc_cls = proc_cls;
cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
- cmd->rtask =
- GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
+ cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
return cmd;
}
* @return the interned identity.
*/
GNUNET_PEER_Id
-GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
+GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
{
GNUNET_PEER_Id ret;
struct PeerEntry *e;
off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
e = (off == 0) ? NULL : &table[off];
if (e != NULL)
- {
- GNUNET_assert (e->rc > 0);
- e->rc++;
- return e->pid;
- }
+ {
+ GNUNET_assert (e->rc > 0);
+ e->rc++;
+ return e->pid;
+ }
ret = free_list_start;
if (ret == size)
- {
- GNUNET_array_grow (table, size, size + 16);
- for (i = ret; i < size; i++)
- table[i].pid = i + 1;
- }
+ {
+ GNUNET_array_grow (table, size, size + 16);
+ for (i = ret; i < size; i++)
+ table[i].pid = i + 1;
+ }
if (ret == 0)
- {
- table[0].pid = 0;
- table[0].rc = 1;
- ret = 1;
- }
+ {
+ table[0].pid = 0;
+ table[0].rc = 1;
+ ret = 1;
+ }
GNUNET_assert (ret < size);
GNUNET_assert (table[ret].rc == 0);
free_list_start = table[ret].pid;
table[ret].rc = 1;
table[ret].pid = ret;
GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey,
- (void *) (long) ret,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey,
+ (void *) (long) ret,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return ret;
}
* @param count size of the ids array
*/
void
-GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count)
+GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count)
{
int i;
GNUNET_PEER_Id id;
if (count == 0)
return;
for (i = count - 1; i >= 0; i--)
+ {
+ id = ids[i];
+ if (id == 0)
+ continue;
+ GNUNET_assert (id < size);
+ GNUNET_assert (table[id].rc > 0);
+ table[id].rc--;
+ if (table[id].rc == 0)
{
- id = ids[i];
- if (id == 0)
- continue;
- GNUNET_assert (id < size);
- GNUNET_assert (table[id].rc > 0);
- table[id].rc--;
- if (table[id].rc == 0)
- {
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (map,
- &table[id].
- id.hashPubKey,
- (void *) (long)
- id));
- table[id].pid = free_list_start;
- free_list_start = id;
- }
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (map,
+ &table[id].
+ id.hashPubKey,
+ (void *) (long) id));
+ table[id].pid = free_list_start;
+ free_list_start = id;
}
+ }
}
GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta));
table[id].rc += delta;
if (table[id].rc == 0)
- {
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (map,
- &table[id].
- id.hashPubKey,
- (void *) (long)
- id));
- table[id].pid = free_list_start;
- free_list_start = id;
- }
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (map,
+ &table[id].
+ id.hashPubKey,
+ (void *) (long) id));
+ table[id].pid = free_list_start;
+ free_list_start = id;
+ }
}
GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
{
if (id == 0)
- {
- memset (pid, 0, sizeof (struct GNUNET_PeerIdentity));
- GNUNET_break (0);
- return;
- }
+ {
+ memset (pid, 0, sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_break (0);
+ return;
+ }
GNUNET_assert (id < size);
GNUNET_assert (table[id].rc > 0);
*pid = table[id].id;
memset (buf, 1, 1024 * 64);
GNUNET_CRYPTO_hash ("foo", 3, &hc1);
for (i = 0; i < 1024; i++)
- {
- GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2);
- GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1);
- GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3);
- }
+ {
+ GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2);
+ GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1);
+ GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3);
+ }
GNUNET_free (buf);
}
start = GNUNET_TIME_absolute_get ();
perfHash ();
printf ("Hash perf took %llu ms\n",
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value);
GAUGER ("UTIL", "Cryptographic hashing",
- 1024 * 64 * 1024 / (1 +
- GNUNET_TIME_absolute_get_duration
- (start).rel_value), "kb/s");
+ 1024 * 64 * 1024 / (1 +
+ GNUNET_TIME_absolute_get_duration
+ (start).rel_value), "kb/s");
return 0;
}
err = lt_dlinit ();
if (err > 0)
- {
- fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"),
- lt_dlerror ());
- return;
- }
+ {
+ fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"),
+ lt_dlerror ());
+ return;
+ }
opath = lt_dlgetsearchpath ();
if (opath != NULL)
old_dlsearchpath = GNUNET_strdup (opath);
path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
if (path != NULL)
+ {
+ if (opath != NULL)
{
- if (opath != NULL)
- {
- GNUNET_asprintf (&cpath, "%s:%s", opath, path);
- lt_dlsetsearchpath (cpath);
- GNUNET_free (path);
- GNUNET_free (cpath);
- }
- else
- {
- lt_dlsetsearchpath (path);
- GNUNET_free (path);
- }
+ GNUNET_asprintf (&cpath, "%s:%s", opath, path);
+ lt_dlsetsearchpath (cpath);
+ GNUNET_free (path);
+ GNUNET_free (cpath);
}
+ else
+ {
+ lt_dlsetsearchpath (path);
+ GNUNET_free (path);
+ }
+ }
}
{
lt_dlsetsearchpath (old_dlsearchpath);
if (old_dlsearchpath != NULL)
- {
- GNUNET_free (old_dlsearchpath);
- old_dlsearchpath = NULL;
- }
+ {
+ GNUNET_free (old_dlsearchpath);
+ old_dlsearchpath = NULL;
+ }
lt_dlexit ();
}
mptr = lt_dlsym (plug->handle, initName);
if (mptr == NULL)
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed to resolve method '%s' with error: %s\n"),
- "lt_dlsym", &initName[1], lt_dlerror ());
+ _("`%s' failed to resolve method '%s' with error: %s\n"), "lt_dlsym",
+ &initName[1], lt_dlerror ());
GNUNET_free (initName);
return mptr;
}
struct PluginList plug;
if (!initialized)
- {
- initialized = GNUNET_YES;
- plugin_init ();
- }
+ {
+ initialized = GNUNET_YES;
+ plugin_init ();
+ }
libhandle = lt_dlopenext (library_name);
if (libhandle == NULL)
return GNUNET_NO;
plug.name = (char *) library_name;
init = resolve_function (&plug, "init");
if (init == NULL)
- {
- GNUNET_break (0);
- lt_dlclose (libhandle);
- return GNUNET_NO;
- }
+ {
+ GNUNET_break (0);
+ lt_dlclose (libhandle);
+ return GNUNET_NO;
+ }
lt_dlclose (libhandle);
return GNUNET_YES;
}
void *ret;
if (!initialized)
- {
- initialized = GNUNET_YES;
- plugin_init ();
- }
+ {
+ initialized = GNUNET_YES;
+ plugin_init ();
+ }
libhandle = lt_dlopenext (library_name);
if (libhandle == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed for library `%s' with error: %s\n"),
- "lt_dlopenext", library_name, lt_dlerror ());
- return NULL;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' failed for library `%s' with error: %s\n"), "lt_dlopenext",
+ library_name, lt_dlerror ());
+ return NULL;
+ }
plug = GNUNET_malloc (sizeof (struct PluginList));
plug->handle = libhandle;
plug->name = GNUNET_strdup (library_name);
plugins = plug;
init = resolve_function (plug, "init");
if ((init == NULL) || (NULL == (ret = init (arg))))
- {
- lt_dlclose (libhandle);
- GNUNET_free (plug->name);
- plugins = plug->next;
- GNUNET_free (plug);
- return NULL;
- }
+ {
+ lt_dlclose (libhandle);
+ GNUNET_free (plug->name);
+ plugins = plug->next;
+ GNUNET_free (plug);
+ return NULL;
+ }
return ret;
}
prev = NULL;
pos = plugins;
while ((pos != NULL) && (0 != strcmp (pos->name, library_name)))
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
return NULL;
GNUNET_free (pos->name);
GNUNET_free (pos);
if (plugins == NULL)
- {
- plugin_fini ();
- initialized = GNUNET_NO;
- }
+ {
+ plugin_fini ();
+ initialized = GNUNET_NO;
+ }
return ret;
}
static int
-find_libraries (void *cls,
- const char *filename)
+find_libraries (void *cls, const char *filename)
{
struct LoadAllContext *lac = cls;
const char *slashpos;
while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR)))
libname = slashpos + 1;
n = strlen (libname);
- if (0 != strncmp (lac->basename,
- libname,
- strlen (lac->basename)))
- return GNUNET_OK; /* wrong name */
- if ( (n > 3) &&
- (0 == strcmp (&libname[n-3],
- ".la")) )
- return GNUNET_OK; /* .la file */
+ if (0 != strncmp (lac->basename, libname, strlen (lac->basename)))
+ return GNUNET_OK; /* wrong name */
+ if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la")))
+ return GNUNET_OK; /* .la file */
basename = GNUNET_strdup (libname);
if (NULL != (dot = strstr (basename, ".")))
*dot = '\0';
* @param cb function to call for each plugin found
* @param cb_cls closure for 'cb'
*/
-void
-GNUNET_PLUGIN_load_all (const char *basename,
- void *arg,
- GNUNET_PLUGIN_LoaderCallback cb,
- void *cb_cls)
+void
+GNUNET_PLUGIN_load_all (const char *basename, void *arg,
+ GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
{
struct LoadAllContext lac;
char *path;
if (path == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not determine plugin installation path.\n"));
+ _("Could not determine plugin installation path.\n"));
return;
}
lac.basename = basename;
lac.arg = arg;
lac.cb = cb;
lac.cb_cls = cb_cls;
- GNUNET_DISK_directory_scan (path,
- &find_libraries,
- &lac);
+ GNUNET_DISK_directory_scan (path, &find_libraries, &lac);
GNUNET_free (path);
}
*/
int
GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
- const char *binaryHelp,
- const struct GNUNET_GETOPT_CommandLineOption *options,
- GNUNET_PROGRAM_Main task, void *task_cls)
+ const char *binaryHelp,
+ const struct GNUNET_GETOPT_CommandLineOption *options,
+ GNUNET_PROGRAM_Main task, void *task_cls)
{
struct CommandContext cc;
char *path;
logfile = NULL;
gargs = getenv ("GNUNET_ARGS");
if (gargs != NULL)
- {
- char **gargv;
- unsigned int gargc;
- int i;
- char *tok;
- char *cargs;
+ {
+ char **gargv;
+ unsigned int gargc;
+ int i;
+ char *tok;
+ char *cargs;
- gargv = NULL;
- gargc = 0;
- for (i = 0; i < argc; i++)
- GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i]));
- cargs = GNUNET_strdup (gargs);
- tok = strtok (cargs, " ");
- while (NULL != tok)
- {
- GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok));
- tok = strtok (NULL, " ");
- }
- GNUNET_free (cargs);
- GNUNET_array_append (gargv, gargc, NULL);
- argv = (char *const *) gargv;
- argc = gargc - 1;
+ gargv = NULL;
+ gargc = 0;
+ for (i = 0; i < argc; i++)
+ GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i]));
+ cargs = GNUNET_strdup (gargs);
+ tok = strtok (cargs, " ");
+ while (NULL != tok)
+ {
+ GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok));
+ tok = strtok (NULL, " ");
}
+ GNUNET_free (cargs);
+ GNUNET_array_append (gargv, gargc, NULL);
+ argv = (char *const *) gargv;
+ argc = gargc - 1;
+ }
memset (&cc, 0, sizeof (cc));
loglev = NULL;
cc.task = task;
setlocale (LC_ALL, "");
path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
if (path != NULL)
- {
- BINDTEXTDOMAIN ("GNUnet", path);
- GNUNET_free (path);
- }
+ {
+ BINDTEXTDOMAIN ("GNUnet", path);
+ GNUNET_free (path);
+ }
textdomain ("GNUnet");
#endif
cnt = 0;
while (options[cnt].name != NULL)
cnt++;
allopts =
- GNUNET_malloc ((cnt +
- 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) +
- sizeof (defoptions));
+ GNUNET_malloc ((cnt +
+ 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) +
+ sizeof (defoptions));
memcpy (allopts, defoptions, sizeof (defoptions));
memcpy (&allopts
- [sizeof (defoptions) /
- sizeof (struct GNUNET_GETOPT_CommandLineOption)], options,
- (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption));
- cnt +=
- sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption);
+ [sizeof (defoptions) /
+ sizeof (struct GNUNET_GETOPT_CommandLineOption)], options,
+ (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption));
+ cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption);
qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption),
- &cmd_sorter);
+ &cmd_sorter);
loglev = NULL;
cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE);
lpfx = GNUNET_strdup (binaryName);
*spc = '\0';
if ((-1 ==
(ret =
- GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv)))
- || (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)))
- {
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free_non_null (cc.cfgfile);
- GNUNET_free_non_null (loglev);
- GNUNET_free_non_null (logfile);
- GNUNET_free (allopts);
- GNUNET_free (lpfx);
- return GNUNET_SYSERR;
- }
+ GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) ||
+ (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)))
+ {
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free_non_null (cc.cfgfile);
+ GNUNET_free_non_null (loglev);
+ GNUNET_free_non_null (logfile);
+ GNUNET_free (allopts);
+ GNUNET_free (lpfx);
+ return GNUNET_SYSERR;
+ }
(void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile);
GNUNET_free (allopts);
GNUNET_free (lpfx);
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset",
- &skew_offset) &&
+ &skew_offset) &&
(GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing",
- "skew_variance",
- &skew_variance)))
- {
- clock_offset = skew_offset - skew_variance;
- GNUNET_TIME_set_offset (clock_offset);
- }
+ "skew_variance", &skew_variance)))
+ {
+ clock_offset = skew_offset - skew_variance;
+ GNUNET_TIME_set_offset (clock_offset);
+ }
/* run */
cc.args = &argv[ret];
GNUNET_SCHEDULER_run (&program_main, &cc);
*/
static void
internal_notify (const GNUNET_HashCode * id,
- const struct GNUNET_CONTAINER_MetaData *md, int rating)
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
struct DiscoveryCallback *pos;
pos = head;
while (pos != NULL)
- {
- pos->callback (pos->closure, id, md, rating);
- pos = pos->next;
- }
+ {
+ pos->callback (pos->closure, id, md, rating);
+ pos = pos->next;
+ }
}
/**
*/
int
GNUNET_PSEUDONYM_discovery_callback_register (const struct
- GNUNET_CONFIGURATION_Handle
- *cfg,
- GNUNET_PSEUDONYM_Iterator
- iterator, void *closure)
+ GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_PSEUDONYM_Iterator
+ iterator, void *closure)
{
struct DiscoveryCallback *list;
*/
int
GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
- iterator, void *closure)
+ iterator, void *closure)
{
struct DiscoveryCallback *prev;
struct DiscoveryCallback *pos;
prev = NULL;
pos = head;
while ((pos != NULL) &&
- ((pos->callback != iterator) || (pos->closure != closure)))
- {
- prev = pos;
- pos = pos->next;
- }
+ ((pos->callback != iterator) || (pos->closure != closure)))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
return GNUNET_SYSERR;
if (prev == NULL)
*/
static char *
get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *prefix, const GNUNET_HashCode * psid)
+ const char *prefix, const GNUNET_HashCode * psid)
{
struct GNUNET_CRYPTO_HashAsciiEncoded enc;
if (psid != NULL)
GNUNET_CRYPTO_hash_to_enc (psid, &enc);
- return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME,
- prefix,
- (psid ==
- NULL) ? NULL : (const char *) &enc,
- NULL);
+ return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, prefix,
+ (psid ==
+ NULL) ? NULL : (const char *) &enc,
+ NULL);
}
*/
static void
write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const GNUNET_HashCode * nsid,
- const struct GNUNET_CONTAINER_MetaData *meta,
- int32_t ranking, const char *ns_name)
+ const GNUNET_HashCode * nsid,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ int32_t ranking, const char *ns_name)
{
char *fn;
struct GNUNET_BIO_WriteHandle *fileW;
GNUNET_assert (fn != NULL);
fileW = GNUNET_BIO_write_open (fn);
if (NULL != fileW)
+ {
+ if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) ||
+ (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) ||
+ (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta)))
{
- if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) ||
- (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) ||
- (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta)))
- {
- (void) GNUNET_BIO_write_close (fileW);
- GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
- GNUNET_free (fn);
- return;
- }
- if (GNUNET_OK != GNUNET_BIO_write_close (fileW))
- {
- GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
- GNUNET_free (fn);
- return;
- }
+ (void) GNUNET_BIO_write_close (fileW);
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_free (fn);
+ return;
}
+ if (GNUNET_OK != GNUNET_BIO_write_close (fileW))
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_free (fn);
+ return;
+ }
+ }
GNUNET_free (fn);
/* create entry for pseudonym name in names */
/* FIXME: 90% of what this call does is not needed
*/
static int
read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const GNUNET_HashCode * nsid,
- struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking,
- char **ns_name)
+ const GNUNET_HashCode * nsid,
+ struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking,
+ char **ns_name)
{
char *fn;
char *emsg;
GNUNET_assert (fn != NULL);
fileR = GNUNET_BIO_read_open (fn);
if (fileR == NULL)
- {
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
emsg = NULL;
*ns_name = NULL;
if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) ||
GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) ||
(GNUNET_OK !=
GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta)))
- {
- (void) GNUNET_BIO_read_close (fileR, &emsg);
- GNUNET_free_non_null (emsg);
- GNUNET_free_non_null (*ns_name);
- *ns_name = NULL;
- GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ (void) GNUNET_BIO_read_close (fileR, &emsg);
+ GNUNET_free_non_null (emsg);
+ GNUNET_free_non_null (*ns_name);
+ *ns_name = NULL;
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Failed to parse metadata about pseudonym from file `%s': %s\n"),
- fn, emsg);
- GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
- GNUNET_CONTAINER_meta_data_destroy (*meta);
- *meta = NULL;
- GNUNET_free_non_null (*ns_name);
- *ns_name = NULL;
- GNUNET_free_non_null (emsg);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fn,
+ emsg);
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_CONTAINER_meta_data_destroy (*meta);
+ *meta = NULL;
+ GNUNET_free_non_null (*ns_name);
+ *ns_name = NULL;
+ GNUNET_free_non_null (emsg);
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (fn);
return GNUNET_OK;
}
*/
char *
GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const GNUNET_HashCode * nsid)
+ const GNUNET_HashCode * nsid)
{
struct GNUNET_CONTAINER_MetaData *meta;
char *name;
meta = NULL;
name = NULL;
if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name))
+ {
+ if ((meta != NULL) && (name == NULL))
+ name =
+ GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
+ EXTRACTOR_METATYPE_TITLE,
+ EXTRACTOR_METATYPE_FILENAME,
+ EXTRACTOR_METATYPE_DESCRIPTION,
+ EXTRACTOR_METATYPE_SUBJECT,
+ EXTRACTOR_METATYPE_PUBLISHER,
+ EXTRACTOR_METATYPE_AUTHOR_NAME,
+ EXTRACTOR_METATYPE_COMMENT,
+ EXTRACTOR_METATYPE_SUMMARY,
+ -1);
+ if (meta != NULL)
{
- if ((meta != NULL) && (name == NULL))
- name =
- GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METATYPE_FILENAME,
- EXTRACTOR_METATYPE_DESCRIPTION,
- EXTRACTOR_METATYPE_SUBJECT,
- EXTRACTOR_METATYPE_PUBLISHER,
- EXTRACTOR_METATYPE_AUTHOR_NAME,
- EXTRACTOR_METATYPE_COMMENT,
- EXTRACTOR_METATYPE_SUMMARY,
- -1);
- if (meta != NULL)
- {
- GNUNET_CONTAINER_meta_data_destroy (meta);
- meta = NULL;
- }
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ meta = NULL;
}
+ }
if (name == NULL)
name = GNUNET_strdup (_("no-name"));
GNUNET_CRYPTO_hash (name, strlen (name), &nh);
if (0 == STAT (fn, &sbuf))
GNUNET_DISK_file_size (fn, &len, GNUNET_YES);
fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_READWRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_READWRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
i = 0;
idx = -1;
while ((len >= sizeof (GNUNET_HashCode)) &&
- (sizeof (GNUNET_HashCode) ==
- GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode))))
- {
- if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode)))
- {
- idx = i;
- break;
- }
- i++;
- len -= sizeof (GNUNET_HashCode);
- }
- if (idx == -1)
+ (sizeof (GNUNET_HashCode) ==
+ GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode))))
+ {
+ if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode)))
{
idx = i;
- if (sizeof (GNUNET_HashCode) !=
- GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn);
+ break;
}
+ i++;
+ len -= sizeof (GNUNET_HashCode);
+ }
+ if (idx == -1)
+ {
+ idx = i;
+ if (sizeof (GNUNET_HashCode) !=
+ GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn);
+ }
GNUNET_DISK_file_close (fh);
ret = GNUNET_malloc (strlen (name) + 32);
GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx);
*/
int
GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *ns_uname, GNUNET_HashCode * nsid)
+ const char *ns_uname, GNUNET_HashCode * nsid)
{
size_t slen;
uint64_t len;
if ((GNUNET_OK != GNUNET_DISK_file_test (fn) ||
(GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES))) ||
((idx + 1) * sizeof (GNUNET_HashCode) > len))
- {
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_READWRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_READWRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
GNUNET_free (fn);
GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode),
- GNUNET_DISK_SEEK_SET);
+ GNUNET_DISK_SEEK_SET);
if (sizeof (GNUNET_HashCode) !=
GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode)))
- {
- GNUNET_DISK_file_close (fh);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_DISK_file_close (fh);
+ return GNUNET_SYSERR;
+ }
GNUNET_DISK_file_close (fh);
return GNUNET_OK;
}
if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))
return GNUNET_OK;
fn = &fullname[strlen (fullname) + 1 -
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
if (fn[-1] != DIR_SEPARATOR)
return GNUNET_OK;
ret = GNUNET_OK;
if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (fn, &id))
- return GNUNET_OK; /* invalid name */
+ return GNUNET_OK; /* invalid name */
str = NULL;
if (GNUNET_OK != read_info (c->cfg, &id, &meta, &rating, &str))
- return GNUNET_OK; /* ignore entry */
+ return GNUNET_OK; /* ignore entry */
GNUNET_free_non_null (str);
if (c->iterator != NULL)
ret = c->iterator (c->closure, &id, meta, rating);
*/
int
GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_PSEUDONYM_Iterator iterator, void *closure)
+ GNUNET_PSEUDONYM_Iterator iterator, void *closure)
{
struct ListPseudonymClosure cls;
char *fn;
*/
int
GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const GNUNET_HashCode * nsid, int delta)
+ const GNUNET_HashCode * nsid, int delta)
{
struct GNUNET_CONTAINER_MetaData *meta;
int ret;
name = NULL;
ret = read_info (cfg, nsid, &meta, &ranking, &name);
if (ret == GNUNET_SYSERR)
- {
- ranking = 0;
- meta = GNUNET_CONTAINER_meta_data_create ();
- }
+ {
+ ranking = 0;
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ }
ranking += delta;
write_pseudonym_info (cfg, nsid, meta, ranking, name);
GNUNET_CONTAINER_meta_data_destroy (meta);
*/
void
GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const GNUNET_HashCode * id,
- const struct GNUNET_CONTAINER_MetaData *meta)
+ const GNUNET_HashCode * id,
+ const struct GNUNET_CONTAINER_MetaData *meta)
{
char *name;
int32_t ranking;
if ((0 == STAT (fn, &sbuf)) &&
(GNUNET_OK == read_info (cfg, id, &old, &ranking, &name)))
- {
- GNUNET_CONTAINER_meta_data_merge (old, meta);
- write_pseudonym_info (cfg, id, old, ranking, name);
- GNUNET_CONTAINER_meta_data_destroy (old);
- GNUNET_free_non_null (name);
- }
+ {
+ GNUNET_CONTAINER_meta_data_merge (old, meta);
+ write_pseudonym_info (cfg, id, old, ranking, name);
+ GNUNET_CONTAINER_meta_data_destroy (old);
+ GNUNET_free_non_null (name);
+ }
else
- {
- write_pseudonym_info (cfg, id, meta, ranking, NULL);
- }
+ {
+ write_pseudonym_info (cfg, id, meta, ranking, NULL);
+ }
GNUNET_free (fn);
internal_notify (id, meta, ranking);
}
#endif
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (resolver_cfg, "resolver",
- "HOSTNAME", &hostname))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME",
- "resolver");
- GNUNET_assert (0);
- }
+ "HOSTNAME", &hostname))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME",
+ "resolver");
+ GNUNET_assert (0);
+ }
if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
(1 != inet_pton (AF_INET6, hostname, &v6)))
+ {
+ GNUNET_free (hostname);
+ return;
+ }
+ i = 0;
+ while (loopback[i] != NULL)
+ if (0 == strcasecmp (loopback[i++], hostname))
{
GNUNET_free (hostname);
return;
}
- i = 0;
- while (loopback[i] != NULL)
- if (0 == strcasecmp (loopback[i++], hostname))
- {
- GNUNET_free (hostname);
- return;
- }
LOG (GNUNET_ERROR_TYPE_ERROR,
_
("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
GNUNET_assert (NULL == req_head);
GNUNET_assert (NULL == req_tail);
if (NULL != client)
- {
+ {
#if DEBUG_RESOLVER
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n");
#endif
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
- client = NULL;
- }
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ client = NULL;
+ }
if (r_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (r_task);
- r_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (r_task);
+ r_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (s_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (s_task);
- s_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (s_task);
+ s_task = GNUNET_SCHEDULER_NO_TASK;
+ }
}
if (salen < sizeof (struct sockaddr))
return NULL;
switch (sa->sa_family)
+ {
+ case AF_INET:
+ if (salen != sizeof (struct sockaddr_in))
+ return NULL;
+ if (NULL ==
+ inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
+ INET_ADDRSTRLEN))
{
- case AF_INET:
- if (salen != sizeof (struct sockaddr_in))
- return NULL;
- if (NULL ==
- inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
- INET_ADDRSTRLEN))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
- return NULL;
- }
- ret = GNUNET_strdup (inet4);
- break;
- case AF_INET6:
- if (salen != sizeof (struct sockaddr_in6))
- return NULL;
- if (NULL ==
- inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr,
- inet6, INET6_ADDRSTRLEN))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
- return NULL;
- }
- ret = GNUNET_strdup (inet6);
- break;
- default:
- ret = NULL;
- break;
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+ return NULL;
}
+ ret = GNUNET_strdup (inet4);
+ break;
+ case AF_INET6:
+ if (salen != sizeof (struct sockaddr_in6))
+ return NULL;
+ if (NULL ==
+ inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, inet6,
+ INET6_ADDRSTRLEN))
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+ return NULL;
+ }
+ ret = GNUNET_strdup (inet6);
+ break;
+ default:
+ ret = NULL;
+ break;
+ }
return ret;
}
/**
* Adjust exponential back-off and reconnect to the service.
*/
-static void reconnect ();
+static void
+reconnect ();
/**
* Process pending requests to the resolver.
*/
-static void process_requests ();
+static void
+process_requests ();
/**
LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n");
#endif
if (msg == NULL)
+ {
+ if (NULL != rh->name_callback)
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Timeout trying to resolve IP address `%s'.\n"),
+ GNUNET_a2s ((const void *) &rh[1], rh->data_len));
+ else
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Timeout trying to resolve hostname `%s'.\n"),
+ (const char *) &rh[1]);
+ /* check if request was canceled */
+ if (rh->was_transmitted != GNUNET_SYSERR)
{
if (NULL != rh->name_callback)
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Timeout trying to resolve IP address `%s'.\n"),
- GNUNET_a2s ((const void *) &rh[1], rh->data_len));
- else
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Timeout trying to resolve hostname `%s'.\n"),
- (const char *) &rh[1]);
- /* check if request was canceled */
- if (rh->was_transmitted != GNUNET_SYSERR)
- {
- if (NULL != rh->name_callback)
- {
- /* no reverse lookup was successful, return ip as string */
- if (rh->received_response == GNUNET_NO)
- rh->name_callback (rh->cls,
- no_resolve ((const struct sockaddr *)
- &rh[1], rh->data_len));
- /* at least one reverse lookup was successful */
- else
- rh->name_callback (rh->cls, NULL);
- }
- if (NULL != rh->addr_callback)
- rh->addr_callback (rh->cls, NULL, 0);
- }
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
- GNUNET_free (rh);
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
- client = NULL;
- reconnect ();
- return;
+ {
+ /* no reverse lookup was successful, return ip as string */
+ if (rh->received_response == GNUNET_NO)
+ rh->name_callback (rh->cls,
+ no_resolve ((const struct sockaddr *) &rh[1],
+ rh->data_len));
+ /* at least one reverse lookup was successful */
+ else
+ rh->name_callback (rh->cls, NULL);
+ }
+ if (NULL != rh->addr_callback)
+ rh->addr_callback (rh->cls, NULL, 0);
}
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_free (rh);
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ client = NULL;
+ reconnect ();
+ return;
+ }
if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type))
- {
- GNUNET_break (0);
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
- client = NULL;
- reconnect ();
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ client = NULL;
+ reconnect ();
+ return;
+ }
size = ntohs (msg->size);
/* message contains not data, just header */
if (size == sizeof (struct GNUNET_MessageHeader))
+ {
+ /* check if request was canceled */
+ if (rh->was_transmitted != GNUNET_SYSERR)
+ {
+ if (NULL != rh->name_callback)
+ rh->name_callback (rh->cls, NULL);
+ if (NULL != rh->addr_callback)
+ rh->addr_callback (rh->cls, NULL, 0);
+ }
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_free (rh);
+ process_requests ();
+ return;
+ }
+ /* return reverse lookup results to caller */
+ if (NULL != rh->name_callback)
+ {
+ hostname = (const char *) &msg[1];
+ if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
{
- /* check if request was canceled */
+ GNUNET_break (0);
if (rh->was_transmitted != GNUNET_SYSERR)
- {
- if (NULL != rh->name_callback)
- rh->name_callback (rh->cls, NULL);
- if (NULL != rh->addr_callback)
- rh->addr_callback (rh->cls, NULL, 0);
- }
+ rh->name_callback (rh->cls, NULL);
GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
GNUNET_free (rh);
- process_requests ();
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ client = NULL;
+ reconnect ();
return;
}
- /* return reverse lookup results to caller */
- if (NULL != rh->name_callback)
- {
- hostname = (const char *) &msg[1];
- if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
- {
- GNUNET_break (0);
- if (rh->was_transmitted != GNUNET_SYSERR)
- rh->name_callback (rh->cls, NULL);
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
- GNUNET_free (rh);
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
- client = NULL;
- reconnect ();
- return;
- }
#if DEBUG_RESOLVER
- LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s' for IP `%s'.\n"),
- hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s' for IP `%s'.\n"),
+ hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len));
#endif
- if (rh->was_transmitted != GNUNET_SYSERR)
- rh->name_callback (rh->cls, hostname);
- rh->received_response = GNUNET_YES;
- GNUNET_CLIENT_receive (client, &handle_response, rh,
- GNUNET_TIME_absolute_get_remaining
- (rh->timeout));
- }
+ if (rh->was_transmitted != GNUNET_SYSERR)
+ rh->name_callback (rh->cls, hostname);
+ rh->received_response = GNUNET_YES;
+ GNUNET_CLIENT_receive (client, &handle_response, rh,
+ GNUNET_TIME_absolute_get_remaining (rh->timeout));
+ }
/* return lookup results to caller */
if (NULL != rh->addr_callback)
+ {
+ sa = (const struct sockaddr *) &msg[1];
+ salen = size - sizeof (struct GNUNET_MessageHeader);
+ if (salen < sizeof (struct sockaddr))
{
- sa = (const struct sockaddr *) &msg[1];
- salen = size - sizeof (struct GNUNET_MessageHeader);
- if (salen < sizeof (struct sockaddr))
- {
- GNUNET_break (0);
- if (rh->was_transmitted != GNUNET_SYSERR)
- rh->addr_callback (rh->cls, NULL, 0);
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
- GNUNET_free (rh);
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
- client = NULL;
- reconnect ();
- return;
- }
+ GNUNET_break (0);
+ if (rh->was_transmitted != GNUNET_SYSERR)
+ rh->addr_callback (rh->cls, NULL, 0);
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_free (rh);
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ client = NULL;
+ reconnect ();
+ return;
+ }
#if DEBUG_RESOLVER
- {
- char *ips = no_resolve (sa, salen);
+ {
+ char *ips = no_resolve (sa, salen);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n",
- ips, (const char *) &rh[1]);
- GNUNET_free (ips);
- }
-#endif
- rh->addr_callback (rh->cls, sa, salen);
- GNUNET_CLIENT_receive (client, &handle_response, rh,
- GNUNET_TIME_absolute_get_remaining
- (rh->timeout));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n", ips,
+ (const char *) &rh[1]);
+ GNUNET_free (ips);
}
+#endif
+ rh->addr_callback (rh->cls, sa, salen);
+ GNUNET_CLIENT_receive (client, &handle_response, rh,
+ GNUNET_TIME_absolute_get_remaining (rh->timeout));
+ }
}
hostname = (const char *) &rh[1];
if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) &&
(1 == inet_pton (AF_INET, hostname, &v4.sin_addr)))
+ {
+ rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
+ if ((rh->domain == AF_UNSPEC) &&
+ (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
{
- rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
- if ((rh->domain == AF_UNSPEC) &&
- (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
- {
- /* this can happen on some systems IF "hostname" is "localhost" */
- rh->addr_callback (rh->cls, (const struct sockaddr *) &v6,
- sizeof (v6));
- }
- rh->addr_callback (rh->cls, NULL, 0);
- GNUNET_free (rh);
- return;
+ /* this can happen on some systems IF "hostname" is "localhost" */
+ rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
}
+ rh->addr_callback (rh->cls, NULL, 0);
+ GNUNET_free (rh);
+ return;
+ }
if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) &&
(1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
- {
- rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
- rh->addr_callback (rh->cls, NULL, 0);
- GNUNET_free (rh);
- return;
- }
+ {
+ rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
+ rh->addr_callback (rh->cls, NULL, 0);
+ GNUNET_free (rh);
+ return;
+ }
/* why are we here? this task should not have been scheduled! */
GNUNET_assert (0);
GNUNET_free (rh);
#endif
v6.sin6_addr = in6addr_loopback;
switch (rh->domain)
- {
- case AF_INET:
- rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
- break;
- case AF_INET6:
- rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
- break;
- case AF_UNSPEC:
- rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
- rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
- break;
- default:
- GNUNET_break (0);
- break;
- }
+ {
+ case AF_INET:
+ rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
+ break;
+ case AF_INET6:
+ rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
+ break;
+ case AF_UNSPEC:
+ rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
+ rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
rh->addr_callback (rh->cls, NULL, 0);
GNUNET_free (rh);
}
struct GNUNET_RESOLVER_RequestHandle *rh;
if (NULL == client)
- {
- reconnect ();
- return;
- }
+ {
+ reconnect ();
+ return;
+ }
rh = req_head;
if (NULL == rh)
- {
- /* nothing to do, release socket really soon if there is nothing
- * else happening... */
- s_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &shutdown_task, NULL);
- return;
- }
+ {
+ /* nothing to do, release socket really soon if there is nothing
+ * else happening... */
+ s_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &shutdown_task, NULL);
+ return;
+ }
if (GNUNET_YES == rh->was_transmitted)
- return; /* waiting for reply */
+ return; /* waiting for reply */
msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
msg->header.size =
- htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
+ htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
msg->direction = htonl (rh->direction);
msg->domain = htonl (rh->domain);
#endif
if (GNUNET_OK !=
GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
- GNUNET_TIME_absolute_get_remaining
- (rh->timeout), GNUNET_YES,
- &handle_response, rh))
- {
- GNUNET_CLIENT_disconnect (client, GNUNET_NO);
- client = NULL;
- reconnect ();
- return;
- }
+ GNUNET_TIME_absolute_get_remaining
+ (rh->timeout), GNUNET_YES,
+ &handle_response, rh))
+ {
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
+ client = NULL;
+ reconnect ();
+ return;
+ }
rh->was_transmitted = GNUNET_YES;
}
{
r_task = GNUNET_SCHEDULER_NO_TASK;
if (NULL == req_head)
- return; /* no work pending */
+ return; /* no work pending */
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
#if DEBUG_RESOLVER
#endif
client = GNUNET_CLIENT_connect ("resolver", resolver_cfg);
if (NULL == client)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect, will try again later\n");
- reconnect ();
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect, will try again later\n");
+ reconnect ();
+ return;
+ }
process_requests ();
}
return;
GNUNET_assert (NULL == client);
if (NULL != (rh = req_head))
+ {
+ switch (rh->was_transmitted)
{
- switch (rh->was_transmitted)
- {
- case GNUNET_NO:
- /* nothing more to do */
- break;
- case GNUNET_YES:
- /* disconnected, transmit again! */
- rh->was_transmitted = GNUNET_NO;
- break;
- case GNUNET_SYSERR:
- /* request was cancelled, remove entirely */
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
- GNUNET_free (rh);
- break;
- default:
- GNUNET_assert (0);
- break;
- }
+ case GNUNET_NO:
+ /* nothing more to do */
+ break;
+ case GNUNET_YES:
+ /* disconnected, transmit again! */
+ rh->was_transmitted = GNUNET_NO;
+ break;
+ case GNUNET_SYSERR:
+ /* request was cancelled, remove entirely */
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_free (rh);
+ break;
+ default:
+ GNUNET_assert (0);
+ break;
}
+ }
#if DEBUG_RESOLVER
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Will try to connect to DNS service in %llu ms\n",
*/
struct GNUNET_RESOLVER_RequestHandle *
GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_RESOLVER_AddressCallback callback,
- void *callback_cls)
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_RESOLVER_AddressCallback callback,
+ void *callback_cls)
{
struct GNUNET_RESOLVER_RequestHandle *rh;
size_t slen;
slen = strlen (hostname) + 1;
if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
rh->domain = domain;
rh->addr_callback = callback;
((domain == AF_INET) || (domain == AF_UNSPEC))) ||
((1 == inet_pton (AF_INET6, hostname, &v6)) &&
((domain == AF_INET6) || (domain == AF_UNSPEC))))
- {
- rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
- return rh;
- }
+ {
+ rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
+ return rh;
+ }
/* then, check if this is a loopback address */
i = 0;
while (loopback[i] != NULL)
if (0 == strcasecmp (loopback[i++], hostname))
- {
- rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh);
- return rh;
- }
+ {
+ rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh);
+ return rh;
+ }
GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
rh->was_queued = GNUNET_YES;
if (s_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (s_task);
- s_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (s_task);
+ s_task = GNUNET_SCHEDULER_NO_TASK;
+ }
process_requests ();
return rh;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result);
#endif
if (result != NULL)
- {
- rh->name_callback (rh->cls, result);
- GNUNET_free (result);
- }
+ {
+ rh->name_callback (rh->cls, result);
+ GNUNET_free (result);
+ }
rh->name_callback (rh->cls, NULL);
GNUNET_free (rh);
}
*/
struct GNUNET_RESOLVER_RequestHandle *
GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen,
- int do_resolve,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_RESOLVER_HostnameCallback callback,
- void *cls)
+ int do_resolve,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_RESOLVER_HostnameCallback callback,
+ void *cls)
{
struct GNUNET_RESOLVER_RequestHandle *rh;
rh->direction = GNUNET_YES;
rh->received_response = GNUNET_NO;
if (GNUNET_NO == do_resolve)
- {
- rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh);
- return rh;
- }
+ {
+ rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh);
+ return rh;
+ }
if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- GNUNET_free (rh);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_free (rh);
+ return NULL;
+ }
GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
rh->was_queued = GNUNET_YES;
if (s_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (s_task);
- s_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (s_task);
+ s_task = GNUNET_SCHEDULER_NO_TASK;
+ }
process_requests ();
return rh;
}
char hostname[GNUNET_OS_get_hostname_max_length () + 1];
if (0 != gethostname (hostname, sizeof (hostname) - 1))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "gethostname");
- return NULL;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "gethostname");
+ return NULL;
+ }
#if DEBUG_RESOLVER
LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), hostname);
#endif
host = gethostbyname (hostname);
if (NULL == host)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"),
- hstrerror (h_errno));
- return NULL;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"),
+ hstrerror (h_errno));
+ return NULL;
+ }
return GNUNET_strdup (host->h_name);
}
*/
struct GNUNET_RESOLVER_RequestHandle *
GNUNET_RESOLVER_hostname_resolve (int domain,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_RESOLVER_AddressCallback callback,
- void *cls)
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_RESOLVER_AddressCallback callback,
+ void *cls)
{
char hostname[GNUNET_OS_get_hostname_max_length () + 1];
if (0 != gethostname (hostname, sizeof (hostname) - 1))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "gethostname");
- return NULL;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "gethostname");
+ return NULL;
+ }
#if DEBUG_RESOLVER
LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"), hostname);
#endif
GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
{
if (rh->task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (rh->task);
- rh->task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (rh->task);
+ rh->task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (rh->was_transmitted == GNUNET_NO)
- {
- if (rh->was_queued == GNUNET_YES)
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
- GNUNET_free (rh);
- return;
- }
+ {
+ if (rh->was_queued == GNUNET_YES)
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_free (rh);
+ return;
+ }
GNUNET_assert (rh->was_transmitted == GNUNET_YES);
- rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
+ rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
}
*/
void
GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select,
- void *new_select_cls)
+ void *new_select_cls)
{
scheduler_select = new_select;
scheduler_select_cls = new_select_cls;
if ((p >= 0) && (p < GNUNET_SCHEDULER_PRIORITY_COUNT))
return p;
GNUNET_assert (0);
- return 0; /* make compiler happy */
+ return 0; /* make compiler happy */
}
if (id < lowest_pending_id)
return GNUNET_NO;
- min = -1; /* maximum value */
+ min = -1; /* maximum value */
pos = pending;
while (pos != NULL)
- {
- if (pos->id == id)
- return GNUNET_YES;
- if (pos->id < min)
- min = pos->id;
- pos = pos->next;
- }
+ {
+ if (pos->id == id)
+ return GNUNET_YES;
+ if (pos->id < min)
+ min = pos->id;
+ pos = pos->next;
+ }
pos = pending_timeout;
while (pos != NULL)
+ {
+ if (pos->id == id)
+ return GNUNET_YES;
+ if (pos->id < min)
+ min = pos->id;
+ pos = pos->next;
+ }
+ for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++)
+ {
+ pos = ready[p];
+ while (pos != NULL)
{
if (pos->id == id)
- return GNUNET_YES;
+ return GNUNET_YES;
if (pos->id < min)
- min = pos->id;
+ min = pos->id;
pos = pos->next;
}
- for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++)
- {
- pos = ready[p];
- while (pos != NULL)
- {
- if (pos->id == id)
- return GNUNET_YES;
- if (pos->id < min)
- min = pos->id;
- pos = pos->next;
- }
- }
+ }
lowest_pending_id = min;
return GNUNET_NO;
}
*/
static void
update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws,
- struct GNUNET_TIME_Relative *timeout)
+ struct GNUNET_TIME_Relative *timeout)
{
struct Task *pos;
struct GNUNET_TIME_Absolute now;
now = GNUNET_TIME_absolute_get ();
pos = pending_timeout;
if (pos != NULL)
- {
- to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
- if (timeout->rel_value > to.rel_value)
- *timeout = to;
- if (pos->reason != 0)
- *timeout = GNUNET_TIME_UNIT_ZERO;
- }
+ {
+ to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
+ if (timeout->rel_value > to.rel_value)
+ *timeout = to;
+ if (pos->reason != 0)
+ *timeout = GNUNET_TIME_UNIT_ZERO;
+ }
pos = pending;
while (pos != NULL)
+ {
+ if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) &&
+ (GNUNET_YES == is_pending (pos->prereq_id)))
{
- if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) &&
- (GNUNET_YES == is_pending (pos->prereq_id)))
- {
- pos = pos->next;
- continue;
- }
- if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
- {
- to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
- if (timeout->rel_value > to.rel_value)
- *timeout = to;
- }
- if (pos->read_fd != -1)
- GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
- if (pos->write_fd != -1)
- GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
- if (pos->read_set != NULL)
- GNUNET_NETWORK_fdset_add (rs, pos->read_set);
- if (pos->write_set != NULL)
- GNUNET_NETWORK_fdset_add (ws, pos->write_set);
- if (pos->reason != 0)
- *timeout = GNUNET_TIME_UNIT_ZERO;
pos = pos->next;
+ continue;
+ }
+ if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
+ {
+ to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
+ if (timeout->rel_value > to.rel_value)
+ *timeout = to;
}
+ if (pos->read_fd != -1)
+ GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
+ if (pos->write_fd != -1)
+ GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
+ if (pos->read_set != NULL)
+ GNUNET_NETWORK_fdset_add (rs, pos->read_set);
+ if (pos->write_set != NULL)
+ GNUNET_NETWORK_fdset_add (ws, pos->write_set);
+ if (pos->reason != 0)
+ *timeout = GNUNET_TIME_UNIT_ZERO;
+ pos = pos->next;
+ }
}
*/
static int
set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
- struct GNUNET_NETWORK_FDSet *want)
+ struct GNUNET_NETWORK_FDSet *want)
{
if ((NULL == want) || (NULL == ready))
return GNUNET_NO;
if (GNUNET_NETWORK_fdset_overlap (ready, want))
- {
- /* copy all over (yes, there maybe unrelated bits,
- * but this should not hurt well-written clients) */
- GNUNET_NETWORK_fdset_copy (want, ready);
- return GNUNET_YES;
- }
+ {
+ /* copy all over (yes, there maybe unrelated bits,
+ * but this should not hurt well-written clients) */
+ GNUNET_NETWORK_fdset_copy (want, ready);
+ return GNUNET_YES;
+ }
return GNUNET_NO;
}
*/
static int
is_ready (struct Task *task, struct GNUNET_TIME_Absolute now,
- const struct GNUNET_NETWORK_FDSet *rs,
- const struct GNUNET_NETWORK_FDSet *ws)
+ const struct GNUNET_NETWORK_FDSet *rs,
+ const struct GNUNET_NETWORK_FDSet *ws)
{
enum GNUNET_SCHEDULER_Reason reason;
reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
(((task->read_fd != -1) &&
- (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd)))
- || (set_overlaps (rs, task->read_set))))
+ (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) ||
+ (set_overlaps (rs, task->read_set))))
reason |= GNUNET_SCHEDULER_REASON_READ_READY;
if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
(((task->write_fd != -1) &&
- (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd)))
+ (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd)))
|| (set_overlaps (ws, task->write_set))))
reason |= GNUNET_SCHEDULER_REASON_WRITE_READY;
if (reason == 0)
- return GNUNET_NO; /* not ready */
+ return GNUNET_NO; /* not ready */
if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK)
+ {
+ if (GNUNET_YES == is_pending (task->prereq_id))
{
- if (GNUNET_YES == is_pending (task->prereq_id))
- {
- task->reason = reason;
- return GNUNET_NO; /* prereq waiting */
- }
- reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
+ task->reason = reason;
+ return GNUNET_NO; /* prereq waiting */
}
+ reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
+ }
task->reason = reason;
return GNUNET_YES;
}
*/
static void
check_ready (const struct GNUNET_NETWORK_FDSet *rs,
- const struct GNUNET_NETWORK_FDSet *ws)
+ const struct GNUNET_NETWORK_FDSet *ws)
{
struct Task *pos;
struct Task *prev;
prev = NULL;
pos = pending_timeout;
while (pos != NULL)
- {
- next = pos->next;
- if (now.abs_value >= pos->timeout.abs_value)
- pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
- if (0 == pos->reason)
- break;
- pending_timeout = next;
- if (pending_timeout_last == pos)
- pending_timeout_last = NULL;
- queue_ready_task (pos);
- pos = next;
- }
+ {
+ next = pos->next;
+ if (now.abs_value >= pos->timeout.abs_value)
+ pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
+ if (0 == pos->reason)
+ break;
+ pending_timeout = next;
+ if (pending_timeout_last == pos)
+ pending_timeout_last = NULL;
+ queue_ready_task (pos);
+ pos = next;
+ }
pos = pending;
while (pos != NULL)
- {
+ {
#if DEBUG_TASKS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Checking readiness of task: %llu / %p\n", pos->id,
- pos->callback_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking readiness of task: %llu / %p\n",
+ pos->id, pos->callback_cls);
#endif
- next = pos->next;
- if (GNUNET_YES == is_ready (pos, now, rs, ws))
- {
- if (prev == NULL)
- pending = next;
- else
- prev->next = next;
- queue_ready_task (pos);
- pos = next;
- continue;
- }
- prev = pos;
+ next = pos->next;
+ if (GNUNET_YES == is_ready (pos, now, rs, ws))
+ {
+ if (prev == NULL)
+ pending = next;
+ else
+ prev->next = next;
+ queue_ready_task (pos);
pos = next;
+ continue;
}
+ prev = pos;
+ pos = next;
+ }
}
pos = pending_timeout;
while (pos != NULL)
- {
- pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
- /* we don't move the task into the ready queue yet; check_ready
- * will do that later, possibly adding additional
- * readiness-factors */
- pos = pos->next;
- }
+ {
+ pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
+ /* we don't move the task into the ready queue yet; check_ready
+ * will do that later, possibly adding additional
+ * readiness-factors */
+ pos = pos->next;
+ }
pos = pending;
while (pos != NULL)
+ {
+ pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
+ /* we don't move the task into the ready queue yet; check_ready
+ * will do that later, possibly adding additional
+ * readiness-factors */
+ pos = pos->next;
+ }
+ for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++)
+ {
+ pos = ready[i];
+ while (pos != NULL)
{
pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
/* we don't move the task into the ready queue yet; check_ready
* readiness-factors */
pos = pos->next;
}
- for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++)
- {
- pos = ready[i];
- while (pos != NULL)
- {
- pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
- /* we don't move the task into the ready queue yet; check_ready
- * will do that later, possibly adding additional
- * readiness-factors */
- pos = pos->next;
- }
- }
+ }
}
max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
do
+ {
+ if (ready_count == 0)
+ return;
+ GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL);
+ /* yes, p>0 is correct, 0 is "KEEP" which should
+ * always be an empty queue (see assertion)! */
+ for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
{
- if (ready_count == 0)
- return;
- GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL);
- /* yes, p>0 is correct, 0 is "KEEP" which should
- * always be an empty queue (see assertion)! */
- for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
- {
- pos = ready[p];
- if (pos != NULL)
- break;
- }
- GNUNET_assert (pos != NULL); /* ready_count wrong? */
- ready[p] = pos->next;
- ready_count--;
- if (current_priority != pos->priority)
- {
- current_priority = pos->priority;
- (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
- pos->priority);
- }
- current_lifeness = pos->lifeness;
- active_task = pos;
+ pos = ready[p];
+ if (pos != NULL)
+ break;
+ }
+ GNUNET_assert (pos != NULL); /* ready_count wrong? */
+ ready[p] = pos->next;
+ ready_count--;
+ if (current_priority != pos->priority)
+ {
+ current_priority = pos->priority;
+ (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
+ pos->priority);
+ }
+ current_lifeness = pos->lifeness;
+ active_task = pos;
#if PROFILE_DELAYS
- if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value >
- DELAY_THRESHOLD.rel_value)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Task %llu took %llums to be scheduled\n", pos->id,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value);
- }
+ if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value >
+ DELAY_THRESHOLD.rel_value)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Task %llu took %llums to be scheduled\n",
+ pos->id,
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value);
+ }
#endif
- tc.reason = pos->reason;
- tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set;
- if ((pos->read_fd != -1) &&
- (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY)))
- GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
- tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set;
- if ((pos->write_fd != -1) &&
- (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)))
- GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
- if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) &&
- (pos->write_fd != -1) &&
- (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
- abort (); // added to ready in previous select loop!
+ tc.reason = pos->reason;
+ tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set;
+ if ((pos->read_fd != -1) &&
+ (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY)))
+ GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
+ tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set;
+ if ((pos->write_fd != -1) &&
+ (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)))
+ GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
+ if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) &&
+ (pos->write_fd != -1) &&
+ (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
+ abort (); // added to ready in previous select loop!
#if DEBUG_TASKS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Running task: %llu / %p\n", pos->id, pos->callback_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id,
+ pos->callback_cls);
#endif
- pos->callback (pos->callback_cls, &tc);
+ pos->callback (pos->callback_cls, &tc);
#if EXECINFO
- int i;
+ int i;
- for (i = 0; i < pos->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Task %llu trace %d: %s\n", pos->id,
- i, pos->backtrace_strings[i]);
+ for (i = 0; i < pos->num_backtrace_strings; i++)
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Task %llu trace %d: %s\n", pos->id, i,
+ pos->backtrace_strings[i]);
#endif
- active_task = NULL;
- destroy_task (pos);
- tasks_run++;
- }
+ active_task = NULL;
+ destroy_task (pos);
+ tasks_run++;
+ }
while ((pending == NULL) || (p >= max_priority_added));
}
sighandler_shutdown ()
{
static char c;
- int old_errno = errno; /* backup errno */
+ int old_errno = errno; /* backup errno */
GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
- (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE),
- &c, sizeof (c));
+ (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE),
+ &c, sizeof (c));
errno = old_errno;
}
if (t->lifeness == GNUNET_YES)
return GNUNET_OK;
if ((NULL != pending) || (NULL != pending_timeout))
- {
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_OK;
- }
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return GNUNET_OK;
+ }
return GNUNET_NO;
}
shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
GNUNET_assert (shutdown_pipe_handle != NULL);
pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
- GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_PIPE_END_READ);
GNUNET_assert (pr != NULL);
shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
current_lifeness = GNUNET_YES;
GNUNET_SCHEDULER_add_continuation (task, task_cls,
- GNUNET_SCHEDULER_REASON_STARTUP);
+ GNUNET_SCHEDULER_REASON_STARTUP);
#if ENABLE_WINDOWS_WORKAROUNDS
- active_task = (void *) (long) -1; /* force passing of sanity check */
+ active_task = (void *) (long) -1; /* force passing of sanity check */
GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
- &GNUNET_OS_install_parent_control_handler,
- NULL);
+ &GNUNET_OS_install_parent_control_handler,
+ NULL);
active_task = NULL;
#endif
last_tr = 0;
busy_wait_warning = 0;
while (GNUNET_OK == check_lifeness ())
+ {
+ GNUNET_NETWORK_fdset_zero (rs);
+ GNUNET_NETWORK_fdset_zero (ws);
+ timeout = GNUNET_TIME_UNIT_FOREVER_REL;
+ update_sets (rs, ws, &timeout);
+ GNUNET_NETWORK_fdset_handle_set (rs, pr);
+ if (ready_count > 0)
{
- GNUNET_NETWORK_fdset_zero (rs);
- GNUNET_NETWORK_fdset_zero (ws);
- timeout = GNUNET_TIME_UNIT_FOREVER_REL;
- update_sets (rs, ws, &timeout);
- GNUNET_NETWORK_fdset_handle_set (rs, pr);
- if (ready_count > 0)
- {
- /* no blocking, more work already ready! */
- timeout = GNUNET_TIME_UNIT_ZERO;
- }
- if (NULL == scheduler_select)
- ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
- else
- ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout);
- if (ret == GNUNET_SYSERR)
- {
- if (errno == EINTR)
- continue;
+ /* no blocking, more work already ready! */
+ timeout = GNUNET_TIME_UNIT_ZERO;
+ }
+ if (NULL == scheduler_select)
+ ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
+ else
+ ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout);
+ if (ret == GNUNET_SYSERR)
+ {
+ if (errno == EINTR)
+ continue;
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select");
#ifndef MINGW
#if USE_LSOF
- char lsof[512];
+ char lsof[512];
- snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ());
- (void) close (1);
- (void) dup2 (2, 1);
- if (0 != system (lsof))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system");
+ snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ());
+ (void) close (1);
+ (void) dup2 (2, 1);
+ if (0 != system (lsof))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system");
#endif
#endif
- abort ();
- break;
- }
- if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Looks like we're busy waiting...\n"));
- sleep (1); /* mitigate */
- }
- check_ready (rs, ws);
- run_ready (rs, ws);
- if (GNUNET_NETWORK_fdset_handle_isset (rs, pr))
- {
- /* consume the signal */
- GNUNET_DISK_file_read (pr, &c, sizeof (c));
- /* mark all active tasks as ready due to shutdown */
- GNUNET_SCHEDULER_shutdown ();
- }
- if (last_tr == tasks_run)
- {
- busy_wait_warning++;
- }
- else
- {
- last_tr = tasks_run;
- busy_wait_warning = 0;
- }
+ abort ();
+ break;
+ }
+ if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Looks like we're busy waiting...\n"));
+ sleep (1); /* mitigate */
+ }
+ check_ready (rs, ws);
+ run_ready (rs, ws);
+ if (GNUNET_NETWORK_fdset_handle_isset (rs, pr))
+ {
+ /* consume the signal */
+ GNUNET_DISK_file_read (pr, &c, sizeof (c));
+ /* mark all active tasks as ready due to shutdown */
+ GNUNET_SCHEDULER_shutdown ();
+ }
+ if (last_tr == tasks_run)
+ {
+ busy_wait_warning++;
+ }
+ else
+ {
+ last_tr = tasks_run;
+ busy_wait_warning = 0;
}
+ }
GNUNET_SIGNAL_handler_uninstall (shc_int);
GNUNET_SIGNAL_handler_uninstall (shc_term);
#ifndef MINGW
ret = 0;
pos = ready[check_priority (p)];
while (pos != NULL)
- {
- pos = pos->next;
- ret++;
- }
+ {
+ pos = pos->next;
+ ret++;
+ }
return ret;
}
prev = NULL;
t = pending;
while (t != NULL)
+ {
+ if (t->id == task)
+ break;
+ prev = t;
+ t = t->next;
+ }
+ if (t == NULL)
+ {
+ prev = NULL;
+ to = 1;
+ t = pending_timeout;
+ while (t != NULL)
{
if (t->id == task)
- break;
+ break;
prev = t;
t = t->next;
}
- if (t == NULL)
- {
- prev = NULL;
- to = 1;
- t = pending_timeout;
- while (t != NULL)
- {
- if (t->id == task)
- break;
- prev = t;
- t = t->next;
- }
- if (pending_timeout_last == t)
- pending_timeout_last = NULL;
- }
+ if (pending_timeout_last == t)
+ pending_timeout_last = NULL;
+ }
p = 0;
while (t == NULL)
+ {
+ p++;
+ if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT)
{
- p++;
- if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Attempt to cancel dead task %llu!\n"),
- (unsigned long long) task);
- GNUNET_assert (0);
- }
- prev = NULL;
- t = ready[p];
- while (t != NULL)
- {
- if (t->id == task)
- {
- ready_count--;
- break;
- }
- prev = t;
- t = t->next;
- }
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Attempt to cancel dead task %llu!\n"),
+ (unsigned long long) task);
+ GNUNET_assert (0);
}
+ prev = NULL;
+ t = ready[p];
+ while (t != NULL)
+ {
+ if (t->id == task)
+ {
+ ready_count--;
+ break;
+ }
+ prev = t;
+ t = t->next;
+ }
+ }
if (prev == NULL)
+ {
+ if (p == 0)
{
- if (p == 0)
- {
- if (to == 0)
- {
- pending = t->next;
- }
- else
- {
- pending_timeout = t->next;
- }
- }
+ if (to == 0)
+ {
+ pending = t->next;
+ }
else
- {
- ready[p] = t->next;
- }
+ {
+ pending_timeout = t->next;
+ }
}
- else
+ else
{
- prev->next = t->next;
+ ready[p] = t->next;
}
+ }
+ else
+ {
+ prev->next = t->next;
+ }
ret = t->callback_cls;
#if DEBUG_TASKS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Canceling task: %llu / %p\n", task, t->callback_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling task: %llu / %p\n", task,
+ t->callback_cls);
#endif
destroy_task (t);
return ret;
*/
void
GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
- enum GNUNET_SCHEDULER_Reason reason)
+ enum GNUNET_SCHEDULER_Reason reason)
{
struct Task *t;
GNUNET_assert (NULL != task);
GNUNET_assert ((active_task != NULL) ||
- (reason == GNUNET_SCHEDULER_REASON_STARTUP));
+ (reason == GNUNET_SCHEDULER_REASON_STARTUP));
t = GNUNET_malloc (sizeof (struct Task));
#if EXECINFO
t->num_backtrace_strings = backtrace (backtrace_array, 50);
t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
#endif
t->read_fd = -1;
t->write_fd = -1;
t->priority = current_priority;
t->lifeness = current_lifeness;
#if DEBUG_TASKS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding continuation task: %llu / %p\n", t->id, t->callback_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id,
+ t->callback_cls);
#endif
queue_ready_task (t);
}
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
- prerequisite_task,
- GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
- task_cls);
+ prerequisite_task, GNUNET_TIME_UNIT_ZERO,
+ NULL, NULL, task, task_cls);
}
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_Task task,
- void *task_cls)
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
- task_cls);
+ GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
+ task_cls);
}
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if 1
/* new, optimized version */
#if EXECINFO
t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
#endif
t->read_fd = -1;
t->write_fd = -1;
* appending to a long list of tasks with timeouts) */
prev = pending_timeout_last;
if (prev != NULL)
- {
- if (prev->timeout.abs_value > t->timeout.abs_value)
- prev = NULL;
- else
- pos = prev->next; /* heuristic success! */
- }
+ {
+ if (prev->timeout.abs_value > t->timeout.abs_value)
+ prev = NULL;
+ else
+ pos = prev->next; /* heuristic success! */
+ }
if (prev == NULL)
- {
- /* heuristic failed, do traversal of timeout list */
- pos = pending_timeout;
- }
+ {
+ /* heuristic failed, do traversal of timeout list */
+ pos = pending_timeout;
+ }
while ((pos != NULL) &&
- ((pos->timeout.abs_value <= t->timeout.abs_value) ||
- (pos->reason != 0)))
- {
- prev = pos;
- pos = pos->next;
- }
+ ((pos->timeout.abs_value <= t->timeout.abs_value) ||
+ (pos->reason != 0)))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (prev == NULL)
pending_timeout = t;
else
pending_timeout_last = t;
#if DEBUG_TASKS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding task: %llu / %p\n", t->id, t->callback_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
+ t->callback_cls);
#endif
#if EXECINFO
int i;
for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
+ t->backtrace_strings[i]);
#endif
return t->id;
#else
/* unoptimized version */
return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK, delay, NULL,
- NULL, task, task_cls);
+ GNUNET_SCHEDULER_NO_TASK, delay, NULL,
+ NULL, task, task_cls);
#endif
}
GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls)
{
return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
- task_cls);
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
+ task_cls);
}
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
- GNUNET_SCHEDULER_Task task,
- void *task_cls)
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
{
GNUNET_SCHEDULER_TaskIdentifier ret;
ret =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
- task_cls);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
+ task_cls);
GNUNET_assert (pending->id == ret);
pending->lifeness = lifeness;
return ret;
#ifndef MINGW
GNUNET_SCHEDULER_TaskIdentifier
add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
struct Task *t;
#if EXECINFO
t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
#endif
#if DEBUG_FDS
if (-1 != rfd)
- {
- int flags = fcntl (rfd, F_GETFD);
+ {
+ int flags = fcntl (rfd, F_GETFD);
- if ((flags == -1) && (errno == EBADF))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Got invalid file descriptor %d!\n", rfd);
+ if ((flags == -1) && (errno == EBADF))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", rfd);
#if EXECINFO
- int i;
+ int i;
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n", t->backtrace_strings[i]);
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]);
#endif
- GNUNET_assert (0);
- }
+ GNUNET_assert (0);
}
+ }
if (-1 != wfd)
- {
- int flags = fcntl (wfd, F_GETFD);
+ {
+ int flags = fcntl (wfd, F_GETFD);
- if (flags == -1 && errno == EBADF)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Got invalid file descriptor %d!\n", wfd);
+ if (flags == -1 && errno == EBADF)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", wfd);
#if EXECINFO
- int i;
+ int i;
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n", t->backtrace_strings[i]);
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]);
#endif
- GNUNET_assert (0);
- }
+ GNUNET_assert (0);
}
+ }
#endif
t->read_fd = rfd;
GNUNET_assert (wfd >= -1);
pending = t;
max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
#if DEBUG_TASKS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding task: %llu / %p\n", t->id, t->callback_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
+ t->callback_cls);
#endif
#if EXECINFO
int i;
for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
+ t->backtrace_strings[i]);
#endif
return t->id;
}
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle * rfd,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ struct GNUNET_NETWORK_Handle *rfd,
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
struct GNUNET_NETWORK_FDSet *rs;
rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set (rs, rfd);
ret =
- GNUNET_SCHEDULER_add_select (check_priority (current_priority),
- GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
- task, task_cls);
+ GNUNET_SCHEDULER_add_select (check_priority (current_priority),
+ GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
+ task, task_cls);
GNUNET_NETWORK_fdset_destroy (rs);
return ret;
#else
return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task,
- task_cls);
+ task_cls);
#endif
}
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle * wfd,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ struct GNUNET_NETWORK_Handle *wfd,
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
struct GNUNET_NETWORK_FDSet *ws;
ws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set (ws, wfd);
ret =
- GNUNET_SCHEDULER_add_select (check_priority (current_priority),
- GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
- task, task_cls);
+ GNUNET_SCHEDULER_add_select (check_priority (current_priority),
+ GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
+ task, task_cls);
GNUNET_NETWORK_fdset_destroy (ws);
return ret;
#else
GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0);
return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task,
- task_cls);
+ task_cls);
#endif
}
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
- const struct GNUNET_DISK_FileHandle * rfd,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ const struct GNUNET_DISK_FileHandle *rfd,
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
struct GNUNET_NETWORK_FDSet *rs;
rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_handle_set (rs, rfd);
ret =
- GNUNET_SCHEDULER_add_select (check_priority (current_priority),
- GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
- task, task_cls);
+ GNUNET_SCHEDULER_add_select (check_priority (current_priority),
+ GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
+ task, task_cls);
GNUNET_NETWORK_fdset_destroy (rs);
return ret;
#else
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
- const struct GNUNET_DISK_FileHandle * wfd,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ const struct GNUNET_DISK_FileHandle *wfd,
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
struct GNUNET_NETWORK_FDSet *ws;
ws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_handle_set (ws, wfd);
ret =
- GNUNET_SCHEDULER_add_select (check_priority (current_priority),
- GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
- task, task_cls);
+ GNUNET_SCHEDULER_add_select (check_priority (current_priority),
+ GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
+ task, task_cls);
GNUNET_NETWORK_fdset_destroy (ws);
return ret;
#else
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier
- prerequisite_task,
- struct GNUNET_TIME_Relative delay,
- const struct GNUNET_NETWORK_FDSet * rs,
- const struct GNUNET_NETWORK_FDSet * ws,
- GNUNET_SCHEDULER_Task task, void *task_cls)
+ GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
+ struct GNUNET_TIME_Relative delay,
+ const struct GNUNET_NETWORK_FDSet *rs,
+ const struct GNUNET_NETWORK_FDSet *ws,
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
struct Task *t;
#if EXECINFO
t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
#endif
t->read_fd = -1;
t->write_fd = -1;
if (rs != NULL)
- {
- t->read_set = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_copy (t->read_set, rs);
- }
+ {
+ t->read_set = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_copy (t->read_set, rs);
+ }
if (ws != NULL)
- {
- t->write_set = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_copy (t->write_set, ws);
- }
+ {
+ t->write_set = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_copy (t->write_set, ws);
+ }
t->id = ++last_id;
#if PROFILE_DELAYS
t->start_time = GNUNET_TIME_absolute_get ();
t->prereq_id = prerequisite_task;
t->timeout = GNUNET_TIME_relative_to_absolute (delay);
t->priority =
- check_priority ((prio ==
- GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority :
- prio);
+ check_priority ((prio ==
+ GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority :
+ prio);
t->lifeness = current_lifeness;
t->next = pending;
pending = t;
max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
#if DEBUG_TASKS
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding task: %llu / %p\n", t->id, t->callback_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
+ t->callback_cls);
#endif
#if EXECINFO
int i;
for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
+ t->backtrace_strings[i]);
#endif
return t->id;
}
* @param tc reason why we are running right now
*/
static void
-process_listen_socket (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_SERVER_Handle *server = cls;
struct GNUNET_CONNECTION_Handle *sock;
while (NULL != server->listen_sockets[i])
GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* ignore shutdown, someone else will take care of it! */
- server->listen_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
- &process_listen_socket, server);
- GNUNET_NETWORK_fdset_destroy (r);
- return;
- }
+ {
+ /* ignore shutdown, someone else will take care of it! */
+ server->listen_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
+ &process_listen_socket, server);
+ GNUNET_NETWORK_fdset_destroy (r);
+ return;
+ }
i = 0;
while (NULL != server->listen_sockets[i])
+ {
+ if (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_sockets[i]))
{
- if (GNUNET_NETWORK_fdset_isset
- (tc->read_ready, server->listen_sockets[i]))
- {
- sock =
- GNUNET_CONNECTION_create_from_accept (server->access,
- server->access_cls,
- server->listen_sockets[i]);
- if (sock != NULL)
- {
+ sock =
+ GNUNET_CONNECTION_create_from_accept (server->access,
+ server->access_cls,
+ server->listen_sockets[i]);
+ if (sock != NULL)
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server accepted incoming connection.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Server accepted incoming connection.\n");
#endif
- client = GNUNET_SERVER_connect_socket (server, sock);
- GNUNET_CONNECTION_ignore_shutdown (sock,
- server->clients_ignore_shutdown);
- /* decrement reference count, we don't keep "client" alive */
- GNUNET_SERVER_client_drop (client);
- }
- }
- i++;
+ client = GNUNET_SERVER_connect_socket (server, sock);
+ GNUNET_CONNECTION_ignore_shutdown (sock,
+ server->clients_ignore_shutdown);
+ /* decrement reference count, we don't keep "client" alive */
+ GNUNET_SERVER_client_drop (client);
+ }
}
+ i++;
+ }
/* listen for more! */
server->listen_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
- &process_listen_socket, server);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
+ &process_listen_socket, server);
GNUNET_NETWORK_fdset_destroy (r);
}
int eno;
switch (serverAddr->sa_family)
- {
- case AF_INET:
- port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port);
- break;
- case AF_INET6:
- port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port);
- break;
- case AF_UNIX:
- port = 0;
- break;
- default:
- GNUNET_break (0);
- port = 0;
- break;
- }
+ {
+ case AF_INET:
+ port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port);
+ break;
+ case AF_INET6:
+ port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port);
+ break;
+ case AF_UNIX:
+ port = 0;
+ break;
+ default:
+ GNUNET_break (0);
+ port = 0;
+ break;
+ }
sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0);
if (NULL == sock)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
- errno = 0;
- return NULL;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
+ errno = 0;
+ return NULL;
+ }
if (port != 0)
- {
- if (GNUNET_NETWORK_socket_setsockopt
- (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ {
+ if (GNUNET_NETWORK_socket_setsockopt
+ (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "setsockopt");
#ifdef IPV6_V6ONLY
- if ((serverAddr->sa_family == AF_INET6) &&
- (GNUNET_NETWORK_socket_setsockopt
- (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ if ((serverAddr->sa_family == AF_INET6) &&
+ (GNUNET_NETWORK_socket_setsockopt
+ (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "setsockopt");
#endif
- }
+ }
/* bind the socket */
if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK)
+ {
+ eno = errno;
+ if (errno != EADDRINUSE)
{
- eno = errno;
- if (errno != EADDRINUSE)
- {
- /* we don't log 'EADDRINUSE' here since an IPv4 bind may
- * fail if we already took the port on IPv6; if both IPv4 and
- * IPv6 binds fail, then our caller will log using the
- * errno preserved in 'eno' */
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
- if (port != 0)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed for port %d (%s).\n"), "bind", port,
- (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
- eno = 0;
- }
- else
- {
- if (port != 0)
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' failed for port %d (%s): address already in use\n"),
- "bind", port,
- (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
- else if (serverAddr->sa_family == AF_UNIX)
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' failed for `%s': address already in use\n"), "bind",
- ((const struct sockaddr_un *) serverAddr)->sun_path);
-
- }
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- errno = eno;
- return NULL;
+ /* we don't log 'EADDRINUSE' here since an IPv4 bind may
+ * fail if we already took the port on IPv6; if both IPv4 and
+ * IPv6 binds fail, then our caller will log using the
+ * errno preserved in 'eno' */
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
+ if (port != 0)
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed for port %d (%s).\n"),
+ "bind", port,
+ (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
+ eno = 0;
}
- if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
+ else
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- errno = 0;
- return NULL;
+ if (port != 0)
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("`%s' failed for port %d (%s): address already in use\n"),
+ "bind", port,
+ (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
+ else if (serverAddr->sa_family == AF_UNIX)
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("`%s' failed for `%s': address already in use\n"), "bind",
+ ((const struct sockaddr_un *) serverAddr)->sun_path);
+
}
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ errno = eno;
+ return NULL;
+ }
+ if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ errno = 0;
+ return NULL;
+ }
#if DEBUG_SERVER
if (port != 0)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server starts to listen on port %u.\n", port);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Server starts to listen on port %u.\n",
+ port);
#endif
return sock;
}
*/
struct GNUNET_SERVER_Handle *
GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
- void *access_cls,
- struct GNUNET_NETWORK_Handle **lsocks,
- struct GNUNET_TIME_Relative idle_timeout,
- int require_found)
+ void *access_cls,
+ struct GNUNET_NETWORK_Handle **lsocks,
+ struct GNUNET_TIME_Relative idle_timeout,
+ int require_found)
{
struct GNUNET_SERVER_Handle *ret;
struct GNUNET_NETWORK_FDSet *r;
ret->access_cls = access_cls;
ret->require_found = require_found;
if (lsocks != NULL)
- {
- r = GNUNET_NETWORK_fdset_create ();
- i = 0;
- while (NULL != ret->listen_sockets[i])
- GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
- ret->listen_task =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
- &process_listen_socket, ret);
- GNUNET_NETWORK_fdset_destroy (r);
- }
+ {
+ r = GNUNET_NETWORK_fdset_create ();
+ i = 0;
+ while (NULL != ret->listen_sockets[i])
+ GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
+ ret->listen_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
+ &process_listen_socket, ret);
+ GNUNET_NETWORK_fdset_destroy (r);
+ }
return ret;
}
*/
struct GNUNET_SERVER_Handle *
GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls,
- struct sockaddr *const *serverAddr,
- const socklen_t * socklen,
- struct GNUNET_TIME_Relative idle_timeout,
- int require_found)
+ struct sockaddr *const *serverAddr,
+ const socklen_t * socklen,
+ struct GNUNET_TIME_Relative idle_timeout,
+ int require_found)
{
struct GNUNET_NETWORK_Handle **lsocks;
unsigned int i;
while (serverAddr[i] != NULL)
i++;
if (i > 0)
+ {
+ lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1));
+ i = 0;
+ j = 0;
+ while (serverAddr[i] != NULL)
{
- lsocks =
- GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1));
- i = 0;
- j = 0;
- while (serverAddr[i] != NULL)
- {
- lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
- if (lsocks[j] != NULL)
- j++;
- i++;
- }
- if (j == 0)
- {
- if (errno != 0)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
- GNUNET_free (lsocks);
- lsocks = NULL;
- }
+ lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
+ if (lsocks[j] != NULL)
+ j++;
+ i++;
}
- else
+ if (j == 0)
{
+ if (errno != 0)
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
+ GNUNET_free (lsocks);
lsocks = NULL;
}
+ }
+ else
+ {
+ lsocks = NULL;
+ }
return GNUNET_SERVER_create_with_sockets (access, access_cls, lsocks,
- idle_timeout, require_found);
+ idle_timeout, require_found);
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n");
#endif
if (GNUNET_SCHEDULER_NO_TASK != s->listen_task)
- {
- GNUNET_SCHEDULER_cancel (s->listen_task);
- s->listen_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (s->listen_task);
+ s->listen_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (s->listen_sockets != NULL)
- {
- i = 0;
- while (s->listen_sockets[i] != NULL)
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (s->listen_sockets[i++]));
- GNUNET_free (s->listen_sockets);
- s->listen_sockets = NULL;
- }
+ {
+ i = 0;
+ while (s->listen_sockets[i] != NULL)
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (s->listen_sockets[i++]));
+ GNUNET_free (s->listen_sockets);
+ s->listen_sockets = NULL;
+ }
while (s->clients != NULL)
GNUNET_SERVER_client_disconnect (s->clients);
while (NULL != (hpos = s->handlers))
- {
- s->handlers = hpos->next;
- GNUNET_free (hpos);
- }
+ {
+ s->handlers = hpos->next;
+ GNUNET_free (hpos);
+ }
while (NULL != (npos = s->disconnect_notify_list))
- {
- npos->callback (npos->callback_cls, NULL);
- s->disconnect_notify_list = npos->next;
- GNUNET_free (npos);
- }
+ {
+ npos->callback (npos->callback_cls, NULL);
+ s->disconnect_notify_list = npos->next;
+ GNUNET_free (npos);
+ }
GNUNET_free (s);
}
*/
void
GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_SERVER_MessageHandler
- *handlers)
+ const struct GNUNET_SERVER_MessageHandler *handlers)
{
struct HandlerList *p;
* @param tc scheduler context (unused)
*/
static void
-warn_no_receive_done (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+warn_no_receive_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_SERVER_Client *client = cls;
client->warn_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_receive_done, client);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_receive_done, client);
if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
LOG (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"),
- (unsigned int) client->warn_type,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value);
+ _
+ ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"),
+ (unsigned int) client->warn_type,
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value);
}
* @param client client for which to disable the warning
*/
void
-GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client
- *client)
+GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client)
{
if (GNUNET_SCHEDULER_NO_TASK != client->warn_task)
- {
- GNUNET_SCHEDULER_cancel (client->warn_task);
- client->warn_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (client->warn_task);
+ client->warn_task = GNUNET_SCHEDULER_NO_TASK;
+ }
}
*/
int
GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
- struct GNUNET_SERVER_Client *sender,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *sender,
+ const struct GNUNET_MessageHeader *message)
{
struct HandlerList *pos;
const struct GNUNET_SERVER_MessageHandler *mh;
pos = server->handlers;
found = GNUNET_NO;
while (pos != NULL)
+ {
+ i = 0;
+ while (pos->handlers[i].callback != NULL)
{
- i = 0;
- while (pos->handlers[i].callback != NULL)
- {
- mh = &pos->handlers[i];
- if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
- {
- if ((mh->expected_size != 0) && (mh->expected_size != size))
- {
+ mh = &pos->handlers[i];
+ if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
+ {
+ if ((mh->expected_size != 0) && (mh->expected_size != size))
+ {
#if GNUNET8_NETWORK_IS_DEAD
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Expected %u bytes for message of type %u, got %u\n",
- mh->expected_size, mh->type, size);
- GNUNET_break_op (0);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Expected %u bytes for message of type %u, got %u\n",
+ mh->expected_size, mh->type, size);
+ GNUNET_break_op (0);
#endif
- return GNUNET_SYSERR;
- }
- if (sender != NULL)
- {
- if (0 == sender->suspended)
- {
- sender->warn_start = GNUNET_TIME_absolute_get ();
- sender->warn_task =
- GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_UNIT_MINUTES, &warn_no_receive_done,
- sender);
- sender->warn_type = type;
- }
- sender->suspended++;
- }
- mh->callback (mh->callback_cls, sender, message);
- found = GNUNET_YES;
- }
- i++;
- }
- pos = pos->next;
+ return GNUNET_SYSERR;
+ }
+ if (sender != NULL)
+ {
+ if (0 == sender->suspended)
+ {
+ sender->warn_start = GNUNET_TIME_absolute_get ();
+ sender->warn_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_receive_done, sender);
+ sender->warn_type = type;
+ }
+ sender->suspended++;
+ }
+ mh->callback (mh->callback_cls, sender, message);
+ found = GNUNET_YES;
+ }
+ i++;
}
+ pos = pos->next;
+ }
if (found == GNUNET_NO)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Received message of unknown type %d\n", type);
- if (server->require_found == GNUNET_YES)
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+ "Received message of unknown type %d\n", type);
+ if (server->require_found == GNUNET_YES)
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
*/
static void
process_incoming (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen,
- int errCode);
+ const struct sockaddr *addr, socklen_t addrlen, int errCode);
/**
process_mst (struct GNUNET_SERVER_Client *client, int ret)
{
while ((ret != GNUNET_SYSERR) && (client->server != NULL) &&
- (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
+ (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
+ {
+ if (ret == GNUNET_OK)
{
- if (ret == GNUNET_OK)
- {
- client->receive_pending = GNUNET_YES;
-#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server re-enters receive loop, timeout: %llu.\n",
- client->idle_timeout.rel_value);
-#endif
- GNUNET_CONNECTION_receive (client->connection,
- GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
- client->idle_timeout, &process_incoming,
- client);
- break;
- }
+ client->receive_pending = GNUNET_YES;
#if DEBUG_SERVER
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server processes additional messages instantly.\n");
+ "Server re-enters receive loop, timeout: %llu.\n",
+ client->idle_timeout.rel_value);
#endif
- ret =
- GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
- GNUNET_YES);
+ GNUNET_CONNECTION_receive (client->connection,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
+ client->idle_timeout, &process_incoming,
+ client);
+ break;
}
+#if DEBUG_SERVER
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Server processes additional messages instantly.\n");
+#endif
+ ret =
+ GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
+ GNUNET_YES);
+ }
#if DEBUG_SERVER
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
#endif
if (ret == GNUNET_NO)
- {
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server has more data pending but is suspended.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Server has more data pending but is suspended.\n");
#endif
- client->receive_pending = GNUNET_SYSERR; /* data pending */
- }
+ client->receive_pending = GNUNET_SYSERR; /* data pending */
+ }
if ((ret == GNUNET_SYSERR) || (GNUNET_YES == client->shutdown_now))
GNUNET_SERVER_client_disconnect (client);
GNUNET_SERVER_client_drop (client);
*/
static void
process_incoming (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+ const struct sockaddr *addr, socklen_t addrlen, int errCode)
{
struct GNUNET_SERVER_Client *client = cls;
struct GNUNET_SERVER_Handle *server = client->server;
GNUNET_assert (client->receive_pending == GNUNET_YES);
client->receive_pending = GNUNET_NO;
now = GNUNET_TIME_absolute_get ();
- end =
- GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout);
+ end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout);
if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) &&
(client->shutdown_now != GNUNET_YES) && (server != NULL) &&
(GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) &&
(end.abs_value > now.abs_value))
- {
- /* wait longer, timeout changed (i.e. due to us sending) */
+ {
+ /* wait longer, timeout changed (i.e. due to us sending) */
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Receive time out, but no disconnect due to sending (%p)\n",
- GNUNET_a2s (addr, addrlen));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Receive time out, but no disconnect due to sending (%p)\n",
+ GNUNET_a2s (addr, addrlen));
#endif
- client->receive_pending = GNUNET_YES;
- GNUNET_CONNECTION_receive (client->connection,
- GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
- GNUNET_TIME_absolute_get_remaining (end),
- &process_incoming, client);
- return;
- }
- if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL)
- || (client->shutdown_now == GNUNET_YES)
- || (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)))
- {
- /* other side closed connection, error connecting, etc. */
- GNUNET_SERVER_client_disconnect (client);
- return;
- }
+ client->receive_pending = GNUNET_YES;
+ GNUNET_CONNECTION_receive (client->connection,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
+ GNUNET_TIME_absolute_get_remaining (end),
+ &process_incoming, client);
+ return;
+ }
+ if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) ||
+ (client->shutdown_now == GNUNET_YES) ||
+ (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)))
+ {
+ /* other side closed connection, error connecting, etc. */
+ GNUNET_SERVER_client_disconnect (client);
+ return;
+ }
#if DEBUG_SERVER
LOG (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n",
(unsigned int) available, GNUNET_a2s (addr, addrlen));
GNUNET_SERVER_client_keep (client);
client->last_activity = now;
ret =
- GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
- GNUNET_YES);
+ GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
+ GNUNET_YES);
process_mst (client, ret);
}
client->restart_task = GNUNET_SCHEDULER_NO_TASK;
if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
(GNUNET_NO == server->clients_ignore_shutdown))
- {
- GNUNET_SERVER_client_disconnect (client);
- return;
- }
+ {
+ GNUNET_SERVER_client_disconnect (client);
+ return;
+ }
if (client->receive_pending == GNUNET_NO)
- {
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server begins to read again from client.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
#endif
- client->receive_pending = GNUNET_YES;
- GNUNET_CONNECTION_receive (client->connection,
- GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
- client->idle_timeout, &process_incoming,
- client);
- return;
- }
+ client->receive_pending = GNUNET_YES;
+ GNUNET_CONNECTION_receive (client->connection,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
+ client->idle_timeout, &process_incoming, client);
+ return;
+ }
#if DEBUG_SERVER
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Server continues processing messages still in the buffer.\n");
*/
static void
client_message_tokenizer_callback (void *cls, void *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVER_Handle *server = cls;
struct GNUNET_SERVER_Client *sender = client;
*/
struct GNUNET_SERVER_Client *
GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
- struct GNUNET_CONNECTION_Handle *connection)
+ struct GNUNET_CONNECTION_Handle *connection)
{
struct GNUNET_SERVER_Client *client;
client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
client->connection = connection;
client->mst =
- GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
+ GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
client->reference_count = 1;
client->server = server;
client->last_activity = GNUNET_TIME_absolute_get ();
client->callback = NULL;
client->callback_cls = NULL;
GNUNET_CONNECTION_receive (client->connection,
- GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
- client->idle_timeout, &process_incoming, client);
+ GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
+ client->idle_timeout, &process_incoming, client);
return client;
}
*/
void
GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
- struct GNUNET_TIME_Relative timeout)
+ struct GNUNET_TIME_Relative timeout)
{
client->idle_timeout = timeout;
}
*/
int
GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
- void **addr, size_t * addrlen)
+ void **addr, size_t * addrlen)
{
return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen);
}
*/
void
GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
- GNUNET_SERVER_DisconnectCallback callback,
- void *callback_cls)
+ GNUNET_SERVER_DisconnectCallback callback,
+ void *callback_cls)
{
struct NotifyList *n;
*/
void
GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
- GNUNET_SERVER_DisconnectCallback
- callback, void *callback_cls)
+ GNUNET_SERVER_DisconnectCallback
+ callback, void *callback_cls)
{
struct NotifyList *pos;
struct NotifyList *prev;
prev = NULL;
pos = server->disconnect_notify_list;
while (pos != NULL)
- {
- if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
- break;
- prev = pos;
- pos = pos->next;
- }
+ {
+ if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
+ break;
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
if (prev == NULL)
server->disconnect_notify_list = pos->next;
else
"Client is being disconnected from the server.\n");
#endif
if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (client->restart_task);
+ client->restart_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (client->warn_task);
+ client->warn_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (GNUNET_YES == client->receive_pending)
+ {
+ GNUNET_CONNECTION_receive_cancel (client->connection);
+ client->receive_pending = GNUNET_NO;
+ }
+
+ rc = client->reference_count;
+ if (client->server != NULL)
+ {
+ server = client->server;
+ client->server = NULL;
+ client->shutdown_now = GNUNET_YES;
+ prev = NULL;
+ pos = server->clients;
+ while ((pos != NULL) && (pos != client))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
+ GNUNET_assert (pos != NULL);
+ if (prev == NULL)
+ server->clients = pos->next;
+ else
+ prev->next = pos->next;
+ if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (client->restart_task);
client->restart_task = GNUNET_SCHEDULER_NO_TASK;
}
- if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
+ if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (client->warn_task);
client->warn_task = GNUNET_SCHEDULER_NO_TASK;
}
- if (GNUNET_YES == client->receive_pending)
- {
- GNUNET_CONNECTION_receive_cancel (client->connection);
- client->receive_pending = GNUNET_NO;
- }
-
- rc = client->reference_count;
- if (client->server != NULL)
+ n = server->disconnect_notify_list;
+ while (n != NULL)
{
- server = client->server;
- client->server = NULL;
- client->shutdown_now = GNUNET_YES;
- prev = NULL;
- pos = server->clients;
- while ((pos != NULL) && (pos != client))
- {
- prev = pos;
- pos = pos->next;
- }
- GNUNET_assert (pos != NULL);
- if (prev == NULL)
- server->clients = pos->next;
- else
- prev->next = pos->next;
- if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (client->restart_task);
- client->restart_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (client->warn_task);
- client->warn_task = GNUNET_SCHEDULER_NO_TASK;
- }
- n = server->disconnect_notify_list;
- while (n != NULL)
- {
- n->callback (n->callback_cls, client);
- n = n->next;
- }
+ n->callback (n->callback_cls, client);
+ n = n->next;
}
+ }
if (rc > 0)
- {
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "RC still positive, not destroying everything.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "RC still positive, not destroying everything.\n");
#endif
- return;
- }
+ return;
+ }
if (client->in_process_client_buffer == GNUNET_YES)
- {
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Still processing inputs, not destroying everything.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Still processing inputs, not destroying everything.\n");
#endif
- return;
- }
+ return;
+ }
if (client->persist == GNUNET_YES)
GNUNET_CONNECTION_persist_ (client->connection);
*/
struct GNUNET_CONNECTION_TransmitHandle *
GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
- size_t size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify
- callback, void *callback_cls)
+ size_t size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CONNECTION_TransmitReadyNotify
+ callback, void *callback_cls)
{
client->callback_cls = callback_cls;
client->callback = callback;
return GNUNET_CONNECTION_notify_transmit_ready (client->connection, size,
- timeout,
- &transmit_ready_callback_wrapper,
- client);
+ timeout,
+ &transmit_ready_callback_wrapper,
+ client);
}
GNUNET_assert (client->suspended > 0);
client->suspended--;
if (success != GNUNET_OK)
- {
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_SERVER_receive_done called with failure indication\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "GNUNET_SERVER_receive_done called with failure indication\n");
#endif
- GNUNET_SERVER_client_disconnect (client);
- return;
- }
+ GNUNET_SERVER_client_disconnect (client);
+ return;
+ }
if (client->suspended > 0)
- {
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_SERVER_receive_done called, but more clients pending\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "GNUNET_SERVER_receive_done called, but more clients pending\n");
#endif
- return;
- }
+ return;
+ }
if (GNUNET_SCHEDULER_NO_TASK != client->warn_task)
- {
- GNUNET_SCHEDULER_cancel (client->warn_task);
- client->warn_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (client->warn_task);
+ client->warn_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (client->in_process_client_buffer == GNUNET_YES)
- {
+ {
#if DEBUG_SERVER
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_SERVER_receive_done called while still in processing loop\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "GNUNET_SERVER_receive_done called while still in processing loop\n");
#endif
- return;
- }
+ return;
+ }
if (client->server == NULL)
- {
- GNUNET_SERVER_client_disconnect (client);
- return;
- }
+ {
+ GNUNET_SERVER_client_disconnect (client);
+ return;
+ }
#if DEBUG_SERVER
LOG (GNUNET_ERROR_TYPE_DEBUG,
"GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
#endif
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task);
- client->restart_task =
- GNUNET_SCHEDULER_add_now (&restart_processing, client);
+ client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, client);
}
*/
struct GNUNET_SERVER_MessageStreamTokenizer *
GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
- void *cb_cls)
+ void *cb_cls)
{
struct GNUNET_SERVER_MessageStreamTokenizer *ret;
*/
int
GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
- void *client_identity, const char *buf,
- size_t size, int purge, int one_shot)
+ void *client_identity, const char *buf, size_t size,
+ int purge, int one_shot)
{
const struct GNUNET_MessageHeader *hdr;
size_t delta;
ret = GNUNET_OK;
ibuf = (char *) mst->hdr;
while (mst->pos > 0)
+ {
+do_align:
+ if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
+ (0 != (mst->off % ALIGN_FACTOR)))
{
- do_align:
- if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
- (0 != (mst->off % ALIGN_FACTOR)))
- {
- /* need to align or need more space */
- mst->pos -= mst->off;
- memmove (ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
- {
- delta =
- GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
- (mst->pos - mst->off), size);
- memcpy (&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
- {
- if (purge)
- {
- mst->off = 0;
- mst->pos = 0;
- }
- return GNUNET_OK;
- }
- hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+ /* need to align or need more space */
+ mst->pos -= mst->off;
+ memmove (ibuf, &ibuf[mst->off], mst->pos);
+ mst->off = 0;
+ }
+ if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
+ {
+ delta =
+ GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
+ (mst->pos - mst->off), size);
+ memcpy (&ibuf[mst->pos], buf, delta);
+ mst->pos += delta;
+ buf += delta;
+ size -= delta;
+ }
+ if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
+ {
+ if (purge)
+ {
+ mst->off = 0;
+ mst->pos = 0;
+ }
+ return GNUNET_OK;
+ }
+ hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+ want = ntohs (hdr->size);
+ if (want < sizeof (struct GNUNET_MessageHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (mst->curr_buf - mst->off < want)
+ {
+ /* need more space */
+ mst->pos -= mst->off;
+ memmove (ibuf, &ibuf[mst->off], mst->pos);
+ mst->off = 0;
+ }
+ if (want > mst->curr_buf)
+ {
+ mst->hdr = GNUNET_realloc (mst->hdr, want);
+ ibuf = (char *) mst->hdr;
+ mst->curr_buf = want;
+ }
+ hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+ if (mst->pos - mst->off < want)
+ {
+ delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
+ memcpy (&ibuf[mst->pos], buf, delta);
+ mst->pos += delta;
+ buf += delta;
+ size -= delta;
+ }
+ if (mst->pos - mst->off < want)
+ {
+ if (purge)
+ {
+ mst->off = 0;
+ mst->pos = 0;
+ }
+ return GNUNET_OK;
+ }
+ if (one_shot == GNUNET_SYSERR)
+ {
+ /* cannot call callback again, but return value saying that
+ * we have another full message in the buffer */
+ ret = GNUNET_NO;
+ goto copy;
+ }
+ if (one_shot == GNUNET_YES)
+ one_shot = GNUNET_SYSERR;
+ mst->cb (mst->cb_cls, client_identity, hdr);
+ mst->off += want;
+ if (mst->off == mst->pos)
+ {
+ /* reset to beginning of buffer, it's free right now! */
+ mst->off = 0;
+ mst->pos = 0;
+ }
+ }
+ while (size > 0)
+ {
+#if DEBUG_SERVER_MST
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Server-mst has %u bytes left in inbound buffer\n",
+ (unsigned int) size);
+#endif
+ if (size < sizeof (struct GNUNET_MessageHeader))
+ break;
+ offset = (unsigned long) buf;
+ need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
+ if (GNUNET_NO == need_align)
+ {
+ /* can try to do zero-copy and process directly from original buffer */
+ hdr = (const struct GNUNET_MessageHeader *) buf;
want = ntohs (hdr->size);
if (want < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (mst->curr_buf - mst->off < want)
- {
- /* need more space */
- mst->pos -= mst->off;
- memmove (ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (want > mst->curr_buf)
- {
- mst->hdr = GNUNET_realloc (mst->hdr, want);
- ibuf = (char *) mst->hdr;
- mst->curr_buf = want;
- }
- hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
- if (mst->pos - mst->off < want)
- {
- delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
- memcpy (&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < want)
- {
- if (purge)
- {
- mst->off = 0;
- mst->pos = 0;
- }
- return GNUNET_OK;
- }
+ {
+ GNUNET_break_op (0);
+ mst->off = 0;
+ return GNUNET_SYSERR;
+ }
+ if (size < want)
+ break; /* or not, buffer incomplete, so copy to private buffer... */
if (one_shot == GNUNET_SYSERR)
- {
- /* cannot call callback again, but return value saying that
- * we have another full message in the buffer */
- ret = GNUNET_NO;
- goto copy;
- }
+ {
+ /* cannot call callback again, but return value saying that
+ * we have another full message in the buffer */
+ ret = GNUNET_NO;
+ goto copy;
+ }
if (one_shot == GNUNET_YES)
- one_shot = GNUNET_SYSERR;
+ one_shot = GNUNET_SYSERR;
mst->cb (mst->cb_cls, client_identity, hdr);
- mst->off += want;
- if (mst->off == mst->pos)
- {
- /* reset to beginning of buffer, it's free right now! */
- mst->off = 0;
- mst->pos = 0;
- }
+ buf += want;
+ size -= want;
}
- while (size > 0)
+ else
{
-#if DEBUG_SERVER_MST
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server-mst has %u bytes left in inbound buffer\n",
- (unsigned int) size);
-#endif
- if (size < sizeof (struct GNUNET_MessageHeader))
- break;
- offset = (unsigned long) buf;
- need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
- if (GNUNET_NO == need_align)
- {
- /* can try to do zero-copy and process directly from original buffer */
- hdr = (const struct GNUNET_MessageHeader *) buf;
- want = ntohs (hdr->size);
- if (want < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- mst->off = 0;
- return GNUNET_SYSERR;
- }
- if (size < want)
- break; /* or not, buffer incomplete, so copy to private buffer... */
- if (one_shot == GNUNET_SYSERR)
- {
- /* cannot call callback again, but return value saying that
- * we have another full message in the buffer */
- ret = GNUNET_NO;
- goto copy;
- }
- if (one_shot == GNUNET_YES)
- one_shot = GNUNET_SYSERR;
- mst->cb (mst->cb_cls, client_identity, hdr);
- buf += want;
- size -= want;
- }
- else
- {
- /* need to copy to private buffer to align;
- * yes, we go a bit more spagetti than usual here */
- goto do_align;
- }
+ /* need to copy to private buffer to align;
+ * yes, we go a bit more spagetti than usual here */
+ goto do_align;
}
+ }
copy:
if ((size > 0) && (!purge))
+ {
+ if (size + mst->pos > mst->curr_buf)
{
- if (size + mst->pos > mst->curr_buf)
- {
- mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos);
- ibuf = (char *) mst->hdr;
- mst->curr_buf = size + mst->pos;
- }
- GNUNET_assert (mst->pos + size <= mst->curr_buf);
- memcpy (&ibuf[mst->pos], buf, size);
- mst->pos += size;
+ mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos);
+ ibuf = (char *) mst->hdr;
+ mst->curr_buf = size + mst->pos;
}
+ GNUNET_assert (mst->pos + size <= mst->curr_buf);
+ memcpy (&ibuf[mst->pos], buf, size);
+ mst->pos += size;
+ }
if (purge)
mst->off = 0;
#if DEBUG_SERVER_MST
struct PendingMessageList *pml;
if (client == NULL)
- {
- nc->server = NULL;
- return;
- }
+ {
+ nc->server = NULL;
+ return;
+ }
prev = NULL;
pos = nc->clients;
while (NULL != pos)
- {
- if (pos->client == client)
- break;
- prev = pos;
- pos = pos->next;
- }
+ {
+ if (pos->client == client)
+ break;
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
return;
#if DEBUG_SERVER_NC
else
prev->next = pos->next;
while (NULL != (pml = pos->pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
- GNUNET_free (pml);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
+ GNUNET_free (pml);
+ }
if (pos->th != NULL)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
- pos->th = NULL;
- }
+ {
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
+ pos->th = NULL;
+ }
GNUNET_SERVER_client_drop (client);
GNUNET_free (pos);
}
* @return handle to the notification context
*/
struct GNUNET_SERVER_NotificationContext *
-GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle
- *server, unsigned int queue_length)
+GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
+ unsigned int queue_length)
{
struct GNUNET_SERVER_NotificationContext *ret;
*/
void
GNUNET_SERVER_notification_context_destroy (struct
- GNUNET_SERVER_NotificationContext
- *nc)
+ GNUNET_SERVER_NotificationContext
+ *nc)
{
struct ClientList *pos;
struct PendingMessageList *pml;
while (NULL != (pos = nc->clients))
+ {
+ nc->clients = pos->next;
+ GNUNET_SERVER_client_drop (pos->client);
+ while (NULL != (pml = pos->pending_head))
{
- nc->clients = pos->next;
- GNUNET_SERVER_client_drop (pos->client);
- while (NULL != (pml = pos->pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail,
- pml);
- GNUNET_free (pml);
- }
- GNUNET_free (pos);
+ GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
+ GNUNET_free (pml);
}
+ GNUNET_free (pos);
+ }
if (nc->server != NULL)
GNUNET_SERVER_disconnect_notify_cancel (nc->server,
- &handle_client_disconnect, nc);
+ &handle_client_disconnect, nc);
GNUNET_free (nc);
}
* @param client client to add
*/
void
-GNUNET_SERVER_notification_context_add (struct
- GNUNET_SERVER_NotificationContext *nc,
- struct GNUNET_SERVER_Client *client)
+GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext
+ *nc,
+ struct GNUNET_SERVER_Client *client)
{
struct ClientList *cl;
cl->th = NULL;
if (buf == NULL)
- {
- /* 'cl' should be freed via disconnect notification shortly */
+ {
+ /* 'cl' should be freed via disconnect notification shortly */
#if DEBUG_SERVER_NC
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to transmit message from NC queue to client\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to transmit message from NC queue to client\n");
#endif
- return 0;
- }
+ return 0;
+ }
ret = 0;
while (NULL != (pml = cl->pending_head))
- {
- msize = ntohs (pml->msg->size);
- if (size < msize)
- break;
- GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml);
+ {
+ msize = ntohs (pml->msg->size);
+ if (size < msize)
+ break;
+ GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml);
#if DEBUG_SERVER_NC
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Copying message of type %u and size %u from pending queue to transmission buffer\n",
- ntohs (pml->msg->type), msize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Copying message of type %u and size %u from pending queue to transmission buffer\n",
+ ntohs (pml->msg->type), msize);
#endif
- memcpy (&cbuf[ret], pml->msg, msize);
- ret += msize;
- size -= msize;
- GNUNET_free (pml);
- cl->num_pending--;
- }
+ memcpy (&cbuf[ret], pml->msg, msize);
+ ret += msize;
+ size -= msize;
+ GNUNET_free (pml);
+ cl->num_pending--;
+ }
if (pml != NULL)
- {
+ {
#if DEBUG_SERVER_NC
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Have %u messages left in NC queue, will try transmission again\n",
- cl->num_pending);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Have %u messages left in NC queue, will try transmission again\n",
+ cl->num_pending);
#endif
- cl->th =
- GNUNET_SERVER_notify_transmit_ready (cl->client,
- ntohs (pml->msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_message, cl);
- }
+ cl->th =
+ GNUNET_SERVER_notify_transmit_ready (cl->client, ntohs (pml->msg->size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_message, cl);
+ }
else
GNUNET_assert (cl->num_pending == 0);
return ret;
*/
static void
do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
- struct ClientList *client, const struct GNUNET_MessageHeader *msg,
- int can_drop)
+ struct ClientList *client, const struct GNUNET_MessageHeader *msg,
+ int can_drop)
{
struct PendingMessageList *pml;
uint16_t size;
if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop))
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Dropping message of type %u and size %u due to full queue (%u entries)\n",
- ntohs (msg->type), ntohs (msg->size),
- (unsigned int) nc->queue_length);
- return; /* drop! */
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Dropping message of type %u and size %u due to full queue (%u entries)\n",
+ ntohs (msg->type), ntohs (msg->size), (unsigned int) nc->queue_length);
+ return; /* drop! */
+ }
if (client->num_pending > nc->queue_length)
- {
- /* FIXME: consider checking for other messages in the
- * queue that are 'droppable' */
- }
+ {
+ /* FIXME: consider checking for other messages in the
+ * queue that are 'droppable' */
+ }
client->num_pending++;
size = ntohs (msg->size);
pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size);
#endif
memcpy (&pml[1], msg, size);
/* append */
- GNUNET_CONTAINER_DLL_insert_tail (client->pending_head,
- client->pending_tail, pml);
+ GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail,
+ pml);
if (client->th == NULL)
client->th =
- GNUNET_SERVER_notify_transmit_ready (client->client,
- ntohs (client->pending_head->
- msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_message, client);
+ GNUNET_SERVER_notify_transmit_ready (client->client,
+ ntohs (client->pending_head->
+ msg->size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_message, client);
}
*/
void
GNUNET_SERVER_notification_context_unicast (struct
- GNUNET_SERVER_NotificationContext
- *nc,
- struct GNUNET_SERVER_Client
- *client,
- const struct GNUNET_MessageHeader
- *msg, int can_drop)
+ GNUNET_SERVER_NotificationContext
+ *nc,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader
+ *msg, int can_drop)
{
struct ClientList *pos;
pos = nc->clients;
while (NULL != pos)
- {
- if (pos->client == client)
- break;
- pos = pos->next;
- }
+ {
+ if (pos->client == client)
+ break;
+ pos = pos->next;
+ }
GNUNET_assert (pos != NULL);
do_unicast (nc, pos, msg, can_drop);
}
*/
void
GNUNET_SERVER_notification_context_broadcast (struct
- GNUNET_SERVER_NotificationContext
- *nc,
- const struct
- GNUNET_MessageHeader *msg,
- int can_drop)
+ GNUNET_SERVER_NotificationContext
+ *nc,
+ const struct GNUNET_MessageHeader
+ *msg, int can_drop)
{
struct ClientList *pos;
pos = nc->clients;
while (NULL != pos)
- {
- do_unicast (nc, pos, msg, can_drop);
- pos = pos->next;
- }
+ {
+ do_unicast (nc, pos, msg, can_drop);
+ pos = pos->next;
+ }
}
size_t msize;
if (buf == NULL)
- {
- GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
- return 0;
- }
+ {
+ GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
+ return 0;
+ }
if (tc->total - tc->off > size)
msize = size;
else
memcpy (buf, &tc->buf[tc->off], msize);
tc->off += msize;
if (tc->total == tc->off)
- {
+ {
- GNUNET_SERVER_receive_done (tc->client, GNUNET_OK);
- GNUNET_SERVER_client_drop (tc->client);
- GNUNET_free_non_null (tc->buf);
- GNUNET_free (tc);
- }
+ GNUNET_SERVER_receive_done (tc->client, GNUNET_OK);
+ GNUNET_SERVER_client_drop (tc->client);
+ GNUNET_free_non_null (tc->buf);
+ GNUNET_free (tc);
+ }
else
+ {
+ if (NULL ==
+ GNUNET_SERVER_notify_transmit_ready (tc->client,
+ GNUNET_MIN (MIN_BLOCK_SIZE,
+ tc->total - tc->off),
+ GNUNET_TIME_absolute_get_remaining
+ (tc->timeout), &transmit_response,
+ tc))
{
- if (NULL ==
- GNUNET_SERVER_notify_transmit_ready (tc->client,
- GNUNET_MIN (MIN_BLOCK_SIZE,
- tc->total -
- tc->off),
- GNUNET_TIME_absolute_get_remaining
- (tc->timeout),
- &transmit_response, tc))
- {
- GNUNET_break (0);
- GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
- }
+ GNUNET_break (0);
+ GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
}
+ }
return msize;
}
* @param type type of the message
*/
void
-GNUNET_SERVER_transmit_context_append_data (struct
- GNUNET_SERVER_TransmitContext *tc,
- const void *data, size_t length,
- uint16_t type)
+GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
+ *tc, const void *data,
+ size_t length, uint16_t type)
{
struct GNUNET_MessageHeader *msg;
size_t size;
*/
void
GNUNET_SERVER_transmit_context_append_message (struct
- GNUNET_SERVER_TransmitContext
- *tc,
- const struct
- GNUNET_MessageHeader *msg)
+ GNUNET_SERVER_TransmitContext
+ *tc,
+ const struct GNUNET_MessageHeader
+ *msg)
{
struct GNUNET_MessageHeader *m;
uint16_t size;
*/
void
GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
- struct GNUNET_TIME_Relative timeout)
+ struct GNUNET_TIME_Relative timeout)
{
tc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
if (NULL ==
GNUNET_SERVER_notify_transmit_ready (tc->client,
- GNUNET_MIN (MIN_BLOCK_SIZE,
- tc->total), timeout,
- &transmit_response, tc))
- {
- GNUNET_break (0);
- GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
- }
+ GNUNET_MIN (MIN_BLOCK_SIZE,
+ tc->total), timeout,
+ &transmit_response, tc))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
+ }
}
*/
void
GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
- *tc, int success)
+ *tc, int success)
{
GNUNET_SERVER_receive_done (tc->client, success);
GNUNET_SERVER_client_drop (tc->client);
i = 0;
pos = 0;
while (i < count)
+ {
+ cnt =
+ sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0],
+ &temps[1], &temps[2], &temps[3], &temps[4], &temps[5],
+ &temps[6], &temps[7]);
+ if (cnt == 8)
{
- cnt =
- sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0],
- &temps[1], &temps[2], &temps[3], &temps[4], &temps[5],
- &temps[6], &temps[7]);
- if (cnt == 8)
- {
- for (j = 0; j < 8; j++)
- if (temps[j] > 0xFF)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid format for IP: `%s'\n"), &routeList[pos]);
- GNUNET_free (result);
- return NULL;
- }
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
- result[i].netmask.s_addr =
- htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) +
- temps[7]);
- while (routeList[pos] != ';')
- pos++;
- pos++;
- i++;
- continue;
- }
- /* try second notation */
- cnt =
- sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1],
- &temps[2], &temps[3], &slash);
- if (cnt == 5)
- {
- for (j = 0; j < 4; j++)
- if (temps[j] > 0xFF)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid format for IP: `%s'\n"), &routeList[pos]);
- GNUNET_free (result);
- return NULL;
- }
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
- if ((slash <= 32) && (slash >= 0))
- {
- result[i].netmask.s_addr = 0;
- while (slash > 0)
- {
- result[i].netmask.s_addr =
- (result[i].netmask.s_addr >> 1) + 0x80000000;
- slash--;
- }
- result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
- while (routeList[pos] != ';')
- pos++;
- pos++;
- i++;
- continue;
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
- slash);
- GNUNET_free (result);
- return NULL; /* error */
- }
- }
- /* try third notation */
- slash = 32;
- cnt =
- sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1],
- &temps[2], &temps[3]);
- if (cnt == 4)
- {
- for (j = 0; j < 4; j++)
- if (temps[j] > 0xFF)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid format for IP: `%s'\n"), &routeList[pos]);
- GNUNET_free (result);
- return NULL;
- }
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
- result[i].netmask.s_addr = 0;
- while (slash > 0)
- {
- result[i].netmask.s_addr =
- (result[i].netmask.s_addr >> 1) + 0x80000000;
- slash--;
- }
- result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
- while (routeList[pos] != ';')
- pos++;
- pos++;
- i++;
- continue;
- }
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
- &routeList[pos]);
- GNUNET_free (result);
- return NULL; /* error */
+ for (j = 0; j < 8; j++)
+ if (temps[j] > 0xFF)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
+ &routeList[pos]);
+ GNUNET_free (result);
+ return NULL;
+ }
+ result[i].network.s_addr =
+ htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
+ temps[3]);
+ result[i].netmask.s_addr =
+ htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) +
+ temps[7]);
+ while (routeList[pos] != ';')
+ pos++;
+ pos++;
+ i++;
+ continue;
}
- if (pos < strlen (routeList))
+ /* try second notation */
+ cnt =
+ sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1],
+ &temps[2], &temps[3], &slash);
+ if (cnt == 5)
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
- &routeList[pos]);
- GNUNET_free (result);
- return NULL; /* oops */
+ for (j = 0; j < 4; j++)
+ if (temps[j] > 0xFF)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
+ &routeList[pos]);
+ GNUNET_free (result);
+ return NULL;
+ }
+ result[i].network.s_addr =
+ htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
+ temps[3]);
+ if ((slash <= 32) && (slash >= 0))
+ {
+ result[i].netmask.s_addr = 0;
+ while (slash > 0)
+ {
+ result[i].netmask.s_addr =
+ (result[i].netmask.s_addr >> 1) + 0x80000000;
+ slash--;
+ }
+ result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
+ while (routeList[pos] != ';')
+ pos++;
+ pos++;
+ i++;
+ continue;
+ }
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
+ slash);
+ GNUNET_free (result);
+ return NULL; /* error */
+ }
}
- return result; /* ok */
+ /* try third notation */
+ slash = 32;
+ cnt =
+ sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1],
+ &temps[2], &temps[3]);
+ if (cnt == 4)
+ {
+ for (j = 0; j < 4; j++)
+ if (temps[j] > 0xFF)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
+ &routeList[pos]);
+ GNUNET_free (result);
+ return NULL;
+ }
+ result[i].network.s_addr =
+ htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
+ temps[3]);
+ result[i].netmask.s_addr = 0;
+ while (slash > 0)
+ {
+ result[i].netmask.s_addr = (result[i].netmask.s_addr >> 1) + 0x80000000;
+ slash--;
+ }
+ result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
+ while (routeList[pos] != ';')
+ pos++;
+ pos++;
+ i++;
+ continue;
+ }
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
+ &routeList[pos]);
+ GNUNET_free (result);
+ return NULL; /* error */
+ }
+ if (pos < strlen (routeList))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
+ &routeList[pos]);
+ GNUNET_free (result);
+ return NULL; /* oops */
+ }
+ return result; /* ok */
}
if (routeList[i] == ';')
count++;
if (routeList[len - 1] != ';')
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid network notation (does not end with ';': `%s')\n"),
- routeList);
- GNUNET_free (routeList);
- return NULL;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Invalid network notation (does not end with ';': `%s')\n"),
+ routeList);
+ GNUNET_free (routeList);
+ return NULL;
+ }
result = GNUNET_malloc (sizeof (struct IPv6NetworkSet) * (count + 1));
memset (result, 0, sizeof (struct IPv6NetworkSet) * (count + 1));
i = 0;
pos = 0;
while (i < count)
+ {
+ start = pos;
+ while (routeList[pos] != ';')
+ pos++;
+ slash = pos;
+ while ((slash >= start) && (routeList[slash] != '/'))
+ slash--;
+ if (slash < start)
{
- start = pos;
- while (routeList[pos] != ';')
- pos++;
+ memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr));
slash = pos;
- while ((slash >= start) && (routeList[slash] != '/'))
- slash--;
- if (slash < start)
- {
- memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr));
- slash = pos;
- }
- else
- {
- routeList[pos] = '\0';
- ret =
- inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask);
- if (ret <= 0)
- {
- save = errno;
- if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits))
- || (bits >= 128))
- {
- if (ret == 0)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Wrong format `%s' for netmask\n"),
- &routeList[slash + 1]);
- else
- {
- errno = save;
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
- }
- GNUNET_free (result);
- GNUNET_free (routeList);
- return NULL;
- }
- off = 0;
- while (bits > 8)
- {
- result[i].netmask.s6_addr[off++] = 0xFF;
- bits -= 8;
- }
- while (bits > 0)
- {
- result[i].netmask.s6_addr[off] =
- (result[i].netmask.s6_addr[off] >> 1) + 0x80;
- bits--;
- }
- }
- }
- routeList[slash] = '\0';
- ret = inet_pton (AF_INET6, &routeList[start], &result[i].network);
+ }
+ else
+ {
+ routeList[pos] = '\0';
+ ret = inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask);
if (ret <= 0)
- {
- if (ret == 0)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Wrong format `%s' for network\n"), &routeList[slash + 1]);
- else
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
- GNUNET_free (result);
- GNUNET_free (routeList);
- return NULL;
- }
- pos++;
- i++;
+ {
+ save = errno;
+ if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits >= 128))
+ {
+ if (ret == 0)
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Wrong format `%s' for netmask\n"),
+ &routeList[slash + 1]);
+ else
+ {
+ errno = save;
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
+ }
+ GNUNET_free (result);
+ GNUNET_free (routeList);
+ return NULL;
+ }
+ off = 0;
+ while (bits > 8)
+ {
+ result[i].netmask.s6_addr[off++] = 0xFF;
+ bits -= 8;
+ }
+ while (bits > 0)
+ {
+ result[i].netmask.s6_addr[off] =
+ (result[i].netmask.s6_addr[off] >> 1) + 0x80;
+ bits--;
+ }
+ }
+ }
+ routeList[slash] = '\0';
+ ret = inet_pton (AF_INET6, &routeList[start], &result[i].network);
+ if (ret <= 0)
+ {
+ if (ret == 0)
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Wrong format `%s' for network\n"),
+ &routeList[slash + 1]);
+ else
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
+ GNUNET_free (result);
+ GNUNET_free (routeList);
+ return NULL;
}
+ pos++;
+ i++;
+ }
GNUNET_free (routeList);
return result;
}
* @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is
*/
static int
-check_ipv4_listed (const struct IPv4NetworkSet *list,
- const struct in_addr *add)
+check_ipv4_listed (const struct IPv4NetworkSet *list, const struct in_addr *add)
{
int i;
return GNUNET_NO;
while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0))
- {
- if ((add->s_addr & list[i].netmask.s_addr) ==
- (list[i].network.s_addr & list[i].netmask.s_addr))
- return GNUNET_YES;
- i++;
- }
+ {
+ if ((add->s_addr & list[i].netmask.s_addr) ==
+ (list[i].network.s_addr & list[i].netmask.s_addr))
+ return GNUNET_YES;
+ i++;
+ }
return GNUNET_NO;
}
* @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is
*/
static int
-check_ipv6_listed (const struct IPv6NetworkSet *list,
- const struct in6_addr *ip)
+check_ipv6_listed (const struct IPv6NetworkSet *list, const struct in6_addr *ip)
{
unsigned int i;
unsigned int j;
i = 0;
NEXT:
while (memcmp (&zero, &list[i].network, sizeof (struct in6_addr)) != 0)
- {
- for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
- if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
- (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j]))
- {
- i++;
- goto NEXT;
- }
- return GNUNET_YES;
- }
+ {
+ for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
+ if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
+ (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j]))
+ {
+ i++;
+ goto NEXT;
+ }
+ return GNUNET_YES;
+ }
return GNUNET_NO;
}
struct GNUNET_MessageHeader *msg;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return 0; /* client disconnected */
+ }
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
*/
static void
handle_test (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
/* simply bounce message back to acknowledge */
if (NULL ==
GNUNET_SERVER_notify_transmit_ready (client,
- sizeof (struct
- GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &write_test, client))
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &write_test, client))
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
}
*/
static int
check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
- const struct sockaddr *addr, socklen_t addrlen)
+ const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_SERVICE_Context *sctx = cls;
const struct sockaddr_in *i4;
int ret;
switch (addr->sa_family)
- {
- case AF_INET:
- GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
- i4 = (const struct sockaddr_in *) addr;
- ret = ((sctx->v4_allowed == NULL) ||
- (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
- ((sctx->v4_denied == NULL) ||
- (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
- break;
- case AF_INET6:
- GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
- i6 = (const struct sockaddr_in6 *) addr;
- ret = ((sctx->v6_allowed == NULL) ||
- (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
- ((sctx->v6_denied == NULL) ||
- (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
- break;
+ {
+ case AF_INET:
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
+ i4 = (const struct sockaddr_in *) addr;
+ ret = ((sctx->v4_allowed == NULL) ||
+ (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
+ ((sctx->v4_denied == NULL) ||
+ (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
+ break;
+ case AF_INET6:
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
+ i6 = (const struct sockaddr_in6 *) addr;
+ ret = ((sctx->v6_allowed == NULL) ||
+ (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
+ ((sctx->v6_denied == NULL) ||
+ (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
+ break;
#ifndef WINDOWS
- case AF_UNIX:
- ret = GNUNET_OK; /* always OK for now */
- if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES))
- ret = GNUNET_NO;
- if ((uc != NULL) &&
- ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) ||
- (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) ||
- (uc->gid == getegid ()) ||
- (uc->gid == getgid ())))
- ret = GNUNET_YES;
- else
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Access denied to UID %d / GID %d\n"),
- (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid);
- break;
+ case AF_UNIX:
+ ret = GNUNET_OK; /* always OK for now */
+ if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES))
+ ret = GNUNET_NO;
+ if ((uc != NULL) &&
+ ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) ||
+ (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) ||
+ (uc->gid == getegid ()) ||
+ (uc->gid == getgid ())))
+ ret = GNUNET_YES;
+ else
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Access denied to UID %d / GID %d\n"),
+ (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid);
+ break;
#endif
- default:
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"),
- addr->sa_family);
- return GNUNET_SYSERR;
- }
+ default:
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"),
+ addr->sa_family);
+ return GNUNET_SYSERR;
+ }
if (ret != GNUNET_OK)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Access from `%s' denied to service `%s'\n"),
- GNUNET_a2s (addr, addrlen), sctx->serviceName);
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Access from `%s' denied to service `%s'\n"), GNUNET_a2s (addr,
+ addrlen),
+ sctx->serviceName);
+ }
return ret;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName,
- "PIDFILE", &pif))
+ "PIDFILE", &pif))
return NULL;
return pif;
}
* Parse an IPv4 access control list.
*/
static int
-process_acl4 (struct IPv4NetworkSet **ret,
- struct GNUNET_SERVICE_Context *sctx, const char *option)
+process_acl4 (struct IPv4NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx,
+ const char *option)
{
char *opt;
if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option))
return GNUNET_OK;
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
- sctx->serviceName,
- option, &opt));
+ GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
+ sctx->serviceName,
+ option, &opt));
if (NULL == (*ret = parse_ipv4_specification (opt)))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
- opt, sctx->serviceName, option);
- GNUNET_free (opt);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
+ opt, sctx->serviceName, option);
+ GNUNET_free (opt);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (opt);
return GNUNET_OK;
}
* Parse an IPv4 access control list.
*/
static int
-process_acl6 (struct IPv6NetworkSet **ret,
- struct GNUNET_SERVICE_Context *sctx, const char *option)
+process_acl6 (struct IPv6NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx,
+ const char *option)
{
char *opt;
if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option))
return GNUNET_OK;
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
- sctx->serviceName,
- option, &opt));
+ GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
+ sctx->serviceName,
+ option, &opt));
if (NULL == (*ret = parse_ipv6_specification (opt)))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
- opt, sctx->serviceName, option);
- GNUNET_free (opt);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
+ opt, sctx->serviceName, option);
+ GNUNET_free (opt);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (opt);
return GNUNET_OK;
}
*/
static void
add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
- const char *unixpath)
+ const char *unixpath)
{
#ifdef AF_UNIX
struct sockaddr_un *un;
*/
int
GNUNET_SERVICE_get_server_addresses (const char *serviceName,
- const struct GNUNET_CONFIGURATION_Handle
- *cfg, struct sockaddr ***addrs,
- socklen_t ** addr_lens)
+ const struct GNUNET_CONFIGURATION_Handle
+ *cfg, struct sockaddr ***addrs,
+ socklen_t ** addr_lens)
{
int disablev6;
struct GNUNET_NETWORK_Handle *desc;
*addr_lens = NULL;
desc = NULL;
if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6"))
- {
- if (GNUNET_SYSERR ==
- (disablev6 =
- GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName,
- "DISABLEV6")))
- return GNUNET_SYSERR;
- }
+ {
+ if (GNUNET_SYSERR ==
+ (disablev6 =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName, "DISABLEV6")))
+ return GNUNET_SYSERR;
+ }
else
disablev6 = GNUNET_NO;
if (!disablev6)
+ {
+ /* probe IPv6 support */
+ desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
+ if (NULL == desc)
{
- /* probe IPv6 support */
- desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
- if (NULL == desc)
- {
- if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
- (errno == EACCES))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
- return GNUNET_SYSERR;
- }
- LOG (GNUNET_ERROR_TYPE_INFO,
- _
- ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
- serviceName, STRERROR (errno));
- disablev6 = GNUNET_YES;
- }
- else
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
- desc = NULL;
- }
+ if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
+ (errno == EACCES))
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
+ return GNUNET_SYSERR;
+ }
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
+ serviceName, STRERROR (errno));
+ disablev6 = GNUNET_YES;
}
+ else
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
+ desc = NULL;
+ }
+ }
port = 0;
if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
+ "PORT", &port));
+ if (port > 65535)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
- "PORT", &port));
- if (port > 65535)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Require valid port number for service `%s' in configuration!\n"),
- serviceName);
- return GNUNET_SYSERR;
- }
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Require valid port number for service `%s' in configuration!\n"),
+ serviceName);
+ return GNUNET_SYSERR;
}
+ }
if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
- {
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
- "BINDTO",
- &hostname));
- }
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
+ "BINDTO", &hostname));
+ }
else
hostname = NULL;
GNUNET_CONFIGURATION_have_value (cfg, serviceName, "UNIXPATH")) &&
(GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH",
- &unixpath)) &&
+ &unixpath)) &&
(0 < strlen (unixpath)))
+ {
+ /* probe UNIX support */
+ struct sockaddr_un s_un;
+
+ if (strlen (unixpath) >= sizeof (s_un.sun_path))
{
- /* probe UNIX support */
- struct sockaddr_un s_un;
-
- if (strlen (unixpath) >= sizeof (s_un.sun_path))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"),
- unixpath, sizeof (s_un.sun_path));
- GNUNET_free_non_null (hostname);
- GNUNET_free (unixpath);
- return GNUNET_SYSERR;
- }
-
- desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
- if (NULL == desc)
- {
- if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
- (errno == EACCES))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
- GNUNET_free_non_null (hostname);
- GNUNET_free (unixpath);
- return GNUNET_SYSERR;
- }
- LOG (GNUNET_ERROR_TYPE_INFO,
- _
- ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
- serviceName, STRERROR (errno));
- GNUNET_free (unixpath);
- unixpath = NULL;
- }
- else
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
- desc = NULL;
- }
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
+ sizeof (s_un.sun_path));
+ GNUNET_free_non_null (hostname);
+ GNUNET_free (unixpath);
+ return GNUNET_SYSERR;
+ }
+
+ desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+ if (NULL == desc)
+ {
+ if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
+ (errno == EACCES))
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
+ GNUNET_free_non_null (hostname);
+ GNUNET_free (unixpath);
+ return GNUNET_SYSERR;
+ }
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
+ serviceName, STRERROR (errno));
+ GNUNET_free (unixpath);
+ unixpath = NULL;
+ }
+ else
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
+ desc = NULL;
}
+ }
#endif
if ((port == 0) && (unixpath == NULL))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ serviceName);
+ GNUNET_free_non_null (hostname);
+ return GNUNET_SYSERR;
+ }
+ if (port == 0)
+ {
+ saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
+ saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
+ add_unixpath (saddrs, saddrlens, unixpath);
+ GNUNET_free_non_null (unixpath);
+ GNUNET_free_non_null (hostname);
+ *addrs = saddrs;
+ *addr_lens = saddrlens;
+ return 1;
+ }
+
+ if (hostname != NULL)
+ {
+#if DEBUG_SERVICE
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Resolving `%s' since that is where `%s' will bind to.\n", hostname,
+ serviceName);
+#endif
+ memset (&hints, 0, sizeof (struct addrinfo));
+ if (disablev6)
+ hints.ai_family = AF_INET;
+ if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
+ (res == NULL))
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
- serviceName);
- GNUNET_free_non_null (hostname);
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"), hostname,
+ gai_strerror (ret));
+ GNUNET_free (hostname);
+ GNUNET_free_non_null (unixpath);
return GNUNET_SYSERR;
}
- if (port == 0)
+ next = res;
+ i = 0;
+ while (NULL != (pos = next))
{
- saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
- saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
- add_unixpath (saddrs, saddrlens, unixpath);
+ next = pos->ai_next;
+ if ((disablev6) && (pos->ai_family == AF_INET6))
+ continue;
+ i++;
+ }
+ if (0 == i)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to find %saddress for `%s'.\n"),
+ disablev6 ? "IPv4 " : "", hostname);
+ freeaddrinfo (res);
+ GNUNET_free (hostname);
GNUNET_free_non_null (unixpath);
- GNUNET_free_non_null (hostname);
- *addrs = saddrs;
- *addr_lens = saddrlens;
- return 1;
+ return GNUNET_SYSERR;
}
-
- if (hostname != NULL)
+ resi = i;
+ if (NULL != unixpath)
+ resi++;
+ saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
+ saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
+ i = 0;
+ if (NULL != unixpath)
{
+ add_unixpath (saddrs, saddrlens, unixpath);
+ i++;
+ }
+ next = res;
+ while (NULL != (pos = next))
+ {
+ next = pos->ai_next;
+ if ((disablev6) && (pos->ai_family == AF_INET6))
+ continue;
+ if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
+ continue; /* not TCP */
+ if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
+ continue; /* huh? */
#if DEBUG_SERVICE
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Resolving `%s' since that is where `%s' will bind to.\n",
- hostname, serviceName);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
+ serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
#endif
- memset (&hints, 0, sizeof (struct addrinfo));
- if (disablev6)
- hints.ai_family = AF_INET;
- if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
- (res == NULL))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"),
- hostname, gai_strerror (ret));
- GNUNET_free (hostname);
- GNUNET_free_non_null (unixpath);
- return GNUNET_SYSERR;
- }
- next = res;
- i = 0;
- while (NULL != (pos = next))
- {
- next = pos->ai_next;
- if ((disablev6) && (pos->ai_family == AF_INET6))
- continue;
- i++;
- }
- if (0 == i)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to find %saddress for `%s'.\n"),
- disablev6 ? "IPv4 " : "", hostname);
- freeaddrinfo (res);
- GNUNET_free (hostname);
- GNUNET_free_non_null (unixpath);
- return GNUNET_SYSERR;
- }
- resi = i;
+ if (pos->ai_family == AF_INET)
+ {
+ GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
+ saddrlens[i] = pos->ai_addrlen;
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
+ memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
+ ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
+ }
+ else
+ {
+ GNUNET_assert (pos->ai_family == AF_INET6);
+ GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
+ saddrlens[i] = pos->ai_addrlen;
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
+ memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
+ }
+ i++;
+ }
+ GNUNET_free (hostname);
+ freeaddrinfo (res);
+ resi = i;
+ }
+ else
+ {
+ /* will bind against everything, just set port */
+ if (disablev6)
+ {
+ /* V4-only */
+ resi = 1;
if (NULL != unixpath)
- resi++;
+ resi++;
+ i = 0;
saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
- i = 0;
if (NULL != unixpath)
- {
- add_unixpath (saddrs, saddrlens, unixpath);
- i++;
- }
- next = res;
- while (NULL != (pos = next))
- {
- next = pos->ai_next;
- if ((disablev6) && (pos->ai_family == AF_INET6))
- continue;
- if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
- continue; /* not TCP */
- if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
- continue; /* huh? */
-#if DEBUG_SERVICE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
- serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
+ {
+ add_unixpath (saddrs, saddrlens, unixpath);
+ i++;
+ }
+ saddrlens[i] = sizeof (struct sockaddr_in);
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
#endif
- if (pos->ai_family == AF_INET)
- {
- GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
- saddrlens[i] = pos->ai_addrlen;
- saddrs[i] = GNUNET_malloc (saddrlens[i]);
- memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
- ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
- }
- else
- {
- GNUNET_assert (pos->ai_family == AF_INET6);
- GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
- saddrlens[i] = pos->ai_addrlen;
- saddrs[i] = GNUNET_malloc (saddrlens[i]);
- memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
- ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
- }
- i++;
- }
- GNUNET_free (hostname);
- freeaddrinfo (res);
- resi = i;
+ ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
+ ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
- else
+ else
{
- /* will bind against everything, just set port */
- if (disablev6)
- {
- /* V4-only */
- resi = 1;
- if (NULL != unixpath)
- resi++;
- i = 0;
- saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
- saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
- if (NULL != unixpath)
- {
- add_unixpath (saddrs, saddrlens, unixpath);
- i++;
- }
- saddrlens[i] = sizeof (struct sockaddr_in);
- saddrs[i] = GNUNET_malloc (saddrlens[i]);
-#if HAVE_SOCKADDR_IN_SIN_LEN
- ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
-#endif
- ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
- ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
- }
- else
- {
- /* dual stack */
- resi = 2;
- if (NULL != unixpath)
- resi++;
- saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
- saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
- i = 0;
- if (NULL != unixpath)
- {
- add_unixpath (saddrs, saddrlens, unixpath);
- i++;
- }
- saddrlens[i] = sizeof (struct sockaddr_in6);
- saddrs[i] = GNUNET_malloc (saddrlens[i]);
+ /* dual stack */
+ resi = 2;
+ if (NULL != unixpath)
+ resi++;
+ saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
+ saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
+ i = 0;
+ if (NULL != unixpath)
+ {
+ add_unixpath (saddrs, saddrlens, unixpath);
+ i++;
+ }
+ saddrlens[i] = sizeof (struct sockaddr_in6);
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
#if HAVE_SOCKADDR_IN_SIN_LEN
- ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
#endif
- ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
- ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
- i++;
- saddrlens[i] = sizeof (struct sockaddr_in);
- saddrs[i] = GNUNET_malloc (saddrlens[i]);
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
+ i++;
+ saddrlens[i] = sizeof (struct sockaddr_in);
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
#if HAVE_SOCKADDR_IN_SIN_LEN
- ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
+ ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
#endif
- ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
- ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
- }
+ ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
+ ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
+ }
GNUNET_free_non_null (unixpath);
*addrs = saddrs;
*addr_lens = saddrlens;
int flags;
#endif
- if (GNUNET_CONFIGURATION_have_value
- (sctx->cfg, sctx->serviceName, "TIMEOUT"))
+ if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT"))
+ {
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName,
+ "TIMEOUT", &idleout))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName,
- "TIMEOUT", &idleout))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is invalid\n"),
- "TIMEOUT", sctx->serviceName);
- return GNUNET_SYSERR;
- }
- sctx->timeout = idleout;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Specified value for `%s' of service `%s' is invalid\n"),
+ "TIMEOUT", sctx->serviceName);
+ return GNUNET_SYSERR;
}
+ sctx->timeout = idleout;
+ }
else
sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
if (GNUNET_CONFIGURATION_have_value
(sctx->cfg, sctx->serviceName, "TOLERANT"))
+ {
+ if (GNUNET_SYSERR ==
+ (tolerant =
+ GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
+ "TOLERANT")))
{
- if (GNUNET_SYSERR ==
- (tolerant =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
- "TOLERANT")))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is invalid\n"),
- "TOLERANT", sctx->serviceName);
- return GNUNET_SYSERR;
- }
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Specified value for `%s' of service `%s' is invalid\n"),
+ "TOLERANT", sctx->serviceName);
+ return GNUNET_SYSERR;
}
+ }
else
tolerant = GNUNET_NO;
(NULL != (nfds = getenv ("LISTEN_FDS"))) &&
(1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
(cnt + 4 < FD_SETSIZE))
+ {
+ sctx->lsocks =
+ GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
+ while (0 < cnt--)
{
- sctx->lsocks =
- GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
- while (0 < cnt--)
- {
- flags = fcntl (3 + cnt, F_GETFD);
- if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
- (NULL ==
- (sctx->lsocks[cnt] =
- GNUNET_NETWORK_socket_box_native (3 + cnt))))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Could not access pre-bound socket %u, will try to bind myself\n"),
- (unsigned int) 3 + cnt);
- cnt++;
- while (sctx->lsocks[cnt] != NULL)
- GNUNET_break (0 ==
- GNUNET_NETWORK_socket_close (sctx->lsocks
- [cnt++]));
- GNUNET_free (sctx->lsocks);
- sctx->lsocks = NULL;
- break;
- }
- }
- unsetenv ("LISTEN_PID");
- unsetenv ("LISTEN_FDS");
+ flags = fcntl (3 + cnt, F_GETFD);
+ if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
+ (NULL ==
+ (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Could not access pre-bound socket %u, will try to bind myself\n"),
+ (unsigned int) 3 + cnt);
+ cnt++;
+ while (sctx->lsocks[cnt] != NULL)
+ GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++]));
+ GNUNET_free (sctx->lsocks);
+ sctx->lsocks = NULL;
+ break;
+ }
}
+ unsetenv ("LISTEN_PID");
+ unsetenv ("LISTEN_FDS");
+ }
#endif
if ((sctx->lsocks == NULL) &&
(GNUNET_SYSERR ==
GNUNET_SERVICE_get_server_addresses (sctx->serviceName, sctx->cfg,
- &sctx->addrs, &sctx->addrlens)))
+ &sctx->addrs, &sctx->addrlens)))
return GNUNET_SYSERR;
sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
sctx->match_uid =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
- "UNIX_MATCH_UID");
+ GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
+ "UNIX_MATCH_UID");
sctx->match_gid =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
- "UNIX_MATCH_GID");
+ GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
+ "UNIX_MATCH_GID");
process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName,
- "USERNAME", &un))
+ "USERNAME", &un))
return NULL;
return un;
}
int len;
if (NULL == (pif = get_pid_file_name (sctx)))
- return GNUNET_OK; /* no file desired */
+ return GNUNET_OK; /* no file desired */
user = get_user_name (sctx);
rdir = GNUNET_strdup (pif);
len = strlen (rdir);
len--;
rdir[len] = '\0';
if (0 != ACCESS (rdir, F_OK))
- {
- /* we get to create a directory -- and claim it
- * as ours! */
- GNUNET_DISK_directory_create (rdir);
- if ((user != NULL) && (0 < strlen (user)))
- GNUNET_DISK_file_change_owner (rdir, user);
- }
+ {
+ /* we get to create a directory -- and claim it
+ * as ours! */
+ GNUNET_DISK_directory_create (rdir);
+ if ((user != NULL) && (0 < strlen (user)))
+ GNUNET_DISK_file_change_owner (rdir, user);
+ }
if (0 != ACCESS (rdir, W_OK | X_OK))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
- GNUNET_free (rdir);
- GNUNET_free_non_null (user);
- GNUNET_free (pif);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
+ GNUNET_free (rdir);
+ GNUNET_free_non_null (user);
+ GNUNET_free (pif);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (rdir);
pidfd = FOPEN (pif, "w");
if (pidfd == NULL)
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
- GNUNET_free (pif);
- GNUNET_free_non_null (user);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
+ GNUNET_free (pif);
+ GNUNET_free_non_null (user);
+ return GNUNET_SYSERR;
+ }
if (0 > FPRINTF (pidfd, "%u", pid))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
GNUNET_break (0 == fclose (pidfd));
GNUNET_RESOLVER_connect (sctx->cfg);
if (sctx->lsocks != NULL)
sctx->server =
- GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
- sctx->timeout, sctx->require_found);
+ GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
+ sctx->timeout, sctx->require_found);
else
sctx->server =
- GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
- sctx->timeout, sctx->require_found);
+ GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
+ sctx->timeout, sctx->require_found);
if (sctx->server == NULL)
+ {
+ if (sctx->addrs != NULL)
{
- if (sctx->addrs != NULL)
- {
- i = 0;
- while (sctx->addrs[i] != NULL)
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Failed to start `%s' at `%s'\n"), sctx->serviceName,
- GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
- i++;
- }
- }
- sctx->ret = GNUNET_SYSERR;
- return;
+ i = 0;
+ while (sctx->addrs[i] != NULL)
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to start `%s' at `%s'\n"),
+ sctx->serviceName, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+ i++;
+ }
}
+ sctx->ret = GNUNET_SYSERR;
+ return;
+ }
if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN))
- {
- /* install a task that will kill the server
- * process if the scheduler ever gets a shutdown signal */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, sctx->server);
- }
+ {
+ /* install a task that will kill the server
+ * process if the scheduler ever gets a shutdown signal */
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+ sctx->server);
+ }
sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
i = 0;
sctx->my_handlers[i++].callback_cls = sctx;
GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
if (sctx->ready_confirm_fd != -1)
- {
- GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1));
- GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd));
- sctx->ready_confirm_fd = -1;
- write_pid_file (sctx, getpid ());
- }
+ {
+ GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1));
+ GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd));
+ sctx->ready_confirm_fd = -1;
+ write_pid_file (sctx, getpid ());
+ }
if (sctx->addrs != NULL)
+ {
+ i = 0;
+ while (sctx->addrs[i] != NULL)
{
- i = 0;
- while (sctx->addrs[i] != NULL)
- {
- LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
- sctx->serviceName, GNUNET_a2s (sctx->addrs[i],
- sctx->addrlens[i]));
- i++;
- }
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
+ sctx->serviceName, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+ i++;
}
+ }
sctx->task (sctx->task_cls, sctx->server, sctx->cfg);
}
int filedes[2];
if (0 != PIPE (filedes))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
+ return GNUNET_SYSERR;
+ }
pid = fork ();
if (pid < 0)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
+ return GNUNET_SYSERR;
+ }
if (pid != 0)
+ {
+ /* Parent */
+ char c;
+
+ GNUNET_break (0 == CLOSE (filedes[1]));
+ c = 'X';
+ if (1 != READ (filedes[0], &c, sizeof (char)))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
+ fflush (stdout);
+ switch (c)
{
- /* Parent */
- char c;
-
- GNUNET_break (0 == CLOSE (filedes[1]));
- c = 'X';
- if (1 != READ (filedes[0], &c, sizeof (char)))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
- fflush (stdout);
- switch (c)
- {
- case '.':
- exit (0);
- case 'I':
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to initialize\n"));
- break;
- case 'S':
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process could not initialize server function\n"));
- break;
- case 'X':
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to report status\n"));
- break;
- }
- exit (1); /* child reported error */
+ case '.':
+ exit (0);
+ case 'I':
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n"));
+ break;
+ case 'S':
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Service process could not initialize server function\n"));
+ break;
+ case 'X':
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Service process failed to report status\n"));
+ break;
}
+ exit (1); /* child reported error */
+ }
GNUNET_break (0 == CLOSE (0));
GNUNET_break (0 == CLOSE (1));
GNUNET_break (0 == CLOSE (filedes[0]));
return GNUNET_SYSERR;
/* set stdin/stdout to /dev/null */
if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
- (void) CLOSE (nullfd);
- return GNUNET_SYSERR;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ (void) CLOSE (nullfd);
+ return GNUNET_SYSERR;
+ }
(void) CLOSE (nullfd);
/* Detach from controlling terminal */
pid = setsid ();
char *user;
if (NULL == (user = get_user_name (sctx)))
- return GNUNET_OK; /* keep */
+ return GNUNET_OK; /* keep */
#ifndef MINGW
struct passwd *pws;
errno = 0;
pws = getpwnam (user);
if (pws == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"), user,
- errno == 0 ? _("No such user") : STRERROR (errno));
- GNUNET_free (user);
- return GNUNET_SYSERR;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Cannot obtain information about user `%s': %s\n"), user,
+ errno == 0 ? _("No such user") : STRERROR (errno));
+ GNUNET_free (user);
+ return GNUNET_SYSERR;
+ }
if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
#if HAVE_INITGROUPS
(0 != initgroups (user, pws->pw_gid)) ||
#endif
(0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
+ {
+ if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
+ (0 != setreuid (pws->pw_uid, pws->pw_uid)))
{
- if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
- (0 != setreuid (pws->pw_uid, pws->pw_uid)))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot change user/group to `%s': %s\n"), user,
- STRERROR (errno));
- GNUNET_free (user);
- return GNUNET_SYSERR;
- }
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot change user/group to `%s': %s\n"),
+ user, STRERROR (errno));
+ GNUNET_free (user);
+ return GNUNET_SYSERR;
}
+ }
#endif
GNUNET_free (user);
return GNUNET_OK;
char *pif = get_pid_file_name (sctx);
if (pif == NULL)
- return; /* no PID file */
+ return; /* no PID file */
if (0 != UNLINK (pif))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
GNUNET_free (pif);
*/
int
GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName,
- enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task,
- void *task_cls)
+ enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task,
+ void *task_cls)
{
#define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0)
goto shutdown;
#if DEBUG_SERVICE
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' runs with configuration from `%s'\n", serviceName,
- cfg_fn);
+ "Service `%s' runs with configuration from `%s'\n", serviceName, cfg_fn);
#endif
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing",
- "skew_offset", &skew_offset)
- && (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing",
- "skew_variance",
- &skew_variance)))
- {
- clock_offset = skew_offset - skew_variance;
- GNUNET_TIME_set_offset (clock_offset);
+ GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset",
+ &skew_offset) &&
+ (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing",
+ "skew_variance", &skew_variance)))
+ {
+ clock_offset = skew_offset - skew_variance;
+ GNUNET_TIME_set_offset (clock_offset);
#if DEBUG_SERVICE
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", clock_offset);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", clock_offset);
#endif
- }
+ }
/* actually run service */
err = 0;
GNUNET_SCHEDULER_run (&service_task, &sctx);
shutdown:
if (sctx.ready_confirm_fd != -1)
- {
- if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
- GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd));
- }
+ {
+ if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd));
+ }
GNUNET_CONFIGURATION_destroy (cfg);
i = 0;
*/
struct GNUNET_SERVICE_Context *
GNUNET_SERVICE_start (const char *serviceName,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
int i;
struct GNUNET_SERVICE_Context *sctx;
sctx = GNUNET_malloc (sizeof (struct GNUNET_SERVICE_Context));
- sctx->ready_confirm_fd = -1; /* no daemonizing */
+ sctx->ready_confirm_fd = -1; /* no daemonizing */
sctx->ret = GNUNET_OK;
sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
sctx->serviceName = serviceName;
/* setup subsystems */
if (GNUNET_OK != setup_service (sctx))
- {
- GNUNET_SERVICE_stop (sctx);
- return NULL;
- }
+ {
+ GNUNET_SERVICE_stop (sctx);
+ return NULL;
+ }
if (sctx->lsocks != NULL)
sctx->server =
- GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
- sctx->timeout, sctx->require_found);
+ GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
+ sctx->timeout, sctx->require_found);
else
sctx->server =
- GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
- sctx->timeout, sctx->require_found);
+ GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
+ sctx->timeout, sctx->require_found);
if (NULL == sctx->server)
- {
- GNUNET_SERVICE_stop (sctx);
- return NULL;
- }
+ {
+ GNUNET_SERVICE_stop (sctx);
+ return NULL;
+ }
sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
i = 0;
GNUNET_SERVER_destroy (sctx->server);
GNUNET_free_non_null (sctx->my_handlers);
if (sctx->addrs != NULL)
- {
- i = 0;
- while (sctx->addrs[i] != NULL)
- GNUNET_free (sctx->addrs[i++]);
- GNUNET_free (sctx->addrs);
- }
+ {
+ i = 0;
+ while (sctx->addrs[i] != NULL)
+ GNUNET_free (sctx->addrs[i++]);
+ GNUNET_free (sctx->addrs);
+ }
GNUNET_free_non_null (sctx->addrlens);
GNUNET_free_non_null (sctx->v4_denied);
GNUNET_free_non_null (sctx->v6_denied);
sig.sa_handler = (void *) handler;
sigemptyset (&sig.sa_mask);
#ifdef SA_INTERRUPT
- sig.sa_flags = SA_INTERRUPT; /* SunOS */
+ sig.sa_flags = SA_INTERRUPT; /* SunOS */
#else
sig.sa_flags = SA_RESTART;
#endif
if (signum == GNUNET_SIGCHLD)
w32_sigchld_handler = handler;
else
- {
- __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler);
+ {
+ __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler);
- if (sigret == SIG_ERR)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("signal (%d, %p) returned %d.\n"), signum, handler, sigret);
- }
+ if (sigret == SIG_ERR)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"),
+ signum, handler, sigret);
}
+ }
#endif
return ret;
}
* (or number of bytes that would have been written)
*/
size_t
-GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count,
- ...)
+GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...)
{
size_t needed;
size_t slen;
needed = 0;
va_start (ap, count);
while (count > 0)
- {
- s = va_arg (ap, const char *);
+ {
+ s = va_arg (ap, const char *);
- slen = strlen (s) + 1;
- if (buffer != NULL)
- {
- GNUNET_assert (needed + slen <= size);
- memcpy (&buffer[needed], s, slen);
- }
- needed += slen;
- count--;
+ slen = strlen (s) + 1;
+ if (buffer != NULL)
+ {
+ GNUNET_assert (needed + slen <= size);
+ memcpy (&buffer[needed], s, slen);
}
+ needed += slen;
+ count--;
+ }
va_end (ap);
return needed;
}
*/
unsigned int
GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
- unsigned int count, ...)
+ unsigned int count, ...)
{
unsigned int start;
unsigned int needed;
needed = 0;
va_start (ap, count);
while (count > 0)
+ {
+ r = va_arg (ap, const char **);
+
+ start = needed;
+ while ((needed < size) && (buffer[needed] != '\0'))
+ needed++;
+ if (needed == size)
{
- r = va_arg (ap, const char **);
-
- start = needed;
- while ((needed < size) && (buffer[needed] != '\0'))
- needed++;
- if (needed == size)
- {
- va_end (ap);
- return 0; /* error */
- }
- *r = &buffer[start];
- needed++; /* skip 0-termination */
- count--;
+ va_end (ap);
+ return 0; /* error */
}
+ *r = &buffer[start];
+ needed++; /* skip 0-termination */
+ count--;
+ }
va_end (ap);
return needed;
}
char *ret;
if (size > 5 * 1024)
+ {
+ size = size / 1024;
+ unit = "KiB";
+ if (size > 5 * 1024)
{
size = size / 1024;
- unit = "KiB";
+ unit = "MiB";
if (size > 5 * 1024)
- {
- size = size / 1024;
- unit = "MiB";
- if (size > 5 * 1024)
- {
- size = size / 1024;
- unit = "GiB";
- if (size > 5 * 1024)
- {
- size = size / 1024;
- unit = "TiB";
- }
- }
- }
+ {
+ size = size / 1024;
+ unit = "GiB";
+ if (size > 5 * 1024)
+ {
+ size = size / 1024;
+ unit = "TiB";
+ }
+ }
}
+ }
ret = GNUNET_malloc (32);
GNUNET_snprintf (ret, 32, "%llu %s", size, unit);
return ret;
*/
int
GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
- unsigned long long *size)
+ unsigned long long *size)
{
- struct {
- const char *name;
+ struct
+ {
+ const char *name;
unsigned long long value;
- } table[] = {
- { "B", 1 },
- { "KiB", 1024 },
- { "kB", 1000 },
- { "MiB", 1024 * 1024 },
- { "MB", 1000 * 1000 },
- { "GiB", 1024 * 1024 * 1024 },
- { "GB", 1000 * 1000 * 1000 },
- { "TiB", 1024LL * 1024LL * 1024LL * 1024LL },
- { "TB", 1000LL * 1000LL * 1000LL * 1024LL },
- { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL },
- { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
- { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
- { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL },
- { NULL, 0 }
+ } table[] =
+ {
+ {
+ "B", 1},
+ {
+ "KiB", 1024},
+ {
+ "kB", 1000},
+ {
+ "MiB", 1024 * 1024},
+ {
+ "MB", 1000 * 1000},
+ {
+ "GiB", 1024 * 1024 * 1024},
+ {
+ "GB", 1000 * 1000 * 1000},
+ {
+ "TiB", 1024LL * 1024LL * 1024LL * 1024LL},
+ {
+ "TB", 1000LL * 1000LL * 1000LL * 1024LL},
+ {
+ "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
+ {
+ "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
+ {
+ "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
+ {
+ "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
+ {
+ NULL, 0}
};
unsigned long long ret;
char *in;
in = GNUNET_strdup (fancy_size);
for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " "))
{
- i=0;
- while ( (table[i].name != NULL) &&
- (0 != strcasecmp (table[i].name, tok) ) )
+ i = 0;
+ while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok)))
i++;
if (table[i].name != NULL)
last *= table[i].value;
ret += last;
last = 0;
if (1 != sscanf (tok, "%llu", &last))
- return GNUNET_SYSERR; /* expected number */
- }
+ return GNUNET_SYSERR; /* expected number */
+ }
}
ret += last;
*size = ret;
*/
int
GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
- struct GNUNET_TIME_Relative *rtime)
+ struct GNUNET_TIME_Relative *rtime)
{
- struct {
- const char *name;
+ struct
+ {
+ const char *name;
unsigned long long value;
- } table[] = {
- { "ms", 1 },
- { "s", 1000 },
- { "\"", 1000 },
- { "min", 60 * 1000 },
- { "minutes", 60 * 1000 },
- { "'", 60 * 1000 },
- { "h", 60 * 60 * 1000 },
- { "d", 24 * 60 * 60 * 1000 },
- { "a", 31557600 /* year */ },
- { NULL, 0 }
+ } table[] =
+ {
+ {
+ "ms", 1},
+ {
+ "s", 1000},
+ {
+ "\"", 1000},
+ {
+ "min", 60 * 1000},
+ {
+ "minutes", 60 * 1000},
+ {
+ "'", 60 * 1000},
+ {
+ "h", 60 * 60 * 1000},
+ {
+ "d", 24 * 60 * 60 * 1000},
+ {
+ "a", 31557600 /* year */ },
+ {
+ NULL, 0}
};
unsigned long long ret;
char *in;
const char *tok;
unsigned long long last;
unsigned int i;
-
+
if ((0 == strcasecmp (fancy_size, "infinity")) ||
(0 == strcasecmp (fancy_size, "forever")))
- {
- *rtime = GNUNET_TIME_UNIT_FOREVER_REL;
- return GNUNET_OK;
- }
+ {
+ *rtime = GNUNET_TIME_UNIT_FOREVER_REL;
+ return GNUNET_OK;
+ }
ret = 0;
last = 0;
in = GNUNET_strdup (fancy_size);
for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " "))
{
- i=0;
- while ( (table[i].name != NULL) &&
- (0 != strcasecmp (table[i].name, tok) ) )
+ i = 0;
+ while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok)))
i++;
if (table[i].name != NULL)
last *= table[i].value;
ret += last;
last = 0;
if (1 != sscanf (tok, "%llu", &last))
- return GNUNET_SYSERR; /* expected number */
- }
+ return GNUNET_SYSERR; /* expected number */
+ }
}
ret += last;
rtime->rel_value = (uint64_t) ret;
cd = iconv_open ("UTF-8", charset);
if (cd == (iconv_t) - 1)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv_open");
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Character set requested was `%s'\n"), charset);
- ret = GNUNET_malloc (len + 1);
- memcpy (ret, input, len);
- ret[len] = '\0';
- return ret;
- }
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv_open");
+ LOG (GNUNET_ERROR_TYPE_WARNING, _("Character set requested was `%s'\n"),
+ charset);
+ ret = GNUNET_malloc (len + 1);
+ memcpy (ret, input, len);
+ ret[len] = '\0';
+ return ret;
+ }
tmpSize = 3 * len + 4;
tmp = GNUNET_malloc (tmpSize);
itmp = tmp;
finSize = tmpSize;
if (iconv (cd,
#if FREEBSD || DARWIN || WINDOWS
- (const char **) &input,
+ (const char **) &input,
#else
- (char **) &input,
+ (char **) &input,
#endif
- &len, &itmp, &finSize) == SIZE_MAX)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv");
- iconv_close (cd);
- GNUNET_free (tmp);
- ret = GNUNET_malloc (len + 1);
- memcpy (ret, input, len);
- ret[len] = '\0';
- return ret;
- }
+ &len, &itmp, &finSize) == SIZE_MAX)
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv");
+ iconv_close (cd);
+ GNUNET_free (tmp);
+ ret = GNUNET_malloc (len + 1);
+ memcpy (ret, input, len);
+ ret[len] = '\0';
+ return ret;
+ }
ret = GNUNET_malloc (tmpSize - finSize + 1);
memcpy (ret, tmp, tmpSize - finSize);
ret[tmpSize - finSize] = '\0';
/* absolute path, just copy */
return GNUNET_strdup (fil);
if (fil[0] == '~')
+ {
+ fm = getenv ("HOME");
+ if (fm == NULL)
{
- fm = getenv ("HOME");
- if (fm == NULL)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Failed to expand `$HOME': environment variable `HOME' not set"));
- return NULL;
- }
- fm = GNUNET_strdup (fm);
- /* do not copy '~' */
- fil_ptr = fil + 1;
-
- /* skip over dir seperator to be consistent */
- if (fil_ptr[0] == DIR_SEPARATOR)
- fil_ptr++;
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to expand `$HOME': environment variable `HOME' not set"));
+ return NULL;
}
+ fm = GNUNET_strdup (fm);
+ /* do not copy '~' */
+ fil_ptr = fil + 1;
+
+ /* skip over dir seperator to be consistent */
+ if (fil_ptr[0] == DIR_SEPARATOR)
+ fil_ptr++;
+ }
else
+ {
+ /* relative path */
+ fil_ptr = fil;
+ len = 512;
+ fm = NULL;
+ while (1)
{
- /* relative path */
- fil_ptr = fil;
- len = 512;
- fm = NULL;
- while (1)
- {
- buffer = GNUNET_malloc (len);
- if (getcwd (buffer, len) != NULL)
- {
- fm = buffer;
- break;
- }
- if ((errno == ERANGE) && (len < 1024 * 1024 * 4))
- {
- len *= 2;
- GNUNET_free (buffer);
- continue;
- }
- GNUNET_free (buffer);
- break;
- }
- if (fm == NULL)
- {
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd");
- buffer = getenv ("PWD"); /* alternative */
- if (buffer != NULL)
- fm = GNUNET_strdup (buffer);
- }
- if (fm == NULL)
- fm = GNUNET_strdup ("./"); /* give up */
+ buffer = GNUNET_malloc (len);
+ if (getcwd (buffer, len) != NULL)
+ {
+ fm = buffer;
+ break;
+ }
+ if ((errno == ERANGE) && (len < 1024 * 1024 * 4))
+ {
+ len *= 2;
+ GNUNET_free (buffer);
+ continue;
+ }
+ GNUNET_free (buffer);
+ break;
+ }
+ if (fm == NULL)
+ {
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd");
+ buffer = getenv ("PWD"); /* alternative */
+ if (buffer != NULL)
+ fm = GNUNET_strdup (buffer);
}
+ if (fm == NULL)
+ fm = GNUNET_strdup ("./"); /* give up */
+ }
n = strlen (fm) + 1 + strlen (fil_ptr) + 1;
buffer = GNUNET_malloc (n);
GNUNET_snprintf (buffer, n, "%s%s%s", fm,
- (fm[strlen (fm) - 1] ==
- DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr);
+ (fm[strlen (fm) - 1] ==
+ DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr);
GNUNET_free (fm);
return buffer;
#else
fn = GNUNET_malloc (MAX_PATH + 1);
if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS)
- {
- SetErrnoFromWinError (lRet);
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path");
- return NULL;
- }
+ {
+ SetErrnoFromWinError (lRet);
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path");
+ return NULL;
+ }
/* is the path relative? */
if ((strncmp (fn + 1, ":\\", 2) != 0) && (strncmp (fn, "\\\\", 2) != 0))
+ {
+ char szCurDir[MAX_PATH + 1];
+
+ lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir);
+ if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
{
- char szCurDir[MAX_PATH + 1];
-
- lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir);
- if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
- {
- SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
- return NULL;
- }
- buffer = GNUNET_malloc (MAX_PATH + 1);
- GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn);
- GNUNET_free (fn);
- fn = buffer;
+ SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
+ return NULL;
}
+ buffer = GNUNET_malloc (MAX_PATH + 1);
+ GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn);
+ GNUNET_free (fn);
+ fn = buffer;
+ }
return fn;
#endif
if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
return GNUNET_strdup (_("eternity"));
if (dval > 5 * 1000)
+ {
+ dval = dval / 1000;
+ unit = _( /* time unit */ "s");
+ if (dval > 5 * 60)
{
- dval = dval / 1000;
- unit = _( /* time unit */ "s");
+ dval = dval / 60;
+ unit = _( /* time unit */ "m");
if (dval > 5 * 60)
- {
- dval = dval / 60;
- unit = _( /* time unit */ "m");
- if (dval > 5 * 60)
- {
- dval = dval / 60;
- unit = _( /* time unit */ "h");
- if (dval > 5 * 24)
- {
- dval = dval / 24;
- unit = _( /* time unit */ " days");
- }
- }
- }
+ {
+ dval = dval / 60;
+ unit = _( /* time unit */ "h");
+ if (dval > 5 * 24)
+ {
+ dval = dval / 24;
+ unit = _( /* time unit */ " days");
+ }
+ }
}
+ }
GNUNET_asprintf (&ret, "%llu %s", dval, unit);
return ret;
}
GNUNET_assert (NULL != fileR);
readResultString = NULL;
GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
+ GNUNET_BIO_read_string (fileR, "Read string error",
+ &readResultString, 200));
GNUNET_assert (NULL != readResultString);
GNUNET_assert (0 == strcmp (TESTSTRING, readResultString));
GNUNET_free (readResultString);
GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
+ GNUNET_BIO_read_meta_data (fileR, "Read meta error",
+ &metaDataR));
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_meta_data_test_equal (metaDataR,
- metaDataW));
+ GNUNET_CONTAINER_meta_data_test_equal (metaDataR, metaDataW));
GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum));
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_CONTAINER_meta_data_destroy (metaDataW);
fileR = GNUNET_BIO_read_open (fileName);
GNUNET_assert (NULL != fileR);
GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
+ GNUNET_BIO_read_string (fileR, "Read string error",
+ &readResultString, 200));
GNUNET_assert (NULL == readResultString);
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
GNUNET_assert (NULL != fileR);
readResultString = NULL;
GNUNET_assert (GNUNET_OK ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
+ GNUNET_BIO_read_string (fileR, "Read string error",
+ &readResultString, 200));
GNUNET_free (readResultString);
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
GNUNET_assert (NULL != fileR);
readResultString = NULL;
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 1));
+ GNUNET_BIO_read_string (fileR, "Read string error",
+ &readResultString, 1));
GNUNET_assert (NULL == readResultString);
msg = NULL;
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_assert (NULL != fileR);
metaDataR = NULL;
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
+ GNUNET_BIO_read_meta_data (fileR, "Read meta error",
+ &metaDataR));
msg = NULL;
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_free (msg);
fileR = GNUNET_BIO_read_open ("/dev");
GNUNET_assert (NULL != fileR);
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read (fileR, "Read error", readResult,
- sizeof (readResult)));
+ GNUNET_BIO_read (fileR, "Read error", readResult,
+ sizeof (readResult)));
msg = NULL;
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_free (msg);
fileR = GNUNET_BIO_read_open ("/dev/null");
GNUNET_assert (NULL != fileR);
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read (fileR, "Read error", readResult,
- sizeof (readResult)));
+ GNUNET_BIO_read (fileR, "Read error", readResult,
+ sizeof (readResult)));
readResultString = NULL;
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResultString, 200));
+ GNUNET_BIO_read_string (fileR, "Read string error",
+ &readResultString, 200));
GNUNET_assert (NULL == readResultString);
GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileR, &testNum));
metaDataR = NULL;
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
+ GNUNET_BIO_read_meta_data (fileR, "Read meta error",
+ &metaDataR));
msg = NULL;
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_free (msg);
fileR = GNUNET_BIO_read_open (fileName);
GNUNET_assert (NULL != fileR);
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_string (fileR, "Read string error",
- &readResult, 200));
+ GNUNET_BIO_read_string (fileR, "Read string error",
+ &readResult, 200));
msg = NULL;
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_free (msg);
GNUNET_assert (NULL != fileR);
metaDataR = NULL;
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
+ GNUNET_BIO_read_meta_data (fileR, "Read meta error",
+ &metaDataR));
GNUNET_assert (NULL == metaDataR);
msg = NULL;
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_assert (NULL != fileR);
metaDataR = NULL;
GNUNET_assert (GNUNET_SYSERR ==
- GNUNET_BIO_read_meta_data (fileR, "Read meta error",
- &metaDataR));
+ GNUNET_BIO_read_meta_data (fileR, "Read meta error",
+ &metaDataR));
msg = NULL;
GNUNET_BIO_read_close (fileR, &msg);
GNUNET_free (msg);
*/
static void
echo_cb (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
struct CopyContext *cc;
struct GNUNET_MessageHeader *cpy;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving message from client, bouncing back\n");
- GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
- ntohs (message->size));
+ "Receiving message from client, bouncing back\n");
+ GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size));
cc = GNUNET_malloc (sizeof (struct CopyContext));
cc->client = client;
cpy = GNUNET_malloc (ntohs (message->size));
memcpy (cpy, message, ntohs (message->size));
cc->cpy = cpy;
GNUNET_assert (NULL !=
- GNUNET_SERVER_notify_transmit_ready (client,
- ntohs (message->size),
- GNUNET_TIME_UNIT_SECONDS,
- ©_msg, cc));
+ GNUNET_SERVER_notify_transmit_ready (client,
+ ntohs (message->size),
+ GNUNET_TIME_UNIT_SECONDS,
+ ©_msg, cc));
}
int *ok = cls;
struct GNUNET_MessageHeader msg;
- GNUNET_assert (got != NULL); /* timeout */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving bounce, checking content\n");
+ GNUNET_assert (got != NULL); /* timeout */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving bounce, checking content\n");
msg.type = htons (MY_TYPE);
msg.size = htons (sizeof (struct GNUNET_MessageHeader));
- GNUNET_assert (0 ==
- memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader)));
+ GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader)));
GNUNET_CLIENT_disconnect (client, GNUNET_YES);
client = NULL;
GNUNET_SERVER_destroy (server);
sa.sin_family = AF_INET;
sa.sin_port = htons (PORT);
server =
- GNUNET_SERVER_create (NULL, NULL, sap, slens,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO);
+ GNUNET_SERVER_create (NULL, NULL, sap, slens,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO);
GNUNET_assert (server != NULL);
handlers[0].callback_cls = cls;
handlers[1].callback_cls = cls;
client = GNUNET_CLIENT_connect (MYNAME, cfg);
GNUNET_assert (client != NULL);
GNUNET_assert (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct
- GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_SECONDS,
- GNUNET_NO, &make_msg,
- NULL));
+ GNUNET_CLIENT_notify_transmit_ready (client,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_NO, &make_msg,
+ NULL));
GNUNET_CLIENT_receive (client, &recv_bounce, cls,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 10000));
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 10000));
}
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT);
- GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME",
- "localhost");
+ GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost");
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
ok = 1;
GNUNET_SCHEDULER_run (&task, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_log_setup ("test_client",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check ();
return ret;
unsigned int ui;
/* GNUNET_malloc/GNUNET_free test */
- k = 352; /* random start value */
+ k = 352; /* random start value */
for (i = 1; i < MAX_TESTVAL; i++)
- {
- ptrs[i] = GNUNET_malloc (i);
- for (j = 0; j < i; j++)
- ptrs[i][j] = k++;
- }
+ {
+ ptrs[i] = GNUNET_malloc (i);
+ for (j = 0; j < i; j++)
+ ptrs[i][j] = k++;
+ }
for (i = MAX_TESTVAL - 1; i >= 1; i--)
- {
- for (j = i - 1; j >= 0; j--)
- if (ptrs[i][j] != (char) --k)
- return 1;
- GNUNET_free (ptrs[i]);
- }
+ {
+ for (j = i - 1; j >= 0; j--)
+ if (ptrs[i][j] != (char) --k)
+ return 1;
+ GNUNET_free (ptrs[i]);
+ }
/* GNUNET_free_non_null test */
GNUNET_free_non_null (NULL);
static void
my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
- const char *date, const char *msg)
+ const char *date, const char *msg)
{
unsigned int *c = ctx;
unsigned int logs = 0;
if (0 != setenv ("GNUNET_FORCE_LOG", "", 1))
- fprintf (stderr,
- "Failed to setenv: %s\n",
- strerror (errno));
+ fprintf (stderr, "Failed to setenv: %s\n", strerror (errno));
GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null");
GNUNET_logger_add (&my_log, &logs);
GNUNET_logger_add (&my_log, &logs);
/* the last 6 calls should be merged (repated bulk messages!) */
GNUNET_logger_remove (&my_log, &logs);
if (logs != 4)
- {
- fprintf (stdout, "Expected 4 log calls, got %u\n", logs);
- failureCount++;
- }
+ {
+ fprintf (stdout, "Expected 4 log calls, got %u\n", logs);
+ failureCount++;
+ }
GNUNET_break (0 ==
- strcmp (_("ERROR"),
- GNUNET_error_type_to_string
- (GNUNET_ERROR_TYPE_ERROR)));
+ strcmp (_("ERROR"),
+ GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_ERROR)));
GNUNET_break (0 ==
- strcmp (_("WARNING"),
- GNUNET_error_type_to_string
- (GNUNET_ERROR_TYPE_WARNING)));
+ strcmp (_("WARNING"),
+ GNUNET_error_type_to_string
+ (GNUNET_ERROR_TYPE_WARNING)));
GNUNET_break (0 ==
- strcmp (_("INFO"),
- GNUNET_error_type_to_string
- (GNUNET_ERROR_TYPE_INFO)));
+ strcmp (_("INFO"),
+ GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_INFO)));
GNUNET_break (0 ==
- strcmp (_("DEBUG"),
- GNUNET_error_type_to_string
- (GNUNET_ERROR_TYPE_DEBUG)));
+ strcmp (_("DEBUG"),
+ GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG)));
GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null");
logs = 0;
GNUNET_logger_add (&my_log, &logs);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n");
GNUNET_logger_remove (&my_log, &logs);
if (logs != 1)
- {
- fprintf (stdout, "Expected 1 log call, got %u\n", logs);
- failureCount++;
- }
+ {
+ fprintf (stdout, "Expected 1 log call, got %u\n", logs);
+ failureCount++;
+ }
if (failureCount != 0)
- {
- fprintf (stdout, "%u TESTS FAILED!\n", failureCount);
- return -1;
- }
+ {
+ fprintf (stdout, "%u TESTS FAILED!\n", failureCount);
+ return -1;
+ }
return 0;
-} /* end of main */
+} /* end of main */
/* end of test_common_logging.c */
static void
my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
- const char *date, const char *msg)
+ const char *date, const char *msg)
{
if (strncmp ("test-common-logging-dummy", component, 25) != 0)
return;
pr2 (GNUNET_ERROR_TYPE_INFO, "INFO");
pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
return 0;
-} /* end of main */
+} /* end of main */
/* end of test_common_logging_dummy.c */
static GNUNET_SCHEDULER_TaskIdentifier die_task;
-static void runone ();
+static void
+runone ();
static void
end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase,
- ok);
+ ok);
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ }
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_close (proc);
proc = NULL;
GNUNET_DISK_pipe_close (pipe_stdout);
if (ok == 1)
+ {
+ if (phase < 9)
{
- if (phase < 9)
- {
- phase += 1;
- runone ();
- }
- else
- ok = 0;
+ phase += 1;
+ runone ();
}
+ else
+ ok = 0;
+ }
else
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failing\n");
}
static char *
read_output_line (int phase_from1, int phase_to1, int phase_from2,
- int phase_to2, char c, char *expect_level,
- long delay_morethan, long delay_lessthan, int phase,
- char *p, int *len, long *delay, char level[8])
+ int phase_to2, char c, char *expect_level,
+ long delay_morethan, long delay_lessthan, int phase, char *p,
+ int *len, long *delay, char level[8])
{
char *r = p;
char t[7];
int i, j, stop = 0;
+
j = 0;
int stage = 0;
+
if (!(phase >= phase_from1 && phase <= phase_to1) &&
!(phase >= phase_from2 && phase <= phase_to2))
return p;
#if 0
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p);
+ "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p);
#endif
for (i = 0; i < *len && !stop; i++)
+ {
+ switch (stage)
{
- switch (stage)
- {
- case 0: /* read first char */
- if (r[i] != c)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected '%c', but got '%c'\n", c, r[i]);
- GNUNET_break (0);
- return NULL;
- }
- stage += 1;
- break;
- case 1: /* read at most 7 char-long error level string, finished by ' ' */
- if (r[i] == ' ')
- {
- level[j] = '\0';
- stage += 1;
- j = 0;
- }
- else if (i == 8)
- {
- GNUNET_break (0);
- ok = 2;
- return NULL;
- }
- else
- level[j++] = r[i];
- break;
- case 2: /* read the delay, finished by '\n' */
- t[j++] = r[i];
+ case 0: /* read first char */
+ if (r[i] != c)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected '%c', but got '%c'\n", c,
+ r[i]);
+ GNUNET_break (0);
+ return NULL;
+ }
+ stage += 1;
+ break;
+ case 1: /* read at most 7 char-long error level string, finished by ' ' */
+ if (r[i] == ' ')
+ {
+ level[j] = '\0';
+ stage += 1;
+ j = 0;
+ }
+ else if (i == 8)
+ {
+ GNUNET_break (0);
+ ok = 2;
+ return NULL;
+ }
+ else
+ level[j++] = r[i];
+ break;
+ case 2: /* read the delay, finished by '\n' */
+ t[j++] = r[i];
#if WINDOWS
- if (r[i] == '\r' && r[i + 1] == '\n')
- {
- i += 1;
- t[j - 1] = '\0';
- *delay = strtol (t, NULL, 10);
- stop = 1;
- }
+ if (r[i] == '\r' && r[i + 1] == '\n')
+ {
+ i += 1;
+ t[j - 1] = '\0';
+ *delay = strtol (t, NULL, 10);
+ stop = 1;
+ }
#else
- if (r[i] == '\n')
- {
- t[j - 1] = '\0';
- *delay = strtol (t, NULL, 10);
- stop = 1;
- }
+ if (r[i] == '\n')
+ {
+ t[j - 1] = '\0';
+ *delay = strtol (t, NULL, 10);
+ stop = 1;
+ }
#endif
- break;
- }
+ break;
}
- if (!stop || strcmp (expect_level, level) != 0 || *delay < 0
- || *delay > 1000
- || (!((*delay < delay_lessthan) || !(*delay > delay_morethan))
- && c != '1' && c != '2'))
+ }
+ if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 || *delay > 1000
+ || (!((*delay < delay_lessthan) || !(*delay > delay_morethan)) && c != '1'
+ && c != '2'))
return NULL;
*len = *len - i;
return &r[i];
long delays[8];
int rd;
- rd =
- GNUNET_DISK_file_read (stdout_read_handle, buf_ptr, sizeof (buf) - bytes);
+ rd = GNUNET_DISK_file_read (stdout_read_handle, buf_ptr,
+ sizeof (buf) - bytes);
if (rd > 0)
- {
- buf_ptr += rd;
- bytes += rd;
+ {
+ buf_ptr += rd;
+ bytes += rd;
#if VERBOSE
- fprintf (stderr, "got %d bytes, reading more\n", rd);
+ fprintf (stderr, "got %d bytes, reading more\n", rd);
#endif
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
- (void *) stdout_read_handle);
- return;
- }
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdout_read_handle, &read_call,
+ (void *) stdout_read_handle);
+ return;
+ }
#if VERBOSE
fprintf (stderr, "bytes is %d:%s\n", bytes, buf);
* | 9 * * * *
*/
char *p = buf;
+
if (bytes == 20 * 16 ||
!(p =
- read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
- &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p,
- &bytes, &delays[0], level))
- || !(p =
- read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p,
- &bytes, &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p,
- &bytes, &delays[1], level))
- || !(p =
- read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
- &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p,
- &bytes, &delays[2], level))
- || !(p =
- read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p,
- &bytes, &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p,
- &bytes, &delays[3], level))
- || !(p =
- read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p,
- &bytes, &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p,
- &bytes, &delays[4], level))
- || !(p =
- read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p,
- &bytes, &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p,
- &bytes, &delays[5], level))
- || !(p =
- read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p,
- &bytes, &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p,
- &bytes, &delays[6], level))
- || !(p =
- read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p,
- &bytes, &delay, level))
- || !(p =
- read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p,
- &bytes, &delays[7], level)))
- {
- if (bytes == 20 * 16)
- fprintf (stderr, "Ran out of buffer space!\n");
- GNUNET_break (0);
- ok = 2;
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_task, NULL);
- return;
- }
+ read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, &bytes,
+ &delays[0], level)) ||
+ !(p =
+ read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p,
+ &bytes, &delays[1], level)) ||
+ !(p =
+ read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, &bytes,
+ &delays[2], level)) ||
+ !(p =
+ read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, &bytes,
+ &delays[3], level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, &bytes,
+ &delays[4], level)) ||
+ !(p =
+ read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p,
+ &bytes, &delays[5], level)) ||
+ !(p =
+ read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, &bytes,
+ &delays[6], level)) ||
+ !(p =
+ read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
+ &delay, level)) ||
+ !(p =
+ read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, &bytes,
+ &delays[7], level)))
+ {
+ if (bytes == 20 * 16)
+ fprintf (stderr, "Ran out of buffer space!\n");
+ GNUNET_break (0);
+ ok = 2;
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_task, NULL);
+ return;
+ }
GNUNET_SCHEDULER_cancel (die_task);
GNUNET_SCHEDULER_add_now (&end_task, NULL);
pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (pipe_stdout == NULL)
- {
- GNUNET_break (0);
- ok = 2;
- return;
- }
+ {
+ GNUNET_break (0);
+ ok = 2;
+ return;
+ }
putenv ("GNUNET_LOG=");
putenv ("GNUNET_FORCE_LOG=");
switch (phase)
- {
- case 0:
- putenv ("GNUNET_LOG=;;;;ERROR");
- break;
- case 1:
- putenv ("GNUNET_LOG=;;;;WARNING");
- break;
- case 2:
- putenv ("GNUNET_LOG=;;;;INFO");
- break;
- case 3:
- putenv ("GNUNET_LOG=;;;;DEBUG");
- break;
- case 4:
- putenv ("GNUNET_FORCE_LOG=;;;;ERROR");
- break;
- case 5:
- putenv ("GNUNET_FORCE_LOG=;;;;WARNING");
- break;
- case 6:
- putenv ("GNUNET_FORCE_LOG=;;;;INFO");
- break;
- case 7:
- putenv ("GNUNET_FORCE_LOG=;;;;DEBUG");
- break;
- case 8:
- putenv ("GNUNET_LOG=blah;;;;ERROR");
- break;
- case 9:
- putenv ("GNUNET_FORCE_LOG=blah;;;;ERROR");
- break;
- }
+ {
+ case 0:
+ putenv ("GNUNET_LOG=;;;;ERROR");
+ break;
+ case 1:
+ putenv ("GNUNET_LOG=;;;;WARNING");
+ break;
+ case 2:
+ putenv ("GNUNET_LOG=;;;;INFO");
+ break;
+ case 3:
+ putenv ("GNUNET_LOG=;;;;DEBUG");
+ break;
+ case 4:
+ putenv ("GNUNET_FORCE_LOG=;;;;ERROR");
+ break;
+ case 5:
+ putenv ("GNUNET_FORCE_LOG=;;;;WARNING");
+ break;
+ case 6:
+ putenv ("GNUNET_FORCE_LOG=;;;;INFO");
+ break;
+ case 7:
+ putenv ("GNUNET_FORCE_LOG=;;;;DEBUG");
+ break;
+ case 8:
+ putenv ("GNUNET_LOG=blah;;;;ERROR");
+ break;
+ case 9:
+ putenv ("GNUNET_FORCE_LOG=blah;;;;ERROR");
+ break;
+ }
proc =
- GNUNET_OS_start_process (NULL, pipe_stdout,
- "./test_common_logging_dummy",
- "test_common_logging_dummy", NULL);
+ GNUNET_OS_start_process (NULL, pipe_stdout, "./test_common_logging_dummy",
+ "test_common_logging_dummy", NULL);
putenv ("GNUNET_FORCE_LOG=");
putenv ("GNUNET_LOG=");
GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
stdout_read_handle =
- GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ);
die_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10), &end_task,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 10), &end_task,
+ NULL);
bytes = 0;
buf_ptr = buf;
memset (&buf, 0, sizeof (buf));
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
- (void *) stdout_read_handle);
+ stdout_read_handle, &read_call,
+ (void *) stdout_read_handle);
}
static void
GNUNET_log_setup ("test-common-logging-runtime-loglevels",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret = check ();
return ret;
REMOVE_ENTRY,
COMPARE
#if DEBUG
- , PRINT
+ , PRINT
#endif
};
*/
static void
diffsCallBack (void *cls, const char *section, const char *option,
- const char *value)
+ const char *value)
{
struct DiffsCBData *cbData = cls;
int cbOption = cbData->callBackOption;
switch (cbOption)
+ {
+ case EDIT_SECTION:
+ if (NULL == cbData->section)
+ cbData->section = section;
+ if (strcmp (cbData->section, section) == 0)
{
- case EDIT_SECTION:
- if (NULL == cbData->section)
- cbData->section = section;
- if (strcmp (cbData->section, section) == 0)
- {
- GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
- "new-value");
- GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
- option, "new-value");
- }
- break;
- case EDIT_ALL:
GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
- "new-value");
+ "new-value");
+ GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
+ "new-value");
+ }
+ break;
+ case EDIT_ALL:
+ GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
+ "new-value");
+ GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
+ "new-value");
+ break;
+ case ADD_NEW_ENTRY:
+ {
+ static int hit = 0;
+
+ if (hit == 0)
+ {
+ hit = 1;
+ GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key",
+ "new-value");
GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
- option, "new-value");
- break;
- case ADD_NEW_ENTRY:
- {
- static int hit = 0;
-
- if (hit == 0)
- {
- hit = 1;
- GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section,
- "new-key", "new-value");
- GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
- "new-key", "new-value");
- }
- break;
- }
- case COMPARE:
- {
- int ret;
- char *diffValue;
-
- diffValue = NULL;
- ret =
- GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section,
- option, &diffValue);
- if (NULL != diffValue)
- {
- if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0)
- cbData->status = 1;
- }
- else
- cbData->status = 1;
- GNUNET_free_non_null (diffValue);
- break;
- }
+ "new-key", "new-value");
+ }
+ break;
+ }
+ case COMPARE:
+ {
+ int ret;
+ char *diffValue;
+
+ diffValue = NULL;
+ ret =
+ GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section,
+ option, &diffValue);
+ if (NULL != diffValue)
+ {
+ if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0)
+ cbData->status = 1;
+ }
+ else
+ cbData->status = 1;
+ GNUNET_free_non_null (diffValue);
+ break;
+ }
#if 0
- case PRINT:
- if (NULL == cbData->section)
- {
- cbData->section = section;
- printf ("\nSection: %s\n", section);
- }
- else if (strcmp (cbData->section, section) != 0)
- {
- cbData->section = section;
- printf ("\nSection: %s\n", section);
- }
- printf ("%s = %s\n", option, value);
-#endif
- default:
- break;
+ case PRINT:
+ if (NULL == cbData->section)
+ {
+ cbData->section = section;
+ printf ("\nSection: %s\n", section);
}
+ else if (strcmp (cbData->section, section) != 0)
+ {
+ cbData->section = section;
+ printf ("\nSection: %s\n", section);
+ }
+ printf ("%s = %s\n", option, value);
+#endif
+ default:
+ break;
+ }
}
diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create ();
switch (option)
+ {
+ case EDIT_SECTION:
+ case EDIT_ALL:
+ case ADD_NEW_ENTRY:
+ diffsCB.callBackOption = option;
+ diffsCB.cfg = cfg;
+ GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB);
+ break;
+ case EDIT_NOTHING:
+ /* Do nothing */
+ break;
+ case ADD_NEW_SECTION:
+ {
+ int i;
+ char *key;
+
+ for (i = 0; i < 5; i++)
{
- case EDIT_SECTION:
- case EDIT_ALL:
- case ADD_NEW_ENTRY:
- diffsCB.callBackOption = option;
- diffsCB.cfg = cfg;
- GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB);
- break;
- case EDIT_NOTHING:
- /* Do nothing */
- break;
- case ADD_NEW_SECTION:
- {
- int i;
- char *key;
-
- for (i = 0; i < 5; i++)
- {
- GNUNET_asprintf (&key, "key%d", i);
- GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
- "new-value");
- GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs,
- "new-section", key,
- "new-value");
- GNUNET_free (key);
- }
- break;
- }
- case REMOVE_SECTION:
- break;
- case REMOVE_ENTRY:
- break;
- default:
- break;
+ GNUNET_asprintf (&key, "key%d", i);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
+ "new-value");
+ GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section",
+ key, "new-value");
+ GNUNET_free (key);
}
+ break;
+ }
+ case REMOVE_SECTION:
+ break;
+ case REMOVE_ENTRY:
+ break;
+ default:
+ break;
+ }
return diffsCB.cfgDiffs;
}
/* Modify configuration and save it */
cfgDiffs = editConfiguration (cfg, option);
- diffsFileName =
- GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf");
+ diffsFileName = GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf");
if (diffsFileName == NULL)
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_CONFIGURATION_destroy (cfgDiffs);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_CONFIGURATION_destroy (cfgDiffs);
+ return 1;
+ }
GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName);
GNUNET_CONFIGURATION_destroy (cfg);
/* Compare the dumped configuration with modifications done */
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_parse (cfg, diffsFileName));
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, diffsFileName));
remove (diffsFileName);
cbData.callBackOption = COMPARE;
cbData.cfgDiffs = cfgDiffs;
GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
if (1 == (ret = cbData.status))
- {
- fprintf (stderr,
- "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
- goto housekeeping;
- }
+ {
+ fprintf (stderr,
+ "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
+ goto housekeeping;
+ }
cbData.cfgDiffs = cfg;
GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData);
if ((ret = cbData.status) == 1)
fprintf (stderr,
- "Incorrect Configuration Diffs: Data may be missing in diffs\n");
+ "Incorrect Configuration Diffs: Data may be missing in diffs\n");
housekeeping:
#if 0
char *c;
unsigned long long l;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c))
return 1;
if (0 != strcmp ("b", c))
- {
- fprintf (stderr, "Got `%s'\n", c);
- GNUNET_free (c);
- return 2;
- }
+ {
+ fprintf (stderr, "Got `%s'\n", c);
+ GNUNET_free (c);
+ return 2;
+ }
GNUNET_free (c);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l))
- {
- GNUNET_break (0);
- return 3;
- }
+ {
+ GNUNET_break (0);
+ return 3;
+ }
if (5 != l)
- {
- GNUNET_break (0);
- return 4;
- }
+ {
+ GNUNET_break (0);
+ return 4;
+ }
GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES");
if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c"))
- {
- GNUNET_break (0);
- return 5;
- }
+ {
+ GNUNET_break (0);
+ return 5;
+ }
GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c))
- {
- GNUNET_break (0);
- return 6;
- }
+ {
+ GNUNET_break (0);
+ return 6;
+ }
if (0 != strcmp (c, "10"))
- {
- GNUNET_free (c);
- GNUNET_break (0);
- return 7;
- }
+ {
+ GNUNET_free (c);
+ GNUNET_break (0);
+ return 7;
+ }
GNUNET_free (c);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c))
- {
- GNUNET_break (0);
- return 8;
- }
+ {
+ GNUNET_break (0);
+ return 8;
+ }
#ifndef MINGW
if (0 != strcmp (c, "/hello/world"))
#else
#define HI "\\hello\\world"
if (strstr (c, HI) != c + strlen (c) - strlen (HI))
#endif
- {
- GNUNET_break (0);
- GNUNET_free (c);
- return 9;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_free (c);
+ return 9;
+ }
GNUNET_free (c);
if (GNUNET_OK !=
int *idx = data;
if (0 == strcmp (want[*idx], fn))
- {
- (*idx)++;
- return GNUNET_OK;
- }
+ {
+ (*idx)++;
+ return GNUNET_OK;
+ }
GNUNET_break (0);
return GNUNET_SYSERR;
}
idx = 0;
if (3 !=
GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
- &check, &idx))
- {
- GNUNET_break (0);
- return 8;
- }
+ &check, &idx))
+ {
+ GNUNET_break (0);
+ return 8;
+ }
if (idx != 3)
return 16;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
- "/File Name"))
- {
- GNUNET_break (0);
- return 24;
- }
+ "/File Name"))
+ {
+ GNUNET_break (0);
+ return 24;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
- "/File Name"))
- {
- GNUNET_break (0);
- return 32;
- }
+ "/File Name"))
+ {
+ GNUNET_break (0);
+ return 32;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
- "Stuff"))
- {
- GNUNET_break (0);
- return 40;
- }
+ "Stuff"))
+ {
+ GNUNET_break (0);
+ return 40;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
- "/Hello"))
- {
- GNUNET_break (0);
- return 48;
- }
+ "/Hello"))
+ {
+ GNUNET_break (0);
+ return 48;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
- "/World"))
- {
- GNUNET_break (0);
- return 56;
- }
+ "/World"))
+ {
+ GNUNET_break (0);
+ return 56;
+ }
if (GNUNET_YES !=
GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
- "/File 1"))
- {
- GNUNET_break (0);
- return 64;
- }
+ "/File 1"))
+ {
+ GNUNET_break (0);
+ return 64;
+ }
if (GNUNET_YES !=
GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
- "/File 2"))
- {
- GNUNET_break (0);
- return 72;
- }
+ "/File 2"))
+ {
+ GNUNET_break (0);
+ return 72;
+ }
idx = 0;
want[1] = "/World";
want[3] = "/File 2";
if (4 !=
GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
- &check, &idx))
- {
- GNUNET_break (0);
- return 80;
- }
+ &check, &idx))
+ {
+ GNUNET_break (0);
+ return 80;
+ }
if (idx != 4)
- {
- GNUNET_break (0);
- return 88;
- }
+ {
+ GNUNET_break (0);
+ return 88;
+ }
return 0;
}
GNUNET_assert (cfg != NULL);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
- {
- fprintf (stderr, "Failed to parse configuration file\n");
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ fprintf (stderr, "Failed to parse configuration file\n");
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
failureCount += testConfig ();
if (failureCount > 0)
goto error;
goto error;
if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
- {
- fprintf (stderr, "Failed to write configuration file\n");
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ fprintf (stderr, "Failed to write configuration file\n");
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf"))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM",
- &c))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", &c))
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
if (0 != strcmp (c, "YES"))
- {
- GNUNET_break (0);
- GNUNET_free (c);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_free (c);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return 1;
+ }
GNUNET_free (c);
GNUNET_CONFIGURATION_destroy (cfg);
/* Testing configuration diffs */
cfgDefault = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfgDefault);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfgDefault);
+ return 1;
+ }
/* Nothing changed in the new configuration */
failureCount += checkDiffs (cfgDefault, EDIT_NOTHING);
error:
if (failureCount != 0)
- {
- fprintf (stderr, "Test failed: %u\n", failureCount);
- return 1;
- }
+ {
+ fprintf (stderr, "Test failed: %u\n", failureCount);
+ return 1;
+ }
return 0;
}
GNUNET_assert (desc != NULL);
if (GNUNET_NETWORK_socket_setsockopt
(desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
GNUNET_assert (GNUNET_NETWORK_socket_bind
- (desc, (const struct sockaddr *) &sa,
- sizeof (sa)) == GNUNET_OK);
+ (desc, (const struct sockaddr *) &sa,
+ sizeof (sa)) == GNUNET_OK);
GNUNET_NETWORK_socket_listen (desc, 5);
return desc;
}
static void
receive_check (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+ const struct sockaddr *addr, socklen_t addrlen, int errCode)
{
int *ok = cls;
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive validates incoming data\n");
#endif
- GNUNET_assert (buf != NULL); /* no timeout */
+ GNUNET_assert (buf != NULL); /* no timeout */
if (0 == memcmp (&"Hello World"[sofar], buf, available))
sofar += available;
if (sofar < 12)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n");
#endif
- GNUNET_CONNECTION_receive (asock, 1024,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5),
- &receive_check, cls);
- }
+ GNUNET_CONNECTION_receive (asock, 1024,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
+ cls);
+ }
else
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receive closes accepted socket\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive closes accepted socket\n");
#endif
- *ok = 0;
- GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
- }
+ *ok = 0;
+ GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
+ }
}
GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Test asks to receive on accepted socket\n");
+ "Test asks to receive on accepted socket\n");
#endif
GNUNET_CONNECTION_receive (asock, 1024,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
- cls);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
+ cls);
}
static size_t
{
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Test prepares to transmit on connect socket\n");
+ "Test prepares to transmit on connect socket\n");
#endif
GNUNET_assert (size >= 12);
strcpy ((char *) buf, "Hello World");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n");
#endif
GNUNET_assert (NULL !=
- GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
- GNUNET_TIME_UNIT_SECONDS,
- &make_hello, NULL));
+ GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
+ GNUNET_TIME_UNIT_SECONDS,
+ &make_hello, NULL));
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n");
#endif
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls,
- &run_accept, cls);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept,
+ cls);
}
ok = 1;
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
GNUNET_SCHEDULER_run (&task, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
return ok;
GNUNET_log_setup ("test_connection",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check ();
return ret;
}
GNUNET_assert (desc != 0);
if (GNUNET_NETWORK_socket_setsockopt
(desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa,
- sizeof (sa)))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "bind");
- GNUNET_assert (0);
- }
+ sizeof (sa)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "bind");
+ GNUNET_assert (0);
+ }
GNUNET_NETWORK_socket_listen (desc, 5);
return desc;
}
static void
receive_check (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+ const struct sockaddr *addr, socklen_t addrlen, int errCode)
{
int *ok = cls;
- GNUNET_assert (buf != NULL); /* no timeout */
+ GNUNET_assert (buf != NULL); /* no timeout */
if (0 == memcmp (&"Hello World"[sofar], buf, available))
sofar += available;
if (sofar < 12)
- {
- GNUNET_CONNECTION_receive (asock, 1024,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5),
- &receive_check, cls);
- }
+ {
+ GNUNET_CONNECTION_receive (asock, 1024,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
+ cls);
+ }
else
- {
- *ok = 0;
- GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
- }
+ {
+ *ok = 0;
+ GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
+ }
}
GNUNET_assert (asock != NULL);
GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONNECTION_get_address (asock, &addr, &alen));
+ GNUNET_CONNECTION_get_address (asock, &addr, &alen));
GNUNET_assert (alen == sizeof (struct sockaddr_in));
v4 = addr;
memset (&expect, 0, sizeof (expect));
GNUNET_free (addr);
GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
GNUNET_CONNECTION_receive (asock, 1024,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
- cls);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
+ cls);
}
static size_t
v4.sin_port = htons (PORT);
v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
csock =
- GNUNET_CONNECTION_create_from_sockaddr (AF_INET,
- (const struct sockaddr *) &v4,
- sizeof (v4));
+ GNUNET_CONNECTION_create_from_sockaddr (AF_INET,
+ (const struct sockaddr *) &v4,
+ sizeof (v4));
GNUNET_assert (csock != NULL);
GNUNET_assert (NULL !=
- GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
- GNUNET_TIME_UNIT_SECONDS,
- &make_hello, NULL));
+ GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
+ GNUNET_TIME_UNIT_SECONDS,
+ &make_hello, NULL));
GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls,
- &run_accept, cls);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept,
+ cls);
}
GNUNET_log_setup ("test_connection_addressing",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check ();
return ret;
}
GNUNET_assert (desc != NULL);
if (GNUNET_NETWORK_socket_setsockopt
(desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
GNUNET_assert (GNUNET_NETWORK_socket_bind
- (desc, (const struct sockaddr *) &sa,
- sizeof (sa)) == GNUNET_OK);
+ (desc, (const struct sockaddr *) &sa,
+ sizeof (sa)) == GNUNET_OK);
GNUNET_NETWORK_socket_listen (desc, 5);
return desc;
}
static void
dead_receive (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+ const struct sockaddr *addr, socklen_t addrlen, int errCode)
{
GNUNET_assert (0);
}
GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
GNUNET_CONNECTION_receive (asock, 1024,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive,
- cls);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls);
}
csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls,
- &run_accept_cancel, cls);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &receive_cancel_task, cls);
+ &run_accept_cancel, cls);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task,
+ cls);
}
ok = 1;
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
GNUNET_SCHEDULER_run (&task_receive_cancel, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
return ok;
GNUNET_assert (desc != NULL);
if (GNUNET_NETWORK_socket_setsockopt
(desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
GNUNET_assert (GNUNET_NETWORK_socket_bind
- (desc, (const struct sockaddr *) &sa,
- sizeof (sa)) == GNUNET_OK);
+ (desc, (const struct sockaddr *) &sa,
+ sizeof (sa)) == GNUNET_OK);
GNUNET_NETWORK_socket_listen (desc, 5);
return desc;
}
int *ok = cls;
if (size == 0)
- {
+ {
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n");
#endif
- GNUNET_assert (buf == NULL);
- *ok = 0;
- GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
- GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
- return 0;
- }
+ GNUNET_assert (buf == NULL);
+ *ok = 0;
+ GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
+ GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
+ return 0;
+ }
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kilo to fill buffer.\n");
#endif
memset (buf, 42, 1024);
GNUNET_assert (NULL !=
- GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
- GNUNET_TIME_UNIT_SECONDS,
- &send_kilo, cls));
+ GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
+ GNUNET_TIME_UNIT_SECONDS,
+ &send_kilo, cls));
return 1024;
}
csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
GNUNET_assert (NULL !=
- GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
- GNUNET_TIME_UNIT_SECONDS,
- &send_kilo, cls));
+ GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
+ GNUNET_TIME_UNIT_SECONDS,
+ &send_kilo, cls));
}
ok = 1;
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
GNUNET_SCHEDULER_run (&task_timeout, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
return ok;
GNUNET_log_setup ("test_connection_timeout",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check_timeout ();
return ret;
}
csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
GNUNET_assert (NULL !=
- GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
- GNUNET_TIME_UNIT_SECONDS,
- &handle_timeout,
- cls));
+ GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
+ GNUNET_TIME_UNIT_SECONDS,
+ &handle_timeout,
+ cls));
}
ok = 1;
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
GNUNET_SCHEDULER_run (&task_timeout, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
return ok;
GNUNET_log_setup ("test_connection_timeout_no_connect",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check_timeout ();
return ret;
}
static void
-task_transmit_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+task_transmit_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
struct GNUNET_CONNECTION_TransmitHandle *th;
csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
th = GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
- GNUNET_TIME_UNIT_MINUTES,
- ¬_run, cls);
+ GNUNET_TIME_UNIT_MINUTES,
+ ¬_run, cls);
GNUNET_assert (NULL != th);
GNUNET_CONNECTION_notify_transmit_ready_cancel (th);
GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
ok = 1;
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
GNUNET_SCHEDULER_run (&task_transmit_cancel, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
return ok;
GNUNET_log_setup ("test_connection_transmit_cancel",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check_transmit_cancel ();
return ret;
bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K);
for (i = 0; i < 200; i++)
- {
- nextHC (&tmp);
- GNUNET_CONTAINER_bloomfilter_add (bf, &tmp);
- }
+ {
+ nextHC (&tmp);
+ GNUNET_CONTAINER_bloomfilter_add (bf, &tmp);
+ }
SRANDOM (1);
ok1 = 0;
for (i = 0; i < 200; i++)
- {
- nextHC (&tmp);
- if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
- ok1++;
- }
+ {
+ nextHC (&tmp);
+ if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
+ ok1++;
+ }
if (ok1 != 200)
- {
- printf ("Got %d elements out of" "200 expected after insertion.\n",
- ok1);
- GNUNET_CONTAINER_bloomfilter_free (bf);
- return -1;
- }
+ {
+ printf ("Got %d elements out of" "200 expected after insertion.\n", ok1);
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ return -1;
+ }
if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, buf, SIZE))
- {
- GNUNET_CONTAINER_bloomfilter_free (bf);
- return -1;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ return -1;
+ }
GNUNET_CONTAINER_bloomfilter_free (bf);
ok1 = 0;
ok2 = 0;
for (i = 0; i < 200; i++)
- {
- nextHC (&tmp);
- if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
- ok1++;
- if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
- ok2++;
- }
+ {
+ nextHC (&tmp);
+ if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
+ ok1++;
+ if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
+ ok2++;
+ }
if (ok1 != 200)
- {
- printf ("Got %d elements out of 200 " "expected after reloading.\n",
- ok1);
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ printf ("Got %d elements out of 200 " "expected after reloading.\n", ok1);
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
if (ok2 != 200)
- {
- printf ("Got %d elements out of 200 "
- "expected after initialization.\n", ok2);
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ printf ("Got %d elements out of 200 " "expected after initialization.\n",
+ ok2);
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
SRANDOM (1);
for (i = 0; i < 100; i++)
- {
- nextHC (&tmp);
- GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp);
- GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp);
- }
+ {
+ nextHC (&tmp);
+ GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp);
+ GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp);
+ }
SRANDOM (1);
ok1 = 0;
ok2 = 0;
for (i = 0; i < 200; i++)
- {
- nextHC (&tmp);
- if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
- ok1++;
- if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
- ok2++;
- }
+ {
+ nextHC (&tmp);
+ if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
+ ok1++;
+ if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
+ ok2++;
+ }
if (ok1 != 100)
- {
- printf ("Expected 100 elements in loaded filter"
- " after adding 200 and deleting 100, got %d\n", ok1);
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ printf ("Expected 100 elements in loaded filter"
+ " after adding 200 and deleting 100, got %d\n", ok1);
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
if (ok2 != 200)
- {
- printf ("Expected 200 elements in initialized filter"
- " after adding 200 and deleting 100 "
- "(which should do nothing for a filter not backed by a file), got %d\n",
- ok2);
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ printf ("Expected 200 elements in initialized filter"
+ " after adding 200 and deleting 100 "
+ "(which should do nothing for a filter not backed by a file), got %d\n",
+ ok2);
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
SRANDOM (3);
GNUNET_CONTAINER_bloomfilter_clear (bf);
falseok = 0;
for (i = 0; i < 1000; i++)
- {
- nextHC (&tmp);
- if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
- falseok++;
- }
+ {
+ nextHC (&tmp);
+ if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
+ falseok++;
+ }
if (falseok > 0)
- {
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_or (bf, buf, SIZE))
- {
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
SRANDOM (2);
i = 20;
ok1 = 0;
ok2 = 0;
for (i = 0; i < 20; i++)
- {
- nextHC (&tmp);
- if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
- ok1++;
- if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
- ok2++;
- }
+ {
+ nextHC (&tmp);
+ if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
+ ok1++;
+ if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
+ ok2++;
+ }
if (ok1 != 20)
- {
- printf ("Expected 20 elements in resized file-backed filter"
- " after adding 20, got %d\n", ok1);
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ printf ("Expected 20 elements in resized file-backed filter"
+ " after adding 20, got %d\n", ok1);
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
if (ok2 != 20)
- {
- printf ("Expected 20 elements in resized filter"
- " after adding 20, got %d\n", ok2);
- GNUNET_CONTAINER_bloomfilter_free (bf);
- GNUNET_CONTAINER_bloomfilter_free (bfi);
- return -1;
- }
+ {
+ printf ("Expected 20 elements in resized filter"
+ " after adding 20, got %d\n", ok2);
+ GNUNET_CONTAINER_bloomfilter_free (bf);
+ GNUNET_CONTAINER_bloomfilter_free (bfi);
+ return -1;
+ }
GNUNET_CONTAINER_bloomfilter_free (bf);
static int
iterator_callback (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
- void *element, GNUNET_CONTAINER_HeapCostType cost)
+ void *element, GNUNET_CONTAINER_HeapCostType cost)
{
return GNUNET_OK;
}
n6 = GNUNET_CONTAINER_heap_insert (myHeap, "30/200", 30);
GNUNET_assert (5 == GNUNET_CONTAINER_heap_get_size (myHeap));
GNUNET_CONTAINER_heap_remove_node (n5);
- r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */
+ r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */
GNUNET_assert (NULL != r);
GNUNET_assert (0 == strcmp ("11", r));
GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200);
GNUNET_CONTAINER_heap_remove_node (n3);
- r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */
+ r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */
GNUNET_assert (NULL != r);
GNUNET_assert (0 == strcmp ("50", r));
- r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */
+ r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */
GNUNET_assert (NULL != r);
GNUNET_assert (0 == strcmp ("30/200", r));
GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (myHeap));
GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
GNUNET_assert (0 ==
- nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap)));
+ nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap)));
GNUNET_assert (0 ==
- nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
+ nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20);
GNUNET_CONTAINER_heap_remove_node (n2);
GNUNET_CONTAINER_heap_remove_node (n1);
GNUNET_assert (0 ==
- nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
+ nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
m = GNUNET_CONTAINER_meta_data_create ();
if (GNUNET_OK !=
- GNUNET_CONTAINER_meta_data_insert (m, "<test>",
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", "TestTitle",
- strlen ("TestTitle") + 1))
+ GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", "TestTitle",
+ strlen ("TestTitle") + 1))
ABORT (m);
if (GNUNET_OK !=
GNUNET_CONTAINER_meta_data_insert (m, "<test>",
- EXTRACTOR_METATYPE_AUTHOR_NAME,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", "TestTitle",
- strlen ("TestTitle") + 1))
+ EXTRACTOR_METATYPE_AUTHOR_NAME,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", "TestTitle",
+ strlen ("TestTitle") + 1))
ABORT (m);
- if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */
+ if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */
ABORT (m);
- if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */
+ if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */
ABORT (m);
if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
ABORT (m);
if (GNUNET_OK !=
GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME,
- "TestTitle",
- strlen ("TestTitle") + 1))
+ "TestTitle", strlen ("TestTitle") + 1))
ABORT (m);
- if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */
+ if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */
ABORT (m);
if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
ABORT (m);
if (GNUNET_OK !=
GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE,
- "TestTitle",
- strlen ("TestTitle") + 1))
+ "TestTitle", strlen ("TestTitle") + 1))
ABORT (m);
- if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */
+ if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */
ABORT (m);
if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
ABORT (m);
for (j = 0; j < i; j++)
- {
- GNUNET_snprintf (val, sizeof (val), "%s.%d",
- "A teststring that should compress well.", j);
- if (GNUNET_OK !=
- GNUNET_CONTAINER_meta_data_insert (m, "<test>",
- EXTRACTOR_METATYPE_UNKNOWN,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", val,
- strlen (val) + 1))
- ABORT (m);
- }
+ {
+ GNUNET_snprintf (val, sizeof (val), "%s.%d",
+ "A teststring that should compress well.", j);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_meta_data_insert (m, "<test>",
+ EXTRACTOR_METATYPE_UNKNOWN,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", val, strlen (val) + 1))
+ ABORT (m);
+ }
if (i != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
ABORT (m);
sval = NULL;
if (size !=
GNUNET_CONTAINER_meta_data_serialize (m, &sval, size,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
- {
- GNUNET_free_non_null (sval);
- ABORT (m);
- }
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
+ {
+ GNUNET_free_non_null (sval);
+ ABORT (m);
+ }
GNUNET_CONTAINER_meta_data_destroy (m);
m = GNUNET_CONTAINER_meta_data_deserialize (sval, size);
GNUNET_free (sval);
if (m == NULL)
ABORT (m);
for (j = 0; j < i; j++)
+ {
+ GNUNET_snprintf (val, sizeof (val), "%s.%d",
+ "A teststring that should compress well.", j);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_UNKNOWN, val,
+ strlen (val) + 1))
{
- GNUNET_snprintf (val, sizeof (val), "%s.%d",
- "A teststring that should compress well.", j);
- if (GNUNET_OK !=
- GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_UNKNOWN,
- val, strlen (val) + 1))
- {
- ABORT (m);
- }
+ ABORT (m);
}
+ }
if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
ABORT (m);
GNUNET_CONTAINER_meta_data_destroy (m);
meta = GNUNET_CONTAINER_meta_data_create ();
for (q = 0; q <= i; q++)
- {
- GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
- GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
- q % EXTRACTOR_metatype_get_max (),
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", txt, strlen (txt) + 1);
- }
+ {
+ GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
+ GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
+ q % EXTRACTOR_metatype_get_max (),
+ EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+ txt, strlen (txt) + 1);
+ }
size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
data = GNUNET_malloc (size * 4);
if (size !=
GNUNET_CONTAINER_meta_data_serialize (meta, &data, size * 4,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
- {
- GNUNET_free (data);
- ABORT (meta);
- }
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
+ {
+ GNUNET_free (data);
+ ABORT (meta);
+ }
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_free (data);
return 0;
m = GNUNET_CONTAINER_meta_data_create ();
if (GNUNET_OK !=
GNUNET_CONTAINER_meta_data_insert (m, "<test>",
- EXTRACTOR_METATYPE_UNKNOWN,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", "link",
- strlen ("link") + 1))
+ EXTRACTOR_METATYPE_UNKNOWN,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", "link",
+ strlen ("link") + 1))
ABORT (m);
if (GNUNET_OK !=
GNUNET_CONTAINER_meta_data_insert (m, "<test>",
- EXTRACTOR_METATYPE_FILENAME,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", "lib-link.m4",
- strlen ("lib-link.m4") + 1))
+ EXTRACTOR_METATYPE_FILENAME,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", "lib-link.m4",
+ strlen ("lib-link.m4") + 1))
ABORT (m);
val = NULL;
size =
- GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
+ GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1,
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
GNUNET_CONTAINER_meta_data_destroy (m);
m = GNUNET_CONTAINER_meta_data_deserialize (val, size);
GNUNET_free (val);
meta = GNUNET_CONTAINER_meta_data_create ();
meta2 = GNUNET_CONTAINER_meta_data_create ();
for (q = 0; q <= i; q++)
- {
- GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
- GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
- EXTRACTOR_METATYPE_UNKNOWN,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", "TestTitle",
- strlen ("TestTitle") + 1);
- GNUNET_CONTAINER_meta_data_insert (meta2, "<test>",
- EXTRACTOR_METATYPE_UNKNOWN,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", "TestTitle",
- strlen ("TestTitle") + 1);
- }
+ {
+ GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
+ GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
+ EXTRACTOR_METATYPE_UNKNOWN,
+ EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+ "TestTitle", strlen ("TestTitle") + 1);
+ GNUNET_CONTAINER_meta_data_insert (meta2, "<test>",
+ EXTRACTOR_METATYPE_UNKNOWN,
+ EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+ "TestTitle", strlen ("TestTitle") + 1);
+ }
//check meta_data_test_equal
if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
//check meta_data_clear
GNUNET_CONTAINER_meta_data_clear (meta2);
if (0 != GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
// check equal branch in meta_data_test_equal
if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
// check "count" branch in meta_data_test_equal
if (GNUNET_NO != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
// check meta_data_add_publication_date
GNUNET_CONTAINER_meta_data_add_publication_date (meta2);
GNUNET_CONTAINER_meta_data_clear (meta2);
GNUNET_CONTAINER_meta_data_merge (meta2, meta);
if (100 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
// check meta_data_get_by_type
GNUNET_CONTAINER_meta_data_clear (meta2);
if (NULL !=
(str =
GNUNET_CONTAINER_meta_data_get_by_type (meta2,
- EXTRACTOR_METATYPE_UNKNOWN)))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- GNUNET_free (str);
- ABORT (meta);
- }
+ EXTRACTOR_METATYPE_UNKNOWN)))
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ GNUNET_free (str);
+ ABORT (meta);
+ }
str =
- GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN);
+ GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN);
GNUNET_assert (NULL != str);
if (str[0] != 'T')
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- GNUNET_free (str);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ GNUNET_free (str);
+ ABORT (meta);
+ }
GNUNET_free (str);
// check branch
if (NULL !=
(str =
GNUNET_CONTAINER_meta_data_get_by_type (meta,
- EXTRACTOR_METATYPE_PUBLICATION_DATE)))
- {
- GNUNET_free (str);
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ EXTRACTOR_METATYPE_PUBLICATION_DATE)))
+ {
+ GNUNET_free (str);
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
//check meta_data_get_first_by_types
str =
- GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
- EXTRACTOR_METATYPE_UNKNOWN,
- -1);
+ GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
+ EXTRACTOR_METATYPE_UNKNOWN,
+ -1);
GNUNET_assert (NULL != str);
if (str[0] != 'T')
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- GNUNET_free (str);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ GNUNET_free (str);
+ ABORT (meta);
+ }
GNUNET_free (str);
//check meta_data_get_thumbnail
if (GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb) != 0)
- {
- GNUNET_free (thumb);
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ {
+ GNUNET_free (thumb);
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
GNUNET_CONTAINER_meta_data_destroy (meta2);
//check meta_data_duplicate
meta2 = GNUNET_CONTAINER_meta_data_duplicate (meta);
if (200 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta2);
- ABORT (meta);
- }
+ {
+ GNUNET_CONTAINER_meta_data_destroy (meta2);
+ ABORT (meta);
+ }
GNUNET_CONTAINER_meta_data_destroy (meta2);
GNUNET_CONTAINER_meta_data_destroy (meta);
return 0;
CHECK (0 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1));
CHECK (0 == GNUNET_CONTAINER_multihashmap_size (m));
CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
- CHECK (0 ==
- GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
+ CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
CHECK (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
+ GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m));
ret = GNUNET_CONTAINER_multihashmap_get (m, &k1);
GNUNET_assert (ret != NULL);
CHECK (0 == strcmp ("v1", ret));
CHECK (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
+ GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m));
CHECK (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
CHECK (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (m, &k1, "v3",
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (m, &k1, "v3",
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
CHECK (3 == GNUNET_CONTAINER_multihashmap_size (m));
CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (m, &k1, "v3"));
CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m));
CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (m, &k1));
CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2));
- CHECK (2 ==
- GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
- CHECK (0 ==
- GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL));
+ CHECK (2 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
+ CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL));
CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1));
for (j = 0; j < 1024; j++)
CHECK (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
GNUNET_CONTAINER_multihashmap_destroy (m);
return 0;
}
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0);
for (i = 0; i < 100; i++)
- GNUNET_CONTAINER_slist_add (l,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- &i, sizeof (i));
+ GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ &i, sizeof (i));
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
for (it = GNUNET_CONTAINER_slist_begin (l), i = 99;
GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;
GNUNET_CONTAINER_slist_next (&it), i--)
+ {
+ p = GNUNET_CONTAINER_slist_get (&it, &s);
+
+ if ((p == NULL) || (i != (j = *(int *) p)) || (s != sizeof (i)))
{
- p = GNUNET_CONTAINER_slist_get (&it, &s);
-
- if ((p == NULL) || (i != (j = *(int *) p)) || (s != sizeof (i)))
- {
- GNUNET_CONTAINER_slist_iter_destroy (&it);
- GNUNET_assert (0);
- }
- j *= 2;
- GNUNET_CONTAINER_slist_insert (&it,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- &j, sizeof (j));
+ GNUNET_CONTAINER_slist_iter_destroy (&it);
+ GNUNET_assert (0);
}
+ j *= 2;
+ GNUNET_CONTAINER_slist_insert (&it,
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ &j, sizeof (j));
+ }
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200);
i = 198;
GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)));
for (it = GNUNET_CONTAINER_slist_begin (l);
GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;)
- {
- p = GNUNET_CONTAINER_slist_get (&it, &s);
- GNUNET_assert (p != NULL);
- GNUNET_assert (s == sizeof (i));
- i = *(int *) p;
+ {
+ p = GNUNET_CONTAINER_slist_get (&it, &s);
+ GNUNET_assert (p != NULL);
+ GNUNET_assert (s == sizeof (i));
+ i = *(int *) p;
- GNUNET_assert (GNUNET_CONTAINER_slist_next (&it) == GNUNET_YES);
- GNUNET_assert (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES);
+ GNUNET_assert (GNUNET_CONTAINER_slist_next (&it) == GNUNET_YES);
+ GNUNET_assert (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES);
- p = GNUNET_CONTAINER_slist_get (&it, &s);
- GNUNET_assert (p != NULL);
- GNUNET_assert (s == sizeof (j));
- j = *(int *) p;
+ p = GNUNET_CONTAINER_slist_get (&it, &s);
+ GNUNET_assert (p != NULL);
+ GNUNET_assert (s == sizeof (j));
+ j = *(int *) p;
- GNUNET_assert (j * 2 == i);
+ GNUNET_assert (j * 2 == i);
- GNUNET_CONTAINER_slist_erase (&it);
- }
+ GNUNET_CONTAINER_slist_erase (&it);
+ }
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
i = 99;
GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
- GNUNET_NO);
+ GNUNET_NO);
i = 198;
GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
- GNUNET_YES);
+ GNUNET_YES);
GNUNET_CONTAINER_slist_clear (l);
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0);
for (i = 0; i < 100; i++)
- GNUNET_CONTAINER_slist_add (l,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- &i, sizeof (i));
+ GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ &i, sizeof (i));
/*check slist_append */
GNUNET_CONTAINER_slist_append (l, l);
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200);
l = GNUNET_CONTAINER_slist_create ();
for (i = 0; i < 100; i++)
GNUNET_CONTAINER_slist_add_end (l,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
- &i, sizeof (i));
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ &i, sizeof (i));
GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
for (it = GNUNET_CONTAINER_slist_begin (l), i = 0;
GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;
GNUNET_CONTAINER_slist_next (&it), i++)
- {
- p = GNUNET_CONTAINER_slist_get (&it, &s);
+ {
+ p = GNUNET_CONTAINER_slist_get (&it, &s);
- if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i)))
- {
- GNUNET_assert (0);
- }
+ if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i)))
+ {
+ GNUNET_assert (0);
}
+ }
GNUNET_CONTAINER_slist_destroy (l);
/*check if disp = GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC */
l = GNUNET_CONTAINER_slist_create ();
for (i = 0; i < 100; i++)
- {
- ip = GNUNET_malloc (sizeof (int));
- *ip = i;
- GNUNET_CONTAINER_slist_add (l,
- GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC,
- ip, sizeof (int));
- }
+ {
+ ip = GNUNET_malloc (sizeof (int));
+ *ip = i;
+ GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC,
+ ip, sizeof (int));
+ }
//creat_add
it = GNUNET_CONTAINER_slist_begin (l);
p = GNUNET_CONTAINER_slist_get (&it, &s);
GNUNET_CRYPTO_aes_create_session_key (&key);
size =
- GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key,
- (const struct
- GNUNET_CRYPTO_AesInitializationVector *)
- INITVALUE, result);
+ GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key,
+ (const struct
+ GNUNET_CRYPTO_AesInitializationVector *)
+ INITVALUE, result);
if (size == -1)
- {
- printf ("symciphertest failed: encryptBlock returned %d\n", size);
- return 1;
- }
+ {
+ printf ("symciphertest failed: encryptBlock returned %d\n", size);
+ return 1;
+ }
size =
- GNUNET_CRYPTO_aes_decrypt (result, size, &key,
- (const struct
- GNUNET_CRYPTO_AesInitializationVector *)
- INITVALUE, res);
+ GNUNET_CRYPTO_aes_decrypt (result, size, &key,
+ (const struct
+ GNUNET_CRYPTO_AesInitializationVector *)
+ INITVALUE, res);
if (strlen (TESTSTRING) + 1 != size)
- {
- printf ("symciphertest failed: decryptBlock returned %d\n", size);
- return 1;
- }
+ {
+ printf ("symciphertest failed: decryptBlock returned %d\n", size);
+ return 1;
+ }
if (0 != strcmp (res, TESTSTRING))
- {
- printf ("symciphertest failed: %s != %s\n", res, TESTSTRING);
- return 1;
- }
+ {
+ printf ("symciphertest failed: %s != %s\n", res, TESTSTRING);
+ return 1;
+ }
else
return 0;
}
int ret;
unsigned char plain[] =
- { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249,
+ { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249,
172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164
};
unsigned char raw_key[] =
- { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25,
+ { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25,
169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184,
34, 191
};
unsigned char encrresult[] =
- { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75,
+ { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75,
195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25,
102
};
memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH);
key.crc32 =
- htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH));
+ htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH));
if (ntohl (key.crc32) != (unsigned int) 38125195LL)
- {
- printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32),
- key.crc32);
+ {
+ printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32),
+ key.crc32);
- ret = 1;
- goto error;
- }
+ ret = 1;
+ goto error;
+ }
if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
GNUNET_CRYPTO_aes_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
- (const struct
- GNUNET_CRYPTO_AesInitializationVector *)
- "testtesttesttest", result))
- {
- printf ("Wrong return value from encrypt block.\n");
- ret = 1;
- goto error;
- }
+ (const struct
+ GNUNET_CRYPTO_AesInitializationVector *)
+ "testtesttesttest", result))
+ {
+ printf ("Wrong return value from encrypt block.\n");
+ ret = 1;
+ goto error;
+ }
if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0)
- {
- printf ("Encrypted result wrong.\n");
- ret = 1;
- goto error;
- }
+ {
+ printf ("Encrypted result wrong.\n");
+ ret = 1;
+ goto error;
+ }
res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH);
if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
- (const struct
- GNUNET_CRYPTO_AesInitializationVector *)
- "testtesttesttest", res))
- {
- printf ("Wrong return value from decrypt block.\n");
- ret = 1;
- goto error;
- }
+ (const struct
+ GNUNET_CRYPTO_AesInitializationVector *)
+ "testtesttesttest", res))
+ {
+ printf ("Wrong return value from decrypt block.\n");
+ ret = 1;
+ goto error;
+ }
if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0)
- {
- printf ("Decrypted result does not match input.\n");
+ {
+ printf ("Decrypted result does not match input.\n");
- ret = 1;
- }
+ ret = 1;
+ }
error:
GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL);
GNUNET_CRYPTO_random_disable_entropy_gathering ();
GNUNET_assert (strlen (INITVALUE) >
- sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
+ sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
failureCount += testSymcipher ();
failureCount += verifyCrypto ();
if (failureCount != 0)
- {
- printf ("%d TESTS FAILED!\n", failureCount);
- return -1;
- }
+ {
+ printf ("%d TESTS FAILED!\n", failureCount);
+ return -1;
+ }
return 0;
}
int i;
for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++)
- {
- printf ("%x ", (int) (key->key[i]));
- }
+ {
+ printf ("%x ", (int) (key->key[i]));
+ }
}
static int
struct GNUNET_CRYPTO_AesInitializationVector INITVALUE;
memset (&INITVALUE, 42,
- sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
+ sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
/* sorry, this is not a weak key -- I don't have
* any at the moment! */
weak_key.key[0] = (char) (0x4c);
weak_key.key[31] = (char) (0xaa);
/* memset(&weak_key, 0, 32); */
weak_key.crc32 =
- htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH));
+ htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH));
size =
- GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING,
- strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key,
- &INITVALUE, result);
+ GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING,
+ strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key,
+ &INITVALUE, result);
if (size == -1)
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res);
if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size)
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
if (0 != strcmp (res, WEAK_KEY_TESTSTRING))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
else
return 0;
}
for (number_of_runs = 0; number_of_runs < MAX_WEAK_KEY_TRIALS;
number_of_runs++)
+ {
+
+ if (number_of_runs % 1000 == 0)
+ fprintf (stderr, ".");
+ /*printf("Got to run number %d.\n", number_of_runs); */
+ GNUNET_CRYPTO_aes_create_session_key (&sessionkey);
+
+ rc = gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB,
+ 0);
+
+ if (rc)
{
+ printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n",
+ number_of_runs, gcry_strerror (rc));
+ continue;
+ }
- if (number_of_runs % 1000 == 0)
- fprintf (stderr, ".");
- /*printf("Got to run number %d.\n", number_of_runs); */
- GNUNET_CRYPTO_aes_create_session_key (&sessionkey);
-
- rc =
- gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB,
- 0);
-
- if (rc)
- {
- printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n",
- number_of_runs, gcry_strerror (rc));
- continue;
- }
-
- rc =
- gcry_cipher_setkey (handle, &sessionkey,
- GNUNET_CRYPTO_AES_KEY_LENGTH);
-
- if ((char) rc == GPG_ERR_WEAK_KEY)
- {
- printf ("\nWeak key (in hex): ");
- printWeakKey (&sessionkey);
- printf ("\n");
- number_of_weak_keys++;
- }
- else if (rc)
- {
- printf ("\nUnexpected error generating keys. Error is %s\n",
- gcry_strerror (rc));
- }
-
- gcry_cipher_close (handle);
+ rc = gcry_cipher_setkey (handle, &sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
+ if ((char) rc == GPG_ERR_WEAK_KEY)
+ {
+ printf ("\nWeak key (in hex): ");
+ printWeakKey (&sessionkey);
+ printf ("\n");
+ number_of_weak_keys++;
+ }
+ else if (rc)
+ {
+ printf ("\nUnexpected error generating keys. Error is %s\n",
+ gcry_strerror (rc));
}
+ gcry_cipher_close (handle);
+
+ }
+
return number_of_weak_keys;
}
GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL);
GNUNET_CRYPTO_random_disable_entropy_gathering ();
if (GENERATE_WEAK_KEYS)
+ {
+ weak_keys = getWeakKeys ();
+
+ if (weak_keys == 0)
+ {
+ printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS);
+ }
+ else
{
- weak_keys = getWeakKeys ();
-
- if (weak_keys == 0)
- {
- printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS);
- }
- else
- {
- printf ("\n%d weak keys found in %d runs.\n", weak_keys,
- MAX_WEAK_KEY_TRIALS);
- }
+ printf ("\n%d weak keys found in %d runs.\n", weak_keys,
+ MAX_WEAK_KEY_TRIALS);
}
+ }
if (testWeakKey () != 0)
return -1;
memset (&h1, number, sizeof (GNUNET_HashCode));
GNUNET_CRYPTO_hash_to_enc (&h1, &enc);
if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &h2))
- {
- printf ("enc2hash failed!\n");
- return 1;
- }
+ {
+ printf ("enc2hash failed!\n");
+ return 1;
+ }
if (0 != memcmp (&h1, &h2, sizeof (GNUNET_HashCode)))
return 1;
return 0;
file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (NULL !=
- GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- FILENAME, 1024, &finished_task,
- cls));
+ GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ FILENAME, 1024, &finished_task, cls));
}
tc1 ()
{
unsigned char ikm[22] =
- { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
};
unsigned char salt[13] =
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c
};
unsigned char info[10] =
- { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
+ { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
unsigned char okm[42] =
- { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43,
+ { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43,
0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a,
0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00,
0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt,
- sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
- NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt,
+ sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
+ NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
tc2 ()
{
unsigned char ikm[80] =
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
unsigned char salt[80] =
- { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
};
unsigned char info[80] =
- { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
+ { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5,
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd,
0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
unsigned char okm[82] =
- { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7,
+ { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7,
0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e,
0xfa, 0xd8, 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04,
0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59,
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt,
- sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
- NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt,
+ sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
+ NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
tc3 ()
{
unsigned char ikm[22] =
- { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
};
unsigned char okm[42] =
- { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f,
+ { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f,
0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1,
0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20,
0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm,
- sizeof (ikm), NULL, 0, NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm,
+ sizeof (ikm), NULL, 0, NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
tc4 ()
{
unsigned char ikm[11] =
- { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b
};
unsigned char salt[13] =
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c
};
unsigned char info[10] =
- { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
+ { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
unsigned char okm[42] =
- { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06,
+ { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06,
0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b,
0x09, 0x15, 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e,
0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
- ikm, sizeof (ikm), info, sizeof (info),
- NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
+ ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
tc5 ()
{
unsigned char ikm[80] =
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
unsigned char salt[80] =
- { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
};
unsigned char info[80] =
- { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
+ { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5,
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd,
0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
unsigned char okm[82] =
- { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1,
+ { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1,
0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d,
0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3,
0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2,
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
- ikm, sizeof (ikm), info, sizeof (info),
- NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
+ ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
tc6 ()
{
unsigned char ikm[22] =
- { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
};
unsigned char okm[42] =
- { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5,
+ { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5,
0x52, 0x98, 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20,
0xa3, 0x06, 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0, 0xea, 0x00,
0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3, 0x49, 0x18
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm,
- sizeof (ikm), NULL, 0, NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm,
+ sizeof (ikm), NULL, 0, NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
tc7 ()
{
unsigned char ikm[80] =
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
unsigned char salt[80] =
- { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
0xfe, 0xff
};
unsigned char okm[82] =
- { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1,
+ { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1,
0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d,
0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3,
0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2,
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
- ikm, sizeof (ikm), info1, sizeof (info1), info2,
- sizeof (info2), NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
+ ikm, sizeof (ikm), info1, sizeof (info1), info2,
+ sizeof (info2), NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
tc8 ()
{
unsigned char ikm[32] =
- { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72,
+ { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72,
0x11, 0xa1, 0xdc, 0x0b, 0x07, 0xdb, 0x1a, 0x5e, 0xd9, 0xb9, 0x81, 0xbe,
0xea, 0xe4, 0x31, 0x5f, 0x24, 0xff, 0xfe, 0x50, 0x8a, 0xde
};
unsigned char salt[4] = { 0xfc, 0x62, 0x76, 0x35 };
unsigned char info[86] =
- { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b,
+ { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b,
0x1d, 0x33, 0x15, 0x3e, 0x52, 0x0b, 0xb0, 0x77, 0xff, 0x7d, 0xc3, 0xc7,
0xef, 0xe5, 0x8e, 0x3c, 0xc4, 0x4e, 0x8b, 0x41, 0x46, 0x1f, 0x02, 0x94,
0x82, 0x35, 0xc5, 0xa6, 0x5e, 0x91, 0xd8, 0xa2, 0x90, 0xfd, 0x6f, 0xb4,
0x74, 0x6f, 0x72, 0x00
};
unsigned char okm[16] =
- { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92,
+ { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92,
0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0
};
char result[18];
memset (result, 0, sizeof (result));
GNUNET_assert (GNUNET_CRYPTO_hkdf
- (result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt,
- sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
- NULL) == GNUNET_YES);
+ (result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt,
+ sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
+ NULL) == GNUNET_YES);
GNUNET_assert (memcmp (result, okm, l) == 0);
GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
}
testCorrectKey ()
{
const char *want =
- "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000";
+ "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000";
GNUNET_HashCode in;
struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
GNUNET_CRYPTO_hash ("X", strlen ("X"), &in);
hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
if (hostkey == NULL)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
GNUNET_CRYPTO_rsa_key_free (hostkey);
#if 0
- for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);
- i++)
+ for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++)
printf ("%02x", ((unsigned char *) &pkey)[i]);
printf ("\n");
#endif
- for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);
- i++)
+ for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++)
+ {
+ snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]);
+ if (0 != strncmp (out, &want[i * 2], 2))
{
- snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]);
- if (0 != strncmp (out, &want[i * 2], 2))
- {
- fprintf (stderr, " Failed! Wanted %.2s but got %2s at %d\n",
- &want[i * 2], out, i);
- return GNUNET_SYSERR;
- }
+ fprintf (stderr, " Failed! Wanted %.2s but got %2s at %d\n", &want[i * 2],
+ out, i);
+ return GNUNET_SYSERR;
}
+ }
fprintf (stderr, " OK\n");
return GNUNET_OK;
}
GNUNET_CRYPTO_hash (word, strlen (word), &in);
hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
if (hostkey == NULL)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
/*
* for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
* printf("\n"); */
GNUNET_CRYPTO_rsa_key_free (hostkey);
for (i = 0; i < UNIQUE_ITER; i++)
+ {
+ fprintf (stderr, ".");
+ hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
+ if (hostkey == NULL)
{
- fprintf (stderr, ".");
- hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
- if (hostkey == NULL)
- {
- GNUNET_break (0);
- fprintf (stderr, " ERROR\n");
- return GNUNET_SYSERR;
- }
- GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1);
- GNUNET_CRYPTO_rsa_key_free (hostkey);
- if (0 !=
- memcmp (&pkey, &pkey1,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
- {
- GNUNET_break (0);
- fprintf (stderr, " ERROR\n");
- return GNUNET_SYSERR;
- }
+ GNUNET_break (0);
+ fprintf (stderr, " ERROR\n");
+ return GNUNET_SYSERR;
}
+ GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1);
+ GNUNET_CRYPTO_rsa_key_free (hostkey);
+ if (0 !=
+ memcmp (&pkey, &pkey1,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+ {
+ GNUNET_break (0);
+ fprintf (stderr, " ERROR\n");
+ return GNUNET_SYSERR;
+ }
+ }
fprintf (stderr, " OK\n");
return GNUNET_OK;
}
ok = 0;
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
+ {
+ fprintf (stderr, ".");
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
+ &target))
+ {
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
+ ok++;
+ continue;
+ }
+ if (-1 ==
+ GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
+ strlen (TESTSTRING) + 1))
{
- fprintf (stderr, ".");
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
- &pkey, &target))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
- ok++;
- continue;
- }
- if (-1 ==
- GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
- strlen (TESTSTRING) + 1))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
- ok++;
- continue;
- }
- if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
- {
- printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
- MAX_TESTVAL, result);
- ok++;
- continue;
- }
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
+ ok++;
+ continue;
}
+ if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
+ {
+ printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
+ MAX_TESTVAL, result);
+ ok++;
+ continue;
+ }
+ }
printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
if (ok == 0)
return GNUNET_OK;
else
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
for (i = 0; i < ITER; i++)
+ {
+ fprintf (stderr, ".");
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
+ {
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
+ ok = GNUNET_SYSERR;
+ continue;
+ }
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig,
+ &pkey))
+ {
+ printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
+ ok = GNUNET_SYSERR;
+ continue;
+ }
+ if (GNUNET_SYSERR !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
+ &purp, &sig, &pkey))
{
- fprintf (stderr, ".");
- if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
- ok = GNUNET_SYSERR;
- continue;
- }
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp,
- &sig, &pkey))
- {
- printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
- ok = GNUNET_SYSERR;
- continue;
- }
- if (GNUNET_SYSERR !=
- GNUNET_CRYPTO_rsa_verify
- (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey))
- {
- printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
- ok = GNUNET_SYSERR;
- continue;
- }
+ printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
+ ok = GNUNET_SYSERR;
+ continue;
}
+ }
printf ("%d RSA sign/verify operations %llums\n", ITER,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value);
return ok;
}
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in);
hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
if (hostkey == NULL)
- {
- printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n");
- return 1;
- }
+ {
+ printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n");
+ return 1;
+ }
if (GNUNET_OK != testMultiKey ("foo"))
failureCount++;
if (GNUNET_OK != testMultiKey ("bar"))
GNUNET_CRYPTO_rsa_key_free (hostkey);
if (failureCount != 0)
- {
- printf ("\n\n%d TESTS FAILED!\n\n", failureCount);
- return -1;
- }
+ {
+ printf ("\n\n%d TESTS FAILED!\n\n", failureCount);
+ return -1;
+ }
return 0;
}
for (i = 0; i < 1024; i++)
GNUNET_break (1024 > (buf[i] = GNUNET_CRYPTO_random_u32 (mode, 1024)));
for (i = 0; i < 10; i++)
+ {
+ b2 = GNUNET_CRYPTO_random_permute (mode, 1024);
+ if (0 == memcmp (b2, buf, sizeof (buf)))
{
- b2 = GNUNET_CRYPTO_random_permute (mode, 1024);
- if (0 == memcmp (b2, buf, sizeof (buf)))
- {
- fprintf (stderr, "!");
- GNUNET_free (b2);
- continue;
- }
+ fprintf (stderr, "!");
GNUNET_free (b2);
- break;
+ continue;
}
+ GNUNET_free (b2);
+ break;
+ }
if (i == 10)
- return 1; /* virtually impossible... */
+ return 1; /* virtually impossible... */
for (n = 10; n < 1024LL * 1024LL * 1024LL; n *= 10)
GNUNET_break (n > GNUNET_CRYPTO_random_u64 (mode, n));
ok = 0;
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
+ {
+ fprintf (stderr, ".");
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
+ &target))
{
- fprintf (stderr, ".");
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
- &pkey, &target))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
- ok++;
- continue;
- }
- if (-1 ==
- GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
- strlen (TESTSTRING) + 1))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
- ok++;
- continue;
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
+ ok++;
+ continue;
+ }
+ if (-1 ==
+ GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
+ strlen (TESTSTRING) + 1))
+ {
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
+ ok++;
+ continue;
- }
- if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
- {
- printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
- (int) MAX_TESTVAL, result);
- ok++;
- continue;
- }
}
+ if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
+ {
+ printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
+ (int) MAX_TESTVAL, result);
+ ok++;
+ continue;
+ }
+ }
printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
GNUNET_CRYPTO_rsa_key_free (hostkey);
if (ok == 0)
return GNUNET_OK;
ok = 0;
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
+ {
+ fprintf (stderr, ".");
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
+ &target))
{
- fprintf (stderr, ".");
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
- &pkey, &target))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
- ok++;
- continue;
- }
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
+ ok++;
+ continue;
}
+ }
printf ("%d RSA encrypt operations %llu ms (%d failures)\n", ITER,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
GNUNET_CRYPTO_rsa_key_free (hostkey);
if (ok != 0)
return GNUNET_SYSERR;
ok = 0;
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
+ {
+ fprintf (stderr, ".");
+ GNUNET_CRYPTO_aes_create_session_key (&insk);
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_rsa_encrypt (&insk,
+ sizeof (struct GNUNET_CRYPTO_AesSessionKey),
+ &pkey, &target))
+ {
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
+ ok++;
+ continue;
+ }
+ if (-1 ==
+ GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, &outsk,
+ sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
+ {
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
+ ok++;
+ continue;
+ }
+ if (0 !=
+ memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
{
- fprintf (stderr, ".");
- GNUNET_CRYPTO_aes_create_session_key (&insk);
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_rsa_encrypt (&insk,
- sizeof (struct
- GNUNET_CRYPTO_AesSessionKey),
- &pkey, &target))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
- ok++;
- continue;
- }
- if (-1 ==
- GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, &outsk,
- sizeof (struct
- GNUNET_CRYPTO_AesSessionKey)))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
- ok++;
- continue;
- }
- if (0 !=
- memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
- {
- printf ("testEncryptDecryptSK failed!\n");
- ok++;
- continue;
- }
+ printf ("testEncryptDecryptSK failed!\n");
+ ok++;
+ continue;
}
+ }
printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", ITER,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
GNUNET_CRYPTO_rsa_key_free (hostkey);
if (ok != 0)
return GNUNET_SYSERR;
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
for (i = 0; i < ITER; i++)
+ {
+ fprintf (stderr, ".");
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
+ {
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
+ ok = GNUNET_SYSERR;
+ continue;
+ }
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig,
+ &pkey))
{
- fprintf (stderr, ".");
- if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
- ok = GNUNET_SYSERR;
- continue;
- }
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp,
- &sig, &pkey))
- {
- printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
- ok = GNUNET_SYSERR;
- continue;
- }
- if (GNUNET_SYSERR !=
- GNUNET_CRYPTO_rsa_verify
- (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey))
- {
- printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
- ok = GNUNET_SYSERR;
- continue;
- }
+ printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
+ ok = GNUNET_SYSERR;
+ continue;
}
+ if (GNUNET_SYSERR !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
+ &purp, &sig, &pkey))
+ {
+ printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
+ ok = GNUNET_SYSERR;
+ continue;
+ }
+ }
printf ("%d RSA sign/verify operations %llums\n", ITER,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value);
GNUNET_CRYPTO_rsa_key_free (hostkey);
return ok;
}
GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
+ {
+ fprintf (stderr, ".");
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
{
- fprintf (stderr, ".");
- if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
- {
- fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
- ok = GNUNET_SYSERR;
- continue;
- }
+ fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
+ ok = GNUNET_SYSERR;
+ continue;
}
+ }
printf ("%d RSA sign operations %llu ms\n", ITER,
- (unsigned long long)
- GNUNET_TIME_absolute_get_duration (start).rel_value);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_duration (start).rel_value);
GNUNET_CRYPTO_rsa_key_free (hostkey);
return ok;
}
failureCount++;
if (failureCount != 0)
- {
- printf ("\n\n%d TESTS FAILED!\n\n", failureCount);
- return -1;
- }
+ {
+ printf ("\n\n%d TESTS FAILED!\n\n", failureCount);
+ return -1;
+ }
return 0;
-} /* end of main */
+} /* end of main */
if (strlen (TESTSTRING) !=
GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
return 1;
if (GNUNET_OK != GNUNET_DISK_file_test (".testfile"))
return 1;
ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1);
if (ret < 0)
- {
- fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
- ".testfile");
- return 1;
- }
+ {
+ fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
+ return 1;
+ }
tmp[ret] = '\0';
if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
- {
- fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n",
- tmp, TESTSTRING, ".testfile");
- return 1;
- }
+ {
+ fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
+ TESTSTRING, ".testfile");
+ return 1;
+ }
GNUNET_DISK_file_copy (".testfile", ".testfile2");
memset (tmp, 0, sizeof (tmp));
ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
if (ret < 0)
- {
- fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
- ".testfile2");
- return 1;
- }
+ {
+ fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
+ ".testfile2");
+ return 1;
+ }
tmp[ret] = '\0';
if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
- {
- fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n",
- tmp, TESTSTRING, ".testfile2");
- return 1;
- }
+ {
+ fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
+ TESTSTRING, ".testfile2");
+ return 1;
+ }
GNUNET_break (0 == UNLINK (".testfile"));
GNUNET_break (0 == UNLINK (".testfile2"));
long avail;
fh = GNUNET_DISK_file_open (".testfile",
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5));
GNUNET_DISK_file_close (fh);
GNUNET_break (GNUNET_OK ==
- GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO));
+ GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO));
if (size != 5)
return 1;
GNUNET_break (0 == UNLINK (".testfile"));
avail = GNUNET_DISK_get_blocks_available (".testfile");
GNUNET_log_skip (0, GNUNET_NO);
fh = GNUNET_DISK_file_open (".testfile",
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_USER_READ);
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_USER_READ);
GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) &&
- (avail != -1))
+ (avail != -1))
if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16))
- {
- GNUNET_DISK_file_close (fh);
- GNUNET_break (0 == UNLINK (".testfile"));
- return 1;
- }
+ {
+ GNUNET_DISK_file_close (fh);
+ GNUNET_break (0 == UNLINK (".testfile"));
+ return 1;
+ }
GNUNET_DISK_file_close (fh);
GNUNET_break (0 == UNLINK (".testfile"));
GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
return 1;
GNUNET_DISK_directory_scan ("test", &scan_callback,
- "test" DIR_SEPARATOR_STR "entry");
+ "test" DIR_SEPARATOR_STR "entry");
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
return 1;
if (ok < 2)
static void
iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di,
- const char *filename, const char *dirname)
+ const char *filename, const char *dirname)
{
int *i = cls;
iter_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- "test", &iter_callback, cls);
+ "test", &iter_callback, cls);
}
static int
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_assert (cfg != NULL);
GNUNET_CONFIGURATION_set_value_string (cfg, "service", "HOME",
- "/tmp/test-gnunet-disk-a/b/c");
+ "/tmp/test-gnunet-disk-a/b/c");
fn = GNUNET_DISK_get_home_filename (cfg, "service", "d", "e", NULL);
GNUNET_assert (fn != NULL);
GNUNET_CONFIGURATION_destroy (cfg);
ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn);
GNUNET_free (fn);
GNUNET_break (GNUNET_OK ==
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a"));
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a"));
return ret;
}
GNUNET_DISK_filename_canonicalize (fn);
if (0 != strcmp (fn, "ab____cd_ef__g_"))
- {
- GNUNET_free (fn);
- return 1;
- }
+ {
+ GNUNET_free (fn);
+ return 1;
+ }
GNUNET_free (fn);
return 0;
}
failureCount += testChangeOwner ();
failureCount += testDirMani ();
if (failureCount != 0)
- {
- fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount);
- return -1;
- }
+ {
+ fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount);
+ return -1;
+ }
return 0;
-} /* end of main */
+} /* end of main */
};
if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
if (vflags != 2)
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
return 0;
}
};
if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
return 0;
}
};
if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
return 0;
}
};
if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
GNUNET_assert (fn != NULL);
if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename")))
- {
- GNUNET_break (0);
- GNUNET_free (level);
- GNUNET_free (fn);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_free (level);
+ GNUNET_free (fn);
+ return 1;
+ }
GNUNET_free (level);
GNUNET_free (fn);
return 0;
};
if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
if ((1 != flag) || (42 != num) || (42 != lnum))
- {
- GNUNET_break (0);
- return 1;
- }
+ {
+ GNUNET_break (0);
+ return 1;
+ }
return 0;
}
return GNUNET_OK;
inet_ntop (addr->sa_family,
- (addr->sa_family ==
- AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr
- : (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, buf,
- sizeof (buf));
+ (addr->sa_family ==
+ AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr
+ : (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, buf,
+ sizeof (buf));
if ((0 == strcmp ("::1", buf)) || (0 == strcmp ("127.0.0.1", buf)))
*ok = 0;
return GNUNET_OK;
{
if (GNUNET_OK !=
GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
- GNUNET_SCHEDULER_PRIORITY_DEFAULT))
+ GNUNET_SCHEDULER_PRIORITY_DEFAULT))
return 1;
if (GNUNET_OK !=
GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
- GNUNET_SCHEDULER_PRIORITY_UI))
+ GNUNET_SCHEDULER_PRIORITY_UI))
return 1;
if (GNUNET_OK !=
GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
- GNUNET_SCHEDULER_PRIORITY_IDLE))
+ GNUNET_SCHEDULER_PRIORITY_IDLE))
return 1;
if (GNUNET_OK !=
GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND))
+ GNUNET_SCHEDULER_PRIORITY_BACKGROUND))
return 1;
if (GNUNET_OK !=
GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
- GNUNET_SCHEDULER_PRIORITY_HIGH))
+ GNUNET_SCHEDULER_PRIORITY_HIGH))
return 1;
if (GNUNET_OK !=
GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
- GNUNET_SCHEDULER_PRIORITY_HIGH))
+ GNUNET_SCHEDULER_PRIORITY_HIGH))
return 1;
return 0;
}
{
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ }
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_close (proc);
proc = NULL;
#endif
if (bytes < 1)
- {
- GNUNET_break (0);
- ok = 1;
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_task, NULL);
- return;
- }
+ {
+ GNUNET_break (0);
+ ok = 1;
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_task, NULL);
+ return;
+ }
ok = strncmp (&buf[0], test_phrase, strlen (test_phrase));
#if VERBOSE
fprintf (stderr, "read %s\n", &buf[0]);
#endif
if (ok == 0)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_task, NULL);
- return;
- }
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ GNUNET_SCHEDULER_add_now (&end_task, NULL);
+ return;
+ }
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
- stdout_read_handle);
+ stdout_read_handle, &read_call,
+ stdout_read_handle);
}
hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
- {
- GNUNET_break (0);
- ok = 1;
- GNUNET_free (fn);
- return;
- }
+ {
+ GNUNET_break (0);
+ ok = 1;
+ GNUNET_free (fn);
+ return;
+ }
proc =
- GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn,
- "test_gnunet_echo_hello", "-", NULL);
+ GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn,
+ "test_gnunet_echo_hello", "-", NULL);
GNUNET_free (fn);
/* Close the write end of the read pipe */
/* Write the test_phrase to the cat process */
if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) !=
strlen (test_phrase) + 1)
- {
- GNUNET_break (0);
- ok = 1;
- return;
- }
+ {
+ GNUNET_break (0);
+ ok = 1;
+ return;
+ }
/* Close the write end to end the cycle! */
GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE);
stdout_read_handle =
- GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ);
die_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 1), &end_task,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 1), &end_task,
+ NULL);
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
- (void *) stdout_read_handle);
+ stdout_read_handle, &read_call,
+ (void *) stdout_read_handle);
}
GNUNET_log_setup ("test-os-start-process",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret = check ();
return ret;
int i;
for (i = 0; i < NUMBER_OF_PEERS; i++)
- {
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
- &pidArr[i].hashPubKey);
+ {
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &pidArr[i].hashPubKey);
#if DEBUG
- printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
+ printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
#endif
- }
+ }
}
GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
/* Insert Peers into PeerEntry table and hashmap */
for (i = 0; i < NUMBER_OF_PEERS; i++)
+ {
+ pid = GNUNET_PEER_intern (&pidArr[i]);
+ if (pid != (i + 1))
{
- pid = GNUNET_PEER_intern (&pidArr[i]);
- if (pid != (i + 1))
- {
- fprintf (stderr,
- "Unexpected Peer ID returned by intern function\n");
- return 1;
- }
+ fprintf (stderr, "Unexpected Peer ID returned by intern function\n");
+ return 1;
}
+ }
/* Referencing the first 3 peers once again */
for (i = 0; i < 3; i++)
+ {
+ pid = GNUNET_PEER_intern (&pidArr[i]);
+ if (pid != (i + 1))
{
- pid = GNUNET_PEER_intern (&pidArr[i]);
- if (pid != (i + 1))
- {
- fprintf (stderr,
- "Unexpected Peer ID returned by intern function\n");
- return 1;
- }
+ fprintf (stderr, "Unexpected Peer ID returned by intern function\n");
+ return 1;
}
+ }
/* Dereferencing the first 3 peers once [decrementing their reference count] */
GNUNET_PEER_decrement_rcs (ids, 3);
GNUNET_log_setup ("test-peer", "ERROR", NULL);
for (i = 0; i < 1; i++)
- {
- generatePeerIdList ();
- if (0 != check ())
- return 1;
- }
+ {
+ generatePeerIdList ();
+ if (0 != check ())
+ return 1;
+ }
return 0;
}
#define VERBOSE GNUNET_EXTRA_LOGGING
static void
-test_cb (void *cls,
- const char *libname,
- void *lib_ret)
+test_cb (void *cls, const char *libname, void *lib_ret)
{
void *ret;
GNUNET_assert (NULL != ret);
GNUNET_assert (0 == strcmp (ret, "World"));
}
-
+
static int
check ()
static void
runner (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
int *ok = cls;
};
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
- options1, &runner, &ok));
+ GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
+ options1, &runner, &ok));
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
- options2, &runner, &ok));
+ GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
+ options2, &runner, &ok));
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
- options3, &runner, &ok));
+ GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
+ options3, &runner, &ok));
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
- options4, &runner, &ok));
+ GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
+ options4, &runner, &ok));
return ok;
}
if ((0 == memcmp (pseudonym, &id1, sizeof (GNUNET_HashCode))) &&
(!GNUNET_CONTAINER_meta_data_test_equal (md, meta)))
- {
- *ok = GNUNET_NO;
- GNUNET_break (0);
- }
+ {
+ *ok = GNUNET_NO;
+ GNUNET_break (0);
+ }
return GNUNET_OK;
}
static int
noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
- const struct GNUNET_CONTAINER_MetaData *md, int rating)
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
int *ret = cls;
static int
fake_noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
- const struct GNUNET_CONTAINER_MetaData *md, int rating)
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
int *ret = cls;
static int
false_callback (void *cls, const GNUNET_HashCode * pseudonym,
- const struct GNUNET_CONTAINER_MetaData *md, int rating)
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
{
return GNUNET_OK;
}
(void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test");
cfg = GNUNET_CONFIGURATION_create ();
if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf"))
- {
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_break (0);
- return -1;
- }
+ {
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_break (0);
+ return -1;
+ }
notiCount = 0;
fakenotiCount = 0;
count = 0;
GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback,
- &fakenotiCount);
+ &fakenotiCount);
GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback,
- ¬iCount);
+ ¬iCount);
GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count);
GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback,
- &fakenotiCount);
+ &fakenotiCount);
/* ACTUAL TEST CODE */
old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_UTF8, "text/plain",
- "test", strlen ("test") + 1);
+ EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+ "test", strlen ("test") + 1);
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1);
GNUNET_PSEUDONYM_add (cfg, &id1, meta);
CHECK (notiCount == 1);
newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
CHECK (old < newVal);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
- EXTRACTOR_METATYPE_COMMENT,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", m,
- strlen (m) + 1));
+ GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
+ EXTRACTOR_METATYPE_COMMENT,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", m,
+ strlen (m) + 1));
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3);
GNUNET_PSEUDONYM_add (cfg, &id3, meta);
name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3);
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_break (GNUNET_OK ==
- GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
return (ok == GNUNET_YES) ? 0 : 1;
}
int *ok = cls;
if (salen == 0)
- {
- (*ok) &= ~8;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Got IP address `%s' for our host.\n"), GNUNET_a2s (sa,
- salen));
+ {
+ (*ok) &= ~8;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"),
+ GNUNET_a2s (sa, salen));
}
if (hostname == NULL)
return;
if (0 == strcmp (hostname, "127.0.0.1"))
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received correct hostname `%s'.\n", hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
+ hostname);
#endif
- (*ok) &= ~4;
- }
+ (*ok) &= ~4;
+ }
else
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received invalid hostname `%s'.\n", hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received invalid hostname `%s'.\n",
+ hostname);
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
}
if (hostname == NULL)
return;
if (0 == strcmp (hostname, "localhost"))
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received correct hostname `%s'.\n", hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
+ hostname);
#endif
- (*ok) &= ~2;
- }
+ (*ok) &= ~2;
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n",
- hostname);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n",
+ hostname);
+ }
}
static void
return;
GNUNET_assert (sizeof (struct sockaddr_in) == salen);
if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK))
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n");
#endif
- (*ok) &= ~1;
- }
+ (*ok) &= ~1;
+ }
else
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n");
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
}
static void
char hostname[GNUNET_OS_get_hostname_max_length () + 1];
if (0 != gethostname (hostname, sizeof (hostname) - 1))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "gethostname");
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "gethostname");
+ return;
+ }
#if DEBUG_RESOLVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"),
- hostname);
+ hostname);
#endif
host = gethostbyname (hostname);
if (NULL == host)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not resolve our FQDN : %s %u\n"),
- hstrerror (h_errno), h_errno);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not resolve our FQDN : %s %u\n"), hstrerror (h_errno),
+ h_errno);
+ return;
+ }
GNUNET_assert (0 != host);
result = strcmp (host->h_name, gnunet_fqdn);
if (0 != result)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Local resolved and resolver resolved fqdns are not equal\n");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Local resolved and resolver resolved fqdns are not equal\n");
+ }
GNUNET_assert (0 == result);
}
GNUNET_assert (sizeof (struct sockaddr_in) == salen);
if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP))
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received correct rootserver ip address.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received correct rootserver ip address.\n");
#endif
- (*ok) &= ~1;
- }
+ (*ok) &= ~1;
+ }
else
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received incorrect rootserver ip address.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received incorrect rootserver ip address.\n");
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
}
static void
return;
if (0 == strcmp (hostname, ROOTSERVER_NAME))
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received correct rootserver hostname `%s'.\n", hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received correct rootserver hostname `%s'.\n", hostname);
#endif
- (*ok) &= ~2;
- }
+ (*ok) &= ~2;
+ }
else
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received invalid rootserver hostname `%s'.\n", hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received invalid rootserver hostname `%s'.\n", hostname);
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
}
static void
int *ok = cls;
struct sockaddr_in sa;
struct GNUNET_TIME_Relative timeout =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
int count_ips = 0;
char *own_fqdn;
rootserver = gethostbyname (rootserver_name);
if (rootserver == NULL)
- {
- /* Error: resolving ip addresses does not work */
+ {
+ /* Error: resolving ip addresses does not work */
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("gethostbyname() could not lookup IP address: %s\n"),
- hstrerror (h_errno));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("gethostbyname() could not lookup IP address: %s\n"),
+ hstrerror (h_errno));
#endif
- fprintf (stderr,
- "System seems to be off-line, will not run all DNS tests\n");
- *ok = 0; /* mark test as passing anyway */
- return;
- }
+ fprintf (stderr,
+ "System seems to be off-line, will not run all DNS tests\n");
+ *ok = 0; /* mark test as passing anyway */
+ return;
+ }
/* Counting returned IP addresses */
while (rootserver->h_addr_list[count_ips] != NULL)
count_ips++;
if (count_ips > 1)
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "IP received range for root name server, but a root name server has only 1 IP\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "IP received range for root name server, but a root name server has only 1 IP\n");
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
/* Comparing to resolved address to the address the root name server should have */
if (strcmp
(inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]),
ROOTSERVER_IP) != 0)
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "IP received and IP for root name server differ\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "IP received and IP for root name server differ\n");
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
#if DEBUG_RESOLVER
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "System's own forward name resolution is working\n");
+ "System's own forward name resolution is working\n");
#endif
/* Resolve the same using GNUNET */
GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout,
- &check_rootserver_ip, cls);
+ &check_rootserver_ip, cls);
/*
* Success: forward lookups work as expected
rootserver->h_name = "";
if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr))
- {
+ {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not transform root name server IP address\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not transform root name server IP address\n");
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
rootserver =
- gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET);
+ gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET);
if (rootserver == NULL)
- {
- /* Error: resolving IP addresses does not work */
+ {
+ /* Error: resolving IP addresses does not work */
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("gethostbyaddr() could not lookup hostname: %s\n"),
- hstrerror (h_errno));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("gethostbyaddr() could not lookup hostname: %s\n"),
+ hstrerror (h_errno));
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
else
+ {
+ if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME))
{
- if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME))
- {
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received hostname and hostname for root name server differ\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received hostname and hostname for root name server differ\n");
#endif
- GNUNET_break (0);
- }
+ GNUNET_break (0);
}
+ }
#if DEBUG_RESOLVER
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "System's own reverse name resolution is working\n");
+ "System's own reverse name resolution is working\n");
#endif
/* Resolve the same using GNUNET */
sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP);
#endif
GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
- sizeof (struct sockaddr), GNUNET_YES, timeout,
- &check_rootserver_name, cls);
+ sizeof (struct sockaddr), GNUNET_YES, timeout,
+ &check_rootserver_name, cls);
memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls);
GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
- sizeof (struct sockaddr), GNUNET_YES, timeout,
- &check_localhost, cls);
+ sizeof (struct sockaddr), GNUNET_YES, timeout,
+ &check_localhost, cls);
GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
- sizeof (struct sockaddr), GNUNET_NO, timeout,
- &check_localhost_num, cls);
+ sizeof (struct sockaddr), GNUNET_NO, timeout,
+ &check_localhost_num, cls);
GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls);
}
struct GNUNET_OS_Process *proc;
char *const argv[] =
- { "test-resolver-api", "-c", "test_resolver_api_data.conf",
+ { "test-resolver-api", "-c", "test_resolver_api_data.conf",
#if VERBOSE
"-L", "DEBUG",
#endif
NULL
};
struct GNUNET_GETOPT_CommandLineOption options[] =
- { GNUNET_GETOPT_OPTION_END };
+ { GNUNET_GETOPT_OPTION_END };
pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR);
GNUNET_free (pfx);
proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", "test_resolver_api_data.conf", NULL);
+ "-c", "test_resolver_api_data.conf", NULL);
GNUNET_assert (NULL != proc);
GNUNET_free (fn);
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-resolver-api", "nohelp",
- options, &run, &ok));
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv, "test-resolver-api", "nohelp",
+ options, &run, &ok));
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- ok = 1;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ ok = 1;
+ }
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_close (proc);
proc = NULL;
GNUNET_log_setup ("test-resolver-api",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret = check ();
return ret;
/* t4 should be ready (albeit with lower priority) */
GNUNET_assert (1 ==
- GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
+ GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
GNUNET_assert (3 == *ok);
(*ok) = 4;
}
(*ok) = 3;
/* t3 will go before t4: higher priority */
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task3,
- cls);
+ cls);
}
static void
GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
(*ok) = 8;
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &taskLast, cls);
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast,
+ cls);
GNUNET_SCHEDULER_shutdown ();
}
GNUNET_assert (NULL != p);
fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0],
- &taskRd, cls);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd,
+ cls);
GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1],
- &taskWrt, cls);
+ &taskWrt, cls);
}
GNUNET_assert (1 == *ok);
*ok = 0;
GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after
- (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL));
+ (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL));
}
else
cumDelta += (target.abs_value - now.abs_value);
target =
- GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, i));
+ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, i));
fprintf (stderr, ".");
if (i > MAXV)
- {
- fprintf (stderr, "\n");
- return;
- }
+ {
+ fprintf (stderr, "\n");
+ return;
+ }
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, i),
- &test_task, NULL);
+ (GNUNET_TIME_UNIT_MILLISECONDS, i), &test_task,
+ NULL);
i += INCR;
}
target = GNUNET_TIME_absolute_get ();
GNUNET_SCHEDULER_run (&test_task, NULL);
FPRINTF (stdout, "Sleep precision: %llu ms. ",
- cumDelta / 1000 / (MAXV / INCR));
+ cumDelta / 1000 / (MAXV / INCR));
if (cumDelta <= 10 * MAXV / INCR)
fprintf (stdout, "Timer precision is excellent.\n");
- else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */
+ else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */
fprintf (stdout, "Timer precision is good.\n");
else if (cumDelta > 250 * MAXV / INCR)
fprintf (stdout, "Timer precision is awful.\n");
static void
recv_fin_cb (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (ok == 5);
ok = 6;
static void
recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (ok == 2);
ok = 3;
argclient = client;
GNUNET_SERVER_client_keep (argclient);
- GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
- ntohs (message->size));
+ GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size));
GNUNET_assert (MY_TYPE == ntohs (message->type));
GNUNET_assert (NULL !=
- GNUNET_SERVER_notify_transmit_ready (client,
- ntohs (message->size),
- TIMEOUT, &reply_msg,
- NULL));
+ GNUNET_SERVER_notify_transmit_ready (client,
+ ntohs (message->size),
+ TIMEOUT, &reply_msg,
+ NULL));
}
transmit_initial_message (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader msg;
-
+
GNUNET_assert (ok == 1);
ok = 2;
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
msg.size = htons (sizeof (struct GNUNET_MessageHeader));
memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader));
GNUNET_assert (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (cc,
- sizeof (struct
- GNUNET_MessageHeader),
- TIMEOUT, GNUNET_YES,
- &transmit_second_message,
- NULL));
+ GNUNET_CLIENT_notify_transmit_ready (cc,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ TIMEOUT, GNUNET_YES,
+ &transmit_second_message,
+ NULL));
GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT);
return sizeof (struct GNUNET_MessageHeader);
}
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
- "localhost");
+ "localhost");
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
cc = GNUNET_CLIENT_connect ("test-server", cfg);
GNUNET_assert (cc != NULL);
GNUNET_assert (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (cc,
- sizeof (struct
- GNUNET_MessageHeader),
- TIMEOUT, GNUNET_YES,
- &transmit_initial_message,
- NULL));
+ GNUNET_CLIENT_notify_transmit_ready (cc,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ TIMEOUT, GNUNET_YES,
+ &transmit_initial_message,
+ NULL));
}
static void
recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (ok == 2);
ok = 3;
GNUNET_SERVER_client_keep (client);
GNUNET_SCHEDULER_add_now (&server_disconnect, client);
- GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
- ntohs (message->size));
+ GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size));
GNUNET_assert (MY_TYPE == ntohs (message->type));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
- "localhost");
+ "localhost");
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
cc = GNUNET_CLIENT_connect ("test-server", cfg);
GNUNET_assert (cc != NULL);
GNUNET_assert (NULL !=
- GNUNET_CLIENT_notify_transmit_ready (cc,
- sizeof (struct
- GNUNET_MessageHeader),
- TIMEOUT, GNUNET_YES,
- &transmit_initial_message,
- NULL));
+ GNUNET_CLIENT_notify_transmit_ready (cc,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ TIMEOUT, GNUNET_YES,
+ &transmit_initial_message,
+ NULL));
}
static void
recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
void *addr;
size_t addrlen;
struct sockaddr_in *have;
GNUNET_assert (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (argclient, &addr,
- &addrlen));
+ GNUNET_SERVER_client_get_address (argclient, &addr, &addrlen));
GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
have = addr;
GNUNET_assert (0 == memcmp (&sa, addr, addrlen));
GNUNET_free (addr);
switch (ok)
- {
- case 2:
- ok++;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 50),
- &send_done, argclient);
- break;
- case 4:
- ok++;
- GNUNET_CLIENT_disconnect (client, GNUNET_YES);
- GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
- break;
- default:
- GNUNET_assert (0);
- }
+ {
+ case 2:
+ ok++;
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 50),
+ &send_done, argclient);
+ break;
+ case 4:
+ ok++;
+ GNUNET_CLIENT_disconnect (client, GNUNET_YES);
+ GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
}
sa.sin_family = AF_INET;
sa.sin_port = htons (PORT);
server =
- GNUNET_SERVER_create (NULL, NULL, sap, slens,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
+ GNUNET_SERVER_create (NULL, NULL, sap, slens,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
GNUNET_assert (server != NULL);
handlers[0].callback_cls = cls;
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls);
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT);
- GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME",
- "localhost");
+ GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
client = GNUNET_CLIENT_connect ("test", cfg);
GNUNET_assert (client != NULL);
GNUNET_CLIENT_notify_transmit_ready (client, 256,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 250),
- GNUNET_NO, ¬ify_ready, NULL);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 250),
+ GNUNET_NO, ¬ify_ready, NULL);
}
GNUNET_log_setup ("test_server_with_client",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check ();
return ret;
static void
recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
switch (ok)
- {
- case 2:
- ok++;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 50),
- &send_done, argclient);
- break;
- case 4:
- ok++;
- GNUNET_CLIENT_disconnect (client, GNUNET_YES);
- GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
- break;
- default:
- GNUNET_assert (0);
- }
+ {
+ case 2:
+ ok++;
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 50),
+ &send_done, argclient);
+ break;
+ case 4:
+ ok++;
+ GNUNET_CLIENT_disconnect (client, GNUNET_YES);
+ GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
}
sap[1] = NULL;
slens[1] = 0;
server =
- GNUNET_SERVER_create (NULL, NULL, sap, slens,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
+ GNUNET_SERVER_create (NULL, NULL, sap, slens,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
GNUNET_assert (server != NULL);
handlers[0].callback_cls = cls;
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath);
GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
- "localhost");
+ "localhost");
client = GNUNET_CLIENT_connect ("test", cfg);
GNUNET_assert (client != NULL);
GNUNET_CLIENT_notify_transmit_ready (client, 256,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 250),
- GNUNET_NO, ¬ify_ready, NULL);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 250),
+ GNUNET_NO, ¬ify_ready, NULL);
}
GNUNET_log_setup ("test_server_with_client_unix",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check ();
return ret;
client = GNUNET_CLIENT_connect ("test_service", cfg);
GNUNET_assert (client != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client connecting, waiting to transmit\n");
+ "Client connecting, waiting to transmit\n");
GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
- &build_msg, client);
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
+ &build_msg, client);
}
static void
recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
static void
runner (void *cls, struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n");
GNUNET_SERVER_add_handlers (server, myhandlers);
GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS,
- &ready, (void *) cfg);
+ &ready, (void *) cfg);
}
};
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service\n");
GNUNET_assert (GNUNET_OK ==
- GNUNET_SERVICE_run (5, argv, "test_service",
- GNUNET_SERVICE_OPTION_NONE, &runner,
- &ok));
+ GNUNET_SERVICE_run (5, argv, "test_service",
+ GNUNET_SERVICE_OPTION_NONE, &runner, &ok));
GNUNET_assert (0 == ok);
return ok;
}
GNUNET_assert (client != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n");
GNUNET_CLIENT_notify_transmit_ready (client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
- &build_msg, client);
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
+ &build_msg, client);
}
static void
runner6 (void *cls, struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing v6 service\n");
GNUNET_SERVER_add_handlers (server, myhandlers);
GNUNET_CLIENT_service_test ("test_service6", cfg, GNUNET_TIME_UNIT_SECONDS,
- &ready6, (void *) cfg);
+ &ready6, (void *) cfg);
}
/**
};
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting v6 service\n");
GNUNET_assert (GNUNET_OK ==
- GNUNET_SERVICE_run (5, argv, "test_service6",
- GNUNET_SERVICE_OPTION_NONE, &runner6,
- &ok));
+ GNUNET_SERVICE_run (5, argv, "test_service6",
+ GNUNET_SERVICE_OPTION_NONE, &runner6,
+ &ok));
GNUNET_assert (0 == ok);
return ok;
}
static void
start_stop_main (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
int *ret = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting service using start method\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service using start method\n");
sctx = GNUNET_SERVICE_start ("test_service", cfg);
GNUNET_assert (NULL != sctx);
runner (cls, GNUNET_SERVICE_get_server (sctx), cfg);
int ret = 1;
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run (5, argv, "test-service-program",
- "no help", options, &start_stop_main,
- &ret));
+ GNUNET_PROGRAM_run (5, argv, "test-service-program", "no help",
+ options, &start_stop_main, &ret));
GNUNET_break (0 == ret);
return ret;
GNUNET_log_setup ("test-service",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret += check ();
ret += check ();
s = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
#endif
if (NULL == s)
+ {
+ if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
+ (errno == EACCES))
{
- if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
- (errno == EACCES))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
- return 1;
- }
- fprintf (stderr,
- "IPv6 support seems to not be available (%s), not testing it!\n",
- strerror (errno));
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ return 1;
}
+ fprintf (stderr,
+ "IPv6 support seems to not be available (%s), not testing it!\n",
+ strerror (errno));
+ }
else
- {
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
- ret += check6 ();
- }
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
+ ret += check6 ();
+ }
ret += check_start_stop ();
return ret;
WANT (buf, b);
sprintf (buf, "4 %s", _( /* time unit */ "ms"));
b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS,
- 4));
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 4));
WANT (buf, b);
sprintf (buf, "7 %s", _( /* time unit */ "s"));
b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS,
- 7 * 1000));
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 7 * 1000));
WANT (buf, b);
sprintf (buf, "7 %s", _( /* time unit */ "h"));
b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS,
- 7 * 60 * 60 * 1000));
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ 7 * 60 * 60 * 1000));
WANT (buf, b);
#ifndef MINGW
hdir = getenv ("HOME");
* where the details of the day and hour depend on the timezone;
* however, the "0:05 19" should always be there; hence: */
if (NULL == strstr (r, "0:05 19"))
- {
- fprintf (stderr, "Got %s\n", r);
- GNUNET_break (0);
- GNUNET_free (r);
- return 1;
- }
+ {
+ fprintf (stderr, "Got %s\n", r);
+ GNUNET_break (0);
+ GNUNET_free (r);
+ return 1;
+ }
GNUNET_free (r);
b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
WANT ("TEST", b);
/*check zero */
rel.rel_value = (UINT64_MAX) - 1024;
GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value ==
- GNUNET_TIME_relative_multiply (rel, 0).rel_value);
+ GNUNET_TIME_relative_multiply (rel, 0).rel_value);
/* test infinity-check for relative to absolute */
GNUNET_log_skip (1, GNUNET_NO);
/*check relative to absolute */
rel.rel_value = 0;
GNUNET_assert (GNUNET_TIME_absolute_get ().abs_value ==
- GNUNET_TIME_relative_to_absolute (rel).abs_value);
+ GNUNET_TIME_relative_to_absolute (rel).abs_value);
/*check forever */
rel.rel_value = UINT64_MAX;
GNUNET_assert (GNUNET_TIME_absolute_get_forever ().abs_value ==
- GNUNET_TIME_relative_to_absolute (rel).abs_value);
+ GNUNET_TIME_relative_to_absolute (rel).abs_value);
/* check overflow for r2a */
rel.rel_value = (UINT64_MAX) - 1024;
GNUNET_log_skip (1, GNUNET_NO);
/* check relation check in get_duration */
future.abs_value = now.abs_value + 1000000;
- GNUNET_assert (GNUNET_TIME_absolute_get_difference (now, future).rel_value
- == 1000000);
- GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value
- == 0);
+ GNUNET_assert (GNUNET_TIME_absolute_get_difference (now, future).rel_value ==
+ 1000000);
+ GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value ==
+ 0);
GNUNET_assert (GNUNET_TIME_absolute_get_difference (zero, forever).rel_value
- == forever.abs_value);
+ == forever.abs_value);
past.abs_value = now.abs_value - 1000000;
rel = GNUNET_TIME_absolute_get_duration (future);
GNUNET_assert (rel.rel_value <= 1000000);
forever = GNUNET_TIME_absolute_get_forever ();
GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value ==
- GNUNET_TIME_absolute_get_remaining (forever).rel_value);
+ GNUNET_TIME_absolute_get_remaining (forever).rel_value);
/* check endianess */
reln = GNUNET_TIME_relative_hton (rel);
GNUNET_assert (future.abs_value == now.abs_value);
GNUNET_assert (forever.abs_value ==
- GNUNET_TIME_absolute_subtract (forever,
- GNUNET_TIME_UNIT_MINUTES).abs_value);
+ GNUNET_TIME_absolute_subtract (forever,
+ GNUNET_TIME_UNIT_MINUTES).abs_value);
/*check absolute subtract */
now.abs_value = 50000;
rel.rel_value = 100000;
GNUNET_assert (GNUNET_TIME_UNIT_ZERO_ABS.abs_value ==
- (GNUNET_TIME_absolute_subtract (now, rel)).abs_value);
+ (GNUNET_TIME_absolute_subtract (now, rel)).abs_value);
rel.rel_value = 10000;
- GNUNET_assert (40000 ==
- (GNUNET_TIME_absolute_subtract (now, rel)).abs_value);
+ GNUNET_assert (40000 == (GNUNET_TIME_absolute_subtract (now, rel)).abs_value);
/*check relative divide */
GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
- (GNUNET_TIME_relative_divide (rel, 0)).rel_value);
+ (GNUNET_TIME_relative_divide (rel, 0)).rel_value);
rel = GNUNET_TIME_UNIT_FOREVER_REL;
GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
- (GNUNET_TIME_relative_divide (rel, 2)).rel_value);
+ (GNUNET_TIME_relative_divide (rel, 2)).rel_value);
rel = GNUNET_TIME_relative_divide (relUnit, 2);
GNUNET_assert (rel.rel_value == relUnit.rel_value / 2);
forever = GNUNET_TIME_absolute_get_forever ();
forever.abs_value = forever.abs_value - 1024;
GNUNET_assert (GNUNET_TIME_absolute_get_zero ().abs_value ==
- GNUNET_TIME_calculate_eta (forever, 50000,
- 100000).rel_value);
+ GNUNET_TIME_calculate_eta (forever, 50000, 100000).rel_value);
/* check zero */
GNUNET_log_skip (1, GNUNET_NO);
GNUNET_assert (GNUNET_TIME_UNIT_ZERO.rel_value ==
- (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value);
+ (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value);
GNUNET_log_skip (0, GNUNET_YES);
/*check forever */
GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
- (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value);
+ (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value);
/*check relative subtract */
now = GNUNET_TIME_absolute_get ();
rel.rel_value = now.abs_value;
relForever.rel_value = rel.rel_value + 1024;
GNUNET_assert (1024 ==
- GNUNET_TIME_relative_subtract (relForever, rel).rel_value);
+ GNUNET_TIME_relative_subtract (relForever, rel).rel_value);
/*check zero */
GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value ==
- GNUNET_TIME_relative_subtract (rel, relForever).rel_value);
+ GNUNET_TIME_relative_subtract (rel, relForever).rel_value);
/*check forever */
rel.rel_value = UINT64_MAX;
GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value ==
- GNUNET_TIME_relative_subtract (rel, relForever).rel_value);
+ GNUNET_TIME_relative_subtract (rel, relForever).rel_value);
/*check GNUNET_TIME_relative_min */
now = GNUNET_TIME_absolute_get ();
rel.rel_value = now.abs_value;
relForever.rel_value = rel.rel_value - 1024;
GNUNET_assert (relForever.rel_value ==
- GNUNET_TIME_relative_min (rel, relForever).rel_value);
+ GNUNET_TIME_relative_min (rel, relForever).rel_value);
/*check GNUNET_TIME_relative_max */
GNUNET_assert (rel.rel_value ==
- GNUNET_TIME_relative_max (rel, relForever).rel_value);
+ GNUNET_TIME_relative_max (rel, relForever).rel_value);
/*check GNUNET_TIME_absolute_min */
now = GNUNET_TIME_absolute_get ();
last.abs_value = now.abs_value - 1024;
GNUNET_assert (last.abs_value ==
- GNUNET_TIME_absolute_min (now, last).abs_value);
+ GNUNET_TIME_absolute_min (now, last).abs_value);
/*check GNUNET_TIME_absolute_max */
GNUNET_assert (now.abs_value ==
- GNUNET_TIME_absolute_max (now, last).abs_value);
+ GNUNET_TIME_absolute_max (now, last).abs_value);
return 0;
}
GETTIMEOFDAY (&tv, NULL);
ret.abs_value =
- (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) +
- ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset;
+ (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) +
+ ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset;
return ret;
}
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
if (rel.rel_value + now.abs_value < rel.rel_value)
- {
- GNUNET_break (0); /* overflow... */
- return GNUNET_TIME_absolute_get_forever ();
- }
+ {
+ GNUNET_break (0); /* overflow... */
+ return GNUNET_TIME_absolute_get_forever ();
+ }
ret.abs_value = rel.rel_value + now.abs_value;
return ret;
}
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
- struct GNUNET_TIME_Relative t2)
+ struct GNUNET_TIME_Relative t2)
{
return (t1.rel_value < t2.rel_value) ? t1 : t2;
}
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
- struct GNUNET_TIME_Relative t2)
+ struct GNUNET_TIME_Relative t2)
{
return (t1.rel_value > t2.rel_value) ? t1 : t2;
}
*/
struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
- struct GNUNET_TIME_Absolute t2)
+ struct GNUNET_TIME_Absolute t2)
{
return (t1.abs_value < t2.abs_value) ? t1 : t2;
}
*/
struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
- struct GNUNET_TIME_Absolute t2)
+ struct GNUNET_TIME_Absolute t2)
{
return (t1.abs_value > t2.abs_value) ? t1 : t2;
}
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start,
- struct GNUNET_TIME_Absolute end)
+ struct GNUNET_TIME_Absolute end)
{
struct GNUNET_TIME_Relative ret;
*/
struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
- struct GNUNET_TIME_Relative duration)
+ struct GNUNET_TIME_Relative duration)
{
struct GNUNET_TIME_Absolute ret;
if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX))
return GNUNET_TIME_absolute_get_forever ();
if (start.abs_value + duration.rel_value < start.abs_value)
- {
- GNUNET_break (0);
- return GNUNET_TIME_absolute_get_forever ();
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_TIME_absolute_get_forever ();
+ }
ret.abs_value = start.abs_value + duration.rel_value;
return ret;
}
*/
struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
- struct GNUNET_TIME_Relative duration)
+ struct GNUNET_TIME_Relative duration)
{
struct GNUNET_TIME_Absolute ret;
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
- unsigned int factor)
+ unsigned int factor)
{
struct GNUNET_TIME_Relative ret;
return GNUNET_TIME_relative_get_zero ();
ret.rel_value = rel.rel_value * (unsigned long long) factor;
if (ret.rel_value / factor != rel.rel_value)
- {
- GNUNET_break (0);
- return GNUNET_TIME_relative_get_forever ();
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_TIME_relative_get_forever ();
+ }
return ret;
}
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
- unsigned int factor)
+ unsigned int factor)
{
struct GNUNET_TIME_Relative ret;
* assuming it continues at the same speed
*/
struct GNUNET_TIME_Relative
-GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
- uint64_t finished, uint64_t total)
+GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished,
+ uint64_t total)
{
struct GNUNET_TIME_Relative dur;
double exp;
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
- struct GNUNET_TIME_Relative a2)
+ struct GNUNET_TIME_Relative a2)
{
struct GNUNET_TIME_Relative ret;
if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX))
return GNUNET_TIME_relative_get_forever ();
if (a1.rel_value + a2.rel_value < a1.rel_value)
- {
- GNUNET_break (0);
- return GNUNET_TIME_relative_get_forever ();
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_TIME_relative_get_forever ();
+ }
ret.rel_value = a1.rel_value + a2.rel_value;
return ret;
}
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1,
- struct GNUNET_TIME_Relative a2)
+ struct GNUNET_TIME_Relative a2)
{
struct GNUNET_TIME_Relative ret;
void
plibc_panic (int err, char *msg)
{
- LOG (((err ==
- INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
+ LOG (((err == INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
"%s", msg);
}
/* Function to get CPU usage under Win NT */
if (hNTDLL)
- {
- GNNtQuerySystemInformation =
- (TNtQuerySystemInformation) GetProcAddress (hNTDLL,
- "NtQuerySystemInformation");
- }
+ {
+ GNNtQuerySystemInformation =
+ (TNtQuerySystemInformation) GetProcAddress (hNTDLL,
+ "NtQuerySystemInformation");
+ }
else
- {
- GNNtQuerySystemInformation = NULL;
- }
+ {
+ GNNtQuerySystemInformation = NULL;
+ }
/* Functions to get information about a network adapter */
hIphlpapi = LoadLibrary ("iphlpapi.dll");
if (hIphlpapi)
- {
- GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
- GNGetIpAddrTable =
- (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable");
- GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
- GNGetBestInterface =
- (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface");
- GGetAdaptersInfo =
- (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo");
- }
+ {
+ GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
+ GNGetIpAddrTable =
+ (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable");
+ GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
+ GNGetBestInterface =
+ (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface");
+ GGetAdaptersInfo =
+ (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo");
+ }
else
- {
- GNGetIfEntry = NULL;
- GNGetIpAddrTable = NULL;
- GNGetIfTable = NULL;
- GNGetBestInterface = NULL;
- GGetAdaptersInfo = NULL;
- }
+ {
+ GNGetIfEntry = NULL;
+ GNGetIpAddrTable = NULL;
+ GNGetIfTable = NULL;
+ GNGetBestInterface = NULL;
+ GGetAdaptersInfo = NULL;
+ }
/* Service & Account functions */
hAdvapi = LoadLibrary ("advapi32.dll");
if (hAdvapi)
- {
- GNOpenSCManager =
- (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA");
- GNCreateService =
- (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA");
- GNCloseServiceHandle =
- (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle");
- GNDeleteService =
- (TDeleteService) GetProcAddress (hAdvapi, "DeleteService");
- GNRegisterServiceCtrlHandler =
- (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi,
- "RegisterServiceCtrlHandlerA");
- GNSetServiceStatus =
- (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus");
- GNStartServiceCtrlDispatcher =
- (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi,
- "StartServiceCtrlDispatcherA");
- GNControlService =
- (TControlService) GetProcAddress (hAdvapi, "ControlService");
- GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
+ {
+ GNOpenSCManager =
+ (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA");
+ GNCreateService =
+ (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA");
+ GNCloseServiceHandle =
+ (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle");
+ GNDeleteService =
+ (TDeleteService) GetProcAddress (hAdvapi, "DeleteService");
+ GNRegisterServiceCtrlHandler =
+ (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi,
+ "RegisterServiceCtrlHandlerA");
+ GNSetServiceStatus =
+ (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus");
+ GNStartServiceCtrlDispatcher =
+ (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi,
+ "StartServiceCtrlDispatcherA");
+ GNControlService =
+ (TControlService) GetProcAddress (hAdvapi, "ControlService");
+ GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
- GNLsaOpenPolicy =
- (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy");
- GNLsaAddAccountRights =
- (TLsaAddAccountRights) GetProcAddress (hAdvapi,
- "LsaAddAccountRights");
- GNLsaRemoveAccountRights =
- (TLsaRemoveAccountRights) GetProcAddress (hAdvapi,
- "LsaRemoveAccountRights");
- GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
- GNLookupAccountName =
- (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA");
+ GNLsaOpenPolicy =
+ (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy");
+ GNLsaAddAccountRights =
+ (TLsaAddAccountRights) GetProcAddress (hAdvapi, "LsaAddAccountRights");
+ GNLsaRemoveAccountRights =
+ (TLsaRemoveAccountRights) GetProcAddress (hAdvapi,
+ "LsaRemoveAccountRights");
+ GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
+ GNLookupAccountName =
+ (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA");
- GNGetFileSecurity =
- (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA");
- GNInitializeSecurityDescriptor =
- (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi,
- "InitializeSecurityDescriptor");
- GNGetSecurityDescriptorDacl =
- (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi,
- "GetSecurityDescriptorDacl");
- GNGetAclInformation =
- (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation");
- GNInitializeAcl =
- (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl");
- GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
- GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
- GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
- GNAddAccessAllowedAce =
- (TAddAccessAllowedAce) GetProcAddress (hAdvapi,
- "AddAccessAllowedAce");
- GNSetNamedSecurityInfo =
- (TSetNamedSecurityInfo) GetProcAddress (hAdvapi,
- "SetNamedSecurityInfoA");
- }
+ GNGetFileSecurity =
+ (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA");
+ GNInitializeSecurityDescriptor =
+ (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi,
+ "InitializeSecurityDescriptor");
+ GNGetSecurityDescriptorDacl =
+ (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi,
+ "GetSecurityDescriptorDacl");
+ GNGetAclInformation =
+ (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation");
+ GNInitializeAcl =
+ (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl");
+ GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
+ GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
+ GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
+ GNAddAccessAllowedAce =
+ (TAddAccessAllowedAce) GetProcAddress (hAdvapi, "AddAccessAllowedAce");
+ GNSetNamedSecurityInfo =
+ (TSetNamedSecurityInfo) GetProcAddress (hAdvapi,
+ "SetNamedSecurityInfoA");
+ }
else
- {
- GNOpenSCManager = NULL;
- GNCreateService = NULL;
- GNCloseServiceHandle = NULL;
- GNDeleteService = NULL;
- GNRegisterServiceCtrlHandler = NULL;
- GNSetServiceStatus = NULL;
- GNStartServiceCtrlDispatcher = NULL;
- GNControlService = NULL;
- GNOpenService = NULL;
+ {
+ GNOpenSCManager = NULL;
+ GNCreateService = NULL;
+ GNCloseServiceHandle = NULL;
+ GNDeleteService = NULL;
+ GNRegisterServiceCtrlHandler = NULL;
+ GNSetServiceStatus = NULL;
+ GNStartServiceCtrlDispatcher = NULL;
+ GNControlService = NULL;
+ GNOpenService = NULL;
- GNLsaOpenPolicy = NULL;
- GNLsaAddAccountRights = NULL;
- GNLsaRemoveAccountRights = NULL;
- GNLsaClose = NULL;
- GNLookupAccountName = NULL;
+ GNLsaOpenPolicy = NULL;
+ GNLsaAddAccountRights = NULL;
+ GNLsaRemoveAccountRights = NULL;
+ GNLsaClose = NULL;
+ GNLookupAccountName = NULL;
- GNGetFileSecurity = NULL;
- GNInitializeSecurityDescriptor = NULL;
- GNGetSecurityDescriptorDacl = NULL;
- GNGetAclInformation = NULL;
- GNInitializeAcl = NULL;
- GNGetAce = NULL;
- GNEqualSid = NULL;
- GNAddAce = NULL;
- GNAddAccessAllowedAce = NULL;
- GNSetNamedSecurityInfo = NULL;
- }
+ GNGetFileSecurity = NULL;
+ GNInitializeSecurityDescriptor = NULL;
+ GNGetSecurityDescriptorDacl = NULL;
+ GNGetAclInformation = NULL;
+ GNInitializeAcl = NULL;
+ GNGetAce = NULL;
+ GNEqualSid = NULL;
+ GNAddAce = NULL;
+ GNAddAccessAllowedAce = NULL;
+ GNSetNamedSecurityInfo = NULL;
+ }
/* Account function */
hNetapi = LoadLibrary ("netapi32.dll");
if (hNetapi)
- {
- GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
- GNNetUserSetInfo =
- (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo");
- }
+ {
+ GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
+ GNNetUserSetInfo =
+ (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo");
+ }
else
- {
- GNNetUserAdd = NULL;
- GNNetUserSetInfo = NULL;
- }
+ {
+ GNNetUserAdd = NULL;
+ GNNetUserSetInfo = NULL;
+ }
return ret;
}
}
static void *
-new_tunnel (void *cls __attribute__((unused)),
- struct GNUNET_MESH_Tunnel *tunnel,
- const struct GNUNET_PeerIdentity *initiator __attribute__((unused)),
- const struct GNUNET_ATS_Information *ats __attribute__((unused)))
+new_tunnel (void *cls
+ __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
+ const struct GNUNET_PeerIdentity *initiator
+ __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats
+ __attribute__ ((unused)))
{
- struct tunnel_state *s = GNUNET_malloc(sizeof *s);
- s->head = NULL;
- s->tail = NULL;
- s->th = NULL;
- return s;
+ struct tunnel_state *s = GNUNET_malloc (sizeof *s);
+
+ s->head = NULL;
+ s->tail = NULL;
+ s->th = NULL;
+ return s;
}
static void
-clean_tunnel (void *cls __attribute__((unused)),
- const struct GNUNET_MESH_Tunnel *tunnel,
+clean_tunnel (void *cls
+ __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel,
void *tunnel_ctx)
{
- GNUNET_free(tunnel_ctx);
+ GNUNET_free (tunnel_ctx);
}
static void
/* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (state->hashmap, &state->hash, state));
+ GNUNET_CONTAINER_multihashmap_remove (state->hashmap,
+ &state->hash, state));
GNUNET_free (state);
}
memcpy (buf, hdr, ntohs (hdr->size));
size = ntohs (hdr->size);
- struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel);
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel);
if (NULL != s->head)
{
GNUNET_CONTAINER_DLL_remove (s->head, s->tail, element);
s->th =
- GNUNET_MESH_notify_transmit_ready (*tunnel,
- GNUNET_NO,
- 42,
+ GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
(const struct GNUNET_PeerIdentity *)
memcpy (_udp, udp, ntohs (udp->len));
- struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(tunnel);
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel);
+
if (NULL == s->th)
{
/* No notify is pending */
s->th =
- GNUNET_MESH_notify_transmit_ready (tunnel,
- GNUNET_NO,
- 42,
+ GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42,
GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
(const struct GNUNET_PeerIdentity *)
memcpy (_tcp, tcp, pktlen);
struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel);
+
if (NULL == s->th)
{
/* No notify is pending */
s->th =
- GNUNET_MESH_notify_transmit_ready (tunnel,
- GNUNET_NO,
- 42,
+ GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42,
GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
(const struct GNUNET_PeerIdentity *)
- NULL,
- len,
+ NULL, len,
send_udp_to_peer_notify_callback,
ctunnel);
}
}
else
{
- struct addrinfo* res;
+ struct addrinfo *res;
- int ret = getaddrinfo(hostname, NULL, NULL, &res);
+ int ret = getaddrinfo (hostname, NULL, NULL, &res);
if (ret != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n",
+ hostname);
+ GNUNET_free (serv);
+ continue;
+ }
+ else
+ {
+ char buf[256];
+ struct addrinfo *c = res;
+
+ if (c)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n", hostname);
- GNUNET_free (serv);
- continue;
+ if (c->ai_family == AF_INET)
+ {
+ serv->version = 4;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found %s as address for %s\n",
+ inet_ntop (c->ai_family,
+ &((struct sockaddr_in *) (c->
+ ai_addr))->sin_addr,
+ (char *) &buf, 256), hostname);
+ memcpy (serv->v4.ip4address,
+ &((struct sockaddr_in *) (c->ai_addr))->sin_addr, 4);
+ }
+ else if (c->ai_family == AF_INET6)
+ {
+ serv->version = 6;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found %s as address for %s\n",
+ inet_ntop (c->ai_family,
+ &((struct sockaddr_in6 *) (c->
+ ai_addr))->sin6_addr,
+ (char *) &buf, 256), hostname);
+ memcpy (serv->v6.ip6address,
+ &((struct sockaddr_in6 *) (c->ai_addr))->sin6_addr, 16);
+ }
}
- else
+ else
{
- char buf[256];
- struct addrinfo* c = res;
-
- if(c)
- {
- if (c->ai_family == AF_INET)
- {
- serv->version = 4;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, (char*)&buf, 256), hostname);
- memcpy(serv->v4.ip4address, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, 4);
- }
- else if (c->ai_family == AF_INET6)
- {
- serv->version = 6;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in6*)(c->ai_addr))->sin6_addr, (char*)&buf, 256), hostname);
- memcpy(serv->v6.ip6address, &((struct sockaddr_in6 *)(c->ai_addr))->sin6_addr, 16);
- }
- }
- else
- {
- freeaddrinfo(res);
- GNUNET_free (serv);
- continue;
- }
- freeaddrinfo(res);
+ freeaddrinfo (res);
+ GNUNET_free (serv);
+ continue;
}
+ freeaddrinfo (res);
+ }
}
serv->remote_port = atoi (hostport);
if (UDP == proto)
switch (serv->version)
{
case 4:
- prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP,
- &serv->v4.ip4address, tunnel, state,
- (struct ip_pkt *) buf);
+ prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v4.ip4address,
+ tunnel, state, (struct ip_pkt *) buf);
break;
case 6:
- prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP,
- &serv->v6.ip6address, tunnel, state,
- (struct ip6_pkt *) buf);
+ prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v6.ip6address,
+ tunnel, state, (struct ip6_pkt *) buf);
break;
default:
switch (s->addrlen)
{
case 4:
- prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP,
- &s->addr, tunnel, state, (struct ip_pkt *) buf);
+ prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel,
+ state, (struct ip_pkt *) buf);
break;
case 16:
- prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP,
- &s->addr, tunnel, state, (struct ip6_pkt *) buf);
+ prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel,
+ state, (struct ip6_pkt *) buf);
break;
default:
GNUNET_free (state);
switch (s->addrlen)
{
case 4:
- prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP,
- &s->addr, tunnel, state, (struct ip_pkt *) buf);
+ prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr,
+ tunnel, state, (struct ip_pkt *) buf);
break;
case 16:
- prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP,
- &s->addr, tunnel, state, (struct ip6_pkt *) buf);
+ prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr,
+ tunnel, state, (struct ip6_pkt *) buf);
break;
default:
GNUNET_assert (0);
* The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
*/
static int
-receive_udp_service (void *cls __attribute__ ((unused)),
- struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx,
- const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)),
+receive_udp_service (void *cls
+ __attribute__ ((unused)),
+ struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
+ const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi __attribute__ ((unused)))
+ const struct GNUNET_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
app_idx++;
}
- mesh_handle = GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, apptypes);
+ mesh_handle =
+ GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers,
+ apptypes);
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_UDP_CONNECTIONS",
- &max_udp_connections))
+ &max_udp_connections))
max_udp_connections = 1024;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_TCP_CONNECTIONS",
- &max_tcp_connections))
+ &max_tcp_connections))
max_tcp_connections = 256;
GNUNET_CONFIGURATION_iterate_sections (cfg, read_service_conf, NULL);
GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL);
/**
- * The main function
+ * The main function
*
* @param argc number of arguments from the command line
* @param argv command line arguments
};
return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit",
- gettext_noop ("Daemon to run to provide an IP exit node for the VPN"),
+ GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit",
+ gettext_noop
+ ("Daemon to run to provide an IP exit node for the VPN"),
options, &run, NULL)) ? ret : 1;
}
send_query (void *cls __attribute__ ((unused)), size_t size, void *buf)
{
size_t len;
+
dns_transmit_handle = NULL;
/*
*/
if (head != NULL)
{
- dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection,
- ntohs (head->pkt.hdr.size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_query, NULL);
+ dns_transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ ntohs (head->pkt.hdr.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
}
else if (restart_hijack == 1)
{
- dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_query, NULL);
+ dns_transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
}
return len;
/* If a packet is already in the list, schedule to send it */
if (dns_transmit_handle == NULL && head != NULL)
- dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection,
- ntohs (head->pkt.hdr.size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_query, NULL);
+ dns_transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ ntohs (head->pkt.hdr.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
else if (dns_transmit_handle == NULL && restart_hijack == 1)
{
- dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_query, NULL);
+ dns_transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
}
}
if (msg == NULL)
{
if (dns_transmit_handle != NULL)
- GNUNET_CLIENT_notify_transmit_ready_cancel(dns_transmit_handle);
+ GNUNET_CLIENT_notify_transmit_ready_cancel (dns_transmit_handle);
dns_transmit_handle = NULL;
GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
dns_connection = NULL;
struct GNUNET_VPN_HELPER_Handle *helper_handle;
-extern struct GNUNET_CLIENT_TransmitHandle* dns_transmit_handle;
+extern struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle;
/**
* The tunnels that will be used to send tcp- and udp-packets
*/
restart_hijack = 1;
if (NULL != dns_connection && dns_transmit_handle == NULL)
- dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_query, NULL);
+ dns_transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
helper_handle->fh_to_helper, &helper_write,
/*}}}*/
-static void*
-initialize_tunnel_state(int addrlen, struct GNUNET_MESH_TransmitHandle* th)
+static void *
+initialize_tunnel_state (int addrlen, struct GNUNET_MESH_TransmitHandle *th)
{
- struct tunnel_state* ts = GNUNET_malloc(sizeof *ts);
+ struct tunnel_state *ts = GNUNET_malloc (sizeof *ts);
+
ts->addrlen = addrlen;
ts->th = th;
return ts;
size_t data_len = len - sizeof (struct answer_packet) + 1;
- void* buf;
+ void *buf;
size_t pkt_len;
if (ans->pkt.addrlen == 16)
- {
- size_t net_len = sizeof (struct ip6_hdr) + sizeof (struct udp_dns) + data_len;
- pkt_len =
- sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + net_len;
+ {
+ size_t net_len =
+ sizeof (struct ip6_hdr) + sizeof (struct udp_dns) + data_len;
+ pkt_len =
+ sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
+ net_len;
- struct ip6_udp_dns *pkt = alloca (pkt_len);
+ struct ip6_udp_dns *pkt = alloca (pkt_len);
- GNUNET_assert (pkt != NULL);
- memset (pkt, 0, pkt_len);
+ GNUNET_assert (pkt != NULL);
+ memset (pkt, 0, pkt_len);
- /* set the gnunet-header */
- pkt->shdr.size = htons (pkt_len);
- pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ /* set the gnunet-header */
+ pkt->shdr.size = htons (pkt_len);
+ pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
- /* set the tun-header (no flags and ethertype of IPv4) */
- pkt->tun.flags = 0;
- pkt->tun.type = htons (0x86dd);
+ /* set the tun-header (no flags and ethertype of IPv4) */
+ pkt->tun.flags = 0;
+ pkt->tun.type = htons (0x86dd);
- memcpy(&pkt->ip6_hdr.sadr, ans->pkt.from, 16);
- memcpy(&pkt->ip6_hdr.dadr, ans->pkt.to, 16);
+ memcpy (&pkt->ip6_hdr.sadr, ans->pkt.from, 16);
+ memcpy (&pkt->ip6_hdr.dadr, ans->pkt.to, 16);
- /* set the udp-header */
- pkt->udp_dns.udp_hdr.spt = htons (53);
- pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port;
- pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip6_hdr));
- pkt->udp_dns.udp_hdr.crc = 0;
- uint32_t sum = 0;
+ /* set the udp-header */
+ pkt->udp_dns.udp_hdr.spt = htons (53);
+ pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port;
+ pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip6_hdr));
+ pkt->udp_dns.udp_hdr.crc = 0;
+ uint32_t sum = 0;
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16);
- sum =
- calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16);
- uint32_t tmp = (pkt->udp_dns.udp_hdr.len & 0xffff);
+ sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16);
+ sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16);
+ uint32_t tmp = (pkt->udp_dns.udp_hdr.len & 0xffff);
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = htons (((pkt->ip6_hdr.nxthdr & 0x00ff)));
- sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+ tmp = htons (((pkt->ip6_hdr.nxthdr & 0x00ff)));
+ sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- sum =
+ sum =
calculate_checksum_update (sum, (uint16_t *) & pkt->udp_dns.udp_hdr,
- ntohs (net_len - sizeof(struct ip6_hdr)));
- pkt->udp_dns.udp_hdr.crc = calculate_checksum_end (sum);
+ ntohs (net_len - sizeof (struct ip6_hdr)));
+ pkt->udp_dns.udp_hdr.crc = calculate_checksum_end (sum);
- pkt->ip6_hdr.version = 6;
- pkt->ip6_hdr.paylgth = net_len - sizeof (struct ip6_hdr);
- pkt->ip6_hdr.nxthdr = IPPROTO_UDP;
- pkt->ip6_hdr.hoplmt = 0xff;
+ pkt->ip6_hdr.version = 6;
+ pkt->ip6_hdr.paylgth = net_len - sizeof (struct ip6_hdr);
+ pkt->ip6_hdr.nxthdr = IPPROTO_UDP;
+ pkt->ip6_hdr.hoplmt = 0xff;
- memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len);
- buf = pkt;
- }
+ memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len);
+ buf = pkt;
+ }
else if (ans->pkt.addrlen == 4)
- {
- size_t net_len = sizeof (struct ip_hdr) + sizeof (struct udp_dns) + data_len;
- pkt_len =
- sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + net_len;
-
- struct ip_udp_dns *pkt = alloca (pkt_len);
-
- GNUNET_assert (pkt != NULL);
- memset (pkt, 0, pkt_len);
-
- /* set the gnunet-header */
- pkt->shdr.size = htons (pkt_len);
- pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
-
- /* set the tun-header (no flags and ethertype of IPv4) */
- pkt->tun.flags = 0;
- pkt->tun.type = htons (0x0800);
-
- /* set the ip-header */
- pkt->ip_hdr.version = 4;
- pkt->ip_hdr.hdr_lngth = 5;
- pkt->ip_hdr.diff_serv = 0;
- pkt->ip_hdr.tot_lngth = htons (net_len);
- pkt->ip_hdr.ident = 0;
- pkt->ip_hdr.flags = 0;
- pkt->ip_hdr.frag_off = 0;
- pkt->ip_hdr.ttl = 255;
- pkt->ip_hdr.proto = IPPROTO_UDP;
- pkt->ip_hdr.chks = 0; /* Will be calculated later */
-
- memcpy(&pkt->ip_hdr.sadr, ans->pkt.from, 4);
- memcpy(&pkt->ip_hdr.dadr, ans->pkt.to, 4);
-
- pkt->ip_hdr.chks = calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4);
-
- /* set the udp-header */
- pkt->udp_dns.udp_hdr.spt = htons (53);
- pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port;
- pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip_hdr));
- pkt->udp_dns.udp_hdr.crc = 0; /* Optional for IPv4 */
-
- memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len);
- buf = pkt;
- }
+ {
+ size_t net_len =
+ sizeof (struct ip_hdr) + sizeof (struct udp_dns) + data_len;
+ pkt_len =
+ sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
+ net_len;
+
+ struct ip_udp_dns *pkt = alloca (pkt_len);
+
+ GNUNET_assert (pkt != NULL);
+ memset (pkt, 0, pkt_len);
+
+ /* set the gnunet-header */
+ pkt->shdr.size = htons (pkt_len);
+ pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+
+ /* set the tun-header (no flags and ethertype of IPv4) */
+ pkt->tun.flags = 0;
+ pkt->tun.type = htons (0x0800);
+
+ /* set the ip-header */
+ pkt->ip_hdr.version = 4;
+ pkt->ip_hdr.hdr_lngth = 5;
+ pkt->ip_hdr.diff_serv = 0;
+ pkt->ip_hdr.tot_lngth = htons (net_len);
+ pkt->ip_hdr.ident = 0;
+ pkt->ip_hdr.flags = 0;
+ pkt->ip_hdr.frag_off = 0;
+ pkt->ip_hdr.ttl = 255;
+ pkt->ip_hdr.proto = IPPROTO_UDP;
+ pkt->ip_hdr.chks = 0; /* Will be calculated later */
+
+ memcpy (&pkt->ip_hdr.sadr, ans->pkt.from, 4);
+ memcpy (&pkt->ip_hdr.dadr, ans->pkt.to, 4);
+
+ pkt->ip_hdr.chks =
+ calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4);
+
+ /* set the udp-header */
+ pkt->udp_dns.udp_hdr.spt = htons (53);
+ pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port;
+ pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip_hdr));
+ pkt->udp_dns.udp_hdr.crc = 0; /* Optional for IPv4 */
+
+ memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len);
+ buf = pkt;
+ }
else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Wrong addrlen = %d\n", ans->pkt.addrlen);
- GNUNET_assert(0);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wrong addrlen = %d\n",
+ ans->pkt.addrlen);
+ GNUNET_assert (0);
+ }
GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans);
GNUNET_free (ans);
struct ip6_udp *pkt6_udp;
struct ip6_icmp *pkt6_icmp;
- pkt6_udp = NULL; /* make compiler happy */
+ pkt6_udp = NULL; /* make compiler happy */
switch (pkt6->ip6_hdr.nxthdr)
{
case IPPROTO_UDP:
pkt6_udp = (struct ip6_udp *) pkt6;
/* Send dns-packets to the service-dns */
if (ntohs (pkt6_udp->udp_hdr.dpt) == 53)
- {
- /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */
- size_t len = sizeof (struct query_packet) + ntohs (pkt6_udp->udp_hdr.len) - 9;
-
- struct query_packet_list *query =
- GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
- query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
- query->pkt.hdr.size = htons (len);
- memcpy(query->pkt.orig_to, &pkt6->ip6_hdr.dadr, 16);
- memcpy(query->pkt.orig_from, &pkt6->ip6_hdr.sadr, 16);
- query->pkt.addrlen = 16;
- query->pkt.src_port = pkt6_udp->udp_hdr.spt;
- memcpy (query->pkt.data, pkt6_udp->data, ntohs (pkt6_udp->udp_hdr.len) - 8);
-
- GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query);
-
- GNUNET_assert (head != NULL);
-
- if (dns_connection != NULL && dns_transmit_handle == NULL)
- dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_query, NULL);
- break;
- }
+ {
+ /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */
+ size_t len =
+ sizeof (struct query_packet) + ntohs (pkt6_udp->udp_hdr.len) - 9;
+
+ struct query_packet_list *query =
+ GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
+ query->pkt.hdr.type =
+ htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
+ query->pkt.hdr.size = htons (len);
+ memcpy (query->pkt.orig_to, &pkt6->ip6_hdr.dadr, 16);
+ memcpy (query->pkt.orig_from, &pkt6->ip6_hdr.sadr, 16);
+ query->pkt.addrlen = 16;
+ query->pkt.src_port = pkt6_udp->udp_hdr.spt;
+ memcpy (query->pkt.data, pkt6_udp->data,
+ ntohs (pkt6_udp->udp_hdr.len) - 8);
+
+ GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query);
+
+ GNUNET_assert (head != NULL);
+
+ if (dns_connection != NULL && dns_transmit_handle == NULL)
+ dns_transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query,
+ NULL);
+ break;
+ }
/* fall through */
case IPPROTO_TCP:
pkt6_tcp = (struct ip6_tcp *) pkt6;
}
else
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n", port_in_ports(me->desc.ports, pkt6_tcp->tcp_hdr.dpt));
- GNUNET_assert(0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n",
+ port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt));
+ GNUNET_assert (0);
}
if (me->tunnel == NULL && NULL != cls)
{
*cls =
- GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL),
- &send_pkt_to_peer, NULL, cls);
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (16, NULL),
+ &send_pkt_to_peer, NULL, cls);
GNUNET_MESH_peer_request_connect_add (*cls,
- (struct
- GNUNET_PeerIdentity *)
- &me->desc.peer);
+ (struct GNUNET_PeerIdentity *)
+ &me->desc.peer);
me->tunnel = *cls;
}
else if (NULL != cls)
memcpy (s->addr, me->addr, me->addrlen);
s->proto = pkt6->ip6_hdr.nxthdr;
if (s->proto == IPPROTO_UDP)
- {
+ {
hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP);
memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
if (me->tunnel == NULL && NULL != cls)
{
*cls =
- GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL),
- &send_pkt_to_peer, NULL, cls);
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (16, NULL),
+ &send_pkt_to_peer, NULL, cls);
- GNUNET_MESH_peer_request_connect_by_type (*cls,
- app_type);
+ GNUNET_MESH_peer_request_connect_by_type (*cls, app_type);
me->tunnel = *cls;
if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type)
udp_tunnel = *cls;
size_t len = sizeof (struct query_packet) + ntohs (udp->udp_hdr.len) - 9;
struct query_packet_list *query =
- GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
query->pkt.hdr.size = htons (len);
- memcpy(query->pkt.orig_to, &pkt->ip_hdr.dadr, 4);
- memcpy(query->pkt.orig_from, &pkt->ip_hdr.sadr, 4);
+ memcpy (query->pkt.orig_to, &pkt->ip_hdr.dadr, 4);
+ memcpy (query->pkt.orig_from, &pkt->ip_hdr.sadr, 4);
query->pkt.addrlen = 4;
query->pkt.src_port = udp->udp_hdr.spt;
memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8);
GNUNET_assert (head != NULL);
if (dns_connection != NULL && dns_transmit_handle == NULL)
- dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_query, NULL);
+ dns_transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_query, NULL);
}
else
{
}
if (me->tunnel == NULL && NULL != cls)
{
- *cls = GNUNET_MESH_tunnel_create(mesh_handle,
- initialize_tunnel_state(4, NULL),
- send_pkt_to_peer, NULL, cls);
+ *cls =
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (4, NULL),
+ send_pkt_to_peer, NULL, cls);
GNUNET_MESH_peer_request_connect_add (*cls,
- (struct GNUNET_PeerIdentity *)
- &me->desc.peer);
+ (struct GNUNET_PeerIdentity
+ *) &me->desc.peer);
me->tunnel = *cls;
}
else if (NULL != cls)
ntohs (pkt->ip_hdr.tot_lngth) -
4 * pkt->ip_hdr.hdr_lngth);
app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
- } else
- GNUNET_assert (0);
+ }
+ else
+ GNUNET_assert (0);
if (me->tunnel == NULL && NULL != cls)
{
*cls =
- GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(4, NULL),
- send_pkt_to_peer, NULL, cls);
+ GNUNET_MESH_tunnel_create (mesh_handle,
+ initialize_tunnel_state (4, NULL),
+ send_pkt_to_peer, NULL, cls);
GNUNET_MESH_peer_request_connect_by_type (*cls, app_type);
me->tunnel = *cls;
/* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me));
+ GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me));
GNUNET_free (me);
}
{
struct GNUNET_MESH_Tunnel **tunnel = cls;
- struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel);
+ struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel);
+
ts->th = NULL;
if (NULL != buf)
- {
- struct GNUNET_MessageHeader *hdr =
+ {
+ struct GNUNET_MessageHeader *hdr =
(struct GNUNET_MessageHeader *) (tunnel + 1);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf,
- size);
- GNUNET_assert (size >= ntohs (hdr->size));
- memcpy (buf, hdr, ntohs (hdr->size));
- size = ntohs (hdr->size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n");
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf,
+ size);
+ GNUNET_assert (size >= ntohs (hdr->size));
+ memcpy (buf, hdr, ntohs (hdr->size));
+ size = ntohs (hdr->size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n");
+ }
else
size = 0;
GNUNET_CONTAINER_DLL_remove (ts->head, ts->tail, element);
ts->th =
- GNUNET_MESH_notify_transmit_ready (*tunnel,
- GNUNET_NO,
- 42,
+ GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
(const struct GNUNET_PeerIdentity *)
{
uint16_t *ps = (uint16_t *) & ports;
- return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port;
+ return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port ||
+ ps[3] == port;
}
void
send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi __attribute__ ((unused)))
+ const struct GNUNET_ATS_Information *atsi
+ __attribute__ ((unused)))
{
/* peer == NULL means that all peers in this request are connected */
if (peer == NULL)
GNUNET_assert (NULL != tunnel);
GNUNET_assert (NULL != *tunnel);
- struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel);
+ struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel);
+
if (NULL == ts->th)
{
ts->th =
- GNUNET_MESH_notify_transmit_ready (*tunnel,
- GNUNET_NO,
- 42,
+ GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
(const struct GNUNET_PeerIdentity *)
- NULL,
- ntohs (hdr->size),
+ NULL, ntohs (hdr->size),
send_pkt_to_peer_notify_callback,
cls);
}
list =
GNUNET_malloc (htons (pkt->hdr.size) +
- sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
char *name = (char *) (map_entry + 1);
list =
- GNUNET_malloc (sizeof(struct answer_packet_list) - sizeof(struct answer_packet) + offset + 2 +
- ntohs (namelen));
+ GNUNET_malloc (sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet) + offset + 2 +
+ ntohs (namelen));
struct answer_packet *rpkt = &list->pkt;
{
list =
GNUNET_malloc (htons (pkt->hdr.size) +
- sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
}
else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA)
list =
GNUNET_malloc (htons (pkt->hdr.size) +
- sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
}
list =
GNUNET_malloc (htons (pkt->hdr.size) +
- sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
}
}
static int
-receive_udp_back (void *cls __attribute__ ((unused)),
- struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx,
- const struct GNUNET_PeerIdentity *sender,
+receive_udp_back (void *cls
+ __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi __attribute__ ((unused)))
+ const struct GNUNET_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct remote_addr *s = (struct remote_addr *) desc;
}
static int
-receive_tcp_back (void *cls __attribute__ ((unused)),
- struct GNUNET_MESH_Tunnel *tunnel,
- void **tunnel_ctx,
- const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)),
+receive_tcp_back (void *cls
+ __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender
+ __attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *atsi __attribute__ ((unused)))
+ const struct GNUNET_ATS_Information *atsi
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct remote_addr *s = (struct remote_addr *) desc;
ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
sizeof (GNUNET_HashCode);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet back, addrlen = %d\n", s->addrlen);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received TCP-Packet back, addrlen = %d\n", s->addrlen);
- if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK ||
+ if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK ||
ts->addrlen == 16)
{
size_t size = pktlen + sizeof (struct ip6_tcp) - 1;
tmp = pkt4->ip_hdr.dadr;
sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
- tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP?
+ tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP?
tmp = htonl (tmp);
return GNUNET_OK;
}
-static void* new_tunnel(void* cls,
- struct GNUNET_MESH_Tunnel *tunnel,
- const struct GNUNET_PeerIdentity *initiator,
- const struct GNUNET_ATS_Information *atsi)
+static void *
+new_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
+ const struct GNUNET_PeerIdentity *initiator,
+ const struct GNUNET_ATS_Information *atsi)
{
/* Why should anyone open an inbound tunnel to vpn? */
- GNUNET_break(0);
+ GNUNET_break (0);
return NULL;
}
-static void cleaner(void *cls,
- const struct GNUNET_MESH_Tunnel *tunnel,
- void *tunnel_ctx)
+static void
+cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx)
{
/* Why should anyone open an inbound tunnel to vpn? */
- GNUNET_break(0);
+ GNUNET_break (0);
}
/**
GNUNET_APPLICATION_TYPE_END
};
- mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, types);
+ mesh_handle =
+ GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers,
+ types);
cfg = cfg_;
restart_hijack = 0;
hashmap = GNUNET_CONTAINER_multihashmap_create (65536);
} /*}}} */
static void
-unparse_dns_name(char* dest, char* src, size_t len)
+unparse_dns_name (char *dest, char *src, size_t len)
{
char *b = dest;
char cnt = 0;
+
dest++;
while (*src != 0)
+ {
+ while (*src != '.' && *src != 0)
{
- while (*src != '.' && *src != 0)
- {
- *dest = *src;
- src++;
- dest++;
- cnt++;
- }
- *b = cnt;
- cnt = 0;
- b = dest;
- dest++;
+ *dest = *src;
src++;
+ dest++;
+ cnt++;
}
+ *b = cnt;
+ cnt = 0;
+ b = dest;
+ dest++;
+ src++;
+ }
*b = 0;
}
struct dns_pkt *
-unparse_dns_packet (struct dns_pkt_parsed* ppkt)
+unparse_dns_packet (struct dns_pkt_parsed *ppkt)
{
- size_t size = sizeof(struct dns_pkt) - 1;
+ size_t size = sizeof (struct dns_pkt) - 1;
int i;
- for (i = 0; i < ntohs(ppkt->s.qdcount); i++)
+
+ for (i = 0; i < ntohs (ppkt->s.qdcount); i++)
size += ppkt->queries[i]->namelen + 1;
- for (i = 0; i < ntohs(ppkt->s.ancount); i++)
- {
- size += ppkt->answers[i]->namelen + 1;
- size += ppkt->answers[i]->data_len;
- }
- for (i = 0; i < ntohs(ppkt->s.nscount); i++)
- {
- size += ppkt->nameservers[i]->namelen + 1;
- size += ppkt->nameservers[i]->data_len;
- }
- for (i = 0; i < ntohs(ppkt->s.arcount); i++)
- {
- size += ppkt->additional[i]->namelen + 1;
- size += ppkt->additional[i]->data_len;
- }
+ for (i = 0; i < ntohs (ppkt->s.ancount); i++)
+ {
+ size += ppkt->answers[i]->namelen + 1;
+ size += ppkt->answers[i]->data_len;
+ }
+ for (i = 0; i < ntohs (ppkt->s.nscount); i++)
+ {
+ size += ppkt->nameservers[i]->namelen + 1;
+ size += ppkt->nameservers[i]->data_len;
+ }
+ for (i = 0; i < ntohs (ppkt->s.arcount); i++)
+ {
+ size += ppkt->additional[i]->namelen + 1;
+ size += ppkt->additional[i]->data_len;
+ }
+
+ size +=
+ 4 * ntohs (ppkt->s.qdcount) + 10 * (ntohs (ppkt->s.ancount) +
+ ntohs (ppkt->s.arcount) +
+ ntohs (ppkt->s.nscount));
- size += 4*ntohs(ppkt->s.qdcount) + 10*(
- ntohs(ppkt->s.ancount)+
- ntohs(ppkt->s.arcount)+
- ntohs(ppkt->s.nscount));
+ struct dns_pkt *pkt = GNUNET_malloc (size);
+ char *pkt_c = (char *) pkt;
- struct dns_pkt *pkt = GNUNET_malloc(size);
- char *pkt_c = (char*)pkt;
- memcpy(&pkt->s, &ppkt->s, sizeof ppkt->s);
+ memcpy (&pkt->s, &ppkt->s, sizeof ppkt->s);
size_t idx = sizeof ppkt->s;
- for (i = 0; i < ntohs(ppkt->s.qdcount); i++)
- {
- unparse_dns_name(&pkt_c[idx], ppkt->queries[i]->name, ppkt->queries[i]->namelen);
- idx += ppkt->queries[i]->namelen;
- struct dns_query_line *d = (struct dns_query_line*)&pkt_c[idx];
- d->class = ppkt->queries[i]->qclass;
- d->type = ppkt->queries[i]->qtype;
- idx += sizeof(struct dns_query_line);
- }
+ for (i = 0; i < ntohs (ppkt->s.qdcount); i++)
+ {
+ unparse_dns_name (&pkt_c[idx], ppkt->queries[i]->name,
+ ppkt->queries[i]->namelen);
+ idx += ppkt->queries[i]->namelen;
+ struct dns_query_line *d = (struct dns_query_line *) &pkt_c[idx];
+
+ d->class = ppkt->queries[i]->qclass;
+ d->type = ppkt->queries[i]->qtype;
+ idx += sizeof (struct dns_query_line);
+ }
- for (i = 0; i < ntohs(ppkt->s.ancount); i++)
- {
- unparse_dns_name(&pkt_c[idx], ppkt->answers[i]->name, ppkt->answers[i]->namelen);
- idx += ppkt->answers[i]->namelen;
- struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx];
- r->type = ppkt->answers[i]->type;
- r->class = ppkt->answers[i]->class;
- r->ttl = ppkt->answers[i]->ttl;
- r->data_len = ppkt->answers[i]->data_len;
- idx += sizeof(struct dns_record_line);
- memcpy(&r->data, ppkt->answers[i]->data, ppkt->answers[i]->data_len);
- idx += ppkt->answers[i]->data_len;
- }
+ for (i = 0; i < ntohs (ppkt->s.ancount); i++)
+ {
+ unparse_dns_name (&pkt_c[idx], ppkt->answers[i]->name,
+ ppkt->answers[i]->namelen);
+ idx += ppkt->answers[i]->namelen;
+ struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx];
+
+ r->type = ppkt->answers[i]->type;
+ r->class = ppkt->answers[i]->class;
+ r->ttl = ppkt->answers[i]->ttl;
+ r->data_len = ppkt->answers[i]->data_len;
+ idx += sizeof (struct dns_record_line);
+ memcpy (&r->data, ppkt->answers[i]->data, ppkt->answers[i]->data_len);
+ idx += ppkt->answers[i]->data_len;
+ }
- for (i = 0; i < ntohs(ppkt->s.nscount); i++)
- {
- unparse_dns_name(&pkt_c[idx], ppkt->nameservers[i]->name, ppkt->nameservers[i]->namelen);
- idx += ppkt->nameservers[i]->namelen;
- struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx];
- r->type = ppkt->nameservers[i]->type;
- r->class = ppkt->nameservers[i]->class;
- r->ttl = ppkt->nameservers[i]->ttl;
- r->data_len = ppkt->nameservers[i]->data_len;
- idx += sizeof(struct dns_record_line);
- memcpy(&r->data, ppkt->nameservers[i]->data, ppkt->nameservers[i]->data_len);
- idx += ppkt->nameservers[i]->data_len;
- }
+ for (i = 0; i < ntohs (ppkt->s.nscount); i++)
+ {
+ unparse_dns_name (&pkt_c[idx], ppkt->nameservers[i]->name,
+ ppkt->nameservers[i]->namelen);
+ idx += ppkt->nameservers[i]->namelen;
+ struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx];
+
+ r->type = ppkt->nameservers[i]->type;
+ r->class = ppkt->nameservers[i]->class;
+ r->ttl = ppkt->nameservers[i]->ttl;
+ r->data_len = ppkt->nameservers[i]->data_len;
+ idx += sizeof (struct dns_record_line);
+ memcpy (&r->data, ppkt->nameservers[i]->data,
+ ppkt->nameservers[i]->data_len);
+ idx += ppkt->nameservers[i]->data_len;
+ }
- for (i = 0; i < ntohs(ppkt->s.arcount); i++)
- {
- unparse_dns_name(&pkt_c[idx], ppkt->additional[i]->name, ppkt->additional[i]->namelen);
- idx += ppkt->additional[i]->namelen;
- struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx];
- r->type = ppkt->additional[i]->type;
- r->class = ppkt->additional[i]->class;
- r->ttl = ppkt->additional[i]->ttl;
- r->data_len = ppkt->additional[i]->data_len;
- idx += sizeof(struct dns_record_line);
- memcpy(&r->data, ppkt->additional[i]->data, ppkt->additional[i]->data_len);
- idx += ppkt->additional[i]->data_len;
- }
+ for (i = 0; i < ntohs (ppkt->s.arcount); i++)
+ {
+ unparse_dns_name (&pkt_c[idx], ppkt->additional[i]->name,
+ ppkt->additional[i]->namelen);
+ idx += ppkt->additional[i]->namelen;
+ struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx];
+
+ r->type = ppkt->additional[i]->type;
+ r->class = ppkt->additional[i]->class;
+ r->ttl = ppkt->additional[i]->ttl;
+ r->data_len = ppkt->additional[i]->data_len;
+ idx += sizeof (struct dns_record_line);
+ memcpy (&r->data, ppkt->additional[i]->data, ppkt->additional[i]->data_len);
+ idx += ppkt->additional[i]->data_len;
+ }
return pkt;
}
unsigned char data[1];
};
-struct answer_packet_list {
+struct answer_packet_list
+{
struct answer_packet_list *next GNUNET_PACKED;
struct answer_packet_list *prev GNUNET_PACKED;
struct GNUNET_SERVER_Client *client;
char *name;
uint8_t namelen;
uint16_t qtype;
-} query_states[UINT16_MAX+1];
+} query_states[UINT16_MAX + 1];
/**
* A struct used to give more than one value as
struct tunnel_state
{
- struct tunnel_notify_queue *head,*tail;
+ struct tunnel_notify_queue *head, *tail;
struct GNUNET_MESH_TransmitHandle *th;
};
-static size_t send_answer (void *cls, size_t size, void *buf);
+static size_t
+send_answer (void *cls, size_t size, void *buf);
static void
-client_disconnect(void* cls, struct GNUNET_SERVER_Client *client)
+client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
- if (NULL == head) return;
+ if (NULL == head)
+ return;
if (head->client == client)
- {
- GNUNET_CONNECTION_notify_transmit_ready_cancel(server_notify);
- server_notify = GNUNET_SERVER_notify_transmit_ready (head->next->client, ntohs (head->next->pkt.hdr.size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer, NULL);
- }
+ {
+ GNUNET_CONNECTION_notify_transmit_ready_cancel (server_notify);
+ server_notify =
+ GNUNET_SERVER_notify_transmit_ready (head->next->client,
+ ntohs (head->next->pkt.hdr.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, NULL);
+ }
struct answer_packet_list *element = head;
+
while (element != NULL)
+ {
+ if (element->client == client)
{
- if (element->client == client)
- {
- GNUNET_SERVER_client_drop(client);
- GNUNET_CONTAINER_DLL_remove(head, tail, element);
- struct answer_packet_list* t = element;
- element = element->next;
- GNUNET_free(t);
- }
- else
- element = element->next;
+ GNUNET_SERVER_client_drop (client);
+ GNUNET_CONTAINER_DLL_remove (head, tail, element);
+ struct answer_packet_list *t = element;
+
+ element = element->next;
+ GNUNET_free (t);
}
+ else
+ element = element->next;
+ }
}
/**
}
static void *
-new_tunnel (void *cls __attribute__((unused)),
- struct GNUNET_MESH_Tunnel *tunnel,
- const struct GNUNET_PeerIdentity *initiator __attribute__((unused)),
- const struct GNUNET_ATS_Information *ats __attribute__((unused)))
+new_tunnel (void *cls
+ __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
+ const struct GNUNET_PeerIdentity *initiator
+ __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats
+ __attribute__ ((unused)))
{
- struct tunnel_state *s = GNUNET_malloc(sizeof *s);
- s->head = NULL;
- s->tail = NULL;
- s->th = NULL;
- return s;
+ struct tunnel_state *s = GNUNET_malloc (sizeof *s);
+
+ s->head = NULL;
+ s->tail = NULL;
+ s->th = NULL;
+ return s;
}
static void
-clean_tunnel (void *cls __attribute__((unused)),
- const struct GNUNET_MESH_Tunnel *tunnel,
+clean_tunnel (void *cls
+ __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel,
void *tunnel_ctx)
{
- GNUNET_free(tunnel_ctx);
+ GNUNET_free (tunnel_ctx);
}
/**
GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns",
"gnunet-hijack-dns", "-d", port_s, virt_dns,
NULL)))
- {
- GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc));
- GNUNET_OS_process_close (proc);
- }
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc));
+ GNUNET_OS_process_close (proc);
+ }
GNUNET_free (virt_dns);
}
/* When more data is to be sent, reschedule */
if (head != NULL)
- server_notify = GNUNET_SERVER_notify_transmit_ready (head->client, ntohs (head->pkt.hdr.size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer, NULL);
+ server_notify =
+ GNUNET_SERVER_notify_transmit_ready (head->client,
+ ntohs (head->pkt.hdr.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, NULL);
- GNUNET_SERVER_client_drop(query->client);
+ GNUNET_SERVER_client_drop (query->client);
GNUNET_free (query);
return len;
}
GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader)));
memcpy (hdr + 1, dns, *sz);
- struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel);
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel);
+
if (NULL != s->head)
{
struct tunnel_notify_queue *element = s->head;
GNUNET_CONTAINER_DLL_remove (head, tail, element);
s->th =
- GNUNET_MESH_notify_transmit_ready (*tunnel,
- GNUNET_NO,
- 42,
+ GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
(const struct GNUNET_PeerIdentity *)
- NULL, element->len,
- element->cb, element->cls);
+ NULL, element->len, element->cb,
+ element->cls);
}
GNUNET_free (cls);
memcpy (buf, &cls_->hdr, size);
- struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel);
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel);
+
if (NULL != s->head)
{
- struct tunnel_notify_queue *element =
- s->head;
- struct tunnel_notify_queue *head =
- s->head;
- struct tunnel_notify_queue *tail =
- s->tail;;
+ struct tunnel_notify_queue *element = s->head;
+ struct tunnel_notify_queue *head = s->head;
+ struct tunnel_notify_queue *tail = s->tail;;
GNUNET_CONTAINER_DLL_remove (head, tail, element);
s->th =
- GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
- GNUNET_NO,
- 42,
+ GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_NO, 42,
GNUNET_TIME_relative_divide
(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
(const struct GNUNET_PeerIdentity *)
- NULL, element->len,
- element->cb, element->cls);
+ NULL, element->len, element->cb,
+ element->cls);
GNUNET_free (element);
}
"Connected to peer %s, %x, sending query with id %d\n",
GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id));
- struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel);
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel);
+
if (NULL == s->head)
{
s->th =
- GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
- GNUNET_YES,
- 42,
- GNUNET_TIME_UNIT_MINUTES,
- NULL,
- cls_->hdr.size,
- mesh_send,
- cls);
+ GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_YES, 42,
+ GNUNET_TIME_UNIT_MINUTES, NULL,
+ cls_->hdr.size, mesh_send, cls);
}
else
{
- struct tunnel_notify_queue *head =
- s->head;
- struct tunnel_notify_queue *tail =
- s->tail;
+ struct tunnel_notify_queue *head = s->head;
+ struct tunnel_notify_queue *tail = s->tail;
struct tunnel_notify_queue *element =
GNUNET_malloc (sizeof (struct tunnel_notify_queue));
struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
- struct tunnel_state *s = GNUNET_malloc(sizeof *s);
+ struct tunnel_state *s = GNUNET_malloc (sizeof *s);
+
s->head = NULL;
s->tail = NULL;
s->th = NULL;
cls_->tunnel =
- GNUNET_MESH_tunnel_create(mesh_handle, s, mesh_connect, NULL, cls_);
+ GNUNET_MESH_tunnel_create (mesh_handle, s, mesh_connect, NULL, cls_);
GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel,
GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER);
struct sockaddr_in dest;
- struct dns_pkt_parsed *pdns = parse_dns_packet(dns);
+ struct dns_pkt_parsed *pdns = parse_dns_packet (dns);
memset (&dest, 0, sizeof dest);
dest.sin_port = htons (53);
char *dns_resolver;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "dns", "EXTERNAL_DNS", &dns_resolver) ||
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "dns", "EXTERNAL_DNS",
+ &dns_resolver) ||
1 != inet_pton (AF_INET, dns_resolver, &dest.sin_addr))
inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr);
query_states[dns->s.id].valid = GNUNET_YES;
int i;
- for (i= 0; i < ntohs(pdns->s.qdcount); i++)
+
+ for (i = 0; i < ntohs (pdns->s.qdcount); i++)
+ {
+ if (pdns->queries[i]->qtype == htons (28) ||
+ pdns->queries[i]->qtype == htons (1))
{
- if (pdns->queries[i]->qtype == htons(28) ||
- pdns->queries[i]->qtype == htons(1))
- {
- query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
- break;
- }
+ query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
+ break;
}
- free_parsed_dns_packet(pdns);
+ }
+ free_parsed_dns_packet (pdns);
GNUNET_NETWORK_socket_sendto (dnsout, dns,
ntohs (message->size) -
+ sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */
struct answer_packet_list *answer =
- GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
answer->pkt.hdr.size = htons (len);
int i = 0;
- while (i < ntohs(pdns->s.ancount) &&
- ntohs(pdns->answers[i]->type) != 28 &&
- ntohs(pdns->answers[i]->type) != 1)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n", ntohs(pdns->answers[i]->type));
+ while (i < ntohs (pdns->s.ancount) && ntohs (pdns->answers[i]->type) != 28 &&
+ ntohs (pdns->answers[i]->type) != 1)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n",
+ ntohs (pdns->answers[i]->type));
i++;
-}
+ }
if (i >= ntohs (pdns->s.ancount))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer does not contain any usable answers.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Answer does not contain any usable answers.\n");
free_parsed_dns_packet (pdns);
GNUNET_free (answer);
return GNUNET_OK;
memcpy (answer->pkt.addr, pdns->answers[i]->data,
ntohs (pdns->answers[i]->data_len));
- memcpy(answer->pkt.from, query_states[dns->s.id].remote_ip, query_states[dns->s.id].addrlen);
- memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, query_states[dns->s.id].addrlen);
+ memcpy (answer->pkt.from, query_states[dns->s.id].remote_ip,
+ query_states[dns->s.id].addrlen);
+ memcpy (answer->pkt.to, query_states[dns->s.id].local_ip,
+ query_states[dns->s.id].addrlen);
answer->pkt.addrlen = query_states[dns->s.id].addrlen;
answer->pkt.dst_port = query_states[dns->s.id].local_port;
(struct dns_record_line *) (dpkt->data +
(query_states[dns->s.id].namelen) +
sizeof (struct dns_query_line) + 2);
- if (htons(28) == query_states[dns->s.id].qtype)
+ if (htons (28) == query_states[dns->s.id].qtype)
{
answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA;
dque->type = htons (28); /* AAAA */
drec_data->type = htons (28); /* AAAA */
drec_data->data_len = htons (16);
}
- else if (htons(1) == query_states[dns->s.id].qtype)
+ else if (htons (1) == query_states[dns->s.id].qtype)
{
answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A;
dque->type = htons (1); /* A */
drec_data->data_len = htons (4);
}
else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n", query_states[dns->s.id].qtype);
- GNUNET_assert(0);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n",
+ query_states[dns->s.id].qtype);
+ GNUNET_assert (0);
+ }
dque->class = htons (1); /* IN */
char *anname =
answer->client = query_states[dns->s.id].client;
if (server_notify == NULL)
- server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer,
- NULL);
+ server_notify =
+ GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
+ len, GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sent answer of length %d on to client, addroffset = %d\n", len,
2 /* We do not know the lenght of the answer yet */ ;
struct answer_packet_list *answer =
- GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
answer->pkt.hdr.size = htons (len);
answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV;
- memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen);
- memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen);
+ memcpy (answer->pkt.from, query_states[id].remote_ip,
+ query_states[id].addrlen);
+ memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen);
answer->pkt.dst_port = query_states[id].local_port;
answer->client = query_states[id].client;
if (server_notify == NULL)
- server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer, NULL);
+ server_notify =
+ GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, NULL);
}
/**
receive_dht (void *cls, struct GNUNET_TIME_Absolute exp
__attribute__ ((unused)), const GNUNET_HashCode * key
__attribute__ ((unused)),
- const struct GNUNET_PeerIdentity *get_path __attribute__ ((unused)),
- unsigned int get_path_length __attribute__ ((unused)),
- const struct GNUNET_PeerIdentity *put_path __attribute__ ((unused)),
- unsigned int put_path_length __attribute__ ((unused)),
- enum GNUNET_BLOCK_Type type, size_t size,
+ const struct GNUNET_PeerIdentity *get_path
+ __attribute__ ((unused)), unsigned int get_path_length
+ __attribute__ ((unused)),
+ const struct GNUNET_PeerIdentity *put_path
+ __attribute__ ((unused)), unsigned int put_path_length
+ __attribute__ ((unused)), enum GNUNET_BLOCK_Type type, size_t size,
const void *data)
{
+ sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */
struct answer_packet_list *answer =
- GNUNET_malloc (len +
- sizeof(struct answer_packet_list) - sizeof(struct answer_packet));
+ GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+ sizeof (struct answer_packet));
answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
answer->pkt.hdr.size = htons (len);
memcpy (&answer->pkt.service_descr.ports, &rec->ports,
sizeof (answer->pkt.service_descr.ports));
- memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen);
- memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen);
+ memcpy (answer->pkt.from, query_states[id].remote_ip,
+ query_states[id].addrlen);
+ memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen);
answer->pkt.addrlen = query_states[id].addrlen;
answer->pkt.dst_port = query_states[id].local_port;
GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
if (server_notify == NULL)
- server_notify = GNUNET_SERVER_notify_transmit_ready (answer->client, len,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer, NULL);
+ server_notify =
+ GNUNET_SERVER_notify_transmit_ready (answer->client, len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, NULL);
}
/**
query_states[dns->s.id].valid = GNUNET_YES;
query_states[dns->s.id].client = client;
- GNUNET_SERVER_client_keep(client);
- memcpy(query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen);
+ GNUNET_SERVER_client_keep (client);
+ memcpy (query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen);
query_states[dns->s.id].addrlen = pkt->addrlen;
query_states[dns->s.id].local_port = pkt->src_port;
- memcpy(query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen);
+ memcpy (query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen);
query_states[dns->s.id].namelen = strlen ((char *) dns->data) + 1;
if (query_states[dns->s.id].name != NULL)
GNUNET_free (query_states[dns->s.id].name);
query_states[dns->s.id].namelen);
int i;
- for (i= 0; i < ntohs(pdns->s.qdcount); i++)
+
+ for (i = 0; i < ntohs (pdns->s.qdcount); i++)
+ {
+ if (pdns->queries[i]->qtype == htons (28) ||
+ pdns->queries[i]->qtype == htons (1))
{
- if (pdns->queries[i]->qtype == htons(28) ||
- pdns->queries[i]->qtype == htons(1))
- {
- query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
- break;
- }
+ query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
+ break;
}
+ }
/* The query is for a .gnunet-address */
if (pdns->queries[0]->namelen > 9 &&
cls->handle =
GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES,
GNUNET_BLOCK_TYPE_DNS, &key,
- 5 /* DEFAULT_GET_REPLICATION */, GNUNET_DHT_RO_NONE, NULL,
- 0, &receive_dht, cls);
+ 5 /* DEFAULT_GET_REPLICATION */ ,
+ GNUNET_DHT_RO_NONE, NULL, 0, &receive_dht, cls);
goto outfree;
}
unsigned char virt_dns_bytes[16];
if (pkt->addrlen == 4)
- {
- char *virt_dns;
-
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No entry 'VIRTDNS' in configuration!\n");
- exit (1);
- }
-
- if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n",
- virt_dns);
- exit (1);
- }
+ {
+ char *virt_dns;
- GNUNET_free (virt_dns);
- }
- else if (pkt->addrlen == 16)
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
+ &virt_dns))
{
- char *virt_dns;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'VIRTDNS' in configuration!\n");
+ exit (1);
+ }
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6", &virt_dns))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No entry 'VIRTDNS6' in configuration!\n");
- exit (1);
- }
+ if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n",
+ virt_dns);
+ exit (1);
+ }
- if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS6': %s; %m!\n",
- virt_dns);
- exit (1);
- }
+ GNUNET_free (virt_dns);
+ }
+ else if (pkt->addrlen == 16)
+ {
+ char *virt_dns;
- GNUNET_free (virt_dns);
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6",
+ &virt_dns))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No entry 'VIRTDNS6' in configuration!\n");
+ exit (1);
}
- else
+
+ if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes))
{
- GNUNET_assert(0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error parsing 'VIRTDNS6': %s; %m!\n", virt_dns);
+ exit (1);
}
- if (memcmp(virt_dns_bytes,pkt->orig_to, pkt->addrlen) == 0)
+ GNUNET_free (virt_dns);
+ }
+ else
+ {
+ GNUNET_assert (0);
+ }
+
+ if (memcmp (virt_dns_bytes, pkt->orig_to, pkt->addrlen) == 0)
{
/* This is a packet that was sent directly to the virtual dns-server
*
cls_->hdr.size - sizeof (struct GNUNET_MessageHeader));
GNUNET_SCHEDULER_add_now (send_mesh_query, cls_);
- if (ntohs(pdns->s.qdcount) == 1)
+ if (ntohs (pdns->s.qdcount) == 1)
+ {
+ if (ntohs (pdns->queries[0]->qtype) == 1)
+ pdns->queries[0]->qtype = htons (28);
+ else if (ntohs (pdns->queries[0]->qtype) == 28)
+ pdns->queries[0]->qtype = htons (1);
+ else
{
- if (ntohs(pdns->queries[0]->qtype) == 1)
- pdns->queries[0]->qtype = htons(28);
- else if (ntohs(pdns->queries[0]->qtype) == 28)
- pdns->queries[0]->qtype = htons(1);
- else
-{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n");
- goto outfree;
-}
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n");
- struct dns_pkt *rdns = unparse_dns_packet (pdns);
- size_t size =
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n");
+ goto outfree;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n");
+ struct dns_pkt *rdns = unparse_dns_packet (pdns);
+ size_t size =
sizeof (struct GNUNET_MESH_Tunnel *) +
sizeof (struct GNUNET_MessageHeader) + (ntohs (message->size) -
sizeof (struct query_packet) +
1);
- struct tunnel_cls *cls_ = GNUNET_malloc (size);
+ struct tunnel_cls *cls_ = GNUNET_malloc (size);
- cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *);
+ cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *);
- cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size);
+ cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size);
- memcpy (&cls_->dns, rdns,
- cls_->hdr.size - sizeof (struct GNUNET_MessageHeader));
- GNUNET_SCHEDULER_add_now (send_mesh_query, cls_);
- GNUNET_free (rdns);
- }
+ memcpy (&cls_->dns, rdns,
+ cls_->hdr.size - sizeof (struct GNUNET_MessageHeader));
+ GNUNET_SCHEDULER_add_now (send_mesh_query, cls_);
+ GNUNET_free (rdns);
+ }
goto outfree;
}
/* The query should be sent to the network */
if (pkt->addrlen == 4)
- {
- struct sockaddr_in dest;
+ {
+ struct sockaddr_in dest;
- memset (&dest, 0, sizeof dest);
- dest.sin_port = htons (53);
- memcpy(&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen);
+ memset (&dest, 0, sizeof dest);
+ dest.sin_port = htons (53);
+ memcpy (&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen);
- GNUNET_NETWORK_socket_sendto (dnsout, dns,
- ntohs (pkt->hdr.size) -
- sizeof (struct query_packet) + 1,
- (struct sockaddr *) &dest, sizeof dest);
- }
+ GNUNET_NETWORK_socket_sendto (dnsout, dns,
+ ntohs (pkt->hdr.size) -
+ sizeof (struct query_packet) + 1,
+ (struct sockaddr *) &dest, sizeof dest);
+ }
else if (pkt->addrlen == 16)
- {
- struct sockaddr_in6 dest;
+ {
+ struct sockaddr_in6 dest;
- memset (&dest, 0, sizeof dest);
- dest.sin6_port = htons (53);
- memcpy(&dest.sin6_addr, pkt->orig_to, pkt->addrlen);
+ memset (&dest, 0, sizeof dest);
+ dest.sin6_port = htons (53);
+ memcpy (&dest.sin6_addr, pkt->orig_to, pkt->addrlen);
- GNUNET_NETWORK_socket_sendto (dnsout6, dns,
- ntohs (pkt->hdr.size) -
- sizeof (struct query_packet) + 1,
- (struct sockaddr *) &dest, sizeof dest);
- }
+ GNUNET_NETWORK_socket_sendto (dnsout6, dns,
+ ntohs (pkt->hdr.size) -
+ sizeof (struct query_packet) + 1,
+ (struct sockaddr *) &dest, sizeof dest);
+ }
outfree:
free_parsed_dns_packet (pdns);
dnsout6 = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_DGRAM, 0);
if (dnsout6 == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n");
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n");
+ return GNUNET_SYSERR;
+ }
memset (&addr, 0, sizeof (struct sockaddr_in6));
addr.sin6_family = AF_INET6;
return GNUNET_YES;
}
-void handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r);
+void
+handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen,
+ int r);
/**
* Read a response-packet of the UDP-Socket
#ifndef MINGW
if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout6), FIONREAD, &len))
{
- (void)open_port6 ();
+ (void) open_port6 ();
return;
}
#else
(struct sockaddr *) &addr, &addrlen);
if (r < 0)
- {
- (void)open_port6 ();
- return;
- }
+ {
+ (void) open_port6 ();
+ return;
+ }
+
+ struct sockaddr *addr_ = GNUNET_malloc (sizeof addr);
- struct sockaddr *addr_ = GNUNET_malloc(sizeof addr);
memcpy (addr_, &addr, sizeof addr);
- handle_response(dns, addr_, 4, r);
+ handle_response (dns, addr_, 4, r);
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout6,
&read_response6, NULL);
#ifndef MINGW
if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "ioctl");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl");
unhijack (dnsoutport);
if (GNUNET_YES == open_port ())
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL);
(struct sockaddr *) &addr, &addrlen);
if (r < 0)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "recvfrom");
- unhijack (dnsoutport);
- if (GNUNET_YES == open_port ())
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL);
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
+ unhijack (dnsoutport);
+ if (GNUNET_YES == open_port ())
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL);
+ return;
+ }
+
+ struct sockaddr *addr_ = GNUNET_malloc (sizeof addr);
- struct sockaddr *addr_ = GNUNET_malloc(sizeof addr);
memcpy (addr_, &addr, sizeof addr);
- handle_response(dns, addr_, 4, r);
+ handle_response (dns, addr_, 4, r);
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout,
&read_response, NULL);
}
void
-handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r)
+handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen,
+ int r)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n",
ntohs (dns->s.id));
if (query_states[dns->s.id].valid == GNUNET_YES)
+ {
+ if (query_states[dns->s.id].tunnel != NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Answer to query %d for a remote peer!\n", ntohs (dns->s.id));
+ /* This response should go through a tunnel */
+ uint32_t *c =
+ GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r);
+ *c = r;
+ struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1);
+
+ *t = query_states[dns->s.id].tunnel;
+ memcpy (t + 1, dns, r);
+ struct tunnel_state *s =
+ GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel);
+ if (NULL == s->th)
+ {
+ s->th =
+ GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel,
+ GNUNET_YES, 32,
+ GNUNET_TIME_UNIT_MINUTES, NULL,
+ r +
+ sizeof (struct
+ GNUNET_MessageHeader),
+ mesh_send_response, c);
+ }
+ else
+ {
+ struct tunnel_notify_queue *element =
+ GNUNET_malloc (sizeof (struct tunnel_notify_queue));
+ element->cls = c;
+ element->len = r + sizeof (struct GNUNET_MessageHeader);
+ element->cb = mesh_send_response;
+
+ GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element);
+ }
+ }
+ else
{
- if (query_states[dns->s.id].tunnel != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Answer to query %d for a remote peer!\n",
- ntohs (dns->s.id));
- /* This response should go through a tunnel */
- uint32_t *c =
- GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r);
- *c = r;
- struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1);
-
- *t = query_states[dns->s.id].tunnel;
- memcpy (t + 1, dns, r);
- struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel);
- if (NULL == s->th)
- {
- s->th =
- GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel,
- GNUNET_YES,
- 32,
- GNUNET_TIME_UNIT_MINUTES,
- NULL,
- r +
- sizeof (struct
- GNUNET_MessageHeader),
- mesh_send_response, c);
- }
- else
- {
- struct tunnel_notify_queue *element =
- GNUNET_malloc (sizeof (struct tunnel_notify_queue));
- element->cls = c;
- element->len = r + sizeof (struct GNUNET_MessageHeader);
- element->cb = mesh_send_response;
-
- GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element);
- }
- }
+ query_states[dns->s.id].valid = GNUNET_NO;
+
+ size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */
+ struct answer_packet_list *answer =
+ GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+ (sizeof (struct answer_packet)));
+ answer->pkt.hdr.type =
+ htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
+ answer->pkt.hdr.size = htons (len);
+ answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
+ answer->pkt.addrlen = addrlen;
+ if (addrlen == 16)
+ {
+ struct sockaddr_in6 *addr_ = (struct sockaddr_in6 *) addr;
+
+ memcpy (answer->pkt.from, &addr_->sin6_addr, addrlen);
+ memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen);
+ }
+ else if (addrlen == 4)
+ {
+ struct sockaddr_in *addr_ = (struct sockaddr_in *) addr;
+
+ memcpy (answer->pkt.from, &addr_->sin_addr.s_addr, addrlen);
+ memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen);
+ }
else
- {
- query_states[dns->s.id].valid = GNUNET_NO;
-
- size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */
- struct answer_packet_list *answer =
- GNUNET_malloc (len + sizeof(struct answer_packet_list) - (sizeof(struct answer_packet)));
- answer->pkt.hdr.type =
- htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
- answer->pkt.hdr.size = htons (len);
- answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
- answer->pkt.addrlen = addrlen;
- if (addrlen == 16)
- {
- struct sockaddr_in6 *addr_ = (struct sockaddr_in6*)addr;
- memcpy(answer->pkt.from, &addr_->sin6_addr, addrlen);
- memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen);
- }
- else if (addrlen == 4)
- {
- struct sockaddr_in *addr_ = (struct sockaddr_in*)addr;
- memcpy(answer->pkt.from, &addr_->sin_addr.s_addr, addrlen);
- memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen);
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen);
- GNUNET_assert(0);
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n", addrlen);
- answer->pkt.dst_port = query_states[dns->s.id].local_port;
- memcpy (answer->pkt.data, dns, r);
- answer->client = query_states[dns->s.id].client;
-
- GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
-
- if (server_notify == NULL)
- server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
- len, GNUNET_TIME_UNIT_FOREVER_REL,
- &send_answer,
- NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen);
+ GNUNET_assert (0);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n",
+ addrlen);
+ answer->pkt.dst_port = query_states[dns->s.id].local_port;
+ memcpy (answer->pkt.data, dns, r);
+ answer->client = query_states[dns->s.id].client;
+
+ GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
+
+ if (server_notify == NULL)
+ server_notify =
+ GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
+ len,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &send_answer, NULL);
}
- GNUNET_free(addr);
+ }
+ GNUNET_free (addr);
}
GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
data.expiration_time =
- GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_HOURS, 2)));
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_HOURS, 2)));
/* Sign the block */
if (GNUNET_OK !=
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n",
*((unsigned int *) &data.service_descriptor), size);
- GNUNET_DHT_put (dht, &data.service_descriptor, 5 /* DEFAULT_PUT_REPLICATION */,
+ GNUNET_DHT_put (dht, &data.service_descriptor,
+ 5 /* DEFAULT_PUT_REPLICATION */ ,
GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size,
(char *) &data,
GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT"))
apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER;
- mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, mesh_handlers, apptypes);
+ mesh_handle =
+ GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel,
+ mesh_handlers, apptypes);
cfg = cfg_;
dht = GNUNET_DHT_connect (cfg, 1024);
GNUNET_SCHEDULER_add_now (publish_names, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SERVER_disconnect_notify(server, &client_disconnect, NULL);
+ GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
cls);
}