mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge branch 'master' of https://github.com/irungentoo/ProjectTox-Core
This commit is contained in:
commit
357c02ac22
|
@ -101,6 +101,7 @@ Grab the following packages:
|
|||
* http://www.gnu.org/software/automake/
|
||||
* http://www.cmake.org/
|
||||
* https://github.com/jedisct1/libsodium
|
||||
* http://www.hyperrealm.com/libconfig/
|
||||
|
||||
Uncompress and install them all. Make sure to follow the README as the instructions change, but they all follow the same pattern below:
|
||||
|
||||
|
@ -118,7 +119,7 @@ make
|
|||
```
|
||||
|
||||
Do not install them from macports (or any dependencies for that matter) as they get shoved in the wrong directory
|
||||
and make your life more annoying.
|
||||
(or the wrong version gets installed) and make your life more annoying.
|
||||
|
||||
Another thing you may want to install is the latest gcc, this caused me a few problems as XCode from 4.3
|
||||
no longer includes gcc and instead uses LLVM-GCC, a nice install guide can be found at
|
||||
|
|
|
@ -22,7 +22,7 @@ Keep everything really simple.
|
|||
|
||||
## The Complex Stuff:
|
||||
+ Tox must use UDP simply because [hole punching](http://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable.
|
||||
+ Every peer is represented as a [byte string](https://en.wikipedia.org/wiki/String_(computer_science)) (the public key of the peer [client ID]).
|
||||
+ Every peer is represented as a [byte string][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))
|
||||
+ When both peers are securely connected, they can exchange messages, initiate a video chat, send files, etc, all using encrypted communications.
|
||||
|
@ -53,3 +53,5 @@ configure for the normal user or suffer from being way too centralized.
|
|||
- [Lossless UDP Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/Lossless-UDP)<br />
|
||||
- [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)<br />
|
||||
- [Ideas](https://github.com/irungentoo/ProjectTox-Core/wiki/Ideas)
|
||||
|
||||
[String]: https://en.wikipedia.org/wiki/String_(computer_science)
|
||||
|
|
|
@ -17,3 +17,4 @@ set(core_sources
|
|||
Messenger.c)
|
||||
|
||||
add_library(toxcore SHARED ${core_sources})
|
||||
target_link_libraries(toxcore ${SODIUM_LIBRARY})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* DHT.c
|
||||
*
|
||||
* An implementation of the DHT as seen in docs/DHT.txt
|
||||
* An implementation of the DHT as seen in http://wiki.tox.im/index.php/DHT
|
||||
*
|
||||
* Copyright (C) 2013 Tox project All Rights Reserved.
|
||||
*
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* DHT.h
|
||||
*
|
||||
* An implementation of the DHT as seen in docs/DHT.txt
|
||||
* An implementation of the DHT as seen in http://wiki.tox.im/index.php/DHT
|
||||
*
|
||||
* Copyright (C) 2013 Tox project All Rights Reserved.
|
||||
*
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* Lossless_UDP.c
|
||||
*
|
||||
* An implementation of the Lossless_UDP protocol as seen in docs/Lossless_UDP.txt
|
||||
* An implementation of the Lossless_UDP protocol as seen in http://wiki.tox.im/index.php/Lossless_UDP
|
||||
*
|
||||
* Copyright (C) 2013 Tox project All Rights Reserved.
|
||||
*
|
||||
|
@ -467,7 +467,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested)
|
|||
/*
|
||||
* BEGIN Packet sending functions
|
||||
* One per packet type.
|
||||
* see docs/Lossless_UDP.txt for more information.
|
||||
* see http://wiki.tox.im/index.php/Lossless_UDP for more information.
|
||||
*/
|
||||
|
||||
int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* Lossless_UDP.h
|
||||
*
|
||||
* An implementation of the Lossless_UDP protocol as seen in docs/Lossless_UDP.txt
|
||||
* An implementation of the Lossless_UDP protocol as seen in http://wiki.tox.im/index.php/Lossless_UDP
|
||||
*
|
||||
* Copyright (C) 2013 Tox project All Rights Reserved.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* net_crypto.c
|
||||
*
|
||||
* Functions for the core network crypto.
|
||||
* See also: docs/Crypto.txt
|
||||
* See also: http://wiki.tox.im/index.php/DHT
|
||||
*
|
||||
* NOTE: This code has to be perfect. We don't mess around with encryption.
|
||||
*
|
||||
|
|
|
@ -36,11 +36,12 @@
|
|||
char lines[HISTORY][STRING_LENGTH];
|
||||
char line[STRING_LENGTH];
|
||||
|
||||
char *help = "[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)\n"
|
||||
"[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)";
|
||||
char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message "
|
||||
"(to send message)\n/s status (to change status)\n[i] /l list (l"
|
||||
"ist friends)\n/h for help\n/i for info\n/n nick (to change nick"
|
||||
"name)\n/q (to quit)";
|
||||
int x, y;
|
||||
|
||||
|
||||
uint8_t pending_requests[256][CLIENT_ID_SIZE];
|
||||
uint8_t num_requests = 0;
|
||||
|
||||
|
@ -82,18 +83,23 @@ void new_lines(char *line)
|
|||
void print_friendlist()
|
||||
{
|
||||
char name[MAX_NAME_LENGTH];
|
||||
int i = 0;
|
||||
new_lines("[i] Friend List:");
|
||||
uint32_t i;
|
||||
for (i = 0; i <= num_requests; i++) {
|
||||
char fstring[128];
|
||||
getname(i, (uint8_t*)name);
|
||||
while(getname(i, (uint8_t *)name) != -1) {
|
||||
/* account for the longest name and the longest "base" string */
|
||||
char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")];
|
||||
|
||||
if (strlen(name) <= 0) {
|
||||
sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i);
|
||||
sprintf(fstring, "[i] Friend: No Friend!\n\tid: %i", i);
|
||||
} else {
|
||||
sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i);
|
||||
}
|
||||
i++;
|
||||
new_lines(fstring);
|
||||
}
|
||||
|
||||
if(i == 0)
|
||||
new_lines("\tno friends! D:");
|
||||
}
|
||||
|
||||
char *format_message(char *message, int friendnum)
|
||||
|
@ -122,7 +128,7 @@ char *format_message(char *message, int friendnum)
|
|||
return msg;
|
||||
}
|
||||
|
||||
void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||
void line_eval(char *line)
|
||||
{
|
||||
if (line[0] == '/') {
|
||||
char inpt_command = line[1];
|
||||
|
@ -236,8 +242,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
|||
do_refresh();
|
||||
}
|
||||
else if (inpt_command == '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, /i for info, /n nick (to change nickname), /q (to quit)");
|
||||
new_lines(help);
|
||||
}
|
||||
else if (inpt_command == 'i') { //info
|
||||
char idstring[200];
|
||||
|
@ -353,10 +358,10 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
|
|||
new_lines(msg);
|
||||
}
|
||||
|
||||
void load_key()
|
||||
void load_key(char *path)
|
||||
{
|
||||
FILE *data_file = NULL;
|
||||
data_file = fopen("data","r");
|
||||
FILE *data_file = fopen(path, "r");
|
||||
|
||||
if (data_file) {
|
||||
//load keys
|
||||
fseek(data_file, 0, SEEK_END);
|
||||
|
@ -368,51 +373,81 @@ void load_key()
|
|||
exit(1);
|
||||
}
|
||||
Messenger_load(data, size);
|
||||
} else {
|
||||
|
||||
} else {
|
||||
//else save new keys
|
||||
int size = Messenger_size();
|
||||
uint8_t data[size];
|
||||
Messenger_save(data);
|
||||
data_file = fopen("data","w");
|
||||
data_file = fopen(path, "w");
|
||||
|
||||
if(!data_file) {
|
||||
perror("[!] load_key");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (fwrite(data, sizeof(uint8_t), size, data_file) != size){
|
||||
printf("[i] could not write data file\n[i] exiting\n");
|
||||
puts("[i] could not write data file! exiting...");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
fclose(data_file);
|
||||
}
|
||||
|
||||
void print_help(void)
|
||||
{
|
||||
printf("nTox %.1f - Command-line tox-core client\n", 0.1);
|
||||
puts("Options:");
|
||||
puts("\t-h\t-\tPrint this help and exit.");
|
||||
puts("\t-f\t-\tSpecify a keyfile to read (or write to) from.");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int on = 0;
|
||||
int c = 0;
|
||||
int i = 0;
|
||||
char *filename = "data";
|
||||
char idstring[200] = {0};
|
||||
|
||||
if (argc < 4) {
|
||||
printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
|
||||
printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
int c;
|
||||
int on = 0;
|
||||
initMessenger();
|
||||
//if keyfiles exist
|
||||
if(argc > 4){
|
||||
if(strncmp(argv[4], "nokey", 6) < 0){
|
||||
//load_key();
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
if(argv[i][0] == '-') {
|
||||
if(argv[i][1] == 'h') {
|
||||
print_help();
|
||||
exit(0);
|
||||
} else if(argv[i][1] == 'f') {
|
||||
if(argv[i + 1] != NULL)
|
||||
filename = argv[i + 1];
|
||||
else {
|
||||
fputs("[!] you passed '-f' without giving an argument!\n", stderr);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
load_key();
|
||||
}
|
||||
|
||||
initMessenger();
|
||||
load_key(filename);
|
||||
|
||||
m_callback_friendrequest(print_request);
|
||||
m_callback_friendmessage(print_message);
|
||||
m_callback_namechange(print_nickchange);
|
||||
m_callback_userstatus(print_statuschange);
|
||||
|
||||
char idstring[200];
|
||||
get_id(idstring);
|
||||
initscr();
|
||||
noecho();
|
||||
raw();
|
||||
getmaxyx(stdscr, y, x);
|
||||
|
||||
new_lines("/h for list of commands");
|
||||
get_id(idstring);
|
||||
new_lines(idstring);
|
||||
new_lines(help);
|
||||
strcpy(line, "");
|
||||
|
||||
IP_Port bootstrap_ip_port;
|
||||
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
||||
int resolved_address = resolve_addr(argv[1]);
|
||||
|
@ -439,7 +474,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
getmaxyx(stdscr, y, x);
|
||||
if (c == '\n') {
|
||||
line_eval(lines, line);
|
||||
line_eval(line);
|
||||
strcpy(line, "");
|
||||
} else if (c == 8 || c == 127) {
|
||||
line[strlen(line)-1] = '\0';
|
||||
|
|
|
@ -37,12 +37,13 @@
|
|||
#include <netdb.h>
|
||||
#include "../core/Messenger.h"
|
||||
#include "../core/network.h"
|
||||
|
||||
#define STRING_LENGTH 256
|
||||
#define HISTORY 50
|
||||
#define PUB_KEY_BYTES 32
|
||||
|
||||
void new_lines(char *line);
|
||||
void line_eval(char lines[HISTORY][STRING_LENGTH], char *line);
|
||||
void line_eval(char *line);
|
||||
void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ;
|
||||
int count_lines(char *string) ;
|
||||
char *appender(char *str, const char c);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../../core/Messenger.h"
|
||||
#include "../../core/network.h"
|
||||
|
@ -26,11 +27,15 @@ typedef struct {
|
|||
|
||||
extern void fix_name(uint8_t* name);
|
||||
|
||||
|
||||
static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) {
|
||||
ChatContext* ctx = (ChatContext*) self->x;
|
||||
uint8_t nick[MAX_NAME_LENGTH] = {0};
|
||||
|
||||
time_t now;
|
||||
time(&now);
|
||||
struct tm * timeinfo;
|
||||
timeinfo = localtime(&now);
|
||||
|
||||
if(ctx->friendnum != num)
|
||||
return;
|
||||
|
||||
|
@ -42,10 +47,11 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len)
|
|||
fix_name(msg);
|
||||
fix_name(nick);
|
||||
|
||||
wattron(ctx->history, COLOR_PAIR(2));
|
||||
wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
wattron(ctx->history, COLOR_PAIR(4));
|
||||
wprintw(ctx->history, "%s: ", nick);
|
||||
wattroff(ctx->history, COLOR_PAIR(4));
|
||||
|
||||
wprintw(ctx->history, "%s\n", msg);
|
||||
|
||||
self->blink = true;
|
||||
|
@ -71,9 +77,26 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1
|
|||
|
||||
}
|
||||
|
||||
/* check that the string has one non-space character */
|
||||
int string_is_empty(char *string)
|
||||
{
|
||||
int rc = 0;
|
||||
char *copy = strdup(string);
|
||||
|
||||
rc = ((strtok(copy, " ") == NULL) ? 1:0);
|
||||
free(copy);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void chat_onKey(ToxWindow* self, int key) {
|
||||
ChatContext* ctx = (ChatContext*) self->x;
|
||||
|
||||
time_t now;
|
||||
time(&now);
|
||||
struct tm * timeinfo;
|
||||
timeinfo = localtime(&now);
|
||||
|
||||
if(isprint(key)) {
|
||||
|
||||
if(ctx->pos != sizeof(ctx->line)-1) {
|
||||
|
@ -81,28 +104,34 @@ static void chat_onKey(ToxWindow* self, int key) {
|
|||
ctx->line[ctx->pos] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
else if(key == '\n') {
|
||||
wattron(ctx->history, COLOR_PAIR(1));
|
||||
wprintw(ctx->history, "you: ", ctx->line);
|
||||
wattroff(ctx->history, COLOR_PAIR(1));
|
||||
if(!string_is_empty(ctx->line)) {
|
||||
/* make sure the string has at least non-space character */
|
||||
wattron(ctx->history, COLOR_PAIR(2));
|
||||
wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
wattron(ctx->history, COLOR_PAIR(1));
|
||||
wprintw(ctx->history, "you: ", ctx->line);
|
||||
wattroff(ctx->history, COLOR_PAIR(1));
|
||||
wprintw(ctx->history, "%s\n", ctx->line);
|
||||
|
||||
wprintw(ctx->history, "%s\n", ctx->line);
|
||||
if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {
|
||||
wattron(ctx->history, COLOR_PAIR(3));
|
||||
wprintw(ctx->history, " * Failed to send message.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(3));
|
||||
}
|
||||
|
||||
if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {
|
||||
wattron(ctx->history, COLOR_PAIR(3));
|
||||
wprintw(ctx->history, " * Failed to send message.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(3));
|
||||
ctx->line[0] = '\0';
|
||||
ctx->pos = 0;
|
||||
}
|
||||
|
||||
ctx->line[0] = '\0';
|
||||
ctx->pos = 0;
|
||||
}
|
||||
|
||||
else if(key == 0x107 || key == 0x8 || key == 0x7f) {
|
||||
if(ctx->pos != 0) {
|
||||
ctx->line[--ctx->pos] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void chat_onDraw(ToxWindow* self) {
|
||||
|
@ -150,7 +179,7 @@ ToxWindow new_chat(int friendnum) {
|
|||
uint8_t nick[MAX_NAME_LENGTH] = {0};
|
||||
getname(friendnum, (uint8_t*) &nick);
|
||||
fix_name(nick);
|
||||
|
||||
|
||||
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
||||
|
||||
ChatContext* x = calloc(1, sizeof(ChatContext));
|
||||
|
|
|
@ -170,12 +170,12 @@ static void do_tox() {
|
|||
doMessenger();
|
||||
}
|
||||
|
||||
static void load_data() {
|
||||
static void load_data(char *path) {
|
||||
FILE* fd;
|
||||
size_t len;
|
||||
uint8_t* buf;
|
||||
|
||||
if((fd = fopen("data", "r")) != NULL) {
|
||||
if((fd = fopen(path, "r")) != NULL) {
|
||||
fseek(fd, 0, SEEK_END);
|
||||
len = ftell(fd);
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
|
@ -213,7 +213,7 @@ static void load_data() {
|
|||
|
||||
Messenger_save(buf);
|
||||
|
||||
fd = fopen("data", "w");
|
||||
fd = fopen(path, "w");
|
||||
if(fd == NULL) {
|
||||
fprintf(stderr, "fopen() failed.\n");
|
||||
|
||||
|
@ -282,13 +282,36 @@ void prepare_window(WINDOW* w) {
|
|||
|
||||
int main(int argc, char* argv[]) {
|
||||
int ch;
|
||||
int i = 0;
|
||||
int f_flag = 0;
|
||||
char *filename = "data";
|
||||
ToxWindow* a;
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
if(argv[i][0] == '-') {
|
||||
if(argv[i][1] == 'f') {
|
||||
if(argv[i + 1] != NULL)
|
||||
filename = argv[i + 1];
|
||||
else {
|
||||
f_flag = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init_term();
|
||||
init_tox();
|
||||
load_data();
|
||||
load_data(filename);
|
||||
init_windows();
|
||||
|
||||
if(f_flag == -1) {
|
||||
attron(COLOR_PAIR(3) | A_BOLD);
|
||||
wprintw(prompt->window, "You passed '-f' without giving an argument!\n"
|
||||
"defaulting to 'data' for a keyfile...\n");
|
||||
attroff(COLOR_PAIR(3) | A_BOLD);
|
||||
}
|
||||
|
||||
|
||||
while(true) {
|
||||
// Update tox.
|
||||
do_tox();
|
||||
|
|
Loading…
Reference in New Issue
Block a user