diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-05 12:47:04 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-05 12:47:04 +0000 |
commit | 6f7bf87716965774090bbe23010af249007fdae0 (patch) | |
tree | 8041967789288571864baba03d51287ffeb799a5 /src/transport/transport_api.c | |
parent | c51fd513a8a5b78fd02c3950030e1acd83b32c97 (diff) | |
download | gnunet-6f7bf87716965774090bbe23010af249007fdae0.tar.gz gnunet-6f7bf87716965774090bbe23010af249007fdae0.zip |
last commit for metric
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r-- | src/transport/transport_api.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index e821abee4..966a71ee3 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) | |||
1180 | 1180 | ||
1181 | 1181 | ||
1182 | /** | 1182 | /** |
1183 | * Send traffic metric message to the service. | ||
1184 | * | ||
1185 | * @param cls the message to send | ||
1186 | * @param size number of bytes available in buf | ||
1187 | * @param buf where to copy the message | ||
1188 | * @return number of bytes copied to buf | ||
1189 | */ | ||
1190 | static size_t | ||
1191 | send_metric (void *cls, size_t size, void *buf) | ||
1192 | { | ||
1193 | struct TrafficMetricMessage *msg = cls; | ||
1194 | uint16_t ssize; | ||
1195 | if (buf == NULL) | ||
1196 | { | ||
1197 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1198 | "Timeout while trying to transmit `%s' request.\n", "TRAFFIC_METRIC"); | ||
1199 | GNUNET_free (msg); | ||
1200 | return 0; | ||
1201 | } | ||
1202 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TRAFFIC_METRIC"); | ||
1203 | ssize = ntohs (msg->header.size); | ||
1204 | GNUNET_assert (size >= ssize); | ||
1205 | memcpy (buf, msg, ssize); | ||
1206 | GNUNET_free (msg); | ||
1207 | return ssize; | ||
1208 | } | ||
1209 | |||
1210 | void | ||
1211 | GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, | ||
1212 | const struct GNUNET_PeerIdentity *peer, | ||
1213 | int direction, | ||
1214 | const struct GNUNET_ATS_Information *ats, | ||
1215 | size_t ats_count) | ||
1216 | { | ||
1217 | struct TrafficMetricMessage *msg; | ||
1218 | |||
1219 | GNUNET_assert (NULL != handle); | ||
1220 | GNUNET_assert (NULL != peer); | ||
1221 | GNUNET_assert (direction >= TM_SEND); | ||
1222 | GNUNET_assert (direction <= TM_BOTH); | ||
1223 | |||
1224 | if (0 == ats_count) | ||
1225 | return; | ||
1226 | |||
1227 | size_t len = sizeof (struct TrafficMetricMessage) + | ||
1228 | ats_count * sizeof (struct GNUNET_ATS_Information); | ||
1229 | |||
1230 | msg = GNUNET_malloc (len); | ||
1231 | msg->header.size = htons (len); | ||
1232 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); | ||
1233 | msg->direction = htons (direction); | ||
1234 | msg->ats_count = htons (ats_count); | ||
1235 | msg->peer = (*peer); | ||
1236 | memcpy (&msg[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
1237 | schedule_control_transmit (handle, len, &send_metric, msg); | ||
1238 | } | ||
1239 | |||
1240 | |||
1241 | |||
1242 | /** | ||
1183 | * Offer the transport service the HELLO of another peer. Note that | 1243 | * Offer the transport service the HELLO of another peer. Note that |
1184 | * the transport service may just ignore this message if the HELLO is | 1244 | * the transport service may just ignore this message if the HELLO is |
1185 | * malformed or useless due to our local configuration. | 1245 | * malformed or useless due to our local configuration. |