Merge branch 'master' into TCP

pull/860/head
irungentoo 2014-05-08 18:26:01 -04:00
commit a26ced5fcb
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
26 changed files with 70 additions and 62 deletions

View File

@ -9,6 +9,7 @@ With the rise of governmental monitoring programs, Tox, a FOSS initiative, aims
## The Complex Stuff:
### UDP vs. TCP
Tox must use UDP simply because [hole punching](http://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable.
However, Tox does use [TCP relays](https://github.com/irungentoo/ProjectTox-Core/blob/master/docs/TCP_Network.txt) as a fallback if it encounters a firewall that prevents UDP hole punching.
### Connecting & Communicating
Every peer is represented as a [byte string][String] (the public key [Tox ID] of the peer). By using torrent-style DHT, peers can find the IP of other peers by using their Tox ID. Once the IP is obtained, peers can initiate a [secure](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto) connection with each other. Once the connection is made, peers can exchange messages, send files, start video chats, etc. using encrypted communications.

View File

@ -21,18 +21,18 @@ See DHT, currently uses the IPv6 Node_format.
Get nodes (Request):
Packet contents:
```
[char with a value of 48][Bob's (The reciever's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the reciever:[char with a value of 48][random 8 byte (ping_id)]
[char with a value of 48][Bob's (The receiver's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the receiver:[char with a value of 48][random 8 byte (ping_id)]
```
Valid replies: a send_nodes packet
Send_nodes (response):
```
[char with a value of 48][Bob's (The reciever's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the reciever:[char with a value of 49][random 8 byte (ping_id)][Nodes in node format, length=40 * (number of nodes (maximum of 6 nodes)) bytes]]
[char with a value of 48][Bob's (The receiver's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the receiver:[char with a value of 49][random 8 byte (ping_id)][Nodes in node format, length=40 * (number of nodes (maximum of 6 nodes)) bytes]]
```
Broadcast packet:
```
[char with a value of 48][Bob's (The reciever's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][nonce][Encrypted with the nonce, private key of the sender and public key of the reciever:[char with a value of 50][Data to send to everyone]]
[char with a value of 48][Bob's (The receiver's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][nonce][Encrypted with the nonce, private key of the sender and public key of the receiver:[char with a value of 50][Data to send to everyone]]
```
@ -68,4 +68,4 @@ Ban a peer
[uint8_t message[messagelen]]
65 - action (/me)
[uint8_t message[messagelen]]
[uint8_t message[messagelen]]

View File

@ -110,7 +110,8 @@ encrypted with that temporary private key and the nonce and the public key from
(if Node D contains the ret data for the node, it sends the stuff in this packet as a data to route response packet to the right node)
The data in the previous packet is in format: [real public key of sender]
encrypted with real private key of the sender, the nonce in the data packet and the real public key of the reciever:[[uint8_t id][data (optional)]]
encrypted with real private key of the sender, the nonce in the data packet and
the real public key of the receiver:[[uint8_t id][data (optional)]]
Data sent to us:
announce response packet:
@ -153,5 +154,5 @@ Data packets:
To tell our friend what our DHT public key is so that he can connect to us we send a data packet
with id 156 and the data being:[uint64_t (in network byte order) no_replay, the packet will only be
accepted if this number is bigger than the last one recieved] [our dht public key][Node_Format * (
accepted if this number is bigger than the last one received] [our dht public key][Node_Format * (
maximum of 8) nodes closest to us so that the friend can find us faster]

View File

@ -81,7 +81,7 @@ received
client sent the server the public key and the public key we sent to the client,
the next with base nonce + 1...)
The connection is set to an unconfirmed state until a packet is recieved and
The connection is set to an unconfirmed state until a packet is received and
decrypted correctly using the information in the handshake.
each packet sent to/from the server has an id (the first byte of the plain text
@ -135,7 +135,7 @@ responses must be sent to the proper client.
Ping responses must have the same ping_id as the request.
If the server recieves a ping packet he must respond with a ping response.
If the server receives a ping packet he must respond with a ping response.
The server will send a ping packet to clients every 30 seconds, they have 30
seconds to respond, if they don't the connection is deleted.

View File

@ -34,7 +34,7 @@ msi_session_t* - pointer to a newly created msi session handler.
###msi_session_t reference:
How to handle msi session:
Controling is done via callbacks and action handlers.
Controlling is done via callbacks and action handlers.
First register callbacks for every state/action received and make sure
NOT TO PLACE SOMETHING LIKE LOOPS THAT TAKES A LOT OF TIME TO EXECUTE; every callback is being called
directly from event loop. You can find examples in phone.c.

View File

@ -74,4 +74,4 @@ Crypto request packets
The encrypted message is encrypted with crypto_box() (using Bobs public key, Alice's private key and the nonce (randomly generated 24 bytes)) and is a message from Alice in which she tells Bob who she is.
Each node can route the request to the reciever if they are connected to him. This is to bypass bad NATs.
Each node can route the request to the receiver if they are connected to him. This is to bypass bad NATs.

View File

@ -53,7 +53,7 @@ fi[]dnl
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
#
# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
# only at the first occurence in configure.ac, so if the first place
# only at the first occurrence in configure.ac, so if the first place
# it's called might be skipped (such as if it is within an "if", you
# have to call PKG_CHECK_EXISTS manually
# --------------------------------------------------------------

View File

@ -1,3 +1,3 @@
As maintaining 2 seperate lists of the same information seemed redundant, this list has been phased out.
As maintaining 2 separate lists of the same information seemed redundant, this list has been phased out.
For a current DHT node list please visit http://wiki.tox.im/nodes

View File

@ -32,7 +32,7 @@ void print_key(uint8_t *client_id)
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("usage: ./cracker public_key(or beggining of one in hex format)\n");
printf("usage: ./cracker public_key(or beginning of one in hex format)\n");
return 0;
}

View File

@ -18,15 +18,18 @@ libtoxav_la_SOURCES = ../toxav/event.h \
libtoxav_la_CFLAGS = -I../toxcore \
-I../toxav \
$(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS) \
$(AV_CFLAGS) \
$(PTHREAD_CFLAGS)
libtoxav_la_LDFLAGS = $(TOXAV_LT_LDFLAGS) \
$(LIBSODIUM_LDFLAGS) \
$(NACL_LDFLAGS) \
$(EXTRA_LT_LDFLAGS)
libtoxav_la_LIBADD = libtoxcore.la \
$(LIBSODIUM_LIBS) \
$(NACL_LIBS) \
$(PTHREAD_LIBS) \
$(AV_LIBS)

View File

@ -36,7 +36,7 @@
#define VIDEO_CODEC_ENCODER_INTERFACE (vpx_codec_vp8_cx())
/* Audio encoding/decoding */
#include <opus/opus.h>
#include <opus.h>
typedef enum _Capabilities
{

View File

@ -206,7 +206,7 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response )
#define ON_HEADER(iterator, header, descriptor, size_const) \
( memcmp(iterator, descriptor, size_const) == 0){ /* Okay */ \
iterator += size_const; /* Set iterator at begining of value part */ \
iterator += size_const; /* Set iterator at beginning of value part */ \
if ( *iterator != value_byte ) { assert(0); return -1; }\
iterator ++;\
uint16_t _value_size = (uint16_t) *(iterator ) << 8 | \
@ -225,7 +225,7 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response )
* @param msg Container.
* @param data The data.
* @return int
* @retval -1 Error occured.
* @retval -1 Error occurred.
* @retval 0 Success.
*/
int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length )
@ -338,7 +338,7 @@ void free_message ( MSIMessage *msg )
* @param type Request or response.
* @param type_id Type of request/response.
* @return MSIMessage* Created message.
* @retval NULL Error occured.
* @retval NULL Error occurred.
*/
MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id )
{
@ -367,7 +367,7 @@ MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id )
*
* @param data The data.
* @return MSIMessage* Parsed message.
* @retval NULL Error occured.
* @retval NULL Error occurred.
*/
MSIMessage *parse_message ( const uint8_t *data, uint16_t length )
{
@ -422,7 +422,7 @@ uint8_t *append_header_to_string (
*dest = field_byte; /* Set the first byte */
uint8_t *_getback_byte = dest + 1; /* remeber the byte we were on */
uint8_t *_getback_byte = dest + 1; /* remember the byte we were on */
dest += 3; /* swith to 4th byte where field value starts */
/* Now set the field value and calculate it's length */
@ -604,7 +604,7 @@ static inline__ const uint8_t *stringify_error_code ( MSICallError error_code )
* @param msg The message.
* @param to Where to.
* @return int
* @retval -1 Error occured.
* @retval -1 Error occurred.
* @retval 0 Success.
*/
int send_message ( MSISession *session, MSIMessage *msg, uint32_t to )
@ -721,7 +721,7 @@ int handle_error ( MSISession *session, MSICallError errid, uint32_t to )
* @param msg The message.
* @return int
* @retval -1 No error.
* @retval 0 Error occured and response sent.
* @retval 0 Error occurred and response sent.
*/
int has_call_error ( MSISession *session, MSIMessage *msg )
{
@ -830,7 +830,7 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout )
*
* @param session Control session.
* @return int
* @retval -1 Error occured.
* @retval -1 Error occurred.
* @retval 0 Success.
*/
int terminate_call ( MSISession *session )
@ -882,7 +882,7 @@ int handle_recv_invite ( MSISession *session, MSIMessage *msg )
* B calls A. Who has advantage is set bey calculating
* 'bigger' Call id and then that call id is being used in
* future. User with 'bigger' Call id has the advantage
* as in he will wait the reponse from the other.
* as in he will wait the response from the other.
*/
if ( call_id_bigger (session->call->id, msg->callid.header_value) == 1 ) { /* Peer has advantage */
@ -1250,7 +1250,7 @@ void msi_register_callback ( MSICallback callback, MSICallbackID id, void* userd
* @param messenger Tox* object.
* @param user_agent User agent, i.e. 'Venom'; 'QT-gui'
* @return MSISession* The created session.
* @retval NULL Error occured.
* @retval NULL Error occurred.
*/
MSISession *msi_init_session ( Messenger* messenger )
{
@ -1351,7 +1351,7 @@ int msi_invite ( MSISession *session, MSICallType call_type, uint32_t rngsec, ui
*
* @param session Control session.
* @return int
* @retval -1 Error occured.
* @retval -1 Error occurred.
* @retval 0 Success.
*/
int msi_hangup ( MSISession *session )
@ -1485,4 +1485,4 @@ int msi_stopcall ( MSISession *session )
terminate_call ( session );
return 0;
}
}

View File

@ -82,7 +82,7 @@ typedef struct _MSICall { /* Call info structure */
int ringing_timer_id; /* Timer id for ringing timeout */
pthread_mutex_t mutex; /* It's to be assumed that call will have
* seperate thread so add mutex
* separate thread so add mutex
*/
uint32_t *peers;
uint16_t peer_count;
@ -152,7 +152,7 @@ void msi_register_callback(MSICallback callback, MSICallbackID id, void* userdat
*
* @param messenger Tox* object.
* @return MSISession* The created session.
* @retval NULL Error occured.
* @retval NULL Error occurred.
*/
MSISession *msi_init_session ( Messenger *messenger );
@ -183,7 +183,7 @@ int msi_invite ( MSISession *session, MSICallType call_type, uint32_t rngsec, ui
*
* @param session Control session.
* @return int
* @retval -1 Error occured.
* @retval -1 Error occurred.
* @retval 0 Success.
*/
int msi_hangup ( MSISession *session );

View File

@ -5,7 +5,7 @@
* This file is for testing/reference purposes only, hence
* it is _poorly_ designed and it does not fully reflect the
* quaility of msi nor rtp. Although toxmsi* and toxrtp* are tested
* there is always possiblity of crashes. If crash occures,
* there is always possibility of crashes. If crash occures,
* contact me ( mannol ) on either irc channel #tox-dev @ freenode.net:6667
* or eniz_vukovic@hotmail.com
*
@ -612,7 +612,7 @@ void *decode_video_thread(void *arg)
} //else {
/* TODO: request the sender to create a new i-frame immediatly */
/* TODO: request the sender to create a new i-frame immediately */
//printf("Bad video packet\n");
//}
//}

View File

@ -164,7 +164,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, uint8_t *secr
}
/* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key
* for packets that we recieve.
* for packets that we receive.
*/
void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, uint8_t *client_id)
{
@ -688,7 +688,7 @@ static int replace_possible_bad( Client_data *list,
sort_list(list, length, comp_client_id);
/* TODO: decide if the folowing lines should stay commented or not.
/* TODO: decide if the following lines should stay commented or not.
if (id_closest(comp_client_id, list[0].client_id, client_id) == 1)
return 0;*/
@ -949,20 +949,20 @@ static int getnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cli
uint64_t temp_time = unix_time();
memcpy(plain_message, &temp_time, sizeof(temp_time));
Node_format reciever;
memcpy(reciever.client_id, public_key, CLIENT_ID_SIZE);
reciever.ip_port = ip_port;
memcpy(plain_message + sizeof(temp_time), &reciever, sizeof(reciever));
Node_format receiver;
memcpy(receiver.client_id, public_key, CLIENT_ID_SIZE);
receiver.ip_port = ip_port;
memcpy(plain_message + sizeof(temp_time), &receiver, sizeof(receiver));
if (sendback_node != NULL)
memcpy(plain_message + sizeof(temp_time) + sizeof(reciever), sendback_node, sizeof(Node_format));
memcpy(plain_message + sizeof(temp_time) + sizeof(receiver), sendback_node, sizeof(Node_format));
else
memset(plain_message + sizeof(temp_time) + sizeof(reciever), 0, sizeof(Node_format));
memset(plain_message + sizeof(temp_time) + sizeof(receiver), 0, sizeof(Node_format));
int len_m = encrypt_data_symmetric(dht->secret_symmetric_key,
nonce,
plain_message,
sizeof(temp_time) + sizeof(reciever) + sizeof(Node_format),
sizeof(temp_time) + sizeof(receiver) + sizeof(Node_format),
encrypted_message + crypto_box_NONCEBYTES);
if (len_m != NODES_ENCRYPTED_MESSAGE_LENGTH - crypto_box_NONCEBYTES)

View File

@ -217,7 +217,7 @@ typedef struct {
void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, uint8_t *secret_key, uint8_t *client_id);
/* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key
* for packets that we recieve.
* for packets that we receive.
*/
void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, uint8_t *client_id);

View File

@ -1835,6 +1835,10 @@ void kill_messenger(Messenger *m)
kill_net_crypto(m->net_crypto);
kill_DHT(m->dht);
kill_networking(m->net);
for (i = 0; i < m->numfriends; ++i) {
if (m->friendlist[i].statusmessage)
free(m->friendlist[i].statusmessage);
}
free(m->friendlist);
free(m);
}
@ -2228,7 +2232,7 @@ void do_friends(Messenger *m)
}
if (m->friendlist[i].ping_lastrecv + FRIEND_CONNECTION_TIMEOUT < temp_time) {
/* If we stopped recieving ping packets, kill it. */
/* If we stopped receiving ping packets, kill it. */
crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id);
m->friendlist[i].crypt_connection_id = -1;
set_friend_status(m, i, FRIEND_CONFIRMED);

View File

@ -88,7 +88,7 @@ enum {
/* Interval between the sending of ping packets. */
#define FRIEND_PING_INTERVAL 5
/* If no packets are recieved from friend in this time interval, kill the connection. */
/* If no packets are received from friend in this time interval, kill the connection. */
#define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 2)
/* USERSTATUS -
@ -352,7 +352,7 @@ int setname(Messenger *m, uint8_t *name, uint16_t length);
/*
* Get your nickname.
* m - The messanger context to use.
* m - The messenger context to use.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
*
* return length of the name.

View File

@ -228,7 +228,7 @@ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length)
return -1;
}
/* return length of recieved packet on success.
/* return length of received packet on success.
* return 0 if could not read any packet.
* return -1 on failure (connection must be killed).
*/

View File

@ -138,7 +138,7 @@ uint16_t read_TCP_length(sock_t sock);
*/
int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length);
/* return length of recieved packet on success.
/* return length of received packet on success.
* return 0 if could not read any packet.
* return -1 on failure (connection must be killed).
*/

View File

@ -28,7 +28,7 @@
* Candidates are kept in buckets of hash tables. The hash
* function is calculated from the client_id. Up to
* HASH_COLLIDE_COUNT alternative positions are tried if
* the inital position is already used by a different entry.
* the initial position is already used by a different entry.
* The collision function is multiplicative, not additive.
*
* A new candidate can bump an existing candidate, if it is

View File

@ -314,7 +314,6 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, uint8_t *data, uint32_t le
* ip and port of sender is put into ip_port.
* Packet data is put into data.
* Packet length is put into length.
* Dump all empty packets.
*/
static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t *length)
{
@ -328,7 +327,7 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
*length = 0;
int fail_or_len = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
if (fail_or_len <= 0) {
if (fail_or_len < 0) {
#ifdef LOGGING
if ((fail_or_len < 0) && (errno != EWOULDBLOCK)) {
@ -337,7 +336,7 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
}
#endif
return -1; /* Nothing received or empty packet. */
return -1; /* Nothing received. */
}
*length = (uint32_t)fail_or_len;

View File

@ -509,9 +509,9 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t
return 0;
}
/* Send data of length length to friendnum.
* This data will be recieved by the friend using the Onion_Data_Handlers callbacks.
* This data will be received by the friend using the Onion_Data_Handlers callbacks.
*
* Even if this function succeeds, the friend might not recieve any data.
* Even if this function succeeds, the friend might not receive any data.
*
* return the number of packets sent on success
* return -1 on failure.
@ -574,7 +574,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32
/* Try to send the fakeid via the DHT instead of onion
*
* Even if this function succeeds, the friend might not recieve any data.
* Even if this function succeeds, the friend might not receive any data.
*
* return the number of packets sent on success
* return -1 on failure.

View File

@ -184,9 +184,9 @@ int onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *d
/* Send data of length length to friendnum.
* Maximum length of data is ONION_CLIENT_MAX_DATA_SIZE.
* This data will be recieved by the friend using the Onion_Data_Handlers callbacks.
* This data will be received by the friend using the Onion_Data_Handlers callbacks.
*
* Even if this function succeeds, the friend might not recieve any data.
* Even if this function succeeds, the friend might not receive any data.
*
* return the number of packets sent on success
* return -1 on failure.

View File

@ -186,7 +186,7 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length)
}
/* Get your nickname.
* m - The messanger context to use.
* m - The messenger context to use.
* name - Pointer to a string for the name. (must be at least MAX_NAME_LENGTH)
*
* return length of the name.
@ -828,4 +828,4 @@ int tox_load(Tox *tox, uint8_t *data, uint32_t length)
{
Messenger *m = tox;
return messenger_load(m, data, length);
}
}

View File

@ -210,7 +210,7 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length);
/*
* Get your nickname.
* m - The messanger context to use.
* m - The messenger context to use.
* name - needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
*
* return length of name.
@ -515,11 +515,11 @@ uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size);
* tox_file_data_remaining(...) can be used to know how many bytes are left to send/receive.
*
* If the connection breaks during file sending (The other person goes offline without pausing the sending and then comes back)
* the reciever must send a control packet with receive_send == 0 message_id = TOX_FILECONTROL_RESUME_BROKEN and the data being
* a uint64_t (in host byte order) containing the number of bytes recieved.
* the receiver must send a control packet with receive_send == 0 message_id = TOX_FILECONTROL_RESUME_BROKEN and the data being
* a uint64_t (in host byte order) containing the number of bytes received.
*
* If the sender recieves this packet, he must send a control packet with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT
* then he must start sending file data from the position (data , uint64_t in host byte order) recieved in the TOX_FILECONTROL_RESUME_BROKEN packet.
* If the sender receives this packet, he must send a control packet with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT
* then he must start sending file data from the position (data , uint64_t in host byte order) received in the TOX_FILECONTROL_RESUME_BROKEN packet.
*
* More to come...
*/