summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Messenger.c95
-rw-r--r--core/Messenger.h48
-rw-r--r--core/net_crypto.c19
-rw-r--r--core/net_crypto.h19
4 files changed, 179 insertions, 2 deletions
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 @@
1/* Messenger.c
2*
3* An implementation of a simple text chat only messenger on the tox network core.
4*
5*/
6
7#include "Messenger.h"
8
9
10typedef struct
11{
12 uint8_t client_id[CLIENT_ID_SIZE];
13
14
15}Friend;
16
17#define MAX_NUM_FRIENDS 256
18
19Friend friendlist[MAX_NUM_FRIENDS];
20
21//add a friend
22//returns the friend number if success
23//return -1 if failure.
24int m_addfriend(uint8_t * client_id)
25{
26
27 //add friend to the DHT
28 addfriend(uint8_t * client_id);
29
30 send_friendrequest(uint8_t * public_key, IP_Port ip_port, uint8_t * data, uint32_t length);
31
32}
33
34//remove a friend
35int m_delfriend(int friendnumber)
36{
37 //delete friend from DHT
38 delfriend(uint8_t * client_id);
39
40}
41
42
43//return 1 if friend is online
44//return 0 if he is not
45int m_friendonline(int friendnumber)
46{
47
48
49}
50
51
52//send a text chat message to a friend.
53int m_sendmessage(int friendnumber)
54{
55 write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length);
56
57}
58
59
60#define PORT 33445
61//run this at startup
62void initMessenger();
63{
64 new_keys();
65 IP ip;
66 ip.i = 0;
67 init_networking(ip, PORT);
68
69}
70
71//the main loop that needs to be run at least 200 times per second.
72void doMessenger();
73{
74 IP_Port ip_port;
75 uint8_t data[MAX_UDP_PACKET_SIZE];
76 uint32_t length;
77 while(recievepacket(&ip_port, data, &length) != -1)
78 {
79 //if(rand() % 3 != 1)//simulate packet loss
80 //{
81 if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port))
82 {
83 //if packet is discarded
84 printf("Received unhandled packet with length: %u\n", length);
85 }
86 else
87 {
88 printf("Received handled packet with length: %u\n", length);
89 }
90 //}
91 }
92 doDHT();
93 doLossless_UDP();
94 doNetCrypto();
95} \ 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 @@
1/* Messenger.h
2*
3* An implementation of a simple text chat only messenger on the tox network core.
4*
5*/
6
7
8#ifndef MESSENGER_H
9#define MESSENGER_H
10
11#include "net_crypto.h"
12#include "DHT.h"
13
14
15//add a friend
16//returns the friend number if success
17//return -1 if failure.
18int m_addfriend(uint8_t * client_id);
19
20
21//remove a friend
22int m_delfriend(int friendnumber);
23
24//return 1 if friend is online
25//return 0 if he is not
26int m_friendonline(int friendnumber);
27
28
29//send a text chat message to a friend.
30int m_sendmessage(int friendnumber);
31
32
33//set the function that will be executed when a friend request is recieved.
34int m_callback_friendrequest();
35
36
37//set the function that will be executed when a message from a friend is recieved.
38int m_callback_friendmessage();
39
40
41//run this at startup
42void initMessenger();
43
44
45//the main loop that needs to be run at least 200 times per second.
46void doMessenger();
47
48#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 @@
5* 5*
6* NOTE: This code has to be perfect. We don't mess around with encryption. 6* NOTE: This code has to be perfect. We don't mess around with encryption.
7* 7*
8*/ 8
9 Copyright (C) 2013 Tox project All Rights Reserved.
10
11 This file is part of Tox.
12
13 Tox is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
9 17
18 Tox is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with Tox. If not, see <http://www.gnu.org/licenses/>.
25
26*/
10 27
11#include "net_crypto.h" 28#include "net_crypto.h"
12 29
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 @@
2* 2*
3* Functions for the core network crypto. 3* Functions for the core network crypto.
4* 4*
5*/ 5
6 Copyright (C) 2013 Tox project All Rights Reserved.
7
8 This file is part of Tox.
9
10 Tox is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
6 14
15 Tox is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with Tox. If not, see <http://www.gnu.org/licenses/>.
22
23*/
7#ifndef NET_CRYPTO_H 24#ifndef NET_CRYPTO_H
8#define NET_CRYPTO_H 25#define NET_CRYPTO_H
9 26