mirror of
https://github.com/TokTok/c-toxcore
synced 2026-06-05 05:52:35 +00:00
+2
-2
@@ -15,8 +15,8 @@ before_script:
|
||||
- cd ..
|
||||
# installing libconfig, needed for DHT_bootstrap_daemon
|
||||
- sudo sed -i 's/precise/quantal/' /etc/apt/sources.list # needed for libconfig-dev
|
||||
- sudo apt-get update -qq
|
||||
- yes | sudo apt-get install libconfig-dev
|
||||
- sudo apt-get update -q
|
||||
- sudo apt-get -y install libconfig-dev
|
||||
|
||||
script:
|
||||
- mkdir build && cd build
|
||||
|
||||
+4
-3
@@ -5,8 +5,9 @@
|
||||
Build dependencies:
|
||||
|
||||
```bash
|
||||
apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev
|
||||
apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev cmake checkinstall
|
||||
```
|
||||
Note that `libconfig-dev` should be >= 1.4.
|
||||
|
||||
You should get and install [libsodium](https://github.com/jedisct1/libsodium):
|
||||
```bash
|
||||
@@ -15,7 +16,7 @@ cd libsodium
|
||||
git checkout tags/0.4.2
|
||||
./autogen.sh
|
||||
./configure && make check
|
||||
sudo make install
|
||||
sudo checkinstall --install --pkgname libsodium --pkgversion 0.4.2 --nodoc
|
||||
sudo ldconfig
|
||||
```
|
||||
|
||||
@@ -68,7 +69,7 @@ You have to [modify your PATH environment variable](http://www.computerhope.com/
|
||||
|
||||
Then you should either clone this repo by using git, or just download a [zip of current Master branch](https://github.com/irungentoo/ProjectTox-Core/archive/master.zip) and extract it somewhere.
|
||||
|
||||
After that you should get precompiled packages of libsodium from [here](https://download.libsodium.org/libsodium/releases/) and extract the archive into this repo's root. That is, `sodium` folder should be along with `core`, `testing` and other folders.
|
||||
After that you should get precompiled package of libsodium from [here](https://download.libsodium.org/libsodium/releases/libsodium-win32-0.4.2.tar.gz) and extract the archive into this repo's root. That is, `sodium` folder should be along with `core`, `testing` and other folders.
|
||||
|
||||
Navigate in `cmd` to this repo and run:
|
||||
```cmd
|
||||
|
||||
@@ -18,7 +18,7 @@ With the rise of governmental monitoring programs, Tox aims to be an easy to use
|
||||
+ Tox must use UDP simply because you can't hole punch with TCP. It's possible, but it doesn't work all the time.
|
||||
+ Every peer is represented as a byte string (the public key of the peer [client id])
|
||||
+ We're using torrent-style DHT so that peers can find the IP of the other peers when they have their ID.
|
||||
+ Once the client has the IP of that peer, they start initiating a secure connection with each other. (See [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)
|
||||
+ Once the client has the IP of that peer, they start initiating a secure connection with each other. (See [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto))
|
||||
+ When both peers are securely connect with the encryption, they can securely exchange messages, initiate a video chat, send files, etc.<br />
|
||||
+ Current build status: [](https://travis-ci.org/irungentoo/ProjectTox-Core)
|
||||
|
||||
|
||||
+7
-7
@@ -6,12 +6,12 @@ if(WIN32)
|
||||
endif()
|
||||
|
||||
set(core_sources
|
||||
DHT.c
|
||||
network.c
|
||||
Lossless_UDP.c
|
||||
net_crypto.c
|
||||
friend_requests.c
|
||||
LAN_discovery.c
|
||||
Messenger.c)
|
||||
DHT.c
|
||||
network.c
|
||||
Lossless_UDP.c
|
||||
net_crypto.c
|
||||
friend_requests.c
|
||||
LAN_discovery.c
|
||||
Messenger.c)
|
||||
|
||||
add_library(core ${core_sources})
|
||||
|
||||
@@ -308,12 +308,16 @@ IP_Port connection_ip(int connection_id)
|
||||
/* returns the number of packets in the queue waiting to be successfully sent. */
|
||||
uint32_t sendqueue(int connection_id)
|
||||
{
|
||||
if (connection_id < 0 || connection_id >= MAX_CONNECTIONS)
|
||||
return 0;
|
||||
return connections[connection_id].sendbuff_packetnum - connections[connection_id].successful_sent;
|
||||
}
|
||||
|
||||
/* returns the number of packets in the queue waiting to be successfully read with read_packet(...) */
|
||||
uint32_t recvqueue(int connection_id)
|
||||
{
|
||||
if (connection_id < 0 || connection_id >= MAX_CONNECTIONS)
|
||||
return 0;
|
||||
return connections[connection_id].recv_packetnum - connections[connection_id].successful_read;
|
||||
}
|
||||
|
||||
@@ -321,6 +325,8 @@ uint32_t recvqueue(int connection_id)
|
||||
return -1 if no packet in queue */
|
||||
char id_packet(int connection_id)
|
||||
{
|
||||
if (connection_id < 0 || connection_id >= MAX_CONNECTIONS)
|
||||
return -1;
|
||||
if (recvqueue(connection_id) != 0 && connections[connection_id].status != 0)
|
||||
return connections[connection_id].recvbuffer[connections[connection_id].successful_read % MAX_QUEUE_NUM].data[0];
|
||||
return -1;
|
||||
|
||||
@@ -71,6 +71,12 @@ int getfriend_id(uint8_t *client_id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns number of friends */
|
||||
int getnumfriends()
|
||||
{
|
||||
return numfriends;
|
||||
}
|
||||
|
||||
/* copies the public key associated to that friend id into client_id buffer.
|
||||
make sure that client_id is of size CLIENT_ID_SIZE.
|
||||
return 0 if success
|
||||
@@ -234,6 +240,16 @@ int setname(uint8_t * name, uint16_t length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get our nickname
|
||||
put it in name
|
||||
name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
|
||||
return the length of the name */
|
||||
uint16_t getself_name(uint8_t *name)
|
||||
{
|
||||
memcpy(name, self_name, self_name_length);
|
||||
return self_name_length;
|
||||
}
|
||||
|
||||
/* get name of friendnumber
|
||||
put it in name
|
||||
name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
|
||||
|
||||
@@ -92,6 +92,11 @@ int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length);
|
||||
return -1 if failure */
|
||||
int setname(uint8_t *name, uint16_t length);
|
||||
|
||||
/* get our nickname
|
||||
put it in name
|
||||
return the length of the name*/
|
||||
uint16_t getself_name(uint8_t *name);
|
||||
|
||||
/* get name of friendnumber
|
||||
put it in name
|
||||
name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
|
||||
|
||||
+2
-2
@@ -169,7 +169,7 @@ void shutdown_networking()
|
||||
address should represent IPv4, IPv6 or a hostname
|
||||
on success returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
|
||||
on failure returns -1 */
|
||||
int resolve_addr(char *address)
|
||||
int resolve_addr(const char *address)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
@@ -178,7 +178,7 @@ int resolve_addr(char *address)
|
||||
|
||||
struct addrinfo *server = NULL;
|
||||
|
||||
int success = getaddrinfo(address, "7", &hints, &server);
|
||||
int success = getaddrinfo(address, "echo", &hints, &server);
|
||||
if(success != 0)
|
||||
return -1;
|
||||
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ void shutdown_networking();
|
||||
address should represent IPv4, IPv6 or a hostname
|
||||
on success returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
|
||||
on failure returns -1 */
|
||||
int resolve_addr(char *address);
|
||||
int resolve_addr(const char *address);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -79,12 +79,20 @@ int main(int argc, char *argv[])
|
||||
manage_keys();
|
||||
printf("Public key: ");
|
||||
uint32_t i;
|
||||
|
||||
FILE *file;
|
||||
file = fopen("PUBLIC_ID.txt", "w");
|
||||
|
||||
for(i = 0; i < 32; i++)
|
||||
{
|
||||
if(self_public_key[i] < 16)
|
||||
printf("0");
|
||||
printf("%hhX",self_public_key[i]);
|
||||
fprintf(file, "%hhX",self_public_key[i]);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
printf("\n");
|
||||
printf("Port: %u\n", PORT);
|
||||
//initialize networking
|
||||
|
||||
@@ -4,7 +4,9 @@ project(DHT_bootstrap_daemon C)
|
||||
set(exe_name DHT_bootstrap_daemon)
|
||||
|
||||
add_executable(${exe_name}
|
||||
DHT_bootstrap_daemon.c)
|
||||
DHT_bootstrap_daemon.c)
|
||||
|
||||
target_link_libraries(${exe_name}
|
||||
config)
|
||||
|
||||
target_link_libraries(${exe_name} config)
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -4,6 +4,7 @@ project(DHT_bootstrap C)
|
||||
set(exe_name DHT_bootstrap)
|
||||
|
||||
add_executable(${exe_name}
|
||||
DHT_bootstrap.c ../testing/misc_tools.c)
|
||||
DHT_bootstrap.c
|
||||
../testing/misc_tools.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -8,8 +8,11 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_test.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
|
||||
if(WIN32)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)
|
||||
endif()
|
||||
|
||||
if(NOT WIN32)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toxic.cmake)
|
||||
|
||||
add_subdirectory(toxic)
|
||||
endif()
|
||||
|
||||
+3
-1
@@ -134,7 +134,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
char temp_id[128];
|
||||
printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n");
|
||||
scanf("%s", temp_id);
|
||||
if(scanf("%s", temp_id) != 1)
|
||||
exit(0);
|
||||
|
||||
DHT_addfriend(hex_string_to_bin(temp_id));
|
||||
|
||||
/* initialize networking */
|
||||
|
||||
@@ -4,6 +4,7 @@ project(DHT_cryptosendfiletest C)
|
||||
set(exe_name DHT_cryptosendfiletest)
|
||||
|
||||
add_executable(${exe_name}
|
||||
DHT_cryptosendfiletest.c misc_tools.c)
|
||||
DHT_cryptosendfiletest.c
|
||||
misc_tools.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -4,6 +4,6 @@ project(DHT_sendfiletest C)
|
||||
set(exe_name DHT_sendfiletest)
|
||||
|
||||
add_executable(${exe_name}
|
||||
DHT_sendfiletest.c)
|
||||
DHT_sendfiletest.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -4,6 +4,7 @@ project(DHT_test C)
|
||||
set(exe_name DHT_test)
|
||||
|
||||
add_executable(${exe_name}
|
||||
DHT_test.c misc_tools.c)
|
||||
DHT_test.c
|
||||
misc_tools.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -4,6 +4,6 @@ project(Lossless_UDP_testclient C)
|
||||
set(exe_name Lossless_UDP_testclient)
|
||||
|
||||
add_executable(${exe_name}
|
||||
Lossless_UDP_testclient.c)
|
||||
Lossless_UDP_testclient.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -4,6 +4,6 @@ project(Lossless_UDP_testserver C)
|
||||
set(exe_name Lossless_UDP_testserver)
|
||||
|
||||
add_executable(${exe_name}
|
||||
Lossless_UDP_testserver.c)
|
||||
Lossless_UDP_testserver.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -4,6 +4,6 @@ project(Messenger_test C)
|
||||
set(exe_name Messenger_test)
|
||||
|
||||
add_executable(${exe_name}
|
||||
Messenger_test.c misc_tools.c)
|
||||
Messenger_test.c misc_tools.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -4,8 +4,9 @@ project(nTox C)
|
||||
set(exe_name nTox)
|
||||
|
||||
add_executable(${exe_name}
|
||||
nTox.c misc_tools.c)
|
||||
|
||||
target_link_libraries(${exe_name} ncurses)
|
||||
nTox.c misc_tools.c)
|
||||
|
||||
target_link_libraries(${exe_name}
|
||||
ncurses)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
cmake_minimum_required(VERSION 2.6.0)
|
||||
project(nTox_win32 C)
|
||||
|
||||
set(exe_name nTox_win32)
|
||||
|
||||
add_executable(${exe_name}
|
||||
nTox_win32.c misc_tools.c)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
+58
-3
@@ -20,10 +20,10 @@
|
||||
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nTox.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#ifdef WIN32
|
||||
@@ -50,6 +50,46 @@ void new_lines(char *line)
|
||||
do_refresh();
|
||||
}
|
||||
|
||||
|
||||
void print_friendlist()
|
||||
{
|
||||
char name[MAX_NAME_LENGTH];
|
||||
uint32_t i;
|
||||
|
||||
new_lines("[i] Friend List:");
|
||||
for (i=0; i <= num_requests; i++) {
|
||||
char fstring[128];
|
||||
|
||||
getname(i, (uint8_t*)name);
|
||||
if (strlen(name) <= 0) {
|
||||
sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i);
|
||||
} else {
|
||||
sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i);
|
||||
}
|
||||
new_lines(fstring);
|
||||
}
|
||||
}
|
||||
|
||||
char *format_message(char *message, int friendnum)
|
||||
{
|
||||
char name[MAX_NAME_LENGTH];
|
||||
if(friendnum != -1) {
|
||||
getname(friendnum, (uint8_t*)name);
|
||||
} else {
|
||||
getself_name((uint8_t*)name);
|
||||
}
|
||||
char *msg = malloc(100+strlen(message)+strlen(name)+1);
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
time ( &rawtime );
|
||||
timeinfo = localtime ( &rawtime );
|
||||
char* time = asctime(timeinfo);
|
||||
size_t len = strlen(time);
|
||||
time[len-1]='\0';
|
||||
sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp
|
||||
return msg;
|
||||
}
|
||||
|
||||
void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||
{
|
||||
if (line[0] == '/') {
|
||||
@@ -88,6 +128,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||
int num = atoi(numstring);
|
||||
if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
|
||||
new_lines("[i] could not send message");
|
||||
} else {
|
||||
new_lines(format_message(message, -1));
|
||||
}
|
||||
}
|
||||
else if (line[1] == 'n') {
|
||||
@@ -104,6 +146,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||
sprintf(numstring, "[i] changed nick to %s", (char*)name);
|
||||
new_lines(numstring);
|
||||
}
|
||||
else if (line[1] == 'l') {
|
||||
print_friendlist();
|
||||
}
|
||||
else if (line[1] == 's') {
|
||||
uint8_t status[MAX_USERSTATUS_LENGTH];
|
||||
int i = 0;
|
||||
@@ -129,11 +174,20 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||
do_refresh();
|
||||
|
||||
}
|
||||
|
||||
else if (line[1] == 'h') { //help
|
||||
new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)");
|
||||
new_lines("[i] /l list (list friends), /h for help, /n nick (to change nickname), /q (to quit)");
|
||||
}
|
||||
|
||||
else if (line[1] == 'q') { //exit
|
||||
endwin();
|
||||
exit(EXIT_SUCCESS);
|
||||
} else {
|
||||
new_lines("[i] invalid command");
|
||||
}
|
||||
} else {
|
||||
new_lines("[i] invalid command");
|
||||
//new_lines(line);
|
||||
}
|
||||
}
|
||||
@@ -224,7 +278,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
||||
size_t len = strlen(temp);
|
||||
temp[len-1]='\0';
|
||||
sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp
|
||||
new_lines(msg);
|
||||
new_lines(format_message((char*)string, friendnumber));
|
||||
}
|
||||
|
||||
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
|
||||
@@ -313,7 +367,8 @@ int main(int argc, char *argv[])
|
||||
raw();
|
||||
getmaxyx(stdscr,y,x);
|
||||
new_lines(idstring0);
|
||||
new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)");
|
||||
new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)");
|
||||
new_lines("[i] /l list (list friends), /n nick (to change nickname), /q (to quit)");
|
||||
strcpy(line, "");
|
||||
IP_Port bootstrap_ip_port;
|
||||
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
/* nTox_win32.c
|
||||
*
|
||||
* Textual frontend for Tox - Windows version
|
||||
*
|
||||
* 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 "nTox_win32.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
#include <process.h>
|
||||
|
||||
uint8_t pending_requests[256][CLIENT_ID_SIZE];
|
||||
uint8_t num_requests;
|
||||
|
||||
char line[STRING_LENGTH];
|
||||
char users_id[200];
|
||||
|
||||
void do_header()
|
||||
{
|
||||
system("cls");
|
||||
printf(users_id);
|
||||
printf("\n---------------------------------");
|
||||
printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /d friendnumber (deletes friend), /q (to quit), /r (reset screen)");
|
||||
printf("\n---------------------------------");
|
||||
}
|
||||
|
||||
void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
|
||||
{
|
||||
printf("\n\n[i] received friend request with message\n");
|
||||
printf((char *)data);
|
||||
char numchar[100];
|
||||
sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests);
|
||||
printf(numchar);
|
||||
memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE);
|
||||
++num_requests;
|
||||
}
|
||||
|
||||
void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
||||
{
|
||||
char name[MAX_NAME_LENGTH];
|
||||
getname(friendnumber, (uint8_t*)name);
|
||||
char msg[100+length+strlen(name)+1];
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
time (&rawtime);
|
||||
timeinfo = localtime (&rawtime);
|
||||
char* temp = asctime(timeinfo);
|
||||
size_t len = strlen(temp);
|
||||
temp[len-1]='\0';
|
||||
sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
|
||||
{
|
||||
char name[MAX_NAME_LENGTH];
|
||||
getname(friendnumber, (uint8_t*)name);
|
||||
char msg[100+length];
|
||||
sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string);
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
|
||||
char name[MAX_NAME_LENGTH];
|
||||
getname(friendnumber, (uint8_t*)name);
|
||||
char msg[100+length+strlen(name)+1];
|
||||
sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string);
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
void load_key()
|
||||
{
|
||||
FILE *data_file = NULL;
|
||||
|
||||
if ((data_file = fopen("data", "r"))) {
|
||||
fseek(data_file, 0, SEEK_END);
|
||||
int size = ftell(data_file);
|
||||
fseek(data_file, 0, SEEK_SET);
|
||||
uint8_t data[size];
|
||||
|
||||
if(fread(data, sizeof(uint8_t), size, data_file) != size) {
|
||||
printf("\n[i] Could not read the data file. Exiting.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Messenger_load(data, size);
|
||||
} else {
|
||||
int size = Messenger_size();
|
||||
uint8_t data[size];
|
||||
Messenger_save(data);
|
||||
data_file = fopen("data", "w");
|
||||
|
||||
if(fwrite(data, sizeof(uint8_t), size, data_file) != size) {
|
||||
printf("\n[i] Could not write data to file. Exiting.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(data_file);
|
||||
}
|
||||
|
||||
void line_eval(char* line)
|
||||
{
|
||||
if(line[0] == '/') {
|
||||
/* Add friend */
|
||||
if(line[1] == 'f') {
|
||||
int i;
|
||||
char temp_id[128];
|
||||
for (i=0; i<128; i++)
|
||||
temp_id[i] = line[i+3];
|
||||
int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
|
||||
char numstring[100];
|
||||
sprintf(numstring, "\n[i] added friend %d\n\n", num);
|
||||
printf(numstring);
|
||||
}
|
||||
|
||||
else if (line[1] == 'r') {
|
||||
do_header();
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
else if (line[1] == 'l') {
|
||||
printf("\n[i] Friend List | Total: %d\n\n", getnumfriends());
|
||||
|
||||
int i;
|
||||
|
||||
for (i=0; i < getnumfriends(); i++) {
|
||||
char name[MAX_NAME_LENGTH];
|
||||
getname(i, (uint8_t*)name);
|
||||
printf("[%d] %s\n\n", i, (uint8_t*)name);
|
||||
}
|
||||
}
|
||||
|
||||
else if (line[1] == 'd') {
|
||||
size_t len = strlen(line);
|
||||
char numstring[len-3];
|
||||
int i;
|
||||
for (i=0; i<len; i++) {
|
||||
if (line[i+3] != ' ') {
|
||||
numstring[i] = line[i+3];
|
||||
}
|
||||
}
|
||||
int num = atoi(numstring);
|
||||
m_delfriend(num);
|
||||
}
|
||||
/* Send message to friend */
|
||||
else if (line[1] == 'm') {
|
||||
int i;
|
||||
size_t len = strlen(line);
|
||||
char numstring[len-3];
|
||||
char message[len-3];
|
||||
for (i=0; i<len; i++) {
|
||||
if (line[i+3] != ' ') {
|
||||
numstring[i] = line[i+3];
|
||||
} else {
|
||||
int j;
|
||||
for (j=i+1; j<len; j++)
|
||||
message[j-i-1] = line[j+3];
|
||||
break;
|
||||
}
|
||||
}
|
||||
int num = atoi(numstring);
|
||||
if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
|
||||
printf("\n[i] could not send message: %s\n", message);
|
||||
} else {
|
||||
//simply for aesthetics
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
else if (line[1] == 'n') {
|
||||
uint8_t name[MAX_NAME_LENGTH];
|
||||
int i = 0;
|
||||
size_t len = strlen(line);
|
||||
for (i=3; i<len; i++) {
|
||||
if (line[i] == 0 || line[i] == '\n') break;
|
||||
name[i - 3] = line[i];
|
||||
}
|
||||
name[i - 3] = 0;
|
||||
setname(name, i);
|
||||
char numstring[100];
|
||||
sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
|
||||
printf(numstring);
|
||||
}
|
||||
|
||||
else if (line[1] == 's') {
|
||||
uint8_t status[MAX_USERSTATUS_LENGTH];
|
||||
int i = 0;
|
||||
size_t len = strlen(line);
|
||||
for (i=3; i<len; i++) {
|
||||
if (line[i] == 0 || line[i] == '\n') break;
|
||||
status[i - 3] = line[i];
|
||||
}
|
||||
status[i - 3] = 0;
|
||||
m_set_userstatus(status, strlen((char*)status));
|
||||
char numstring[100];
|
||||
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
|
||||
printf(numstring);
|
||||
}
|
||||
|
||||
else if (line[1] == 'a') {
|
||||
uint8_t numf = atoi(line + 3);
|
||||
char numchar[100];
|
||||
sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
|
||||
printf(numchar);
|
||||
int num = m_addfriend_norequest(pending_requests[numf]);
|
||||
sprintf(numchar, "\n[i] added friendnumber %d\n\n", num);
|
||||
printf(numchar);
|
||||
}
|
||||
/* EXIT */
|
||||
else if (line[1] == 'q') {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
//nothing atm
|
||||
}
|
||||
}
|
||||
|
||||
void get_input()
|
||||
{
|
||||
while(1) {
|
||||
fgets(line, STRING_LENGTH, stdin);
|
||||
line_eval(line);
|
||||
strcpy(line, "");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 4) {
|
||||
printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (initMessenger() == -1) {
|
||||
printf("initMessenger failed");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (argc > 4) {
|
||||
if(strncmp(argv[4], "nokey", 6) < 0) {
|
||||
}
|
||||
} else {
|
||||
load_key();
|
||||
}
|
||||
|
||||
m_callback_friendrequest(print_request);
|
||||
m_callback_friendmessage(print_message);
|
||||
m_callback_namechange(print_nickchange);
|
||||
m_callback_userstatus(print_statuschange);
|
||||
|
||||
char idstring1[32][5];
|
||||
char idstring2[32][5];
|
||||
uint32_t i;
|
||||
for(i = 0; i < 32; i++)
|
||||
{
|
||||
if(self_public_key[i] < 16)
|
||||
strcpy(idstring1[i],"0");
|
||||
else
|
||||
strcpy(idstring1[i], "");
|
||||
sprintf(idstring2[i], "%hhX",self_public_key[i]);
|
||||
}
|
||||
strcpy(users_id,"[i] your ID: ");
|
||||
for (i=0; i<32; i++) {
|
||||
strcat(users_id,idstring1[i]);
|
||||
strcat(users_id,idstring2[i]);
|
||||
}
|
||||
|
||||
do_header();
|
||||
|
||||
IP_Port bootstrap_ip_port;
|
||||
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
||||
int resolved_address = resolve_addr(argv[1]);
|
||||
if (resolved_address != -1)
|
||||
bootstrap_ip_port.ip.i = resolved_address;
|
||||
else
|
||||
exit(1);
|
||||
|
||||
DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
||||
|
||||
int c;
|
||||
int on = 0;
|
||||
|
||||
_beginthread(get_input, 0, NULL);
|
||||
|
||||
while(1) {
|
||||
if (on == 1 && DHT_isconnected() == -1) {
|
||||
printf("\n---------------------------------");
|
||||
printf("\n[i] Disconnected from the DHT");
|
||||
printf("\n---------------------------------\n\n");
|
||||
on = 0;
|
||||
}
|
||||
|
||||
if (on == 0 && DHT_isconnected()) {
|
||||
printf("\n[i] Connected to DHT");
|
||||
printf("\n---------------------------------\n\n");
|
||||
on = 1;
|
||||
}
|
||||
|
||||
doMessenger();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/* nTox_win32.h
|
||||
*
|
||||
* Textual frontend for Tox - Windows version
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef NTOX_WIN32_H
|
||||
#define NTOX_WIN32_H
|
||||
|
||||
#include "../core/Messenger.h"
|
||||
#include "../core/network.h"
|
||||
|
||||
#define STRING_LENGTH 256
|
||||
|
||||
#endif
|
||||
@@ -1,11 +1,13 @@
|
||||
cmake_minimum_required(VERSION 2.6.0)
|
||||
project(toxic C)
|
||||
|
||||
set(exe_name toxic/toxic)
|
||||
set(exe_name toxic)
|
||||
|
||||
add_executable(${exe_name}
|
||||
toxic/main.c toxic/prompt.c)
|
||||
|
||||
target_link_libraries(${exe_name} curses)
|
||||
main.c
|
||||
prompt.c)
|
||||
|
||||
target_link_libraries(${exe_name}
|
||||
curses)
|
||||
|
||||
linkCoreLibraries(${exe_name})
|
||||
Reference in New Issue
Block a user