From 2528ec148c6b1865a489c232800377f1d3952f04 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 6 Jul 2013 22:28:15 -0400 Subject: Very basic start on the Tox messaging api.(Should give you a basic idea how it's gonna work) --- core/Messenger.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ core/Messenger.h | 48 ++++++++++++++++++++++++++++ core/net_crypto.c | 19 ++++++++++- core/net_crypto.h | 19 ++++++++++- 4 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 core/Messenger.c create mode 100644 core/Messenger.h (limited to 'core') diff --git a/core/Messenger.c b/core/Messenger.c new file mode 100644 index 00000000..7cfbb8ca --- /dev/null +++ b/core/Messenger.c @@ -0,0 +1,95 @@ +/* Messenger.c +* +* An implementation of a simple text chat only messenger on the tox network core. +* +*/ + +#include "Messenger.h" + + +typedef struct +{ + uint8_t client_id[CLIENT_ID_SIZE]; + + +}Friend; + +#define MAX_NUM_FRIENDS 256 + +Friend friendlist[MAX_NUM_FRIENDS]; + +//add a friend +//returns the friend number if success +//return -1 if failure. +int m_addfriend(uint8_t * client_id) +{ + + //add friend to the DHT + addfriend(uint8_t * client_id); + + send_friendrequest(uint8_t * public_key, IP_Port ip_port, uint8_t * data, uint32_t length); + +} + +//remove a friend +int m_delfriend(int friendnumber) +{ + //delete friend from DHT + delfriend(uint8_t * client_id); + +} + + +//return 1 if friend is online +//return 0 if he is not +int m_friendonline(int friendnumber) +{ + + +} + + +//send a text chat message to a friend. +int m_sendmessage(int friendnumber) +{ + write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length); + +} + + +#define PORT 33445 +//run this at startup +void initMessenger(); +{ + new_keys(); + IP ip; + ip.i = 0; + init_networking(ip, PORT); + +} + +//the main loop that needs to be run at least 200 times per second. +void doMessenger(); +{ + IP_Port ip_port; + uint8_t data[MAX_UDP_PACKET_SIZE]; + uint32_t length; + while(recievepacket(&ip_port, data, &length) != -1) + { + //if(rand() % 3 != 1)//simulate packet loss + //{ + if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) + { + //if packet is discarded + printf("Received unhandled packet with length: %u\n", length); + } + else + { + printf("Received handled packet with length: %u\n", length); + } + //} + } + doDHT(); + doLossless_UDP(); + doNetCrypto(); +} \ No newline at end of file diff --git a/core/Messenger.h b/core/Messenger.h new file mode 100644 index 00000000..ae8ace16 --- /dev/null +++ b/core/Messenger.h @@ -0,0 +1,48 @@ +/* Messenger.h +* +* An implementation of a simple text chat only messenger on the tox network core. +* +*/ + + +#ifndef MESSENGER_H +#define MESSENGER_H + +#include "net_crypto.h" +#include "DHT.h" + + +//add a friend +//returns the friend number if success +//return -1 if failure. +int m_addfriend(uint8_t * client_id); + + +//remove a friend +int m_delfriend(int friendnumber); + +//return 1 if friend is online +//return 0 if he is not +int m_friendonline(int friendnumber); + + +//send a text chat message to a friend. +int m_sendmessage(int friendnumber); + + +//set the function that will be executed when a friend request is recieved. +int m_callback_friendrequest(); + + +//set the function that will be executed when a message from a friend is recieved. +int m_callback_friendmessage(); + + +//run this at startup +void initMessenger(); + + +//the main loop that needs to be run at least 200 times per second. +void doMessenger(); + +#endif diff --git a/core/net_crypto.c b/core/net_crypto.c index 02a95e6b..9a7500ea 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -5,8 +5,25 @@ * * NOTE: This code has to be perfect. We don't mess around with encryption. * -*/ + + 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 . + +*/ #include "net_crypto.h" diff --git a/core/net_crypto.h b/core/net_crypto.h index 3de0eb2f..a9bf1351 100644 --- a/core/net_crypto.h +++ b/core/net_crypto.h @@ -2,8 +2,25 @@ * * Functions for the core network crypto. * -*/ + + 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 . + +*/ #ifndef NET_CRYPTO_H #define NET_CRYPTO_H -- cgit v1.2.3