mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #53 from stal888/master
Add support for DHT_bootstrap to connect to other nodes
This commit is contained in:
commit
44da025629
|
@ -1,13 +1,13 @@
|
|||
/* DHT boostrap
|
||||
*
|
||||
*
|
||||
* A simple DHT boostrap server for tox.
|
||||
*
|
||||
* Build commands (use one or the other):
|
||||
*
|
||||
* Build commands (use one or the other):
|
||||
* 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 ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} DHT_bootstrap.c
|
||||
*
|
||||
*
|
||||
* gcc -O2 -Wall -o bootstrap_server ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c -lsodium DHT_bootstrap.c
|
||||
*/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include "../core/DHT.h"
|
||||
|
||||
|
||||
|
@ -21,7 +21,19 @@
|
|||
|
||||
#define PORT 33445
|
||||
|
||||
|
||||
unsigned char * hex_string_to_bin(char hex_string[])
|
||||
{
|
||||
unsigned char * val = malloc(strlen(hex_string));
|
||||
char * pos = hex_string;
|
||||
int i=0;
|
||||
while(i < strlen(hex_string))
|
||||
{
|
||||
sscanf(pos,"%2hhx",&val[i]);
|
||||
pos+=2;
|
||||
i++;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -42,13 +54,29 @@ int main(int argc, char *argv[])
|
|||
init_networking(ip, PORT);
|
||||
|
||||
perror("Initialization");
|
||||
|
||||
if (argc > 3) {
|
||||
printf("Trying to bootstrap into the network...\n");
|
||||
IP_Port bootstrap_info;
|
||||
bootstrap_info.ip.i = inet_addr(argv[1]);
|
||||
bootstrap_info.port = htons(atoi(argv[2]));
|
||||
uint8_t *bootstrap_key = hex_string_to_bin(argv[3]);
|
||||
DHT_bootstrap(bootstrap_info, bootstrap_key);
|
||||
free(bootstrap_key);
|
||||
}
|
||||
|
||||
IP_Port ip_port;
|
||||
uint8_t data[MAX_UDP_PACKET_SIZE];
|
||||
uint32_t length;
|
||||
|
||||
int is_waiting_for_dht_connection = 1;
|
||||
while(1)
|
||||
{
|
||||
{
|
||||
if (is_waiting_for_dht_connection && DHT_isconnected())
|
||||
{
|
||||
printf("Connected to other bootstrap server successfully.\n");
|
||||
is_waiting_for_dht_connection = 0;
|
||||
}
|
||||
doDHT();
|
||||
|
||||
while(receivepacket(&ip_port, data, &length) != -1)
|
||||
|
@ -58,5 +86,5 @@ int main(int argc, char *argv[])
|
|||
c_sleep(1);
|
||||
}
|
||||
shutdown_networking();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user