Skip to content

Commit c6bed82

Browse files
committed
Merge branch 'tox-bootstrapd-docker-support' of https://github.com/nurupo/InsertProjectNameHere
2 parents 760f20c + 9d1efd5 commit c6bed82

22 files changed

+1581
-772
lines changed

build/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ include ../toxencryptsave/Makefile.inc
1010
include ../toxav/Makefile.inc
1111
include ../other/Makefile.inc
1212
include ../testing/Makefile.inc
13-
include ../other/bootstrap_daemon/Makefile.inc
13+
include ../other/bootstrap_daemon/src/Makefile.inc
1414
include ../auto_tests/Makefile.inc

other/DHT_bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "../testing/misc_tools.c"
4141

4242
#ifdef DHT_NODE_EXTRA_PACKETS
43-
#include "./bootstrap_node_packets.c"
43+
#include "./bootstrap_node_packets.h"
4444

4545
#define DHT_VERSION_NUMBER 1
4646
#define DHT_MOTD "This is a test motd"

other/Makefile.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ bin_PROGRAMS += DHT_bootstrap
22

33
DHT_bootstrap_SOURCES = ../other/DHT_bootstrap.c \
44
../toxcore/DHT.h \
5-
../toxcore/friend_requests.h
5+
../toxcore/friend_requests.h \
6+
../other/bootstrap_node_packets.h \
7+
../other/bootstrap_node_packets.c
68

79
DHT_bootstrap_CFLAGS = -I$(top_srcdir)/other \
810
$(LIBSODIUM_CFLAGS) \

other/bootstrap_daemon/Makefile.inc

Lines changed: 0 additions & 27 deletions
This file was deleted.

other/bootstrap_daemon/README.md

Lines changed: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
#Instructions
22

