[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31829 - in gnunet/src: include transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31829 - in gnunet/src: include transport |
Date: |
Wed, 8 Jan 2014 11:50:27 +0100 |
Author: wachs
Date: 2014-01-08 11:50:27 +0100 (Wed, 08 Jan 2014)
New Revision: 31829
Modified:
gnunet/src/include/gnunet_protocols.h
gnunet/src/include/gnunet_transport_service.h
gnunet/src/transport/Makefile.am
gnunet/src/transport/gnunet-service-transport_clients.c
gnunet/src/transport/gnunet-service-transport_neighbours.c
gnunet/src/transport/gnunet-service-transport_neighbours.h
gnunet/src/transport/transport.h
gnunet/src/transport/transport_api_monitoring.c
Log:
implementing monitoring api
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2014-01-08 10:47:06 UTC (rev
31828)
+++ gnunet/src/include/gnunet_protocols.h 2014-01-08 10:50:27 UTC (rev
31829)
@@ -1278,7 +1278,7 @@
/**
* Request to monitor addresses used by a peer or all peers.
*/
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE 380
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST 380
/**
* Message send by a peer to notify the other to keep the session alive
@@ -1287,16 +1287,16 @@
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE 381
/**
- * Response to a GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE message to
+ * Response to a #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE message to
* measure latency in a regular interval
*/
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE 382
-
/**
- * Request to iterate over all known addresses.
+ * Response to #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
+ * request to iterate over all known addresses.
*/
-#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE 383
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE 383
/**
* Message send by a peer to notify the other to keep the session alive.
@@ -1308,8 +1308,19 @@
*/
#define GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 385
+/**
+ * Request to monitor address validations by a peer or all peers.
+ */
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST 386
+/**
+ * Response to #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
+ * request to iterate over all known addresses.
+ */
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE 387
+
+
/*******************************************************************************
* FS-PUBLISH-HELPER IPC Messages
******************************************************************************/
Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h 2014-01-08 10:47:06 UTC
(rev 31828)
+++ gnunet/src/include/gnunet_transport_service.h 2014-01-08 10:50:27 UTC
(rev 31829)
@@ -587,8 +587,25 @@
GNUNET_TRANSPORT_AddressToStringContext
*pic);
+/**
+ * Convert a transport state to a human readable string.
+ *
+ * @param alc handle for the request to cancel
+ */
+const char *
+GNUNET_TRANSPORT_p2s (enum GNUNET_TRANSPORT_PeerState state);
+
/**
+ * Check if a state is defined as connected
+ *
+ * @param state the state value
+ * @return GNUNET_YES or GNUNET_NO
+ */
+int
+GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
+
+/**
* Return information about a specific peer or all peers currently known to
* transport service once or in monitoring mode. To obtain information about
* a specific peer, a peer identity can be passed. To obtain information about
Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am 2014-01-08 10:47:06 UTC (rev 31828)
+++ gnunet/src/transport/Makefile.am 2014-01-08 10:50:27 UTC (rev 31829)
@@ -210,6 +210,7 @@
gnunet-service-transport_validation.h gnunet-service-transport_validation.c \
gnunet-service-transport_manipulation.h
gnunet-service-transport_manipulation.c
gnunet_service_transport_LDADD = \
+ $(top_builddir)/src/transport/libgnunettransport.la \
$(top_builddir)/src/ats/libgnunetats.la \
$(top_builddir)/src/hello/libgnunethello.la \
$(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c 2014-01-08
10:47:06 UTC (rev 31828)
+++ gnunet/src/transport/gnunet-service-transport_clients.c 2014-01-08
10:50:27 UTC (rev 31829)
@@ -468,16 +468,21 @@
*/
static void
notify_client_about_neighbour (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO
bandwidth_out)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute state_timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
{
struct TransportClient *tc = cls;
struct ConnectInfoMessage *cim;
size_t size = sizeof (struct ConnectInfoMessage);
char buf[size] GNUNET_ALIGN;
+ if (GNUNET_NO == GST_neighbours_test_connected (peer))
+ return;
+
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
cim = (struct ConnectInfoMessage *) buf;
cim->header.size = htons (size);
@@ -873,7 +878,7 @@
msg = GNUNET_malloc (size);
msg->header.size = htons (size);
msg->header.type =
- htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
+ htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
msg->reserved = htonl (0);
msg->peer = *peer;
msg->addrlen = htonl (alen);
@@ -888,33 +893,55 @@
}
+struct PeerIterationContext
+{
+ struct GNUNET_SERVER_TransmitContext *tc;
+
+ struct GNUNET_PeerIdentity id;
+
+ int all;
+};
+
/**
- * Output the active address of connected neighbours to the given client.
+ * Output information of neighbours to the given client.
*
- * @param cls the 'struct GNUNET_SERVER_TransmitContext' for transmission to
the client
+ * @param cls the 'struct PeerIterationContext'
* @param peer identity of the neighbour
* @param address the address
* @param bandwidth_in inbound quota in NBO
* @param bandwidth_out outbound quota in NBO
*/
static void
-output_address (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
+send_peer_information (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Address *address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute state_timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
{
- struct GNUNET_SERVER_TransmitContext *tc = cls;
+ struct PeerIterationContext *pc = cls;
struct PeerIterateResponseMessage *msg;
- msg = compose_address_iterate_response_message (peer, address);
- GNUNET_SERVER_transmit_context_append_message (tc, &msg->header);
- GNUNET_free (msg);
+ if ( (GNUNET_YES == pc->all) ||
+ (0 == memcmp (peer, &pc->id, sizeof (pc->id))) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending information about `%s' using address `%s' in state `%s'\n",
+ GNUNET_i2s(peer), address);
+ msg = compose_address_iterate_response_message (peer, address);
+ msg->state = htonl (state);
+ msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
+ GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header);
+ GNUNET_free (msg);
+ }
}
+
+
/**
- * Client asked to obtain information about all actively used addresses
- * of connected peers
+ * Client asked to obtain information about a specific or all peers
* Process the request.
*
* @param cls unused
@@ -922,27 +949,27 @@
* @param message the peer address information request
*/
static void
-clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
+clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
static struct GNUNET_PeerIdentity all_zeros;
struct GNUNET_SERVER_TransmitContext *tc;
- struct PeerIterateMessage *msg;
- struct GNUNET_HELLO_Address *address;
+ struct PeerMonitorMessage *msg;
+ struct PeerIterationContext pc;
- if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
+ if (ntohs (message->type) !=
GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- if (ntohs (message->size) != sizeof (struct PeerIterateMessage))
+ if (ntohs (message->size) != sizeof (struct PeerMonitorMessage))
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- msg = (struct PeerIterateMessage *) message;
+ msg = (struct PeerMonitorMessage *) message;
if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
(NULL != lookup_monitoring_client (client)) )
{
@@ -954,26 +981,33 @@
return;
}
GNUNET_SERVER_disable_receive_done_warning (client);
- tc = GNUNET_SERVER_transmit_context_create (client);
+ pc.tc = tc = GNUNET_SERVER_transmit_context_create (client);
+
+ /* Send initial list */
if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct
GNUNET_PeerIdentity)))
{
/* iterate over all neighbours */
- GST_neighbours_iterate (&output_address, tc);
+ pc.all = GNUNET_YES;
+ pc.id = msg->peer;
}
else
{
/* just return one neighbour */
- address = GST_neighbour_get_current_address (&msg->peer);
- if (address != NULL)
- output_address (tc, &msg->peer, address,
- GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
- GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT);
+ pc.all = GNUNET_NO;
+ pc.id = msg->peer;
}
+ GST_neighbours_iterate (&send_peer_information, &pc);
+
if (GNUNET_YES != ntohl (msg->one_shot))
+ {
setup_monitoring_client (client, &msg->peer);
+ }
else
+ {
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
+ }
+
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -998,9 +1032,9 @@
sizeof (struct TransportRequestConnectMessage)},
{&clients_handle_address_to_string, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
- {&clients_handle_address_iterate, NULL,
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
- sizeof (struct PeerIterateMessage)},
+ {&clients_handle_monitor_peers, NULL,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
+ sizeof (struct PeerMonitorMessage)},
{&GST_blacklist_handle_init, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
sizeof (struct GNUNET_MessageHeader)},
Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c 2014-01-08
10:47:06 UTC (rev 31828)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c 2014-01-08
10:50:27 UTC (rev 31829)
@@ -514,55 +514,6 @@
/**
- * Convert state to human-readable string.
- *
- * @param state the state value
- * @return corresponding string
- */
-static const char *
-print_state (enum GNUNET_TRANSPORT_PeerState state)
-{
- switch (state)
- {
- case S_NOT_CONNECTED:
- return "S_NOT_CONNECTED";
- case S_INIT_ATS:
- return "S_INIT_ATS";
- case S_INIT_BLACKLIST:
- return "S_INIT_BLACKLIST";
- case S_CONNECT_SENT:
- return "S_CONNECT_SENT";
- case S_CONNECT_RECV_BLACKLIST_INBOUND:
- return "S_CONNECT_RECV_BLACKLIST_INBOUND";
- case S_CONNECT_RECV_ATS:
- return "S_CONNECT_RECV_ATS";
- case S_CONNECT_RECV_BLACKLIST:
- return "S_CONNECT_RECV_BLACKLIST";
- case S_CONNECT_RECV_ACK:
- return "S_CONNECT_RECV_ACK";
- case S_CONNECTED:
- return "S_CONNECTED";
- case S_RECONNECT_ATS:
- return "S_RECONNECT_ATS";
- case S_RECONNECT_BLACKLIST:
- return "S_RECONNECT_BLACKLIST";
- case S_RECONNECT_SENT:
- return "S_RECONNECT_SENT";
- case S_CONNECTED_SWITCHING_BLACKLIST:
- return "S_CONNECTED_SWITCHING_BLACKLIST";
- case S_CONNECTED_SWITCHING_CONNECT_SENT:
- return "S_CONNECTED_SWITCHING_CONNECT_SENT";
- case S_DISCONNECT:
- return "S_DISCONNECT";
- case S_DISCONNECT_FINISHED:
- return "S_DISCONNECT_FINISHED";
- default:
- GNUNET_break (0);
- return "UNDEFINED";
- }
-}
-
-/**
* Test if we're connected to the given peer.
*
* @param n neighbour entry of peer to test
@@ -573,35 +524,7 @@
{
if (NULL == n)
return GNUNET_NO;
- switch (n->state)
- {
- case S_NOT_CONNECTED:
- case S_INIT_ATS:
- case S_INIT_BLACKLIST:
- case S_CONNECT_SENT:
- case S_CONNECT_RECV_BLACKLIST_INBOUND:
- case S_CONNECT_RECV_ATS:
- case S_CONNECT_RECV_BLACKLIST:
- case S_CONNECT_RECV_ACK:
- return GNUNET_NO;
- case S_CONNECTED:
- case S_RECONNECT_ATS:
- case S_RECONNECT_BLACKLIST:
- case S_RECONNECT_SENT:
- case S_CONNECTED_SWITCHING_BLACKLIST:
- case S_CONNECTED_SWITCHING_CONNECT_SENT:
- return GNUNET_YES;
- case S_DISCONNECT:
- case S_DISCONNECT_FINISHED:
- return GNUNET_NO;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unhandled state `%s' \n",
- print_state (n->state));
- GNUNET_break (0);
- break;
- }
- return GNUNET_SYSERR;
+ return GNUNET_TRANSPORT_is_connected (n->state);
}
/**
@@ -960,7 +883,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting from peer %s in state %s\n",
GNUNET_i2s (&n->id),
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
/* depending on state, notify neighbour and/or upper layers of this peer
about disconnect */
switch (n->state)
@@ -1022,7 +945,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
break;
}
@@ -1693,7 +1616,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Asked to connect to peer `%s' (state: %s)\n",
GNUNET_i2s (target),
- (NULL != n) ? print_state(n->state) : "NEW PEER");
+ (NULL != n) ? GNUNET_TRANSPORT_p2s(n->state) : "NEW PEER");
if (NULL != n)
{
switch (n->state)
@@ -1734,7 +1657,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
free_neighbour (n, GNUNET_NO);
break;
@@ -1795,7 +1718,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received blacklist result for peer `%s' in state %s/%d\n",
GNUNET_i2s (peer),
- print_state (n->state),
+ GNUNET_TRANSPORT_p2s (n->state),
n->send_connect_ack);
switch (n->state)
{
@@ -1992,7 +1915,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
free_neighbour (n, GNUNET_NO);
break;
@@ -2093,7 +2016,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received SESSION_CONNECT for peer `%s' in state %s/%d\n",
GNUNET_i2s (peer),
- print_state (n->state),
+ GNUNET_TRANSPORT_p2s (n->state),
n->send_connect_ack);
switch (n->state)
{
@@ -2161,7 +2084,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
return GNUNET_SYSERR;
}
@@ -2234,7 +2157,7 @@
address->transport_name,
session,
GNUNET_i2s (peer),
- print_state (n->state),
+ GNUNET_TRANSPORT_p2s (n->state),
n->send_connect_ack,
ntohl (bandwidth_in.value__),
ntohl (bandwidth_out.value__));
@@ -2404,7 +2327,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
break;
}
@@ -2571,7 +2494,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Master task runs for neighbour `%s' in state %s with timeout in
%s\n",
GNUNET_i2s (&n->id),
- print_state(n->state),
+ GNUNET_TRANSPORT_p2s(n->state),
GNUNET_STRINGS_relative_time_to_string (delay,
GNUNET_YES));
switch (n->state)
@@ -2742,7 +2665,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
break;
}
@@ -2930,7 +2853,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
return GNUNET_SYSERR;
}
@@ -3060,7 +2983,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
break;
}
@@ -3117,7 +3040,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received SESSION_ACK message from peer `%s' in state %s/%d\n",
GNUNET_i2s (peer),
- print_state (n->state),
+ GNUNET_TRANSPORT_p2s (n->state),
n->send_connect_ack);
GNUNET_STATISTICS_update (GST_stats,
gettext_noop ("# unexpected SESSION_ACK
messages"), 1,
@@ -3297,7 +3220,7 @@
/**
- * Call the callback from the closure for each connected neighbour.
+ * Call the callback from the closure for each neighbour.
*
* @param cls the `struct IteratorContext`
* @param key the hash of the public key of the neighbour
@@ -3314,8 +3237,6 @@
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
- if (GNUNET_YES != test_connected (n))
- return GNUNET_OK;
if (NULL != n->primary_address.address)
{
@@ -3327,8 +3248,11 @@
bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
}
- ic->cb (ic->cb_cls, &n->id,
+ ic->cb (ic->cb_cls,
+ &n->id,
n->primary_address.address,
+ n->state,
+ n->timeout,
bandwidth_in, bandwidth_out);
return GNUNET_OK;
}
@@ -3415,7 +3339,7 @@
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unhandled state `%s'\n",
- print_state (n->state));
+ GNUNET_TRANSPORT_p2s (n->state));
GNUNET_break (0);
break;
}
Modified: gnunet/src/transport/gnunet-service-transport_neighbours.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.h 2014-01-08
10:47:06 UTC (rev 31828)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.h 2014-01-08
10:50:27 UTC (rev 31829)
@@ -170,19 +170,21 @@
/**
- * Function called for each connected neighbour.
+ * Function called for each neighbour.
*
* @param cls closure
* @param neighbour identity of the neighbour
* @param address the address (or NULL)
+ * @param state current state the peer is in
+ * @param state_timeout timeout for this state
* @param bandwidth_in inbound quota in NBO
* @param bandwidth_out outbound quota in NBO
*/
typedef void (*GST_NeighbourIterator) (void *cls,
- const struct GNUNET_PeerIdentity *
- neighbour,
- const struct GNUNET_HELLO_Address *
- address,
+ const struct GNUNET_PeerIdentity
*neighbour,
+ const struct GNUNET_HELLO_Address
*address,
+ enum GNUNET_TRANSPORT_PeerState state,
+ struct GNUNET_TIME_Absolute
state_timeout,
struct GNUNET_BANDWIDTH_Value32NBO
bandwidth_in,
struct GNUNET_BANDWIDTH_Value32NBO
bandwidth_out);
Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h 2014-01-08 10:47:06 UTC (rev 31828)
+++ gnunet/src/transport/transport.h 2014-01-08 10:50:27 UTC (rev 31829)
@@ -375,7 +375,7 @@
* Message from the library to the transport service
* asking for binary addresses known for a peer.
*/
-struct PeerIterateMessage
+struct PeerMonitorMessage
{
/**
* Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE
Modified: gnunet/src/transport/transport_api_monitoring.c
===================================================================
--- gnunet/src/transport/transport_api_monitoring.c 2014-01-08 10:47:06 UTC
(rev 31828)
+++ gnunet/src/transport/transport_api_monitoring.c 2014-01-08 10:50:27 UTC
(rev 31829)
@@ -140,8 +140,96 @@
int one_shot;
};
+/**
+ * Check if a state is defined as connected
+ *
+ * @param state the state value
+ * @return GNUNET_YES or GNUNET_NO
+ */
+int
+GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state)
+{
+ switch (state)
+ {
+ case S_NOT_CONNECTED:
+ case S_INIT_ATS:
+ case S_INIT_BLACKLIST:
+ case S_CONNECT_SENT:
+ case S_CONNECT_RECV_BLACKLIST_INBOUND:
+ case S_CONNECT_RECV_ATS:
+ case S_CONNECT_RECV_BLACKLIST:
+ case S_CONNECT_RECV_ACK:
+ return GNUNET_NO;
+ case S_CONNECTED:
+ case S_RECONNECT_ATS:
+ case S_RECONNECT_BLACKLIST:
+ case S_RECONNECT_SENT:
+ case S_CONNECTED_SWITCHING_BLACKLIST:
+ case S_CONNECTED_SWITCHING_CONNECT_SENT:
+ return GNUNET_YES;
+ case S_DISCONNECT:
+ case S_DISCONNECT_FINISHED:
+ return GNUNET_NO;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unhandled state `%s' \n",
+ GNUNET_TRANSPORT_p2s (state));
+ GNUNET_break (0);
+ break;
+ }
+ return GNUNET_SYSERR;
+}
+/**
+ * Convert state to human-readable string.
+ *
+ * @param state the state value
+ * @return corresponding string
+ */
+const char *
+GNUNET_TRANSPORT_p2s (enum GNUNET_TRANSPORT_PeerState state)
+{
+ switch (state)
+ {
+ case S_NOT_CONNECTED:
+ return "S_NOT_CONNECTED";
+ case S_INIT_ATS:
+ return "S_INIT_ATS";
+ case S_INIT_BLACKLIST:
+ return "S_INIT_BLACKLIST";
+ case S_CONNECT_SENT:
+ return "S_CONNECT_SENT";
+ case S_CONNECT_RECV_BLACKLIST_INBOUND:
+ return "S_CONNECT_RECV_BLACKLIST_INBOUND";
+ case S_CONNECT_RECV_ATS:
+ return "S_CONNECT_RECV_ATS";
+ case S_CONNECT_RECV_BLACKLIST:
+ return "S_CONNECT_RECV_BLACKLIST";
+ case S_CONNECT_RECV_ACK:
+ return "S_CONNECT_RECV_ACK";
+ case S_CONNECTED:
+ return "S_CONNECTED";
+ case S_RECONNECT_ATS:
+ return "S_RECONNECT_ATS";
+ case S_RECONNECT_BLACKLIST:
+ return "S_RECONNECT_BLACKLIST";
+ case S_RECONNECT_SENT:
+ return "S_RECONNECT_SENT";
+ case S_CONNECTED_SWITCHING_BLACKLIST:
+ return "S_CONNECTED_SWITCHING_BLACKLIST";
+ case S_CONNECTED_SWITCHING_CONNECT_SENT:
+ return "S_CONNECTED_SWITCHING_CONNECT_SENT";
+ case S_DISCONNECT:
+ return "S_DISCONNECT";
+ case S_DISCONNECT_FINISHED:
+ return "S_DISCONNECT_FINISHED";
+ default:
+ GNUNET_break (0);
+ return "UNDEFINED";
+ }
+}
+
/**
* Function called with responses from the service.
*
@@ -150,7 +238,7 @@
* message with the human-readable address
*/
static void
-peer_address_response_processor (void *cls,
+peer_response_processor (void *cls,
const struct GNUNET_MessageHeader *msg);
@@ -162,10 +250,10 @@
static void
send_request (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
{
- struct PeerIterateMessage msg;
+ struct PeerMonitorMessage msg;
- msg.header.size = htons (sizeof (struct PeerIterateMessage));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE);
+ msg.header.size = htons (sizeof (struct PeerMonitorMessage));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST);
msg.one_shot = htonl (pal_ctx->one_shot);
msg.timeout = GNUNET_TIME_absolute_hton (pal_ctx->timeout);
msg.peer = pal_ctx->peer;
@@ -174,7 +262,7 @@
&msg.header,
GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout),
GNUNET_YES,
-
&peer_address_response_processor,
+
&peer_response_processor,
pal_ctx));
}
@@ -218,16 +306,16 @@
/**
* Function called with responses from the service.
*
- * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
+ * @param cls our 'struct GNUNET_TRANSPORT_PeerMonitoringContext*'
* @param msg NULL on timeout or error, otherwise presumably a
* message with the human-readable address
*/
static void
-peer_address_response_processor (void *cls,
+peer_response_processor (void *cls,
const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
- struct PeerIterateResponseMessage *air_msg;
+ struct PeerIterateResponseMessage *pir_msg;
struct GNUNET_HELLO_Address *address;
const char *addr;
const char *transport_name;
@@ -251,7 +339,7 @@
}
size = ntohs (msg->size);
GNUNET_break (ntohs (msg->type) ==
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
if (size == sizeof (struct GNUNET_MessageHeader))
{
/* done! */
@@ -270,7 +358,7 @@
if ((size < sizeof (struct PeerIterateResponseMessage)) ||
(ntohs (msg->type) !=
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE))
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE))
{
GNUNET_break (0);
if (pal_ctx->one_shot)
@@ -286,9 +374,9 @@
return;
}
- air_msg = (struct PeerIterateResponseMessage *) msg;
- tlen = ntohl (air_msg->pluginlen);
- alen = ntohl (air_msg->addrlen);
+ pir_msg = (struct PeerIterateResponseMessage *) msg;
+ tlen = ntohl (pir_msg->pluginlen);
+ alen = ntohl (pir_msg->addrlen);
if (size != sizeof (struct PeerIterateResponseMessage) + tlen + alen)
{
@@ -308,12 +396,12 @@
if (alen == 0 && tlen == 0)
{
- pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, NULL,
+ pal_ctx->cb (pal_ctx->cb_cls, &pir_msg->peer, NULL,
S_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
}
else
{
- addr = (const char *) &air_msg[1];
+ addr = (const char *) &pir_msg[1];
transport_name = &addr[alen];
if (transport_name[tlen - 1] != '\0')
@@ -333,16 +421,16 @@
}
/* notify client */
- address = GNUNET_HELLO_address_allocate (&air_msg->peer,
+ address = GNUNET_HELLO_address_allocate (&pir_msg->peer,
transport_name, addr, alen);
- pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, address,
- ntohl(air_msg->state),
- GNUNET_TIME_absolute_ntoh (air_msg->state_timeout));
+ pal_ctx->cb (pal_ctx->cb_cls, &pir_msg->peer, address,
+ ntohl(pir_msg->state),
+ GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout));
GNUNET_HELLO_address_free (address);
}
/* expect more replies */
- GNUNET_CLIENT_receive (pal_ctx->client, &peer_address_response_processor,
+ GNUNET_CLIENT_receive (pal_ctx->client, &peer_response_processor,
pal_ctx,
GNUNET_TIME_absolute_get_remaining
(pal_ctx->timeout));
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31829 - in gnunet/src: include transport,
gnunet <=