You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
9.0 KiB
C

/*
* Copyright (c) 2018 Håvard Pettersson <mail@haavard.me>
*
* This file is part of Tox-WeeChat.
*
* Tox-WeeChat is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tox-WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#include <tox/tox.h>
#include <weechat/weechat-plugin.h>
#include "twc-utils.h"
#include "twc-profile.h"
#include "twc.h"
#include "twc-bootstrap.h"
struct t_twc_bootstrap_node
{
char const *const key;
char const *const address;
uint16_t const port;
};
/* bootstrap nodes generated by /o/var/local/src/tox-weechat.git/misc/getnodes.py
* last generated 2024-03-07T09:12:04.788351 */
static struct t_twc_bootstrap_node const twc_bootstrap_nodes[] = {
/* Maintainer: velusip, location: CA */
{"7E5668E0EE09E19F320AD47902419331FFEE147BB3606769CFBE921A2A2FD34C",
"144.217.167.73", 33445},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 53},
/* Maintainer: kotelnik, location: DE */
{"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707",
"46.101.197.175", 33445},
/* Maintainer: Toxdaemon, location: RU */
{"DA98A4C0CD7473A133E115FEA2EBDAEEA2EF4F79FD69325FC070DA4DE4BA3238",
"5.19.249.240", 38296},
/* Maintainer: Nikat, location: RU */
{"1911341A83E02503AB1FD6561BD64AF3A9D6C3F12B5FBB656976B2E678644A67",
"188.225.9.167", 33445},
/* Maintainer: Gabe, location: US */
{"933BA20B2E258B4C0D475B6DECE90C7E827FE83EFA9655414E7841251B19A72C",
"104.225.141.59", 43334},
/* Maintainer: ToxTom, location: CA */
{"F76A11284547163889DDC89A7738CF271797BF5E5E220643E97AD3C7E7903D55",
"139.162.110.188", 33445},
/* Maintainer: amr, location: CA */
{"D46E97CF995DC1820B92B7D899E152A217D36ABE22730FEA4B6BF1BFC06C617C",
"172.105.109.31", 33445},
/* Maintainer: Toxdaemon, location: EE */
{"B5E7DAC610DBDE55F359C7F8690B294C8E4FCEC4385DE9525DBFA5523EAD9D53",
"91.146.66.26", 33445},
/* Maintainer: zero-one, location: US */
{"DA2BD927E01CD05EBCC2574EBE5BEBB10FF59AE0B2105A7D1E2B40E49BB20239",
"172.104.215.182", 33445},
/* Maintainer: turambar, location: EG */
{"2A9F7A620581D5D1B09B004624559211C5ED3D1D712E8066ACDB0896A7335705",
"188.214.122.30", 33445},
/* Maintainer: UR1229SWL, location: NL */
{"99E8460035E45C0A6B6DC2C02B14440F7F876518E9D054D028209B5669827645",
"194.36.190.71", 33445},
/* Maintainer: Alexsandr, location: RU */
{"52BD37D53357701CB9C69ABA81E7741C5F14105523C89153A770D73F434AC473",
"62.183.96.32", 33445},
/* Maintainer: lzk, location: US */
{"1FD96DF8DCAC4A95C117B460F23EB740C8FBA60DE89BE7B45136790B8E3D4B63",
"141.11.229.155", 33445},
};
static struct t_twc_bootstrap_node const twc_bootstrap_relays[] = {
/* Maintainer: velusip, location: CA */
{"7E5668E0EE09E19F320AD47902419331FFEE147BB3606769CFBE921A2A2FD34C",
"144.217.167.73", 3389},
/* Maintainer: velusip, location: CA */
{"7E5668E0EE09E19F320AD47902419331FFEE147BB3606769CFBE921A2A2FD34C",
"144.217.167.73", 33445},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 53},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 443},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 3389},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 33445},
/* Maintainer: kotelnik, location: DE */
{"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707",
"46.101.197.175", 3389},
/* Maintainer: kotelnik, location: DE */
{"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707",
"46.101.197.175", 33445},
/* Maintainer: Toxdaemon, location: RU */
{"DA98A4C0CD7473A133E115FEA2EBDAEEA2EF4F79FD69325FC070DA4DE4BA3238",
"5.19.249.240", 38296},
/* Maintainer: Toxdaemon, location: RU */
{"DA98A4C0CD7473A133E115FEA2EBDAEEA2EF4F79FD69325FC070DA4DE4BA3238",
"5.19.249.240", 3389},
/* Maintainer: Nikat, location: RU */
{"1911341A83E02503AB1FD6561BD64AF3A9D6C3F12B5FBB656976B2E678644A67",
"188.225.9.167", 3389},
/* Maintainer: Nikat, location: RU */
{"1911341A83E02503AB1FD6561BD64AF3A9D6C3F12B5FBB656976B2E678644A67",
"188.225.9.167", 33445},
/* Maintainer: Gabe, location: US */
{"933BA20B2E258B4C0D475B6DECE90C7E827FE83EFA9655414E7841251B19A72C",
"104.225.141.59", 3389},
/* Maintainer: Gabe, location: US */
{"933BA20B2E258B4C0D475B6DECE90C7E827FE83EFA9655414E7841251B19A72C",
"104.225.141.59", 33445},
/* Maintainer: ToxTom, location: CA */
{"F76A11284547163889DDC89A7738CF271797BF5E5E220643E97AD3C7E7903D55",
"139.162.110.188", 443},
/* Maintainer: ToxTom, location: CA */
{"F76A11284547163889DDC89A7738CF271797BF5E5E220643E97AD3C7E7903D55",
"139.162.110.188", 33445},
/* Maintainer: ToxTom, location: CA */
{"F76A11284547163889DDC89A7738CF271797BF5E5E220643E97AD3C7E7903D55",
"139.162.110.188", 3389},
/* Maintainer: amr, location: CA */
{"D46E97CF995DC1820B92B7D899E152A217D36ABE22730FEA4B6BF1BFC06C617C",
"172.105.109.31", 33445},
/* Maintainer: zero-one, location: US */
{"DA2BD927E01CD05EBCC2574EBE5BEBB10FF59AE0B2105A7D1E2B40E49BB20239",
"172.104.215.182", 33445},
/* Maintainer: zero-one, location: US */
{"DA2BD927E01CD05EBCC2574EBE5BEBB10FF59AE0B2105A7D1E2B40E49BB20239",
"172.104.215.182", 443},
/* Maintainer: zero-one, location: US */
{"DA2BD927E01CD05EBCC2574EBE5BEBB10FF59AE0B2105A7D1E2B40E49BB20239",
"172.104.215.182", 3389},
/* Maintainer: turambar, location: EG */
{"2A9F7A620581D5D1B09B004624559211C5ED3D1D712E8066ACDB0896A7335705",
"188.214.122.30", 3389},
/* Maintainer: turambar, location: EG */
{"2A9F7A620581D5D1B09B004624559211C5ED3D1D712E8066ACDB0896A7335705",
"188.214.122.30", 33445},
/* Maintainer: UR1229SWL, location: NL */
{"99E8460035E45C0A6B6DC2C02B14440F7F876518E9D054D028209B5669827645",
"194.36.190.71", 33445},
/* Maintainer: Alexsandr, location: RU */
{"52BD37D53357701CB9C69ABA81E7741C5F14105523C89153A770D73F434AC473",
"62.183.96.32", 33445},
/* Maintainer: lzk, location: US */
{"1FD96DF8DCAC4A95C117B460F23EB740C8FBA60DE89BE7B45136790B8E3D4B63",
"141.11.229.155", 33445},
/* Maintainer: lzk, location: US */
{"1FD96DF8DCAC4A95C117B460F23EB740C8FBA60DE89BE7B45136790B8E3D4B63",
"141.11.229.155", 3389},
};
static int const twc_bootstrap_count =
sizeof(twc_bootstrap_nodes) / sizeof(twc_bootstrap_nodes[0]);
/**
* Bootstrap a Tox object with a DHT bootstrap node. Returns the result of
* tox_bootstrap_from_address.
*/
int
twc_bootstrap_dht(Tox *tox, const char *address, uint16_t port,
const char *public_key)
{
uint8_t binary_key[TOX_ADDRESS_SIZE];
twc_hex2bin(public_key, TOX_ADDRESS_SIZE, binary_key);
TOX_ERR_BOOTSTRAP err;
int result;
result = tox_bootstrap(tox, address, port, binary_key, &err);
return result;
}
/**
* Bootstrap a Tox object with a relay node. Returns the result of
* tox_bootstrap_from_address.
*/
int
twc_bootstrap_relay(Tox *tox, const char *address, uint16_t port,
const char *public_key)
{
uint8_t binary_key[TOX_ADDRESS_SIZE];
twc_hex2bin(public_key, TOX_ADDRESS_SIZE, binary_key);
TOX_ERR_BOOTSTRAP err;
int result;
result = tox_add_tcp_relay(tox, address, port, binary_key, &err);
return result;
}
/**
* Bootstrap a Tox object with a random DHT bootstrap node.
*/
int
twc_bootstrap_random_dht(Tox *tox)
{
int i = rand() % twc_bootstrap_count;
struct t_twc_bootstrap_node const *const node = &twc_bootstrap_nodes[i];
int result;
result = twc_bootstrap_dht(tox, node->address, node->port, node->key);
weechat_printf(NULL, "Bootstrapped node %s %d %s", node->address, node->port, node->key);
return result;
}
/**
* Bootstrap a Tox object with a random DHT bootstrap node.
*/
int
twc_bootstrap_random_relay(Tox *tox)
{
int i = rand() % twc_bootstrap_count;
struct t_twc_bootstrap_node const *const node = &twc_bootstrap_relays[i];
int result;
result = twc_bootstrap_relay(tox, node->address, node->port, node->key);
weechat_printf(NULL, "Bootstrapped relay %s %d %s", node->address, node->port, node->key);
return result;
}