diff options
| -rw-r--r-- | man4/opentracker.conf.4 | 3 | ||||
| -rw-r--r-- | opentracker.conf.sample | 6 | ||||
| -rw-r--r-- | ot_sync.c | 165 | ||||
| -rw-r--r-- | ot_sync.h | 26 |
4 files changed, 0 insertions, 200 deletions
diff --git a/man4/opentracker.conf.4 b/man4/opentracker.conf.4 index 1bd1c7a..239ab88 100644 --- a/man4/opentracker.conf.4 +++ b/man4/opentracker.conf.4 | |||
| @@ -84,9 +84,6 @@ Specifies the IP address and port opentracker will listen on for incoming live s | |||
| 84 | .It livesync.cluster.node_ip Ar ip_address | 84 | .It livesync.cluster.node_ip Ar ip_address |
| 85 | Specifies one trusted IP address for sync between trackers running in a cluster. Can be added more than once. | 85 | Specifies one trusted IP address for sync between trackers running in a cluster. Can be added more than once. |
| 86 | .Pp | 86 | .Pp |
| 87 | .It batchsync.cluster.admin_ip Ar ip_address | ||
| 88 | Specifies the admin IP address for old-style (HTTP-based) asynchronous tracker syncing. | ||
| 89 | .Pp | ||
| 90 | .It tracker.rootdir Ar path | 87 | .It tracker.rootdir Ar path |
| 91 | Specifies the directory opentracker will chroot/chdir to. All black/white list files must be located in this directory. | 88 | Specifies the directory opentracker will chroot/chdir to. All black/white list files must be located in this directory. |
| 92 | .Pp | 89 | .Pp |
diff --git a/opentracker.conf.sample b/opentracker.conf.sample index f075703..491c88a 100644 --- a/opentracker.conf.sample +++ b/opentracker.conf.sample | |||
| @@ -154,12 +154,6 @@ | |||
| 154 | # livesync.cluster.node_ip 192.168.0.4 | 154 | # livesync.cluster.node_ip 192.168.0.4 |
| 155 | # livesync.cluster.node_ip 192.168.0.5 | 155 | # livesync.cluster.node_ip 192.168.0.5 |
| 156 | # livesync.cluster.node_ip 192.168.0.6 | 156 | # livesync.cluster.node_ip 192.168.0.6 |
| 157 | # | ||
| 158 | # This is the admin ip address for old style (HTTP based) asynchronus | ||
| 159 | # tracker syncing. | ||
| 160 | # | ||
| 161 | # batchsync.cluster.admin_ip 10.1.1.1 | ||
| 162 | # | ||
| 163 | 157 | ||
| 164 | # V) Control privilege drop behaviour. | 158 | # V) Control privilege drop behaviour. |
| 165 | # Put in the directory opentracker will chroot/chdir to. All black/white | 159 | # Put in the directory opentracker will chroot/chdir to. All black/white |
diff --git a/ot_sync.c b/ot_sync.c deleted file mode 100644 index c19cf36..0000000 --- a/ot_sync.c +++ /dev/null | |||
| @@ -1,165 +0,0 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. | ||
| 3 | |||
| 4 | $id$ */ | ||
| 5 | |||
| 6 | /* System */ | ||
| 7 | #include <pthread.h> | ||
| 8 | #include <stdio.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <sys/types.h> | ||
| 11 | #include <sys/uio.h> | ||
| 12 | |||
| 13 | /* Opentracker */ | ||
| 14 | #include "ot_fmt.h" | ||
| 15 | #include "ot_iovec.h" | ||
| 16 | #include "ot_mutex.h" | ||
| 17 | #include "ot_workqueue.h" | ||
| 18 | #include "ot_scan.h" | ||
| 19 | #include "ot_stats.h" | ||
| 20 | #include "ot_sync.h" | ||
| 21 | #include "trackerlogic.h" | ||
| 22 | |||
| 23 | #ifdef WANT_SYNC_BATCH | ||
| 24 | |||
| 25 | #define OT_SYNC_CHUNK_SIZE (512 * 1024) | ||
| 26 | |||
| 27 | /* Import Changeset from an external authority | ||
| 28 | format: d4:syncd[..]ee | ||
| 29 | [..]: ( 20:01234567890abcdefghij16:XXXXYYYY )+ | ||
| 30 | */ | ||
| 31 | int add_changeset_to_tracker(uint8_t *data, size_t len) { | ||
| 32 | ot_hash *hash; | ||
| 33 | uint8_t *end = data + len; | ||
| 34 | uint64_t peer_count; | ||
| 35 | |||
| 36 | /* We do know, that the string is \n terminated, so it can't | ||
| 37 | overflow */ | ||
| 38 | if (!memcmp(data, "d4:syncd", 8)) | ||
| 39 | return -1; | ||
| 40 | data += 8; | ||
| 41 | |||
| 42 | while (1) { | ||
| 43 | if (!memcmp(data, "20:", 3)) { | ||
| 44 | if (!memcmp(data, "ee", 2)) | ||
| 45 | return -1; | ||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | data += 3; | ||
| 49 | hash = (ot_hash *)data; | ||
| 50 | data += sizeof(ot_hash); | ||
| 51 | |||
| 52 | /* Scan string length indicator, strictly: bencode writes no leading zeros */ | ||
| 53 | data += (len = scan_uint_bencode((char *)data, &peer_count, (uint64_t)(end - data))); | ||
| 54 | |||
| 55 | /* If no long was scanned, it is not divisible by 8, it is not | ||
| 56 | followed by a colon or claims to need to much memory, we fail */ | ||
| 57 | if (!len || !peer_count || (peer_count & 7) || (*data++ != ':') || (data + peer_count > end)) | ||
| 58 | return -1; | ||
| 59 | |||
| 60 | while (peer_count > 0) { | ||
| 61 | add_peer_to_torrent(hash, (ot_peer *)data, 1); | ||
| 62 | data += 8; | ||
| 63 | peer_count -= 8; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | /* Proposed output format | ||
| 70 | d4:syncd20:<info_hash>8*N:(xxxxyyyy)*Nee | ||
| 71 | */ | ||
| 72 | static void sync_make(size_t *iovec_entries, struct iovec **iovector) { | ||
| 73 | size_t bucket; | ||
| 74 | char *r, *re; | ||
| 75 | |||
| 76 | /* Setup return vector... */ | ||
| 77 | *iovec_entries = 0; | ||
| 78 | *iovector = NULL; | ||
| 79 | if (!(r = iovec_new_chunk(iovec_entries, iovector, OT_SYNC_CHUNK_SIZE))) | ||
| 80 | return; | ||
| 81 | |||
| 82 | /* ... and pointer to end of current output buffer. | ||
| 83 | This works as a low watermark */ | ||
| 84 | re = r + OT_SYNC_CHUNK_SIZE; | ||
| 85 | |||
| 86 | memmove(r, "d4:syncd", 8); | ||
| 87 | r += 8; | ||
| 88 | |||
| 89 | /* For each bucket... */ | ||
| 90 | for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { | ||
| 91 | /* Get exclusive access to that bucket */ | ||
| 92 | ot_vector *torrents_list = mutex_bucket_lock(bucket); | ||
| 93 | size_t tor_offset; | ||
| 94 | |||
| 95 | /* For each torrent in this bucket.. */ | ||
| 96 | for (tor_offset = 0; tor_offset < torrents_list->size; ++tor_offset) { | ||
| 97 | /* Address torrents members */ | ||
| 98 | ot_peerlist *peer_list = (((ot_torrent *)(torrents_list->data))[tor_offset]).peer_list; | ||
| 99 | ot_hash *hash = &(((ot_torrent *)(torrents_list->data))[tor_offset]).hash; | ||
| 100 | const size_t byte_count = sizeof(ot_peer) * peer_list->changeset.size; | ||
| 101 | |||
| 102 | /* If we reached our low watermark in buffer... */ | ||
| 103 | if (re - r <= (ssize_t)(/* strlen( "20:" ) == */ 3 + sizeof(ot_hash) + /* strlen_max( "%zd" ) == */ 12 + byte_count)) { | ||
| 104 | |||
| 105 | /* Allocate a fresh output buffer at the end of our buffers list | ||
| 106 | release bucket and return, if that fails */ | ||
| 107 | if (!(r = iovec_next_chunk(iovec_entries, iovector, r, OT_SYNC_CHUNK_SIZE))) | ||
| 108 | return mutex_bucket_unlock(bucket); | ||
| 109 | |||
| 110 | /* Adjust new end of output buffer */ | ||
| 111 | re = r + OT_SYNC_CHUNK_SIZE; | ||
| 112 | } | ||
| 113 | |||
| 114 | fmt_append(&r, re, "20:"); | ||
| 115 | fmt_bytes(&r, re, hash, sizeof(ot_hash)); | ||
| 116 | fmt_append(&r, re, "%zd:", byte_count); | ||
| 117 | fmt_bytes(&r, re, peer_list->changeset.data, byte_count); | ||
| 118 | } | ||
| 119 | |||
| 120 | /* All torrents done: release lock on currenct bucket */ | ||
| 121 | mutex_bucket_unlock(bucket); | ||
| 122 | } | ||
| 123 | |||
| 124 | /* Close bencoded sync dictionary */ | ||
| 125 | *r++ = 'e'; | ||
| 126 | *r++ = 'e'; | ||
| 127 | |||
| 128 | /* Release unused memory in current output buffer */ | ||
| 129 | iovec_trim_last(iovec_entries, iovector, r); | ||
| 130 | } | ||
| 131 | |||
| 132 | /* This is the entry point into this worker thread | ||
| 133 | It grabs tasks from mutex_tasklist and delivers results back | ||
| 134 | */ | ||
| 135 | static void *sync_worker(void *args) { | ||
| 136 | size_t iovec_entries; | ||
| 137 | struct iovec *iovector; | ||
| 138 | |||
| 139 | args = args; | ||
| 140 | |||
| 141 | while (1) { | ||
| 142 | ot_tasktype tasktype = TASK_SYNC_OUT; | ||
| 143 | ot_taskid taskid = workqueue_poptask(&tasktype); | ||
| 144 | sync_make(&iovec_entries, &iovector); | ||
| 145 | stats_issue_event(ws, EVENT_SYNC_OUT, FLAG_TCP, iovec_length(&iovec_entries, &iovector)); | ||
| 146 | if (workqueue_pushresult(taskid, iovec_entries, iovector)) | ||
| 147 | iovec_free(&iovec_entries, &iovector); | ||
| 148 | } | ||
| 149 | return NULL; | ||
| 150 | } | ||
| 151 | |||
| 152 | static pthread_t thread_id; | ||
| 153 | void sync_init( ) { | ||
| 154 | pthread_create( &thread_id, NULL, sync_worker, NULL ); | ||
| 155 | } | ||
| 156 | |||
| 157 | void sync_deinit( ) { | ||
| 158 | pthread_cancel( thread_id ); | ||
| 159 | } | ||
| 160 | |||
| 161 | void sync_deliver( int64_t socket ) { | ||
| 162 | workqueue_pushtask( socket, TASK_SYNC_OUT ); | ||
| 163 | } | ||
| 164 | |||
| 165 | #endif | ||
diff --git a/ot_sync.h b/ot_sync.h deleted file mode 100644 index b6964fa..0000000 --- a/ot_sync.h +++ /dev/null | |||
| @@ -1,26 +0,0 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. | ||
| 3 | |||
| 4 | $id$ */ | ||
| 5 | |||
| 6 | #ifndef OT_SYNC_H__ | ||
| 7 | #define OT_SYNC_H__ | ||
| 8 | |||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | #ifdef WANT_SYNC_BATCH | ||
| 12 | enum { SYNC_IN, SYNC_OUT }; | ||
| 13 | |||
| 14 | void sync_init(); | ||
| 15 | void sync_deinit(); | ||
| 16 | void sync_deliver(int64_t socket); | ||
| 17 | |||
| 18 | int add_changeset_to_tracker(uint8_t *data, size_t len); | ||
| 19 | #else | ||
| 20 | |||
| 21 | #define sync_init() | ||
| 22 | #define sync_deinit() | ||
| 23 | |||
| 24 | #endif | ||
| 25 | |||
| 26 | #endif | ||
