aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-12-16 17:13:42 +0100
committerChristian Grothoff <christian@grothoff.org>2018-12-16 17:13:42 +0100
commitd37218d0b13292b78fcfc08d2903d6e415da0236 (patch)
treef9f354e6859b9868859cf421acbf747d8351ee7b
parent18784b77764c56842ae59428f3ebea95c157ffab (diff)
downloadgnunet-d37218d0b13292b78fcfc08d2903d6e415da0236.tar.gz
gnunet-d37218d0b13292b78fcfc08d2903d6e415da0236.zip
more work on tng
-rw-r--r--src/include/gnunet_bandwidth_lib.h6
-rw-r--r--src/include/gnunet_container_lib.h2
-rw-r--r--src/include/gnunet_protocols.h26
-rw-r--r--src/include/gnunet_signatures.h8
-rw-r--r--src/include/gnunet_transport_communication_service.h39
-rw-r--r--src/include/gnunet_transport_monitor_service.h2
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/gnunet-communicator-unix.c27
-rw-r--r--src/transport/gnunet-service-tng.c512
-rw-r--r--src/transport/transport.h101
-rw-r--r--src/transport/transport_api2_communication.c66
-rw-r--r--src/transport/transport_api2_core.c2
-rw-r--r--src/transport/transport_api_core.c1
13 files changed, 673 insertions, 121 deletions
diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h
index 4395b878b..cb30b73e1 100644
--- a/src/include/gnunet_bandwidth_lib.h
+++ b/src/include/gnunet_bandwidth_lib.h
@@ -236,10 +236,10 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
236/** 236/**
237 * Initialize bandwidth tracker. Note that in addition to the 237 * Initialize bandwidth tracker. Note that in addition to the
238 * 'max_carry_s' limit, we also always allow at least 238 * 'max_carry_s' limit, we also always allow at least
239 * GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the 239 * #GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the
240 * bytes-per-second limit is so small that within 'max_carry_s' not 240 * bytes-per-second limit is so small that within 'max_carry_s' not
241 * even GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is 241 * even #GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is
242 * ignored and replaced by GNUNET_MAX_MESSAGE_SIZE (which is in 242 * ignored and replaced by #GNUNET_MAX_MESSAGE_SIZE (which is in
243 * bytes). 243 * bytes).
244 * 244 *
245 * @param av tracker to initialize 245 * @param av tracker to initialize
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index a06d697f7..1fb460ece 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.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*/
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index c82b11762..fd5adeef2 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -3076,6 +3076,20 @@ extern "C"
3076 */ 3076 */
3077#define GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR 1211 3077#define GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR 1211
3078 3078
3079/**
3080 * Tell transport that it should assist with exchanging a
3081 * message between communicators. Usually used when
3082 * communciators are uni-directional and need an alternative
3083 * back-channel.
3084 */
3085#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL 1212
3086
3087/**
3088 * Message type used between transport services when they
3089 * internally forward communicator backchannel messages.
3090 */
3091#define GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION 1213
3092
3079 3093
3080/** 3094/**
3081 * Message sent to indicate to the transport that a monitor 3095 * Message sent to indicate to the transport that a monitor
@@ -3094,6 +3108,18 @@ extern "C"
3094 */ 3108 */
3095#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END 1252 3109#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END 1252
3096 3110
3111/**
3112 * Message exchanged between communicators to confirm
3113 * successful KX (and address validation).
3114 */
3115#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION 1275
3116
3117/**
3118 * Message exchanged between communicators to exchange
3119 * flow control (FC) limits and acknowledgemets.
3120 */
3121#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS 1276
3122
3097 3123
3098/* ************** NEW (NG) ATS Messages ************* */ 3124/* ************** NEW (NG) ATS Messages ************* */
3099 3125
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 03c97f199..109fe7045 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.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*/
@@ -194,6 +194,12 @@ extern "C"
194 */ 194 */
195#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 29 195#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 29
196 196
197/**
198 * Signature by a peer affirming that the given ephemeral
199 * key is currently in use by that peer's transport service.
200 */
201#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 30
202
197#if 0 /* keep Emacsens' auto-indent happy */ 203#if 0 /* keep Emacsens' auto-indent happy */
198{ 204{
199#endif 205#endif
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h
index 2ba1f831a..a5547778e 100644
--- a/src/include/gnunet_transport_communication_service.h
+++ b/src/include/gnunet_transport_communication_service.h
@@ -105,15 +105,23 @@ enum GNUNET_TRANSPORT_CommunicatorCharacteristics {
105/** 105/**
106 * Function called when the transport service has received an 106 * Function called when the transport service has received an
107 * acknowledgement for this communicator (!) via a different return 107 * acknowledgement for this communicator (!) via a different return
108 * path. 108 * path.
109 *
110 * Typically used to receive messages of type
111 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS or
112 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION
113 * as well as communicator-specific messages to assist with
114 * NAT traversal.
115 *
116 * @param cls closure
117 * @param sender which peer sent the notification
118 * @param msg payload
109 */ 119 */
110typedef void 120typedef void
111(*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls, 121(*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls,
112 const struct GNUNET_PeerIdentity *sender, 122 const struct GNUNET_PeerIdentity *sender,
113 struct GNUNET_TIME_Absolute monotonic_time, 123 const struct GNUNET_MessageHeader *msg);
114 struct GNUNET_TIME_Relative validity, 124
115 const struct GNUNET_HashCode *token
116 );
117 125
118/** 126/**
119 * Connect to the transport service. 127 * Connect to the transport service.
@@ -127,6 +135,8 @@ typedef void
127 * the address of another peer, can be NULL if the 135 * the address of another peer, can be NULL if the
128 * communicator only supports receiving messages 136 * communicator only supports receiving messages
129 * @param mq_init_cls closure for @a mq_init 137 * @param mq_init_cls closure for @a mq_init
138 * @param notify_cb function to pass backchannel messages to communicator
139 * @param notify_cb_cls closure for @a notify_cb
130 * @return NULL on error 140 * @return NULL on error
131 */ 141 */
132struct GNUNET_TRANSPORT_CommunicatorHandle * 142struct GNUNET_TRANSPORT_CommunicatorHandle *
@@ -135,9 +145,9 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle
135 const char *addr_prefix, 145 const char *addr_prefix,
136 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 146 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
137 GNUNET_TRANSPORT_CommunicatorMqInit mq_init, 147 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
138 void *mq_init_cls); 148 void *mq_init_cls,
139// GNUNET_TRANSPORT_CommunicatorNotify notify_cb, 149 GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
140// void *notify_cb_cls); 150 void *notify_cb_cls);
141 151
142 152
143/** 153/**
@@ -221,7 +231,7 @@ enum GNUNET_TRANSPORT_ConnectionStatus {
221 231
222 232
223/** 233/**
224 * Notify transport service that an MQ became available due to an 234 * Notify transport service that a MQ became available due to an
225 * "inbound" connection or because the communicator discovered the 235 * "inbound" connection or because the communicator discovered the
226 * presence of another peer. 236 * presence of another peer.
227 * 237 *
@@ -299,17 +309,16 @@ GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIde
299 * send the message back itself). 309 * send the message back itself).
300 * 310 *
301 * @param ch handle of this communicator 311 * @param ch handle of this communicator
302 * @param target_pid peer to send the message to 312 * @param pid peer to send the message to
303 * @param target_comm name of the communicator to send the message to 313 * @param comm name of the communicator to send the message to
314 * @param header header of the message to transmit and pass via the
315 * notify-API to @a pid's communicator @a comm
304 */ 316 */
305void 317void
306GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 318GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
307 const struct GNUNET_PeerIdentity *pid, 319 const struct GNUNET_PeerIdentity *pid,
308 const char *comm, 320 const char *comm,
309 struct GNUNET_TIME_Absolute monotonic_time, 321 const struct GNUNET_MessageHeader *header);
310 struct GNUNET_TIME_Relative validity,
311 const struct GNUNET_HashCode *token
312 );
313 322
314 323
315#if 0 /* keep Emacsens' auto-indent happy */ 324#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_transport_monitor_service.h b/src/include/gnunet_transport_monitor_service.h
index ef599f902..8357b101f 100644
--- a/src/include/gnunet_transport_monitor_service.h
+++ b/src/include/gnunet_transport_monitor_service.h
@@ -41,7 +41,7 @@ extern "C"
41#endif 41#endif
42 42
43#include "gnunet_util_lib.h" 43#include "gnunet_util_lib.h"
44#include "gnunet_ats_service.h" 44#include "gnunet_ats_transport_service.h"
45#include "gnunet_transport_communication_service.h" 45#include "gnunet_transport_communication_service.h"
46 46
47 47
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index da79773be..ab4ef4bfa 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -328,7 +328,7 @@ gnunet_service_transport_CFLAGS = \
328gnunet_service_tng_SOURCES = \ 328gnunet_service_tng_SOURCES = \
329 gnunet-service-tng.c 329 gnunet-service-tng.c
330gnunet_service_tng_LDADD = \ 330gnunet_service_tng_LDADD = \
331 $(top_builddir)/src/ats/libgnunetats.la \ 331 $(top_builddir)/src/ats/libgnunetatstransport.la \
332 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ 332 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
333 $(top_builddir)/src/hello/libgnunethello.la \ 333 $(top_builddir)/src/hello/libgnunethello.la \
334 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 334 $(top_builddir)/src/statistics/libgnunetstatistics.la \
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index e8a1cf0b2..57fa22ecf 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -983,6 +983,29 @@ do_shutdown (void *cls)
983 983
984 984
985/** 985/**
986 * Function called when the transport service has received an
987 * acknowledgement for this communicator (!) via a different return
988 * path.
989 *
990 * Not applicable for UNIX.
991 *
992 * @param cls closure
993 * @param sender which peer sent the notification
994 * @param msg payload
995 */
996static void
997enc_notify_cb (void *cls,
998 const struct GNUNET_PeerIdentity *sender,
999 const struct GNUNET_MessageHeader *msg)
1000{
1001 (void) cls;
1002 (void) sender;
1003 (void) msg;
1004 GNUNET_break_op (0);
1005}
1006
1007
1008/**
986 * Setup communicator and launch network interactions. 1009 * Setup communicator and launch network interactions.
987 * 1010 *
988 * @param cls NULL (always) 1011 * @param cls NULL (always)
@@ -1087,7 +1110,9 @@ run (void *cls,
1087 COMMUNICATOR_ADDRESS_PREFIX, 1110 COMMUNICATOR_ADDRESS_PREFIX,
1088 GNUNET_TRANSPORT_CC_RELIABLE, 1111 GNUNET_TRANSPORT_CC_RELIABLE,
1089 &mq_init, 1112 &mq_init,
1090 NULL); 1113 NULL,
1114 &enc_notify_cb,
1115 NULL);
1091 if (NULL == ch) 1116 if (NULL == ch)
1092 { 1117 {
1093 GNUNET_break (0); 1118 GNUNET_break (0);
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 3630e6af0..85ac3da83 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -16,32 +16,70 @@
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 */
18/** 18/**
19 * @file transport/gnunet-service-transport.c 19 * @file transport/gnunet-service-tng.c
20 * @brief main for gnunet-service-transport 20 * @brief main for gnunet-service-tng
21 * @author Christian Grothoff 21 * @author Christian Grothoff
22 * 22 *
23 * TODO: 23 * TODO:
24 * - design ATS-NG API
25 * - figure out how to transmit (selective) ACKs in case of uni-directional 24 * - figure out how to transmit (selective) ACKs in case of uni-directional
26 * communicators (with/without core? DV-only?) When do we use ACKs? 25 * communicators (with/without core? DV-only?) When do we use ACKs?
27 * How/where do we distinguish between TCP/HTTP and unreliable communicators? 26 * => communicators use selective ACKs for flow control
28 * => Should communicator provide reliable/unreliable ("flags") information? 27 * => transport uses message-level ACKs for RTT, fragment confirmation
28 * => integrate DV into transport, use neither core nor communicators
29 * but rather give communicators transport-encapsulated messages
30 * (which could be core-data, background-channel traffic, or
31 * transport-to-transport traffic)
32 *
33 * Implement:
29 * - manage fragmentation/defragmentation, retransmission, track RTT, loss, etc. 34 * - manage fragmentation/defragmentation, retransmission, track RTT, loss, etc.
35 *
36 * Easy:
37 * - use ATS bandwidth allocation callback and schedule transmissions!
38 *
39 * Plan:
30 * - inform ATS about RTT, goodput/loss, overheads, etc. 40 * - inform ATS about RTT, goodput/loss, overheads, etc.
31 * - ask ATS about bandwidth allocation! 41 *
42 * Later:
32 * - change transport-core API to provide proper flow control in both 43 * - change transport-core API to provide proper flow control in both
33 * directions, allow multiple messages per peer simultaneously (tag 44 * directions, allow multiple messages per peer simultaneously (tag
34 * confirmations with unique message ID), and replace quota-out with 45 * confirmations with unique message ID), and replace quota-out with
35 * proper flow control; 46 * proper flow control;
47 *
48 * Design realizations / discussion:
49 * - communicators do flow control by calling MQ "notify sent"
50 * when 'ready'. They determine flow implicitly (i.e. TCP blocking)
51 * or explicitly via background channel FC ACKs. As long as the
52 * channel is not full, they may 'notify sent' even if the other
53 * peer has not yet confirmed receipt. The other peer confirming
54 * is _only_ for FC, not for more reliable transmission; reliable
55 * transmission (i.e. of fragments) is left to _transport_.
56 * - ACKs sent back in uni-directional communicators are done via
57 * the background channel API; here transport _may_ initially
58 * broadcast (with bounded # hops) if no path is known;
59 * - transport should _integrate_ DV-routing and build a view of
60 * the network; then background channel traffic can be
61 * routed via DV as well as explicit "DV" traffic.
62 * - background channel is also used for ACKs and NAT traversal support
63 * - transport service is responsible for AEAD'ing the background
64 * channel, timestamps and monotonic time are used against replay
65 * of old messages -> peerstore needs to be supplied with
66 * "latest timestamps seen" data
67 * - if transport implements DV, we likely need a 3rd peermap
68 * in addition to ephemerals and (direct) neighbours
69 * => in this data structure, we should track ATS metrics (distance, RTT, etc.)
70 * as well as latest timestamps seen, goodput, fragments for transmission, etc.
71 * ==> check if stuff needs to be moved out of "Neighbour"
72 * - transport should encapsualte core-level messages and do its
73 * own ACKing for RTT/goodput/loss measurements _and_ fragment
74 * for retransmission
36 */ 75 */
37#include "platform.h" 76#include "platform.h"
38#include "gnunet_util_lib.h" 77#include "gnunet_util_lib.h"
39#include "gnunet_statistics_service.h" 78#include "gnunet_statistics_service.h"
40#include "gnunet_transport_service.h"
41#include "gnunet_transport_monitor_service.h" 79#include "gnunet_transport_monitor_service.h"
42#include "gnunet_peerstore_service.h" 80#include "gnunet_peerstore_service.h"
43#include "gnunet_ats_service.h" 81#include "gnunet_hello_lib.h"
44#include "gnunet-service-transport.h" 82#include "gnunet_ats_transport_service.h"
45#include "transport.h" 83#include "transport.h"
46 84
47 85
@@ -60,6 +98,122 @@
60#define MAX_PENDING (128 * 1024) 98#define MAX_PENDING (128 * 1024)
61 99
62 100
101GNUNET_NETWORK_STRUCT_BEGIN
102
103/**
104 * Outer layer of an encapsulated backchannel message.
105 */
106struct TransportBackchannelEncapsulationMessage
107{
108 /**
109 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION.
110 */
111 struct GNUNET_MessageHeader header;
112
113 /**
114 * Distance the backchannel message has traveled, to be updated at
115 * each hop. Used to bound the number of hops in case a backchannel
116 * message is broadcast and thus travels without routing
117 * information (during initial backchannel discovery).
118 */
119 uint32_t distance;
120
121 /**
122 * Target's peer identity (as backchannels may be transmitted
123 * indirectly, or even be broadcast).
124 */
125 struct GNUNET_PeerIdentity target;
126
127 /**
128 * Ephemeral key setup by the sender for @e target, used
129 * to encrypt the payload.
130 */
131 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
132
133 /**
134 * HMAC over the ciphertext of the encrypted, variable-size
135 * body that follows. Verified via DH of @e target and
136 * @e ephemeral_key
137 */
138 struct GNUNET_HashCode hmac;
139
140 /* Followed by encrypted, variable-size payload */
141};
142
143
144/**
145 * Message by which a peer confirms that it is using an
146 * ephemeral key.
147 */
148struct EphemeralConfirmation
149{
150
151 /**
152 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL
153 */
154 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
155
156 /**
157 * How long is this signature over the ephemeral key
158 * valid?
159 */
160 struct GNUNET_TIME_AbsoluteNBO ephemeral_validity;
161
162 /**
163 * Ephemeral key setup by the sender for @e target, used
164 * to encrypt the payload.
165 */
166 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
167
168};
169
170/**
171 * Plaintext of the variable-size payload that is encrypted
172 * within a `struct TransportBackchannelEncapsulationMessage`
173 */
174struct TransportBackchannelRequestPayload
175{
176
177 /**
178 * Sender's peer identity.
179 */
180 struct GNUNET_PeerIdentity sender;
181
182 /**
183 * Signature of the sender over an
184 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL.
185 */
186 struct GNUNET_CRYPTO_EddsaSignature sender_sig;
187
188 /**
189 * How long is this signature over the ephemeral key
190 * valid?
191 */
192 struct GNUNET_TIME_AbsoluteNBO ephemeral_validity;
193
194 /**
195 * Current monotonic time of the sending transport service. Used to
196 * detect replayed messages. Note that the receiver should remember
197 * a list of the recently seen timestamps and only reject messages
198 * if the timestamp is in the list, or the list is "full" and the
199 * timestamp is smaller than the lowest in the list. This list of
200 * timestamps per peer should be persisted to guard against replays
201 * after restarts.
202 */
203 struct GNUNET_TIME_AbsoluteNBO monotonic_time;
204
205 /* Followed by a `struct GNUNET_MessageHeader` with a message
206 for a communicator */
207
208 /* Followed by a 0-termianted string specifying the name of
209 the communicator which is to receive the message */
210
211};
212
213GNUNET_NETWORK_STRUCT_END
214
215
216
63/** 217/**
64 * What type of client is the `struct TransportClient` about? 218 * What type of client is the `struct TransportClient` about?
65 */ 219 */
@@ -88,6 +242,42 @@ enum ClientType
88 242
89 243
90/** 244/**
245 * Entry in our cache of ephemeral keys we currently use.
246 */
247struct EphemeralCacheEntry
248{
249
250 /**
251 * Target's peer identity (we don't re-use ephemerals
252 * to limit linkability of messages).
253 */
254 struct GNUNET_PeerIdentity target;
255
256 /**
257 * Signature affirming @e ephemeral_key of type
258 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL
259 */
260 struct GNUNET_CRYPTO_EddsaSignature sender_sig;
261
262 /**
263 * How long is @e sender_sig valid
264 */
265 struct GNUNET_TIME_Absolute ephemeral_validity;
266
267 /**
268 * Our ephemeral key.
269 */
270 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
271
272 /**
273 * Node in the ephemeral cache for this entry.
274 * Used for expiration.
275 */
276 struct GNUNET_CONTAINER_HeapNode *hn;
277};
278
279
280/**
91 * Client connected to the transport service. 281 * Client connected to the transport service.
92 */ 282 */
93struct TransportClient; 283struct TransportClient;
@@ -100,72 +290,73 @@ struct Neighbour;
100 290
101 291
102/** 292/**
103 * List of available queues for a particular neighbour. 293 * An ATS session is a message queue provided by a communicator
294 * via which we can reach a particular neighbour.
104 */ 295 */
105struct Queue 296struct GNUNET_ATS_Session
106{ 297{
107 /** 298 /**
108 * Kept in a MDLL. 299 * Kept in a MDLL.
109 */ 300 */
110 struct Queue *next_neighbour; 301 struct GNUNET_ATS_Session *next_neighbour;
111 302
112 /** 303 /**
113 * Kept in a MDLL. 304 * Kept in a MDLL.
114 */ 305 */
115 struct Queue *prev_neighbour; 306 struct GNUNET_ATS_Session *prev_neighbour;
116 307
117 /** 308 /**
118 * Kept in a MDLL. 309 * Kept in a MDLL.
119 */ 310 */
120 struct Queue *prev_client; 311 struct GNUNET_ATS_Session *prev_client;
121 312
122 /** 313 /**
123 * Kept in a MDLL. 314 * Kept in a MDLL.
124 */ 315 */
125 struct Queue *next_client; 316 struct GNUNET_ATS_Session *next_client;
126 317
127 /** 318 /**
128 * Which neighbour is this queue for? 319 * Which neighbour is this ATS session for?
129 */ 320 */
130 struct Neighbour *neighbour; 321 struct Neighbour *neighbour;
131 322
132 /** 323 /**
133 * Which communicator offers this queue? 324 * Which communicator offers this ATS session?
134 */ 325 */
135 struct TransportClient *tc; 326 struct TransportClient *tc;
136 327
137 /** 328 /**
138 * Address served by the queue. 329 * Address served by the ATS session.
139 */ 330 */
140 const char *address; 331 const char *address;
141 332
142 /** 333 /**
143 * Our current RTT estimate for this queue. 334 * Our current RTT estimate for this ATS session.
144 */ 335 */
145 struct GNUNET_TIME_Relative rtt; 336 struct GNUNET_TIME_Relative rtt;
146 337
147 /** 338 /**
148 * Unique identifier of this queue with the communicator. 339 * Unique identifier of this ATS session with the communicator.
149 */ 340 */
150 uint32_t qid; 341 uint32_t qid;
151 342
152 /** 343 /**
153 * Maximum transmission unit supported by this queue. 344 * Maximum transmission unit supported by this ATS session.
154 */ 345 */
155 uint32_t mtu; 346 uint32_t mtu;
156 347
157 /** 348 /**
158 * Distance to the target of this queue. 349 * Distance to the target of this ATS session.
159 */ 350 */
160 uint32_t distance; 351 uint32_t distance;
161 352
162 /** 353 /**
163 * Network type offered by this queue. 354 * Network type offered by this ATS session.
164 */ 355 */
165 enum GNUNET_NetworkType nt; 356 enum GNUNET_NetworkType nt;
166 357
167 /** 358 /**
168 * Connection status for this queue. 359 * Connection status for this ATS session.
169 */ 360 */
170 enum GNUNET_TRANSPORT_ConnectionStatus cs; 361 enum GNUNET_TRANSPORT_ConnectionStatus cs;
171 362
@@ -179,7 +370,15 @@ struct Queue
179 */ 370 */
180 uint32_t num_bytes_pending; 371 uint32_t num_bytes_pending;
181 372
182 // FIXME: add ATS-specific fields here! 373 /**
374 * How much outbound bandwidth do we have available for this session?
375 */
376 struct GNUNET_BANDWIDTH_Tracker tracker_out;
377
378 /**
379 * How much inbound bandwidth do we have available for this session?
380 */
381 struct GNUNET_BANDWIDTH_Tracker tracker_in;
183}; 382};
184 383
185 384
@@ -205,14 +404,14 @@ struct Neighbour
205 struct PendingMessage *pending_msg_tail; 404 struct PendingMessage *pending_msg_tail;
206 405
207 /** 406 /**
208 * Head of DLL of queues to this peer. 407 * Head of DLL of ATS sessions to this peer.
209 */ 408 */
210 struct Queue *queue_head; 409 struct GNUNET_ATS_Session *session_head;
211 410
212 /** 411 /**
213 * Tail of DLL of queues to this peer. 412 * Tail of DLL of ATS sessions to this peer.
214 */ 413 */
215 struct Queue *queue_tail; 414 struct GNUNET_ATS_Session *session_tail;
216 415
217 /** 416 /**
218 * Quota at which CORE is allowed to transmit to this peer 417 * Quota at which CORE is allowed to transmit to this peer
@@ -411,12 +610,12 @@ struct TransportClient
411 /** 610 /**
412 * Head of DLL of queues offered by this communicator. 611 * Head of DLL of queues offered by this communicator.
413 */ 612 */
414 struct Queue *queue_head; 613 struct GNUNET_ATS_Session *session_head;
415 614
416 /** 615 /**
417 * Tail of DLL of queues offered by this communicator. 616 * Tail of DLL of queues offered by this communicator.
418 */ 617 */
419 struct Queue *queue_tail; 618 struct GNUNET_ATS_Session *session_tail;
420 619
421 /** 620 /**
422 * Head of list of the addresses of this peer offered by this communicator. 621 * Head of list of the addresses of this peer offered by this communicator.
@@ -453,22 +652,22 @@ static struct TransportClient *clients_tail;
453/** 652/**
454 * Statistics handle. 653 * Statistics handle.
455 */ 654 */
456struct GNUNET_STATISTICS_Handle *GST_stats; 655static struct GNUNET_STATISTICS_Handle *GST_stats;
457 656
458/** 657/**
459 * Configuration handle. 658 * Configuration handle.
460 */ 659 */
461const struct GNUNET_CONFIGURATION_Handle *GST_cfg; 660static const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
462 661
463/** 662/**
464 * Our public key. 663 * Our public key.
465 */ 664 */
466struct GNUNET_PeerIdentity GST_my_identity; 665static struct GNUNET_PeerIdentity GST_my_identity;
467 666
468/** 667/**
469 * Our private key. 668 * Our private key.
470 */ 669 */
471struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key; 670static struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
472 671
473/** 672/**
474 * Map from PIDs to `struct Neighbour` entries. A peer is 673 * Map from PIDs to `struct Neighbour` entries. A peer is
@@ -481,6 +680,42 @@ static struct GNUNET_CONTAINER_MultiPeerMap *neighbours;
481 */ 680 */
482static struct GNUNET_PEERSTORE_Handle *peerstore; 681static struct GNUNET_PEERSTORE_Handle *peerstore;
483 682
683/**
684 * Heap sorting `struct EphemeralCacheEntry` by their
685 * key/signature validity.
686 */
687static struct GNUNET_CONTAINER_Heap *ephemeral_heap;
688
689/**
690 * Hash map for looking up `struct EphemeralCacheEntry`s
691 * by peer identity. (We may have ephemerals in our
692 * cache for which we do not have a neighbour entry,
693 * and similar many neighbours may not need ephemerals,
694 * so we use a second map.)
695 */
696static struct GNUNET_CONTAINER_MultiPeerMap *ephemeral_map;
697
698/**
699 * Our connection to ATS for allocation and bootstrapping.
700 */
701static struct GNUNET_ATS_TransportHandle *ats;
702
703
704/**
705 * Free cached ephemeral key.
706 *
707 * @param ece cached signature to free
708 */
709static void
710free_ephemeral (struct EphemeralCacheEntry *ece)
711{
712 GNUNET_CONTAINER_multipeermap_remove (ephemeral_map,
713 &ece->target,
714 ece);
715 GNUNET_CONTAINER_heap_remove_node (ece->hn);
716 GNUNET_free (ece);
717}
718
484 719
485/** 720/**
486 * Lookup neighbour record for peer @a pid. 721 * Lookup neighbour record for peer @a pid.
@@ -654,7 +889,7 @@ client_connect_cb (void *cls,
654static void 889static void
655free_neighbour (struct Neighbour *neighbour) 890free_neighbour (struct Neighbour *neighbour)
656{ 891{
657 GNUNET_assert (NULL == neighbour->queue_head); 892 GNUNET_assert (NULL == neighbour->session_head);
658 GNUNET_assert (GNUNET_YES == 893 GNUNET_assert (GNUNET_YES ==
659 GNUNET_CONTAINER_multipeermap_remove (neighbours, 894 GNUNET_CONTAINER_multipeermap_remove (neighbours,
660 &neighbour->pid, 895 &neighbour->pid,
@@ -743,7 +978,7 @@ cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid)
743 * @param queue the queue to free 978 * @param queue the queue to free
744 */ 979 */
745static void 980static void
746free_queue (struct Queue *queue) 981free_queue (struct GNUNET_ATS_Session *queue)
747{ 982{
748 struct Neighbour *neighbour = queue->neighbour; 983 struct Neighbour *neighbour = queue->neighbour;
749 struct TransportClient *tc = queue->tc; 984 struct TransportClient *tc = queue->tc;
@@ -753,20 +988,22 @@ free_queue (struct Queue *queue)
753 }; 988 };
754 989
755 GNUNET_CONTAINER_MDLL_remove (neighbour, 990 GNUNET_CONTAINER_MDLL_remove (neighbour,
756 neighbour->queue_head, 991 neighbour->session_head,
757 neighbour->queue_tail, 992 neighbour->session_tail,
758 queue); 993 queue);
759 GNUNET_CONTAINER_MDLL_remove (client, 994 GNUNET_CONTAINER_MDLL_remove (client,
760 tc->details.communicator.queue_head, 995 tc->details.communicator.session_head,
761 tc->details.communicator.queue_tail, 996 tc->details.communicator.session_tail,
762 queue); 997 queue);
763 998
764 notify_monitors (&neighbour->pid, 999 notify_monitors (&neighbour->pid,
765 queue->address, 1000 queue->address,
766 queue->nt, 1001 queue->nt,
767 &me); 1002 &me);
1003 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_in);
1004 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_out);
768 GNUNET_free (queue); 1005 GNUNET_free (queue);
769 if (NULL == neighbour->queue_head) 1006 if (NULL == neighbour->session_head)
770 { 1007 {
771 cores_send_disconnect_info (&neighbour->pid); 1008 cores_send_disconnect_info (&neighbour->pid);
772 free_neighbour (neighbour); 1009 free_neighbour (neighbour);
@@ -844,10 +1081,10 @@ client_disconnect_cb (void *cls,
844 break; 1081 break;
845 case CT_COMMUNICATOR: 1082 case CT_COMMUNICATOR:
846 { 1083 {
847 struct Queue *q; 1084 struct GNUNET_ATS_Session *q;
848 struct AddressListEntry *ale; 1085 struct AddressListEntry *ale;
849 1086
850 while (NULL != (q = tc->details.communicator.queue_head)) 1087 while (NULL != (q = tc->details.communicator.session_head))
851 free_queue (q); 1088 free_queue (q);
852 while (NULL != (ale = tc->details.communicator.addr_head)) 1089 while (NULL != (ale = tc->details.communicator.addr_head))
853 free_address_list_entry (ale); 1090 free_address_list_entry (ale);
@@ -1356,6 +1593,34 @@ check_add_queue_message (void *cls,
1356 1593
1357 1594
1358/** 1595/**
1596 * Bandwidth tracker informs us that the delay until we
1597 * can transmit again changed.
1598 *
1599 * @param cls a `struct GNUNET_ATS_Session` for which the delay changed
1600 */
1601static void
1602tracker_update_cb (void *cls)
1603{
1604 struct GNUNET_ATS_Session *queue = cls;
1605
1606 // FIXME: re-schedule transmission tasks if applicable!
1607}
1608
1609
1610/**
1611 * Bandwidth tracker informs us that excessive bandwidth was allocated
1612 * which is not being used.
1613 *
1614 * @param cls a `struct GNUNET_ATS_Session` for which the excess was noted
1615 */
1616static void
1617tracker_excess_cb (void *cls)
1618{
1619 /* FIXME: what do we do? */
1620}
1621
1622
1623/**
1359 * New queue became available. Process the request. 1624 * New queue became available. Process the request.
1360 * 1625 *
1361 * @param cls the client 1626 * @param cls the client
@@ -1366,7 +1631,7 @@ handle_add_queue_message (void *cls,
1366 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 1631 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
1367{ 1632{
1368 struct TransportClient *tc = cls; 1633 struct TransportClient *tc = cls;
1369 struct Queue *queue; 1634 struct GNUNET_ATS_Session *queue;
1370 struct Neighbour *neighbour; 1635 struct Neighbour *neighbour;
1371 const char *addr; 1636 const char *addr;
1372 uint16_t addr_len; 1637 uint16_t addr_len;
@@ -1388,7 +1653,7 @@ handle_add_queue_message (void *cls,
1388 addr_len = ntohs (aqm->header.size) - sizeof (*aqm); 1653 addr_len = ntohs (aqm->header.size) - sizeof (*aqm);
1389 addr = (const char *) &aqm[1]; 1654 addr = (const char *) &aqm[1];
1390 1655
1391 queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); 1656 queue = GNUNET_malloc (sizeof (struct GNUNET_ATS_Session) + addr_len);
1392 queue->tc = tc; 1657 queue->tc = tc;
1393 queue->address = (const char *) &queue[1]; 1658 queue->address = (const char *) &queue[1];
1394 queue->rtt = GNUNET_TIME_UNIT_FOREVER_REL; 1659 queue->rtt = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1398,6 +1663,20 @@ handle_add_queue_message (void *cls,
1398 queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt); 1663 queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt);
1399 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); 1664 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs);
1400 queue->neighbour = neighbour; 1665 queue->neighbour = neighbour;
1666 GNUNET_BANDWIDTH_tracker_init2 (&queue->tracker_in,
1667 &tracker_update_cb,
1668 queue,
1669 GNUNET_BANDWIDTH_ZERO,
1670 0 /* FIXME: max carry in seconds! */,
1671 &tracker_excess_cb,
1672 queue);
1673 GNUNET_BANDWIDTH_tracker_init2 (&queue->tracker_out,
1674 &tracker_update_cb,
1675 queue,
1676 GNUNET_BANDWIDTH_ZERO,
1677 0 /* FIXME: max carry in seconds! */,
1678 &tracker_excess_cb,
1679 queue);
1401 memcpy (&queue[1], 1680 memcpy (&queue[1],
1402 addr, 1681 addr,
1403 addr_len); 1682 addr_len);
@@ -1414,12 +1693,12 @@ handle_add_queue_message (void *cls,
1414 &me); 1693 &me);
1415 } 1694 }
1416 GNUNET_CONTAINER_MDLL_insert (neighbour, 1695 GNUNET_CONTAINER_MDLL_insert (neighbour,
1417 neighbour->queue_head, 1696 neighbour->session_head,
1418 neighbour->queue_tail, 1697 neighbour->session_tail,
1419 queue); 1698 queue);
1420 GNUNET_CONTAINER_MDLL_insert (client, 1699 GNUNET_CONTAINER_MDLL_insert (client,
1421 tc->details.communicator.queue_head, 1700 tc->details.communicator.session_head,
1422 tc->details.communicator.queue_tail, 1701 tc->details.communicator.session_tail,
1423 queue); 1702 queue);
1424 // FIXME: possibly transmit queued messages? 1703 // FIXME: possibly transmit queued messages?
1425 GNUNET_SERVICE_client_continue (tc->client); 1704 GNUNET_SERVICE_client_continue (tc->client);
@@ -1444,7 +1723,7 @@ handle_del_queue_message (void *cls,
1444 GNUNET_SERVICE_client_drop (tc->client); 1723 GNUNET_SERVICE_client_drop (tc->client);
1445 return; 1724 return;
1446 } 1725 }
1447 for (struct Queue *queue = tc->details.communicator.queue_head; 1726 for (struct GNUNET_ATS_Session *queue = tc->details.communicator.session_head;
1448 NULL != queue; 1727 NULL != queue;
1449 queue = queue->next_client) 1728 queue = queue->next_client)
1450 { 1729 {
@@ -1504,7 +1783,7 @@ notify_client_queues (void *cls,
1504 struct Neighbour *neighbour = value; 1783 struct Neighbour *neighbour = value;
1505 1784
1506 GNUNET_assert (CT_MONITOR == tc->type); 1785 GNUNET_assert (CT_MONITOR == tc->type);
1507 for (struct Queue *q = neighbour->queue_head; 1786 for (struct GNUNET_ATS_Session *q = neighbour->session_head;
1508 NULL != q; 1787 NULL != q;
1509 q = q->next_neighbour) 1788 q = q->next_neighbour)
1510 { 1789 {
@@ -1555,6 +1834,74 @@ handle_monitor_start (void *cls,
1555 1834
1556 1835
1557/** 1836/**
1837 * Signature of a function called by ATS with the current bandwidth
1838 * allocation to be used as determined by ATS.
1839 *
1840 * @param cls closure, NULL
1841 * @param session session this is about
1842 * @param bandwidth_out assigned outbound bandwidth for the connection,
1843 * 0 to signal disconnect
1844 * @param bandwidth_in assigned inbound bandwidth for the connection,
1845 * 0 to signal disconnect
1846 */
1847static void
1848ats_allocation_cb (void *cls,
1849 struct GNUNET_ATS_Session *session,
1850 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1851 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
1852{
1853 (void) cls;
1854 GNUNET_BANDWIDTH_tracker_update_quota (&session->tracker_out,
1855 bandwidth_out);
1856 GNUNET_BANDWIDTH_tracker_update_quota (&session->tracker_in,
1857 bandwidth_in);
1858}
1859
1860
1861/**
1862 * Find transport client providing communication service
1863 * for the protocol @a prefix.
1864 *
1865 * @param prefix communicator name
1866 * @return NULL if no such transport client is available
1867 */
1868static struct TransportClient *
1869lookup_communicator (const char *prefix)
1870{
1871 GNUNET_break (0); // FIXME: implement
1872 return NULL;
1873}
1874
1875
1876/**
1877 * Signature of a function called by ATS suggesting transport to
1878 * try connecting with a particular address.
1879 *
1880 * @param cls closure, NULL
1881 * @param pid target peer
1882 * @param address the address to try
1883 */
1884static void
1885ats_suggestion_cb (void *cls,
1886 const struct GNUNET_PeerIdentity *pid,
1887 const char *address)
1888{
1889 struct TransportClient *tc;
1890 char *prefix;
1891
1892 (void) cls;
1893 prefix = NULL; // FIXME
1894 tc = lookup_communicator (prefix);
1895 if (NULL == tc)
1896 {
1897 // STATS...
1898 return;
1899 }
1900 // FIXME: forward suggestion to tc
1901}
1902
1903
1904/**
1558 * Free neighbour entry. 1905 * Free neighbour entry.
1559 * 1906 *
1560 * @param cls NULL 1907 * @param cls NULL
@@ -1579,6 +1926,28 @@ free_neighbour_cb (void *cls,
1579 1926
1580 1927
1581/** 1928/**
1929 * Free ephemeral entry.
1930 *
1931 * @param cls NULL
1932 * @param pid unused
1933 * @param value a `struct Neighbour`
1934 * @return #GNUNET_OK (always)
1935 */
1936static int
1937free_ephemeral_cb (void *cls,
1938 const struct GNUNET_PeerIdentity *pid,
1939 void *value)
1940{
1941 struct EphemeralCacheEntry *ece = value;
1942
1943 (void) cls;
1944 (void) pid;
1945 free_ephemeral (ece);
1946 return GNUNET_OK;
1947}
1948
1949
1950/**
1582 * Function called when the service shuts down. Unloads our plugins 1951 * Function called when the service shuts down. Unloads our plugins
1583 * and cancels pending validations. 1952 * and cancels pending validations.
1584 * 1953 *
@@ -1592,6 +1961,11 @@ do_shutdown (void *cls)
1592 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 1961 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
1593 &free_neighbour_cb, 1962 &free_neighbour_cb,
1594 NULL); 1963 NULL);
1964 if (NULL != ats)
1965 {
1966 GNUNET_ATS_transport_done (ats);
1967 ats = NULL;
1968 }
1595 if (NULL != peerstore) 1969 if (NULL != peerstore)
1596 { 1970 {
1597 GNUNET_PEERSTORE_disconnect (peerstore, 1971 GNUNET_PEERSTORE_disconnect (peerstore,
@@ -1610,6 +1984,14 @@ do_shutdown (void *cls)
1610 GST_my_private_key = NULL; 1984 GST_my_private_key = NULL;
1611 } 1985 }
1612 GNUNET_CONTAINER_multipeermap_destroy (neighbours); 1986 GNUNET_CONTAINER_multipeermap_destroy (neighbours);
1987 neighbours = NULL;
1988 GNUNET_CONTAINER_multipeermap_iterate (ephemeral_map,
1989 &free_ephemeral_cb,
1990 NULL);
1991 GNUNET_CONTAINER_multipeermap_destroy (ephemeral_map);
1992 ephemeral_map = NULL;
1993 GNUNET_CONTAINER_heap_destroy (ephemeral_heap);
1994 ephemeral_heap = NULL;
1613} 1995}
1614 1996
1615 1997
@@ -1630,6 +2012,9 @@ run (void *cls,
1630 GST_cfg = c; 2012 GST_cfg = c;
1631 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, 2013 neighbours = GNUNET_CONTAINER_multipeermap_create (1024,
1632 GNUNET_YES); 2014 GNUNET_YES);
2015 ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32,
2016 GNUNET_YES);
2017 ephemeral_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1633 GST_my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); 2018 GST_my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg);
1634 if (NULL == GST_my_private_key) 2019 if (NULL == GST_my_private_key)
1635 { 2020 {
@@ -1643,19 +2028,28 @@ run (void *cls,
1643 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2028 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1644 "My identity is `%s'\n", 2029 "My identity is `%s'\n",
1645 GNUNET_i2s_full (&GST_my_identity)); 2030 GNUNET_i2s_full (&GST_my_identity));
1646
1647 GST_stats = GNUNET_STATISTICS_create ("transport", 2031 GST_stats = GNUNET_STATISTICS_create ("transport",
1648 GST_cfg); 2032 GST_cfg);
1649 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 2033 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
1650 NULL); 2034 NULL);
1651 peerstore = GNUNET_PEERSTORE_connect (GST_cfg); 2035 peerstore = GNUNET_PEERSTORE_connect (GST_cfg);
1652 if (NULL == peerstore) 2036 if (NULL == peerstore)
1653 { 2037 {
1654 GNUNET_break (0); 2038 GNUNET_break (0);
1655 GNUNET_SCHEDULER_shutdown (); 2039 GNUNET_SCHEDULER_shutdown ();
1656 return; 2040 return;
1657 } 2041 }
1658 /* start subsystems */ 2042 ats = GNUNET_ATS_transport_init (GST_cfg,
2043 &ats_allocation_cb,
2044 NULL,
2045 &ats_suggestion_cb,
2046 NULL);
2047 if (NULL == ats)
2048 {
2049 GNUNET_break (0);
2050 GNUNET_SCHEDULER_shutdown ();
2051 return;
2052 }
1659} 2053}
1660 2054
1661 2055
diff --git a/src/transport/transport.h b/src/transport/transport.h
index df1321d1a..3c5fe72de 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -26,7 +26,6 @@
26 26
27#include "gnunet_crypto_lib.h" 27#include "gnunet_crypto_lib.h"
28#include "gnunet_time_lib.h" 28#include "gnunet_time_lib.h"
29#include "gnunet_transport_service.h"
30#include "gnunet_constants.h" 29#include "gnunet_constants.h"
31 30
32#define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING 31#define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING
@@ -79,6 +78,7 @@ typedef void
79 78
80GNUNET_NETWORK_STRUCT_BEGIN 79GNUNET_NETWORK_STRUCT_BEGIN
81 80
81
82/** 82/**
83 * Message from the transport service to the library 83 * Message from the transport service to the library
84 * asking to check if both processes agree about this 84 * asking to check if both processes agree about this
@@ -241,61 +241,67 @@ struct SendOkMessage
241 241
242}; 242};
243 243
244
244/** 245/**
245 * Message used to notify the transport API about an address to string 246 * Message used to notify the transport service about a message
246 * conversion. Message is followed by the string with the humand-readable 247 * to be transmitted to another peer. The actual message follows.
247 * address. For each lookup, multiple results may be returned. The
248 * last message must have a @e res of #GNUNET_OK and an @e addr_len
249 * of zero.
250 */ 248 */
251struct AddressToStringResultMessage 249struct OutboundMessage
252{ 250{
253 251
254 /** 252 /**
255 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY 253 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
256 */ 254 */
257 struct GNUNET_MessageHeader header; 255 struct GNUNET_MessageHeader header;
258 256
259 /** 257 /**
260 * #GNUNET_OK if the conversion succeeded, 258 * Always zero.
261 * #GNUNET_SYSERR if it failed
262 */ 259 */
263 uint32_t res GNUNET_PACKED; 260 uint32_t reserved GNUNET_PACKED;
264 261
265 /** 262 /**
266 * Length of the following string, zero if @e is #GNUNET_SYSERR 263 * Allowed delay.
267 */ 264 */
268 uint32_t addr_len GNUNET_PACKED; 265 struct GNUNET_TIME_RelativeNBO timeout;
266
267 /**
268 * Which peer should receive the message?
269 */
270 struct GNUNET_PeerIdentity peer;
271
269}; 272};
270 273
271 274
275
276
277#if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION)||defined(GNUNET_TRANSPORT_CORE_VERSION))
278
279
272/** 280/**
273 * Message used to notify the transport service about a message 281 * Message used to notify the transport API about an address to string
274 * to be transmitted to another peer. The actual message follows. 282 * conversion. Message is followed by the string with the humand-readable
283 * address. For each lookup, multiple results may be returned. The
284 * last message must have a @e res of #GNUNET_OK and an @e addr_len
285 * of zero.
275 */ 286 */
276struct OutboundMessage 287struct AddressToStringResultMessage
277{ 288{
278 289
279 /** 290 /**
280 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND 291 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
281 */ 292 */
282 struct GNUNET_MessageHeader header; 293 struct GNUNET_MessageHeader header;
283 294
284 /** 295 /**
285 * Always zero. 296 * #GNUNET_OK if the conversion succeeded,
286 */ 297 * #GNUNET_SYSERR if it failed
287 uint32_t reserved GNUNET_PACKED;
288
289 /**
290 * Allowed delay.
291 */ 298 */
292 struct GNUNET_TIME_RelativeNBO timeout; 299 uint32_t res GNUNET_PACKED;
293 300
294 /** 301 /**
295 * Which peer should receive the message? 302 * Length of the following string, zero if @e is #GNUNET_SYSERR
296 */ 303 */
297 struct GNUNET_PeerIdentity peer; 304 uint32_t addr_len GNUNET_PACKED;
298
299}; 305};
300 306
301 307
@@ -639,13 +645,7 @@ struct TransportPluginMonitorMessage
639 645
640}; 646};
641 647
642 648#else
643
644
645
646
647
648
649 649
650/* *********************** TNG messages ***************** */ 650/* *********************** TNG messages ***************** */
651 651
@@ -950,6 +950,35 @@ struct GNUNET_TRANSPORT_SendMessageToAck
950}; 950};
951 951
952 952
953/**
954 * Message from communicator to transport service asking for
955 * transmission of a backchannel message with the given peer @e pid
956 * and communicator.
957 */
958struct GNUNET_TRANSPORT_CommunicatorBackchannel
959{
960 /**
961 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL
962 */
963 struct GNUNET_MessageHeader header;
964
965 /**
966 * Always zero, for alignment.
967 */
968 uint32_t reserved;
969
970 /**
971 * Target peer.
972 */
973 struct GNUNET_PeerIdentity pid;
974
975 /* Followed by a `struct GNUNET_MessageHeader` with the encapsulated
976 message to the communicator */
977
978 /* Followed by the 0-terminated string specifying the desired
979 communicator */
980};
981
953 982
954 983
955/** 984/**
@@ -1028,9 +1057,7 @@ struct GNUNET_TRANSPORT_MonitorData
1028 1057
1029}; 1058};
1030 1059
1031 1060#endif
1032
1033
1034 1061
1035GNUNET_NETWORK_STRUCT_END 1062GNUNET_NETWORK_STRUCT_END
1036 1063
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index ffd7f208e..a8237f18f 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -25,6 +25,7 @@
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
26#include "gnunet_protocols.h" 26#include "gnunet_protocols.h"
27#include "gnunet_transport_communication_service.h" 27#include "gnunet_transport_communication_service.h"
28#include "gnunet_ats_transport_service.h"
28#include "transport.h" 29#include "transport.h"
29 30
30 31
@@ -178,6 +179,18 @@ struct GNUNET_TRANSPORT_CommunicatorHandle
178 void *mq_init_cls; 179 void *mq_init_cls;
179 180
180 /** 181 /**
182 * Function to call when the transport service receives messages
183 * for a communicator (i.e. for NAT traversal or for non-bidirectional
184 * communicators).
185 */
186 GNUNET_TRANSPORT_CommunicatorNotify notify_cb;
187
188 /**
189 * Closure for @e notify_Cb.
190 */
191 void *notify_cb_cls;
192
193 /**
181 * Queue to talk to the transport service. 194 * Queue to talk to the transport service.
182 */ 195 */
183 struct GNUNET_MQ_Handle *mq; 196 struct GNUNET_MQ_Handle *mq;
@@ -744,6 +757,7 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
744 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, 757 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG,
745 struct GNUNET_TRANSPORT_SendMessageTo, 758 struct GNUNET_TRANSPORT_SendMessageTo,
746 ch), 759 ch),
760 // FIXME: handle backchannel notifications!
747 GNUNET_MQ_handler_end() 761 GNUNET_MQ_handler_end()
748 }; 762 };
749 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; 763 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam;
@@ -790,6 +804,8 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
790 * the address of another peer, can be NULL if the 804 * the address of another peer, can be NULL if the
791 * communicator only supports receiving messages 805 * communicator only supports receiving messages
792 * @param mq_init_cls closure for @a mq_init 806 * @param mq_init_cls closure for @a mq_init
807 * @param notify_cb function to pass backchannel messages to communicator
808 * @param notify_cb_cls closure for @a notify_cb
793 * @return NULL on error 809 * @return NULL on error
794 */ 810 */
795struct GNUNET_TRANSPORT_CommunicatorHandle * 811struct GNUNET_TRANSPORT_CommunicatorHandle *
@@ -798,7 +814,9 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle
798 const char *addr_prefix, 814 const char *addr_prefix,
799 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 815 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
800 GNUNET_TRANSPORT_CommunicatorMqInit mq_init, 816 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
801 void *mq_init_cls) 817 void *mq_init_cls,
818 GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
819 void *notify_cb_cls)
802{ 820{
803 struct GNUNET_TRANSPORT_CommunicatorHandle *ch; 821 struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
804 822
@@ -808,6 +826,8 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle
808 ch->addr_prefix = addr_prefix; 826 ch->addr_prefix = addr_prefix;
809 ch->mq_init = mq_init; 827 ch->mq_init = mq_init;
810 ch->mq_init_cls = mq_init_cls; 828 ch->mq_init_cls = mq_init_cls;
829 ch->notify_cb = notify_cb;
830 ch->notify_cb_cls = notify_cb_cls;
811 ch->cc = cc; 831 ch->cc = cc;
812 reconnect (ch); 832 reconnect (ch);
813 if (GNUNET_OK != 833 if (GNUNET_OK !=
@@ -1041,4 +1061,48 @@ GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIde
1041} 1061}
1042 1062
1043 1063
1064/* ************************* Backchannel *************************** */
1065
1066
1067/**
1068 * The communicator asks the transport service to route a message via
1069 * a different path to another communicator service at another peer.
1070 * This must only be done for special control traffic (as there is no
1071 * flow control for this API), such as acknowledgements, and generally
1072 * only be done if the communicator is uni-directional (i.e. cannot
1073 * send the message back itself).
1074 *
1075 * @param ch handle of this communicator
1076 * @param pid peer to send the message to
1077 * @param comm name of the communicator to send the message to
1078 * @param header header of the message to transmit and pass via the
1079 * notify-API to @a pid's communicator @a comm
1080 */
1081void
1082GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
1083 const struct GNUNET_PeerIdentity *pid,
1084 const char *comm,
1085 const struct GNUNET_MessageHeader *header)
1086{
1087 struct GNUNET_MQ_Envelope *env;
1088 struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb;
1089 size_t slen = strlen (comm) + 1;
1090 uint16_t mlen = ntohs (header->size);
1091
1092 GNUNET_assert (mlen + slen + sizeof (*cb) < UINT16_MAX);
1093 env = GNUNET_MQ_msg_extra (cb,
1094 slen + mlen,
1095 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL);
1096 cb->pid = *pid;
1097 memcpy (&cb[1],
1098 header,
1099 mlen);
1100 memcpy (((char *)&cb[1]) + mlen,
1101 comm,
1102 slen);
1103 GNUNET_MQ_send (ch->mq,
1104 env);
1105}
1106
1107
1044/* end of transport_api2_communication.c */ 1108/* end of transport_api2_communication.c */
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c
index 78d8dcce0..d81a6f730 100644
--- a/src/transport/transport_api2_core.c
+++ b/src/transport/transport_api2_core.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*/
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c
index 2e897d94a..06d459f4e 100644
--- a/src/transport/transport_api_core.c
+++ b/src/transport/transport_api_core.c
@@ -28,6 +28,7 @@
28#include "gnunet_hello_lib.h" 28#include "gnunet_hello_lib.h"
29#include "gnunet_protocols.h" 29#include "gnunet_protocols.h"
30#include "gnunet_transport_core_service.h" 30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_service.h"
31#include "transport.h" 32#include "transport.h"
32 33
33#define LOG(kind,...) GNUNET_log_from (kind, "transport-api-core",__VA_ARGS__) 34#define LOG(kind,...) GNUNET_log_from (kind, "transport-api-core",__VA_ARGS__)