tox-weechat/src/twc-bootstrap.c

248 lines
9.7 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 "twc-utils.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/misc/getnodes.py
* last generated 2022-11-11T08:54:10.303144 */
static struct t_twc_bootstrap_node const twc_bootstrap_nodes[] = {
/* Maintainer: MAH69K, location: RU */
{"DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43",
"85.143.221.42", 33445},
/* Maintainer: initramfs, location: TW */
{"3F0A45A268367C1BEA652F258C85F4A66DA76BCAA667A49E770BCC4917AB6A25",
"114.35.245.150", 33445},
/* Maintainer: velusip, location: CA */
{"7E5668E0EE09E19F320AD47902419331FFEE147BB3606769CFBE921A2A2FD34C",
"144.217.167.73", 33445},
/* Maintainer: Cody, location: US */
{"BEF0CFB37AF874BD17B9A8F9FE64C75521DB95A37D33C5BDB00E9CF58659C04F",
"198.199.98.108", 33445},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 53},
/* Maintainer: kotelnik, location: DE */
{"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707",
"46.101.197.175", 33445},
/* Maintainer: 2mf, location: DE */
{"B3E5FA80DC8EBD1149AD2AB35ED8B85BD546DEDE261CA593234C619249419506",
"49.12.229.145", 33445},
/* Maintainer: tux1973, location: DE */
{"B84E865125B4EC4C368CD047C72BCE447644A2DC31EF75BD2CDA345BFD310107",
"195.201.7.101", 33445},
/* Maintainer: Tha_14, location: MD */
{"836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409",
"114.35.245.150", 33445},
/* Maintainer: Nikat, location: RU */
{"1911341A83E02503AB1FD6561BD64AF3A9D6C3F12B5FBB656976B2E678644A67",
"188.225.9.167", 33445},
/* Maintainer: miaoski, location: TW */
{"5716530A10D362867C8E87EE1CD5362A233BAFBBA4CF47FA73B7CAD368BD5E6E",
"122.116.39.151", 33445},
/* Maintainer: Cüber, location: LV */
{"534A589BA7427C631773D13083570F529238211893640C99D1507300F055FE73",
"195.123.208.139", 33445},
/* Maintainer: ToxTom, location: CA */
{"F76A11284547163889DDC89A7738CF271797BF5E5E220643E97AD3C7E7903D55",
"139.162.110.188", 33445},
/* Maintainer: Cüber, location: US */
{"28DB44A3CEEE69146469855DFFE5F54DA567F5D65E03EFB1D38BBAEFF2553255",
"198.98.49.206", 33445},
/* Maintainer: Toxdaemon, location: RU */
{"DA98A4C0CD7473A133E115FEA2EBDAEEA2EF4F79FD69325FC070DA4DE4BA3238",
"5.19.249.240", 38296},
};
static struct t_twc_bootstrap_node const twc_bootstrap_relays[] = {
/* Maintainer: MAH69K, location: RU */
{"DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43",
"85.143.221.42", 33445},
/* Maintainer: MAH69K, location: RU */
{"DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43",
"85.143.221.42", 3389},
/* Maintainer: initramfs, location: TW */
{"3F0A45A268367C1BEA652F258C85F4A66DA76BCAA667A49E770BCC4917AB6A25",
"114.35.245.150", 3389},
/* Maintainer: initramfs, location: TW */
{"3F0A45A268367C1BEA652F258C85F4A66DA76BCAA667A49E770BCC4917AB6A25",
"114.35.245.150", 33445},
/* Maintainer: velusip, location: CA */
{"7E5668E0EE09E19F320AD47902419331FFEE147BB3606769CFBE921A2A2FD34C",
"144.217.167.73", 33445},
/* Maintainer: velusip, location: CA */
{"7E5668E0EE09E19F320AD47902419331FFEE147BB3606769CFBE921A2A2FD34C",
"144.217.167.73", 3389},
/* Maintainer: Cody, location: US */
{"BEF0CFB37AF874BD17B9A8F9FE64C75521DB95A37D33C5BDB00E9CF58659C04F",
"198.199.98.108", 33445},
/* Maintainer: Cody, location: US */
{"BEF0CFB37AF874BD17B9A8F9FE64C75521DB95A37D33C5BDB00E9CF58659C04F",
"198.199.98.108", 3389},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 3389},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 443},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 33445},
/* Maintainer: GDR!, location: US */
{"3091C6BEB2A993F1C6300C16549FABA67098FF3D62C6D253828B531470B53D68",
"205.185.115.131", 53},
/* Maintainer: kotelnik, location: DE */
{"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707",
"46.101.197.175", 3389},
/* Maintainer: kotelnik, location: DE */
{"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707",
"46.101.197.175", 33445},
/* Maintainer: 2mf, location: DE */
{"B3E5FA80DC8EBD1149AD2AB35ED8B85BD546DEDE261CA593234C619249419506",
"49.12.229.145", 3389},
/* Maintainer: 2mf, location: DE */
{"B3E5FA80DC8EBD1149AD2AB35ED8B85BD546DEDE261CA593234C619249419506",
"49.12.229.145", 33445},
/* Maintainer: tux1973, location: DE */
{"B84E865125B4EC4C368CD047C72BCE447644A2DC31EF75BD2CDA345BFD310107",
"195.201.7.101", 3389},
/* Maintainer: tux1973, location: DE */
{"B84E865125B4EC4C368CD047C72BCE447644A2DC31EF75BD2CDA345BFD310107",
"195.201.7.101", 33445},
/* Maintainer: Tha_14, location: MD */
{"836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409",
"114.35.245.150", 33445},
/* Maintainer: Tha_14, location: MD */
{"836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409",
"114.35.245.150", 443},
/* Maintainer: Tha_14, location: MD */
{"836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409",
"114.35.245.150", 3389},
/* Maintainer: Nikat, location: RU */
{"1911341A83E02503AB1FD6561BD64AF3A9D6C3F12B5FBB656976B2E678644A67",
"188.225.9.167", 3389},
/* Maintainer: Nikat, location: RU */
{"1911341A83E02503AB1FD6561BD64AF3A9D6C3F12B5FBB656976B2E678644A67",
"188.225.9.167", 33445},
/* Maintainer: miaoski, location: TW */
{"5716530A10D362867C8E87EE1CD5362A233BAFBBA4CF47FA73B7CAD368BD5E6E",
"122.116.39.151", 3389},
/* Maintainer: miaoski, location: TW */
{"5716530A10D362867C8E87EE1CD5362A233BAFBBA4CF47FA73B7CAD368BD5E6E",
"122.116.39.151", 33445},
/* Maintainer: Cüber, location: LV */
{"534A589BA7427C631773D13083570F529238211893640C99D1507300F055FE73",
"195.123.208.139", 3389},
/* Maintainer: Cüber, location: LV */
{"534A589BA7427C631773D13083570F529238211893640C99D1507300F055FE73",
"195.123.208.139", 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: Cüber, location: US */
{"28DB44A3CEEE69146469855DFFE5F54DA567F5D65E03EFB1D38BBAEFF2553255",
"198.98.49.206", 33445},
/* Maintainer: Toxdaemon, location: RU */
{"DA98A4C0CD7473A133E115FEA2EBDAEEA2EF4F79FD69325FC070DA4DE4BA3238",
"5.19.249.240", 3389},
/* Maintainer: Toxdaemon, location: RU */
{"DA98A4C0CD7473A133E115FEA2EBDAEEA2EF4F79FD69325FC070DA4DE4BA3238",
"5.19.249.240", 38296},
};
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_tox(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_node(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_tox(tox, 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);
return result;
}