diff options
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r-- | src/transport/transport_api.c | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index d672b4d46..6e47b269b 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -1054,7 +1054,8 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
1054 | * @return a `struct GNUNET_TRANSPORT_TransmitHandle` | 1054 | * @return a `struct GNUNET_TRANSPORT_TransmitHandle` |
1055 | */ | 1055 | */ |
1056 | static struct GNUNET_TRANSPORT_TransmitHandle * | 1056 | static struct GNUNET_TRANSPORT_TransmitHandle * |
1057 | schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size, | 1057 | schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, |
1058 | size_t size, | ||
1058 | GNUNET_TRANSPORT_TransmitReadyNotify notify, | 1059 | GNUNET_TRANSPORT_TransmitReadyNotify notify, |
1059 | void *notify_cls) | 1060 | void *notify_cls) |
1060 | { | 1061 | { |
@@ -1476,7 +1477,9 @@ send_hello (void *cls, size_t size, void *buf) | |||
1476 | * @return number of bytes copied to @a buf | 1477 | * @return number of bytes copied to @a buf |
1477 | */ | 1478 | */ |
1478 | static size_t | 1479 | static size_t |
1479 | send_metric (void *cls, size_t size, void *buf) | 1480 | send_metric (void *cls, |
1481 | size_t size, | ||
1482 | void *buf) | ||
1480 | { | 1483 | { |
1481 | struct TrafficMetricMessage *msg = cls; | 1484 | struct TrafficMetricMessage *msg = cls; |
1482 | uint16_t ssize; | 1485 | uint16_t ssize; |
@@ -1484,14 +1487,12 @@ send_metric (void *cls, size_t size, void *buf) | |||
1484 | if (NULL == buf) | 1487 | if (NULL == buf) |
1485 | { | 1488 | { |
1486 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1489 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1487 | "Timeout while trying to transmit `%s' request.\n", | 1490 | "Timeout while trying to transmit TRAFFIC_METRIC request.\n"); |
1488 | "TRAFFIC_METRIC"); | ||
1489 | GNUNET_free (msg); | 1491 | GNUNET_free (msg); |
1490 | return 0; | 1492 | return 0; |
1491 | } | 1493 | } |
1492 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1494 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1493 | "Transmitting `%s' request.\n", | 1495 | "Transmitting TRAFFIC_METRIC request.\n"); |
1494 | "TRAFFIC_METRIC"); | ||
1495 | ssize = ntohs (msg->header.size); | 1496 | ssize = ntohs (msg->header.size); |
1496 | GNUNET_assert (size >= ssize); | 1497 | GNUNET_assert (size >= ssize); |
1497 | memcpy (buf, msg, ssize); | 1498 | memcpy (buf, msg, ssize); |
@@ -1505,56 +1506,35 @@ send_metric (void *cls, size_t size, void *buf) | |||
1505 | * | 1506 | * |
1506 | * @param handle transport handle | 1507 | * @param handle transport handle |
1507 | * @param peer the peer to set the metric for | 1508 | * @param peer the peer to set the metric for |
1508 | * @param inbound set inbound direction (#GNUNET_YES or #GNUNET_NO) | 1509 | * @param prop the performance metrics to set |
1509 | * @param outbound set outbound direction (#GNUNET_YES or #GNUNET_NO) | 1510 | * @param delay_in inbound delay to introduce |
1510 | * @param ats the metric as ATS information | 1511 | * @param delay_out outbound delay to introduce |
1511 | * @param ats_count the number of metrics | ||
1512 | * | 1512 | * |
1513 | * Supported ATS values: | 1513 | * Note: Delay restrictions in receiving direction will be enforced |
1514 | * #GNUNET_ATS_QUALITY_NET_DELAY (value in ms) | 1514 | * with one message delay. |
1515 | * #GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops)) | ||
1516 | * | ||
1517 | * Example: | ||
1518 | * To enforce a delay of 10 ms for peer p1 in sending direction use: | ||
1519 | * <code> | ||
1520 | * struct GNUNET_ATS_Information ats; | ||
1521 | * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
1522 | * ats.value = ntohl (10); | ||
1523 | * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1); | ||
1524 | * </code> | ||
1525 | * Note: | ||
1526 | * Delay restrictions in receiving direction will be enforced with | ||
1527 | * 1 message delay. | ||
1528 | */ | 1515 | */ |
1529 | void | 1516 | void |
1530 | GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, | 1517 | GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, |
1531 | const struct GNUNET_PeerIdentity *peer, | 1518 | const struct GNUNET_PeerIdentity *peer, |
1532 | int inbound, | 1519 | const struct GNUNET_ATS_Properties *prop, |
1533 | int outbound, | 1520 | struct GNUNET_TIME_Relative delay_in, |
1534 | const struct GNUNET_ATS_Information *ats, | 1521 | struct GNUNET_TIME_Relative delay_out) |
1535 | size_t ats_count) | ||
1536 | { | 1522 | { |
1537 | struct TrafficMetricMessage *msg; | 1523 | struct TrafficMetricMessage *msg; |
1538 | 1524 | ||
1539 | GNUNET_assert ((outbound == GNUNET_YES) || (outbound == GNUNET_NO)); | 1525 | msg = GNUNET_new (struct TrafficMetricMessage); |
1540 | GNUNET_assert ((inbound == GNUNET_YES) || (inbound == GNUNET_NO)); | 1526 | msg->header.size = htons (sizeof (struct TrafficMetricMessage)); |
1541 | if ((GNUNET_NO == inbound) && (GNUNET_NO == outbound)) | ||
1542 | return; | ||
1543 | if (0 == ats_count) | ||
1544 | return; | ||
1545 | |||
1546 | size_t len = sizeof (struct TrafficMetricMessage) + | ||
1547 | ats_count * sizeof (struct GNUNET_ATS_Information); | ||
1548 | |||
1549 | msg = GNUNET_malloc (len); | ||
1550 | msg->header.size = htons (len); | ||
1551 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); | 1527 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); |
1552 | msg->direction = htons (0 + outbound + 2 * inbound); | 1528 | msg->reserved = htonl (0); |
1553 | msg->ats_count = htons (ats_count); | 1529 | msg->peer = *peer; |
1554 | msg->peer = (*peer); | 1530 | GNUNET_ATS_properties_hton (&msg->properties, |
1555 | memcpy (&msg[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | 1531 | prop); |
1556 | schedule_control_transmit (handle, len, | 1532 | msg->delay_in = GNUNET_TIME_relative_hton (delay_in); |
1557 | &send_metric, msg); | 1533 | msg->delay_out = GNUNET_TIME_relative_hton (delay_out); |
1534 | schedule_control_transmit (handle, | ||
1535 | sizeof (struct TrafficMetricMessage), | ||
1536 | &send_metric, | ||
1537 | msg); | ||
1558 | } | 1538 | } |
1559 | 1539 | ||
1560 | 1540 | ||