Added the shell of onion.{c, h}

This commit is contained in:
irungentoo 2013-12-24 16:22:56 -05:00
parent 01949b6a67
commit ad2037e165
5 changed files with 156 additions and 4 deletions

View File

@ -138,4 +138,4 @@ encrypted with temp symmetric key of Node A: [IP_Port (of us)][data to send back
(sent from node A to us):
[uint8_t packet id (143)][data to send back]
[data to send back]

View File

@ -111,6 +111,21 @@ typedef int sock_t;
#define NET_PACKET_LAN_DISCOVERY 33 /* LAN discovery packet ID. */
#define NET_PACKET_GROUP_CHATS 48 /* Group chats packet ID. */
/* See: docs/Prevent_Tracking.txt and onion.{c, h} */
#define NET_PACKET_ONION_SEND_INITIAL 128
#define NET_PACKET_ONION_SEND_1 129
#define NET_PACKET_ONION_SEND_2 130
#define NET_PACKET_ANNOUNCE_REQUEST 131
#define NET_PACKET_ANNOUNCE_RESPONSE 132
#define NET_PACKET_ONION_DATA_REQUEST 133
#define NET_PACKET_ONION_DATA_RESPONSE 134
#define NET_PACKET_ONION_RECV_3 140
#define NET_PACKET_ONION_RECV_2 141
#define NET_PACKET_ONION_RECV_1 142
#define TOX_PORTRANGE_FROM 33445
#define TOX_PORTRANGE_TO 33545
#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM

104
toxcore/onion.c Normal file
View File

@ -0,0 +1,104 @@
/*
* onion.c -- Implementation of the onion part of docs/Prevent_Tracking.txt
*
* 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/>.
*
*/
#include "onion.h"
static int handle_send_initial(void *object, IP_Port source, uint8_t *packet, uint32_t length)
{
Onion *onion = object;
return 0;
}
static int handle_send_1(void *object, IP_Port source, uint8_t *packet, uint32_t length)
{
Onion *onion = object;
return 0;
}
static int handle_send_2(void *object, IP_Port source, uint8_t *packet, uint32_t length)
{
Onion *onion = object;
return 0;
}
static int handle_recv_3(void *object, IP_Port source, uint8_t *packet, uint32_t length)
{
Onion *onion = object;
return 0;
}
static int handle_recv_2(void *object, IP_Port source, uint8_t *packet, uint32_t length)
{
Onion *onion = object;
return 0;
}
static int handle_recv_1(void *object, IP_Port source, uint8_t *packet, uint32_t length)
{
Onion *onion = object;
return 0;
}
Onion *new_onion(DHT *dht)
{
if (dht == NULL)
return NULL;
Onion *onion = calloc(1, sizeof(Onion));
if (onion == NULL)
return NULL;
new_symmetric_key(onion->secret_symmetric_key);
networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_INITIAL, &handle_send_initial, onion);
networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, &handle_send_1, onion);
networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, &handle_send_2, onion);
networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_3, &handle_recv_3, onion);
networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_2, &handle_recv_2, onion);
networking_registerhandler(dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_1, &handle_recv_1, onion);
return onion;
}
void kill_onion(Onion *onion)
{
networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_INITIAL, NULL, NULL);
networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, NULL, NULL);
networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_SEND_1, NULL, NULL);
networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_3, NULL, NULL);
networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_2, NULL, NULL);
networking_registerhandler(onion->dht->c->lossless_udp->net, NET_PACKET_ONION_RECV_1, NULL, NULL);
free(onion);
}

33
toxcore/onion.h Normal file
View File

@ -0,0 +1,33 @@
/*
* onion.h -- Implementation of the onion part of docs/Prevent_Tracking.txt
*
* 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/>.
*
*/
#include "DHT.h"
typedef struct {
DHT *dht;
uint8_t secret_symmetric_key[crypto_secretbox_KEYBYTES];
} Onion;
Onion *new_onion(DHT *dht);
void kill_onion(Onion *onion);

View File

@ -672,11 +672,11 @@ uint32_t tox_size_encrypted(Tox *tox);
/* Save the messenger, encrypting the data with key of length key_length
*
* This functions simply calls and then encrypt the output of tox_save(..)
* This functions simply calls and then encrypt the output of tox_save(..)
* with crypto_secretbox(...) from NaCl/libsodium with the key
* given to crypto_secretbox(...) being the SHA256 sum of the key
* given to crypto_secretbox(...) being the SHA256 sum of the key
* passed to this function.
*
*
* return 0 on success.
* return -1 on failure.
*/