diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-06 22:28:15 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-06 22:28:15 -0400 |
commit | 2528ec148c6b1865a489c232800377f1d3952f04 (patch) | |
tree | 7479f63fc65eb56336d2619c7205046577580d72 /core/Messenger.c | |
parent | 6a9805d368c56e68e3220dc8a68bcd213f327d90 (diff) |
Very basic start on the Tox messaging api.(Should give you a basic idea how it's gonna work)
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 95 |
1 files changed, 95 insertions, 0 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 | |||
10 | typedef struct | ||
11 | { | ||
12 | uint8_t client_id[CLIENT_ID_SIZE]; | ||
13 | |||
14 | |||
15 | }Friend; | ||
16 | |||
17 | #define MAX_NUM_FRIENDS 256 | ||
18 | |||
19 | Friend friendlist[MAX_NUM_FRIENDS]; | ||
20 | |||
21 | //add a friend | ||
22 | //returns the friend number if success | ||
23 | //return -1 if failure. | ||
24 | int 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 | ||
35 | int 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 | ||
45 | int m_friendonline(int friendnumber) | ||
46 | { | ||
47 | |||
48 | |||
49 | } | ||
50 | |||
51 | |||
52 | //send a text chat message to a friend. | ||
53 | int 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 | ||
62 | void 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. | ||
72 | void 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 | ||