Merged upstream

This commit is contained in:
mannol 2014-06-22 02:41:32 +02:00
commit 77150081ba
14 changed files with 61 additions and 54 deletions

View File

@ -45,17 +45,18 @@ pkg install autoconf automake gcc-47
On FreeBSD 10+:
```tcsh
pkg install automake autoconf
pkg install net-im/tox
```
Note, if you install from ports select NaCl for performance, and sodium if you want it to be portable.
You should get and install [libsodium](https://github.com/jedisct1/libsodium):
```bash
git clone git://github.com/jedisct1/libsodium.git
cd libsodium
git checkout tags/0.4.2
git checkout tags/0.5.0
./autogen.sh
./configure && make check
sudo checkinstall --install --pkgname libsodium --pkgversion 0.4.2 --nodoc
sudo checkinstall --install --pkgname libsodium --pkgversion 0.5.0 --nodoc
sudo ldconfig
cd ..
```
@ -67,7 +68,7 @@ this will install the libs to /usr/local/lib and the headers to /usr/local/inclu
```bash
git clone git://github.com/jedisct1/libsodium.git
cd libsodium
git checkout tags/0.4.2
git checkout tags/0.5.0
./autogen.sh
./configure
make check
@ -183,10 +184,10 @@ MinGW will install an "MinGW shell" (you should get a shortcut for it), make
sure to perform all operations (i.e., generating/running configure script, compiling, etc.) from the MinGW shell.
First download the source tarball from https://download.libsodium.org/libsodium/releases/ and build it.
Assuming that you got the libsodium-0.4.2.tar.gz release:
Assuming that you got the libsodium-0.5.0.tar.gz release:
```cmd
tar -zxvf libsodium-0.4.2.tar.gz
cd libsodium-0.4.2
tar -zxvf libsodium-0.5.0.tar.gz
cd libsodium-0.5.0
./configure
make
make install

View File

@ -1,21 +1,21 @@
![Project Tox](https://raw.github.com/irungentoo/ProjectTox-Core/master/other/tox.png "Project Tox")
![Project Tox](https://raw.github.com/irungentoo/toxcore/master/other/tox.png "Project Tox")
***
With the rise of governmental monitoring programs, Tox, a FOSS initiative, aims to be an easy to use, all-in-one communication platform that ensures their users full privacy and secure message delivery.<br /> <br />
[**Website**](https://tox.im) **|** [**Wiki**](http://wiki.tox.im/) **|** [**Blog**](https://blog.libtoxcore.so/) **|** [**FAQ**](http://wiki.tox.im/FAQ) **|** [**Binaries**](http://download.tox.im/) **|** [**Clients**](http://wiki.tox.im/Client) **|** [**Compiling**](http://wiki.tox.im/Installing) **|** [**API**](http://api.libtoxcore.so/) **|** [**Qt-GUI**](https://github.com/nurupo/ProjectTox-Qt-GUI) **|** **IRC:** #tox@freenode
[**Website**](https://tox.im) **|** [**Wiki**](https://wiki.tox.im/) **|** [**Blog**](https://blog.libtoxcore.so/) **|** [**FAQ**](http://wiki.tox.im/FAQ) **|** [**Binaries**](https://wiki.tox.im/Binaries) **|** [**Clients**](https://wiki.tox.im/Client) **|** [**Compiling**](https://wiki.tox.im/Installing) **|** [**API**](https://libtoxcore.so/) **|** **IRC:** #tox@freenode
## 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.
Tox must use UDP simply because [hole punching](https://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.
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/toxcore/wiki/Crypto) connection with each other. Once the connection is made, peers can exchange messages, send files, start video chats, etc. using encrypted communications.
**Current build status:** [![Build Status](https://travis-ci.org/irungentoo/ProjectTox-Core.png?branch=master)](https://travis-ci.org/irungentoo/ProjectTox-Core)
**Current build status:** [![Build Status](https://travis-ci.org/irungentoo/toxcore.png?branch=master)](https://travis-ci.org/irungentoo/toxcore)
## Q&A:
@ -34,9 +34,9 @@ The goal of this project is to create a configuration-free P2P Skype replacement
## Documentation:
- [Installation](/INSTALL.md)
- [DHT Protocol](http://wiki.tox.im/index.php/DHT)<br />
- [Lossless UDP Protocol](http://wiki.tox.im/index.php/Lossless_UDP)<br />
- [Crypto](http://wiki.tox.im/index.php/Crypto)<br />
- [Ideas](http://wiki.tox.im/index.php/Ideas)
- [DHT Protocol](https://wiki.tox.im/index.php/DHT)<br />
- [Lossless UDP Protocol](https://wiki.tox.im/index.php/Lossless_UDP)<br />
- [Crypto](https://wiki.tox.im/index.php/Crypto)<br />
- [Ideas](https://wiki.tox.im/index.php/Ideas)
[String]: https://en.wikipedia.org/wiki/String_(computer_science)

View File

@ -36,6 +36,7 @@ int load_file(char *filename, char **result)
if (size != fread(*result, sizeof(char), size, f)) {
free(*result);
fclose(f);
return -2; // -2 means file reading fail
}

View File

@ -531,11 +531,11 @@ void line_eval(Tox *m, char *line)
}
}
} else if (inpt_command == 't') {
char msg[512];
char *posi[1];
int friendnum = strtoul(line + prompt_offset, posi, 0);
if (**posi != 0) {
char msg[512];
sprintf(msg, "[t] Sending file %s to friendnum %u filenumber is %i (-1 means failure)", *posi + 1, friendnum,
add_filesender(m, friendnum, *posi + 1));
new_lines(msg);
@ -634,7 +634,7 @@ void line_eval(Tox *m, char *line)
* otherwise turns spaces into newlines if possible */
void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int line_width)
{
size_t i, k, m, len = strlen(input);
size_t i, len = strlen(input);
if ((line_width < 4) || (len < (size_t)line_width)) {
/* if line_width ridiculously tiny, it's not worth the effort */
@ -652,8 +652,8 @@ void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int lin
for (i = line_width; i < len; i += line_width) {
/* look backward for a space to expand/turn into a new line */
k = i;
m = i - line_width;
size_t k = i;
size_t m = i - line_width;
while (input[k] != ' ' && k > m) {
k--;
@ -837,7 +837,6 @@ void do_refresh()
{
int count = 0;
char wrap_output[STRING_LENGTH_WRAPPED];
int L;
int i;
for (i = 0; i < HISTORY; i++) {
@ -846,7 +845,7 @@ void do_refresh()
else
wrap(wrap_output, lines[i], x);
L = count_lines(wrap_output);
int L = count_lines(wrap_output);
count = count + L;
if (count < y) {
@ -921,11 +920,10 @@ static char *data_file_name = NULL;
static int load_data(Tox *m)
{
FILE *data_file = fopen(data_file_name, "r");
size_t size = 0;
if (data_file) {
fseek(data_file, 0, SEEK_END);
size = ftell(data_file);
size_t size = ftell(data_file);
rewind(data_file);
uint8_t data[size];
@ -1215,7 +1213,6 @@ int main(int argc, char *argv[])
exit(1);
int on = 0;
int c = 0;
char *filename = "data";
char idstring[200] = {0};
Tox *m;
@ -1282,8 +1279,6 @@ int main(int argc, char *argv[])
time_t timestamp0 = time(NULL);
uint8_t pollok = 0;
while (1) {
if (on == 0) {
if (tox_isconnected(m)) {
@ -1305,7 +1300,7 @@ int main(int argc, char *argv[])
tox_do(m);
do_refresh();
c = timeout_getch(m);
int c = timeout_getch(m);
if (c == ERR || c == 27)
continue;

View File

@ -154,12 +154,11 @@ void queue(JitterBuffer *q, RTPMessage *pk)
q->queue[q->rear] = pk;
int a;
int b;
int j;
a = q->rear;
for (j = 0; j < q->size - 1; ++j) {
b = a - 1;
int b = a - 1;
if (b < 0)
b += q->capacity;
@ -336,4 +335,4 @@ int energy_VAD(CodecState* cs, int16_t* PCM, uint16_t frame_size, float energy)
if ( cs->EVAD_tolerance_cr ) { cs->EVAD_tolerance_cr --; return 1; }
return 0;
}
}

View File

@ -431,8 +431,11 @@ MSIMessage *parse_message ( const uint8_t *data, uint16_t length )
*/
int stringify_message(MSIMessage *msg, char *dest)
{
// THIS CODE HAS NO EFFECT, AND THE ARGUMENTS ARE NOT MODIFIED
#if 0
#define HDR_TO_STR(__dest, __hdr) if (__hdr.header_value) {\
char nltstr[MSI_MAXMSG_SIZE]; memset(nltstr, '\0', MSI_MAXMSG_SIZE); int i = 0; \
char nltstr[MSI_MAXMSG_SIZE]; memset(nltstr+__hdr.size, '\0', MSI_MAXMSG_SIZE-__hdr.size); int i = 0; \
for ( ; i < __hdr.size; i ++) nltstr[i] = (char)__hdr.header_value[i]; \
}
@ -452,6 +455,7 @@ int stringify_message(MSIMessage *msg, char *dest)
// U8_TO_NLTCHAR(msg->version.header_value, msg->version.size, nltstr, MSI_MAXMSG_SIZE);
// sprintf(dest, "Version: %s\n", nltstr);
// }
#endif
return 0;
}

View File

@ -604,7 +604,7 @@ int rtp_release_session_recv ( RTPSession *session )
void rtp_queue_adjust_limit(RTPSession *session, uint64_t limit)
{
pthread_mutex_lock(&session->mutex);
RTPMessage *_tmp, * _it = session->oldest_msg;
for ( ; session->queue_size > limit; _it = _tmp ) {

View File

@ -475,16 +475,20 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
if (cii(call_index, av->msi_session)) return ErrorNoCall;
uint8_t packet [RTP_PAYLOAD_SIZE];
int recved_size = 0;
int rc;
CallSpecific *call = &av->calls[call_index];
int recved_size = 0;
do {
recved_size = toxav_recv_rtp_payload(av, call_index, TypeVideo, packet);
if (recved_size > 0 && ( rc = vpx_codec_decode(&call->cs->v_decoder, packet, recved_size, NULL, 0) ) != VPX_CODEC_OK) {
LOGGER_ERROR("Error decoding video: %s\n", vpx_codec_err_to_string(rc));
return ErrorInternal;
if (recved_size > 0) {
int rc = vpx_codec_decode(&call->cs->v_decoder, packet, recved_size, NULL, 0);
if (rc != VPX_CODEC_OK) {
LOGGER_ERROR("Error decoding video: %s\n", vpx_codec_err_to_string(rc));
return ErrorInternal;
}
}
} while (recved_size > 0);

View File

@ -2221,11 +2221,11 @@ uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num)
return 0;
uint16_t count = 0;
Client_data *list = NULL;
uint16_t list_size = 0;
uint32_t i;
for (i = 0; i < max_num; ++i) {
Client_data *list = NULL;
uint16_t rand_num = rand() % (dht->num_friends);
list = dht->friends_list[rand_num].client_list;
list_size = MAX_FRIEND_CLIENTS;

View File

@ -581,9 +581,11 @@ int m_copy_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *buf, uint3
if (friend_not_valid(m, friendnumber))
return -1;
memset(buf, 0, maxlen);
memcpy(buf, m->friendlist[friendnumber].statusmessage, MIN(maxlen, m->friendlist[friendnumber].statusmessage_length));
return MIN(maxlen, m->friendlist[friendnumber].statusmessage_length);
int msglen = MIN(maxlen, m->friendlist[friendnumber].statusmessage_length);
memcpy(buf, m->friendlist[friendnumber].statusmessage, msglen);
memset(buf + msglen, 0, maxlen - msglen);
return msglen;
}
/* return the size of friendnumber's user status.
@ -596,9 +598,10 @@ int m_get_self_statusmessage_size(Messenger *m)
int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen)
{
memset(buf, 0, maxlen);
memcpy(buf, m->statusmessage, MIN(maxlen, m->statusmessage_length));
return MIN(maxlen, m->statusmessage_length);
int msglen = MIN(maxlen, m->statusmessage_length);
memcpy(buf, m->statusmessage, msglen);
memset(buf + msglen, 0, maxlen - msglen);
return msglen;
}
uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber)
@ -2693,7 +2696,6 @@ void messenger_save(Messenger *m, uint8_t *data)
memset(relays, 0, len);
copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS);
memcpy(data, relays, len);
data += len;
}
static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)

View File

@ -818,9 +818,10 @@ static sock_t new_listening_TCP_socket(int family, uint16_t port)
return ~0;
}
int ok = 1;
#ifndef TCP_SERVER_USE_EPOLL
ok = set_socket_nonblock(sock);
int ok = set_socket_nonblock(sock);
#else
int ok = 1;
#endif
if (ok && family == AF_INET6) {

View File

@ -886,7 +886,7 @@ void do_Assoc(Assoc *assoc, DHT *dht)
* send getnode() requests to both */
uint8_t *target_id = NULL;
Client_entry *heard = NULL, *seen = NULL;
size_t i, k, m, bckt;
size_t i, k, m;
for (i = 1; i < assoc->candidates_bucket_count; i++) {
if (i % 2)
@ -894,7 +894,7 @@ void do_Assoc(Assoc *assoc, DHT *dht)
else
k = i >> 1;
bckt = (candidate + k) % assoc->candidates_bucket_count;
size_t bckt = (candidate + k) % assoc->candidates_bucket_count;
for (m = 0; m < assoc->candidates_bucket_size; m++)
if (assoc->candidates[bckt].list[m].hash) {

View File

@ -596,10 +596,10 @@ Networking_Core *new_networking(IP ip, uint16_t port)
*/
uint16_t port_to_try = port;
*portptr = htons(port_to_try);
int tries, res;
int tries;
for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) {
res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
int res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
if (!res) {
temp->port = *portptr;

View File

@ -1001,7 +1001,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
if (count < (uint32_t)rand() % MAX_ONION_CLIENTS) {
Node_format nodes_list[MAX_SENT_NODES];
uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list,
rand() % 2 ? AF_INET : AF_INET6, 1, 0);
(rand() % 2) ? AF_INET : AF_INET6, 1, 0);
for (i = 0; i < num_nodes; ++i)
client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0, ~0);
@ -1083,7 +1083,7 @@ static void do_announce(Onion_Client *onion_c)
if (count < (uint32_t)rand() % MAX_ONION_CLIENTS) {
Node_format nodes_list[MAX_SENT_NODES];
uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->c->self_public_key, nodes_list,
rand() % 2 ? AF_INET : AF_INET6, 1, 0);
(rand() % 2) ? AF_INET : AF_INET6, 1, 0);
for (i = 0; i < num_nodes; ++i) {
client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0, ~0);