diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-26 21:00:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-26 21:00:53 +0000 |
commit | 8ff0618cd174a9270d9bad688bdc4da45984067b (patch) | |
tree | e3ea72aefff17cb8c3940a2ed54f1915dd806a25 /src/transport/gnunet-transport.c | |
parent | f7ac06c047ff39c29a9b3bd3b057f7e5c887f0cf (diff) | |
download | gnunet-8ff0618cd174a9270d9bad688bdc4da45984067b.tar.gz gnunet-8ff0618cd174a9270d9bad688bdc4da45984067b.zip |
documenting gnunet-transport a bit
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r-- | src/transport/gnunet-transport.c | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index e8d1e3572..bc78e3d04 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -32,28 +32,68 @@ | |||
32 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
33 | #include "gnunet_transport_service.h" | 33 | #include "gnunet_transport_service.h" |
34 | 34 | ||
35 | /** | ||
36 | * Which peer should we connect to? | ||
37 | */ | ||
35 | static char *cpid; | 38 | static char *cpid; |
36 | 39 | ||
40 | /** | ||
41 | * Handle to transport service. | ||
42 | */ | ||
37 | static struct GNUNET_TRANSPORT_Handle *handle; | 43 | static struct GNUNET_TRANSPORT_Handle *handle; |
38 | 44 | ||
45 | /** | ||
46 | * Option -s. | ||
47 | */ | ||
39 | static int benchmark_send; | 48 | static int benchmark_send; |
40 | 49 | ||
50 | /** | ||
51 | * Option -b. | ||
52 | */ | ||
41 | static int benchmark_receive; | 53 | static int benchmark_receive; |
42 | 54 | ||
55 | /** | ||
56 | * Global return value (0 success). | ||
57 | */ | ||
43 | static int ret; | 58 | static int ret; |
44 | 59 | ||
60 | /** | ||
61 | * Number of bytes of traffic we received so far. | ||
62 | */ | ||
45 | static unsigned long long traffic_received; | 63 | static unsigned long long traffic_received; |
46 | 64 | ||
65 | /** | ||
66 | * Number of bytes of traffic we sent so far. | ||
67 | */ | ||
47 | static unsigned long long traffic_sent; | 68 | static unsigned long long traffic_sent; |
48 | 69 | ||
70 | /** | ||
71 | * Starting time of transmitting/receiving data. | ||
72 | */ | ||
49 | static struct GNUNET_TIME_Absolute start_time; | 73 | static struct GNUNET_TIME_Absolute start_time; |
50 | 74 | ||
75 | /** | ||
76 | * Handle for current transmission request. | ||
77 | */ | ||
51 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 78 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
52 | 79 | ||
80 | /** | ||
81 | * Identity of the peer we transmit to / connect to. | ||
82 | * (equivalent to 'cpid' string). | ||
83 | */ | ||
53 | static struct GNUNET_PeerIdentity pid; | 84 | static struct GNUNET_PeerIdentity pid; |
54 | 85 | ||
86 | /** | ||
87 | * Task scheduled for cleanup / termination of the process. | ||
88 | */ | ||
55 | static GNUNET_SCHEDULER_TaskIdentifier end; | 89 | static GNUNET_SCHEDULER_TaskIdentifier end; |
56 | 90 | ||
91 | /** | ||
92 | * Selected level of verbosity. | ||
93 | */ | ||
94 | static int verbosity; | ||
95 | |||
96 | |||
57 | 97 | ||
58 | /** | 98 | /** |
59 | * Shutdown, print statistics. | 99 | * Shutdown, print statistics. |
@@ -74,7 +114,7 @@ do_disconnect (void *cls, | |||
74 | { | 114 | { |
75 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 115 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
76 | fprintf (stderr, | 116 | fprintf (stderr, |
77 | "Received %llu bytes/s (%llu bytes in %llu ms)\n", | 117 | _("Received %llu bytes/s (%llu bytes in %llu ms)\n"), |
78 | 1000 * traffic_received / (1+duration.rel_value), | 118 | 1000 * traffic_received / (1+duration.rel_value), |
79 | traffic_received, | 119 | traffic_received, |
80 | (unsigned long long) duration.rel_value); | 120 | (unsigned long long) duration.rel_value); |
@@ -83,7 +123,7 @@ do_disconnect (void *cls, | |||
83 | { | 123 | { |
84 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 124 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
85 | fprintf (stderr, | 125 | fprintf (stderr, |
86 | "Transmitted %llu bytes/s (%llu bytes in %llu ms)\n", | 126 | _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"), |
87 | 1000 * traffic_sent / (1+duration.rel_value), | 127 | 1000 * traffic_sent / (1+duration.rel_value), |
88 | traffic_sent, | 128 | traffic_sent, |
89 | (unsigned long long) duration.rel_value); | 129 | (unsigned long long) duration.rel_value); |
@@ -120,10 +160,11 @@ transmit_data (void *cls, size_t size, | |||
120 | 0, | 160 | 0, |
121 | GNUNET_TIME_UNIT_FOREVER_REL, | 161 | GNUNET_TIME_UNIT_FOREVER_REL, |
122 | &transmit_data, NULL); | 162 | &transmit_data, NULL); |
123 | fprintf (stderr, | 163 | if (verbosity > 0) |
124 | "Transmitting %u bytes to %s\n", | 164 | fprintf (stderr, |
125 | (unsigned int) size, | 165 | _("Transmitting %u bytes to %s\n"), |
126 | GNUNET_i2s (&pid)); | 166 | (unsigned int) size, |
167 | GNUNET_i2s (&pid)); | ||
127 | return size; | 168 | return size; |
128 | } | 169 | } |
129 | 170 | ||
@@ -145,9 +186,10 @@ notify_connect (void *cls, | |||
145 | GNUNET_ATS_Information | 186 | GNUNET_ATS_Information |
146 | * ats, uint32_t ats_count) | 187 | * ats, uint32_t ats_count) |
147 | { | 188 | { |
148 | fprintf (stderr, | 189 | if (verbosity > 0) |
149 | "Connected to %s\n", | 190 | fprintf (stderr, |
150 | GNUNET_i2s (peer)); | 191 | _("Connected to %s\n"), |
192 | GNUNET_i2s (peer)); | ||
151 | if (0 != memcmp (&pid, | 193 | if (0 != memcmp (&pid, |
152 | peer, | 194 | peer, |
153 | sizeof (struct GNUNET_PeerIdentity))) | 195 | sizeof (struct GNUNET_PeerIdentity))) |
@@ -185,9 +227,10 @@ notify_disconnect (void *cls, | |||
185 | const struct | 227 | const struct |
186 | GNUNET_PeerIdentity * peer) | 228 | GNUNET_PeerIdentity * peer) |
187 | { | 229 | { |
188 | fprintf (stderr, | 230 | if (verbosity > 0) |
189 | "Disconnected from %s\n", | 231 | fprintf (stderr, |
190 | GNUNET_i2s (peer)); | 232 | _("Disconnected from %s\n"), |
233 | GNUNET_i2s (peer)); | ||
191 | if ( (0 == memcmp (&pid, | 234 | if ( (0 == memcmp (&pid, |
192 | peer, | 235 | peer, |
193 | sizeof (struct GNUNET_PeerIdentity))) && | 236 | sizeof (struct GNUNET_PeerIdentity))) && |
@@ -224,10 +267,11 @@ notify_receive (void *cls, | |||
224 | { | 267 | { |
225 | if (! benchmark_receive) | 268 | if (! benchmark_receive) |
226 | return; | 269 | return; |
227 | fprintf (stderr, | 270 | if (verbosity > 0) |
228 | "Received %u bytes from %s\n", | 271 | fprintf (stderr, |
229 | (unsigned int) ntohs (message->size), | 272 | _("Received %u bytes from %s\n"), |
230 | GNUNET_i2s (peer)); | 273 | (unsigned int) ntohs (message->size), |
274 | GNUNET_i2s (peer)); | ||
231 | if (traffic_received == 0) | 275 | if (traffic_received == 0) |
232 | start_time = GNUNET_TIME_absolute_get (); | 276 | start_time = GNUNET_TIME_absolute_get (); |
233 | traffic_received += ntohs (message->size); | 277 | traffic_received += ntohs (message->size); |
@@ -300,6 +344,7 @@ main (int argc, char *const *argv) | |||
300 | {'s', "send", NULL, | 344 | {'s', "send", NULL, |
301 | gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), | 345 | gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), |
302 | 0, &GNUNET_GETOPT_set_one, &benchmark_send}, | 346 | 0, &GNUNET_GETOPT_set_one, &benchmark_send}, |
347 | GNUNET_GETOPT_OPTION_VERBOSE(&verbosity), | ||
303 | GNUNET_GETOPT_OPTION_END | 348 | GNUNET_GETOPT_OPTION_END |
304 | }; | 349 | }; |
305 | return (GNUNET_OK == | 350 | return (GNUNET_OK == |