aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_transport_service.h284
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/gnunet-service-transport.h13
-rw-r--r--src/transport/gnunet-service-transport_clients.c18
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c169
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h3
-rw-r--r--src/transport/gnunet-transport.c633
-rw-r--r--src/transport/transport.h34
-rw-r--r--src/transport/transport_api_monitoring.c (renamed from src/transport/transport_api_address_lookup.c)192
9 files changed, 738 insertions, 610 deletions
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
index 4b0735b10..dee8e7118 100644
--- a/src/include/gnunet_transport_service.h
+++ b/src/include/gnunet_transport_service.h
@@ -45,6 +45,170 @@ extern "C"
45 45
46 46
47/** 47/**
48 * Possible state of a neighbour. Initially, we are #S_NOT_CONNECTED.
49 *
50 * Then, there are two main paths. If we receive a CONNECT message, we
51 * first run a check against the blacklist (#S_CONNECT_RECV_BLACKLIST_INBOUND).
52 * If this check is successful, we give the inbound address to ATS.
53 * After the check we ask ATS for a suggestion (S_CONNECT_RECV_ATS).
54 * If ATS makes a suggestion, we ALSO give that suggestion to the blacklist
55 * (#S_CONNECT_RECV_BLACKLIST). Once the blacklist approves the
56 * address we got from ATS, we send our CONNECT_ACK and go to
57 * #S_CONNECT_RECV_ACK. If we receive a SESSION_ACK, we go to
58 * #S_CONNECTED (and notify everyone about the new connection). If the
59 * operation times out, we go to #S_DISCONNECT.
60 *
61 * The other case is where we transmit a CONNECT message first. We
62 * start with #S_INIT_ATS. If we get an address, we enter
63 * #S_INIT_BLACKLIST and check the blacklist. If the blacklist is OK
64 * with the connection, we actually send the CONNECT message and go to
65 * state S_CONNECT_SENT. Once we receive a CONNECT_ACK, we go to
66 * #S_CONNECTED (and notify everyone about the new connection and send
67 * back a SESSION_ACK). If the operation times out, we go to
68 * #S_DISCONNECT.
69 *
70 * If the session is in trouble (i.e. transport-level disconnect or
71 * timeout), we go to #S_RECONNECT_ATS where we ask ATS for a new
72 * address (we don't notify anyone about the disconnect yet). Once we
73 * have a new address, we go to #S_RECONNECT_BLACKLIST to check the new
74 * address against the blacklist. If the blacklist approves, we enter
75 * #S_RECONNECT_SENT and send a CONNECT message. If we receive a
76 * CONNECT_ACK, we go to #S_CONNECTED and nobody noticed that we had
77 * trouble; we also send a SESSION_ACK at this time just in case. If
78 * the operation times out, we go to S_DISCONNECT (and notify everyone
79 * about the lost connection).
80 *
81 * If ATS decides to switch addresses while we have a normal
82 * connection, we go to #S_CONNECTED_SWITCHING_BLACKLIST to check the
83 * new address against the blacklist. If the blacklist approves, we
84 * go to #S_CONNECTED_SWITCHING_CONNECT_SENT and send a
85 * SESSION_CONNECT. If we get a SESSION_ACK back, we switch the
86 * primary connection to the suggested alternative from ATS, go back
87 * to #S_CONNECTED and send a SESSION_ACK to the other peer just to be
88 * sure. If the operation times out (or the blacklist disapproves),
89 * we go to #S_CONNECTED (and notify ATS that the given alternative
90 * address is "invalid").
91 *
92 * Once a session is in #S_DISCONNECT, it is cleaned up and then goes
93 * to (#S_DISCONNECT_FINISHED). If we receive an explicit disconnect
94 * request, we can go from any state to #S_DISCONNECT, possibly after
95 * generating disconnect notifications.
96 *
97 * Note that it is quite possible that while we are in any of these
98 * states, we could receive a 'CONNECT' request from the other peer.
99 * We then enter a 'weird' state where we pursue our own primary state
100 * machine (as described above), but with the 'send_connect_ack' flag
101 * set to 1. If our state machine allows us to send a 'CONNECT_ACK'
102 * (because we have an acceptable address), we send the 'CONNECT_ACK'
103 * and set the 'send_connect_ack' to 2. If we then receive a
104 * 'SESSION_ACK', we go to #S_CONNECTED (and reset 'send_connect_ack'
105 * to 0).
106 *
107 */
108enum GNUNET_TRANSPORT_PeerState
109{
110 /**
111 * fresh peer or completely disconnected
112 */
113 S_NOT_CONNECTED = 0,
114
115 /**
116 * Asked to initiate connection, trying to get address from ATS
117 */
118 S_INIT_ATS,
119
120 /**
121 * Asked to initiate connection, trying to get address approved
122 * by blacklist.
123 */
124 S_INIT_BLACKLIST,
125
126 /**
127 * Sent CONNECT message to other peer, waiting for CONNECT_ACK
128 */
129 S_CONNECT_SENT,
130
131 /**
132 * Received a CONNECT, do a blacklist check for inbound address
133 */
134 S_CONNECT_RECV_BLACKLIST_INBOUND,
135
136 /**
137 * Received a CONNECT, asking ATS about address suggestions.
138 */
139 S_CONNECT_RECV_ATS,
140
141 /**
142 * Received CONNECT from other peer, got an address, checking with blacklist.
143 */
144 S_CONNECT_RECV_BLACKLIST,
145
146 /**
147 * CONNECT request from other peer was SESSION_ACK'ed, waiting for
148 * SESSION_ACK.
149 */
150 S_CONNECT_RECV_ACK,
151
152 /**
153 * Got our CONNECT_ACK/SESSION_ACK, connection is up.
154 */
155 S_CONNECTED,
156
157 /**
158 * Connection got into trouble, rest of the system still believes
159 * it to be up, but we're getting a new address from ATS.
160 */
161 S_RECONNECT_ATS,
162
163 /**
164 * Connection got into trouble, rest of the system still believes
165 * it to be up; we are checking the new address against the blacklist.
166 */
167 S_RECONNECT_BLACKLIST,
168
169 /**
170 * Sent CONNECT over new address (either by ATS telling us to switch
171 * addresses or from RECONNECT_ATS); if this fails, we need to tell
172 * the rest of the system about a disconnect.
173 */
174 S_RECONNECT_SENT,
175
176 /**
177 * We have some primary connection, but ATS suggested we switch
178 * to some alternative; we're now checking the alternative against
179 * the blacklist.
180 */
181 S_CONNECTED_SWITCHING_BLACKLIST,
182
183 /**
184 * We have some primary connection, but ATS suggested we switch
185 * to some alternative; we now sent a CONNECT message for the
186 * alternative session to the other peer and waiting for a
187 * CONNECT_ACK to make this our primary connection.
188 */
189 S_CONNECTED_SWITCHING_CONNECT_SENT,
190
191 /**
192 * Disconnect in progress (we're sending the DISCONNECT message to the
193 * other peer; after that is finished, the state will be cleaned up).
194 */
195 S_DISCONNECT,
196
197 /**
198 * We're finished with the disconnect; and are cleaning up the state
199 * now! We put the struct into this state when we are really in the
200 * task that calls 'free' on it and are about to remove the record
201 * from the map. We should never find a 'struct NeighbourMapEntry'
202 * in this state in the map. Accessing a 'struct NeighbourMapEntry'
203 * in this state virtually always means using memory that has been
204 * freed (the exception being the cleanup code in #free_neighbour()).
205 */
206 S_DISCONNECT_FINISHED
207};
208
209
210
211/**
48 * Function called by the transport for each received message. 212 * Function called by the transport for each received message.
49 * 213 *
50 * @param cls closure 214 * @param cls closure
@@ -119,19 +283,39 @@ typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
119 283
120 284
121/** 285/**
122 * Function to call with a binary format of an address 286 * Function to call with information about a peer
123 * 287 *
124 * @param cls closure 288 * @param cls closure
125 * @param peer peer this update is about (never NULL) 289 * @param peer peer this update is about,
290 * NULL if this is the final last callback for a iteration operation
126 * @param address address, NULL for disconnect notification in monitor mode 291 * @param address address, NULL for disconnect notification in monitor mode
292 * @param state current state this peer is in
293 * @param state_timeout timeout for the current state of the peer
127 */ 294 */
128typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls, 295typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
129 const struct 296 const struct GNUNET_PeerIdentity *peer,
130 GNUNET_PeerIdentity * 297 const struct GNUNET_HELLO_Address *address,
131 peer, 298 enum GNUNET_TRANSPORT_PeerState state,
132 const struct 299 struct GNUNET_TIME_Absolute state_timeout);
133 GNUNET_HELLO_Address * 300
134 address); 301
302/**
303 * Function to call with validation information about a peer
304 *
305 * @param cls closure
306 * @param peer peer this update is about,
307 * NULL if this is the final last callback for a iteration operation
308 * @param address address, NULL for disconnect notification in monitor mode
309 * @param valid_until when does this address expire
310 * @param next_validation time of the next validation operation
311 *
312 */
313typedef void (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls,
314 const struct GNUNET_PeerIdentity *peer,
315 const struct GNUNET_HELLO_Address *address,
316 struct GNUNET_TIME_Absolute valid_until,
317 struct GNUNET_TIME_Absolute next_validation);
318
135 319
136 320
137/** 321/**
@@ -401,46 +585,84 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
401void 585void
402GNUNET_TRANSPORT_address_to_string_cancel (struct 586GNUNET_TRANSPORT_address_to_string_cancel (struct
403 GNUNET_TRANSPORT_AddressToStringContext 587 GNUNET_TRANSPORT_AddressToStringContext
404 *alc); 588 *pic);
405 589
406 590
407/** 591/**
408 * Return all the known addresses for a specific peer or all peers. 592 * Return information about a specific peer or all peers currently known to
409 * Returns continuously all address if one_shot is set to GNUNET_NO 593 * transport service once or in monitoring mode. To obtain information about
594 * a specific peer, a peer identity can be passed. To obtain information about
595 * all peers currently known to transport service, NULL can be passed as peer
596 * identity.
410 * 597 *
411 * CHANGE: Returns the address(es) that we are currently using for this 598 * For each peer, the callback is called with information about the address used
412 * peer. Upon completion, the 'AddressLookUpCallback' is called one more 599 * to communicate with this peer, the state this peer is currently in and the
413 * time with 'NULL' for the address and the peer. After this, the operation must no 600 * the current timeout for this state.
414 * longer be explicitly cancelled. 601 *
602 * Upon completion, the 'GNUNET_TRANSPORT_PeerIterateCallback' is called one
603 * more time with 'NULL'. After this, the operation must no longer be
604 * explicitly canceled.
415 * 605 *
416 * @param cfg configuration to use 606 * @param cfg configuration to use
417 * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers 607 * @param peer a specific peer identity to obtain information for,
608 * NULL for all peers
418 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), 609 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
419 * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled, NOT implemented yet!) 610 * GNUNET_NO to monitor peers continuously
420 * @param timeout how long is the lookup allowed to take at most 611 * @param timeout how long is the lookup allowed to take at most
421 * @param peer_address_callback function to call with the results 612 * @param peer_address_callback function to call with the results
422 * @param peer_address_callback_cls closure for peer_address_callback 613 * @param peer_address_callback_cls closure for peer_address_callback
423 */ 614 */
424struct GNUNET_TRANSPORT_PeerIterateContext * 615struct GNUNET_TRANSPORT_PeerMonitoringContext *
425GNUNET_TRANSPORT_peer_get_active_addresses (const struct 616GNUNET_TRANSPORT_monitor_peers (const struct
426 GNUNET_CONFIGURATION_Handle *cfg, 617 GNUNET_CONFIGURATION_Handle *cfg,
427 const struct GNUNET_PeerIdentity 618 const struct GNUNET_PeerIdentity *peer,
428 *peer, int one_shot, 619 int one_shot,
429 struct GNUNET_TIME_Relative timeout, 620 struct GNUNET_TIME_Relative timeout,
430 GNUNET_TRANSPORT_PeerIterateCallback 621 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
431 peer_address_callback, 622 void *peer_callback_cls);
432 void *peer_address_callback_cls);
433 623
434 624
435/** 625/**
436 * Cancel request for peer lookup. 626 * Cancel request to monitor peers
437 * 627 *
438 * @param alc handle for the request to cancel 628 * @param pic handle for the request to cancel
439 */ 629 */
440void 630void
441GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct 631GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
442 GNUNET_TRANSPORT_PeerIterateContext 632
443 *alc); 633
634
635/**
636 * Return information about pending address validation operations for a specific
637 * or all peers
638 *
639 * @param cfg configuration to use
640 * @param peer a specific peer identity to obtain validation entries for,
641 * NULL for all peers
642 * @param one_shot GNUNET_YES to return all entries and then end (with NULL+NULL),
643 * GNUNET_NO to monitor validation entries continuously
644 * @param timeout how long is the lookup allowed to take at most
645 * @param validation_callback function to call with the results
646 * @param validation_callback_cls closure for peer_address_callback
647 */
648struct GNUNET_TRANSPORT_ValidationMonitoringContext *
649GNUNET_TRANSPORT_monitor_validation_entries (const struct
650 GNUNET_CONFIGURATION_Handle *cfg,
651 const struct GNUNET_PeerIdentity *peer,
652 int one_shot,
653 struct GNUNET_TIME_Relative timeout,
654 GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
655 void *validation_callback_cls);
656
657
658/**
659 * Return information about all current pending validation operations
660 *
661 * @param vic handle for the request to cancel
662 */
663void
664GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic);
665
444 666
445 667
446/** 668/**
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index e6ecf4ffe..1221cdbea 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -134,7 +134,7 @@ libgnunettransport_la_SOURCES = \
134 transport_api.c transport.h \ 134 transport_api.c transport.h \
135 transport_api_blacklist.c \ 135 transport_api_blacklist.c \
136 transport_api_address_to_string.c \ 136 transport_api_address_to_string.c \
137 transport_api_address_lookup.c 137 transport_api_monitoring.c
138libgnunettransport_la_LIBADD = \ 138libgnunettransport_la_LIBADD = \
139 $(top_builddir)/src/hello/libgnunethello.la \ 139 $(top_builddir)/src/hello/libgnunethello.la \
140 $(top_builddir)/src/util/libgnunetutil.la \ 140 $(top_builddir)/src/util/libgnunetutil.la \
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h
index 1a079e167..cc83f2c83 100644
--- a/src/transport/gnunet-service-transport.h
+++ b/src/transport/gnunet-service-transport.h
@@ -62,6 +62,19 @@ extern struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
62 */ 62 */
63extern struct GNUNET_ATS_SchedulingHandle *GST_ats; 63extern struct GNUNET_ATS_SchedulingHandle *GST_ats;
64 64
65
66/**
67 * Function to call when a peer's address has changed
68 *
69 * @param cls closure
70 * @param peer peer this update is about,
71 * @param address address, NULL for disconnect notification
72 */
73typedef void (*GNUNET_TRANSPORT_AddressChangeCallback) (void *cls,
74 const struct GNUNET_PeerIdentity *peer,
75 const struct GNUNET_HELLO_Address *address);
76
77
65/** 78/**
66 * Function called by the transport for each received message. 79 * Function called by the transport for each received message.
67 * This function should also be called with "NULL" for the 80 * This function should also be called with "NULL" for the
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 8679f40b4..7c4a9d712 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -851,11 +851,11 @@ clients_handle_address_to_string (void *cls,
851 * @param address the address, NULL on disconnect 851 * @param address the address, NULL on disconnect
852 * @return composed message 852 * @return composed message
853 */ 853 */
854static struct AddressIterateResponseMessage * 854static struct PeerIterateResponseMessage *
855compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer, 855compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
856 const struct GNUNET_HELLO_Address *address) 856 const struct GNUNET_HELLO_Address *address)
857{ 857{
858 struct AddressIterateResponseMessage *msg; 858 struct PeerIterateResponseMessage *msg;
859 size_t size; 859 size_t size;
860 size_t tlen; 860 size_t tlen;
861 size_t alen; 861 size_t alen;
@@ -869,7 +869,7 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer
869 } 869 }
870 else 870 else
871 tlen = alen = 0; 871 tlen = alen = 0;
872 size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen); 872 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen);
873 msg = GNUNET_malloc (size); 873 msg = GNUNET_malloc (size);
874 msg->header.size = htons (size); 874 msg->header.size = htons (size);
875 msg->header.type = 875 msg->header.type =
@@ -904,7 +904,7 @@ output_address (void *cls, const struct GNUNET_PeerIdentity *peer,
904 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 904 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
905{ 905{
906 struct GNUNET_SERVER_TransmitContext *tc = cls; 906 struct GNUNET_SERVER_TransmitContext *tc = cls;
907 struct AddressIterateResponseMessage *msg; 907 struct PeerIterateResponseMessage *msg;
908 908
909 msg = compose_address_iterate_response_message (peer, address); 909 msg = compose_address_iterate_response_message (peer, address);
910 GNUNET_SERVER_transmit_context_append_message (tc, &msg->header); 910 GNUNET_SERVER_transmit_context_append_message (tc, &msg->header);
@@ -927,7 +927,7 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
927{ 927{
928 static struct GNUNET_PeerIdentity all_zeros; 928 static struct GNUNET_PeerIdentity all_zeros;
929 struct GNUNET_SERVER_TransmitContext *tc; 929 struct GNUNET_SERVER_TransmitContext *tc;
930 struct AddressIterateMessage *msg; 930 struct PeerIterateMessage *msg;
931 struct GNUNET_HELLO_Address *address; 931 struct GNUNET_HELLO_Address *address;
932 932
933 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE) 933 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
@@ -936,13 +936,13 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
936 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 936 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
937 return; 937 return;
938 } 938 }
939 if (ntohs (message->size) != sizeof (struct AddressIterateMessage)) 939 if (ntohs (message->size) != sizeof (struct PeerIterateMessage))
940 { 940 {
941 GNUNET_break (0); 941 GNUNET_break (0);
942 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 942 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
943 return; 943 return;
944 } 944 }
945 msg = (struct AddressIterateMessage *) message; 945 msg = (struct PeerIterateMessage *) message;
946 if ( (GNUNET_YES != ntohl (msg->one_shot)) && 946 if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
947 (NULL != lookup_monitoring_client (client)) ) 947 (NULL != lookup_monitoring_client (client)) )
948 { 948 {
@@ -1000,7 +1000,7 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server)
1000 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, 1000 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
1001 {&clients_handle_address_iterate, NULL, 1001 {&clients_handle_address_iterate, NULL,
1002 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, 1002 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
1003 sizeof (struct AddressIterateMessage)}, 1003 sizeof (struct PeerIterateMessage)},
1004 {&GST_blacklist_handle_init, NULL, 1004 {&GST_blacklist_handle_init, NULL,
1005 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, 1005 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
1006 sizeof (struct GNUNET_MessageHeader)}, 1006 sizeof (struct GNUNET_MessageHeader)},
@@ -1090,7 +1090,7 @@ void
1090GST_clients_broadcast_address_notification (const struct GNUNET_PeerIdentity *peer, 1090GST_clients_broadcast_address_notification (const struct GNUNET_PeerIdentity *peer,
1091 const struct GNUNET_HELLO_Address *address) 1091 const struct GNUNET_HELLO_Address *address)
1092{ 1092{
1093 struct AddressIterateResponseMessage *msg; 1093 struct PeerIterateResponseMessage *msg;
1094 struct MonitoringClient *mc; 1094 struct MonitoringClient *mc;
1095 static struct GNUNET_PeerIdentity all_zeros; 1095 static struct GNUNET_PeerIdentity all_zeros;
1096 msg = compose_address_iterate_response_message (peer, address); 1096 msg = compose_address_iterate_response_message (peer, address);
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 7183f1f84..d451991f1 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -231,167 +231,6 @@ struct MessageQueue
231}; 231};
232 232
233 233
234/**
235 * Possible state of a neighbour. Initially, we are #S_NOT_CONNECTED.
236 *
237 * Then, there are two main paths. If we receive a CONNECT message, we
238 * first run a check against the blacklist (#S_CONNECT_RECV_BLACKLIST_INBOUND).
239 * If this check is successful, we give the inbound address to ATS.
240 * After the check we ask ATS for a suggestion (S_CONNECT_RECV_ATS).
241 * If ATS makes a suggestion, we ALSO give that suggestion to the blacklist
242 * (#S_CONNECT_RECV_BLACKLIST). Once the blacklist approves the
243 * address we got from ATS, we send our CONNECT_ACK and go to
244 * #S_CONNECT_RECV_ACK. If we receive a SESSION_ACK, we go to
245 * #S_CONNECTED (and notify everyone about the new connection). If the
246 * operation times out, we go to #S_DISCONNECT.
247 *
248 * The other case is where we transmit a CONNECT message first. We
249 * start with #S_INIT_ATS. If we get an address, we enter
250 * #S_INIT_BLACKLIST and check the blacklist. If the blacklist is OK
251 * with the connection, we actually send the CONNECT message and go to
252 * state S_CONNECT_SENT. Once we receive a CONNECT_ACK, we go to
253 * #S_CONNECTED (and notify everyone about the new connection and send
254 * back a SESSION_ACK). If the operation times out, we go to
255 * #S_DISCONNECT.
256 *
257 * If the session is in trouble (i.e. transport-level disconnect or
258 * timeout), we go to #S_RECONNECT_ATS where we ask ATS for a new
259 * address (we don't notify anyone about the disconnect yet). Once we
260 * have a new address, we go to #S_RECONNECT_BLACKLIST to check the new
261 * address against the blacklist. If the blacklist approves, we enter
262 * #S_RECONNECT_SENT and send a CONNECT message. If we receive a
263 * CONNECT_ACK, we go to #S_CONNECTED and nobody noticed that we had
264 * trouble; we also send a SESSION_ACK at this time just in case. If
265 * the operation times out, we go to S_DISCONNECT (and notify everyone
266 * about the lost connection).
267 *
268 * If ATS decides to switch addresses while we have a normal
269 * connection, we go to #S_CONNECTED_SWITCHING_BLACKLIST to check the
270 * new address against the blacklist. If the blacklist approves, we
271 * go to #S_CONNECTED_SWITCHING_CONNECT_SENT and send a
272 * SESSION_CONNECT. If we get a SESSION_ACK back, we switch the
273 * primary connection to the suggested alternative from ATS, go back
274 * to #S_CONNECTED and send a SESSION_ACK to the other peer just to be
275 * sure. If the operation times out (or the blacklist disapproves),
276 * we go to #S_CONNECTED (and notify ATS that the given alternative
277 * address is "invalid").
278 *
279 * Once a session is in #S_DISCONNECT, it is cleaned up and then goes
280 * to (#S_DISCONNECT_FINISHED). If we receive an explicit disconnect
281 * request, we can go from any state to #S_DISCONNECT, possibly after
282 * generating disconnect notifications.
283 *
284 * Note that it is quite possible that while we are in any of these
285 * states, we could receive a 'CONNECT' request from the other peer.
286 * We then enter a 'weird' state where we pursue our own primary state
287 * machine (as described above), but with the 'send_connect_ack' flag
288 * set to 1. If our state machine allows us to send a 'CONNECT_ACK'
289 * (because we have an acceptable address), we send the 'CONNECT_ACK'
290 * and set the 'send_connect_ack' to 2. If we then receive a
291 * 'SESSION_ACK', we go to #S_CONNECTED (and reset 'send_connect_ack'
292 * to 0).
293 *
294 */
295enum State
296{
297 /**
298 * fresh peer or completely disconnected
299 */
300 S_NOT_CONNECTED = 0,
301
302 /**
303 * Asked to initiate connection, trying to get address from ATS
304 */
305 S_INIT_ATS,
306
307 /**
308 * Asked to initiate connection, trying to get address approved
309 * by blacklist.
310 */
311 S_INIT_BLACKLIST,
312
313 /**
314 * Sent CONNECT message to other peer, waiting for CONNECT_ACK
315 */
316 S_CONNECT_SENT,
317
318 /**
319 * Received a CONNECT, do a blacklist check for inbound address
320 */
321 S_CONNECT_RECV_BLACKLIST_INBOUND,
322
323 /**
324 * Received a CONNECT, asking ATS about address suggestions.
325 */
326 S_CONNECT_RECV_ATS,
327
328 /**
329 * Received CONNECT from other peer, got an address, checking with blacklist.
330 */
331 S_CONNECT_RECV_BLACKLIST,
332
333 /**
334 * CONNECT request from other peer was SESSION_ACK'ed, waiting for
335 * SESSION_ACK.
336 */
337 S_CONNECT_RECV_ACK,
338
339 /**
340 * Got our CONNECT_ACK/SESSION_ACK, connection is up.
341 */
342 S_CONNECTED,
343
344 /**
345 * Connection got into trouble, rest of the system still believes
346 * it to be up, but we're getting a new address from ATS.
347 */
348 S_RECONNECT_ATS,
349
350 /**
351 * Connection got into trouble, rest of the system still believes
352 * it to be up; we are checking the new address against the blacklist.
353 */
354 S_RECONNECT_BLACKLIST,
355
356 /**
357 * Sent CONNECT over new address (either by ATS telling us to switch
358 * addresses or from RECONNECT_ATS); if this fails, we need to tell
359 * the rest of the system about a disconnect.
360 */
361 S_RECONNECT_SENT,
362
363 /**
364 * We have some primary connection, but ATS suggested we switch
365 * to some alternative; we're now checking the alternative against
366 * the blacklist.
367 */
368 S_CONNECTED_SWITCHING_BLACKLIST,
369
370 /**
371 * We have some primary connection, but ATS suggested we switch
372 * to some alternative; we now sent a CONNECT message for the
373 * alternative session to the other peer and waiting for a
374 * CONNECT_ACK to make this our primary connection.
375 */
376 S_CONNECTED_SWITCHING_CONNECT_SENT,
377
378 /**
379 * Disconnect in progress (we're sending the DISCONNECT message to the
380 * other peer; after that is finished, the state will be cleaned up).
381 */
382 S_DISCONNECT,
383
384 /**
385 * We're finished with the disconnect; and are cleaning up the state
386 * now! We put the struct into this state when we are really in the
387 * task that calls 'free' on it and are about to remove the record
388 * from the map. We should never find a 'struct NeighbourMapEntry'
389 * in this state in the map. Accessing a 'struct NeighbourMapEntry'
390 * in this state virtually always means using memory that has been
391 * freed (the exception being the cleanup code in #free_neighbour()).
392 */
393 S_DISCONNECT_FINISHED
394};
395 234
396 235
397/** 236/**
@@ -534,7 +373,7 @@ struct NeighbourMapEntry
534 /** 373 /**
535 * The current state of the peer. 374 * The current state of the peer.
536 */ 375 */
537 enum State state; 376 enum GNUNET_TRANSPORT_PeerState state;
538 377
539 /** 378 /**
540 * Did we sent an KEEP_ALIVE message and are we expecting a response? 379 * Did we sent an KEEP_ALIVE message and are we expecting a response?
@@ -641,7 +480,7 @@ static GNUNET_TRANSPORT_NotifyDisconnect disconnect_notify_cb;
641/** 480/**
642 * Function to call when we changed an active address of a neighbour. 481 * Function to call when we changed an active address of a neighbour.
643 */ 482 */
644static GNUNET_TRANSPORT_PeerIterateCallback address_change_cb; 483static GNUNET_TRANSPORT_AddressChangeCallback address_change_cb;
645 484
646/** 485/**
647 * counter for connected neighbours 486 * counter for connected neighbours
@@ -681,7 +520,7 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
681 * @return corresponding string 520 * @return corresponding string
682 */ 521 */
683static const char * 522static const char *
684print_state (enum State state) 523print_state (enum GNUNET_TRANSPORT_PeerState state)
685{ 524{
686 switch (state) 525 switch (state)
687 { 526 {
@@ -3616,7 +3455,7 @@ void
3616GST_neighbours_start (void *cls, 3455GST_neighbours_start (void *cls,
3617 NotifyConnect connect_cb, 3456 NotifyConnect connect_cb,
3618 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb, 3457 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb,
3619 GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb, 3458 GNUNET_TRANSPORT_AddressChangeCallback peer_address_cb,
3620 unsigned int max_fds) 3459 unsigned int max_fds)
3621{ 3460{
3622 callback_cls = cls; 3461 callback_cls = cls;
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index b5abcf5da..c72b298c5 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -29,6 +29,7 @@
29#include "gnunet_statistics_service.h" 29#include "gnunet_statistics_service.h"
30#include "gnunet_transport_service.h" 30#include "gnunet_transport_service.h"
31#include "gnunet_transport_plugin.h" 31#include "gnunet_transport_plugin.h"
32#include "gnunet-service-transport.h"
32#include "transport.h" 33#include "transport.h"
33#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
34 35
@@ -50,7 +51,7 @@ void
50GST_neighbours_start (void *cls, 51GST_neighbours_start (void *cls,
51 NotifyConnect connect_cb, 52 NotifyConnect connect_cb,
52 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb, 53 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb,
53 GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb, 54 GNUNET_TRANSPORT_AddressChangeCallback peer_address_cb,
54 unsigned int max_fds); 55 unsigned int max_fds);
55 56
56 57
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index aff4d30aa..a6ffb2bab 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19 */
20 20
21/** 21/**
22 * @file src/transport/gnunet-transport.c 22 * @file src/transport/gnunet-transport.c
@@ -48,7 +48,6 @@
48 */ 48 */
49#define BLOCKSIZE 4 49#define BLOCKSIZE 4
50 50
51
52/** 51/**
53 * Which peer should we connect to? 52 * Which peer should we connect to?
54 */ 53 */
@@ -90,6 +89,11 @@ static int benchmark_receive;
90static int iterate_connections; 89static int iterate_connections;
91 90
92/** 91/**
92 * Option -a.
93 */
94static int iterate_all;
95
96/**
93 * Option -t. 97 * Option -t.
94 */ 98 */
95static int test_configuration; 99static int test_configuration;
@@ -147,7 +151,7 @@ static struct GNUNET_TRANSPORT_TransmitHandle *th;
147/** 151/**
148 * 152 *
149 */ 153 */
150struct GNUNET_TRANSPORT_PeerIterateContext *pic; 154struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
151 155
152/** 156/**
153 * Identity of the peer we transmit to / connect to. 157 * Identity of the peer we transmit to / connect to.
@@ -213,7 +217,6 @@ struct TestContext
213 217
214}; 218};
215 219
216
217/** 220/**
218 * Task run in monitor mode when the user presses CTRL-C to abort. 221 * Task run in monitor mode when the user presses CTRL-C to abort.
219 * Stops monitoring activity. 222 * Stops monitoring activity.
@@ -222,54 +225,53 @@ struct TestContext
222 * @param tc scheduler context 225 * @param tc scheduler context
223 */ 226 */
224static void 227static void
225shutdown_task (void *cls, 228shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
226 const struct GNUNET_SCHEDULER_TaskContext *tc)
227{ 229{
228 struct GNUNET_TIME_Relative duration; 230 struct GNUNET_TIME_Relative duration;
229 end = GNUNET_SCHEDULER_NO_TASK; 231 end = GNUNET_SCHEDULER_NO_TASK;
230 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 232 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
231 { 233 {
232 GNUNET_SCHEDULER_cancel (op_timeout); 234 GNUNET_SCHEDULER_cancel (op_timeout);
233 op_timeout = GNUNET_SCHEDULER_NO_TASK; 235 op_timeout = GNUNET_SCHEDULER_NO_TASK;
234 } 236 }
235 if (NULL != tc_handle) 237 if (NULL != tc_handle)
236 { 238 {
237 GNUNET_TRANSPORT_try_connect_cancel (tc_handle); 239 GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
238 tc_handle = NULL; 240 tc_handle = NULL;
239 } 241 }
240 if (NULL != pic) 242 if (NULL != pic)
241 { 243 {
242 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic); 244 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
243 pic = NULL; 245 pic = NULL;
244 } 246 }
245 if (NULL != th) 247 if (NULL != th)
246 { 248 {
247 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 249 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
248 th = NULL; 250 th = NULL;
249 } 251 }
250 if (NULL != handle) 252 if (NULL != handle)
251 { 253 {
252 GNUNET_TRANSPORT_disconnect(handle); 254 GNUNET_TRANSPORT_disconnect (handle);
253 handle = NULL; 255 handle = NULL;
254 } 256 }
255 if (benchmark_send) 257 if (benchmark_send)
256 { 258 {
257 duration = GNUNET_TIME_absolute_get_duration (start_time); 259 duration = GNUNET_TIME_absolute_get_duration (start_time);
258 FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), 260 FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
259 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), traffic_sent, 261 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
260 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 262 traffic_sent,
263 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
261 } 264 }
262 if (benchmark_receive) 265 if (benchmark_receive)
263 { 266 {
264 duration = GNUNET_TIME_absolute_get_duration (start_time); 267 duration = GNUNET_TIME_absolute_get_duration (start_time);
265 FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"), 268 FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"),
266 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 269 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
267 traffic_received, 270 traffic_received,
268 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 271 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
269 } 272 }
270} 273}
271 274
272
273static struct ResolutionContext *rc_head; 275static struct ResolutionContext *rc_head;
274static struct ResolutionContext *rc_tail; 276static struct ResolutionContext *rc_tail;
275 277
@@ -282,50 +284,45 @@ struct ResolutionContext
282 int printed; 284 int printed;
283}; 285};
284 286
285
286static void 287static void
287operation_timeout (void *cls, 288operation_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
288 const struct GNUNET_SCHEDULER_TaskContext *tc)
289{ 289{
290 struct ResolutionContext *cur; 290 struct ResolutionContext *cur;
291 struct ResolutionContext *next; 291 struct ResolutionContext *next;
292 op_timeout = GNUNET_SCHEDULER_NO_TASK; 292 op_timeout = GNUNET_SCHEDULER_NO_TASK;
293 if ((try_connect) || (benchmark_send) || 293 if ((try_connect) || (benchmark_send) || (benchmark_receive))
294 (benchmark_receive))
295 { 294 {
296 FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); 295 FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
297 if (GNUNET_SCHEDULER_NO_TASK != end) 296 if (GNUNET_SCHEDULER_NO_TASK != end)
298 GNUNET_SCHEDULER_cancel (end); 297 GNUNET_SCHEDULER_cancel (end);
299 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 298 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
300 ret = 1; 299 ret = 1;
301 return; 300 return;
302 } 301 }
303 if (iterate_connections) 302 if (iterate_connections)
304 { 303 {
305 next = rc_head; 304 next = rc_head;
306 while (NULL != (cur = next)) 305 while (NULL != (cur = next))
307 { 306 {
308 next = cur->next; 307 next = cur->next;
309 FPRINTF (stdout, _("Failed to resolve address for peer `%s'\n"), 308 FPRINTF (stdout, _("Failed to resolve address for peer `%s'\n"),
310 GNUNET_i2s (&cur->addrcp->peer)); 309 GNUNET_i2s (&cur->addrcp->peer));
311
312 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur);
313 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
314 GNUNET_free (cur->addrcp);
315 GNUNET_free (cur);
316
317 }
318 FPRINTF (stdout, "%s", _("Failed to list connections, timeout occured\n"));
319 if (GNUNET_SCHEDULER_NO_TASK != end)
320 GNUNET_SCHEDULER_cancel (end);
321 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
322 ret = 1;
323 return;
324 }
325 310
326} 311 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur);
312 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
313 GNUNET_free(cur->addrcp);
314 GNUNET_free(cur);
327 315
316 }
317 FPRINTF (stdout, "%s", _("Failed to list connections, timeout occured\n") );
318 if (GNUNET_SCHEDULER_NO_TASK != end)
319 GNUNET_SCHEDULER_cancel (end);
320 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
321 ret = 1;
322 return;
323 }
328 324
325}
329 326
330/** 327/**
331 * Display the result of the test. 328 * Display the result of the test.
@@ -354,17 +351,16 @@ display_test_result (struct TestContext *tc, int result)
354 GNUNET_NAT_test_stop (tc->tst); 351 GNUNET_NAT_test_stop (tc->tst);
355 tc->tst = NULL; 352 tc->tst = NULL;
356 } 353 }
357 GNUNET_free (tc); 354 GNUNET_free(tc);
358 resolver_users--; 355 resolver_users--;
359 if ((0 == resolver_users) && (NULL != resolver)) 356 if ((0 == resolver_users) && (NULL != resolver))
360 { 357 {
361 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, GNUNET_TERM_SIG)); 358 GNUNET_break(0 == GNUNET_OS_process_kill (resolver, GNUNET_TERM_SIG));
362 GNUNET_OS_process_destroy (resolver); 359 GNUNET_OS_process_destroy (resolver);
363 resolver = NULL; 360 resolver = NULL;
364 } 361 }
365} 362}
366 363
367
368/** 364/**
369 * Function called by NAT on success. 365 * Function called by NAT on success.
370 * Clean up and update GUI (with success). 366 * Clean up and update GUI (with success).
@@ -374,16 +370,13 @@ display_test_result (struct TestContext *tc, int result)
374 * @param emsg error message, NULL on success 370 * @param emsg error message, NULL on success
375 */ 371 */
376static void 372static void
377result_callback (void *cls, 373result_callback (void *cls, int success, const char *emsg)
378 int success,
379 const char *emsg)
380{ 374{
381 struct TestContext *tc = cls; 375 struct TestContext *tc = cls;
382 376
383 display_test_result (tc, success); 377 display_test_result (tc, success);
384} 378}
385 379
386
387/** 380/**
388 * Function called if NAT failed to confirm success. 381 * Function called if NAT failed to confirm success.
389 * Clean up and update GUI (with failure). 382 * Clean up and update GUI (with failure).
@@ -400,7 +393,6 @@ fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
400 display_test_result (tstc, GNUNET_NO); 393 display_test_result (tstc, GNUNET_NO);
401} 394}
402 395
403
404/** 396/**
405 * Test our plugin's configuration (NAT traversal, etc.). 397 * Test our plugin's configuration (NAT traversal, etc.).
406 * 398 *
@@ -416,53 +408,47 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
416 struct TestContext *tc; 408 struct TestContext *tc;
417 char *binary; 409 char *binary;
418 410
419 if (GNUNET_OK != 411 if (GNUNET_OK
420 GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins", 412 != GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
421 &plugins)) 413 &plugins))
422 { 414 {
423 FPRINTF (stderr, 415 FPRINTF (stderr, "%s", _
424 "%s", 416 ("No transport plugins configured, peer will never communicate\n") );
425 _
426 ("No transport plugins configured, peer will never communicate\n"));
427 ret = 4; 417 ret = 4;
428 return; 418 return;
429 } 419 }
430 for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " ")) 420 for (tok = strtok (plugins, " "); tok != NULL ; tok = strtok (NULL, " "))
431 { 421 {
432 char section[12 + strlen (tok)]; 422 char section[12 + strlen (tok)];
433 423
434 GNUNET_snprintf (section, sizeof (section), "transport-%s", tok); 424 GNUNET_snprintf (section, sizeof(section), "transport-%s", tok);
435 if (GNUNET_OK != 425 if (GNUNET_OK
436 GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port)) 426 != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT",
427 &bnd_port))
437 { 428 {
438 FPRINTF (stderr, 429 FPRINTF (stderr,
439 _("No port configured for plugin `%s', cannot test it\n"), tok); 430 _("No port configured for plugin `%s', cannot test it\n"), tok);
440 continue; 431 continue;
441 } 432 }
442 if (GNUNET_OK != 433 if (GNUNET_OK
443 GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT", 434 != GNUNET_CONFIGURATION_get_value_number (cfg, section,
444 &adv_port)) 435 "ADVERTISED_PORT", &adv_port))
445 adv_port = bnd_port; 436 adv_port = bnd_port;
446 if (NULL == resolver) 437 if (NULL == resolver)
447 { 438 {
448 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); 439 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
449 resolver = 440 resolver = GNUNET_OS_start_process (GNUNET_YES,
450 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, 441 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary,
451 binary, 442 "gnunet-service-resolver", NULL );
452 "gnunet-service-resolver", NULL); 443 GNUNET_free(binary);
453 GNUNET_free (binary);
454 } 444 }
455 resolver_users++; 445 resolver_users++;
456 GNUNET_RESOLVER_connect (cfg); 446 GNUNET_RESOLVER_connect (cfg);
457 tc = GNUNET_new (struct TestContext); 447 tc = GNUNET_new (struct TestContext);
458 tc->name = GNUNET_strdup (tok); 448 tc->name = GNUNET_strdup (tok);
459 tc->tst = 449 tc->tst = GNUNET_NAT_test_start (cfg,
460 GNUNET_NAT_test_start (cfg, 450 (0 == strcasecmp (tok, "udp")) ? GNUNET_NO : GNUNET_YES,
461 (0 == 451 (uint16_t) bnd_port, (uint16_t) adv_port, &result_callback, tc);
462 strcasecmp (tok,
463 "udp")) ? GNUNET_NO : GNUNET_YES,
464 (uint16_t) bnd_port, (uint16_t) adv_port,
465 &result_callback, tc);
466 if (NULL == tc->tst) 452 if (NULL == tc->tst)
467 { 453 {
468 display_test_result (tc, GNUNET_SYSERR); 454 display_test_result (tc, GNUNET_SYSERR);
@@ -470,10 +456,9 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
470 } 456 }
471 tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc); 457 tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc);
472 } 458 }
473 GNUNET_free (plugins); 459 GNUNET_free(plugins);
474} 460}
475 461
476
477/** 462/**
478 * Function called to notify a client about the socket 463 * Function called to notify a client about the socket
479 * begin ready to queue more data. @a buf will be 464 * begin ready to queue more data. @a buf will be
@@ -496,22 +481,20 @@ transmit_data (void *cls, size_t size, void *buf)
496 return 0; 481 return 0;
497 } 482 }
498 483
499 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 484 GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader));
500 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 485 GNUNET_assert(size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
501 m->size = ntohs (size); 486 m->size = ntohs (size);
502 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); 487 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
503 memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader)); 488 memset (&m[1], 52, size - sizeof(struct GNUNET_MessageHeader));
504 traffic_sent += size; 489 traffic_sent += size;
505 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, BLOCKSIZE * 1024, 0, 490 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, BLOCKSIZE * 1024,
506 GNUNET_TIME_UNIT_FOREVER_REL, 491 0, GNUNET_TIME_UNIT_FOREVER_REL, &transmit_data, NULL );
507 &transmit_data, NULL);
508 if (verbosity > 0) 492 if (verbosity > 0)
509 FPRINTF (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size, 493 FPRINTF (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
510 GNUNET_i2s (&pid)); 494 GNUNET_i2s (&pid));
511 return size; 495 return size;
512} 496}
513 497
514
515/** 498/**
516 * Function called to notify transport users that another 499 * Function called to notify transport users that another
517 * peer connected to us. 500 * peer connected to us.
@@ -522,27 +505,26 @@ transmit_data (void *cls, size_t size, void *buf)
522static void 505static void
523notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 506notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
524{ 507{
525 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 508 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
526 return; 509 return;
527 ret = 0; 510 ret = 0;
528 if (try_connect) 511 if (try_connect)
529 { 512 {
530 /* all done, terminate instantly */ 513 /* all done, terminate instantly */
531 FPRINTF (stdout, 514 FPRINTF (stdout, _("Successfully connected to `%s'\n"),
532 _("Successfully connected to `%s'\n"), 515 GNUNET_i2s_full (peer));
533 GNUNET_i2s_full (peer)); 516 ret = 0;
534 ret = 0;
535 517
536 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 518 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
537 { 519 {
538 GNUNET_SCHEDULER_cancel (op_timeout); 520 GNUNET_SCHEDULER_cancel (op_timeout);
539 op_timeout = GNUNET_SCHEDULER_NO_TASK; 521 op_timeout = GNUNET_SCHEDULER_NO_TASK;
540 } 522 }
541 523
542 if (GNUNET_SCHEDULER_NO_TASK != end) 524 if (GNUNET_SCHEDULER_NO_TASK != end)
543 GNUNET_SCHEDULER_cancel (end); 525 GNUNET_SCHEDULER_cancel (end);
544 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 526 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
545 return; 527 return;
546 } 528 }
547 if (benchmark_send) 529 if (benchmark_send)
548 { 530 {
@@ -552,21 +534,20 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
552 op_timeout = GNUNET_SCHEDULER_NO_TASK; 534 op_timeout = GNUNET_SCHEDULER_NO_TASK;
553 } 535 }
554 if (verbosity > 0) 536 if (verbosity > 0)
555 FPRINTF (stdout, _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), 537 FPRINTF (stdout,
538 _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
556 GNUNET_i2s (&pid), BLOCKSIZE); 539 GNUNET_i2s (&pid), BLOCKSIZE);
557 start_time = GNUNET_TIME_absolute_get (); 540 start_time = GNUNET_TIME_absolute_get ();
558 if (NULL == th) 541 if (NULL == th)
559 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 542 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer,
560 BLOCKSIZE * 1024, 0, 543 BLOCKSIZE * 1024, 0, GNUNET_TIME_UNIT_FOREVER_REL, &transmit_data,
561 GNUNET_TIME_UNIT_FOREVER_REL, 544 NULL );
562 &transmit_data, NULL);
563 else 545 else
564 GNUNET_break (0); 546 GNUNET_break(0);
565 return; 547 return;
566 } 548 }
567} 549}
568 550
569
570/** 551/**
571 * Function called to notify transport users that another 552 * Function called to notify transport users that another
572 * peer disconnected from us. 553 * peer disconnected from us.
@@ -577,7 +558,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
577static void 558static void
578notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 559notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
579{ 560{
580 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 561 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
581 return; 562 return;
582 563
583 if (NULL != th) 564 if (NULL != th)
@@ -587,10 +568,11 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
587 } 568 }
588 if (benchmark_send) 569 if (benchmark_send)
589 { 570 {
590 FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"), GNUNET_i2s (&pid)); 571 FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"),
591 if (GNUNET_SCHEDULER_NO_TASK != end) 572 GNUNET_i2s (&pid));
592 GNUNET_SCHEDULER_cancel (end); 573 if (GNUNET_SCHEDULER_NO_TASK != end)
593 return; 574 GNUNET_SCHEDULER_cancel (end);
575 return;
594 } 576 }
595} 577}
596 578
@@ -604,19 +586,14 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
604static void 586static void
605monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 587monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
606{ 588{
607 monitor_connect_counter ++; 589 monitor_connect_counter++;
608 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 590 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
609 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 591 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
610 592
611 FPRINTF (stdout, 593 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str,
612 _("%24s: %-17s %4s (%u connections in total)\n"), 594 _("Connected to"), GNUNET_i2s (peer), monitor_connect_counter);
613 now_str,
614 _("Connected to"),
615 GNUNET_i2s (peer),
616 monitor_connect_counter);
617} 595}
618 596
619
620/** 597/**
621 * Function called to notify transport users that another 598 * Function called to notify transport users that another
622 * peer disconnected from us. 599 * peer disconnected from us.
@@ -627,22 +604,16 @@ monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
627static void 604static void
628monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 605monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
629{ 606{
630 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 607 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
631 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 608 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
632 609
633 GNUNET_assert (monitor_connect_counter > 0); 610 GNUNET_assert(monitor_connect_counter > 0);
634 monitor_connect_counter --; 611 monitor_connect_counter--;
635 612
636 FPRINTF (stdout, 613 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str,
637 _("%24s: %-17s %4s (%u connections in total)\n"), 614 _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter);
638 now_str,
639 _("Disconnected from"),
640 GNUNET_i2s (peer),
641 monitor_connect_counter);
642} 615}
643 616
644
645
646/** 617/**
647 * Function called by the transport for each received message. 618 * Function called by the transport for each received message.
648 * 619 *
@@ -652,16 +623,15 @@ monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
652 */ 623 */
653static void 624static void
654notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 625notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
655 const struct GNUNET_MessageHeader *message) 626 const struct GNUNET_MessageHeader *message)
656{ 627{
657 if (benchmark_receive) 628 if (benchmark_receive)
658 { 629 {
659 if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type)) 630 if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type))
660 return; 631 return;
661 if (verbosity > 0) 632 if (verbosity > 0)
662 FPRINTF (stdout, 633 FPRINTF (stdout, _("Received %u bytes from %s\n"),
663 _("Received %u bytes from %s\n"), 634 (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
664 (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
665 635
666 if (traffic_received == 0) 636 if (traffic_received == 0)
667 start_time = GNUNET_TIME_absolute_get (); 637 start_time = GNUNET_TIME_absolute_get ();
@@ -670,11 +640,8 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
670 } 640 }
671} 641}
672 642
673
674static void 643static void
675resolve_address (const struct GNUNET_HELLO_Address *address, 644resolve_address (const struct GNUNET_HELLO_Address *address, int numeric);
676 int numeric);
677
678 645
679static void 646static void
680process_string (void *cls, const char *address) 647process_string (void *cls, const char *address)
@@ -682,136 +649,133 @@ process_string (void *cls, const char *address)
682 struct ResolutionContext *rc = cls; 649 struct ResolutionContext *rc = cls;
683 struct GNUNET_HELLO_Address *addrcp = rc->addrcp; 650 struct GNUNET_HELLO_Address *addrcp = rc->addrcp;
684 651
685 if (address != NULL) 652 if (address != NULL )
686 { 653 {
687 FPRINTF (stdout, 654 FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (&addrcp->peer),
688 _("Peer `%s': %s %s\n"), 655 addrcp->transport_name, address);
689 GNUNET_i2s (&addrcp->peer),
690 addrcp->transport_name,
691 address);
692 rc->printed = GNUNET_YES; 656 rc->printed = GNUNET_YES;
693 } 657 }
694 else 658 else
695 { 659 {
696 /* done */ 660 /* done */
697 GNUNET_assert (address_resolutions > 0); 661 GNUNET_assert(address_resolutions > 0);
698 address_resolutions --; 662 address_resolutions--;
699 if (GNUNET_NO == rc->printed) 663 if (GNUNET_NO == rc->printed)
700 { 664 {
701 if (numeric == GNUNET_NO) 665 if (numeric == GNUNET_NO)
702 { 666 {
703 resolve_address (rc->addrcp, GNUNET_YES ); /* Failed to resolve address, try numeric lookup */ 667 resolve_address (rc->addrcp, GNUNET_YES); /* Failed to resolve address, try numeric lookup */
704 } 668 }
705 else 669 else
706 FPRINTF (stdout, 670 FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"),
707 _("Peer `%s': %s <unable to resolve address>\n"), 671 GNUNET_i2s (&addrcp->peer), addrcp->transport_name);
708 GNUNET_i2s (&addrcp->peer),
709 addrcp->transport_name);
710 } 672 }
711 GNUNET_free (rc->addrcp); 673 GNUNET_free(rc->addrcp);
712 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); 674 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc);
713 GNUNET_free (rc); 675 GNUNET_free(rc);
714 if ((0 == address_resolutions) && (iterate_connections)) 676 if ((0 == address_resolutions) && (iterate_connections))
715 { 677 {
716 if (GNUNET_SCHEDULER_NO_TASK != end) 678 if (GNUNET_SCHEDULER_NO_TASK != end)
717 { 679 {
718 GNUNET_SCHEDULER_cancel (end); 680 GNUNET_SCHEDULER_cancel (end);
719 end = GNUNET_SCHEDULER_NO_TASK; 681 end = GNUNET_SCHEDULER_NO_TASK;
720 } 682 }
721 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 683 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
722 { 684 {
723 GNUNET_SCHEDULER_cancel (op_timeout); 685 GNUNET_SCHEDULER_cancel (op_timeout);
724 op_timeout = GNUNET_SCHEDULER_NO_TASK; 686 op_timeout = GNUNET_SCHEDULER_NO_TASK;
725 } 687 }
726 ret = 0; 688 ret = 0;
727 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 689 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
728 } 690 }
729 } 691 }
730} 692}
731 693
732
733static void 694static void
734resolve_address (const struct GNUNET_HELLO_Address *address, 695resolve_address (const struct GNUNET_HELLO_Address *address, int numeric)
735 int numeric)
736{ 696{
737 struct ResolutionContext *rc; 697 struct ResolutionContext *rc;
738 698
739 rc = GNUNET_new (struct ResolutionContext); 699 rc = GNUNET_new (struct ResolutionContext);
740 GNUNET_assert (NULL != rc); 700 GNUNET_assert(NULL != rc);
741 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); 701 GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc);
742 address_resolutions ++; 702 address_resolutions++;
743 703
744 rc->addrcp = GNUNET_HELLO_address_copy(address); 704 rc->addrcp = GNUNET_HELLO_address_copy (address);
745 rc->printed = GNUNET_NO; 705 rc->printed = GNUNET_NO;
746 /* Resolve address to string */ 706 /* Resolve address to string */
747 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, 707 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
748 RESOLUTION_TIMEOUT, &process_string, 708 RESOLUTION_TIMEOUT, &process_string, rc);
749 rc);
750} 709}
751 710
752/** 711/**
753 * Function to call with a binary address 712 * Function called with information about a peers
754 * 713 *
755 * @param cls closure 714 * @param cls closure
756 * @param peer identity of the peer 715 * @param peer identity of the peer, NULL for final callback when operation done
757 * @param address binary address (NULL on disconnect) 716 * @param address binary address used to communicate with this peer,
717 * NULL on disconnect or when done
718 * @param state current state this peer is in
719 * @param state_timeout time out for the current state
720 *
758 */ 721 */
759static void 722static void
760process_address (void *cls, const struct GNUNET_PeerIdentity *peer, 723process_peer_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
761 const struct GNUNET_HELLO_Address *address) 724 const struct GNUNET_HELLO_Address *address,
725 enum GNUNET_TRANSPORT_PeerState state,
726 struct GNUNET_TIME_Absolute state_timeout)
762{ 727{
763 if (peer == NULL) 728 if (peer == NULL )
764 { 729 {
765 /* done */ 730 /* done */
766 address_resolution_in_progress = GNUNET_NO; 731 address_resolution_in_progress = GNUNET_NO;
767 pic = NULL; 732 pic = NULL;
768 if (GNUNET_SCHEDULER_NO_TASK != end) 733 if (GNUNET_SCHEDULER_NO_TASK != end)
769 GNUNET_SCHEDULER_cancel (end); 734 GNUNET_SCHEDULER_cancel (end);
770 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 735 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
771 return; 736 return;
772 } 737 }
773 if (address == NULL) 738 if (address == NULL )
774 { 739 {
775 FPRINTF (stdout, _("Peer `%s' disconnected\n"), GNUNET_i2s (peer)); 740 FPRINTF (stdout, _("Peer `%s' disconnected\n"), GNUNET_i2s (peer));
776 return; 741 return;
777 } 742 }
778 743
779 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 744 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
780 GNUNET_SCHEDULER_cancel (op_timeout); 745 GNUNET_SCHEDULER_cancel (op_timeout);
781 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 746 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
782 &operation_timeout, NULL); 747 NULL );
783 748
784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received address for peer `%s': %s\n", 749 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received address for peer `%s': %s\n",
785 GNUNET_i2s (peer), address->transport_name); 750 GNUNET_i2s (peer), address->transport_name);
786 resolve_address (address, numeric); 751 resolve_address (address, numeric);
787} 752}
788 753
789
790static void 754static void
791try_connect_cb (void *cls, 755try_connect_cb (void *cls, const int result)
792 const int result)
793{ 756{
794 static int retries = 0; 757 static int retries = 0;
795 if (GNUNET_OK == result) 758 if (GNUNET_OK == result)
796 { 759 {
797 tc_handle = NULL; 760 tc_handle = NULL;
798 return; 761 return;
799 } 762 }
800 retries ++; 763 retries++;
801 if (retries < 10) 764 if (retries < 10)
802 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL); 765 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
766 NULL );
803 else 767 else
804 { 768 {
805 FPRINTF (stderr, "%s", _("Failed to send connect request to transport service\n")); 769 FPRINTF (stderr, "%s",
770 _("Failed to send connect request to transport service\n") );
806 if (GNUNET_SCHEDULER_NO_TASK != end) 771 if (GNUNET_SCHEDULER_NO_TASK != end)
807 GNUNET_SCHEDULER_cancel (end); 772 GNUNET_SCHEDULER_cancel (end);
808 ret = 1; 773 ret = 1;
809 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 774 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
810 return; 775 return;
811 } 776 }
812} 777}
813 778
814
815/** 779/**
816 * Function called with the result of the check if the 'transport' 780 * Function called with the result of the check if the 'transport'
817 * service is running. 781 * service is running.
@@ -820,43 +784,43 @@ try_connect_cb (void *cls,
820 * @param result #GNUNET_YES if transport is running 784 * @param result #GNUNET_YES if transport is running
821 */ 785 */
822static void 786static void
823testservice_task (void *cls, 787testservice_task (void *cls, int result)
824 int result)
825{ 788{
826 int counter = 0; 789 int counter = 0;
827 ret = 1; 790 ret = 1;
828 791
829 if (GNUNET_YES != result) 792 if (GNUNET_YES != result)
830 { 793 {
831 FPRINTF (stderr, 794 FPRINTF (stderr, _("Service `%s' is not running\n"), "transport");
832 _("Service `%s' is not running\n"), "transport");
833 return; 795 return;
834 } 796 }
835 797
836 if ( (NULL != cpid) && 798 if ((NULL != cpid)
837 (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, 799 && (GNUNET_OK
838 strlen (cpid), 800 != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, strlen (cpid),
839 &pid.public_key))) 801 &pid.public_key)))
840 { 802 {
841 FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid); 803 FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
842 return; 804 return;
843 } 805 }
844 806
845 counter = benchmark_send + benchmark_receive + iterate_connections + 807 counter = benchmark_send + benchmark_receive + iterate_connections
846 monitor_connections + monitor_connects + try_connect; 808 + monitor_connections + monitor_connects + try_connect;
847 809
848 if (1 < counter) 810 if (1 < counter)
849 { 811 {
850 FPRINTF (stderr, 812 FPRINTF (stderr,
851 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s\n"), 813 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s\n"),
852 "connect", "benchmark send", "benchmark receive", "information", "monitor", "events"); 814 "connect", "benchmark send", "benchmark receive", "information",
815 "monitor", "events");
853 return; 816 return;
854 } 817 }
855 if (0 == counter) 818 if (0 == counter)
856 { 819 {
857 FPRINTF (stderr, 820 FPRINTF (stderr,
858 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s\n"), 821 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s\n"),
859 "connect", "benchmark send", "benchmark receive", "information", "monitor", "events"); 822 "connect", "benchmark send", "benchmark receive", "information",
823 "monitor", "events");
860 return; 824 return;
861 } 825 }
862 826
@@ -864,35 +828,30 @@ testservice_task (void *cls,
864 { 828 {
865 if (NULL == cpid) 829 if (NULL == cpid)
866 { 830 {
867 FPRINTF (stderr, 831 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
868 _("Option `%s' makes no sense without option `%s'.\n"), 832 "-C", "-p");
869 "-C", "-p");
870 ret = 1; 833 ret = 1;
871 return; 834 return;
872 } 835 }
873 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 836 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
874 &notify_receive, 837 &notify_connect, &notify_disconnect);
875 &notify_connect,
876 &notify_disconnect);
877 if (NULL == handle) 838 if (NULL == handle)
878 { 839 {
879 FPRINTF (stderr, 840 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
880 "%s", 841 ret = 1;
881 _("Failed to connect to transport service\n")); 842 return;
882 ret = 1;
883 return;
884 } 843 }
885 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL); 844 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
845 NULL );
886 if (NULL == tc_handle) 846 if (NULL == tc_handle)
887 { 847 {
888 FPRINTF (stderr, 848 FPRINTF (stderr, "%s",
889 "%s", 849 _("Failed to send request to transport service\n") );
890 _("Failed to send request to transport service\n"));
891 ret = 1; 850 ret = 1;
892 return; 851 return;
893 } 852 }
894 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 853 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
895 &operation_timeout, NULL); 854 NULL );
896 855
897 } 856 }
898 else if (benchmark_send) /* -s: Benchmark sending */ 857 else if (benchmark_send) /* -s: Benchmark sending */
@@ -900,76 +859,68 @@ testservice_task (void *cls,
900 if (NULL == cpid) 859 if (NULL == cpid)
901 { 860 {
902 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 861 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
903 "-s", "-p"); 862 "-s", "-p");
904 ret = 1; 863 ret = 1;
905 return; 864 return;
906 } 865 }
907 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 866 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
908 &notify_receive, 867 &notify_connect, &notify_disconnect);
909 &notify_connect,
910 &notify_disconnect);
911 if (NULL == handle) 868 if (NULL == handle)
912 { 869 {
913 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n")); 870 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
914 ret = 1; 871 ret = 1;
915 return; 872 return;
916 } 873 }
917 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL); 874 tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
875 NULL );
918 if (NULL == tc_handle) 876 if (NULL == tc_handle)
919 { 877 {
920 FPRINTF (stderr, "%s", _("Failed to send request to transport service\n")); 878 FPRINTF (stderr, "%s",
921 ret = 1; 879 _("Failed to send request to transport service\n") );
922 return; 880 ret = 1;
881 return;
923 } 882 }
924 start_time = GNUNET_TIME_absolute_get (); 883 start_time = GNUNET_TIME_absolute_get ();
925 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 884 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
926 &operation_timeout, NULL); 885 NULL );
927 } 886 }
928 else if (benchmark_receive) /* -b: Benchmark receiving */ 887 else if (benchmark_receive) /* -b: Benchmark receiving */
929 { 888 {
930 handle = 889 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive, NULL,
931 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive, 890 NULL );
932 NULL, NULL);
933 if (NULL == handle) 891 if (NULL == handle)
934 { 892 {
935 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n")); 893 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
936 ret = 1; 894 ret = 1;
937 return; 895 return;
938 } 896 }
939 if (verbosity > 0) 897 if (verbosity > 0)
940 FPRINTF (stdout, "%s", _("Starting to receive benchmark data\n")); 898 FPRINTF (stdout, "%s", _("Starting to receive benchmark data\n") );
941 start_time = GNUNET_TIME_absolute_get (); 899 start_time = GNUNET_TIME_absolute_get ();
942 900
943 } 901 }
944 else if (iterate_connections) /* -i: List all active addresses once */ 902 else if (iterate_connections) /* -i: List information about peers once */
945 { 903 {
946 address_resolution_in_progress = GNUNET_YES; 904 address_resolution_in_progress = GNUNET_YES;
947 pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, 905 pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid,
948 (NULL == cpid) ? NULL : &pid, 906 GNUNET_YES, TIMEOUT, &process_peer_cb, (void *) cfg);
949 GNUNET_YES, 907 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
950 TIMEOUT, 908 NULL );
951 &process_address, (void *) cfg);
952 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
953 &operation_timeout, NULL);
954 } 909 }
955 else if (monitor_connections) /* -m: List all active addresses continously */ 910 else if (monitor_connections) /* -m: List information about peers continuously */
956 { 911 {
957 address_resolution_in_progress = GNUNET_YES; 912 address_resolution_in_progress = GNUNET_YES;
958 pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, 913 pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid,
959 (NULL == cpid) ? NULL : &pid, 914 GNUNET_NO, TIMEOUT, &process_peer_cb, (void *) cfg);
960 GNUNET_NO,
961 TIMEOUT,
962 &process_address, (void *) cfg);
963 } 915 }
964 else if (monitor_connects) /* -e : Monitor (dis)connect events continously */ 916 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
965 { 917 {
966 monitor_connect_counter = 0; 918 monitor_connect_counter = 0;
967 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, 919 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
968 &monitor_notify_connect, 920 &monitor_notify_connect, &monitor_notify_disconnect);
969 &monitor_notify_disconnect);
970 if (NULL == handle) 921 if (NULL == handle)
971 { 922 {
972 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n")); 923 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
973 ret = 1; 924 ret = 1;
974 return; 925 return;
975 } 926 }
@@ -977,17 +928,15 @@ testservice_task (void *cls,
977 } 928 }
978 else 929 else
979 { 930 {
980 GNUNET_break (0); 931 GNUNET_break(0);
981 return; 932 return;
982 } 933 }
983 934
984 end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 935 end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
985 &shutdown_task, 936 &shutdown_task, NULL );
986 NULL);
987 937
988} 938}
989 939
990
991/** 940/**
992 * Main function that will be run by the scheduler. 941 * Main function that will be run by the scheduler.
993 * 942 *
@@ -997,8 +946,8 @@ testservice_task (void *cls,
997 * @param mycfg configuration 946 * @param mycfg configuration
998 */ 947 */
999static void 948static void
1000run (void *cls, char *const *args, const char *cfgfile, 949run (void *cls, char * const *args, const char *cfgfile,
1001 const struct GNUNET_CONFIGURATION_Handle *mycfg) 950 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1002{ 951{
1003 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 952 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1004 if (test_configuration) 953 if (test_configuration)
@@ -1006,62 +955,54 @@ run (void *cls, char *const *args, const char *cfgfile,
1006 do_test_configuration (cfg); 955 do_test_configuration (cfg);
1007 return; 956 return;
1008 } 957 }
1009 GNUNET_CLIENT_service_test ("transport", cfg, 958 GNUNET_CLIENT_service_test ("transport", cfg, GNUNET_TIME_UNIT_SECONDS,
1010 GNUNET_TIME_UNIT_SECONDS, 959 &testservice_task, (void *) cfg);
1011 &testservice_task,
1012 (void *) cfg);
1013} 960}
1014 961
1015
1016int 962int
1017main (int argc, char *const *argv) 963main (int argc, char * const *argv)
1018{ 964{
1019 int res; 965 int res;
1020 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 966 static const struct GNUNET_GETOPT_CommandLineOption options[] =
1021 {'b', "benchmark", NULL, 967 {
1022 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"), 968 { 'a', "all", NULL,
1023 0, &GNUNET_GETOPT_set_one, &benchmark_receive}, 969 gettext_noop ("print information for all peers (instead of only connected peers )"),
1024 {'C', "connect", NULL, 970 0, &GNUNET_GETOPT_set_one, &iterate_all },
1025 gettext_noop ("connect to a peer"), 971 { 'b', "benchmark", NULL,
1026 0, &GNUNET_GETOPT_set_one, &try_connect}, 972 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1027 {'i', "information", NULL, 973 0, &GNUNET_GETOPT_set_one, &benchmark_receive }, { 'C', "connect",
1028 gettext_noop ("provide information about all current connections (once)"), 974 NULL, gettext_noop ("connect to a peer"), 0,
1029 0, &GNUNET_GETOPT_set_one, &iterate_connections}, 975 &GNUNET_GETOPT_set_one, &try_connect },
1030 {'m', "monitor", NULL, 976 { 'i', "information", NULL,
1031 gettext_noop ("provide information about all current connections (continuously)"), 977 gettext_noop ("provide information about all current connections (once)"),
1032 0, &GNUNET_GETOPT_set_one, &monitor_connections}, 978 0, &GNUNET_GETOPT_set_one, &iterate_connections },
1033 {'e', "events", NULL, 979 { 'm', "monitor", NULL,
1034 gettext_noop ("provide information about all connects and disconnect events (continuously)"), 980 gettext_noop ("provide information about all current connections (continuously)"),
1035 0, &GNUNET_GETOPT_set_one, &monitor_connects}, 981 0, &GNUNET_GETOPT_set_one, &monitor_connections },
1036 {'n', "numeric", NULL, 982 { 'e', "events", NULL,
1037 gettext_noop ("do not resolve hostnames"), 983 gettext_noop ("provide information about all connects and disconnect events (continuously)"),
1038 0, &GNUNET_GETOPT_set_one, &numeric}, 984 0, &GNUNET_GETOPT_set_one, &monitor_connects }, { 'n', "numeric",
1039 {'p', "peer", "PEER", 985 NULL, gettext_noop ("do not resolve hostnames"), 0,
1040 gettext_noop ("peer identity"), 986 &GNUNET_GETOPT_set_one, &numeric }, { 'p', "peer", "PEER",
1041 1, &GNUNET_GETOPT_set_string, &cpid}, 987 gettext_noop ("peer identity"), 1, &GNUNET_GETOPT_set_string,
1042 {'s', "send", NULL, 988 &cpid }, { 's', "send", NULL, gettext_noop
1043 gettext_noop 989 ("send data for benchmarking to the other peer (until CTRL-C)"), 0,
1044 ("send data for benchmarking to the other peer (until CTRL-C)"), 990 &GNUNET_GETOPT_set_one, &benchmark_send },
1045 0, &GNUNET_GETOPT_set_one, &benchmark_send}, 991 { 't', "test", NULL,
1046 {'t', "test", NULL, 992 gettext_noop ("test transport configuration (involves external server)"),
1047 gettext_noop ("test transport configuration (involves external server)"), 993 0, &GNUNET_GETOPT_set_one, &test_configuration },
1048 0, &GNUNET_GETOPT_set_one, &test_configuration}, 994 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
1049 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), 995 GNUNET_GETOPT_OPTION_END };
1050 GNUNET_GETOPT_OPTION_END
1051 };
1052 996
1053 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 997 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1054 return 2; 998 return 2;
1055 999
1056 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", 1000 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", gettext_noop
1057 gettext_noop 1001 ("Direct access to transport service."), options, &run, NULL );
1058 ("Direct access to transport service."), options, 1002 GNUNET_free((void * ) argv);
1059 &run, NULL);
1060 GNUNET_free ((void *) argv);
1061 if (GNUNET_OK == res) 1003 if (GNUNET_OK == res)
1062 return ret; 1004 return ret;
1063 return 1; 1005 return 1;
1064} 1006}
1065 1007
1066
1067/* end of gnunet-transport.c */ 1008/* end of gnunet-transport.c */
diff --git a/src/transport/transport.h b/src/transport/transport.h
index f1376f5a7..75cdd729c 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -341,11 +341,12 @@ struct AddressLookupMessage
341}; 341};
342 342
343 343
344#if 0
344/** 345/**
345 * Message from the library to the transport service 346 * Message from the library to the transport service
346 * asking for human readable addresses known for a peer. 347 * asking for human readable addresses known for a peer.
347 */ 348 */
348struct PeerAddressLookupMessage 349struct PeerLookupMessage
349{ 350{
350 /** 351 /**
351 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP 352 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP
@@ -367,13 +368,14 @@ struct PeerAddressLookupMessage
367 */ 368 */
368 struct GNUNET_PeerIdentity peer; 369 struct GNUNET_PeerIdentity peer;
369}; 370};
371#endif
370 372
371 373
372/** 374/**
373 * Message from the library to the transport service 375 * Message from the library to the transport service
374 * asking for binary addresses known for a peer. 376 * asking for binary addresses known for a peer.
375 */ 377 */
376struct AddressIterateMessage 378struct PeerIterateMessage
377{ 379{
378 /** 380 /**
379 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE 381 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE
@@ -427,15 +429,19 @@ struct TrafficMetricMessage
427 429
428 430
429/** 431/**
430 * Message from the transport service to the library 432 * Message from the transport service to the library containing information
431 * containing binary addresses known for a peer. 433 * about a peer. Information contained are:
434 * - current address used to communicate with this peer
435 * - state
436 * - state timeout
437 *
432 * Memory layout: 438 * Memory layout:
433 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] 439 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
434 */ 440 */
435struct AddressIterateResponseMessage 441struct PeerIterateResponseMessage
436{ 442{
437 /** 443 /**
438 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE 444 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE
439 */ 445 */
440 struct GNUNET_MessageHeader header; 446 struct GNUNET_MessageHeader header;
441 447
@@ -444,18 +450,28 @@ struct AddressIterateResponseMessage
444 */ 450 */
445 uint32_t reserved; 451 uint32_t reserved;
446 452
447 /** 453 /**
448 * Peer identity 454 * Peer identity
449 */ 455 */
450 struct GNUNET_PeerIdentity peer; 456 struct GNUNET_PeerIdentity peer;
451 457
452 /** 458 /**
453 * address length 459 * Timeout for the state this peer is in
460 */
461 struct GNUNET_TIME_AbsoluteNBO state_timeout;
462
463 /**
464 * State this peer is in as #GNUNET_TRANSPORT_PeerState enumeration element
465 */
466 uint32_t state GNUNET_PACKED;
467
468 /**
469 * Address length
454 */ 470 */
455 uint32_t addrlen GNUNET_PACKED; 471 uint32_t addrlen GNUNET_PACKED;
456 472
457 /** 473 /**
458 * length of the plugin name 474 * Length of the plugin name
459 */ 475 */
460 uint32_t pluginlen GNUNET_PACKED; 476 uint32_t pluginlen GNUNET_PACKED;
461 477
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_monitoring.c
index d547b8ed8..d7bc56e09 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_monitoring.c
@@ -19,14 +19,15 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file transport/transport_api_address_lookup.c 22 * @file transport/transport_api_montoring.c
23 * @brief given a peer id, get all known addresses from transport service 23 * @brief montoring api for transport peer status and validation entries
24 * 24 *
25 * This api provides the ability to query the transport service about 25 * This api provides the ability to query the transport service about
26 * the status of connections to a specific peer. Calls back with a 26 * the status of a specific or all peers as well as address validation entries.
27 * pretty printed string of the address, as formatted by the appropriate 27 *
28 * transport plugin, and whether or not the address given is currently 28 * Calls back with information about peer(s) including address used, state and
29 * in the 'connected' state (according to the transport service). 29 * state timeout for peer requests and address, address lifetime and next revalidation
30 * for validation entries.
30 */ 31 */
31#include "platform.h" 32#include "platform.h"
32#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
@@ -37,9 +38,9 @@
37#include "transport.h" 38#include "transport.h"
38 39
39/** 40/**
40 * Context for the address lookup. 41 * Context for iterating validation entries.
41 */ 42 */
42struct GNUNET_TRANSPORT_PeerIterateContext 43struct GNUNET_TRANSPORT_PeerMonitoringContext
43{ 44{
44 /** 45 /**
45 * Function to call with the binary address. 46 * Function to call with the binary address.
@@ -89,6 +90,59 @@ struct GNUNET_TRANSPORT_PeerIterateContext
89 90
90 91
91/** 92/**
93 * Context for the address lookup.
94 */
95struct GNUNET_TRANSPORT_ValidationMonitoringContext
96{
97 /**
98 * Function to call with the binary address.
99 */
100 GNUNET_TRANSPORT_ValidationIterateCallback cb;
101
102 /**
103 * Closure for cb.
104 */
105 void *cb_cls;
106
107 /**
108 * Connection to the service.
109 */
110 struct GNUNET_CLIENT_Connection *client;
111
112 /**
113 * Configuration we use.
114 */
115 const struct GNUNET_CONFIGURATION_Handle *cfg;
116
117 /**
118 * When should this operation time out?
119 */
120 struct GNUNET_TIME_Absolute timeout;
121
122 /**
123 * Backoff for reconnect.
124 */
125 struct GNUNET_TIME_Relative backoff;
126
127 /**
128 * Task ID for reconnect.
129 */
130 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
131
132 /**
133 * Identity of the peer to monitor.
134 */
135 struct GNUNET_PeerIdentity peer;
136
137 /**
138 * Was this a one-shot request?
139 */
140 int one_shot;
141};
142
143
144
145/**
92 * Function called with responses from the service. 146 * Function called with responses from the service.
93 * 147 *
94 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*' 148 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
@@ -106,11 +160,11 @@ peer_address_response_processor (void *cls,
106 * @param pal_ctx our context 160 * @param pal_ctx our context
107 */ 161 */
108static void 162static void
109send_request (struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx) 163send_request (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
110{ 164{
111 struct AddressIterateMessage msg; 165 struct PeerIterateMessage msg;
112 166
113 msg.header.size = htons (sizeof (struct AddressIterateMessage)); 167 msg.header.size = htons (sizeof (struct PeerIterateMessage));
114 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); 168 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE);
115 msg.one_shot = htonl (pal_ctx->one_shot); 169 msg.one_shot = htonl (pal_ctx->one_shot);
116 msg.timeout = GNUNET_TIME_absolute_hton (pal_ctx->timeout); 170 msg.timeout = GNUNET_TIME_absolute_hton (pal_ctx->timeout);
@@ -134,7 +188,7 @@ static void
134do_connect (void *cls, 188do_connect (void *cls,
135 const struct GNUNET_SCHEDULER_TaskContext *tc) 189 const struct GNUNET_SCHEDULER_TaskContext *tc)
136{ 190{
137 struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls; 191 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
138 192
139 pal_ctx->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 193 pal_ctx->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
140 pal_ctx->client = GNUNET_CLIENT_connect ("transport", pal_ctx->cfg); 194 pal_ctx->client = GNUNET_CLIENT_connect ("transport", pal_ctx->cfg);
@@ -149,7 +203,7 @@ do_connect (void *cls,
149 * @param pal_ctx our context 203 * @param pal_ctx our context
150 */ 204 */
151static void 205static void
152reconnect (struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx) 206reconnect (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
153{ 207{
154 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot); 208 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
155 GNUNET_CLIENT_disconnect (pal_ctx->client); 209 GNUNET_CLIENT_disconnect (pal_ctx->client);
@@ -172,8 +226,8 @@ static void
172peer_address_response_processor (void *cls, 226peer_address_response_processor (void *cls,
173 const struct GNUNET_MessageHeader *msg) 227 const struct GNUNET_MessageHeader *msg)
174{ 228{
175 struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls; 229 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
176 struct AddressIterateResponseMessage *air_msg; 230 struct PeerIterateResponseMessage *air_msg;
177 struct GNUNET_HELLO_Address *address; 231 struct GNUNET_HELLO_Address *address;
178 const char *addr; 232 const char *addr;
179 const char *transport_name; 233 const char *transport_name;
@@ -185,8 +239,9 @@ peer_address_response_processor (void *cls,
185 { 239 {
186 if (pal_ctx->one_shot) 240 if (pal_ctx->one_shot)
187 { 241 {
188 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); 242 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
189 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); 243 S_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
244 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
190 } 245 }
191 else 246 else
192 { 247 {
@@ -202,8 +257,9 @@ peer_address_response_processor (void *cls,
202 /* done! */ 257 /* done! */
203 if (pal_ctx->one_shot) 258 if (pal_ctx->one_shot)
204 { 259 {
205 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); 260 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
206 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); 261 S_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
262 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
207 } 263 }
208 else 264 else
209 { 265 {
@@ -212,15 +268,16 @@ peer_address_response_processor (void *cls,
212 return; 268 return;
213 } 269 }
214 270
215 if ((size < sizeof (struct AddressIterateResponseMessage)) || 271 if ((size < sizeof (struct PeerIterateResponseMessage)) ||
216 (ntohs (msg->type) != 272 (ntohs (msg->type) !=
217 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE)) 273 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE))
218 { 274 {
219 GNUNET_break (0); 275 GNUNET_break (0);
220 if (pal_ctx->one_shot) 276 if (pal_ctx->one_shot)
221 { 277 {
222 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); 278 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
223 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); 279 S_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
280 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
224 } 281 }
225 else 282 else
226 { 283 {
@@ -229,17 +286,18 @@ peer_address_response_processor (void *cls,
229 return; 286 return;
230 } 287 }
231 288
232 air_msg = (struct AddressIterateResponseMessage *) msg; 289 air_msg = (struct PeerIterateResponseMessage *) msg;
233 tlen = ntohl (air_msg->pluginlen); 290 tlen = ntohl (air_msg->pluginlen);
234 alen = ntohl (air_msg->addrlen); 291 alen = ntohl (air_msg->addrlen);
235 292
236 if (size != sizeof (struct AddressIterateResponseMessage) + tlen + alen) 293 if (size != sizeof (struct PeerIterateResponseMessage) + tlen + alen)
237 { 294 {
238 GNUNET_break (0); 295 GNUNET_break (0);
239 if (pal_ctx->one_shot) 296 if (pal_ctx->one_shot)
240 { 297 {
241 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); 298 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
242 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); 299 S_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
300 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
243 } 301 }
244 else 302 else
245 { 303 {
@@ -250,7 +308,8 @@ peer_address_response_processor (void *cls,
250 308
251 if (alen == 0 && tlen == 0) 309 if (alen == 0 && tlen == 0)
252 { 310 {
253 pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, NULL); 311 pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, NULL,
312 S_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
254 } 313 }
255 else 314 else
256 { 315 {
@@ -262,8 +321,9 @@ peer_address_response_processor (void *cls,
262 GNUNET_break (0); 321 GNUNET_break (0);
263 if (pal_ctx->one_shot) 322 if (pal_ctx->one_shot)
264 { 323 {
265 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); 324 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
266 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); 325 S_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
326 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
267 } 327 }
268 else 328 else
269 { 329 {
@@ -273,10 +333,11 @@ peer_address_response_processor (void *cls,
273 } 333 }
274 334
275 /* notify client */ 335 /* notify client */
276 address = 336 address = GNUNET_HELLO_address_allocate (&air_msg->peer,
277 GNUNET_HELLO_address_allocate (&air_msg->peer, transport_name, addr, 337 transport_name, addr, alen);
278 alen); 338 pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, address,
279 pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, address); 339 ntohl(air_msg->state),
340 GNUNET_TIME_absolute_ntoh (air_msg->state_timeout));
280 GNUNET_HELLO_address_free (address); 341 GNUNET_HELLO_address_free (address);
281 } 342 }
282 343
@@ -304,17 +365,15 @@ peer_address_response_processor (void *cls,
304 * @param peer_address_callback function to call with the results 365 * @param peer_address_callback function to call with the results
305 * @param peer_address_callback_cls closure for peer_address_callback 366 * @param peer_address_callback_cls closure for peer_address_callback
306 */ 367 */
307struct GNUNET_TRANSPORT_PeerIterateContext * 368struct GNUNET_TRANSPORT_PeerMonitoringContext *
308GNUNET_TRANSPORT_peer_get_active_addresses (const struct 369GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
309 GNUNET_CONFIGURATION_Handle *cfg, 370 const struct GNUNET_PeerIdentity *peer,
310 const struct GNUNET_PeerIdentity 371 int one_shot,
311 *peer, int one_shot, 372 struct GNUNET_TIME_Relative timeout,
312 struct GNUNET_TIME_Relative timeout, 373 GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback,
313 GNUNET_TRANSPORT_PeerIterateCallback 374 void *peer_address_callback_cls)
314 peer_address_callback,
315 void *peer_address_callback_cls)
316{ 375{
317 struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx; 376 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx;
318 struct GNUNET_CLIENT_Connection *client; 377 struct GNUNET_CLIENT_Connection *client;
319 378
320 client = GNUNET_CLIENT_connect ("transport", cfg); 379 client = GNUNET_CLIENT_connect ("transport", cfg);
@@ -322,7 +381,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct
322 return NULL; 381 return NULL;
323 if (GNUNET_YES != one_shot) 382 if (GNUNET_YES != one_shot)
324 timeout = GNUNET_TIME_UNIT_FOREVER_REL; 383 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
325 pal_ctx = GNUNET_new (struct GNUNET_TRANSPORT_PeerIterateContext); 384 pal_ctx = GNUNET_new (struct GNUNET_TRANSPORT_PeerMonitoringContext);
326 pal_ctx->cb = peer_address_callback; 385 pal_ctx->cb = peer_address_callback;
327 pal_ctx->cb_cls = peer_address_callback_cls; 386 pal_ctx->cb_cls = peer_address_callback_cls;
328 pal_ctx->cfg = cfg; 387 pal_ctx->cfg = cfg;
@@ -343,9 +402,8 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct
343 * @param alc handle for the request to cancel 402 * @param alc handle for the request to cancel
344 */ 403 */
345void 404void
346GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct 405GNUNET_TRANSPORT_monitor_peers_cancel (
347 GNUNET_TRANSPORT_PeerIterateContext 406 struct GNUNET_TRANSPORT_PeerMonitoringContext *alc)
348 *alc)
349{ 407{
350 if (NULL != alc->client) 408 if (NULL != alc->client)
351 { 409 {
@@ -361,4 +419,42 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
361} 419}
362 420
363 421
364/* end of transport_api_peer_address_lookup.c */ 422/**
423 * Return information about a peer's or all current pending validation operations
424 *
425 * @param cfg configuration to use
426 * @param peer a specific peer identity to obtain validation entries for,
427 * NULL for all peers
428 * @param one_shot GNUNET_YES to return all entries and then end (with NULL+NULL),
429 * GNUNET_NO to monitor validation entries continuously
430 * @param timeout how long is the lookup allowed to take at most
431 * @param peer_address_callback function to call with the results
432 * @param peer_address_callback_cls closure for peer_address_callback
433 */
434struct GNUNET_TRANSPORT_ValidationMonitoringContext *
435GNUNET_TRANSPORT_monitor_validation_entries (const struct
436 GNUNET_CONFIGURATION_Handle *cfg,
437 const struct GNUNET_PeerIdentity *peer,
438 int one_shot,
439 struct GNUNET_TIME_Relative timeout,
440 GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
441 void *validation_callback_cls)
442{
443 /* Not implemented */
444 return NULL;
445}
446
447
448/**
449 * Return information about all current pending validation operations
450 *
451 * @param vic handle for the request to cancel
452 */
453void
454GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic)
455{
456 /* Not implemented */
457}
458
459
460/* end of transport_api_montoring.c */