33
- [For `systemd` users](#systemd)
4+
- [Setting up](#systemd-setting-up)
5+
- [Updating](#systemd-updating)
46
- [Troubleshooting](#systemd-troubleshooting)
57
<br>
6-
- [For `init.d` users](#initd)
7-
- [Troubleshooting](#initd-troubleshooting)
8+
- [For `SysVinit` users](#sysvinit)
9+
- [Setting up](#sysvinit-setting-up)
10+
- [Updating](#sysvinit-updating)
11+
- [Troubleshooting](#sysvinit-troubleshooting)
12+
<br>
13+
- [For `Docker` users](#docker)
14+
- [Setting up](#docker-setting-up)
15+
- [Updating](#docker-updating)
16+
- [Troubleshooting](#docker-troubleshooting)
817

918

10-
These instructions are primarily tested on Debian Linux, Wheezy for init.d and Jessie for systemd, but they should work on other POSIX-compliant systems too.
19+
These instructions are primarily tested on Debian Linux, Wheezy for SysVinit and Jessie for systemd, but they should work on other POSIX-compliant systems too.
1120

1221

1322
<a name="systemd" />
14-
##For `systemd` users:
23+
##For `systemd` users
24+
25+
<a name="systemd-setting-up" />
26+
###Setting up
1527

1628
For security reasons we run the daemon under its own user.
1729

@@ -56,8 +68,31 @@ Get your public key and check that the daemon initialized correctly:
5668
sudo grep "tox-bootstrapd" /var/log/syslog
5769
```
5870

71+
<a name="systemd-updating" />
72+
###Updating
73+
74+
You want to make sure that the daemon uses the newest toxcore, as there might have been some changes done to the DHT, so it's advised to update the daemon at least once every month.
75+
76+
To update the daemon first stop it:
77+
78+
```sh
79+
sudo systemctl stop tox-bootstrapd.service
80+
```
81+
82+
Then update your toxcore git repository, rebuild the toxcore and the daemon and make sure to install them.
83+
84+
Check if `tox-bootstrapd.service` in toxcore git repository was modified since the last time you copied it, as you might need to update it too.
85+
86+
After all of this is done, simply start the daemon back again:
87+
88+
```sh
89+
sudo systemctl start tox-bootstrapd.service
90+
```
91+
92+
Note that `tox-bootstrapd.service` file might
93+
5994
<a name="systemd-troubleshooting" />
60-
###Troubleshooting:
95+
###Troubleshooting
6196

6297
- Check daemon's status:
6398
```sh
@@ -80,8 +115,11 @@ sudo journalctl -f _SYSTEMD_UNIT=tox-bootstrapd.service
80115
- Make sure tox-bootstrapd location matches its path in tox-bootstrapd.service file.
81116

82117

83-
<a name="initd" />
84-
##For `init.d` users
118+
<a name="sysvinit" />
119+
##For `SysVinit` users
120+
121+
<a name="sysvinit-setting-up" />
122+
###Setting up
85123

86124
For security reasons we run the daemon under its own user.
87125

@@ -126,8 +164,29 @@ Get your public key and check that the daemon initialized correctly:
126164
sudo grep "tox-bootstrapd" /var/log/syslog
127165
```
128166

129-
<a name="initd-troubleshooting" />
130-
###Troubleshooting:
167+
<a name="sysvinit-updating" />
168+
###Updating
169+
170+
You want to make sure that the daemon uses the newest toxcore, as there might have been some changes done to the DHT, so it's advised to update the daemon at least once every month.
171+
172+
To update the daemon first stop it:
173+
174+
```sh
175+
sudo service tox-bootstrapd stop
176+
```
177+
178+
Then update your toxcore git repository, rebuild the toxcore and the daemon and make sure to install them.
179+
180+
Check if `tox-bootstrapd.sh` in toxcore git repository was modified since the last time you copied it, as you might need to update it too.
181+
182+
After all of this is done, simply start the daemon back again:
183+
184+
```sh
185+
sudo service tox-bootstrapd start
186+
```
187+
188+
<a name="sysvinit-troubleshooting" />
189+
###Troubleshooting
131190

132191
- Check daemon's status:
133192
```sh
@@ -146,3 +205,63 @@ sudo grep "tox-bootstrapd" /var/log/syslog
146205
- Make sure tox-bootstrapd has read permission for the config file.
147206

148207
- Make sure tox-bootstrapd location matches its path in the `/etc/init.d/tox-bootstrapd` init script.
208+
209+
210+
<a name="docker" />
211+
##For `Docker` users:
212+
213+
<a name="docker-setting-up" />
214+
###Setting up
215+
216+
If you are familiar with Docker and would rather run the daemon in a Docker container, run the following from this directory:
217+
218+
```sh
219+
sudo docker build -t tox-bootstrapd docker/
220+
221+
sudo useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
222+
sudo chmod 700 /var/lib/tox-bootstrapd
223+
224+
sudo docker run -d --name tox-bootstrapd --restart always -v /var/lib/tox-bootstrapd/:/var/lib/tox-bootstrapd/ -p 443:443 -p 3389:3389 -p 33445:33445 -p 33445:33445/udp tox-bootstrapd
225+
```
226+
227+
We create a new user and protect its home directory in order to mount it in the Docker image, so that the kyepair the daemon uses would be stored on the host system, which makes it less likely that you would loose the keypair while playing with or updating the Docker container.
228+
229+
You can check logs for your public key or any errors:
230+
```sh
231+
sudo docker logs tox-bootstrapd
232+
```
233+
234+
Note that the Docker container runs a script which pulls a list of bootstrap nodes off https://nodes.tox.chat/ and adds them in the config file.
235+
236+
<a name="docker-updating" />
237+
###Updating
238+
239+
You want to make sure that the daemon uses the newest toxcore, as there might have been some changes done to the DHT, so it's advised to update the daemon at least once every month.
240+
241+
To update the daemon, all you need is to erase current container with its image:
242+
243+
```sh
244+
sudo docker stop tox-bootstrapd
245+
sudo docker rm tox-bootstrapd
246+
sudo docker rmi tox-bootstrapd
247+
```
248+
249+
Then rebuild and run the image again:
250+
251+
```sh
252+
sudo docker build -t tox-bootstrapd docker/
253+
sudo docker run -d --name tox-bootstrapd --restart always -v /var/lib/tox-bootstrapd/:/var/lib/tox-bootstrapd/ -p 443:443 -p 3389:3389 -p 33445:33445 -p 33445:33445/udp tox-bootstrapd
254+
```
255+
256+
<a name="docker-troubleshooting" />
257+
###Troubleshooting
258+
259+
- Check if the container is running:
260+
```sh
261+
sudo docker ps -a
262+
```
263+
264+
- Check the log for errors:
265+
```sh
266+
sudo docker logs tox-bootstrapd
267+
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM debian:jessie
2+
3+
# get all deps
4+
RUN apt-get update && apt-get install -y \
5+
build-essential \
6+
libtool \
7+
autotools-dev \
8+
automake \
9+
checkinstall \
10+
check \
11+
git \
12+
yasm \
13+
libsodium-dev \
14+
libconfig-dev \
15+
python3 \
16+
&& apt-get clean \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# install toxcore and daemon
20+
WORKDIR /root/
21+
RUN git clone https://github.com/irungentoo/toxcore
22+
WORKDIR /root/toxcore/
23+
RUN ./autogen.sh
24+
RUN ./configure --enable-daemon
25+
RUN make -j`nproc`
26+
RUN make install -j`nproc`
27+
RUN ldconfig
28+
29+
WORKDIR /root/toxcore/other/bootstrap_daemon/
30+
31+
# add new user
32+
RUN useradd --home-dir /var/lib/tox-bootstrapd --create-home \
33+
--system --shell /sbin/nologin \
34+
--comment "Account to run Tox's DHT bootstrap daemon" \
35+
--user-group tox-bootstrapd
36+
RUN chmod 700 /var/lib/tox-bootstrapd
37+
38+
RUN cp tox-bootstrapd.conf /etc/tox-bootstrapd.conf
39+
40+
# remove all the example bootstrap nodes from the config file
41+
RUN N=-1 && \
42+
while grep -q "bootstrap_nodes =" /etc/tox-bootstrapd.conf; \
43+
do \
44+
head -n $N tox-bootstrapd.conf > /etc/tox-bootstrapd.conf; \
45+
N=$((N-1)); \
46+
done
47+
48+
# add bootstrap nodes from https://nodes.tox.chat/
49+
RUN python3 docker/get-nodes.py >> /etc/tox-bootstrapd.conf
50+
51+
USER tox-bootstrapd
52+
53+
ENTRYPOINT /usr/local/bin/tox-bootstrapd \
54+
--config /etc/tox-bootstrapd.conf \
55+
--log-backend stdout \
56+
--foreground
57+
58+
EXPOSE 443 3389 33445
59+
EXPOSE 33445/udp
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Copyright (c) 2016 by nurupo <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
"""
23+
24+
# Gets a list of nodes from https://nodes.tox.chat/json and prints them out
25+
# in the format of tox-bootstrapd config file.
26+
27+
import urllib.request
28+
import json
29+
30+
response = urllib.request.urlopen('https://nodes.tox.chat/json')
31+
raw_json = response.read().decode('ascii', 'ignore')
32+
nodes = json.loads(raw_json)['nodes']
33+
34+
output = 'bootstrap_nodes = ('
35+
36+
for node in nodes:
37+
node_output = ' { // ' + node['maintainer'] + '\n'
38+
node_output += ' public_key = "' + node['public_key'] + '"\n'
39+
node_output += ' port = ' + str(node['port']) + '\n'
40+
node_output += ' address = "'
41+
if len(node['ipv4']) > 4:
42+
output += node_output + node['ipv4'] + '"\n },\n'
43+
if len(node['ipv6']) > 4:
44+
output += node_output + node['ipv6'] + '"\n },\n'
45+
46+
# remove last comma
47+
output = output[:-2] + '\n)\n'
48+
49+
print(output)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
if BUILD_DHT_BOOTSTRAP_DAEMON
2+
3+
bin_PROGRAMS += tox-bootstrapd
4+
5+
tox_bootstrapd_SOURCES = \
6+
../other/bootstrap_daemon/src/command_line_arguments.c \
7+
../other/bootstrap_daemon/src/command_line_arguments.h \
8+
../other/bootstrap_daemon/src/config.c \
9+
../other/bootstrap_daemon/src/config_defaults.h \
10+
../other/bootstrap_daemon/src/config.h \
11+
../other/bootstrap_daemon/src/log.c \
12+
../other/bootstrap_daemon/src/log.h \
13+
../other/bootstrap_daemon/src/tox-bootstrapd.c \
14+
../other/bootstrap_node_packets.c \
15+
../other/bootstrap_node_packets.h
16+
17+
18+
tox_bootstrapd_CFLAGS = \
19+
-I$(top_srcdir)/other/bootstrap_daemon \
20+
$(LIBSODIUM_CFLAGS) \
21+
$(NACL_CFLAGS) \
22+
$(LIBCONFIG_CFLAGS)
23+
24+
tox_bootstrapd_LDADD = \
25+
$(LIBSODIUM_LDFLAGS) \
26+
$(NACL_LDFLAGS) \
27+
libtoxcore.la \
28+
$(LIBCONFIG_LIBS) \
29+
$(LIBSODIUM_LIBS) \
30+
$(NACL_LIBS)
31+
32+
endif
33+
34+
EXTRA_DIST += \
35+
$(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd.conf \
36+
$(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd.service \
37+
$(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd.sh
38+

0 commit comments

Comments
 (0)