Debian Codegraph @

tools/rist2rist.c

raw symbols SCIP
1 /* librist. Copyright © 2020 SipRadius LLC. All right reserved.
2 * Author: Gijs Peskens
3 * Author: Sergio Ammirata, Ph.D. <[email protected]>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8 /* rist2rist receive simple profile rist and expose it as main profile */
9
10 #include <librist/librist.h>
11 #include "librist/version.h"
12 #include "risturlhelp.h"
13 #include "config.h"
14 #if HAVE_SRP_SUPPORT
15 #include "librist/librist_srp.h"
16 #include "srp_shared.h"
17 #endif
18 #if HAVE_PROMETHEUS_SUPPORT
19 #include "prometheus-exporter.h"
20 #endif
21 #include "vcs_version.h"
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include "getopt-shim.h"
26 #include <assert.h>
27 #include <signal.h>
28 #ifdef __unix
29 #include <unistd.h>
30 #endif
31 #include "oob_shared.h"
32 #include "string-shim.h"
33
34 #define RIST2RIST_VERSION "31"
35
36 struct rist_sender_args {
37 char* cname;
38 char* shared_secret;
39 char* outputurl;
40 uint16_t dst_port;
41 enum rist_log_level loglevel;
42 int encryption_type;
43 uint32_t flow_id;
44 int statsinterval;
45 int npd_enabled;
46 };
47
48 struct rist_cb_arg {
49 uint16_t src_port;
50 uint16_t dst_port;
51 struct rist_ctx *sender_ctx;
52 struct rist_sender_args *client_args;
53 };
54
55 static int keep_running = 1;
56 static struct rist_logging_settings logging_settings = LOGGING_SETTINGS_INITIALIZER;
57
58 #if HAVE_PROMETHEUS_SUPPORT
59 static struct rist_prometheus_stats *prom_stats_ctx = NULL;
60 static bool prometheus_httpd = false;
61 static bool enable_prometheus = false;
62 static char *prometheus_tags = NULL;
63 static uint16_t prometheus_port = 9100;
64 static char *prometheus_ip = NULL;
65 #endif
66
67 static struct option long_options[] = {
68 { "inurl", required_argument, NULL, 'i' },
69 { "outurl", required_argument, NULL, 'o' },
70 { "secret", required_argument, NULL, 's' },
71 { "encryption-type", required_argument, NULL, 'e' },
72 { "cname", required_argument, NULL, 'N' },
73 { "statsinterval", required_argument, NULL, 'S' },
74 { "verbose-level", required_argument, NULL, 'v' },
75 { "remote-logging", required_argument, NULL, 'r' },
76 { "profile", required_argument, NULL, 'p' },
77 { "npd", no_argument, NULL, 'n' },
78 #if HAVE_SRP_SUPPORT
79 { "srpfile", required_argument, NULL, 'F' },
80 #endif
81 #if HAVE_PROMETHEUS_SUPPORT
82 { "enable-metrics", no_argument, NULL, 'M' },
83 { "metrics-tags", required_argument, NULL, 1 },
84 #if HAVE_LIBMICROHTTPD
85 { "metrics-http", no_argument, NULL, 4 },
86 { "metrics-port", required_argument, NULL, 2 },
87 { "metrics-ip", required_argument, NULL, 3 },
88 #endif
89 #endif
90 { "help", no_argument, NULL, 'h' },
91 { 0, 0, 0, 0 },
92 };
93
94 const char help_str[] = "Where OPTIONS are:\n"
95 " -i | --inurl ADDRESS:PORT[,ADDR:PORT]* * | Input URL (comma-separated list for source bonding) |\n"
96 " -o | --outurl ADDRESS:PORT[,ADDR:PORT]* * | Output URL (comma-separated list for destination fanout) |\n"
97 " -s | --secret PWD | Pre-shared encryption secret |\n"
98 " -e | --encryption-type TYPE | Encryption type (0 = none, 1 = AES-128, 2 = AES-256) |\n"
99 " -S | --statsinterval value (ms) | Interval at which stats get printed, 0 to disable |\n"
100 " -N | --cname identifier | Manually configured identifier |\n"
101 " -v | --verbose-level value | To disable logging: -1, log levels match syslog levels |\n"
102 " -r | --remote-logging IP:PORT | Send logs and stats to this IP:PORT using udp messages |\n"
103 " -p | --profile number | Rist receive profile (0 = simple, 1 = main, 2 = advanced)|\n"
104 " -n | --npd | Enable Null Packet Deletion on output |\n"
105 #if HAVE_SRP_SUPPORT
106 " -F | --srpfile filepath | When in listening mode, use this file to hold the list |\n"
107 " | of usernames and passwords to validate against. Use the |\n"
108 " | ristsrppasswd tool to create the line entries. |\n"
109 #endif
110 #if HAVE_PROMETHEUS_SUPPORT
111 " -M | --enable-metrics | Enable OpenMetrics/Prometheus compatible metrics |\n"
112 " | --metrics-tags | Additional tags to add to the metrics |\n"
113 #if HAVE_LIBMICROHTTPD
114 " | --metrics-http | Start HTTP server to expose metrics |\n"
115 " | --metrics-port | Port for metrics HTTP server (default: 9100) |\n"
116 " | --metrics-ip | IP for metrics HTTP server (default: 0.0.0.0) |\n"
117 #endif
118 #endif
119 " -h | --help | Show this help |\n"
120 " -u | --help-url | Show all the possible url options |\n"
121 " * == mandatory value \n"
122 "Default values:\n"
123 " --profile 0 \\\n"
124 " --statsinterval 1000 \\\n"
125 " --verbose-level 6 \n";
126
127 #if HAVE_SRP_SUPPORT
128 char *srpfile = NULL;
129 #endif
130
131 static void usage(char *cmd)
132 {
133 rist_log(&logging_settings, RIST_LOG_INFO,
134 "rist2rist version %s libRIST library: %s API version: %s\n"
135 "Usage: %s [OPTIONS]\n%s",
136 RIST2RIST_VERSION, librist_version(), librist_api_version(),
137 cmd, help_str);
138 exit(1);
139 }
140
141 static int cb_auth_connect(void *arg, const char* connecting_ip, uint16_t connecting_port, const char* local_ip, uint16_t local_port, struct rist_peer *peer)
142 {
143 struct rist_ctx *receiver_ctx = (struct rist_ctx *)arg;
144 uint16_t buffer[250];
145 char message[200];
146 int message_len = snprintf(message, 200, "auth,%s:%d,%s:%d", connecting_ip, connecting_port, local_ip, local_port);
147 // To be compliant with the spec, the message must have an ipv4 header
148 int ret = oob_build_api_payload(buffer, (char *)connecting_ip, (char *)local_ip, message, message_len);
149 rist_log(&logging_settings, RIST_LOG_INFO,"Peer has been authenticated, sending oob/api message: %s\n", message);
150 struct rist_oob_block oob_block;
151 oob_block.peer = peer;
152 oob_block.payload = buffer;
153 oob_block.payload_len = ret;
154 rist_oob_write(receiver_ctx, &oob_block);
155 return 0;
156 }
157
158 static int cb_auth_disconnect(void *arg, struct rist_peer *peer)
159 {
160 (void)peer;
161 struct rist_ctx *ctx = (struct rist_ctx *)arg;
162 (void)ctx;
163 return 0;
164 }
165
166 static int cb_recv_oob(void *arg, const struct rist_oob_block *oob_block)
167 {
168 struct rist_ctx *ctx = (struct rist_ctx *)arg;
169 (void)ctx;
170 int message_len = 0;
171 char *message = oob_process_api_message((int)oob_block->payload_len, (char *)oob_block->payload, &message_len);
172 if (message) {
173 rist_log(&logging_settings, RIST_LOG_INFO,"Out-of-band api data received: %.*s\n", message_len, message);
174 }
175 return 0;
176 }
177
178 static int cb_stats(void *arg, const struct rist_stats *stats_container) {
179 rist_log(&logging_settings, RIST_LOG_INFO, "%s\n\n", stats_container->stats_json);
180 #if HAVE_PROMETHEUS_SUPPORT
181 if (prom_stats_ctx) {
182 rist_prometheus_parse_stats(prom_stats_ctx, stats_container, (uintptr_t)arg);
183 }
184 #else
185 (void)arg;
186 #endif
187 rist_stats_free(stats_container);
188 return 0;
189 }
190
191 static struct rist_ctx* setup_rist_sender(struct rist_sender_args *setup) {
192 struct rist_ctx *ctx;
193 printf("CName: %s\n", setup->cname);
194 printf("Outurl: %s\n", setup->outputurl);
195 int rist;
196 if (rist_sender_create(&ctx, RIST_PROFILE_MAIN, setup->flow_id, &logging_settings) != 0) {
197 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not create rist sender context\n");
198 exit(1);
199 }
200
201 rist = rist_auth_handler_set(ctx, cb_auth_connect, cb_auth_disconnect, ctx);
202 if (rist < 0) {
203 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not initialize rist auth handler\n");
204 exit(1);
205 }
206
207 if (rist_oob_callback_set(ctx, cb_recv_oob, ctx) == -1) {
208 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not add enable out-of-band data\n");
209 exit(1);
210 }
211
212 if (setup->statsinterval) {
213 /* Pass ctx pointer as user data so the Prometheus id is unique per
214 * context (receiver vs. sender) when both are active in the same
215 * process. */
216 rist_stats_callback_set(ctx, setup->statsinterval, cb_stats, ctx);
217 }
218
219 if (setup->npd_enabled) {
220 if (rist_sender_npd_enable(ctx) != 0) {
221 rist_log(&logging_settings, RIST_LOG_WARN, "Could not enable null-packet-deletion on sender\n");
222 } else {
223 rist_log(&logging_settings, RIST_LOG_INFO, "Null-packet-deletion enabled on sender\n");
224 }
225 }
226
227 int keysize = setup->encryption_type * 128;
228
229 /* Tokenize the output URL list on ',' and add one sender peer per token.
230 * Matches the convention used by ristsender/ristreceiver. */
231 char *saveptr = NULL;
232 char *outtoken = strtok_r(setup->outputurl, ",", &saveptr);
233 int peer_count = 0;
234 while (outtoken) {
235 /* Applications defaults reset per peer (URL parsing mutates config). */
236 struct rist_peer_config app_peer_config = {
237 .version = RIST_PEER_CONFIG_VERSION,
238 .virt_dst_port = setup->dst_port,
239 .recovery_mode = RIST_DEFAULT_RECOVERY_MODE,
240 .recovery_maxbitrate = RIST_DEFAULT_RECOVERY_MAXBITRATE,
241 .recovery_maxbitrate_return = RIST_DEFAULT_RECOVERY_MAXBITRATE_RETURN,
242 .recovery_length_min = RIST_DEFAULT_RECOVERY_LENGTH_MIN,
243 .recovery_length_max = RIST_DEFAULT_RECOVERY_LENGTH_MAX,
244 .recovery_reorder_buffer = RIST_DEFAULT_RECOVERY_REORDER_BUFFER,
245 .recovery_rtt_min = RIST_DEFAULT_RECOVERY_RTT_MIN,
246 .recovery_rtt_max = RIST_DEFAULT_RECOVERY_RTT_MAX,
247 .weight = 5,
248 .congestion_control_mode = RIST_DEFAULT_CONGESTION_CONTROL_MODE,
249 .min_retries = RIST_DEFAULT_MIN_RETRIES,
250 .max_retries = RIST_DEFAULT_MAX_RETRIES,
251 .key_size = keysize,
252 };
253
254 if (setup->shared_secret != NULL) {
255 strncpy(app_peer_config.secret, setup->shared_secret, RIST_MAX_STRING_SHORT -1);
256 }
257
258 if (setup->cname != NULL) {
259 strncpy(app_peer_config.cname, setup->cname, RIST_MAX_STRING_SHORT -1);
260 }
261
262 /* URL overrides (also cleans up the URL) */
263 struct rist_peer_config *peer_config = &app_peer_config;
264 if (rist_parse_address2(outtoken, &peer_config)) {
265 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not parse peer options for sender: %s\n", outtoken);
266 exit(1);
267 }
268
269 struct rist_peer *peer;
270 if (rist_peer_create(ctx, &peer, peer_config) == -1) {
271 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not add peer connector to sender: %s\n", outtoken);
272 exit(1);
273 }
274
275 #if HAVE_SRP_SUPPORT
276 int srp_error = 0;
277 if (strlen(peer_config->srp_username) > 0 && strlen(peer_config->srp_password) > 0)
278 {
279 srp_error = rist_enable_eap_srp_2(peer, peer_config->srp_username, peer_config->srp_password, NULL, NULL);
280 if (srp_error)
281 rist_log(&logging_settings, RIST_LOG_WARN, "Error %d trying to enable SRP for peer\n", srp_error);
282 }
283 if (srpfile)
284 {
285 srp_error = rist_enable_eap_srp_2(peer, NULL, NULL, user_verifier_lookup, srpfile);
286 if (srp_error)
287 rist_log(&logging_settings, RIST_LOG_WARN, "Error %d trying to enable SRP global authenticator, file %s\n", srp_error, srpfile);
288 }
289 #endif
290 peer_count++;
291 outtoken = strtok_r(NULL, ",", &saveptr);
292 }
293
294 if (peer_count == 0) {
295 rist_log(&logging_settings, RIST_LOG_ERROR, "No valid output peer URLs provided\n");
296 exit(1);
297 }
298
299 if (rist_start(ctx) == -1) {
300 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not start rist sender\n");
301 exit(1);
302 }
303 return ctx;
304 }
305
306 static int cb_recv(void *arg, struct rist_data_block *b)
307 {
308 struct rist_cb_arg *cb_arg = (struct rist_cb_arg *) arg;
309 struct rist_data_block *block = (struct rist_data_block*)b;
310 if (cb_arg->client_args->flow_id != b->flow_id) {
311 printf("Flow ID %ud\n",b->flow_id);
312 cb_arg->client_args->flow_id = b->flow_id;
313 assert(cb_arg->sender_ctx != NULL);
314 rist_sender_flow_id_set(cb_arg->sender_ctx, b->flow_id);
315 }
316 b->virt_src_port = cb_arg->src_port;
317 b->virt_dst_port = cb_arg->dst_port;
318 block->flags = RIST_DATA_FLAGS_USE_SEQ;//We only need this flag set, this way we don't have to null it beforehand.
319 int ret = rist_sender_data_write(cb_arg->sender_ctx, b);
320 rist_receiver_data_block_free2(&b);
321 return ret;
322 }
323
324 static void intHandler(int signal) {
325 rist_log(&logging_settings, RIST_LOG_NOTICE, "Signal %d received\n", signal);
326 keep_running = 0;
327 }
328
329 int main (int argc, char **argv) {
330 char *inputurl = NULL;
331 char *cname = NULL;
332 char *outputurl = NULL;
333 struct rist_cb_arg cb_arg;
334 struct rist_sender_args client_args;
335 cb_arg.client_args = &client_args;
336 cb_arg.src_port = 1971;
337 cb_arg.dst_port = 1968;
338 client_args.dst_port = 1968;
339 client_args.encryption_type = 0;
340 client_args.shared_secret = NULL;
341 client_args.flow_id = 0;
342 client_args.npd_enabled = 0;
343 int statsinterval = 1000;
344 enum rist_log_level loglevel = RIST_LOG_INFO;
345 char *remote_log_address = NULL;
346 int exitcode = 0;
347 enum rist_profile profile = RIST_PROFILE_SIMPLE;
348 #ifdef _WIN32
349 #define STDERR_FILENO 2
350 signal(SIGINT, intHandler);
351 signal(SIGTERM, intHandler);
352 signal(SIGABRT, intHandler);
353 #else
354 struct sigaction act = { {0} };
355 act.sa_handler = intHandler;
356 act.sa_flags = 0;
357 sigaction(SIGINT, &act, NULL);
358 #endif
359
360 // Default log settings
361 struct rist_logging_settings *log_ptr = &logging_settings;
362 if (rist_logging_set(&log_ptr, loglevel, NULL, NULL, NULL, stderr) != 0) {
363 fprintf(stderr,"Failed to setup default logging!\n");
364 exit(1);
365 }
366
367 rist_log(&logging_settings, RIST_LOG_INFO, "Starting rist2rist version: %s libRIST library: %s API version: %s\n", RIST2RIST_VERSION, librist_version(), librist_api_version());
368
369 int option_index;
370 int c;
371 /* Short-option string. Note: 'n' is flag-only (no argument), while 'M'
372 * (enable-metrics) is also flag-only. Long-only options use numeric
373 * return codes (see long_options). */
374 const char *short_opts =
375 #if HAVE_SRP_SUPPORT
376 "r:i:o:s:e:N:v:S:p:F:nMhu";
377 #else
378 "r:i:o:s:e:N:v:S:p:nMhu";
379 #endif
380 while ((c = getopt_long(argc, argv, short_opts, long_options, &option_index)) != -1) {
381 switch (c) {
382 case 'i':
383 if (inputurl != NULL)
384 goto usage;
385 inputurl = strdup(optarg);
386 break;
387 case 'o':
388 if (outputurl != NULL)
389 goto usage;
390 outputurl = strdup(optarg);
391 break;
392 case 's':
393 if (client_args.shared_secret != NULL)
394 goto usage;
395 client_args.shared_secret = strdup(optarg);
396 break;
397 case 'e':
398 client_args.encryption_type =atoi(optarg);
399 break;
400 case 'N':
401 if (cname != NULL)
402 goto usage;
403 cname = strdup(optarg);
404 break;
405 case 'p':
406 profile = atoi(optarg);
407 break;
408 case 'n':
409 client_args.npd_enabled = 1;
410 break;
411 case 'v':
412 loglevel = (enum rist_log_level) atoi(optarg);
413 break;
414 case 'r':
415 if (remote_log_address != NULL)
416 goto usage;
417 remote_log_address = strdup(optarg);
418 break;
419 #if HAVE_SRP_SUPPORT
420 case 'F': {
421 FILE* f = fopen(optarg, "r");
422 if (!f) {
423 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not open srp file %s\n", optarg);
424 return 1;
425 }
426 srpfile = strdup(optarg);
427 }
428 break;
429 #endif
430 #if HAVE_PROMETHEUS_SUPPORT
431 case 'M':
432 enable_prometheus = true;
433 break;
434 case 1:
435 if (prometheus_tags)
436 free(prometheus_tags);
437 prometheus_tags = strdup(optarg);
438 break;
439 #if HAVE_LIBMICROHTTPD
440 case 2:
441 prometheus_port = (uint16_t)atoi(optarg);
442 break;
443 case 3:
444 if (prometheus_ip)
445 free(prometheus_ip);
446 prometheus_ip = strdup(optarg);
447 break;
448 case 4:
449 prometheus_httpd = true;
450 break;
451 #endif
452 #endif
453 case 'S':
454 statsinterval = atoi(optarg);
455 break;
456 case 'u':
457 rist_log(&logging_settings, RIST_LOG_INFO, "%s", help_urlstr);
458 exit(1);
459 case 'h':
460 //
461 default:
462 usage:
463 usage(argv[0]);
464 break;
465 }
466 }
467 client_args.cname = cname;
468 client_args.loglevel = loglevel;
469 client_args.outputurl = outputurl;
470 client_args.statsinterval = statsinterval;
471
472 if (inputurl == NULL || outputurl == NULL) {
473 usage(argv[0]);
474 }
475
476 if (argc < 2) {
477 usage(argv[0]);
478 }
479
480 if (rist_logging_set(&log_ptr, loglevel, NULL, NULL, remote_log_address, stderr) != 0) {
481 fprintf(stderr, "Failed to setup logging!\n");
482 exitcode = 1;
483 goto out;;
484 }
485
486 #if HAVE_PROMETHEUS_SUPPORT
487 if (enable_prometheus) {
488 struct prometheus_httpd_options httpd_opt = {
489 .enabled = prometheus_httpd,
490 .port = prometheus_port,
491 .bind_sockaddr = false,
492 .ip = prometheus_ip,
493 };
494 prom_stats_ctx = rist_setup_prometheus_stats(log_ptr,
495 prometheus_tags,
496 /* multiple_metric_datapoints */ false,
497 /* skipcreated */ false,
498 &httpd_opt,
499 /* unix_socket */ NULL);
500 if (prom_stats_ctx == NULL) {
501 rist_log(&logging_settings, RIST_LOG_ERROR, "Failed to initialise Prometheus metrics exporter\n");
502 exitcode = 1;
503 goto out;
504 }
505 }
506 #endif
507
508 struct rist_ctx *receiver_ctx;
509
510 if (rist_receiver_create(&receiver_ctx, profile, &logging_settings) != 0) {
511 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not create rist receiver context\n");
512 exitcode = 1;
513 goto out;
514 }
515
516 if (rist_auth_handler_set(receiver_ctx, cb_auth_connect, cb_auth_disconnect, receiver_ctx) == -1) {
517 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not init rist auth handler\n");
518 exitcode = 1;
519 goto out;
520 }
521
522 struct rist_peer_config app_peer_config = {
523 .version = RIST_PEER_CONFIG_VERSION,
524 .virt_dst_port = RIST_DEFAULT_VIRT_DST_PORT,
525 .recovery_mode = RIST_DEFAULT_RECOVERY_MODE,
526 .recovery_maxbitrate = RIST_DEFAULT_RECOVERY_MAXBITRATE,
527 .recovery_maxbitrate_return = RIST_DEFAULT_RECOVERY_MAXBITRATE_RETURN,
528 .recovery_length_min = RIST_DEFAULT_RECOVERY_LENGTH_MIN,
529 .recovery_length_max = RIST_DEFAULT_RECOVERY_LENGTH_MAX,
530 .recovery_reorder_buffer = RIST_DEFAULT_RECOVERY_REORDER_BUFFER,
531 .recovery_rtt_min = RIST_DEFAULT_RECOVERY_RTT_MIN,
532 .recovery_rtt_max = RIST_DEFAULT_RECOVERY_RTT_MAX,
533 .weight = 5,
534 .congestion_control_mode = RIST_DEFAULT_CONGESTION_CONTROL_MODE,
535 .min_retries = RIST_DEFAULT_MIN_RETRIES,
536 .max_retries = RIST_DEFAULT_MAX_RETRIES,
537 .key_size = 0
538 };
539
540 if (cname != NULL) {
541 strncpy(app_peer_config.cname, cname, RIST_MAX_STRING_SHORT -1);
542 }
543
544 if (statsinterval) {
545 rist_stats_callback_set(receiver_ctx, statsinterval, cb_stats, receiver_ctx);
546 }
547
548 /* Tokenize the input URL list on ',' and add one receiver peer per token.
549 * Matches ristreceiver's convention for multi-peer/bonded inputs. */
550 char *rx_saveptr = NULL;
551 char *intoken = strtok_r(inputurl, ",", &rx_saveptr);
552 int rx_peer_count = 0;
553 while (intoken) {
554 struct rist_peer_config per_peer_config = app_peer_config;
555 struct rist_peer_config *peer_config = &per_peer_config;
556 if (rist_parse_address2(intoken, &peer_config)) {
557 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not parse peer options for receiver: %s\n", intoken);
558 exitcode = 1;
559 goto out;
560 }
561
562 struct rist_peer *peer;
563 if (rist_peer_create(receiver_ctx, &peer, peer_config) == -1) {
564 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not add peer connector to receiver: %s\n", intoken);
565 exitcode = 1;
566 goto out;
567 }
568 rx_peer_count++;
569 intoken = strtok_r(NULL, ",", &rx_saveptr);
570 }
571
572 if (rx_peer_count == 0) {
573 rist_log(&logging_settings, RIST_LOG_ERROR, "No valid input peer URLs provided\n");
574 exitcode = 1;
575 goto out;
576 }
577
578
579 // callback is best unless you are using the timestamps passed with the buffer
580 int enable_data_callback = 0;
581
582 if (enable_data_callback == 1) {
583 if (rist_receiver_data_callback_set2(receiver_ctx, cb_recv, &cb_arg))
584 {
585 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not set data_callback pointer");
586 exitcode = 1;
587 goto out;
588 }
589 }
590 cb_arg.sender_ctx = setup_rist_sender(&client_args);
591 if (rist_start(receiver_ctx)) {
592 rist_log(&logging_settings, RIST_LOG_ERROR, "Could not start rist receiver\n");
593 exitcode = 1;
594 goto out;
595 }
596 /* Start the rist protocol thread */
597 if (enable_data_callback == 1) {
598 #ifdef _WIN32
599 system("pause");
600 #else
601 pause();
602 #endif
603 }
604 else {
605 // Master loop
606 while (keep_running)
607 {
608 struct rist_data_block *b;
609 int ret = rist_receiver_data_read2(receiver_ctx, &b, 5);
610 if (ret && b && b->payload) cb_recv(&cb_arg, b);
611 }
612 }
613
614 rist_destroy(receiver_ctx);
615 rist_destroy(cb_arg.sender_ctx);
616 out:
617 #if HAVE_PROMETHEUS_SUPPORT
618 if (prom_stats_ctx) {
619 rist_prometheus_stats_destroy(prom_stats_ctx);
620 prom_stats_ctx = NULL;
621 }
622 if (prometheus_tags)
623 free(prometheus_tags);
624 if (prometheus_ip)
625 free(prometheus_ip);
626 #endif
627 rist_logging_unset_global();
628 if (client_args.shared_secret)
629 free(client_args.shared_secret);
630 if (cname)
631 free(cname);
632 if (inputurl)
633 free(inputurl);
634 if (outputurl)
635 free(outputurl);
636 if (remote_log_address)
637 free(remote_log_address);
638
639 return exitcode;
640 }