2017-01-14 23:46:31 +08:00
|
|
|
/*
|
2014-02-23 06:06:07 +08:00
|
|
|
* Special bootstrap node only packets.
|
2014-02-02 07:45:37 +08:00
|
|
|
*
|
2014-02-23 06:06:07 +08:00
|
|
|
* Include it in your bootstrap node and use: bootstrap_set_callbacks() to enable.
|
2017-01-14 23:46:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright © 2016-2017 The TokTok team.
|
|
|
|
* Copyright © 2013 Tox project.
|
2014-02-02 07:45:37 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* This file is part of Tox, the free peer to peer instant messenger.
|
2014-02-02 07:45:37 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* 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.
|
2014-02-02 07:45:37 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* 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.
|
2014-02-02 07:45:37 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
2014-02-02 07:45:37 +08:00
|
|
|
*/
|
2016-01-01 13:19:35 +08:00
|
|
|
#include "bootstrap_node_packets.h"
|
2014-02-02 07:45:37 +08:00
|
|
|
|
|
|
|
#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
|
|
|
|
*/
|
2016-08-17 17:52:04 +08:00
|
|
|
static int handle_info_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
|
2014-02-02 07:45:37 +08:00
|
|
|
{
|
2016-09-01 02:12:19 +08:00
|
|
|
if (length != INFO_REQUEST_PACKET_LENGTH) {
|
2014-02-02 07:45:37 +08:00
|
|
|
return 1;
|
2016-09-01 02:12:19 +08:00
|
|
|
}
|
2014-02-02 07:45:37 +08:00
|
|
|
|
2016-09-18 08:31:55 +08:00
|
|
|
Networking_Core *nc = (Networking_Core *)object;
|
|
|
|
|
2014-02-02 07:45:37 +08:00
|
|
|
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);
|
|
|
|
|
2016-09-18 08:31:55 +08:00
|
|
|
if (sendpacket(nc, source, data, len) == len) {
|
2014-02-02 07:45:37 +08:00
|
|
|
return 0;
|
2016-09-01 02:12:19 +08:00
|
|
|
}
|
2014-02-02 07:45:37 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bootstrap_set_callbacks(Networking_Core *net, uint32_t version, uint8_t *motd, uint16_t motd_length)
|
|
|
|
{
|
2016-09-01 02:12:19 +08:00
|
|
|
if (motd_length > MAX_MOTD_LENGTH) {
|
2014-02-02 07:45:37 +08:00
|
|
|
return -1;
|
2016-09-01 02:12:19 +08:00
|
|
|
}
|
2014-02-02 07:45:37 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|