diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ot_config.c | 10 | ||||
| -rw-r--r-- | src/ot_livesync.c | 18 | ||||
| -rw-r--r-- | src/ot_livesync.h | 4 |
3 files changed, 26 insertions, 6 deletions
diff --git a/src/ot_config.c b/src/ot_config.c index 95136b5..6b51c61 100644 --- a/src/ot_config.c +++ b/src/ot_config.c | |||
| @@ -208,6 +208,7 @@ typedef enum { | |||
| 208 | CONFIG_TRACKER_REDIRECT_URL, | 208 | CONFIG_TRACKER_REDIRECT_URL, |
| 209 | CONFIG_LIVESYNC_CLUSTER_NODE_IP, | 209 | CONFIG_LIVESYNC_CLUSTER_NODE_IP, |
| 210 | CONFIG_LIVESYNC_CLUSTER_LISTEN, | 210 | CONFIG_LIVESYNC_CLUSTER_LISTEN, |
| 211 | CONFIG_LIVESYNC_CLUSTER_GROUP, | ||
| 211 | } config_kind; | 212 | } config_kind; |
| 212 | 213 | ||
| 213 | typedef struct { | 214 | typedef struct { |
| @@ -247,6 +248,7 @@ static const config_key config_keys[] = { | |||
| 247 | #ifdef WANT_SYNC_LIVE | 248 | #ifdef WANT_SYNC_LIVE |
| 248 | CONFIG_KEY("livesync.cluster.node_ip", CONFIG_LIVESYNC_CLUSTER_NODE_IP), | 249 | CONFIG_KEY("livesync.cluster.node_ip", CONFIG_LIVESYNC_CLUSTER_NODE_IP), |
| 249 | CONFIG_KEY("livesync.cluster.listen", CONFIG_LIVESYNC_CLUSTER_LISTEN), | 250 | CONFIG_KEY("livesync.cluster.listen", CONFIG_LIVESYNC_CLUSTER_LISTEN), |
| 251 | CONFIG_KEY("livesync.cluster.group", CONFIG_LIVESYNC_CLUSTER_GROUP), | ||
| 250 | #endif | 252 | #endif |
| 251 | }; | 253 | }; |
| 252 | static const size_t config_entry_count = sizeof(config_keys) / sizeof(config_keys[0]); | 254 | static const size_t config_entry_count = sizeof(config_keys) / sizeof(config_keys[0]); |
| @@ -318,7 +320,7 @@ static int parse_configfile(char *config_filename) { | |||
| 318 | int off = scan_ip6_port(p, tmpip, &tmpport); | 320 | int off = scan_ip6_port(p, tmpip, &tmpport); |
| 319 | 321 | ||
| 320 | if (!off || !listen_scan_options(p + off, &shared, &workers)) | 322 | if (!off || !listen_scan_options(p + off, &shared, &workers)) |
| 321 | goto parse_error; | 323 | exerr("listen.tcp, listen.udp and listen.tcp_udp want an address, optionally a port and options."); |
| 322 | if (kind != CONFIG_LISTEN_UDP) | 324 | if (kind != CONFIG_LISTEN_UDP) |
| 323 | listen_append(tmpip, tmpport, FLAG_TCP, shared, workers), ++bound; | 325 | listen_append(tmpip, tmpport, FLAG_TCP, shared, workers), ++bound; |
| 324 | if (kind != CONFIG_LISTEN_TCP) | 326 | if (kind != CONFIG_LISTEN_TCP) |
| @@ -378,6 +380,10 @@ static int parse_configfile(char *config_filename) { | |||
| 378 | set_config_option(&g_redirecturl, p); | 380 | set_config_option(&g_redirecturl, p); |
| 379 | break; | 381 | break; |
| 380 | #ifdef WANT_SYNC_LIVE | 382 | #ifdef WANT_SYNC_LIVE |
| 383 | case CONFIG_LIVESYNC_CLUSTER_GROUP: | ||
| 384 | if (!ip_parse(p, tmpip) || livesync_set_group(tmpip) == -1) | ||
| 385 | exerr("livesync.cluster.group wants a multicast address, out of 224.0.0.0/4."); | ||
| 386 | break; | ||
| 381 | case CONFIG_LIVESYNC_CLUSTER_NODE_IP: | 387 | case CONFIG_LIVESYNC_CLUSTER_NODE_IP: |
| 382 | if (!scan_ip6_net(p, &tmpnet)) | 388 | if (!scan_ip6_net(p, &tmpnet)) |
| 383 | goto parse_error; | 389 | goto parse_error; |
| @@ -440,7 +446,7 @@ static void help(char *name) { | |||
| 440 | fprintf(stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -f ./opentracker.conf -i 10.1.1.23 -p 2710 -p 80\n"); | 446 | fprintf(stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -f ./opentracker.conf -i 10.1.1.23 -p 2710 -p 80\n"); |
| 441 | fprintf(stderr, " Here -i 127.0.0.1 selects the ip address for the next -p 6969 and -P 6969.\n"); | 447 | fprintf(stderr, " Here -i 127.0.0.1 selects the ip address for the next -p 6969 and -P 6969.\n"); |
| 442 | fprintf(stderr, " If no port is bound from config file or command line, the last address given\n"); | 448 | fprintf(stderr, " If no port is bound from config file or command line, the last address given\n"); |
| 443 | fprintf(stderr, " (or ::1 if none is set) will be used on port 6969.\n"); | 449 | fprintf(stderr, " is used on port 6969, and every interface if none was given.\n"); |
| 444 | } | 450 | } |
| 445 | #undef HELPLINE | 451 | #undef HELPLINE |
| 446 | 452 | ||
diff --git a/src/ot_livesync.c b/src/ot_livesync.c index 11b75d2..85577f7 100644 --- a/src/ot_livesync.c +++ b/src/ot_livesync.c | |||
| @@ -22,8 +22,10 @@ | |||
| 22 | 22 | ||
| 23 | #ifdef WANT_SYNC_LIVE | 23 | #ifdef WANT_SYNC_LIVE |
| 24 | 24 | ||
| 25 | ot_ip6 groupip_1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 224, 0, 23, 5}; | 25 | /* The multicast group, legacy opentrackers joined by default 224.0.23.5, so it |
| 26 | static uint16_t g_port = LIVESYNC_PORT; | 26 | stays the default */ |
| 27 | static ot_ip6 g_group = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 224, 0, 23, 5}; | ||
| 28 | static uint16_t g_port = LIVESYNC_PORT; | ||
| 27 | 29 | ||
| 28 | #define LIVESYNC_INCOMING_BUFFSIZE (256 * 256) | 30 | #define LIVESYNC_INCOMING_BUFFSIZE (256 * 256) |
| 29 | 31 | ||
| @@ -96,6 +98,14 @@ void livesync_deinit(void) { | |||
| 96 | close(g_socket_out); | 98 | close(g_socket_out); |
| 97 | } | 99 | } |
| 98 | 100 | ||
| 101 | int livesync_set_group(const ot_ip6 group) { | ||
| 102 | /* v4 multicast is 224.0.0.0/4, and the socket layer has nothing else */ | ||
| 103 | if (!ip_is_v4mapped(group) || (group[12] & 0xf0) != 0xe0) | ||
| 104 | return -1; | ||
| 105 | memcpy(g_group, group, sizeof(ot_ip6)); | ||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | |||
| 99 | void livesync_bind_mcast(ot_ip6 ip, uint16_t port) { | 109 | void livesync_bind_mcast(ot_ip6 ip, uint16_t port) { |
| 100 | if (!ip_is_v4mapped(ip)) | 110 | if (!ip_is_v4mapped(ip)) |
| 101 | exerr("v6 mcast support not yet available."); | 111 | exerr("v6 mcast support not yet available."); |
| @@ -105,7 +115,7 @@ void livesync_bind_mcast(ot_ip6 ip, uint16_t port) { | |||
| 105 | 115 | ||
| 106 | g_port = port; | 116 | g_port = port; |
| 107 | 117 | ||
| 108 | if ((g_socket_in = socket_mcast_join(groupip_1, ip, port)) == -1) | 118 | if ((g_socket_in = socket_mcast_join(g_group, ip, port)) == -1) |
| 109 | exerr("Error: Cant bind live sync incoming socket."); | 119 | exerr("Error: Cant bind live sync incoming socket."); |
| 110 | 120 | ||
| 111 | if ((g_socket_out = socket_mcast_bind(ip, port, 0)) == -1) | 121 | if ((g_socket_out = socket_mcast_bind(ip, port, 0)) == -1) |
| @@ -125,7 +135,7 @@ static void livesync_issue_peersync(sync_buffer *buf) { | |||
| 125 | has modified the protected element */ | 135 | has modified the protected element */ |
| 126 | pthread_mutex_unlock(&g_outbuf_mutex); | 136 | pthread_mutex_unlock(&g_outbuf_mutex); |
| 127 | 137 | ||
| 128 | socket_mcast_send(g_socket_out, mycopy, fill, groupip_1, g_port); | 138 | socket_mcast_send(g_socket_out, mycopy, fill, g_group, g_port); |
| 129 | } | 139 | } |
| 130 | 140 | ||
| 131 | static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size) { | 141 | static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size) { |
diff --git a/src/ot_livesync.h b/src/ot_livesync.h index d8d20b3..cf3c64c 100644 --- a/src/ot_livesync.h +++ b/src/ot_livesync.h | |||
| @@ -48,6 +48,10 @@ | |||
| 48 | void livesync_init(void); | 48 | void livesync_init(void); |
| 49 | void livesync_deinit(void); | 49 | void livesync_deinit(void); |
| 50 | 50 | ||
| 51 | /* The group to join and to send to, (defaults to 224.0.23.5). | ||
| 52 | Returns -1 if group is not a v4 multicast address. */ | ||
| 53 | int livesync_set_group(const ot_ip6 group); | ||
| 54 | |||
| 51 | /* Join multicast group for listening and create sending socket */ | 55 | /* Join multicast group for listening and create sending socket */ |
| 52 | void livesync_bind_mcast(ot_ip6 ip, uint16_t port); | 56 | void livesync_bind_mcast(ot_ip6 ip, uint16_t port); |
| 53 | 57 | ||
