diff options
| -rw-r--r-- | man1/opentracker.1 | 16 | ||||
| -rw-r--r-- | man4/opentracker.conf.4 | 42 | ||||
| -rw-r--r-- | ot_http.c | 20 | ||||
| -rw-r--r-- | ot_vector.c | 9 |
4 files changed, 43 insertions, 44 deletions
diff --git a/man1/opentracker.1 b/man1/opentracker.1 index 85ded7b..0103ebe 100644 --- a/man1/opentracker.1 +++ b/man1/opentracker.1 | |||
| @@ -20,7 +20,6 @@ | |||
| 20 | is a bittorrent tracker that implements announce and scrape actions over the | 20 | is a bittorrent tracker that implements announce and scrape actions over the |
| 21 | UDP and the plain http protocol, aiming for minimal resource usage. | 21 | UDP and the plain http protocol, aiming for minimal resource usage. |
| 22 | .Pp | 22 | .Pp |
| 23 | |||
| 24 | When invoked with parameters, it binds to TCP and UDP port 6969 on all | 23 | When invoked with parameters, it binds to TCP and UDP port 6969 on all |
| 25 | interfaces. The recommended way to configure opentracker is by providing a | 24 | interfaces. The recommended way to configure opentracker is by providing a |
| 26 | config file using the | 25 | config file using the |
| @@ -29,17 +28,14 @@ option. See | |||
| 29 | .Xr opentracker.conf 4 | 28 | .Xr opentracker.conf 4 |
| 30 | for details. | 29 | for details. |
| 31 | .Pp | 30 | .Pp |
| 32 | |||
| 33 | .Sh OPTIONS | 31 | .Sh OPTIONS |
| 34 | The following options are available: | 32 | The following options are available: |
| 35 | |||
| 36 | .Bl -tag -width -indent=8 | 33 | .Bl -tag -width -indent=8 |
| 37 | .It Fl f Ar config | 34 | .It Fl f Ar config |
| 38 | Parse a config file with a list of options. Consecutive command options | 35 | Parse a config file with a list of options. Consecutive command options |
| 39 | will override options from the config file. See | 36 | will override options from the config file. See |
| 40 | .Xr opentracker.conf 4 | 37 | .Xr opentracker.conf 4 |
| 41 | for details. | 38 | for details. |
| 42 | |||
| 43 | .It Fl i Ar ip-select | 39 | .It Fl i Ar ip-select |
| 44 | Select an ip address that will be used with the next | 40 | Select an ip address that will be used with the next |
| 45 | .Op Fl p | 41 | .Op Fl p |
| @@ -90,15 +86,11 @@ or | |||
| 90 | .Br WANT_ACCESSLIST_WHITE | 86 | .Br WANT_ACCESSLIST_WHITE |
| 91 | options, this option sets the location of the accesslist. | 87 | options, this option sets the location of the accesslist. |
| 92 | .El | 88 | .El |
| 93 | |||
| 94 | .Sh EXAMPLES | 89 | .Sh EXAMPLES |
| 95 | |||
| 96 | Start | 90 | Start |
| 97 | .Nm | 91 | .Nm |
| 98 | bound on UDP and TCP ports 6969 on IPv6 localhost. | 92 | bound on UDP and TCP ports 6969 on IPv6 localhost. |
| 99 | |||
| 100 | .Dl # ./opentracker -i ::1 -p 6969 -P 6969 | 93 | .Dl # ./opentracker -i ::1 -p 6969 -P 6969 |
| 101 | |||
| 102 | .Pp | 94 | .Pp |
| 103 | Start | 95 | Start |
| 104 | .Nm | 96 | .Nm |
| @@ -106,12 +98,9 @@ bound on UDP port 6868 and TCP port 6868 on IPv4 localhost and allow | |||
| 106 | privileged access from the network 192.168/16 while redirecting | 98 | privileged access from the network 192.168/16 while redirecting |
| 107 | HTTP clients accessing the root directory, which is not covered by the | 99 | HTTP clients accessing the root directory, which is not covered by the |
| 108 | bittorrent tracker protocol, to https://my-trackersite.com/. | 100 | bittorrent tracker protocol, to https://my-trackersite.com/. |
| 109 | |||
| 110 | .Dl # ./opentracker -i 192.168.0.4 -p 6868 -P 6969 -A 192.168/16 -r https://my-trackersite.com/ | 101 | .Dl # ./opentracker -i 192.168.0.4 -p 6868 -P 6969 -A 192.168/16 -r https://my-trackersite.com/ |
| 111 | |||
| 112 | The announce URLs are http://192.168.0.4:6868/announce and | 102 | The announce URLs are http://192.168.0.4:6868/announce and |
| 113 | udp://192.168.0.4:6868/announce respectively. | 103 | udp://192.168.0.4:6868/announce respectively. |
| 114 | |||
| 115 | .Sh FILES | 104 | .Sh FILES |
| 116 | .Bl -tag -width indent | 105 | .Bl -tag -width indent |
| 117 | .It Pa opentracker.conf | 106 | .It Pa opentracker.conf |
| @@ -127,16 +116,15 @@ opentracker documentation | |||
| 127 | .Pp | 116 | .Pp |
| 128 | Bittorrent tracker protocol | 117 | Bittorrent tracker protocol |
| 129 | .Lk http://www.bittorrent.org/beps/bep_0015.html | 118 | .Lk http://www.bittorrent.org/beps/bep_0015.html |
| 130 | .Sh | ||
| 131 | .Sh AUTHOR | 119 | .Sh AUTHOR |
| 132 | .An Dirk Engling | 120 | .An Dirk Engling |
| 133 | .Aq Mt erdgeist@erdgeist.org . | 121 | .Aq Mt erdgeist@erdgeist.org . |
| 134 | .Sh LICENSE | 122 | .Sh LICENSE |
| 135 | This software is released under the Beerware License: | 123 | This software is released under the Beerware License: |
| 136 | 124 | .Pp | |
| 137 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software | 125 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| 138 | and associated documentation files (the "Software"), to deal in the Software with the following | 126 | and associated documentation files (the "Software"), to deal in the Software with the following |
| 139 | terms and conditions: | 127 | terms and conditions: |
| 140 | 128 | .Pp | |
| 141 | If you meet the author(s) someday, and you think this software is worth it, you can buy them | 129 | If you meet the author(s) someday, and you think this software is worth it, you can buy them |
| 142 | a beer in return. | 130 | a beer in return. |
diff --git a/man4/opentracker.conf.4 b/man4/opentracker.conf.4 index b4f5f51..2bc1389 100644 --- a/man4/opentracker.conf.4 +++ b/man4/opentracker.conf.4 | |||
| @@ -14,59 +14,59 @@ configuration file specifies various options for configuring the behavior of the | |||
| 14 | Lines starting with '#' are comments and are ignored. Options are specified as 'keyword value' pairs. | 14 | Lines starting with '#' are comments and are ignored. Options are specified as 'keyword value' pairs. |
| 15 | .Pp | 15 | .Pp |
| 16 | The following options are available: | 16 | The following options are available: |
| 17 | 17 | .Pp | |
| 18 | .Bl -tag -width ".It access.proxy" -compact | 18 | .Bl -tag -width ".It access.proxy" -compact |
| 19 | .It listen.tcp_udp Ar address | 19 | .It listen.tcp_udp Ar address |
| 20 | Specifies an address opentracker will listen on for both TCP and UDP connections. If none are specified, opentracker listens on 0.0.0.0:6969 by default. Can be added more than once. | 20 | Specifies an address opentracker will listen on for both TCP and UDP connections. If none are specified, opentracker listens on 0.0.0.0:6969 by default. Can be added more than once. |
| 21 | 21 | .Pp | |
| 22 | .It listen.tcp Ar address | 22 | .It listen.tcp Ar address |
| 23 | Specifies the address opentracker will listen on for TCP connections. Can be added more than once. | 23 | Specifies the address opentracker will listen on for TCP connections. Can be added more than once. |
| 24 | 24 | .Pp | |
| 25 | .It listen.udp Ar address | 25 | .It listen.udp Ar address |
| 26 | Specifies the address opentracker will listen on for UDP connections. Can be added more than once. | 26 | Specifies the address opentracker will listen on for UDP connections. Can be added more than once. |
| 27 | 27 | .Pp | |
| 28 | .It listen.udp.workers Ar threads | 28 | .It listen.udp.workers Ar threads |
| 29 | Specifies how many threads will be spawned to handle UDP connections. Defaults to 4. | 29 | Specifies how many threads will be spawned to handle UDP connections. Defaults to 4. |
| 30 | 30 | .Pp | |
| 31 | .It access.whitelist Ar path/to/whitelist | 31 | .It access.whitelist Ar path/to/whitelist |
| 32 | Specifies the path to the whitelist file containing all torrent hashes that opentracker will serve. Use this option if opentracker runs in a non-open mode. | 32 | Specifies the path to the whitelist file containing all torrent hashes that opentracker will serve. Use this option if opentracker runs in a non-open mode. |
| 33 | 33 | .Pp | |
| 34 | .It access.blacklist Ar path/to/blacklist | 34 | .It access.blacklist Ar path/to/blacklist |
| 35 | Specifies the path to the blacklist file containing all torrent hashes that opentracker will not serve. Use this option if opentracker was compiled to allow blacklisting. | 35 | Specifies the path to the blacklist file containing all torrent hashes that opentracker will not serve. Use this option if opentracker was compiled to allow blacklisting. |
| 36 | 36 | .Pp | |
| 37 | .It access.fifo_add Ar path/to/adder.fifo | 37 | .It access.fifo_add Ar path/to/adder.fifo |
| 38 | Specifies the path to the FIFO (named pipe) used for dynamic changesets to accesslists. Info hashes written to this FIFO will be added to the main accesslist file. | 38 | Specifies the path to the FIFO (named pipe) used for dynamic changesets to accesslists. Info hashes written to this FIFO will be added to the main accesslist file. |
| 39 | 39 | .Pp | |
| 40 | .It access.fifo_delete Ar path/to/deleter.fifo | 40 | .It access.fifo_delete Ar path/to/deleter.fifo |
| 41 | Specifies the path to the FIFO (named pipe) used for dynamic changesets to accesslists. Info hashes written to this FIFO will be removed from the main accesslist file. | 41 | Specifies the path to the FIFO (named pipe) used for dynamic changesets to accesslists. Info hashes written to this FIFO will be removed from the main accesslist file. |
| 42 | 42 | .Pp | |
| 43 | .It access.stats Ar ip_address_or_network | 43 | .It access.stats Ar ip_address_or_network |
| 44 | Specifies the IP address or network in CIDR notation allowed to fetch stats from opentracker. | 44 | Specifies the IP address or network in CIDR notation allowed to fetch stats from opentracker. |
| 45 | 45 | .Pp | |
| 46 | .It access.stats_path Ar path | 46 | .It access.stats_path Ar path |
| 47 | Specifies the path to the stats location. You can configure opentracker to appear anywhere on your tracker. Defaults to /stats. | 47 | Specifies the path to the stats location. You can configure opentracker to appear anywhere on your tracker. Defaults to /stats. |
| 48 | 48 | .Pp | |
| 49 | .It access.proxy Ar ip_address_or_network | 49 | .It access.proxy Ar ip_address_or_network |
| 50 | Specifies the IP address or network of the reverse proxies. Opentracker will take the X-Forwarded-For address instead of the source IP address. Can be added more than once. | 50 | Specifies the IP address or network of the reverse proxies. Opentracker will take the X-Forwarded-For address instead of the source IP address. Can be added more than once. |
| 51 | 51 | .Pp | |
| 52 | .It livesync.cluster.listen Ar ip_address:port | 52 | .It livesync.cluster.listen Ar ip_address:port |
| 53 | Specifies the IP address and port opentracker will listen on for incoming live sync packets to keep a cluster of opentrackers synchronized. | 53 | Specifies the IP address and port opentracker will listen on for incoming live sync packets to keep a cluster of opentrackers synchronized. |
| 54 | 54 | .Pp | |
| 55 | .It livesync.cluster.node_ip Ar ip_address | 55 | .It livesync.cluster.node_ip Ar ip_address |
| 56 | Specifies one trusted IP address for sync between trackers running in a cluster. Can be added more than once. | 56 | Specifies one trusted IP address for sync between trackers running in a cluster. Can be added more than once. |
| 57 | 57 | .Pp | |
| 58 | .It batchsync.cluster.admin_ip Ar ip_address | 58 | .It batchsync.cluster.admin_ip Ar ip_address |
| 59 | Specifies the admin IP address for old-style (HTTP-based) asynchronous tracker syncing. | 59 | Specifies the admin IP address for old-style (HTTP-based) asynchronous tracker syncing. |
| 60 | 60 | .Pp | |
| 61 | .It tracker.rootdir Ar path | 61 | .It tracker.rootdir Ar path |
| 62 | Specifies the directory opentracker will chroot/chdir to. All black/white list files must be located in this directory. | 62 | Specifies the directory opentracker will chroot/chdir to. All black/white list files must be located in this directory. |
| 63 | 63 | .Pp | |
| 64 | .It tracker.user Ar username | 64 | .It tracker.user Ar username |
| 65 | Specifies the user opentracker will setuid to after binding to potentially privileged ports. | 65 | Specifies the user opentracker will setuid to after binding to potentially privileged ports. |
| 66 | 66 | .Pp | |
| 67 | .It tracker.redirect_url Ar URL | 67 | .It tracker.redirect_url Ar URL |
| 68 | Specifies the URL opentracker will redirect to in response to a "GET / HTTP" request. | 68 | Specifies the URL opentracker will redirect to in response to a "GET / HTTP" request. |
| 69 | 69 | .El | |
| 70 | .Sh EXAMPLES | 70 | .Sh EXAMPLES |
| 71 | To specify the address opentracker will listen on for both TCP and UDP connections: | 71 | To specify the address opentracker will listen on for both TCP and UDP connections: |
| 72 | .Dl listen.tcp_udp 0.0.0.0:6969 | 72 | .Dl listen.tcp_udp 0.0.0.0:6969 |
| @@ -76,11 +76,11 @@ To specify the address opentracker will listen on for TCP connections: | |||
| 76 | .Pp | 76 | .Pp |
| 77 | To specify the address opentracker will listen on for UDP connections: | 77 | To specify the address opentracker will listen on for UDP connections: |
| 78 | .Dl listen.udp 0.0.0.0:6969 | 78 | .Dl listen.udp 0.0.0.0:6969 |
| 79 | 79 | .Pp | |
| 80 | .Sh SEE ALSO | 80 | .Sh SEE ALSO |
| 81 | .Xr opentracker 1 | 81 | .Xr opentracker 1 |
| 82 | 82 | .Pp | |
| 83 | .Sh AUTHOR | 83 | .Sh AUTHOR |
| 84 | .An Dirk Engling | 84 | .An Dirk Engling |
| 85 | .Aq Mt erdgeist@erdgeist.org | 85 | .Aq Mt erdgeist@erdgeist.org |
| 86 | 86 | .Pp | |
| @@ -32,7 +32,7 @@ | |||
| 32 | #include "trackerlogic.h" | 32 | #include "trackerlogic.h" |
| 33 | 33 | ||
| 34 | #ifdef WANT_NO_AUTO_FREE | 34 | #ifdef WANT_NO_AUTO_FREE |
| 35 | #define OT_IOB_INIT(B) bzero(B, sizeof(io_batch)) | 35 | #define OT_IOB_INIT(B) (bzero(B, sizeof(io_batch)), 0) |
| 36 | #else | 36 | #else |
| 37 | #define OT_IOB_INIT(B) iob_init_autofree(B, 0) | 37 | #define OT_IOB_INIT(B) iob_init_autofree(B, 0) |
| 38 | #endif | 38 | #endif |
| @@ -88,7 +88,15 @@ static void http_senddata(const int64 sock, struct ot_workstruct *ws) { | |||
| 88 | memcpy(outbuf, ws->reply + written_size, ws->reply_size - written_size); | 88 | memcpy(outbuf, ws->reply + written_size, ws->reply_size - written_size); |
| 89 | if (!cookie->batch) { | 89 | if (!cookie->batch) { |
| 90 | cookie->batch = malloc(sizeof(io_batch)); | 90 | cookie->batch = malloc(sizeof(io_batch)); |
| 91 | OT_IOB_INIT(cookie->batch); | 91 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { |
| 92 | free(cookie->batch); | ||
| 93 | free(outbuf); | ||
| 94 | array_reset(&cookie->request); | ||
| 95 | free(cookie); | ||
| 96 | io_close(sock); | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | |||
| 92 | cookie->batches = 1; | 100 | cookie->batches = 1; |
| 93 | } | 101 | } |
| 94 | 102 | ||
| @@ -183,12 +191,12 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec | |||
| 183 | 191 | ||
| 184 | if (!cookie->batch) { | 192 | if (!cookie->batch) { |
| 185 | cookie->batch = malloc(sizeof(io_batch)); | 193 | cookie->batch = malloc(sizeof(io_batch)); |
| 186 | if (!cookie->batch) { | 194 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { |
| 195 | free(cookie->batch); | ||
| 187 | free(header); | 196 | free(header); |
| 188 | iovec_free(&iovec_entries, &iovector); | 197 | iovec_free(&iovec_entries, &iovector); |
| 189 | HTTPERROR_500; | 198 | HTTPERROR_500; |
| 190 | } | 199 | } |
| 191 | OT_IOB_INIT(cookie->batch); | ||
| 192 | cookie->batches = 1; | 200 | cookie->batches = 1; |
| 193 | } | 201 | } |
| 194 | current = cookie->batch + cookie->batches - 1; | 202 | current = cookie->batch + cookie->batches - 1; |
| @@ -201,8 +209,8 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec | |||
| 201 | io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); | 209 | io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); |
| 202 | if (new_batch) { | 210 | if (new_batch) { |
| 203 | cookie->batch = new_batch; | 211 | cookie->batch = new_batch; |
| 204 | current = cookie->batch + cookie->batches++; | 212 | if (OT_IOB_INIT(current) != -1) |
| 205 | OT_IOB_INIT(current); | 213 | current = cookie->batch + cookie->batches++; |
| 206 | } | 214 | } |
| 207 | } | 215 | } |
| 208 | iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len); | 216 | iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len); |
diff --git a/ot_vector.c b/ot_vector.c index 2bc07b5..2acfbef 100644 --- a/ot_vector.c +++ b/ot_vector.c | |||
| @@ -67,12 +67,15 @@ void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, si | |||
| 67 | return match; | 67 | return match; |
| 68 | 68 | ||
| 69 | if (vector->size + 1 > vector->space) { | 69 | if (vector->size + 1 > vector->space) { |
| 70 | size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS; | 70 | size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS; |
| 71 | uint8_t *new_data = realloc(vector->data, new_space * member_size); | 71 | ptrdiff_t match_off = match - (uint8_t *)vector->data; |
| 72 | uint8_t *new_data = realloc(vector->data, new_space * member_size); | ||
| 73 | |||
| 72 | if (!new_data) | 74 | if (!new_data) |
| 73 | return NULL; | 75 | return NULL; |
| 76 | |||
| 74 | /* Adjust pointer if it moved by realloc */ | 77 | /* Adjust pointer if it moved by realloc */ |
| 75 | match = new_data + (match - (uint8_t *)vector->data); | 78 | match = new_data + match_off; |
| 76 | 79 | ||
| 77 | vector->data = new_data; | 80 | vector->data = new_data; |
| 78 | vector->space = new_space; | 81 | vector->space = new_space; |
