aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-11-22 22:46:43 +0100
committerChristian Grothoff <christian@grothoff.org>2018-11-22 22:46:43 +0100
commitfbc5f3876a2ed52f18e2a2810e3cdda497cc99ea (patch)
treed01a9a8f202dd53a6ff6901c190d4d7031da1baa /src
parentc87f73a07df468eccedbe1fdfa82bdd5b633a0d5 (diff)
downloadgnunet-fbc5f3876a2ed52f18e2a2810e3cdda497cc99ea.tar.gz
gnunet-fbc5f3876a2ed52f18e2a2810e3cdda497cc99ea.zip
add design sketch for new ATS API
Diffstat (limited to 'src')
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/gnunet_ats_application_service.h99
-rw-r--r--src/include/gnunet_ats_transport_service.h238
-rw-r--r--src/include/gnunet_transport_communication_service.h32
-rw-r--r--src/transport/gnunet-communicator-unix.c44
-rw-r--r--src/transport/gnunet-service-tng.c16
-rw-r--r--src/transport/transport.h10
-rw-r--r--src/transport/transport_api2_communication.c105
8 files changed, 480 insertions, 66 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 185f649ac..9d0c4f8ea 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -29,6 +29,8 @@ gnunetinclude_HEADERS = \
29 gnunet_applications.h \ 29 gnunet_applications.h \
30 gnunet_arm_service.h \ 30 gnunet_arm_service.h \
31 gnunet_ats_service.h \ 31 gnunet_ats_service.h \
32 gnunet_ats_application_service.h \
33 gnunet_ats_transport_service.h \
32 gnunet_ats_plugin.h \ 34 gnunet_ats_plugin.h \
33 gnunet_bandwidth_lib.h \ 35 gnunet_bandwidth_lib.h \
34 gnunet_bio_lib.h \ 36 gnunet_bio_lib.h \
diff --git a/src/include/gnunet_ats_application_service.h b/src/include/gnunet_ats_application_service.h
new file mode 100644
index 000000000..af92d5639
--- /dev/null
+++ b/src/include/gnunet_ats_application_service.h
@@ -0,0 +1,99 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18/**
19 * @file
20 * Bandwidth allocation API for applications to interact with
21 *
22 * @author Christian Grothoff
23 * @author Matthias Wachs
24 *
25 * @defgroup ats ATS service
26 * Bandwidth allocation
27 *
28 * @see [Documentation](https://gnunet.org/ats-subsystem)
29 *
30 * @{
31 */
32#ifndef GNUNET_ATS_APPLICATION_SERVICE_H
33#define GNUNET_ATS_APPLICATION_SERVICE_H
34
35#include "gnunet_constants.h"
36#include "gnunet_util_lib.h"
37
38/**
39 * Handle to the ATS subsystem for making suggestions about
40 * connections the peer would like to have.
41 */
42struct GNUNET_ATS_ConnectivityHandle;
43
44
45/**
46 * Initialize the ATS connectivity suggestion client handle.
47 *
48 * @param cfg configuration to use
49 * @return ats connectivity handle, NULL on error
50 */
51struct GNUNET_ATS_ConnectivityHandle *
52GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
53
54
55/**
56 * Shutdown ATS connectivity suggestion client.
57 *
58 * @param ch handle to destroy
59 */
60void
61GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch);
62
63
64/**
65 * Handle for address suggestion requests.
66 */
67struct GNUNET_ATS_ConnectivitySuggestHandle;
68
69
70/**
71 * An application would like to communicate with a peer. ATS should
72 * allocate bandwith using a suitable address for requiremetns @a pk
73 * to transport.
74 *
75 * @param ch handle
76 * @param peer identity of the peer we need an address for
77 * @param pk what kind of connectivity will the application require (can be
78 * #GNUNET_MQ_PREFERENCE_NONE, we will still try to connect)
79 * @param bw desired bandwith, can be zero (we will still try to connect)
80 * @return suggestion handle, NULL if request is already pending
81 */
82struct GNUNET_ATS_ConnectivitySuggestHandle *
83GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
84 const struct GNUNET_PeerIdentity *peer,
85 enum GNUNET_MQ_PreferenceKind pk,
86 struct GNUNET_BANDWIDTH_Value32NBO bw);
87
88
89/**
90 * We no longer care about communicating with a peer.
91 *
92 * @param sh handle
93 */
94void
95GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh);
96
97/** @} */ /* end of group */
98
99/* end of file gnunet_ats_application_service.h */
diff --git a/src/include/gnunet_ats_transport_service.h b/src/include/gnunet_ats_transport_service.h
new file mode 100644
index 000000000..b069f8b24
--- /dev/null
+++ b/src/include/gnunet_ats_transport_service.h
@@ -0,0 +1,238 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18/**
19 * @file
20 * Bandwidth allocation API for the transport service
21 *
22 * @author Christian Grothoff
23 * @author Matthias Wachs
24 *
25 * @defgroup ats ATS service
26 * Bandwidth allocation for transport service
27 *
28 * @see [Documentation](https://gnunet.org/ats-subsystem)
29 *
30 * @{
31 */
32#ifndef GNUNET_ATS_TRANSPORT_SERVICE_H
33#define GNUNET_ATS_TRANSPORT_SERVICE_H
34
35#include "gnunet_constants.h"
36#include "gnunet_util_lib.h"
37#include "gnunet_nt_lib.h"
38#include "gnunet_transport_communication_service.h"
39
40
41/**
42 * ATS performance characteristics for an address.
43 */
44struct GNUNET_ATS_Properties
45{
46
47 /**
48 * Delay. Time between when the time packet is sent and the packet
49 * arrives. FOREVER if we did not (successfully) measure yet.
50 */
51 struct GNUNET_TIME_Relative delay;
52
53 /**
54 * Confirmed successful payload on this connection from this peer to
55 * the other peer.
56 *
57 * Unit: [bytes/second]
58 */
59 uint32_t goodput_out;
60
61 /**
62 * Confirmed useful payload on this connection to this peer from
63 * the other peer.
64 *
65 * Unit: [bytes/second]
66 */
67 uint32_t goodput_in;
68
69 /**
70 * Actual traffic on this connection from this peer to the other peer.
71 * Includes transport overhead.
72 *
73 * Unit: [bytes/second]
74 */
75 uint32_t utilization_out;
76
77 /**
78 * Actual traffic on this connection from the other peer to this peer.
79 * Includes transport overhead.
80 *
81 * Unit: [bytes/second]
82 */
83 uint32_t utilization_in;
84
85 /**
86 * Distance on network layer (required for distance-vector routing)
87 * in hops. Zero for direct connections (i.e. plain TCP/UDP).
88 */
89 uint32_t distance;
90
91 /**
92 * MTU of the network layer, UINT32_MAX for no MTU (stream).
93 *
94 * Unit: [bytes]
95 */
96 uint32_t mtu;
97
98 /**
99 * Which network scope does the respective address belong to?
100 */
101 enum GNUNET_NetworkType nt;
102
103 /**
104 * What characteristics does this communicator have?
105 */
106 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
107
108};
109
110
111/* ******************************** Scheduling API ***************************** */
112
113/**
114 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
115 */
116struct GNUNET_ATS_SchedulingHandle;
117
118/**
119 * Opaque session handle, to be defined by transport. Contents not known to ATS.
120 */
121struct GNUNET_ATS_Session;
122
123
124/**
125 * Signature of a function called by ATS with the current bandwidth
126 * allocation to be used as determined by ATS.
127 *
128 * @param cls closure
129 * @param session session this is about
130 * @param bandwidth_out assigned outbound bandwidth for the connection,
131 * 0 to signal disconnect
132 * @param bandwidth_in assigned inbound bandwidth for the connection,
133 * 0 to signal disconnect
134 */
135typedef void
136(*GNUNET_ATS_AllocationCallback) (void *cls,
137 struct GNUNET_ATS_Session *session,
138 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
139 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
140
141
142/**
143 * Signature of a function called by ATS suggesting transport to
144 * try connecting with a particular address.
145 *
146 * @param cls closure
147 * @param pid target peer
148 * @param address the address to try
149 */
150typedef void
151(*GNUNET_ATS_SuggestionCallback) (void *cls,
152 const struct GNUNET_PeerIdentity *pid,
153 const char *address);
154
155
156/**
157 * Initialize the ATS scheduling subsystem.
158 *
159 * @param cfg configuration to use
160 * @param alloc_cb notification to call whenever the allocation changed
161 * @param alloc_cb_cls closure for @a alloc_cb
162 * @param suggest_cb notification to call whenever the suggestation is made
163 * @param suggest_cb_cls closure for @a suggest_cb
164 * @return ats context
165 */
166struct GNUNET_ATS_SchedulingHandle *
167GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
168 GNUNET_ATS_AllocationCallback alloc_cb,
169 void *alloc_cb_cls);
170 GNUNET_ATS_SuggestionCallback suggest_cb,
171 void *suggest_cb_cls);
172
173
174/**
175 * Client is done with ATS scheduling, release resources.
176 *
177 * @param sh handle to release
178 */
179void
180GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
181
182
183/**
184 * Handle used within ATS to track an address.
185 */
186struct GNUNET_ATS_AddressRecord;
187
188
189/**
190 * We have a new address ATS should know. Addresses have to be added with this
191 * function before they can be: updated, set in use and destroyed
192 *
193 * @param sh handle
194 * @param pid peer we connected to
195 * @param address the address (human readable version), NULL if
196 * the session is inbound-only
197 * @param session transport-internal handle for the address/queue
198 * @param prop performance data for the address
199 * @return handle to the address representation inside ATS, NULL
200 * on error (i.e. ATS knows this exact address already, or
201 * address is invalid)
202 */
203struct GNUNET_ATS_AddressRecord *
204GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
205 const struct GNUNET_PeerIdentity *pid,
206 const char *address,
207 struct GNUNET_ATS_Session *session,
208 const struct GNUNET_ATS_Properties *prop);
209
210
211/**
212 * We have updated performance statistics for a given address. Based
213 * on the information provided, ATS may update bandwidth assignments.
214 *
215 * @param ar address record to update information for
216 * @param prop performance data for the address
217 */
218void
219GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
220 const struct GNUNET_ATS_Properties *prop);
221
222
223/**
224 * A session was destroyed, ATS should now schedule and
225 * allocate under the assumption that this @a ar is no
226 * longer in use.
227 *
228 * @param ar address record to drop
229 */
230void
231GNUNET_ATS_address_del (struct GNUNET_ATS_AddressRecord *ar);
232
233
234#endif
235
236/** @} */ /* end of group */
237
238/* end of file gnunet-service-transport_ats.h */
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h
index fed681f0f..e80ba85cf 100644
--- a/src/include/gnunet_transport_communication_service.h
+++ b/src/include/gnunet_transport_communication_service.h
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
@@ -80,12 +80,36 @@ struct GNUNET_TRANSPORT_CommunicatorHandle;
80 80
81 81
82/** 82/**
83 * What characteristics does this communicator have?
84 */
85enum GNUNET_TRANSPORT_CommunicatorCharacteristics {
86
87 /**
88 * Characteristics are unknown (i.e. DV).
89 */
90 GNUNET_TRANSPORT_CC_UNKNOWN = 0,
91
92 /**
93 * Transmission is reliabile (with ACKs), i.e. TCP/HTTP/HTTPS.
94 */
95 GNUNET_TRANSPORT_CC_RELIABLE = 1,
96
97 /**
98 * Transmission is unreliable (i.e. UDP)
99 */
100 GNUNET_TRANSPORT_CC_UNRELIABILE = 2
101
102};
103
104
105/**
83 * Connect to the transport service. 106 * Connect to the transport service.
84 * 107 *
85 * @param cfg configuration to use 108 * @param cfg configuration to use
86 * @param config_section section of the configuration to use for options 109 * @param config_section section of the configuration to use for options
87 * @param addr_prefix address prefix for addresses supported by this 110 * @param addr_prefix address prefix for addresses supported by this
88 * communicator, could be NULL for incoming-only communicators 111 * communicator, could be NULL for incoming-only communicators
112 * @param cc what characteristics does the communicator have?
89 * @param mq_init function to call to initialize a message queue given 113 * @param mq_init function to call to initialize a message queue given
90 * the address of another peer, can be NULL if the 114 * the address of another peer, can be NULL if the
91 * communicator only supports receiving messages 115 * communicator only supports receiving messages
@@ -96,6 +120,7 @@ struct GNUNET_TRANSPORT_CommunicatorHandle *
96GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 120GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
97 const char *config_section_name, 121 const char *config_section_name,
98 const char *addr_prefix, 122 const char *addr_prefix,
123 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
99 GNUNET_TRANSPORT_CommunicatorMqInit mq_init, 124 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
100 void *mq_init_cls); 125 void *mq_init_cls);
101 126
@@ -162,14 +187,17 @@ struct GNUNET_TRANSPORT_QueueHandle;
162 * Possible states of a connection. 187 * Possible states of a connection.
163 */ 188 */
164enum GNUNET_TRANSPORT_ConnectionStatus { 189enum GNUNET_TRANSPORT_ConnectionStatus {
190
165 /** 191 /**
166 * Connection is down. 192 * Connection is down.
167 */ 193 */
168 GNUNET_TRANSPORT_CS_DOWN = -1, 194 GNUNET_TRANSPORT_CS_DOWN = -1,
195
169 /** 196 /**
170 * this is an outbound connection (transport initiated) 197 * this is an outbound connection (transport initiated)
171 */ 198 */
172 GNUNET_TRANSPORT_CS_OUTBOUND = 0, 199 GNUNET_TRANSPORT_CS_OUTBOUND = 0,
200
173 /** 201 /**
174 * this is an inbound connection (communicator initiated) 202 * this is an inbound connection (communicator initiated)
175 */ 203 */
@@ -188,6 +216,7 @@ enum GNUNET_TRANSPORT_ConnectionStatus {
188 * @param mtu maximum message size supported by queue, 0 if 216 * @param mtu maximum message size supported by queue, 0 if
189 * sending is not supported, SIZE_MAX for no MTU 217 * sending is not supported, SIZE_MAX for no MTU
190 * @param nt which network type does the @a address belong to? 218 * @param nt which network type does the @a address belong to?
219 * @param distance how many hops does this queue use (DV-only)?
191 * @param cs what is the connection status of the queue? 220 * @param cs what is the connection status of the queue?
192 * @param mq message queue of the @a peer 221 * @param mq message queue of the @a peer
193 * @return API handle identifying the new MQ 222 * @return API handle identifying the new MQ
@@ -198,6 +227,7 @@ GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle
198 const char *address, 227 const char *address,
199 uint32_t mtu, 228 uint32_t mtu,
200 enum GNUNET_ATS_Network_Type nt, 229 enum GNUNET_ATS_Network_Type nt,
230 uint32_t distance,
201 enum GNUNET_TRANSPORT_ConnectionStatus cs, 231 enum GNUNET_TRANSPORT_ConnectionStatus cs,
202 struct GNUNET_MQ_Handle *mq); 232 struct GNUNET_MQ_Handle *mq);
203 233
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index a9a75f779..a97560ad4 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
@@ -31,8 +31,8 @@
31#include "gnunet_transport_communication_service.h" 31#include "gnunet_transport_communication_service.h"
32 32
33/** 33/**
34 * How many messages do we keep at most in the queue to the 34 * How many messages do we keep at most in the queue to the
35 * transport service before we start to drop (default, 35 * transport service before we start to drop (default,
36 * can be changed via the configuration file). 36 * can be changed via the configuration file).
37 * Should be _below_ the level of the communicator API, as 37 * Should be _below_ the level of the communicator API, as
38 * otherwise we may read messages just to have them dropped 38 * otherwise we may read messages just to have them dropped
@@ -113,17 +113,17 @@ struct Queue
113 * if this queue is in the #queue_head DLL. 113 * if this queue is in the #queue_head DLL.
114 */ 114 */
115 const struct GNUNET_MessageHeader *msg; 115 const struct GNUNET_MessageHeader *msg;
116 116
117 /** 117 /**
118 * Message queue we are providing for the #ch. 118 * Message queue we are providing for the #ch.
119 */ 119 */
120 struct GNUNET_MQ_Handle *mq; 120 struct GNUNET_MQ_Handle *mq;
121 121
122 /** 122 /**
123 * handle for this queue with the #ch. 123 * handle for this queue with the #ch.
124 */ 124 */
125 struct GNUNET_TRANSPORT_QueueHandle *qh; 125 struct GNUNET_TRANSPORT_QueueHandle *qh;
126 126
127 /** 127 /**
128 * Number of bytes we currently have in our write queue. 128 * Number of bytes we currently have in our write queue.
129 */ 129 */
@@ -211,14 +211,14 @@ queue_destroy (struct Queue *queue)
211 struct GNUNET_MQ_Handle *mq; 211 struct GNUNET_MQ_Handle *mq;
212 212
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Disconnecting queue for peer `%s'\n", 214 "Disconnecting queue for peer `%s'\n",
215 GNUNET_i2s (&queue->target)); 215 GNUNET_i2s (&queue->target));
216 if (0 != queue->bytes_in_queue) 216 if (0 != queue->bytes_in_queue)
217 { 217 {
218 GNUNET_CONTAINER_DLL_remove (queue_head, 218 GNUNET_CONTAINER_DLL_remove (queue_head,
219 queue_tail, 219 queue_tail,
220 queue); 220 queue);
221 queue->bytes_in_queue = 0; 221 queue->bytes_in_queue = 0;
222 } 222 }
223 if (NULL != (mq = queue->mq)) 223 if (NULL != (mq = queue->mq))
224 { 224 {
@@ -439,7 +439,7 @@ select_write_cb (void *cls)
439 queue->address_len); 439 queue->address_len);
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "UNIX transmitted message to %s (%d/%u: %s)\n", 441 "UNIX transmitted message to %s (%d/%u: %s)\n",
442 GNUNET_i2s (&queue->target), 442 GNUNET_i2s (&queue->target),
443 (int) sent, 443 (int) sent,
444 (unsigned int) msg_size, 444 (unsigned int) msg_size,
445 (sent < 0) ? STRERROR (errno) : "ok"); 445 (sent < 0) ? STRERROR (errno) : "ok");
@@ -463,7 +463,7 @@ select_write_cb (void *cls)
463 /* We should retry later... */ 463 /* We should retry later... */
464 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, 464 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG,
465 "send"); 465 "send");
466 return; 466 return;
467 case EMSGSIZE: 467 case EMSGSIZE:
468 { 468 {
469 socklen_t size = 0; 469 socklen_t size = 0;
@@ -533,7 +533,7 @@ mq_send (struct GNUNET_MQ_Handle *mq,
533 533
534 GNUNET_assert (mq == queue->mq); 534 GNUNET_assert (mq == queue->mq);
535 GNUNET_assert (NULL == queue->msg); 535 GNUNET_assert (NULL == queue->msg);
536 queue->msg = msg; 536 queue->msg = msg;
537 GNUNET_CONTAINER_DLL_insert (queue_head, 537 GNUNET_CONTAINER_DLL_insert (queue_head,
538 queue_tail, 538 queue_tail,
539 queue); 539 queue);
@@ -664,7 +664,7 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
664 queue); 664 queue);
665 { 665 {
666 char *foreign_addr; 666 char *foreign_addr;
667 667
668 if ('\0' == un->sun_path[0]) 668 if ('\0' == un->sun_path[0])
669 GNUNET_asprintf (&foreign_addr, 669 GNUNET_asprintf (&foreign_addr,
670 "%s-@%s", 670 "%s-@%s",
@@ -679,8 +679,9 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
679 = GNUNET_TRANSPORT_communicator_mq_add (ch, 679 = GNUNET_TRANSPORT_communicator_mq_add (ch,
680 &queue->target, 680 &queue->target,
681 foreign_addr, 681 foreign_addr,
682 UNIX_MTU, 682 UNIX_MTU,
683 GNUNET_ATS_NET_LOOPBACK, 683 GNUNET_ATS_NET_LOOPBACK,
684 0 /* distance */,
684 cs, 685 cs,
685 queue->mq); 686 queue->mq);
686 GNUNET_free (foreign_addr); 687 GNUNET_free (foreign_addr);
@@ -798,12 +799,12 @@ select_read_cb (void *cls)
798 _("Maximum number of UNIX connections exceeded, dropping incoming message\n")); 799 _("Maximum number of UNIX connections exceeded, dropping incoming message\n"));
799 return; 800 return;
800 } 801 }
801 802
802 { 803 {
803 uint16_t offset = 0; 804 uint16_t offset = 0;
804 uint16_t tsize = msize - sizeof (struct UNIXMessage); 805 uint16_t tsize = msize - sizeof (struct UNIXMessage);
805 const char *msgbuf = (const char *) &msg[1]; 806 const char *msgbuf = (const char *) &msg[1];
806 807
807 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) 808 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
808 { 809 {
809 const struct GNUNET_MessageHeader *currhdr; 810 const struct GNUNET_MessageHeader *currhdr;
@@ -870,7 +871,7 @@ mq_init (void *cls,
870 const char *path; 871 const char *path;
871 struct sockaddr_un *un; 872 struct sockaddr_un *un;
872 socklen_t un_len; 873 socklen_t un_len;
873 874
874 if (0 != strncmp (address, 875 if (0 != strncmp (address,
875 COMMUNICATOR_ADDRESS_PREFIX "-", 876 COMMUNICATOR_ADDRESS_PREFIX "-",
876 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 877 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
@@ -902,7 +903,7 @@ mq_init (void *cls,
902 { 903 {
903 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 904 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
904 "Failed to setup queue to %s at `%s'\n", 905 "Failed to setup queue to %s at `%s'\n",
905 GNUNET_i2s (peer), 906 GNUNET_i2s (peer),
906 path); 907 path);
907 return GNUNET_NO; 908 return GNUNET_NO;
908 } 909 }
@@ -981,7 +982,7 @@ do_shutdown (void *cls)
981 982
982/** 983/**
983 * Setup communicator and launch network interactions. 984 * Setup communicator and launch network interactions.
984 * 985 *
985 * @param cls NULL (always) 986 * @param cls NULL (always)
986 * @param args remaining command-line arguments 987 * @param args remaining command-line arguments
987 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 988 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
@@ -998,7 +999,7 @@ run (void *cls,
998 socklen_t un_len; 999 socklen_t un_len;
999 char *my_addr; 1000 char *my_addr;
1000 (void) cls; 1001 (void) cls;
1001 1002
1002 if (GNUNET_OK != 1003 if (GNUNET_OK !=
1003 GNUNET_CONFIGURATION_get_value_filename (cfg, 1004 GNUNET_CONFIGURATION_get_value_filename (cfg,
1004 COMMUNICATOR_CONFIG_SECTION, 1005 COMMUNICATOR_CONFIG_SECTION,
@@ -1016,7 +1017,7 @@ run (void *cls,
1016 "MAX_QUEUE_LENGTH", 1017 "MAX_QUEUE_LENGTH",
1017 &max_queue_length)) 1018 &max_queue_length))
1018 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 1019 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
1019 1020
1020 un = unix_address_to_sockaddr (unix_socket_path, 1021 un = unix_address_to_sockaddr (unix_socket_path,
1021 &un_len); 1022 &un_len);
1022 if (NULL == un) 1023 if (NULL == un)
@@ -1082,6 +1083,7 @@ run (void *cls,
1082 ch = GNUNET_TRANSPORT_communicator_connect (cfg, 1083 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
1083 COMMUNICATOR_CONFIG_SECTION, 1084 COMMUNICATOR_CONFIG_SECTION,
1084 COMMUNICATOR_ADDRESS_PREFIX, 1085 COMMUNICATOR_ADDRESS_PREFIX,
1086 GNUNET_TRANSPORT_CC_RELIABLE,
1085 &mq_init, 1087 &mq_init,
1086 NULL); 1088 NULL);
1087 if (NULL == ch) 1089 if (NULL == ch)
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index ca8838380..3e08900bb 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -155,6 +155,11 @@ struct Queue
155 uint32_t mtu; 155 uint32_t mtu;
156 156
157 /** 157 /**
158 * Distance to the target of this queue.
159 */
160 uint32_t distance;
161
162 /**
158 * Network type offered by this queue. 163 * Network type offered by this queue.
159 */ 164 */
160 enum GNUNET_ATS_Network_Type nt; 165 enum GNUNET_ATS_Network_Type nt;
@@ -423,6 +428,11 @@ struct TransportClient
423 */ 428 */
424 struct AddressListEntry *addr_tail; 429 struct AddressListEntry *addr_tail;
425 430
431 /**
432 * Characteristics of this communicator.
433 */
434 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
435
426 } communicator; 436 } communicator;
427 437
428 } details; 438 } details;
@@ -1106,7 +1116,10 @@ handle_communicator_available (void *cls,
1106 size = ntohs (cam->header.size) - sizeof (*cam); 1116 size = ntohs (cam->header.size) - sizeof (*cam);
1107 if (0 == size) 1117 if (0 == size)
1108 return; /* receive-only communicator */ 1118 return; /* receive-only communicator */
1109 tc->details.communicator.address_prefix = GNUNET_strdup ((const char *) &cam[1]); 1119 tc->details.communicator.address_prefix
1120 = GNUNET_strdup ((const char *) &cam[1]);
1121 tc->details.communicator.cc
1122 = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc);
1110 GNUNET_SERVICE_client_continue (tc->client); 1123 GNUNET_SERVICE_client_continue (tc->client);
1111} 1124}
1112 1125
@@ -1413,6 +1426,7 @@ handle_add_queue_message (void *cls,
1413 queue->rtt = GNUNET_TIME_UNIT_FOREVER_REL; 1426 queue->rtt = GNUNET_TIME_UNIT_FOREVER_REL;
1414 queue->qid = aqm->qid; 1427 queue->qid = aqm->qid;
1415 queue->mtu = ntohl (aqm->mtu); 1428 queue->mtu = ntohl (aqm->mtu);
1429 queue->distance = ntohl (aqm->distance);
1416 queue->nt = (enum GNUNET_ATS_Network_Type) ntohl (aqm->nt); 1430 queue->nt = (enum GNUNET_ATS_Network_Type) ntohl (aqm->nt);
1417 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); 1431 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs);
1418 queue->neighbour = neighbour; 1432 queue->neighbour = neighbour;
diff --git a/src/transport/transport.h b/src/transport/transport.h
index e8c276342..515c178f4 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -661,6 +661,11 @@ struct GNUNET_TRANSPORT_CommunicatorAvailableMessage
661 */ 661 */
662 struct GNUNET_MessageHeader header; 662 struct GNUNET_MessageHeader header;
663 663
664 /**
665 * NBO encoding of `enum GNUNET_TRANSPORT_CommunicatorCharacteristics`
666 */
667 uint32_t cc;
668
664 /* Followed by the address prefix of the communicator */ 669 /* Followed by the address prefix of the communicator */
665}; 670};
666 671
@@ -810,6 +815,11 @@ struct GNUNET_TRANSPORT_AddQueueMessage
810 */ 815 */
811 uint32_t cs; 816 uint32_t cs;
812 817
818 /**
819 * Hops to the target (DV-only), in NBO.
820 */
821 uint32_t distance;
822
813 /* followed by UTF-8 encoded, 0-terminated human-readable address */ 823 /* followed by UTF-8 encoded, 0-terminated human-readable address */
814}; 824};
815 825
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index 6704f0cd8..a89802ddd 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
@@ -29,8 +29,8 @@
29 29
30 30
31/** 31/**
32 * How many messages do we keep at most in the queue to the 32 * How many messages do we keep at most in the queue to the
33 * transport service before we start to drop (default, 33 * transport service before we start to drop (default,
34 * can be changed via the configuration file). 34 * can be changed via the configuration file).
35 */ 35 */
36#define DEFAULT_MAX_QUEUE_LENGTH 16 36#define DEFAULT_MAX_QUEUE_LENGTH 16
@@ -60,7 +60,7 @@ struct FlowControl
60 * Closure for @e cb 60 * Closure for @e cb
61 */ 61 */
62 void *cb_cls; 62 void *cb_cls;
63 63
64 /** 64 /**
65 * Which peer is this about? 65 * Which peer is this about?
66 */ 66 */
@@ -93,7 +93,7 @@ struct AckPending
93 * Communicator this entry belongs to. 93 * Communicator this entry belongs to.
94 */ 94 */
95 struct GNUNET_TRANSPORT_CommunicatorHandle *ch; 95 struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
96 96
97 /** 97 /**
98 * Which peer is this about? 98 * Which peer is this about?
99 */ 99 */
@@ -145,12 +145,12 @@ struct GNUNET_TRANSPORT_CommunicatorHandle
145 * DLL of queues we offer. 145 * DLL of queues we offer.
146 */ 146 */
147 struct GNUNET_TRANSPORT_QueueHandle *queue_head; 147 struct GNUNET_TRANSPORT_QueueHandle *queue_head;
148 148
149 /** 149 /**
150 * DLL of queues we offer. 150 * DLL of queues we offer.
151 */ 151 */
152 struct GNUNET_TRANSPORT_QueueHandle *queue_tail; 152 struct GNUNET_TRANSPORT_QueueHandle *queue_tail;
153 153
154 /** 154 /**
155 * Our configuration. 155 * Our configuration.
156 */ 156 */
@@ -181,12 +181,12 @@ struct GNUNET_TRANSPORT_CommunicatorHandle
181 * Queue to talk to the transport service. 181 * Queue to talk to the transport service.
182 */ 182 */
183 struct GNUNET_MQ_Handle *mq; 183 struct GNUNET_MQ_Handle *mq;
184 184
185 /** 185 /**
186 * Maximum permissable queue length. 186 * Maximum permissable queue length.
187 */ 187 */
188 unsigned long long max_queue_length; 188 unsigned long long max_queue_length;
189 189
190 /** 190 /**
191 * Flow-control identifier generator. 191 * Flow-control identifier generator.
192 */ 192 */
@@ -202,7 +202,12 @@ struct GNUNET_TRANSPORT_CommunicatorHandle
202 * Queue identifier generator. 202 * Queue identifier generator.
203 */ 203 */
204 uint32_t queue_gen; 204 uint32_t queue_gen;
205 205
206 /**
207 * Characteristics of the communicator.
208 */
209 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
210
206}; 211};
207 212
208 213
@@ -222,21 +227,26 @@ struct GNUNET_TRANSPORT_QueueHandle
222 * Kept in a DLL. 227 * Kept in a DLL.
223 */ 228 */
224 struct GNUNET_TRANSPORT_QueueHandle *prev; 229 struct GNUNET_TRANSPORT_QueueHandle *prev;
225 230
226 /** 231 /**
227 * Handle this queue belongs to. 232 * Handle this queue belongs to.
228 */ 233 */
229 struct GNUNET_TRANSPORT_CommunicatorHandle *ch; 234 struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
230 235
231 /** 236 /**
232 * Which peer we can communciate with. 237 * Address used by the communication queue.
233 */ 238 */
234 struct GNUNET_PeerIdentity peer; 239 char *address;
235 240
236 /** 241 /**
237 * Address used by the communication queue. 242 * The queue itself.
238 */ 243 */
239 char *address; 244 struct GNUNET_MQ_Handle *mq;
245
246 /**
247 * Which peer we can communciate with.
248 */
249 struct GNUNET_PeerIdentity peer;
240 250
241 /** 251 /**
242 * Network type of the communciation queue. 252 * Network type of the communciation queue.
@@ -247,11 +257,11 @@ struct GNUNET_TRANSPORT_QueueHandle
247 * Communication status of the queue. 257 * Communication status of the queue.
248 */ 258 */
249 enum GNUNET_TRANSPORT_ConnectionStatus cs; 259 enum GNUNET_TRANSPORT_ConnectionStatus cs;
250 260
251 /** 261 /**
252 * The queue itself. 262 * How many hops is the target away (DV-only)
253 */ 263 */
254 struct GNUNET_MQ_Handle *mq; 264 uint32_t distance;
255 265
256 /** 266 /**
257 * ID for this queue when talking to the transport service. 267 * ID for this queue when talking to the transport service.
@@ -262,7 +272,7 @@ struct GNUNET_TRANSPORT_QueueHandle
262 * Maximum transmission unit for the queue. 272 * Maximum transmission unit for the queue.
263 */ 273 */
264 uint32_t mtu; 274 uint32_t mtu;
265 275
266}; 276};
267 277
268 278
@@ -282,7 +292,7 @@ struct GNUNET_TRANSPORT_AddressIdentifier
282 * Kept in a DLL. 292 * Kept in a DLL.
283 */ 293 */
284 struct GNUNET_TRANSPORT_AddressIdentifier *prev; 294 struct GNUNET_TRANSPORT_AddressIdentifier *prev;
285 295
286 /** 296 /**
287 * Transport handle where the address was added. 297 * Transport handle where the address was added.
288 */ 298 */
@@ -298,7 +308,7 @@ struct GNUNET_TRANSPORT_AddressIdentifier
298 * address.) 308 * address.)
299 */ 309 */
300 struct GNUNET_TIME_Relative expiration; 310 struct GNUNET_TIME_Relative expiration;
301 311
302 /** 312 /**
303 * Internal UUID for the address used in communication with the 313 * Internal UUID for the address used in communication with the
304 * transport service. 314 * transport service.
@@ -309,7 +319,7 @@ struct GNUNET_TRANSPORT_AddressIdentifier
309 * Network type for the address. 319 * Network type for the address.
310 */ 320 */
311 enum GNUNET_ATS_Network_Type nt; 321 enum GNUNET_ATS_Network_Type nt;
312 322
313}; 323};
314 324
315 325
@@ -333,7 +343,7 @@ send_add_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
333{ 343{
334 struct GNUNET_MQ_Envelope *env; 344 struct GNUNET_MQ_Envelope *env;
335 struct GNUNET_TRANSPORT_AddAddressMessage *aam; 345 struct GNUNET_TRANSPORT_AddAddressMessage *aam;
336 346
337 if (NULL == ai->ch->mq) 347 if (NULL == ai->ch->mq)
338 return; 348 return;
339 env = GNUNET_MQ_msg_extra (aam, 349 env = GNUNET_MQ_msg_extra (aam,
@@ -360,10 +370,10 @@ send_del_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
360{ 370{
361 struct GNUNET_MQ_Envelope *env; 371 struct GNUNET_MQ_Envelope *env;
362 struct GNUNET_TRANSPORT_DelAddressMessage *dam; 372 struct GNUNET_TRANSPORT_DelAddressMessage *dam;
363 373
364 if (NULL == ai->ch->mq) 374 if (NULL == ai->ch->mq)
365 return; 375 return;
366 env = GNUNET_MQ_msg (dam, 376 env = GNUNET_MQ_msg (dam,
367 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS); 377 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS);
368 dam->aid = htonl (ai->aid); 378 dam->aid = htonl (ai->aid);
369 GNUNET_MQ_send (ai->ch->mq, 379 GNUNET_MQ_send (ai->ch->mq,
@@ -382,7 +392,7 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
382{ 392{
383 struct GNUNET_MQ_Envelope *env; 393 struct GNUNET_MQ_Envelope *env;
384 struct GNUNET_TRANSPORT_AddQueueMessage *aqm; 394 struct GNUNET_TRANSPORT_AddQueueMessage *aqm;
385 395
386 if (NULL == qh->ch->mq) 396 if (NULL == qh->ch->mq)
387 return; 397 return;
388 env = GNUNET_MQ_msg_extra (aqm, 398 env = GNUNET_MQ_msg_extra (aqm,
@@ -393,6 +403,7 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
393 aqm->nt = htonl ((uint32_t) qh->nt); 403 aqm->nt = htonl ((uint32_t) qh->nt);
394 aqm->mtu = htonl (qh->mtu); 404 aqm->mtu = htonl (qh->mtu);
395 aqm->cs = htonl ((uint32_t) qh->cs); 405 aqm->cs = htonl ((uint32_t) qh->cs);
406 aqm->distance = htonl (qh->distance);
396 memcpy (&aqm[1], 407 memcpy (&aqm[1],
397 qh->address, 408 qh->address,
398 strlen (qh->address) + 1); 409 strlen (qh->address) + 1);
@@ -412,10 +423,10 @@ send_del_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
412{ 423{
413 struct GNUNET_MQ_Envelope *env; 424 struct GNUNET_MQ_Envelope *env;
414 struct GNUNET_TRANSPORT_DelQueueMessage *dqm; 425 struct GNUNET_TRANSPORT_DelQueueMessage *dqm;
415 426
416 if (NULL == qh->ch->mq) 427 if (NULL == qh->ch->mq)
417 return; 428 return;
418 env = GNUNET_MQ_msg (dqm, 429 env = GNUNET_MQ_msg (dqm,
419 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN); 430 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN);
420 dqm->qid = htonl (qh->queue_id); 431 dqm->qid = htonl (qh->queue_id);
421 dqm->receiver = qh->peer; 432 dqm->receiver = qh->peer;
@@ -437,7 +448,7 @@ disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
437{ 448{
438 struct FlowControl *fcn; 449 struct FlowControl *fcn;
439 struct AckPending *apn; 450 struct AckPending *apn;
440 451
441 for (struct FlowControl *fc = ch->fc_head; 452 for (struct FlowControl *fc = ch->fc_head;
442 NULL != fc; 453 NULL != fc;
443 fc = fcn) 454 fc = fcn)
@@ -497,7 +508,7 @@ handle_incoming_ack (void *cls,
497 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack) 508 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
498{ 509{
499 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 510 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
500 511
501 for (struct FlowControl *fc = ch->fc_head; 512 for (struct FlowControl *fc = ch->fc_head;
502 NULL != fc; 513 NULL != fc;
503 fc = fc->next) 514 fc = fc->next)
@@ -563,7 +574,7 @@ handle_create_queue (void *cls,
563 const char *addr = (const char *) &cq[1]; 574 const char *addr = (const char *) &cq[1];
564 struct GNUNET_TRANSPORT_CreateQueueResponse *cqr; 575 struct GNUNET_TRANSPORT_CreateQueueResponse *cqr;
565 struct GNUNET_MQ_Envelope *env; 576 struct GNUNET_MQ_Envelope *env;
566 577
567 if (GNUNET_OK != 578 if (GNUNET_OK !=
568 ch->mq_init (ch->mq_init_cls, 579 ch->mq_init (ch->mq_init_cls,
569 &cq->receiver, 580 &cq->receiver,
@@ -573,12 +584,12 @@ handle_create_queue (void *cls,
573 "Address `%s' invalid for this communicator\n", 584 "Address `%s' invalid for this communicator\n",
574 addr); 585 addr);
575 env = GNUNET_MQ_msg (cqr, 586 env = GNUNET_MQ_msg (cqr,
576 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL); 587 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL);
577 } 588 }
578 else 589 else
579 { 590 {
580 env = GNUNET_MQ_msg (cqr, 591 env = GNUNET_MQ_msg (cqr,
581 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK); 592 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK);
582 } 593 }
583 cqr->request_id = cq->request_id; 594 cqr->request_id = cq->request_id;
584 GNUNET_MQ_send (ch->mq, 595 GNUNET_MQ_send (ch->mq,
@@ -678,12 +689,12 @@ handle_send_msg (void *cls,
678 struct AckPending *ap; 689 struct AckPending *ap;
679 struct GNUNET_TRANSPORT_QueueHandle *qh; 690 struct GNUNET_TRANSPORT_QueueHandle *qh;
680 691
681 for (qh = ch->queue_head;NULL != qh; qh = qh->next) 692 for (qh = ch->queue_head;NULL != qh; qh = qh->next)
682 if ( (qh->queue_id == smt->qid) && 693 if ( (qh->queue_id == smt->qid) &&
683 (0 == memcmp (&qh->peer, 694 (0 == memcmp (&qh->peer,
684 &smt->receiver, 695 &smt->receiver,
685 sizeof (struct GNUNET_PeerIdentity))) ) 696 sizeof (struct GNUNET_PeerIdentity))) )
686 break; 697 break;
687 if (NULL == qh) 698 if (NULL == qh)
688 { 699 {
689 /* queue is already gone, tell transport this one failed */ 700 /* queue is already gone, tell transport this one failed */
@@ -737,7 +748,7 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
737 }; 748 };
738 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; 749 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam;
739 struct GNUNET_MQ_Envelope *env; 750 struct GNUNET_MQ_Envelope *env;
740 751
741 ch->mq = GNUNET_CLIENT_connect (ch->cfg, 752 ch->mq = GNUNET_CLIENT_connect (ch->cfg,
742 "transport", 753 "transport",
743 handlers, 754 handlers,
@@ -745,9 +756,10 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
745 ch); 756 ch);
746 if (NULL == ch->mq) 757 if (NULL == ch->mq)
747 return; 758 return;
748 env = GNUNET_MQ_msg_extra (cam, 759 env = GNUNET_MQ_msg_extra (cam,
749 strlen (ch->addr_prefix) + 1, 760 strlen (ch->addr_prefix) + 1,
750 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); 761 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR);
762 cam->cc = htonl ((uint32_t) ch->cc);
751 memcpy (&cam[1], 763 memcpy (&cam[1],
752 ch->addr_prefix, 764 ch->addr_prefix,
753 strlen (ch->addr_prefix) + 1); 765 strlen (ch->addr_prefix) + 1);
@@ -771,6 +783,7 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
771 * @param config_section section of the configuration to use for options 783 * @param config_section section of the configuration to use for options
772 * @param addr_prefix address prefix for addresses supported by this 784 * @param addr_prefix address prefix for addresses supported by this
773 * communicator, could be NULL for incoming-only communicators 785 * communicator, could be NULL for incoming-only communicators
786 * @param cc what characteristics does the communicator have?
774 * @param mtu maximum message size supported by communicator, 0 if 787 * @param mtu maximum message size supported by communicator, 0 if
775 * sending is not supported, SIZE_MAX for no MTU 788 * sending is not supported, SIZE_MAX for no MTU
776 * @param mq_init function to call to initialize a message queue given 789 * @param mq_init function to call to initialize a message queue given
@@ -783,17 +796,19 @@ struct GNUNET_TRANSPORT_CommunicatorHandle *
783GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 796GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
784 const char *config_section, 797 const char *config_section,
785 const char *addr_prefix, 798 const char *addr_prefix,
799 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
786 GNUNET_TRANSPORT_CommunicatorMqInit mq_init, 800 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
787 void *mq_init_cls) 801 void *mq_init_cls)
788{ 802{
789 struct GNUNET_TRANSPORT_CommunicatorHandle *ch; 803 struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
790 804
791 ch = GNUNET_new (struct GNUNET_TRANSPORT_CommunicatorHandle); 805 ch = GNUNET_new (struct GNUNET_TRANSPORT_CommunicatorHandle);
792 ch->cfg = cfg; 806 ch->cfg = cfg;
793 ch->config_section = config_section; 807 ch->config_section = config_section;
794 ch->addr_prefix = addr_prefix; 808 ch->addr_prefix = addr_prefix;
795 ch->mq_init = mq_init; 809 ch->mq_init = mq_init;
796 ch->mq_init_cls = mq_init_cls; 810 ch->mq_init_cls = mq_init_cls;
811 ch->cc = cc;
797 reconnect (ch); 812 reconnect (ch);
798 if (GNUNET_OK != 813 if (GNUNET_OK !=
799 GNUNET_CONFIGURATION_get_value_number (cfg, 814 GNUNET_CONFIGURATION_get_value_number (cfg,
@@ -858,7 +873,7 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl
858 struct GNUNET_MQ_Envelope *env; 873 struct GNUNET_MQ_Envelope *env;
859 struct GNUNET_TRANSPORT_IncomingMessage *im; 874 struct GNUNET_TRANSPORT_IncomingMessage *im;
860 uint16_t msize; 875 uint16_t msize;
861 876
862 if (NULL == ch->mq) 877 if (NULL == ch->mq)
863 return GNUNET_SYSERR; 878 return GNUNET_SYSERR;
864 if ( (NULL == cb) && 879 if ( (NULL == cb) &&
@@ -869,7 +884,7 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl
869 ch->max_queue_length); 884 ch->max_queue_length);
870 return GNUNET_NO; 885 return GNUNET_NO;
871 } 886 }
872 887
873 msize = ntohs (msg->size); 888 msize = ntohs (msg->size);
874 env = GNUNET_MQ_msg_extra (im, 889 env = GNUNET_MQ_msg_extra (im,
875 msize, 890 msize,
@@ -918,6 +933,8 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl
918 * @param mtu maximum message size supported by queue, 0 if 933 * @param mtu maximum message size supported by queue, 0 if
919 * sending is not supported, SIZE_MAX for no MTU 934 * sending is not supported, SIZE_MAX for no MTU
920 * @param nt which network type does the @a address belong to? 935 * @param nt which network type does the @a address belong to?
936 * @param cc what characteristics does the communicator have?
937 * @param distance how many hops does this queue use (DV-only)?
921 * @param cs what is the connection status of the queue? 938 * @param cs what is the connection status of the queue?
922 * @param mq message queue of the @a peer 939 * @param mq message queue of the @a peer
923 * @return API handle identifying the new MQ 940 * @return API handle identifying the new MQ
@@ -928,6 +945,7 @@ GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle
928 const char *address, 945 const char *address,
929 uint32_t mtu, 946 uint32_t mtu,
930 enum GNUNET_ATS_Network_Type nt, 947 enum GNUNET_ATS_Network_Type nt,
948 uint32_t distance,
931 enum GNUNET_TRANSPORT_ConnectionStatus cs, 949 enum GNUNET_TRANSPORT_ConnectionStatus cs,
932 struct GNUNET_MQ_Handle *mq) 950 struct GNUNET_MQ_Handle *mq)
933{ 951{
@@ -939,6 +957,7 @@ GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle
939 qh->address = GNUNET_strdup (address); 957 qh->address = GNUNET_strdup (address);
940 qh->nt = nt; 958 qh->nt = nt;
941 qh->mtu = mtu; 959 qh->mtu = mtu;
960 qh->distance = distance;
942 qh->cs = cs; 961 qh->cs = cs;
943 qh->mq = mq; 962 qh->mq = mq;
944 qh->queue_id = ch->queue_gen++; 963 qh->queue_id = ch->queue_gen++;
@@ -960,7 +979,7 @@ void
960GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh) 979GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh)
961{ 980{
962 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch; 981 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch;
963 982
964 send_del_queue (qh); 983 send_del_queue (qh);
965 GNUNET_CONTAINER_DLL_remove (ch->queue_head, 984 GNUNET_CONTAINER_DLL_remove (ch->queue_head,
966 ch->queue_tail, 985 ch->queue_tail,