diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-23 17:31:08 -0700 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-23 17:31:08 -0700 |
commit | 3b53bc3218a8ffd149d4a93bb62becab41da7ae1 (patch) | |
tree | b5904dde54020c46f5e0778df7c907196e4eccc0 | |
parent | ff9e6822ec2518e14cc274407c506fe49f9cbddc (diff) | |
parent | 020aa7814fb3f9045721076fadd5794ce2c8e76e (diff) |
Merge pull request #96 from tawm/master
Make the bootstrap daemon configurable
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/CMakeLists.txt | 1 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c | 394 | ||||
-rwxr-xr-x | other/bootstrap_serverdaemon/DHT_bootstrap_daemon.sh | 109 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/initscript.sh | 109 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/server.cfg | 30 |
6 files changed, 475 insertions, 173 deletions
diff --git a/.travis.yml b/.travis.yml index 0a294bf1..4d49f5fe 100644 --- a/.travis.yml +++ b/.travis.yml | |||
@@ -4,6 +4,7 @@ compiler: | |||
4 | - clang | 4 | - clang |
5 | 5 | ||
6 | before_script: | 6 | before_script: |
7 | # installing libsodium, needed for Core | ||
7 | - git clone git://github.com/jedisct1/libsodium.git | 8 | - git clone git://github.com/jedisct1/libsodium.git |
8 | - cd libsodium | 9 | - cd libsodium |
9 | - git checkout tags/0.4.2 | 10 | - git checkout tags/0.4.2 |
@@ -12,6 +13,10 @@ before_script: | |||
12 | - sudo make install | 13 | - sudo make install |
13 | - sudo ldconfig | 14 | - sudo ldconfig |
14 | - cd .. | 15 | - cd .. |
16 | # installing libconfig, needed for DHT_bootstrap_daemon | ||
17 | - sudo sed -i 's/precise/quantal/' /etc/apt/sources.list # needed for libconfig-dev | ||
18 | - sudo apt-get update -qq | ||
19 | - yes | sudo apt-get install libconfig-dev | ||
15 | 20 | ||
16 | script: | 21 | script: |
17 | - mkdir build && cd build | 22 | - mkdir build && cd build |
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) | |||
6 | add_executable(${exe_name} | 6 | add_executable(${exe_name} |
7 | DHT_bootstrap_daemon.c) | 7 | DHT_bootstrap_daemon.c) |
8 | 8 | ||
9 | target_link_libraries(${exe_name} config) | ||
9 | linkCoreLibraries(${exe_name}) | 10 | linkCoreLibraries(${exe_name}) |
diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c index 4d79c48b..395bd7f2 100644 --- a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c +++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c | |||
@@ -1,50 +1,305 @@ | |||
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 | ||
6 | #include <sys/types.h> /* pid_t */ | 6 | #include <sys/types.h> /* pid_t */ |
7 | #include <sys/stat.h> /* umask */ | 7 | #include <sys/stat.h> /* umask */ |
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <unistd.h> /* POSIX things */ | 8 | #include <unistd.h> /* POSIX things */ |
11 | #include <errno.h> | 9 | #include <errno.h> |
12 | 10 | ||
11 | #include <stdio.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <libconfig.h> | ||
14 | #include <arpa/inet.h> /* htons() */ | ||
15 | #include <string.h> /* strcpy() */ | ||
16 | |||
13 | #include "../../core/DHT.h" | 17 | #include "../../core/DHT.h" |
14 | #include "../../core/friend_requests.h" | 18 | #include "../../core/friend_requests.h" |
15 | 19 | ||
16 | 20 | #define DEFAULT_PORT 33445 | |
17 | /* Sleep function (x = milliseconds) */ | 21 | #define DEFAULT_PID_FILE "bootstrap_server.pid" |
18 | #ifdef WIN32 | 22 | #define DEFAULT_KEYS_FILE "bootstrap_server.keys" |
19 | #define c_sleep(x) Sleep(1*x) | 23 | |
20 | #else | 24 | /* Server info struct */ |
21 | #include <unistd.h> | 25 | struct server_info_s { |
22 | #define c_sleep(x) usleep(1000*x) | 26 | int valid; |
23 | #endif | 27 | IP_Port conn; |
24 | 28 | uint8_t bs_pk[32]; | |
25 | #define PORT 33445 | 29 | }; |
26 | #define USERNAME getenv("USER") | 30 | |
27 | #define PIDFILE "/home/%s/.bootstrap_server.pid" /* %s represents the unser's name */ | 31 | /* This is the struct configure_server() uses to return its data to */ |
28 | 32 | struct server_conf_s { | |
33 | int err; | ||
34 | int port; | ||
35 | char pid_file[512]; | ||
36 | char keys_file[512]; | ||
37 | struct server_info_s info[32]; | ||
38 | }; | ||
39 | |||
40 | int b16_to_key(char b16_string[], uint8_t *bs_pubkey) { | ||
41 | |||
42 | int i; | ||
43 | unsigned int num1 = 0, num2 = 0; | ||
44 | |||
45 | for(i = 0; i < 32; ++i) | ||
46 | { | ||
47 | sscanf(&b16_string[i*2], "%1X", &num1); | ||
48 | sscanf(&b16_string[i*2+1], "%1X", &num2); | ||
49 | num1 = num1 << 4; | ||
50 | bs_pubkey[i] = bs_pubkey[i] | num1; | ||
51 | bs_pubkey[i] = bs_pubkey[i] | num2; | ||
52 | } | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | /* This unction connects to all specified servers | ||
57 | and connect to them. | ||
58 | returns 1 if the connection to the DHT is up | ||
59 | returns -1 if all attempts failed | ||
60 | */ | ||
61 | int connect_to_servers(struct server_info_s *info) | ||
62 | { | ||
63 | int i; | ||
64 | int c; | ||
65 | |||
66 | IP_Port ip_port; | ||
67 | uint8_t data[MAX_UDP_PACKET_SIZE]; | ||
68 | uint32_t length; | ||
69 | |||
70 | for(i = 0; i < 32; ++i) { | ||
71 | if(info[i].valid) { | ||
72 | /* Actual bootstrapping code goes here */ | ||
73 | //puts("Calling DHT_bootstrap"); | ||
74 | DHT_bootstrap(info[i].conn, info[i].bs_pk); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | /* Check if we're connected to the DHT */ | ||
79 | for(c = 0; c != 100; ++c) { | ||
80 | usleep(10000); | ||
81 | if(DHT_isconnected()) { | ||
82 | //puts("Connected"); | ||
83 | return 1; | ||
84 | break; | ||
85 | } | ||
86 | if(DHT_isconnected() == 0 && c == 99) { | ||
87 | //puts("Not connected"); | ||
88 | return -1; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | doDHT(); | ||
93 | |||
94 | while(receivepacket(&ip_port, data, &length) != -1) | ||
95 | { | ||
96 | DHT_handlepacket(data, length, ip_port); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /* This probably never happens */ | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | void manage_keys(char *keys_file) | ||
105 | { | ||
106 | const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; | ||
107 | uint8_t keys[KEYS_SIZE]; | ||
108 | |||
109 | /* TODO: stat the file before trying to open it. We aren't cave people! */ | ||
110 | FILE *keysf = fopen(keys_file, "r"); | ||
111 | if (keysf != NULL) { | ||
112 | /* if file was opened successfully -- load keys */ | ||
113 | size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keysf); | ||
114 | if (read_size != KEYS_SIZE) { | ||
115 | printf("Error while reading the key file\nExiting.\n"); | ||
116 | exit(1); | ||
117 | } else { | ||
118 | printf("Keys loaded successfully\n"); | ||
119 | } | ||
120 | load_keys(keys); | ||
121 | |||
122 | } else { | ||
123 | /* otherwise save new keys */ | ||
124 | /* Silly work-around to ignore any errors coming from new_keys() */ | ||
125 | new_keys(); | ||
126 | save_keys(keys); | ||
127 | keysf = fopen(keys_file, "w"); | ||
128 | if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keysf) != KEYS_SIZE) { | ||
129 | printf("Error while writing the key file.\nExiting.\n"); | ||
130 | exit(1); | ||
131 | } else { | ||
132 | printf("Keys saved successfully\n"); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | fclose(keysf); | ||
137 | } | ||
138 | |||
139 | /* This reads the configuration file, and returns a struct server_conf_s with: | ||
140 | *an error number: | ||
141 | *-1 = file wasn't read, for whatever reason | ||
142 | *-2 = no bootstrap servers found | ||
143 | *the port | ||
144 | *the location of the keys file | ||
145 | *the location of the PID file | ||
146 | *the list of bootstrap servers | ||
147 | */ | ||
148 | struct server_conf_s configure_server(char *cfg_file) | ||
149 | { | ||
150 | config_t cfg; | ||
151 | config_setting_t *server_list; | ||
152 | |||
153 | /* This one will be strcpy'd into the pid_file array in server_conf */ | ||
154 | const char *pid_file_tmp; | ||
155 | const char *keys_file_tmp; | ||
156 | |||
157 | /* Remote bootstrap server variables */ | ||
158 | int bs_port; | ||
159 | const char *bs_ip; | ||
160 | const char *bs_pk; | ||
161 | |||
162 | /* The big struct */ | ||
163 | static struct server_conf_s server_conf; | ||
164 | |||
165 | /* Set both to their default values. If there's an error | ||
166 | with opening/reading the config file, we return right away */ | ||
167 | server_conf.port = DEFAULT_PORT; | ||
168 | strcpy(server_conf.pid_file, DEFAULT_PID_FILE); | ||
169 | strcpy(server_conf.keys_file, DEFAULT_KEYS_FILE); | ||
170 | |||
171 | config_init(&cfg); | ||
172 | |||
173 | /* Read the file. If there is an error, report it and exit. */ | ||
174 | if(! config_read_file(&cfg, cfg_file)) | ||
175 | { | ||
176 | fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), | ||
177 | config_error_line(&cfg), config_error_text(&cfg)); | ||
178 | config_destroy(&cfg); | ||
179 | server_conf.err = -1; | ||
180 | return server_conf; | ||
181 | } | ||
182 | |||
183 | /* Get the port to listen on */ | ||
184 | if(config_lookup_int(&cfg, "port", &server_conf.port)) { | ||
185 | //printf("Port: %d\n", port); | ||
186 | } else { | ||
187 | fprintf(stderr, "No 'port' setting in configuration file.\n"); | ||
188 | } | ||
189 | |||
190 | /* Get PID file location */ | ||
191 | if(config_lookup_string(&cfg, "pid_file", &pid_file_tmp)) { | ||
192 | //printf("PID file: %s\n", pid_file_tmp); | ||
193 | strcpy(server_conf.pid_file, pid_file_tmp); | ||
194 | } else { | ||
195 | fprintf(stderr, "No 'pid_file' setting in configuration file.\n"); | ||
196 | } | ||
197 | |||
198 | /* Get keys file location */ | ||
199 | if(config_lookup_string(&cfg, "keys_file", &keys_file_tmp)) { | ||
200 | //printf("Keys file: %s\n", keys_file_tmp); | ||
201 | strcpy(server_conf.keys_file, keys_file_tmp); | ||
202 | } else { | ||
203 | fprintf(stderr, "No 'keys_file' setting in configuration file.\n"); | ||
204 | } | ||
205 | |||
206 | /* Get all the servers in the list */ | ||
207 | server_list = config_lookup(&cfg, "bootstrap_servers"); | ||
208 | if(server_list != NULL) { | ||
209 | int count = config_setting_length(server_list); | ||
210 | int i; | ||
211 | |||
212 | char tmp_ip[30]; /* IP */ | ||
213 | char tmp_pk[64]; /* bs_pk */ | ||
214 | for(i = 0; i < count; ++i) { | ||
215 | config_setting_t *server = config_setting_get_elem(server_list, i); | ||
216 | /* Get a pointer on the key aray */ | ||
217 | uint8_t *bs_pk_p = server_conf.info[i].bs_pk; | ||
218 | |||
219 | /* Only output the record if all of the expected fields are present. */ | ||
220 | if(!(config_setting_lookup_string(server, "ip", &bs_ip) | ||
221 | && config_setting_lookup_int(server, "port", &bs_port) | ||
222 | && config_setting_lookup_string(server, "bs_pk", &bs_pk))) | ||
223 | continue; | ||
224 | |||
225 | /* Converting all that stuff into usable formats and storing | ||
226 | it away in the server_info struct */ | ||
227 | server_conf.info[i].valid = 1; | ||
228 | |||
229 | if(resolve_addr(strcpy(tmp_ip, bs_ip)) == -1) { | ||
230 | server_conf.info[i].valid = 0; | ||
231 | printf("bootstrap_server %d: Invalid IP\n", i); | ||
232 | } | ||
233 | |||
234 | if(strlen(bs_pk) != 64) { | ||
235 | server_conf.info[i].valid = 0; | ||
236 | printf("bootstrap_server %d: Invalid public key\n", i); | ||
237 | } | ||
238 | |||
239 | if(!bs_port) { | ||
240 | server_conf.info[i].valid = 0; | ||
241 | printf("bootstrap_server %d: Invalid port\n", i); | ||
242 | } | ||
243 | |||
244 | server_conf.info[i].conn.ip.i = resolve_addr(strcpy(tmp_ip, bs_ip)); | ||
245 | server_conf.info[i].conn.port = htons(bs_port); | ||
246 | b16_to_key(strcpy(tmp_pk, bs_pk), bs_pk_p); | ||
247 | } | ||
248 | |||
249 | /* Check if at least one server entry is valid */ | ||
250 | for(i = 0; i < 32; ++i) { | ||
251 | if(server_conf.info[i].valid) | ||
252 | break; | ||
253 | else | ||
254 | server_conf.err = -2; | ||
255 | } | ||
256 | |||
257 | } else { | ||
258 | server_conf.err = -2; | ||
259 | } | ||
260 | |||
261 | config_destroy(&cfg); | ||
262 | return server_conf; | ||
263 | } | ||
264 | |||
29 | int main(int argc, char *argv[]) { | 265 | int main(int argc, char *argv[]) { |
30 | 266 | ||
31 | char pidfloc[512]; /* Location of the soon-to-be PID file */ | ||
32 | pid_t pid, sid; /* Process- and Session-ID */ | 267 | pid_t pid, sid; /* Process- and Session-ID */ |
33 | 268 | struct server_conf_s server_conf; | |
269 | |||
34 | FILE *pidf; /* The PID file */ | 270 | FILE *pidf; /* The PID file */ |
35 | 271 | ||
36 | /* Assemble PID file location an try to open the file */ | 272 | if(argc < 2) { |
37 | sprintf(pidfloc, PIDFILE, USERNAME); | 273 | printf("Please specify a configuration file.\n"); |
38 | pidf = fopen(pidfloc, "w"); | 274 | exit(EXIT_FAILURE); |
39 | 275 | } | |
40 | /* Generate new keypair */ | 276 | |
41 | new_keys(); | 277 | /* Read the config file */ |
42 | 278 | server_conf = configure_server(argv[1]); | |
279 | |||
280 | printf("PID file: %s\n", server_conf.pid_file); | ||
281 | printf("Key file: %s\n", server_conf.keys_file); | ||
282 | |||
283 | if(server_conf.err == -1) | ||
284 | printf("Config file not read.\n"); | ||
285 | |||
286 | if(server_conf.err == -2) | ||
287 | printf("No valid servers in list.\n"); | ||
288 | |||
289 | /* Open PID file for writing - if an error happens, | ||
290 | it will be caught down the line */ | ||
291 | pidf = fopen(server_conf.pid_file, "w"); | ||
292 | |||
293 | /* Manage the keys */ | ||
294 | /* for now, just ignore any errors after this call. */ | ||
295 | int tmperr = errno; | ||
296 | manage_keys(server_conf.keys_file); | ||
297 | errno = tmperr; | ||
298 | |||
43 | /* Public key */ | 299 | /* Public key */ |
44 | uint32_t i; | 300 | int i; |
45 | |||
46 | printf("\nPublic Key: "); | 301 | printf("\nPublic Key: "); |
47 | for(i = 0; i < 32; i++) | 302 | for(i = 0; i < 32; ++i) |
48 | { | 303 | { |
49 | uint8_t ln, hn; | 304 | uint8_t ln, hn; |
50 | ln = 0x0F & self_public_key[i]; | 305 | ln = 0x0F & self_public_key[i]; |
@@ -53,84 +308,95 @@ int main(int argc, char *argv[]) { | |||
53 | printf("%X%X", hn, ln); | 308 | printf("%X%X", hn, ln); |
54 | } | 309 | } |
55 | printf("\n"); | 310 | printf("\n"); |
56 | 311 | ||
57 | /* initialize networking | 312 | /* initialize networking |
58 | bind to ip 0.0.0.0:PORT */ | 313 | bind to ip 0.0.0.0:PORT */ |
59 | IP ip; | 314 | IP ip; |
60 | ip.i = 0; | 315 | ip.i = 0; |
61 | init_networking(ip, PORT); | 316 | init_networking(ip, server_conf.port); |
62 | 317 | ||
318 | /* Bootstrap the DHT | ||
319 | This one throws odd errors, too. Ignore. I assume they come | ||
320 | from somewhere in the core. */ | ||
321 | tmperr = errno; | ||
322 | connect_to_servers(server_conf.info); | ||
323 | errno = tmperr; | ||
324 | |||
325 | if(!DHT_isconnected()) { | ||
326 | puts("Could not establish DHT connection. Check server settings.\n"); | ||
327 | exit(EXIT_FAILURE); | ||
328 | } else { | ||
329 | printf("Connected to DHT successfully.\n"); | ||
330 | } | ||
331 | |||
63 | /* If there's been an error, exit before forking off */ | 332 | /* If there's been an error, exit before forking off */ |
64 | if (errno != 0) { | 333 | if (errno != 0) { |
65 | perror("Error"); | 334 | perror("Error"); |
66 | printf("Error(s) occured during start-up. Exiting.\n"); | 335 | printf("Error(s) occured during start-up. Exiting.\n"); |
67 | exit(EXIT_FAILURE); | 336 | exit(EXIT_FAILURE); |
68 | } | 337 | } |
69 | 338 | ||
70 | // /* Assemble the location of the PID file */ | 339 | /* Things that make the daemon work come past here. |
71 | // sprintf(pidfloc, PIDFILE, USERNAME); | 340 | There should be nothing here but the daemon code and |
72 | // pidf = fopen(pidfloc, "w"); | 341 | the main loop. */ |
73 | // /* Check if we can actually open the file */ | 342 | |
74 | // if(pidf == NULL) { | 343 | /* 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(); | 344 | pid = fork(); |
81 | if (pid < 0) { | 345 | if (pid < 0) { |
82 | printf("Forking failed.\n"); | 346 | printf("Forking failed.\n"); |
83 | exit(EXIT_FAILURE); | 347 | exit(EXIT_FAILURE); |
84 | } | 348 | } |
85 | 349 | ||
86 | /* If we got a good PID, then | 350 | /* If we got a good PID, then |
87 | we can exit the parent process. */ | 351 | we can exit the parent process. */ |
88 | if (pid > 0) { | 352 | if (pid > 0) { |
89 | printf("Forked successfully: %d\n", pid); | 353 | printf("Forked successfully: %d\n", pid); |
90 | 354 | ||
91 | /* Write the PID file */ | 355 | /* Write the PID file */ |
92 | fprintf(pidf, "%d\n", pid); | 356 | fprintf(pidf, "%d\n", pid); |
93 | fclose(pidf); | 357 | fclose(pidf); |
94 | 358 | ||
95 | /* Exit parent */ | 359 | /* Exit parent */ |
96 | exit(EXIT_SUCCESS); | 360 | exit(EXIT_SUCCESS); |
97 | } | 361 | } |
98 | 362 | ||
99 | /* Change the file mode mask */ | 363 | /* Change the file mode mask */ |
100 | umask(0); | 364 | umask(0); |
101 | 365 | ||
102 | /* Create a new SID for the child process */ | 366 | /* Create a new SID for the child process */ |
103 | sid = setsid(); | 367 | sid = setsid(); |
104 | if (sid < 0) { | 368 | if (sid < 0) { |
105 | printf("SID creation failure.\n"); | 369 | printf("SID creation failure.\n"); |
106 | exit(EXIT_FAILURE); | 370 | exit(EXIT_FAILURE); |
107 | } | 371 | } |
108 | 372 | ||
109 | /* Change the current working directory */ | 373 | /* Change the current working directory */ |
110 | if ((chdir("/")) < 0) { | 374 | if ((chdir("/")) < 0) { |
111 | exit(EXIT_FAILURE); | 375 | exit(EXIT_FAILURE); |
112 | } | 376 | } |
113 | 377 | ||
114 | /* Go quiet */ | 378 | /* Go quiet */ |
115 | close(STDIN_FILENO); | ||
116 | close(STDOUT_FILENO); | 379 | close(STDOUT_FILENO); |
380 | close(STDIN_FILENO); | ||
117 | close(STDERR_FILENO); | 381 | close(STDERR_FILENO); |
118 | 382 | ||
383 | /* Main loop */ | ||
119 | IP_Port ip_port; | 384 | IP_Port ip_port; |
120 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 385 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
121 | uint32_t length; | 386 | uint32_t length; |
122 | 387 | ||
123 | /* Main loop */ | 388 | while(1) |
124 | while(1) { | 389 | { |
125 | doDHT(); | 390 | doDHT(); |
126 | while(receivepacket(&ip_port, data, &length) != -1) { | 391 | |
392 | while(receivepacket(&ip_port, data, &length) != -1) | ||
393 | { | ||
127 | DHT_handlepacket(data, length, ip_port); | 394 | DHT_handlepacket(data, length, ip_port); |
128 | friendreq_handlepacket(data, length, ip_port); | 395 | friendreq_handlepacket(data, length, ip_port); |
129 | } | 396 | } |
130 | c_sleep(1); | 397 | usleep(10000); |
131 | } | 398 | } |
132 | 399 | ||
133 | shutdown_networking(); | 400 | shutdown_networking(); |
134 | exit(EXIT_SUCCESS); | 401 | exit(EXIT_SUCCESS); |
135 | } | 402 | } |
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 | ||
14 | PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
15 | DESC="ProjectTox bootstrap server daemon" | ||
16 | NAME=DHT_bootstrap_daemon | ||
17 | CFG=/home/$USER/server.cfg | ||
18 | DAEMON=/home/$USER/$NAME | ||
19 | DAEMON_ARGS="$CFG" | ||
20 | PIDFILE=/home/$USER/.$NAME.pid | ||
21 | SCRIPTNAME=/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 | # | ||
40 | do_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 | # | ||
53 | do_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 | |||
66 | case "$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 | ;; | ||
109 | esac | ||
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 | ||
14 | PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
15 | DESC="ProjectTox bootstrap server daemon" | ||
16 | NAME=bootstrap_server | ||
17 | DAEMON=/home/$USER/$NAME | ||
18 | DAEMON_ARGS="" | ||
19 | PIDFILE=/home/$USER/.$NAME.pid | ||
20 | SCRIPTNAME=/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 | # | ||
39 | do_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 | # | ||
52 | do_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 | |||
65 | case "$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 | ;; | ||
108 | esac | ||
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 | ||
4 | port = 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 | ||
9 | keys_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 | ||
14 | pid_file = "/home/tom/.bootstrap_server.pid"; | ||
15 | |||
16 | // The info of the node bootstap_server will | ||
17 | // bootstrap itself from. | ||
18 | bootstrap_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 | ); | ||