1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# $Id$
# Linux flavour
# PREFIX?=/opt/diet
# LIBOWFAT_HEADERS=$(PREFIX)/include
# LIBOWFAT_LIBRARY=$(PREFIX)/lib
# BSD flavour
# PREFIX?=/usr/local
# LIBOWFAT_HEADERS=$(PREFIX)/include/libowfat
# LIBOWFAT_LIBRARY=$(PREFIX)/lib
# Debug flavour
PREFIX?=..
LIBOWFAT_HEADERS=$(PREFIX)/libowfat
LIBOWFAT_LIBRARY=$(PREFIX)/libowfat
BINDIR?=$(PREFIX)/bin
STRIP?=strip
#FEATURES+=-DWANT_V4_ONLY
#FEATURES+=-DWANT_ACCESSLIST_BLACK
#FEATURES+=-DWANT_ACCESSLIST_WHITE
#FEATURES+=-DWANT_DYNAMIC_ACCESSLIST
#FEATURES+=-DWANT_SYNC_LIVE
#FEATURES+=-DWANT_IP_FROM_QUERY_STRING
# If you want gzip support to be compiled in, uncomment the next include.
# You can further modify the behaviour by setting DWANT_COMPRESSION_GZIP_ALWAYS
# in Makefile.gzip
include Makefile.gzip
# If you want zstd support to be compiled in, uncomment the next include.
# You can further modify the behaviour by setting DWANT_COMPRESSION_ZSTD_ALWAYS
# in Makefile.zstd
#include Makefile.zstd
#FEATURES+=-DWANT_LOG_NETWORKS
#FEATURES+=-DWANT_RESTRICT_STATS
#FEATURES+=-DWANT_IP_FROM_PROXY
#FEATURES+=-DWANT_FULLLOG_NETWORKS
#FEATURES+=-DWANT_LOG_NUMWANT
#FEATURES+=-DWANT_MODEST_FULLSCRAPES
#FEATURES+=-DWANT_SPOT_WOODPECKER
#FEATURES+=-DWANT_SYSLOGS
#FEATURES+=-DWANT_DEV_RANDOM
FEATURES+=-DWANT_FULLSCRAPE
# opentracker takes its randomness from arc4random, which is part of libc on
# the BSDs, on macOS and on glibc 2.36 and newer. On an older glibc or on musl
# it comes from libbsd instead, so uncomment the next include to link it.
#LDFLAGS+=-lbsd
#FEATURES+=-D_DEBUG_HTTPERROR
#FEATURES+=-D_DEBUG_RANDOMTORRENTS
GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse HEAD || echo _git_or_commit_not_found_'`
OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage
OPTS_production=-O3
CFLAGS+=-DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic
LDFLAGS+=-pthread
# Only the proxy, which has not been ported since the tracker went dual stack,
# still wants libowfat.
CFLAGS_libowfat=-I$(LIBOWFAT_HEADERS)
LDFLAGS_libowfat=-L$(LIBOWFAT_LIBRARY) -lowfat
BINARY =opentracker
HEADERS=trackerlogic.h ot_urlencoded.h ot_batch.h ot_buf.h ot_event.h ot_fdstate.h ot_fmt.h ot_hex.h ot_ip.h ot_config.h ot_scan.h ot_socket.h ot_mutex.h ot_random.h ot_stats.h ot_vector.h ot_clean.h ot_udp.h ot_iovec.h ot_fullscrape.h ot_accesslist.h ot_http.h ot_livesync.h ot_rijndael.h
SOURCES=opentracker.c trackerlogic.c ot_urlencoded.c ot_batch.c ot_buf.c ot_event.c ot_fdstate.c ot_fmt.c ot_hex.c ot_ip.c ot_config.c ot_scan.c ot_socket.c ot_mutex.c ot_random.c ot_stats.c ot_vector.c ot_clean.c ot_udp.c ot_iovec.c ot_fullscrape.c ot_accesslist.c ot_http.c ot_livesync.c ot_rijndael.c
SOURCES_proxy=proxy.c ot_batch.c ot_fdstate.c ot_vector.c ot_mutex.c ot_random.c ot_scan.c ot_ip.c ot_socket.c
OBJECTS = $(SOURCES:%.c=%.o)
OBJECTS_debug = $(SOURCES:%.c=%.debug.o)
OBJECTS_proxy = $(SOURCES_proxy:%.c=%.proxy.o)
OBJECTS_proxy_debug = $(SOURCES_proxy:%.c=%.proxy.debug.o)
.SUFFIXES: .proxy.debug.o .proxy.o .debug.o .o .c
all: $(BINARY) $(BINARY).debug
CFLAGS_production = $(CFLAGS) $(OPTS_production) $(FEATURES)
CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES)
CFLAGS_proxy = $(CFLAGS_production) $(CFLAGS_libowfat) -DWANT_SYNC_LIVE
CFLAGS_proxy_debug = $(CFLAGS_debug) $(CFLAGS_libowfat) -DWANT_SYNC_LIVE
$(BINARY): $(OBJECTS)
$(CC) -o $@ $(OBJECTS) $(LDFLAGS)
$(STRIP) $@
$(BINARY).debug: $(OBJECTS_debug)
$(CC) -o $@ $(OBJECTS_debug) $(LDFLAGS)
proxy: $(OBJECTS_proxy)
$(CC) -o $@ $(OBJECTS_proxy) $(CFLAGS_production) $(LDFLAGS) $(LDFLAGS_libowfat)
proxy.debug: $(OBJECTS_proxy_debug)
$(CC) -o $@ $(OBJECTS_proxy_debug) $(LDFLAGS) $(LDFLAGS_libowfat)
$(OBJECTS): $(HEADERS)
$(OBJECTS_debug): $(HEADERS)
$(OBJECTS_proxy): $(HEADERS)
$(OBJECTS_proxy_debug): $(HEADERS)
.c.proxy.debug.o :
$(CC) -c -o $@ $(CFLAGS_proxy_debug) $(<:.proxy.debug.o=.c)
.c.proxy.o :
$(CC) -c -o $@ $(CFLAGS_proxy) $(<:.proxy.o=.c)
.c.debug.o :
$(CC) -c -o $@ $(CFLAGS_debug) $(<:.debug.o=.c)
.c.o :
$(CC) -c -o $@ $(CFLAGS_production) $<
# Unit tests. The modules under test are compiled straight into the test
# binary, so a test may reach a static function by including the source if it
# has to. tests/stubs.c supplies the few symbols those modules reference but
# the tests never reach.
TESTBIN=tests/runner
TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_urlencoded.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c tests/t_mutex.c tests/t_batch.c tests/t_fdstate.c tests/t_event.c tests/t_fmt.c
TEST_UNITS=ot_urlencoded.c ot_fmt.c ot_event.c ot_batch.c ot_fdstate.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c ot_mutex.c
TEST_HEADERS=tests/test.h $(HEADERS)
# Tests reach code that sits behind feature flags, so the units under test are
# built with those features enabled. A test binary is not a production binary.
FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE
CFLAGS_test = $(CFLAGS) -I. -g -O1 $(FEATURES_test)
$(TESTBIN): $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS)
$(CC) -o $@ $(CFLAGS_test) $(TEST_SOURCES) $(TEST_UNITS)
check: $(TESTBIN) $(BINARY)
./$(TESTBIN)
# Black box tests: these drive the real binary over the wire, so they cover
# the event loop and the parsers working together, which the unit tests
# cannot reach. Built with the sanitizers on, so the tracker reports its own
# memory errors and the harness turns those into failures.
PYTHON?=python3
FEATURES_integration=$(FEATURES) -DWANT_IP_FROM_QUERY_STRING
CFLAGS_integration=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer
LDFLAGS_integration=$(LDFLAGS) -fsanitize=address,undefined
opentracker.integration: $(SOURCES) $(HEADERS)
$(CC) -o $@ $(CFLAGS_integration) $(SOURCES) $(LDFLAGS_integration) -lz
check-integration: opentracker.integration
OPENTRACKER=./opentracker.integration $(PYTHON) -m unittest discover -s tests/integration
.PHONY: all check check-integration clean install
clean:
rm -rf opentracker opentracker.debug opentracker.integration proxy proxy.debug $(TESTBIN) *.o *~
install:
install -m 755 opentracker $(DESTDIR)$(BINDIR)
|