summaryrefslogtreecommitdiff
path: root/other
diff options
context:
space:
mode:
authorAstonex <softukitu@gmail.com>2013-07-27 02:52:24 +0100
committerAstonex <softukitu@gmail.com>2013-07-27 02:52:24 +0100
commit3e1b96f333b7e51c8a714c2e701e7310239f1364 (patch)
tree838d8d55a7f2f69830ff59161820f21e86ddcca0 /other
parent37a300f9021cbf8c5e6e1134ae8eee9c33307eb7 (diff)
parent1b4ea2e1aeb874e872a2c767326633450de12d20 (diff)
Merge remote-tracking branch 'ProjectTox/master'
Diffstat (limited to 'other')
-rw-r--r--other/DHT_bootstrap.c27
-rw-r--r--other/bootstrap_serverdaemon/CMakeLists.txt1
-rw-r--r--other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c412
-rwxr-xr-xother/bootstrap_serverdaemon/DHT_bootstrap_daemon.sh109
-rw-r--r--other/bootstrap_serverdaemon/initscript.sh109
-rw-r--r--other/bootstrap_serverdaemon/server.cfg30
6 files changed, 512 insertions, 176 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index 0bacccd9..8942c237 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -6,6 +6,25 @@
6 * gcc -O2 -Wall -D VANILLA_NACL -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../core/friend_requests.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_bootstrap.c 6 * gcc -O2 -Wall -D VANILLA_NACL -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../core/friend_requests.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_bootstrap.c
7 * 7 *
8 * gcc -O2 -Wall -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../core/friend_requests.c -lsodium DHT_bootstrap.c 8 * gcc -O2 -Wall -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../core/friend_requests.c -lsodium DHT_bootstrap.c
9 *
10 *
11 * Copyright (C) 2013 Tox project All Rights Reserved.
12 *
13 * This file is part of Tox.
14 *
15 * Tox is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * Tox is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
27 *
9 */ 28 */
10 29
11#include "../core/DHT.h" 30#include "../core/DHT.h"
@@ -22,12 +41,14 @@
22 41
23#define PORT 33445 42#define PORT 33445
24 43
44//TODO: rewrite
25unsigned char * hex_string_to_bin(char hex_string[]) 45unsigned char * hex_string_to_bin(char hex_string[])
26{ 46{
27 unsigned char * val = malloc(strlen(hex_string)); 47 size_t len = strlen(hex_string);
48 unsigned char * val = malloc(len);
28 char * pos = hex_string; 49 char * pos = hex_string;
29 int i=0; 50 int i=0;
30 while(i < strlen(hex_string)) 51 while(i < len)
31 { 52 {
32 sscanf(pos,"%2hhx",&val[i]); 53 sscanf(pos,"%2hhx",&val[i]);
33 pos+=2; 54 pos+=2;
@@ -120,4 +141,4 @@ int main(int argc, char *argv[])
120 } 141 }
121 shutdown_networking(); 142 shutdown_networking();
122 return 0; 143 return 0;
123} \ No newline at end of file 144}
diff --git a/other/bootstrap_serverdaemon/CMakeLists.txt b/other/bootstrap_serverdaemon/CMakeLists.txt
index bc717d4b..6aa4dbee 100644
--- a/other/bootstrap_serverdaemon/CMakeLists.txt
+++ b/other/bootstrap_serverdaemon/CMakeLists.txt
@@ -6,4 +6,5 @@ set(exe_name DHT_bootstrap_daemon)
6add_executable(${exe_name} 6add_executable(${exe_name}
7 DHT_bootstrap_daemon.c) 7 DHT_bootstrap_daemon.c)
8 8
9target_link_libraries(${exe_name} config)
9linkCoreLibraries(${exe_name}) 10linkCoreLibraries(${exe_name})
diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
index 4d79c48b..8e278b28 100644
--- a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
+++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
@@ -1,50 +1,323 @@
1/* DHT boostrap 1/* DHT boostrap
2* 2 *
3* A simple DHT boostrap server for tox (daemon edition) 3 * A simple DHT boostrap server for tox - daemon edition.
4*/ 4 *
5 5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
6#include <sys/types.h> /* pid_t */ 24#include <sys/types.h> /* pid_t */
7#include <sys/stat.h> /* umask */ 25#include <sys/stat.h> /* umask */
8#include <stdio.h>
9#include <stdlib.h>
10#include <unistd.h> /* POSIX things */ 26#include <unistd.h> /* POSIX things */
11#include <errno.h> 27#include <errno.h>
12 28
29#include <stdio.h>
30#include <stdlib.h>
31#include <libconfig.h>
32#include <arpa/inet.h> /* htons() */
33#include <string.h> /* strcpy() */
34
13#include "../../core/DHT.h" 35#include "../../core/DHT.h"
14#include "../../core/friend_requests.h" 36#include "../../core/friend_requests.h"
15 37
16 38#define DEFAULT_PORT 33445
17/* Sleep function (x = milliseconds) */ 39#define DEFAULT_PID_FILE "bootstrap_server.pid"
18#ifdef WIN32 40#define DEFAULT_KEYS_FILE "bootstrap_server.keys"
19#define c_sleep(x) Sleep(1*x) 41
20#else 42/* Server info struct */
21#include <unistd.h> 43struct server_info_s {
22#define c_sleep(x) usleep(1000*x) 44 int valid;
23#endif 45 IP_Port conn;
24 46 uint8_t bs_pk[32];
25#define PORT 33445 47};
26#define USERNAME getenv("USER") 48
27#define PIDFILE "/home/%s/.bootstrap_server.pid" /* %s represents the unser's name */ 49/* This is the struct configure_server() uses to return its data to */
28 50struct server_conf_s {
51 int err;
52 int port;
53 char pid_file[512];
54 char keys_file[512];
55 struct server_info_s info[32];
56};
57
58int b16_to_key(char b16_string[], uint8_t *bs_pubkey) {
59
60 int i;
61 unsigned int num1 = 0, num2 = 0;
62
63 for(i = 0; i < 32; ++i)
64 {
65 sscanf(&b16_string[i*2], "%1X", &num1);
66 sscanf(&b16_string[i*2+1], "%1X", &num2);
67 num1 = num1 << 4;
68 bs_pubkey[i] = bs_pubkey[i] | num1;
69 bs_pubkey[i] = bs_pubkey[i] | num2;
70 }
71 return 0;
72}
73
74/* This unction connects to all specified servers
75and connect to them.
76returns 1 if the connection to the DHT is up
77returns -1 if all attempts failed
78*/
79int connect_to_servers(struct server_info_s *info)
80{
81 int i;
82 int c;
83
84 IP_Port ip_port;
85 uint8_t data[MAX_UDP_PACKET_SIZE];
86 uint32_t length;
87
88 for(i = 0; i < 32; ++i) {
89 if(info[i].valid) {
90 /* Actual bootstrapping code goes here */
91 //puts("Calling DHT_bootstrap");
92 DHT_bootstrap(info[i].conn, info[i].bs_pk);
93 }
94 }
95
96 /* Check if we're connected to the DHT */
97 for(c = 0; c != 100; ++c) {
98 usleep(10000);
99 if(DHT_isconnected()) {
100 //puts("Connected");
101 return 1;
102 break;
103 }
104 if(DHT_isconnected() == 0 && c == 99) {
105 //puts("Not connected");
106 return -1;
107 break;
108 }
109
110 doDHT();
111
112 while(receivepacket(&ip_port, data, &length) != -1)
113 {
114 DHT_handlepacket(data, length, ip_port);
115 }
116 }
117
118 /* This probably never happens */
119 return 0;
120}
121
122void manage_keys(char *keys_file)
123{
124 const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
125 uint8_t keys[KEYS_SIZE];
126
127 /* TODO: stat the file before trying to open it. We aren't cave people! */
128 FILE *keysf = fopen(keys_file, "r");
129 if (keysf != NULL) {
130 /* if file was opened successfully -- load keys */
131 size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keysf);
132 if (read_size != KEYS_SIZE) {
133 printf("Error while reading the key file\nExiting.\n");
134 exit(1);
135 } else {
136 printf("Keys loaded successfully\n");
137 }
138 load_keys(keys);
139
140 } else {
141 /* otherwise save new keys */
142 /* Silly work-around to ignore any errors coming from new_keys() */
143 new_keys();
144 save_keys(keys);
145 keysf = fopen(keys_file, "w");
146 if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keysf) != KEYS_SIZE) {
147 printf("Error while writing the key file.\nExiting.\n");
148 exit(1);
149 } else {
150 printf("Keys saved successfully\n");
151 }
152 }
153
154 fclose(keysf);
155}
156
157/* This reads the configuration file, and returns a struct server_conf_s with:
158 *an error number:
159 *-1 = file wasn't read, for whatever reason
160 *-2 = no bootstrap servers found
161 *the port
162 *the location of the keys file
163 *the location of the PID file
164 *the list of bootstrap servers
165*/
166struct server_conf_s configure_server(char *cfg_file)
167{
168 config_t cfg;
169 config_setting_t *server_list;
170
171 /* This one will be strcpy'd into the pid_file array in server_conf */
172 const char *pid_file_tmp;
173 const char *keys_file_tmp;
174
175 /* Remote bootstrap server variables */
176 int bs_port;
177 const char *bs_ip;
178 const char *bs_pk;
179
180 /* The big struct */
181 static struct server_conf_s server_conf;
182
183 /* Set both to their default values. If there's an error
184 with opening/reading the config file, we return right away */
185 server_conf.port = DEFAULT_PORT;
186 strcpy(server_conf.pid_file, DEFAULT_PID_FILE);
187 strcpy(server_conf.keys_file, DEFAULT_KEYS_FILE);
188
189 config_init(&cfg);
190
191 /* Read the file. If there is an error, report it and exit. */
192 if(! config_read_file(&cfg, cfg_file))
193 {
194 fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
195 config_error_line(&cfg), config_error_text(&cfg));
196 config_destroy(&cfg);
197 server_conf.err = -1;
198 return server_conf;
199 }
200
201 /* Get the port to listen on */
202 if(config_lookup_int(&cfg, "port", &server_conf.port)) {
203 //printf("Port: %d\n", port);
204 } else {
205 fprintf(stderr, "No 'port' setting in configuration file.\n");
206 }
207
208 /* Get PID file location */
209 if(config_lookup_string(&cfg, "pid_file", &pid_file_tmp)) {
210 //printf("PID file: %s\n", pid_file_tmp);
211 strcpy(server_conf.pid_file, pid_file_tmp);
212 } else {
213 fprintf(stderr, "No 'pid_file' setting in configuration file.\n");
214 }
215
216 /* Get keys file location */
217 if(config_lookup_string(&cfg, "keys_file", &keys_file_tmp)) {
218 //printf("Keys file: %s\n", keys_file_tmp);
219 strcpy(server_conf.keys_file, keys_file_tmp);
220 } else {
221 fprintf(stderr, "No 'keys_file' setting in configuration file.\n");
222 }
223
224 /* Get all the servers in the list */
225 server_list = config_lookup(&cfg, "bootstrap_servers");
226 if(server_list != NULL) {
227 int count = config_setting_length(server_list);
228 int i;
229
230 char tmp_ip[30]; /* IP */
231 char tmp_pk[64]; /* bs_pk */
232 for(i = 0; i < count; ++i) {
233 config_setting_t *server = config_setting_get_elem(server_list, i);
234 /* Get a pointer on the key aray */
235 uint8_t *bs_pk_p = server_conf.info[i].bs_pk;
236
237 /* Only output the record if all of the expected fields are present. */
238 if(!(config_setting_lookup_string(server, "ip", &bs_ip)
239 && config_setting_lookup_int(server, "port", &bs_port)
240 && config_setting_lookup_string(server, "bs_pk", &bs_pk)))
241 continue;
242
243 /* Converting all that stuff into usable formats and storing
244 it away in the server_info struct */
245 server_conf.info[i].valid = 1;
246
247 if(resolve_addr(strcpy(tmp_ip, bs_ip)) == -1) {
248 server_conf.info[i].valid = 0;
249 printf("bootstrap_server %d: Invalid IP\n", i);
250 }
251
252 if(strlen(bs_pk) != 64) {
253 server_conf.info[i].valid = 0;
254 printf("bootstrap_server %d: Invalid public key\n", i);
255 }
256
257 if(!bs_port) {
258 server_conf.info[i].valid = 0;
259 printf("bootstrap_server %d: Invalid port\n", i);
260 }
261
262 server_conf.info[i].conn.ip.i = resolve_addr(strcpy(tmp_ip, bs_ip));
263 server_conf.info[i].conn.port = htons(bs_port);
264 b16_to_key(strcpy(tmp_pk, bs_pk), bs_pk_p);
265 }
266
267 /* Check if at least one server entry is valid */
268 for(i = 0; i < 32; ++i) {
269 if(server_conf.info[i].valid)
270 break;
271 else
272 server_conf.err = -2;
273 }
274
275 } else {
276 server_conf.err = -2;
277 }
278
279 config_destroy(&cfg);
280 return server_conf;
281}
282
29int main(int argc, char *argv[]) { 283int main(int argc, char *argv[]) {
30 284
31 char pidfloc[512]; /* Location of the soon-to-be PID file */
32 pid_t pid, sid; /* Process- and Session-ID */ 285 pid_t pid, sid; /* Process- and Session-ID */
33 286 struct server_conf_s server_conf;
287
34 FILE *pidf; /* The PID file */ 288 FILE *pidf; /* The PID file */
35 289
36 /* Assemble PID file location an try to open the file */ 290 if(argc < 2) {
37 sprintf(pidfloc, PIDFILE, USERNAME); 291 printf("Please specify a configuration file.\n");
38 pidf = fopen(pidfloc, "w"); 292 exit(EXIT_FAILURE);
39 293 }
40 /* Generate new keypair */ 294
41 new_keys(); 295 /* Read the config file */
42 296 server_conf = configure_server(argv[1]);
297
298 printf("PID file: %s\n", server_conf.pid_file);
299 printf("Key file: %s\n", server_conf.keys_file);
300
301 if(server_conf.err == -1)
302 printf("Config file not read.\n");
303
304 if(server_conf.err == -2)
305 printf("No valid servers in list.\n");
306
307 /* Open PID file for writing - if an error happens,
308 it will be caught down the line */
309 pidf = fopen(server_conf.pid_file, "w");
310
311 /* Manage the keys */
312 /* for now, just ignore any errors after this call. */
313 int tmperr = errno;
314 manage_keys(server_conf.keys_file);
315 errno = tmperr;
316
43 /* Public key */ 317 /* Public key */
44 uint32_t i; 318 int i;
45
46 printf("\nPublic Key: "); 319 printf("\nPublic Key: ");
47 for(i = 0; i < 32; i++) 320 for(i = 0; i < 32; ++i)
48 { 321 {
49 uint8_t ln, hn; 322 uint8_t ln, hn;
50 ln = 0x0F & self_public_key[i]; 323 ln = 0x0F & self_public_key[i];
@@ -53,84 +326,95 @@ int main(int argc, char *argv[]) {
53 printf("%X%X", hn, ln); 326 printf("%X%X", hn, ln);
54 } 327 }
55 printf("\n"); 328 printf("\n");
56 329
57 /* initialize networking 330 /* initialize networking
58 bind to ip 0.0.0.0:PORT */ 331 bind to ip 0.0.0.0:PORT */
59 IP ip; 332 IP ip;
60 ip.i = 0; 333 ip.i = 0;
61 init_networking(ip, PORT); 334 init_networking(ip, server_conf.port);
62 335
336 /* Bootstrap the DHT
337 This one throws odd errors, too. Ignore. I assume they come
338 from somewhere in the core. */
339 tmperr = errno;
340 connect_to_servers(server_conf.info);
341 errno = tmperr;
342
343 if(!DHT_isconnected()) {
344 puts("Could not establish DHT connection. Check server settings.\n");
345 exit(EXIT_FAILURE);
346 } else {
347 printf("Connected to DHT successfully.\n");
348 }
349
63 /* If there's been an error, exit before forking off */ 350 /* If there's been an error, exit before forking off */
64 if (errno != 0) { 351 if (errno != 0) {
65 perror("Error"); 352 perror("Error");
66 printf("Error(s) occured during start-up. Exiting.\n"); 353 printf("Error(s) occured during start-up. Exiting.\n");
67 exit(EXIT_FAILURE); 354 exit(EXIT_FAILURE);
68 } 355 }
69 356
70// /* Assemble the location of the PID file */ 357 /* Things that make the daemon work come past here.
71// sprintf(pidfloc, PIDFILE, USERNAME); 358 There should be nothing here but the daemon code and
72// pidf = fopen(pidfloc, "w"); 359 the main loop. */
73// /* Check if we can actually open the file */ 360
74// if(pidf == NULL) { 361 /* Fork off from the parent process */
75// printf("Couldn't open PID-File %s for writing.\n", pidfloc);
76// exit(EXIT_FAILURE);
77// }
78
79 /* Fork off the parent process */
80 pid = fork(); 362 pid = fork();
81 if (pid < 0) { 363 if (pid < 0) {
82 printf("Forking failed.\n"); 364 printf("Forking failed.\n");
83 exit(EXIT_FAILURE); 365 exit(EXIT_FAILURE);
84 } 366 }
85 367
86 /* If we got a good PID, then 368 /* If we got a good PID, then
87 we can exit the parent process. */ 369 we can exit the parent process. */
88 if (pid > 0) { 370 if (pid > 0) {
89 printf("Forked successfully: %d\n", pid); 371 printf("Forked successfully: %d\n", pid);
90 372
91 /* Write the PID file */ 373 /* Write the PID file */
92 fprintf(pidf, "%d\n", pid); 374 fprintf(pidf, "%d\n", pid);
93 fclose(pidf); 375 fclose(pidf);
94 376
95 /* Exit parent */ 377 /* Exit parent */
96 exit(EXIT_SUCCESS); 378 exit(EXIT_SUCCESS);
97 } 379 }
98 380
99 /* Change the file mode mask */ 381 /* Change the file mode mask */
100 umask(0); 382 umask(0);
101 383
102 /* Create a new SID for the child process */ 384 /* Create a new SID for the child process */
103 sid = setsid(); 385 sid = setsid();
104 if (sid < 0) { 386 if (sid < 0) {
105 printf("SID creation failure.\n"); 387 printf("SID creation failure.\n");
106 exit(EXIT_FAILURE); 388 exit(EXIT_FAILURE);
107 } 389 }
108 390
109 /* Change the current working directory */ 391 /* Change the current working directory */
110 if ((chdir("/")) < 0) { 392 if ((chdir("/")) < 0) {
111 exit(EXIT_FAILURE); 393 exit(EXIT_FAILURE);
112 } 394 }
113 395
114 /* Go quiet */ 396 /* Go quiet */
115 close(STDIN_FILENO);
116 close(STDOUT_FILENO); 397 close(STDOUT_FILENO);
398 close(STDIN_FILENO);
117 close(STDERR_FILENO); 399 close(STDERR_FILENO);
118 400
401 /* Main loop */
119 IP_Port ip_port; 402 IP_Port ip_port;
120 uint8_t data[MAX_UDP_PACKET_SIZE]; 403 uint8_t data[MAX_UDP_PACKET_SIZE];
121 uint32_t length; 404 uint32_t length;
122 405
123 /* Main loop */ 406 while(1)
124 while(1) { 407 {
125 doDHT(); 408 doDHT();
126 while(receivepacket(&ip_port, data, &length) != -1) { 409
410 while(receivepacket(&ip_port, data, &length) != -1)
411 {
127 DHT_handlepacket(data, length, ip_port); 412 DHT_handlepacket(data, length, ip_port);
128 friendreq_handlepacket(data, length, ip_port); 413 friendreq_handlepacket(data, length, ip_port);
129 } 414 }
130 c_sleep(1); 415 usleep(10000);
131 } 416 }
132 417
133 shutdown_networking(); 418 shutdown_networking();
134 exit(EXIT_SUCCESS); 419 exit(EXIT_SUCCESS);
135} 420}
136
diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.sh b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.sh
new file mode 100755
index 00000000..936bc808
--- /dev/null
+++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.sh
@@ -0,0 +1,109 @@
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides: DHT_bootstrap_daemon
4# Required-Start: $remote_fs $syslog
5# Required-Stop: $remote_fs $syslog
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Start the Tox bootstrapping server
9# Description: Use this piece of junk to start the Tox
10# bootstrap server.
11### END INIT INFO
12
13# PATH should only include /usr/* if it runs after the mountnfs.sh script
14PATH=/sbin:/usr/sbin:/bin:/usr/bin
15DESC="ProjectTox bootstrap server daemon"
16NAME=DHT_bootstrap_daemon
17CFG=/home/$USER/server.cfg
18DAEMON=/home/$USER/$NAME
19DAEMON_ARGS="$CFG"
20PIDFILE=/home/$USER/.$NAME.pid
21SCRIPTNAME=/etc/init.d/$NAME
22
23# Exit if the package is not installed
24[ -x "$DAEMON" ] || exit 0
25
26# Read configuration variable file if it is present
27#[ -r /etc/default/$NAME ] && . /etc/default/$NAME
28
29# Load the VERBOSE setting and other rcS variables
30. /lib/init/vars.sh
31
32# Define LSB log_* functions.
33# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
34# and status_of_proc is working.
35. /lib/lsb/init-functions
36
37#
38# Function that starts the daemon/service
39#
40do_start()
41{
42 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
43 || return 1
44 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
45 $DAEMON_ARGS \
46 || return 2
47 sleep 1
48}
49
50#
51# Function that stops the daemon/service
52#
53do_stop()
54{
55 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON
56 RETVAL="$?"
57 [ "$RETVAL" = 2 ] && return 2
58
59 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
60 [ "$?" = 2 ] && return 2
61 # Many daemons don't delete their pidfiles when they exit.
62 rm -f $PIDFILE
63 return "$RETVAL"
64}
65
66case "$1" in
67 start)
68 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
69 do_start
70 case "$?" in
71 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
72 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
73 esac
74 ;;
75 stop)
76 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
77 do_stop
78 case "$?" in
79 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
80 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
81 esac
82 ;;
83 status)
84 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
85 ;;
86
87 restart) #|force-reload)
88 log_daemon_msg "Restarting $DESC" "$NAME"
89 do_stop
90 case "$?" in
91 0|1)
92 do_start
93 case "$?" in
94 0) log_end_msg 0 ;;
95 1) log_end_msg 1 ;; # Old process is still running
96 *) log_end_msg 1 ;; # Failed to start
97 esac
98 ;;
99 *)
100 # Failed to stop
101 log_end_msg 1
102 ;;
103 esac
104 ;;
105 *)
106 echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
107 exit 3
108 ;;
109esac
diff --git a/other/bootstrap_serverdaemon/initscript.sh b/other/bootstrap_serverdaemon/initscript.sh
deleted file mode 100644
index aa4b3e77..00000000
--- a/other/bootstrap_serverdaemon/initscript.sh
+++ /dev/null
@@ -1,109 +0,0 @@
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides: bootstrap_server
4# Required-Start: $remote_fs $syslog
5# Required-Stop: $remote_fs $syslog
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Start the Tox bootstrapping server
9# Description: Use this piece of junk to start the Tox
10# bootstrap server.
11### END INIT INFO
12
13# PATH should only include /usr/* if it runs after the mountnfs.sh script
14PATH=/sbin:/usr/sbin:/bin:/usr/bin
15DESC="ProjectTox bootstrap server daemon"
16NAME=bootstrap_server
17DAEMON=/home/$USER/$NAME
18DAEMON_ARGS=""
19PIDFILE=/home/$USER/.$NAME.pid
20SCRIPTNAME=/etc/init.d/$NAME
21
22# Exit if the package is not installed
23[ -x "$DAEMON" ] || exit 0
24
25# Read configuration variable file if it is present
26[ -r /etc/default/$NAME ] && . /etc/default/$NAME
27
28# Load the VERBOSE setting and other rcS variables
29. /lib/init/vars.sh
30
31# Define LSB log_* functions.
32# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
33# and status_of_proc is working.
34. /lib/lsb/init-functions
35
36#
37# Function that starts the daemon/service
38#
39do_start()
40{
41 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
42 || return 1
43 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
44 $DAEMON_ARGS \
45 || return 2
46 sleep 1
47}
48
49#
50# Function that stops the daemon/service
51#
52do_stop()
53{
54 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON
55 RETVAL="$?"
56 [ "$RETVAL" = 2 ] && return 2
57
58 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
59 [ "$?" = 2 ] && return 2
60 # Many daemons don't delete their pidfiles when they exit.
61 rm -f $PIDFILE
62 return "$RETVAL"
63}
64
65case "$1" in
66 start)
67 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
68 do_start
69 case "$?" in
70 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
71 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
72 esac
73 ;;
74 stop)
75 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
76 do_stop
77 case "$?" in
78 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
79 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
80 esac
81 ;;
82 status)
83 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
84 ;;
85
86 restart) #|force-reload)
87 log_daemon_msg "Restarting $DESC" "$NAME"
88 do_stop
89 case "$?" in
90 0|1)
91 do_start
92 case "$?" in
93 0) log_end_msg 0 ;;
94 1) log_end_msg 1 ;; # Old process is still running
95 *) log_end_msg 1 ;; # Failed to start
96 esac
97 ;;
98 *)
99 # Failed to stop
100 log_end_msg 1
101 ;;
102 esac
103 ;;
104 *)
105 echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
106 exit 3
107 ;;
108esac
109
diff --git a/other/bootstrap_serverdaemon/server.cfg b/other/bootstrap_serverdaemon/server.cfg
new file mode 100644
index 00000000..8ef516ca
--- /dev/null
+++ b/other/bootstrap_serverdaemon/server.cfg
@@ -0,0 +1,30 @@
1// ProjectTox bootstrap server configuration file
2
3// The port used by bootstrap_server to listen on
4port = 33445;
5
6// The key file
7// make sure that the user who runs the server
8// does have permissions to read it/write to it
9keys_file = "/home/tom/.bootstrap_server.keys"
10
11// The PID file written to by bootstrap_server,
12// make sure that the user who runs the server
13// does have permissions to write to it
14pid_file = "/home/tom/.bootstrap_server.pid";
15
16// The info of the node bootstap_server will
17// bootstrap itself from.
18bootstrap_servers = (
19 { // Server 1
20 ip = "198.46.136.167";
21 port = 33445;
22 bs_pk = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854";
23// }
24 },
25 { // Server 2
26 ip = "192.81.133.111";
27 port = 33445;
28 bs_pk = "8CD5A9BF0A6CE358BA36F7A653F99FA6B258FF756E490F52C1F98CC420F78858";
29 }
30);