diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-16 14:11:07 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-16 14:11:07 +0000 |
commit | fefe7e30ec57df396375b0f6d26c6581a1916704 (patch) | |
tree | 9aae84196285465b5ba273bdee5902cd83125285 | |
parent | a692bdacf59e0f6406428610fcb9af53864cc8a3 (diff) | |
download | gnunet-fefe7e30ec57df396375b0f6d26c6581a1916704.tar.gz gnunet-fefe7e30ec57df396375b0f6d26c6581a1916704.zip |
print ats properties
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 34 | ||||
-rw-r--r-- | src/include/gnunet_ats_service.h | 34 |
2 files changed, 61 insertions, 7 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 73e017fc1..0543549aa 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -75,17 +75,49 @@ void transport_addr_to_str_cb (void *cls, const char *address) | |||
75 | struct PendingResolutions * pr = cls; | 75 | struct PendingResolutions * pr = cls; |
76 | char *ats_str; | 76 | char *ats_str; |
77 | char *ats_tmp; | 77 | char *ats_tmp; |
78 | char *ats_prop_arr[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings; | ||
79 | char *ats_net_arr[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; | ||
80 | char *ats_prop_value; | ||
78 | unsigned int c; | 81 | unsigned int c; |
82 | uint32_t ats_type; | ||
83 | uint32_t ats_value; | ||
84 | |||
79 | if (NULL != address) | 85 | if (NULL != address) |
80 | { | 86 | { |
81 | ats_str = GNUNET_strdup(""); | 87 | ats_str = GNUNET_strdup(""); |
82 | for (c = 0; c < pr->ats_count; c++) | 88 | for (c = 0; c < pr->ats_count; c++) |
83 | { | 89 | { |
84 | ats_tmp = ats_str; | 90 | ats_tmp = ats_str; |
85 | GNUNET_asprintf (&ats_str, "%s%u %u ", ats_tmp, ntohl(pr->ats[c].type), ntohl(pr->ats[c].value)); | 91 | |
92 | ats_type = ntohl(pr->ats[c].type); | ||
93 | ats_value = ntohl(pr->ats[c].value); | ||
94 | |||
95 | if (ats_type > GNUNET_ATS_PropertyCount) | ||
96 | { | ||
97 | GNUNET_break (0); | ||
98 | continue; | ||
99 | } | ||
100 | |||
101 | switch (ats_type) { | ||
102 | case GNUNET_ATS_NETWORK_TYPE: | ||
103 | if (ats_value > GNUNET_ATS_NetworkTypeCount) | ||
104 | { | ||
105 | GNUNET_break (0); | ||
106 | continue; | ||
107 | } | ||
108 | GNUNET_asprintf (&ats_prop_value, "%s", ats_net_arr[ats_value]); | ||
109 | break; | ||
110 | default: | ||
111 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); | ||
112 | break; | ||
113 | } | ||
114 | |||
115 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type] , ats_prop_value); | ||
86 | GNUNET_free (ats_tmp); | 116 | GNUNET_free (ats_tmp); |
117 | GNUNET_free (ats_prop_value); | ||
87 | } | 118 | } |
88 | 119 | ||
120 | |||
89 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), | 121 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), |
90 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, | 122 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, |
91 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),ats_str); | 123 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),ats_str); |
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index e8e7abb5b..11d718158 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h | |||
@@ -30,6 +30,20 @@ | |||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
32 | 32 | ||
33 | /** | ||
34 | * Number of network types supported by ATS | ||
35 | */ | ||
36 | #define GNUNET_ATS_NetworkTypeCount 5 | ||
37 | |||
38 | /** | ||
39 | * ATS network types as array initializer | ||
40 | */ | ||
41 | #define GNUNET_ATS_NetworkType {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} | ||
42 | |||
43 | /** | ||
44 | * ATS network types as string array initializer | ||
45 | */ | ||
46 | #define GNUNET_ATS_NetworkTypeString {"UNSPECIFIED", "LOOPBACK", "LAN", "WAN", "WLAN"} | ||
33 | 47 | ||
34 | enum GNUNET_ATS_Network_Type | 48 | enum GNUNET_ATS_Network_Type |
35 | { | 49 | { |
@@ -40,6 +54,18 @@ enum GNUNET_ATS_Network_Type | |||
40 | GNUNET_ATS_NET_WLAN = 4, | 54 | GNUNET_ATS_NET_WLAN = 4, |
41 | }; | 55 | }; |
42 | 56 | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Number of property types supported by ATS | ||
61 | */ | ||
62 | #define GNUNET_ATS_PropertyCount 9 | ||
63 | |||
64 | /** | ||
65 | * ATS properties types as string array initializer | ||
66 | */ | ||
67 | #define GNUNET_ATS_PropertyStrings {"Terminator", "Utilization up", "Utilization down", "Network type", "Delay", "Distance", "Cost WAN", "Cost LAN", "Cost WLAN"} | ||
68 | |||
43 | /** | 69 | /** |
44 | * Enum defining all known property types for ATS Enum values are used | 70 | * Enum defining all known property types for ATS Enum values are used |
45 | * in the GNUNET_ATS_Information struct as | 71 | * in the GNUNET_ATS_Information struct as |
@@ -413,14 +439,10 @@ enum GNUNET_ATS_Property | |||
413 | #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE} | 439 | #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE} |
414 | 440 | ||
415 | /** | 441 | /** |
416 | * Number of ATS quality properties | 442 | * ATS quality properties as string array initializer |
417 | */ | 443 | */ |
418 | #define GNUNET_ATS_NetworkTypeCount 5 | 444 | #define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"} |
419 | 445 | ||
420 | /** | ||
421 | * ATS quality properties as array initializer | ||
422 | */ | ||
423 | #define GNUNET_ATS_NetworkType {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} | ||
424 | 446 | ||
425 | GNUNET_NETWORK_STRUCT_BEGIN | 447 | GNUNET_NETWORK_STRUCT_BEGIN |
426 | 448 | ||