mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added DHT bootstrap server info packets.
define DHT_SERVER_EXTRA_PACKETS to enable.
This commit is contained in:
parent
d5c005f024
commit
ad5d58b4a2
|
@ -33,6 +33,13 @@
|
||||||
|
|
||||||
#include "../testing/misc_tools.c"
|
#include "../testing/misc_tools.c"
|
||||||
|
|
||||||
|
#ifdef DHT_SERVER_EXTRA_PACKETS
|
||||||
|
#include "./bootstrap_server_packets.c"
|
||||||
|
|
||||||
|
#define DHT_VERSION_NUMBER 1
|
||||||
|
#define DHT_MOTD "This is a test motd"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Sleep function (x = milliseconds) */
|
/* Sleep function (x = milliseconds) */
|
||||||
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
||||||
#define c_sleep(x) Sleep(1*x)
|
#define c_sleep(x) Sleep(1*x)
|
||||||
|
@ -45,7 +52,6 @@
|
||||||
#define PORT 33445
|
#define PORT 33445
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void manage_keys(DHT *dht)
|
void manage_keys(DHT *dht)
|
||||||
{
|
{
|
||||||
const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
||||||
|
@ -105,6 +111,10 @@ int main(int argc, char *argv[])
|
||||||
Onion *onion = new_onion(dht);
|
Onion *onion = new_onion(dht);
|
||||||
Onion_Announce *onion_a = new_onion_announce(dht);
|
Onion_Announce *onion_a = new_onion_announce(dht);
|
||||||
|
|
||||||
|
#ifdef DHT_SERVER_EXTRA_PACKETS
|
||||||
|
bootstrap_set_callbacks(dht->net, DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD));
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!(onion && onion_a)) {
|
if (!(onion && onion_a)) {
|
||||||
printf("Something failed to initialize.\n");
|
printf("Something failed to initialize.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
65
other/bootstrap_server_packets.c
Normal file
65
other/bootstrap_server_packets.c
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* bootstrap_server_packets.c
|
||||||
|
*
|
||||||
|
* Special bootstrap server only packets.
|
||||||
|
*
|
||||||
|
* Include it in your bootstrap server and use: bootstrap_set_callbacks() to enable.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Tox project All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This file is part of Tox.
|
||||||
|
*
|
||||||
|
* Tox 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 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. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAX_MOTD_LENGTH 256 /* I recommend you use a maximum of 96 bytes. The hard maximum is this though. */
|
||||||
|
|
||||||
|
#define INFO_REQUEST_PACKET_LENGTH 78
|
||||||
|
|
||||||
|
static uint32_t bootstrap_version;
|
||||||
|
static uint8_t bootstrap_motd[MAX_MOTD_LENGTH];
|
||||||
|
static uint16_t bootstrap_motd_length;
|
||||||
|
|
||||||
|
/* To request this packet just send a packet of length INFO_REQUEST_PACKET_LENGTH
|
||||||
|
* with the first byte being BOOTSTRAP_INFO_PACKET_ID
|
||||||
|
*/
|
||||||
|
static int handle_info_request(void *object, IP_Port source, uint8_t *packet, uint32_t length)
|
||||||
|
{
|
||||||
|
if (length != INFO_REQUEST_PACKET_LENGTH)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH];
|
||||||
|
data[0] = BOOTSTRAP_INFO_PACKET_ID;
|
||||||
|
memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version));
|
||||||
|
uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length;
|
||||||
|
memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length);
|
||||||
|
|
||||||
|
if (sendpacket(object, source, data, len) == len)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bootstrap_set_callbacks(Networking_Core *net, uint32_t version, uint8_t *motd, uint16_t motd_length)
|
||||||
|
{
|
||||||
|
if (motd_length > MAX_MOTD_LENGTH)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
bootstrap_version = htonl(version);
|
||||||
|
memcpy(bootstrap_motd, motd, motd_length);
|
||||||
|
bootstrap_motd_length = motd_length;
|
||||||
|
|
||||||
|
networking_registerhandler(net, BOOTSTRAP_INFO_PACKET_ID, &handle_info_request, net);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -143,6 +143,9 @@ typedef int sock_t;
|
||||||
#define NET_PACKET_ONION_RECV_2 141
|
#define NET_PACKET_ONION_RECV_2 141
|
||||||
#define NET_PACKET_ONION_RECV_1 142
|
#define NET_PACKET_ONION_RECV_1 142
|
||||||
|
|
||||||
|
/* Only used for bootstrap servers */
|
||||||
|
#define BOOTSTRAP_INFO_PACKET_ID 240
|
||||||
|
|
||||||
|
|
||||||
#define TOX_PORTRANGE_FROM 33445
|
#define TOX_PORTRANGE_FROM 33445
|
||||||
#define TOX_PORTRANGE_TO 33545
|
#define TOX_PORTRANGE_TO 33545
|
||||||
|
|
|
@ -325,7 +325,7 @@ Onion_Announce *new_onion_announce(DHT *dht)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
onion_a->dht = dht;
|
onion_a->dht = dht;
|
||||||
onion_a->net = dht->c->lossless_udp->net;
|
onion_a->net = dht->net;
|
||||||
new_symmetric_key(onion_a->secret_bytes);
|
new_symmetric_key(onion_a->secret_bytes);
|
||||||
|
|
||||||
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_announce_request, onion_a);
|
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_announce_request, onion_a);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user