streamers / streamer.c @ 03de31e0
History | View | Annotate | Download (11.8 KB)
1 | 89e893e2 | Luca | /*
|
---|---|---|---|
2 | 8fed7779 | CsabaKiraly | * Copyright (c) 2010 Luca Abeni
|
3 | * Copyright (c) 2010 Csaba Kiraly
|
||
4 | 89e893e2 | Luca | *
|
5 | 8fed7779 | CsabaKiraly | * This is free software; see gpl-3.0.txt
|
6 | 89e893e2 | Luca | */
|
7 | #include <stdlib.h> |
||
8 | #include <stdint.h> |
||
9 | #include <stdio.h> |
||
10 | 46c24e94 | Csaba Kiraly | #include <stdbool.h> |
11 | 89e893e2 | Luca | #include <string.h> |
12 | #include <getopt.h> |
||
13 | 5dcfffbc | CsabaKiraly | #include <signal.h> |
14 | d7a4d49c | Csaba Kiraly | #include <time.h> |
15 | 839ae781 | Csaba Kiraly | #include <errno.h> |
16 | #include <math.h> |
||
17 | #ifndef NAN //NAN is missing in some old math.h versions |
||
18 | #define NAN (0.0/0.0) |
||
19 | #endif
|
||
20 | |||
21 | e28a1487 | CsabaKiraly | #include <grapes_msg_types.h> |
22 | 89e893e2 | Luca | #include <net_helper.h> |
23 | |||
24 | 95e6fe96 | CsabaKiraly | #ifdef WIN32
|
25 | #include <winsock2.h> |
||
26 | #endif
|
||
27 | |||
28 | 89e893e2 | Luca | #include "net_helpers.h" |
29 | #include "loop.h" |
||
30 | f0bb64e2 | Csaba Kiraly | #include "output.h" |
31 | 581339c4 | Csaba Kiraly | #include "channel.h" |
32 | f088e50e | MarcoBiazzini | #include "topology.h" |
33 | a8a31ce0 | Csaba Kiraly | #include "measures.h" |
34 | 1d21cb23 | Csaba Kiraly | #include "streamer.h" |
35 | |||
36 | static struct nodeID *my_sock; |
||
37 | 89e893e2 | Luca | |
38 | 7c21b5b1 | CsabaKiraly | const char *peername = NULL; |
39 | |||
40 | 613263e9 | Csaba Kiraly | static const char *my_iface = NULL; |
41 | 89e893e2 | Luca | static int port = 6666; |
42 | static int srv_port; |
||
43 | 0f23522a | Luca | static const char *srv_ip = ""; |
44 | 66f50156 | Csaba Kiraly | static int period = 40; |
45 | static int chunks_per_second = 25; |
||
46 | 839ae781 | Csaba Kiraly | static double capacity_override = NAN; |
47 | 6d0c8116 | GiuseppeTropea | #ifdef HTTPIO
|
48 | //input-http.c needs this in order to accomplish the -m multiple send_chunk()
|
||
49 | 66f84460 | CsabaKiraly | int multiply = 3; |
50 | 6d0c8116 | GiuseppeTropea | #else
|
51 | 66f84460 | CsabaKiraly | static int multiply = 3; |
52 | 6d0c8116 | GiuseppeTropea | #endif
|
53 | 789d6502 | Csaba Kiraly | static int buff_size = 50; |
54 | 66f84460 | CsabaKiraly | static int outbuff_size = 50; |
55 | adb2a9b2 | CsabaKiraly | static const char *fname = "/dev/stdin"; |
56 | 03de31e0 | Csaba Kiraly | static const char *output_config =""; |
57 | 193622ac | CsabaKiraly | static const char *net_helper_config = ""; |
58 | 5f72f6b3 | Csaba Kiraly | static const char *topo_config = ""; |
59 | 33d23b91 | MarcoBiazzini | unsigned char msgTypes[] = {MSG_TYPE_CHUNK,MSG_TYPE_SIGNALLING}; |
60 | 1cd06c26 | CsabaKiraly | bool chunk_log = false; |
61 | 4536b69e | Csaba Kiraly | static int randomize_start = 0; |
62 | a2fa286f | Luca Abeni | int start_id = -1; |
63 | int end_id = -1; |
||
64 | int initial_id = -1; |
||
65 | 89e893e2 | Luca | |
66 | 20663df3 | Csaba Kiraly | extern int NEIGHBORHOOD_TARGET_SIZE; |
67 | 3730fda0 | Csaba Kiraly | extern uint64_t CB_SIZE_TIME;
|
68 | 9818ca86 | Csaba Kiraly | extern double desired_bw; |
69 | 4ca3a6bd | Luca Abeni | extern double desired_rtt; |
70 | extern double alpha_target; |
||
71 | f672dcde | Csaba Kiraly | extern double topo_mem; |
72 | 79ef0588 | Csaba Kiraly | extern bool topo_out; |
73 | extern bool topo_in; |
||
74 | f6e9f400 | Csaba Kiraly | extern bool topo_keep_best; |
75 | extern bool topo_add_best; |
||
76 | 20663df3 | Csaba Kiraly | |
77 | d8288eb0 | Csaba Kiraly | #ifndef MONL
|
78 | 75b2b975 | Csaba Kiraly | extern struct timeval print_tdiff; |
79 | extern struct timeval tstartdiff; |
||
80 | d8288eb0 | Csaba Kiraly | #endif
|
81 | 75b2b975 | Csaba Kiraly | |
82 | 43c2d7d6 | CsabaKiraly | static void print_usage(int argc, char *argv[]) |
83 | a02fc4cf | MarcoMellia | { |
84 | fprintf (stderr, |
||
85 | 60784aa1 | CsabaKiraly | "Usage:%s [options]\n"
|
86 | a02fc4cf | MarcoMellia | "\n"
|
87 | "Peer options\n"
|
||
88 | "\t[-p port]: port of the remote peer to connect at during bootstrap.\n"
|
||
89 | "\t Usually it is the source peer port.\n"
|
||
90 | "\t[-i IP]: IP address of the remote peer to connect at during bootstrap.\n"
|
||
91 | "\t Usually it is the source peer IP\n"
|
||
92 | "\t[-C name]: set the channel name to use on the repository.\n"
|
||
93 | "\t All peers should use the same channel name.\n"
|
||
94 | "\n"
|
||
95 | "\t[-b size]: set the peer Chunk Buffer size.\n"
|
||
96 | "\t This is also the chunk trading window size.\n"
|
||
97 | "\t[-o size]: set the Output Buffer size.\n"
|
||
98 | "\t[-c chunks]: set the number of chunks a peer can send per seconds.\n"
|
||
99 | "\t it controls the upload capacity of peer as well.\n"
|
||
100 | 20663df3 | Csaba Kiraly | "\t[-M peers]: neighbourhood target size.\n"
|
101 | 5f72f6b3 | Csaba Kiraly | "\t[-t config]: topology config.\n"
|
102 | a02fc4cf | MarcoMellia | "\t[-P port]: local UDP port to be used by the peer.\n"
|
103 | 60784aa1 | CsabaKiraly | "\t[-I iface]: local netwok interface to be used by the peer.\n"
|
104 | a02fc4cf | MarcoMellia | "\t Useful if the host has several interfaces/addresses.\n"
|
105 | 7c21b5b1 | CsabaKiraly | "\t[-N name]: set the name of the peer.\n"
|
106 | "\t This name will be used when publishing in the repository.\n"
|
||
107 | 193622ac | CsabaKiraly | "\t[-n options]: pass configuration options to the net-helper\n"
|
108 | 1cd06c26 | CsabaKiraly | "\t[--chunk_log]: print a chunk level log on stderr\n"
|
109 | 60784aa1 | CsabaKiraly | "\t[-F config]: configure the output module\n"
|
110 | 4ca3a6bd | Luca Abeni | "\t[-a alpha]: set the topology alpha value (from 0 to 100)\n"
|
111 | 29aaab6c | Csaba Kiraly | "\t[-r rtt]: set the RTT threshold (in ms) for desired neighbours\n"
|
112 | 9818ca86 | Csaba Kiraly | "\t[--desired_bw bw]: set the BW threshold (in bits/s) for desired neighbours. Use of K(ilo), M(ega) allowed, e.g 0.8M\n"
|
113 | f672dcde | Csaba Kiraly | "\t[--topo_mem p]: keep p (0..1) portion of peers between topology operations\n"
|
114 | 79ef0588 | Csaba Kiraly | "\t[--topo_out]: peers only choose out-neighbours\n"
|
115 | "\t[--topo_in]: peers only choose in-neighbours\n"
|
||
116 | "\t[--topo_bidir]: peers choose both in- and out-neighbours (bidir)\n"
|
||
117 | f6e9f400 | Csaba Kiraly | "\t[--topo_keep_best]: keep best peers, not random subset\n"
|
118 | "\t[--topo_add_best]: add best peers among desired ones, not random subset\n"
|
||
119 | a02fc4cf | MarcoMellia | "\n"
|
120 | "Special Source Peer options\n"
|
||
121 | "\t[-m chunks]: set the number of copies the source injects in the overlay.\n"
|
||
122 | "\t[-f filename]: name of the video stream file to transmit.\n"
|
||
123 | a2fa286f | Luca Abeni | "\t[-S]: set initial chunk_id (source only).\n"
|
124 | "\t[-s]: set start_id from which to start output.\n"
|
||
125 | "\t[-e]: set end_id at which to end output.\n"
|
||
126 | a02fc4cf | MarcoMellia | "\n"
|
127 | 4536b69e | Csaba Kiraly | "Special options\n"
|
128 | "\t[--randomize_start ms]: random wait before starting in to ms millisecs.\n"
|
||
129 | "\n"
|
||
130 | 60784aa1 | CsabaKiraly | "NOTE: by deafult the peer will dump the received video on STDOUT in raw format\n"
|
131 | a02fc4cf | MarcoMellia | " it can be played by your favourite player simply using a pipe\n"
|
132 | 60784aa1 | CsabaKiraly | " e.g., | cvlc /dev/stdin\n"
|
133 | a02fc4cf | MarcoMellia | "\n"
|
134 | "Examples:\n"
|
||
135 | "\n"
|
||
136 | "Start a source peer on port 6600:\n"
|
||
137 | "\n"
|
||
138 | 60784aa1 | CsabaKiraly | "%s -l -f foreman.mpg -P 6600\n"
|
139 | a02fc4cf | MarcoMellia | "\n"
|
140 | "Start a peer connecting to the previous source, and using videolan as player:\n"
|
||
141 | "\n"
|
||
142 | 60784aa1 | CsabaKiraly | "%s -i <sourceIP> -p <sourcePort> | cvlc /dev/stdin\n"
|
143 | "=======================================================\n", argv[0], argv[0], argv[0] |
||
144 | a02fc4cf | MarcoMellia | ); |
145 | } |
||
146 | |||
147 | |||
148 | c7beb713 | Csaba Kiraly | static double atod_kmg(const char *s) { |
149 | double d;
|
||
150 | char *e;
|
||
151 | |||
152 | errno = 0;
|
||
153 | d = strtod(s, &e); |
||
154 | if (errno) {
|
||
155 | fprintf(stderr, "Error parsing option: %s\n", s);
|
||
156 | exit(-1);
|
||
157 | } |
||
158 | switch (*e) {
|
||
159 | case 'g': |
||
160 | case 'G': |
||
161 | d *= 1024;
|
||
162 | case 'm': |
||
163 | case 'M': |
||
164 | d *= 1024;
|
||
165 | case 'k': |
||
166 | case 'K': |
||
167 | d *= 1024;
|
||
168 | case 0: |
||
169 | break;
|
||
170 | default:
|
||
171 | fprintf(stderr, "Error parsing option: %s\n", s);
|
||
172 | exit(-1);
|
||
173 | } |
||
174 | |||
175 | return d;
|
||
176 | } |
||
177 | a02fc4cf | MarcoMellia | |
178 | 89e893e2 | Luca | static void cmdline_parse(int argc, char *argv[]) |
179 | { |
||
180 | int o;
|
||
181 | |||
182 | 4aaa8891 | MatteoSammarco | int option_index = 0; |
183 | static struct option long_options[] = { |
||
184 | e63b7606 | MatteoSammarco | {"chunk_log", no_argument, 0, 0}, |
185 | 75b2b975 | Csaba Kiraly | {"measure_start", required_argument, 0, 0}, |
186 | {"measure_every", required_argument, 0, 0}, |
||
187 | 3730fda0 | Csaba Kiraly | {"playout_limit", required_argument, 0, 0}, |
188 | 4536b69e | Csaba Kiraly | {"randomize_start", required_argument, 0, 0}, |
189 | 839ae781 | Csaba Kiraly | {"capacity_override", required_argument, 0, 0}, |
190 | 9818ca86 | Csaba Kiraly | {"desired_bw", required_argument, 0, 0}, |
191 | f672dcde | Csaba Kiraly | {"topo_mem", required_argument, 0, 0}, |
192 | 79ef0588 | Csaba Kiraly | {"topo_in", no_argument, 0, 0}, |
193 | {"topo_out", no_argument, 0, 0}, |
||
194 | {"topo_bidir", no_argument, 0, 0}, |
||
195 | f6e9f400 | Csaba Kiraly | {"topo_keep_best", no_argument, 0, 0}, |
196 | {"topo_add_best", no_argument, 0, 0}, |
||
197 | e63b7606 | MatteoSammarco | {0, 0, 0, 0} |
198 | 4aaa8891 | MatteoSammarco | }; |
199 | |||
200 | a2fa286f | Luca Abeni | while ((o = getopt_long (argc, argv, "r:a:b:o:c:p:i:P:I:f:F:m:lC:N:n:M:t:s:e:S:",long_options, &option_index)) != -1) { //use this function to manage long options |
201 | 89e893e2 | Luca | switch(o) {
|
202 | 4aaa8891 | MatteoSammarco | case 0: //for long options |
203 | 1cd06c26 | CsabaKiraly | if( strcmp( "chunk_log", long_options[option_index].name ) == 0 ) { chunk_log = true; } |
204 | d8288eb0 | Csaba Kiraly | #ifndef MONL
|
205 | 75b2b975 | Csaba Kiraly | if( strcmp( "measure_start", long_options[option_index].name ) == 0 ) { tstartdiff.tv_sec = atoi(optarg); } |
206 | if( strcmp( "measure_every", long_options[option_index].name ) == 0 ) { print_tdiff.tv_sec = atoi(optarg); } |
||
207 | d8288eb0 | Csaba Kiraly | #endif
|
208 | 3730fda0 | Csaba Kiraly | if( strcmp( "playout_limit", long_options[option_index].name ) == 0 ) { CB_SIZE_TIME = atoi(optarg); } |
209 | 4536b69e | Csaba Kiraly | if( strcmp( "randomize_start", long_options[option_index].name ) == 0 ) { randomize_start = atoi(optarg); } |
210 | 839ae781 | Csaba Kiraly | if( strcmp( "capacity_override", long_options[option_index].name ) == 0 ) { capacity_override = atod_kmg(optarg); } |
211 | 9818ca86 | Csaba Kiraly | if( strcmp( "desired_bw", long_options[option_index].name ) == 0 ) { desired_bw = atod_kmg(optarg); } |
212 | f672dcde | Csaba Kiraly | if( strcmp( "topo_mem", long_options[option_index].name ) == 0 ) { topo_mem = atof(optarg); } |
213 | 79ef0588 | Csaba Kiraly | else if( strcmp( "topo_in", long_options[option_index].name ) == 0 ) { topo_in = true; topo_out = false; } |
214 | else if( strcmp( "topo_out", long_options[option_index].name ) == 0 ) { topo_in = false; topo_out = true; } |
||
215 | else if( strcmp( "topo_bidir", long_options[option_index].name ) == 0 ) { topo_in = true; topo_out = true; } |
||
216 | f6e9f400 | Csaba Kiraly | else if( strcmp( "topo_keep_best", long_options[option_index].name ) == 0 ) { topo_keep_best = true; } |
217 | else if( strcmp( "topo_add_best", long_options[option_index].name ) == 0 ) { topo_add_best = true; } |
||
218 | 1cd06c26 | CsabaKiraly | break;
|
219 | 4ca3a6bd | Luca Abeni | case 'a': |
220 | alpha_target = (double)atoi(optarg) / 100.0; |
||
221 | break;
|
||
222 | case 'r': |
||
223 | desired_rtt = (double)atoi(optarg) / 1000.0; |
||
224 | break;
|
||
225 | 90f3a290 | CsabaKiraly | case 'b': |
226 | 0a40460a | Luca | buff_size = atoi(optarg); |
227 | break;
|
||
228 | 90f3a290 | CsabaKiraly | case 'o': |
229 | f0bb64e2 | Csaba Kiraly | outbuff_size = atoi(optarg); |
230 | break;
|
||
231 | 90f3a290 | CsabaKiraly | case 'c': |
232 | 0a40460a | Luca | chunks_per_second = atoi(optarg); |
233 | break;
|
||
234 | 90f3a290 | CsabaKiraly | case 'm': |
235 | 59b7cfc6 | Csaba Kiraly | multiply = atoi(optarg); |
236 | break;
|
||
237 | 90f3a290 | CsabaKiraly | case 'p': |
238 | 89e893e2 | Luca | srv_port = atoi(optarg); |
239 | break;
|
||
240 | 90f3a290 | CsabaKiraly | case 'i': |
241 | 89e893e2 | Luca | srv_ip = strdup(optarg); |
242 | break;
|
||
243 | 90f3a290 | CsabaKiraly | case 'P': |
244 | 89e893e2 | Luca | port = atoi(optarg); |
245 | break;
|
||
246 | 90f3a290 | CsabaKiraly | case 'I': |
247 | 568bd1bd | Luca Abeni | my_iface = strdup(optarg); |
248 | 89e893e2 | Luca | break;
|
249 | 90f3a290 | CsabaKiraly | case 'f': |
250 | e37511b1 | Luca Abeni | fname = strdup(optarg); |
251 | break;
|
||
252 | 463000a4 | CsabaKiraly | case 'F': |
253 | output_config = strdup(optarg); |
||
254 | break;
|
||
255 | 90f3a290 | CsabaKiraly | case 'C': |
256 | 581339c4 | Csaba Kiraly | channel_set_name(optarg); |
257 | 8253c8ea | CsabaKiraly | break;
|
258 | 193622ac | CsabaKiraly | case 'n': |
259 | net_helper_config = strdup(optarg); |
||
260 | 581339c4 | Csaba Kiraly | break;
|
261 | 7c21b5b1 | CsabaKiraly | case 'N': |
262 | peername = strdup(optarg); |
||
263 | break;
|
||
264 | 20663df3 | Csaba Kiraly | case 'M': |
265 | NEIGHBORHOOD_TARGET_SIZE = atoi(optarg); |
||
266 | break;
|
||
267 | 5f72f6b3 | Csaba Kiraly | case 't': |
268 | topo_config = strdup(optarg); |
||
269 | break;
|
||
270 | a2fa286f | Luca Abeni | case 'S': |
271 | initial_id = atoi(optarg); |
||
272 | break;
|
||
273 | case 's': |
||
274 | start_id = atoi(optarg); |
||
275 | break;
|
||
276 | case 'e': |
||
277 | end_id = atoi(optarg); |
||
278 | break;
|
||
279 | 89e893e2 | Luca | default:
|
280 | fprintf(stderr, "Error: unknown option %c\n", o);
|
||
281 | 43c2d7d6 | CsabaKiraly | print_usage(argc, argv); |
282 | 89e893e2 | Luca | |
283 | exit(-1);
|
||
284 | } |
||
285 | } |
||
286 | 581339c4 | Csaba Kiraly | |
287 | if (!channel_get_name()) {
|
||
288 | channel_set_name("generic");
|
||
289 | } |
||
290 | 37b749c8 | CsabaKiraly | |
291 | if (argc <= 1) { |
||
292 | print_usage(argc, argv); |
||
293 | fprintf(stderr, "Trying to start a source with default parameters, reading from %s\n", fname);
|
||
294 | } |
||
295 | 89e893e2 | Luca | } |
296 | |||
297 | 1d21cb23 | Csaba Kiraly | const struct nodeID *get_my_addr(void) |
298 | { |
||
299 | return my_sock;
|
||
300 | } |
||
301 | |||
302 | 7a673aa5 | Csaba Kiraly | static void init_rand(const char * s) |
303 | { |
||
304 | long i, l, x;
|
||
305 | struct timeval t;
|
||
306 | |||
307 | gettimeofday(&t, NULL);
|
||
308 | |||
309 | x = 1;
|
||
310 | l = strlen(s); |
||
311 | for (i = 0; i < l; i++) { |
||
312 | x *= s[i]; |
||
313 | } |
||
314 | |||
315 | srand(t.tv_usec * t.tv_sec * x); |
||
316 | } |
||
317 | |||
318 | 89e893e2 | Luca | static struct nodeID *init(void) |
319 | { |
||
320 | bdd19faf | Csaba Kiraly | int i;
|
321 | 89e893e2 | Luca | struct nodeID *myID;
|
322 | 613263e9 | Csaba Kiraly | char *my_addr;
|
323 | |||
324 | if (my_iface) {
|
||
325 | my_addr = iface_addr(my_iface); |
||
326 | } else {
|
||
327 | 371a4639 | Csaba Kiraly | my_addr = default_ip_addr(); |
328 | 613263e9 | Csaba Kiraly | } |
329 | 89e893e2 | Luca | |
330 | f858e682 | Luca Abeni | if (my_addr == NULL) { |
331 | fprintf(stderr, "Cannot find network interface %s\n", my_iface);
|
||
332 | |||
333 | return NULL; |
||
334 | } |
||
335 | 33d23b91 | MarcoBiazzini | for (i=0;i<2;i++) |
336 | bdd19faf | Csaba Kiraly | bind_msg_type(msgTypes[i]); |
337 | 193622ac | CsabaKiraly | myID = net_helper_init(my_addr, port, net_helper_config); |
338 | 4136911a | Luca Abeni | if (myID == NULL) { |
339 | 89e893e2 | Luca | fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
|
340 | 568bd1bd | Luca Abeni | free(my_addr); |
341 | 4136911a | Luca Abeni | |
342 | e63ea799 | Luca | return NULL; |
343 | 89e893e2 | Luca | } |
344 | 568bd1bd | Luca Abeni | free(my_addr); |
345 | 5331023a | CsabaKiraly | fprintf(stderr, "My network ID is: %s\n", node_addr(myID));
|
346 | 7a673aa5 | Csaba Kiraly | |
347 | init_rand(node_addr(myID)); |
||
348 | |||
349 | 5f72f6b3 | Csaba Kiraly | topologyInit(myID, topo_config); |
350 | 89e893e2 | Luca | |
351 | return myID;
|
||
352 | } |
||
353 | |||
354 | 5dcfffbc | CsabaKiraly | void leave(int sig) { |
355 | a4a7d0f1 | Csaba Kiraly | fprintf(stderr, "Received signal %d, exiting!\n", sig);
|
356 | a8a31ce0 | Csaba Kiraly | end_measures(); |
357 | 5dcfffbc | CsabaKiraly | exit(sig); |
358 | } |
||
359 | 89e893e2 | Luca | |
360 | 4536b69e | Csaba Kiraly | static void random_wait(int max) { |
361 | struct timespec t;
|
||
362 | uint64_t ms; |
||
363 | |||
364 | ms = (rand()/(RAND_MAX + 1.0)) * max; |
||
365 | t.tv_sec = ms / 1000000;
|
||
366 | t.tv_nsec = (ms % 1000000) * 1000; |
||
367 | nanosleep(&t, NULL);
|
||
368 | } |
||
369 | |||
370 | 89e893e2 | Luca | int main(int argc, char *argv[]) |
371 | { |
||
372 | |||
373 | 5dcfffbc | CsabaKiraly | (void) signal(SIGTERM,leave);
|
374 | fbf7067c | Csaba Kiraly | (void) signal(SIGINT,leave);
|
375 | 5dcfffbc | CsabaKiraly | |
376 | 89e893e2 | Luca | cmdline_parse(argc, argv); |
377 | |||
378 | my_sock = init(); |
||
379 | e63ea799 | Luca | if (my_sock == NULL) { |
380 | 1931ff6c | Csaba Kiraly | fprintf(stderr, "Cannot initialize streamer, exiting!\n");
|
381 | e63ea799 | Luca | return -1; |
382 | } |
||
383 | 89e893e2 | Luca | if (srv_port != 0) { |
384 | 74a5d4ae | CsabaKiraly | struct nodeID *srv;
|
385 | 89e893e2 | Luca | |
386 | d7a4d49c | Csaba Kiraly | //random wait a bit before starting
|
387 | 4536b69e | Csaba Kiraly | if (randomize_start) random_wait(randomize_start);
|
388 | d7a4d49c | Csaba Kiraly | |
389 | 463000a4 | CsabaKiraly | output_init(outbuff_size, output_config); |
390 | |||
391 | 4136911a | Luca Abeni | srv = create_node(srv_ip, srv_port); |
392 | 0f23522a | Luca | if (srv == NULL) { |
393 | fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
|
||
394 | |||
395 | return -1; |
||
396 | } |
||
397 | f088e50e | MarcoBiazzini | topoAddNeighbour(srv, NULL, 0); |
398 | 89e893e2 | Luca | |
399 | 0a40460a | Luca | loop(my_sock, 1000000 / chunks_per_second, buff_size);
|
400 | 98c28f0f | CsabaKiraly | } else {
|
401 | 03de31e0 | Csaba Kiraly | source_loop(fname, my_sock, period * 1000, multiply, buff_size);
|
402 | 89e893e2 | Luca | } |
403 | return 0; |
||
404 | } |
||
405 | b88c9f4a | Csaba Kiraly | |
406 | 70921454 | Csaba Kiraly | int am_i_source()
|
407 | { |
||
408 | return (srv_port == 0); |
||
409 | } |
||
410 | |||
411 | b88c9f4a | Csaba Kiraly | int get_cb_size()
|
412 | { |
||
413 | return buff_size;
|
||
414 | } |
||
415 | 815ebf31 | Csaba Kiraly | |
416 | int get_chunks_per_sec()
|
||
417 | { |
||
418 | return chunks_per_second;
|
||
419 | } |
||
420 | 839ae781 | Csaba Kiraly | |
421 | //capacity in bits/s, or NAN if unknown
|
||
422 | double get_capacity()
|
||
423 | { |
||
424 | return capacity_override;
|
||
425 | } |