summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/trackerlogic.c b/trackerlogic.c
index 7c6b7e1..59e9643 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -5,16 +5,12 @@
5 5
6/* System */ 6/* System */
7#include <arpa/inet.h> 7#include <arpa/inet.h>
8#include <errno.h>
9#include <stdint.h> 8#include <stdint.h>
10#include <stdio.h> 9#include <stdio.h>
11#include <stdlib.h> 10#include <stdlib.h>
12#include <string.h> 11#include <string.h>
13#include <unistd.h>
14 12
15/* Libowfat */ 13/* Libowfat */
16#include "array.h"
17#include "byte.h"
18#include "io.h" 14#include "io.h"
19#include "iob.h" 15#include "iob.h"
20#include "ip6.h" 16#include "ip6.h"
@@ -49,30 +45,35 @@ void add_torrent_from_saved_state(ot_hash const hash, ot_time base, size_t down_
49 ot_torrent *torrent; 45 ot_torrent *torrent;
50 ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash); 46 ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash);
51 47
52 if (!accesslist_hashisvalid(hash)) 48 if (!accesslist_hashisvalid(hash)) {
53 return mutex_bucket_unlock_by_hash(hash, 0); 49 mutex_bucket_unlock_by_hash(hash, 0);
50 return;
51 }
54 52
55 torrent = vector_find_or_insert(torrents_list, (void *)hash, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch); 53 torrent = vector_find_or_insert(torrents_list, (void *)hash, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch);
56 if (!torrent || exactmatch) 54 if (!torrent || exactmatch) {
57 return mutex_bucket_unlock_by_hash(hash, 0); 55 mutex_bucket_unlock_by_hash(hash, 0);
56 return;
57 }
58 58
59 /* Create a new torrent entry, then */ 59 /* Create a new torrent entry, then */
60 byte_zero(torrent, sizeof(ot_torrent)); 60 memset(torrent, 0, sizeof(ot_torrent));
61 memcpy(torrent->hash, hash, sizeof(ot_hash)); 61 memcpy(torrent->hash, hash, sizeof(ot_hash));
62 62
63 if (!(torrent->peer_list6 = malloc(sizeof(ot_peerlist))) || !(torrent->peer_list4 = malloc(sizeof(ot_peerlist)))) { 63 if (!(torrent->peer_list6 = malloc(sizeof(ot_peerlist))) || !(torrent->peer_list4 = malloc(sizeof(ot_peerlist)))) {
64 vector_remove_torrent(torrents_list, torrent); 64 vector_remove_torrent(torrents_list, torrent);
65 return mutex_bucket_unlock_by_hash(hash, 0); 65 mutex_bucket_unlock_by_hash(hash, 0);
66 return;
66 } 67 }
67 68
68 byte_zero(torrent->peer_list6, sizeof(ot_peerlist)); 69 memset(torrent->peer_list6, 0, sizeof(ot_peerlist));
69 byte_zero(torrent->peer_list4, sizeof(ot_peerlist)); 70 memset(torrent->peer_list4, 0, sizeof(ot_peerlist));
70 torrent->peer_list6->base = base; 71 torrent->peer_list6->base = base;
71 torrent->peer_list4->base = base; 72 torrent->peer_list4->base = base;
72 torrent->peer_list6->down_count = down_count; 73 torrent->peer_list6->down_count = down_count;
73 torrent->peer_list4->down_count = down_count; 74 torrent->peer_list4->down_count = down_count;
74 75
75 return mutex_bucket_unlock_by_hash(hash, 1); 76 mutex_bucket_unlock_by_hash(hash, 1);
76} 77}
77 78
78size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount) { 79size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount) {
@@ -102,7 +103,7 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru
102 103
103 if (!exactmatch) { 104 if (!exactmatch) {
104 /* Create a new torrent entry, then */ 105 /* Create a new torrent entry, then */
105 byte_zero(torrent, sizeof(ot_torrent)); 106 memset(torrent, 0, sizeof(ot_torrent));
106 memcpy(torrent->hash, *ws->hash, sizeof(ot_hash)); 107 memcpy(torrent->hash, *ws->hash, sizeof(ot_hash));
107 108
108 if (!(torrent->peer_list6 = malloc(sizeof(ot_peerlist))) || !(torrent->peer_list4 = malloc(sizeof(ot_peerlist)))) { 109 if (!(torrent->peer_list6 = malloc(sizeof(ot_peerlist))) || !(torrent->peer_list4 = malloc(sizeof(ot_peerlist)))) {
@@ -111,8 +112,8 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru
111 return 0; 112 return 0;
112 } 113 }
113 114
114 byte_zero(torrent->peer_list6, sizeof(ot_peerlist)); 115 memset(torrent->peer_list6, 0, sizeof(ot_peerlist));
115 byte_zero(torrent->peer_list4, sizeof(ot_peerlist)); 116 memset(torrent->peer_list4, 0, sizeof(ot_peerlist));
116 delta_torrentcount = 1; 117 delta_torrentcount = 1;
117 } else 118 } else
118 clean_single_torrent(torrent); 119 clean_single_torrent(torrent);