Refactored and fixed bootstrap process.
This fixes a bug where htons would be called twice on port numbers after an update to libtoxcore.
This commit is contained in:
parent
dfcb43d4f8
commit
b3b15b1a89
1 changed files with 19 additions and 9 deletions
|
@ -2,7 +2,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ char *tox_weechat_bootstrap_addresses[] = {
|
||||||
"195.154.119.113",
|
"195.154.119.113",
|
||||||
};
|
};
|
||||||
|
|
||||||
int tox_weechat_bootstrap_ports[] = {
|
uint16_t tox_weechat_bootstrap_ports[] = {
|
||||||
33445, 33445, 33445, 33445, 33445,
|
33445, 33445, 33445, 33445, 33445,
|
||||||
33445, 33445, 33445, 33445, 33445,
|
33445, 33445, 33445, 33445, 33445,
|
||||||
};
|
};
|
||||||
|
@ -51,6 +50,8 @@ char *tox_weechat_bootstrap_keys[] = {
|
||||||
"E398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354",
|
"E398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int tox_weechat_bootstrap_count = sizeof(tox_weechat_bootstrap_addresses)/sizeof(tox_weechat_bootstrap_addresses[0]);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
tox_weechat_identity_data_file_path(struct t_tox_weechat_identity *identity)
|
tox_weechat_identity_data_file_path(struct t_tox_weechat_identity *identity)
|
||||||
{
|
{
|
||||||
|
@ -136,14 +137,14 @@ tox_weechat_identity_buffer_close_callback(void *data,
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
tox_weechat_bootstrap_tox(Tox *tox, char *address, uint16_t port, char *public_key)
|
tox_weechat_bootstrap_tox(Tox *tox, const char *address, uint16_t port, const char *public_key)
|
||||||
{
|
{
|
||||||
char *binary_key = malloc(TOX_FRIEND_ADDRESS_SIZE);
|
char *binary_key = malloc(TOX_FRIEND_ADDRESS_SIZE);
|
||||||
tox_weechat_hex2bin(public_key, binary_key);
|
tox_weechat_hex2bin(public_key, binary_key);
|
||||||
|
|
||||||
int result = tox_bootstrap_from_address(tox,
|
int result = tox_bootstrap_from_address(tox,
|
||||||
address,
|
address,
|
||||||
htons(port),
|
port,
|
||||||
(uint8_t *)binary_key);
|
(uint8_t *)binary_key);
|
||||||
free(binary_key);
|
free(binary_key);
|
||||||
|
|
||||||
|
@ -184,6 +185,15 @@ tox_weechat_identity_new(const char *name)
|
||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tox_weechat_bootstrap_random_node(Tox *tox)
|
||||||
|
{
|
||||||
|
int i = rand() % tox_weechat_bootstrap_count;
|
||||||
|
tox_weechat_bootstrap_tox(tox, tox_weechat_bootstrap_addresses[i],
|
||||||
|
tox_weechat_bootstrap_ports[i],
|
||||||
|
tox_weechat_bootstrap_keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
|
tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
|
||||||
{
|
{
|
||||||
|
@ -215,11 +225,11 @@ tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
// bootstrap DHT
|
// bootstrap DHT
|
||||||
int bootstrap_count = sizeof(tox_weechat_bootstrap_addresses)/sizeof(tox_weechat_bootstrap_addresses[0]);
|
int max_bootstrap_nodes = 5;
|
||||||
for (int i = 0; i < bootstrap_count; ++i)
|
int bootstrap_nodes = max_bootstrap_nodes > tox_weechat_bootstrap_count ?
|
||||||
tox_weechat_bootstrap_tox(identity->tox, tox_weechat_bootstrap_addresses[i],
|
tox_weechat_bootstrap_count : max_bootstrap_nodes;
|
||||||
tox_weechat_bootstrap_ports[i],
|
for (int i = 0; i < bootstrap_nodes; ++i)
|
||||||
tox_weechat_bootstrap_keys[i]);
|
tox_weechat_bootstrap_random_node(identity->tox);
|
||||||
|
|
||||||
// start Tox_do loop
|
// start Tox_do loop
|
||||||
tox_weechat_do_timer_cb(identity, 0);
|
tox_weechat_do_timer_cb(identity, 0);
|
||||||
|
|
Loading…
Reference in a new issue