mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #89 from nurupo/master
Some DHT bootstrap improvements
This commit is contained in:
commit
485d5eee67
|
@ -3,3 +3,7 @@ cmake_minimum_required(VERSION 2.6.0)
|
|||
cmake_policy(SET CMP0011 NEW)
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake)
|
||||
|
||||
if(NOT WIN32)
|
||||
add_subdirectory(bootstrap_serverdaemon)
|
||||
endif()
|
||||
|
|
|
@ -36,9 +36,41 @@ unsigned char * hex_string_to_bin(char hex_string[])
|
|||
return val;
|
||||
}
|
||||
|
||||
void manage_keys()
|
||||
{
|
||||
const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
||||
uint8_t keys[KEYS_SIZE];
|
||||
|
||||
FILE *keys_file = fopen("key", "r");
|
||||
if (keys_file != NULL) {
|
||||
//if file was opened successfully -- load keys
|
||||
size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
|
||||
if (read_size != KEYS_SIZE) {
|
||||
printf("Error while reading the key file\nExiting.\n");
|
||||
exit(1);
|
||||
} else {
|
||||
printf("Keys loaded successfully\n");
|
||||
}
|
||||
load_keys(keys);
|
||||
} else {
|
||||
//otherwise save new keys
|
||||
new_keys();
|
||||
save_keys(keys);
|
||||
keys_file = fopen("key", "w");
|
||||
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
||||
printf("Error while writing the key file.\nExiting.\n");
|
||||
exit(1);
|
||||
} else {
|
||||
printf("Keys saved successfully\n");
|
||||
}
|
||||
}
|
||||
|
||||
fclose(keys_file);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
new_keys();
|
||||
manage_keys();
|
||||
printf("Public key: ");
|
||||
uint32_t i;
|
||||
for(i = 0; i < 32; i++)
|
||||
|
|
9
other/bootstrap_serverdaemon/CMakeLists.txt
Normal file
9
other/bootstrap_serverdaemon/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
cmake_minimum_required(VERSION 2.6.0)
|
||||
project(DHT_bootstrap_daemon C)
|
||||
|
||||
set(exe_name DHT_bootstrap_daemon)
|
||||
|
||||
add_executable(${exe_name}
|
||||
DHT_bootstrap_daemon.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
Loading…
Reference in New Issue
Block a user