diff options
author | wachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96> | 2013-02-05 12:47:04 +0000 |
---|---|---|
committer | wachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96> | 2013-02-05 12:47:04 +0000 |
commit | 97cabd74c84b8a92da6453cb293897cbe3c42abe (patch) | |
tree | 8041967789288571864baba03d51287ffeb799a5 | |
parent | b19e191a9e83970b66cbc6bd1cd33949a6491ce9 (diff) |
last commit for metric
git-svn-id: https://gnunet.org/svn/gnunet@26016 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r-- | src/include/gnunet_transport_service.h | 15 | ||||
-rw-r--r-- | src/transport/Makefile.am | 15 | ||||
-rw-r--r-- | src/transport/transport_api.c | 60 |
3 files changed, 88 insertions, 2 deletions
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 5f03b3fc37..00b06c44f3 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -43,6 +43,13 @@ extern "C" */ #define GNUNET_TRANSPORT_VERSION 0x00000000 +enum TRAFFIC_METRIC_DIRECTION +{ + TM_SEND = 0, + TM_RECEIVE = 1, + TM_BOTH = 2 +}; + /** * Function called by the transport for each received message. @@ -282,6 +289,14 @@ GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *hand const struct GNUNET_PeerIdentity *peer); +void +GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, + const struct GNUNET_PeerIdentity *peer, + int direction, + const struct GNUNET_ATS_Information *ats, + size_t ats_count); + + /** * Obtain updates on changes to the HELLO message for this peer. The callback * given in this function is never called synchronously. diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 4723758292..d02117437e 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -164,7 +164,8 @@ gnunet_service_transport_SOURCES = \ gnunet-service-transport_hello.h gnunet-service-transport_hello.c \ gnunet-service-transport_neighbours.h gnunet-service-transport_neighbours.c \ gnunet-service-transport_plugins.h gnunet-service-transport_plugins.c \ - gnunet-service-transport_validation.h gnunet-service-transport_validation.c + 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/ats/libgnunetats.la \ $(top_builddir)/src/hello/libgnunethello.la \ @@ -342,6 +343,7 @@ check_PROGRAMS = \ $(HTTPS_API_TIMEOUT_TEST) \ $(WLAN_API_TEST) \ test_transport_api_multi \ + test_transport_api_manipulation_tcp \ test_transport_api_reliability_tcp \ test_transport_api_reliability_tcp_nat \ test_transport_api_unreliability_udp \ @@ -389,6 +391,7 @@ TESTS = \ $(HTTPS_API_TIMEOUT_TEST) \ $(WLAN_API_TEST) \ test_transport_api_multi \ + test_transport_api_manipulation_tcp \ test_transport_api_reliability_tcp \ test_transport_api_reliability_tcp_nat \ test_transport_api_unreliability_udp \ @@ -430,7 +433,6 @@ test_transport_testing_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - test_transport_api_blacklisting_SOURCES = \ test_transport_api_blacklisting.c test_transport_api_blacklisting_LDADD = \ @@ -590,6 +592,15 @@ test_transport_api_tcp_nat_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la +test_transport_api_manipulation_tcp_SOURCES = \ + test_transport_api_manipulation.c +test_transport_api_manipulation_tcp_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/transport/libgnunettransporttesting.la + + test_transport_api_reliability_tcp_SOURCES = \ test_transport_api_reliability.c test_transport_api_reliability_tcp_LDADD = \ diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index e821abee4c..966a71ee33 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -1180,6 +1180,66 @@ send_hello (void *cls, size_t size, void *buf) /** + * Send traffic metric message to the service. + * + * @param cls the message to send + * @param size number of bytes available in buf + * @param buf where to copy the message + * @return number of bytes copied to buf + */ +static size_t +send_metric (void *cls, size_t size, void *buf) +{ + struct TrafficMetricMessage *msg = cls; + uint16_t ssize; + if (buf == NULL) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Timeout while trying to transmit `%s' request.\n", "TRAFFIC_METRIC"); + GNUNET_free (msg); + return 0; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TRAFFIC_METRIC"); + ssize = ntohs (msg->header.size); + GNUNET_assert (size >= ssize); + memcpy (buf, msg, ssize); + GNUNET_free (msg); + return ssize; +} + +void +GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, + const struct GNUNET_PeerIdentity *peer, + int direction, + const struct GNUNET_ATS_Information *ats, + size_t ats_count) +{ + struct TrafficMetricMessage *msg; + + GNUNET_assert (NULL != handle); + GNUNET_assert (NULL != peer); + GNUNET_assert (direction >= TM_SEND); + GNUNET_assert (direction <= TM_BOTH); + + if (0 == ats_count) + return; + + size_t len = sizeof (struct TrafficMetricMessage) + + ats_count * sizeof (struct GNUNET_ATS_Information); + + msg = GNUNET_malloc (len); + msg->header.size = htons (len); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); + msg->direction = htons (direction); + msg->ats_count = htons (ats_count); + msg->peer = (*peer); + memcpy (&msg[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information)); + schedule_control_transmit (handle, len, &send_metric, msg); +} + + + +/** * Offer the transport service the HELLO of another peer. Note that * the transport service may just ignore this message if the HELLO is * malformed or useless due to our local configuration. |