Very basic start on the Tox messaging api.(Should give you a basic idea how it's gonna work)

This commit is contained in:
irungentoo 2013-07-06 22:28:15 -04:00
parent 6a9805d368
commit 2528ec148c
4 changed files with 179 additions and 2 deletions

95
core/Messenger.c Normal file
View File

@ -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();
}

48
core/Messenger.h Normal file
View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "net_crypto.h"

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef NET_CRYPTO_H
#define NET_CRYPTO_H