From db37eca44bca126c08dff4353c9d1dab824f8030 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 8 Jul 2013 20:50:25 -0400 Subject: Some work done on the messenger part. --- testing/Messenger_test.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 testing/Messenger_test.c (limited to 'testing') diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c new file mode 100644 index 00000000..4290d0fa --- /dev/null +++ b/testing/Messenger_test.c @@ -0,0 +1,92 @@ + + +#include "../core/Messenger.h" + +#ifdef WIN32 + +#define c_sleep(x) Sleep(1*x) + +#else +#include +#include +#define c_sleep(x) usleep(1000*x) + +#endif + +//horrible function from one of my first C programs. +//only here because I was too lazy to write a proper one. +unsigned char * hex_string_to_bin(char hex_string[]) +{ + unsigned char * val = malloc(strlen(hex_string)); + char * pos = hex_string; + int i=0; + while(i < strlen(hex_string)) + { + sscanf(pos,"%2hhx",&val[i]); + pos+=2; + i++; + } + return val; +} + +void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) +{ + printf("Friend request recieved from: \n"); + printf("ClientID: "); + uint32_t j; + for(j = 0; j < 32; j++) + { + if(public_key[j] < 16) + printf("0"); + printf("%hhX", public_key[j]); + } + printf("\nOf length: %u with data: %s \n", length, data); + +} + +void print_message(int friendnumber, uint8_t * string, uint16_t length) +{ + printf("Message with length %u recieved from %u: %s \n", length, friendnumber, string); + +} + +int main(int argc, char *argv[]) +{ + if (argc < 3) { + printf("usage %s ip port (of the DHT bootstrap node)\n", argv[0]); + exit(0); + } + initMessenger(); + m_callback_friendrequest(print_request); + m_callback_friendmessage(print_message); + + m_setinfo("Install Gentoo", sizeof("Install Gentoo"));//The message we send is a message of peace + + printf("OUR ID: "); + uint32_t i; + for(i = 0; i < 32; i++) + { + if(self_public_key[i] < 16) + printf("0"); + printf("%hhX",self_public_key[i]); + } + + char temp_id[128]; + printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); + scanf("%s", temp_id); + int num = m_addfriend(hex_string_to_bin(temp_id)); + + perror("Initialization"); + IP_Port bootstrap_ip_port; + bootstrap_ip_port.port = htons(atoi(argv[2])); + bootstrap_ip_port.ip.i = inet_addr(argv[1]); + DHT_bootstrap(bootstrap_ip_port); + + while(1) + { + m_sendmessage(num, "Test", 5); + doMessenger(); + c_sleep(1); + } + +} -- cgit v1.2.3