- struct TrafficMetricMessage *tm = (struct TrafficMetricMessage *) message;
- struct GNUNET_PeerIdentity dummy;
- struct GNUNET_ATS_Information *ats;
- struct TM_Peer *tmp;
- uint32_t type;
- uint32_t value;
- uint16_t direction;
- int c;
- int c2;
-
- if (0 == ntohs (tm->ats_count))
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-
- switch (ntohs(tm->direction)) {
- case 1:
- direction = TM_SEND;
- break;
- case 2:
- direction = TM_RECEIVE;
- break;
- case 3:
- direction = TM_BOTH;
- break;
- default:
- break;
- }
-
- memset (&dummy, '\0', sizeof (struct GNUNET_PeerIdentity));
- if (0 == memcmp (&tm->peer, &dummy, sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for all peers \n");
-
- ats = (struct GNUNET_ATS_Information *) &tm[1];
- for (c = 0; c < ntohs (tm->ats_count); c++)
- {
- type = htonl (ats[c].type);
- value = htonl (ats[c].value);
-
- switch (type) {
- case GNUNET_ATS_QUALITY_NET_DELAY:
- if ((TM_RECEIVE == direction) || (TM_BOTH == direction))
- man_handle.delay_recv.rel_value = value;
- if ((TM_SEND == direction) || (TM_BOTH == direction))
- man_handle.delay_send.rel_value = value;
- break;
- case GNUNET_ATS_QUALITY_NET_DISTANCE:
- if ((TM_RECEIVE == direction) || (TM_BOTH == direction))
- man_handle.distance_recv = value;
- if ((TM_SEND == direction) || (TM_BOTH == direction))
- man_handle.distance_send = value;
- break;
- default:
- break;
- }
-
- }
- return;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for peer `%s'\n",
- GNUNET_i2s(&tm->peer));
-
- if (NULL == (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &tm->peer.hashPubKey)))
- {
- tmp = GNUNET_malloc (sizeof (struct TM_Peer));
- tmp->peer = (tm->peer);
- for (c = 0; c < TM_BOTH; c++)
- {
- for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++)
- {
- tmp->metrics[c][c2] = UINT32_MAX;
- }
- }
- GNUNET_CONTAINER_multihashmap_put (man_handle.peers, &tm->peer.hashPubKey, tmp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
- }
-
- ats = (struct GNUNET_ATS_Information *) &tm[1];
- for (c = 0; c < ntohs (tm->ats_count); c++)
- {
- type = htonl (ats[c].type);
- value = htonl (ats[c].value);
- switch (type) {
- case GNUNET_ATS_QUALITY_NET_DELAY:
- set_delay (tmp, &tm->peer, direction, value);
- break;
- case GNUNET_ATS_QUALITY_NET_DISTANCE:
- set_distance (tmp, &tm->peer, direction, value);
- break;
- default:
- break;
- }
- }
-
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ static struct GNUNET_PeerIdentity zero;
+ struct TM_Peer *tmp;
+
+ if (0 == memcmp (&tm->peer,
+ &zero,
+ sizeof(struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received traffic metrics for all peers\n");
+ delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in);
+ delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received traffic metrics for peer `%s'\n",
+ GNUNET_i2s (&tm->peer));
+ if (NULL ==
+ (tmp = GNUNET_CONTAINER_multipeermap_get (peers,
+ &tm->peer)))
+ {
+ tmp = GNUNET_new (struct TM_Peer);
+ tmp->peer = tm->peer;
+ GNUNET_CONTAINER_multipeermap_put (peers,
+ &tm->peer,
+ tmp,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ }
+ GNUNET_ATS_properties_ntoh (&tmp->properties,
+ &tm->properties);
+ tmp->delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in);
+ tmp->delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out);