82#include "gnunet_signatures.h"
88#define RING_BUFFER_SIZE 16
93#define MAX_FC_RETRANSMIT_COUNT 1000
99#define MAX_CUMMULATIVE_ACKS 64
113#define FC_NO_CHANGE_REPLY_PROBABILITY 8
119#define IN_PACKET_SIZE_WITHOUT_MTU 128
125#define GOODPUT_AGING_SLOTS 4
131#define DEFAULT_WINDOW_SIZE (128 * 1024)
141#define MAX_INCOMING_REQUEST 16
147#define MAX_DV_DISCOVERY_SELECTION 16
157#define RECV_WINDOW_SIZE 4
166#define MIN_DV_PATH_LENGTH_FOR_INITIATOR 3
171#define MAX_DV_HOPS_ALLOWED 16
177#define MAX_DV_LEARN_PENDING 64
182#define MAX_DV_PATHS_TO_TARGET 3
189#define DELAY_WARN_THRESHOLD \
190 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
196#define DV_FORWARD_TIMEOUT \
197 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
202#define DEFAULT_ACK_WAIT_DURATION \
203 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
210#define DV_QUALITY_RTT_THRESHOLD \
211 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
217#define DV_PATH_VALIDITY_TIMEOUT \
218 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
224#define BACKCHANNEL_INACTIVITY_TIMEOUT \
225 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
231#define DV_PATH_DISCOVERY_FREQUENCY \
232 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
237#define EPHEMERAL_VALIDITY \
238 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
243#define REASSEMBLY_EXPIRATION \
244 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
250#define FAST_VALIDATION_CHALLENGE_FREQ \
251 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
256#define MAX_VALIDATION_CHALLENGE_FREQ \
257 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1)
264#define ACK_CUMMULATOR_TIMEOUT \
265 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
271#define DV_LEARN_BASE_FREQUENCY GNUNET_TIME_UNIT_MINUTES
277#define DV_LEARN_QUALITY_THRESHOLD 100
282#define MAX_ADDRESS_VALID_UNTIL \
283 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1)
288#define ADDRESS_VALIDATION_LIFETIME \
289 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
297#define MIN_DELAY_ADDRESS_VALIDATION GNUNET_TIME_UNIT_MILLISECONDS
305#define VALIDATION_RTT_BUFFER_FACTOR 3
313#define COMMUNICATOR_TOTAL_QUEUE_LIMIT 512
320#define QUEUE_LENGTH_LIMIT 32
325#define QUEUE_ENTRY_TIMEOUT \
326 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
333 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
2795 uint32_t last_window_consum_limit;
3121 "free_pending_acknowledgement\n");
3130 "remove pa from message\n");
3132 "remove pa from message %" PRIu64
"\n",
3135 "remove pa from message %u\n",
3138 "remove pa from message %s\n",
3169 while (NULL != (frag = root->
head_frag))
3174 while (NULL != (pa = frag->
pa_head))
3180 if (NULL != frag->
qe)
3183 frag->
qe->
pm = NULL;
3213 tc->details.core.pending_msg_head,
3214 tc->details.core.pending_msg_tail,
3217 if ((NULL != vl) && (NULL ==
pm->frag_parent))
3220 "Removing pm %" PRIu64
"\n",
3236 while (NULL != (pa =
pm->pa_head))
3240 "free pending pa null\n");
3241 if (NULL ==
pm->pa_tail)
3243 "free pending pa_tail null\n");
3246 "free pending pa prev null\n");
3249 "free pending pa next null\n");
3260 if (NULL !=
pm->bpm)
3263 if (NULL !=
pm->bpm->qe)
3274 "Freeing pm done\n");
3359 "free virtual link %p\n",
3411 if (NULL != vs->revalidation_task)
3414 vs->revalidation_task = NULL;
3420 "Remove key %s for address %s map size %u contains %u during freeing state\n",
3549 "Informing CORE clients about disconnect from %s\n",
3585 if (NULL != (vl =
dv->
vl))
3635 size_t addr_len = strlen (
address) + 1;
3640 md->
nt = htonl ((uint32_t)
nt);
3646 md->
cs = htonl ((uint32_t)
me->cs);
3649 memcpy (&md[1],
address, addr_len);
3673 if (
tc->details.monitor.one_shot)
3705 "Client %p of type %u connected\n",
3743 "Freeing neighbour\n");
3748 while (NULL != (dvh = neighbour->
dv_head))
3756 if (NULL != neighbour->
get)
3759 neighbour->
get = NULL;
3761 if (NULL != neighbour->
sc)
3766 neighbour->
sc = NULL;
3768 if (NULL != (
vl = neighbour->
vl))
3782 neighbour->
vl = NULL;
3817 "Informing CORE clients about connection to %s\n",
3848 if (s->tc->details.communicator.address_prefix !=
3849 queue->tc->details.communicator.address_prefix)
3852 "queue address %s qid %u compare with queue: address %s qid %u\n",
3857 if ((s->priority >
queue->priority) && (0 < s->q_capacity) &&
3885 queue->tc->details.communicator.
3889 if (
queue->tc->details.communicator.total_queue_length >=
3893 "Transmission on queue %s (QID %u) throttled due to communicator queue limit\n",
3898 "# Transmission throttled due to communicator queue limit",
3907 "Transmission on queue %s (QID %u) throttled due to communicator queue length limit\n",
3911 "# Transmission throttled due to queue queue limit",
3917 if (0 ==
queue->q_capacity)
3920 "Transmission on queue %s (QID %u) throttled due to communicator message has capacity %"
3926 "# Transmission throttled due to message queue capacity",
3933 if (NULL !=
queue->transmit_task)
3935 queue->transmit_task =
3939 "Considering transmission on queue `%s' QID %llu to %s\n",
3941 (
unsigned long long)
queue->qid,
3962 "Checking if link is down\n");
3970 pos->path_valid_until);
3985 if ((NULL == vl->
n) && (NULL == vl->
dv))
4016 "Cleaning up queue %u\n",
queue->qid);
4017 if (NULL !=
queue->mo)
4022 if (NULL !=
queue->transmit_task)
4025 queue->transmit_task = NULL;
4027 while (NULL != (pa =
queue->pa_head))
4038 tc->details.communicator.queue_head,
4039 tc->details.communicator.queue_tail,
4042 tc->details.communicator.total_queue_length);
4044 "Cleaning up queue with length %u\n",
4045 queue->queue_length);
4046 while (NULL != (
qe =
queue->queue_head))
4049 queue->queue_length--;
4050 tc->details.communicator.total_queue_length--;
4060 tc->details.communicator.total_queue_length))
4065 "# Transmission throttled due to communicator queue limit",
4068 for (
struct Queue *s =
tc->details.communicator.queue_head; NULL != s;
4078 if ((NULL != vl) && (neighbour == vl->
n))
4101 tc->details.communicator.addr_tail,
4103 if (NULL != ale->
sc)
4110 if (NULL != ale->
st)
4176 "Unknown Client %p disconnected, cleaning up.\n",
4182 "CORE Client %p disconnected, cleaning up.\n",
4187 while (NULL != (
pm =
tc->details.core.pending_msg_head))
4190 tc->details.core.pending_msg_head,
4191 tc->details.core.pending_msg_tail,
4200 "MONITOR Client %p disconnected, cleaning up.\n",
4207 "COMMUNICATOR Client %p disconnected, cleaning up.\n",
4213 if (NULL !=
tc->details.communicator.free_queue_entry_task)
4215 tc->details.communicator.free_queue_entry_task);
4216 while (NULL != (
q =
tc->details.communicator.queue_head))
4218 while (NULL != (ale =
tc->details.communicator.addr_head))
4226 "APPLICATION Client %p disconnected, cleaning up.\n",
4239 "Our last client disconnected\n");
4266 "Telling new CORE client about existing connection to %s\n",
4292 while (NULL != (cmc = vl->
cmc_tail))
4333 "New CORE client with PID %s registered\n",
4393 "client send response\n");
4402 "Confirming transmission of <%" PRIu64
"> to %s\n",
4424 unsigned int hops_array_length)
4426 uint64_t
choices[hops_array_length];
4428 unsigned int dv_count;
4446 if (dv_count <= hops_array_length)
4451 hops_array[dv_count++] = pos;
4454 for (
unsigned int i = 0; i < hops_array_length; i++)
4462 for (
unsigned int j = 0; j < i; j++)
4481 for (
unsigned int i = 0; i < hops_array_length; i++)
4483 hops_array[dv_count++] = pos;
4528 if (0 != ntohl (cmc->
im.
fc_on))
4535 "Acknowledge message with flow control id %" PRIu64
"\n",
4587 "# RECV_OK dropped: virtual link unknown",
4596 "CORE ack receiving message, increased CORE recv window to %d\n",
4602 while (NULL != (cmc = vl->
cmc_tail))
4629 "Receive-only communicator connected\n");
4632 tc->details.communicator.address_prefix =
4634 tc->details.communicator.cc =
4636 tc->details.communicator.can_burst
4639 "Communicator for peer %s with prefix '%s' connected %s\n",
4641 tc->details.communicator.address_prefix,
4642 tc->details.communicator.can_burst ?
"can burst" :
4666 msize = ntohs (cb->
header.
size) -
sizeof(*cb);
4668 isize = ntohs (inbox->
size);
4674 is = (
const char *) inbox;
4678 if (
'\0' !=
is[msize - 1])
4723 "freeing timedout queue entries\n");
4725 tc->details.communicator.free_queue_entry_task = NULL;
4732 "checking QID %u for timedout queue entries\n",
4743 "diff to now %s \n",
4748 "Freeing timed out QueueEntry with MID %" PRIu64
4772 size_t payload_size)
4781 "Queueing %u bytes of payload for transmission <%" PRIu64
4782 "> on queue %llu to %s\n",
4783 (
unsigned int) payload_size,
4784 (NULL ==
pm) ? 0 :
pm->logging_uuid,
4785 (
unsigned long long)
queue->qid,
4793 memcpy (&smt[1],
payload, payload_size);
4802 "Create QueueEntry with MID %" PRIu64
4803 " and QID %u and prefix %s\n",
4806 queue->tc->details.communicator.address_prefix);
4817 "Retransmitting message <%" PRIu64
4818 "> remove pm from qe with MID: %llu \n",
4820 (
unsigned long long)
pm->qe->mid);
4826 if (0 ==
queue->q_capacity)
4833 " (pm type %u) was not send because queue has no capacity.\n",
4843 queue->queue_length++;
4844 queue->tc->details.communicator.total_queue_length++;
4846 queue->q_capacity--;
4848 "Queue %s with qid %u has capacity %" PRIu64
"\n",
4853 queue->tc->details.communicator.total_queue_length)
4857 if (0 ==
queue->q_capacity)
4864 if (NULL ==
tc->details.communicator.free_queue_entry_task)
4865 tc->details.communicator.free_queue_entry_task =
4871 if (NULL !=
pm && NULL != (pa =
pm->pa_head))
4873 while (
pm != pa->
pm)
4879 "Sending message MID %" PRIu64
4880 " of type %u (%u) and size %lu with MQ %p queue %s (QID %u) pending %"
4885 (
unsigned long) payload_size,
4889 (NULL ==
pm) ? 0 :
pm->logging_uuid);
4911 unsigned int candidates;
4923 for (
struct Queue *pos = n->queue_head; NULL != pos;
4924 pos = pos->next_neighbour)
4927 (pos->validated_until.abs_value_us > now.
abs_value_us))
4930 if (0 == candidates)
4935 "Could not route message of type %u to %s: no valid queue\n",
4939 "# route selection failed (all no valid queue)",
4952 for (
struct Queue *pos = n->queue_head; NULL != pos;
4953 pos = pos->next_neighbour)
4956 (pos->validated_until.abs_value_us > now.
abs_value_us))
4958 if ((sel1 == candidates) || (sel2 == candidates))
4961 "Routing message of type %u to %s using %s (#%u)\n",
4965 (sel1 == candidates) ? 1 : 2);
5025 sizeof(
key->material),
5027 "gnunet-transport-dv-key",
5028 strlen (
"gnunet-transport-dv-key")
5036 "Deriving backchannel key based on KM %s and IV %s\n",
5042 GCRY_CIPHER_MODE_CTR,
5045 &
key->material.aes_key,
5046 sizeof(
key->material.aes_key)));
5047 gcry_cipher_setctr (
key->cipher,
5048 &
key->material.aes_ctr,
5049 sizeof(
key->material.aes_ctr));
5085 gcry_cipher_encrypt (
key->cipher, dst, in_size, in, in_size));
5106 gcry_cipher_decrypt (
key->cipher,
5120 gcry_cipher_close (
key->cipher);
5156 unsigned int num_dvhs,
5166 uint16_t enc_body_size = ntohs (hdr->
size);
5193 sizeof(box_hdr.
iv));
5210 for (
unsigned int i = 0; i < num_dvhs; i++)
5213 unsigned int num_hops = dvh->
distance + 1;
5221 box_hdr.
orig_size = htons (
sizeof(buf));
5222 box_hdr.
num_hops = htons (num_hops);
5223 memcpy (buf, &box_hdr,
sizeof(box_hdr));
5234 for (
unsigned int j = 0; j < num_hops; j++)
5243 "Routing message of type %u to %s using DV (#%u/%u) via %s\n",
5252 memcpy (&dhops[num_hops],
enc,
sizeof(
enc));
5308 "Trying to route message of type %u to %s without fc\n",
5328 if ((NULL == n) && (NULL == dv))
5331 "Cannot route message of type %u to %s: no route\n",
5335 "# Messages dropped in routing: no acceptable method",
5341 "Routing message of type %u to %s with options %X\n",
5354 if ((NULL != n) && (NULL != dv))
5362 "Try to route message of type %u to %s without fc via neighbour\n",
5379 "Failed to route message, could not determine DV path\n");
5383 "encapsulate_for_dv 1\n");
5433 char *addr = (
char *) &tgna[1];
5436 "sending address %s length %u\n",
5472 size_t addresses_size =
5474 ->size_of_global_addresses;
5514 "Sending FC seq %u to %s with new window %llu %lu %u\n",
5536 "FC retransmission to %s failed, will retry in %s\n",
5586 "check_vl_transmission to target %s\n",
5595 "check_vl_transmission loop\n");
5602 "Stalled message %" PRIu64
5603 " transmission on VL %s due to flow control: %llu < %llu\n",
5607 (
unsigned long long) (
pm->bytes_msg
5613 "Target window on VL %s not stalled. Scheduling transmission on queue\n",
5626 "Direct neighbour %s not stalled\n",
5635 "Neighbour Queue QID: %u (%u) busy or invalid\n",
5648 struct Neighbour *nh_iter = pos->next_hop;
5651 if (pos->path_valid_until.abs_value_us <= now.
abs_value_us)
5661 "Stalled message %" PRIu64
5662 " transmission on next hop %s due to flow control: %llu < %llu\n",
5667 (
unsigned long long) (
pm->bytes_msg
5669 outbound_fc_window_size_used));
5679 "Next hop neighbour %s not stalled\n",
5688 "DV Queue QID: %u (%u) busy or invalid\n",
5696 "Eligible message %" PRIu64
" of size %u to %s: %llu/%llu\n",
5701 (
unsigned long long) (
pm->bytes_msg
5726 bytes_msg = ntohs (obmm->
size);
5732 "Don't have %s as a neighbour (anymore).\n",
5740 "# messages dropped (neighbour unknown)",
5748 "1 created pm %p storing vl %p\n",
5755 pm->bytes_msg = bytes_msg;
5756 memcpy (&
pm[1], obmm, bytes_msg);
5758 "Sending message of type %u with %u bytes as <%" PRIu64
5765 tc->details.core.pending_msg_head,
5766 tc->details.core.pending_msg_tail,
5796 uint16_t isize = ntohs (inbox->
size);
5797 const char *
is = ((
const char *) &cb[1]) + isize;
5798 size_t slen = strlen (
is) + 1;
5809 "Preparing backchannel transmission to %s:%s of type %u and size %u\n",
5812 ntohs (inbox->
type),
5813 ntohs (inbox->
size));
5818 memcpy (&be[1], inbox, isize);
5889 "Failed to store our own address `%s' in peerstore!\n",
5893 "Successfully stored our own address `%s' in peerstore!\n",
5922 if (NULL == ale->
sc)
5925 "Failed to store our address `%s' with peerstore\n",
5948 unsigned int add_success;
5950 dash = strchr (ale->
address,
'-');
5960 "Storing our address `%s' in peerstore until %s!\n",
5968 "Storing our address `%s' %s\n",
5970 GNUNET_NO == add_success ?
"not done" :
"failed");
5978 "Storing our address `%s'\n",
6012 char *address_without_port;
6016 ale->
address = (
const char *) &ale[1];
6020 memcpy (&ale[1],
address, slen);
6023 "Is this %s a local address (%s)\n",
6024 address_without_port,
6026 if (0 != strcmp (
"127.0.0.1", address_without_port))
6051 "Communicator added address `%s'!\n",
6052 (
const char *) &aam[1]);
6053 slen = ntohs (aam->
header.
size) -
sizeof(*aam);
6055 memcpy (
address, &aam[1], slen);
6063 tc->details.communicator.addr_tail,
6094 if (dam->
aid != ale->aid)
6098 "Communicator deleted address `%s'!\n",
6105 "Communicator removed address we did not even have.\n");
6154 unsigned int free_cmc)
6156 uint16_t
size = ntohs (
mh->size);
6162 "# CORE messages dropped (FC arithmetic overflow)",
6166 "CORE messages of type %u with %u bytes dropped (FC arithmetic overflow)\n",
6167 (
unsigned int) ntohs (
mh->type),
6168 (
unsigned int) ntohs (
mh->size));
6176 "# CORE messages dropped (FC window overflow)",
6180 "CORE messages of type %u with %u bytes dropped (FC window overflow)\n",
6181 (
unsigned int) ntohs (
mh->type),
6182 (
unsigned int) ntohs (
mh->size));
6208 memcpy (&im[1],
mh,
size);
6215 "Dropped message to CORE: no CORE client connected!\n");
6221 "Dropped message of type %u with %u bytes to CORE: no CORE client connected!\n",
6222 (
unsigned int) ntohs (
mh->type),
6223 (
unsigned int) ntohs (
mh->size));
6229 "Delivered message from %s of type %u to CORE recv window %d\n",
6263 uint16_t
size = ntohs (
mh->size);
6266 "Handling raw message of type %u with %u bytes\n",
6267 (
unsigned int) ntohs (
mh->type),
6268 (
unsigned int) ntohs (
mh->size));
6311 "Storing message for %s and type %u (%u) in ring buffer head %u is full %u\n",
6313 (
unsigned int) ntohs (
mh->type),
6314 (
unsigned int) ntohs (mh_copy->
type),
6326 "%u items stored in ring buffer\n",
6422 "Sending ACK with %u components to %s\n",
6432 for (
unsigned int i = 0; i < ac->
num_acks; i++)
6483 "Scheduling ACK %s for transmission to %s\n",
6589 "No virtual link for %s to handle fragment\n",
6613 fsize = ntohs (fb->
header.
size) -
sizeof(*fb);
6614 if (NULL == (rc = fc.
rc))
6617 + (msize + 7) / 8 *
sizeof(uint8_t) );
6633 target = (
char *) &rc[1];
6640 "Received fragment with size %u at offset %u/%u %u bytes missing from %s for NEW message %"
6651 target = (
char *) &rc[1];
6653 "Received fragment at offset %u/%u from %s for message %u\n",
6674 if (frag_off + fsize > msize)
6681 memcpy (&target[frag_off], &fb[1], fsize);
6683 for (
unsigned int i = frag_off; i < frag_off + fsize; i++)
6685 if (0 == (rc->
bitfield[i / 8] & (1 << (i % 8))))
6687 rc->
bitfield[i / 8] |= (1 << (i % 8));
6718 "Fragment reassembly complete for message %u\n",
6748 "check_send_msg with size %u: inner msg type %u and size %u (%lu %lu)\n",
6776 "Received reliability box from %s with UUID %s of type %u\n",
6779 (
unsigned int) ntohs (inbox->
type));
6837 uint16_t bytes_transmitted_ok)
6841 unsigned int age =
get_age ();
6863 uint16_t bytes_transmitted_ok)
6879 uint16_t bytes_transmitted_ok)
6898 "Complete transmission of message %" PRIu64
" %u\n",
6911 pos =
pm->frag_parent;
6915 "pos frag_off %lu pos bytes_msg %lu pmt %u parent %u\n",
6928 pos =
pm->frag_parent;