diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-17 12:07:19 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-17 12:07:19 -0400 |
commit | 4864cb9edbe567af6f774bcf6ad90211449a258f (patch) | |
tree | c23d1d72b7de039dd0df1e3ce60963bdddf7e4a1 /testing | |
parent | ffa809b3797e1e8fba4c1c495c4990cae44477d7 (diff) |
Bug fixed, Loading and saving added to core.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/Messenger_test.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index c049aa18..484098b9 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -10,9 +10,14 @@ | |||
10 | * This is how I compile it: gcc -O2 -Wall -D VANILLA_NACL -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} Messenger_test.c | 10 | * This is how I compile it: gcc -O2 -Wall -D VANILLA_NACL -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} Messenger_test.c |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * Command line arguments are the ip and port of a node (for bootstrapping). | 13 | * Command line arguments are the ip, port and public_key of a node (for bootstrapping). |
14 | * | ||
15 | * EX: ./test 127.0.0.1 33445 CDCFD319CE3460824B33BE58FD86B8941C9585181D8FBD7C79C5721D7C2E9F7C | ||
16 | * | ||
17 | * Or the argument can be the path to the save file. | ||
18 | * | ||
19 | * EX: ./test Save.bak | ||
14 | * | 20 | * |
15 | * EX: ./test 127.0.0.1 33445 | ||
16 | */ | 21 | */ |
17 | 22 | ||
18 | #include "../core/Messenger.h" | 23 | #include "../core/Messenger.h" |
@@ -77,11 +82,29 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
77 | 82 | ||
78 | int main(int argc, char *argv[]) | 83 | int main(int argc, char *argv[]) |
79 | { | 84 | { |
80 | if (argc < 4) { | 85 | if (argc < 4 && argc != 2) { |
81 | printf("usage %s ip port public_key (of the DHT bootstrap node)\n", argv[0]); | 86 | printf("usage %s ip port public_key (of the DHT bootstrap node)\n or\n %s Save.bak\n", argv[0], argv[0]); |
82 | exit(0); | 87 | exit(0); |
83 | } | 88 | } |
84 | initMessenger(); | 89 | initMessenger(); |
90 | if(argc > 3) | ||
91 | { | ||
92 | IP_Port bootstrap_ip_port; | ||
93 | bootstrap_ip_port.port = htons(atoi(argv[2])); | ||
94 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); | ||
95 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | FILE *file = fopen(argv[1], "rb"); | ||
100 | if ( file==NULL ){return 1;} | ||
101 | int read; | ||
102 | uint8_t buffer[128000]; | ||
103 | read = fread(buffer, 1, 128000, file); | ||
104 | printf("Messenger loaded: %i\n", Messenger_load(buffer, read)); | ||
105 | fclose(file); | ||
106 | |||
107 | } | ||
85 | m_callback_friendrequest(print_request); | 108 | m_callback_friendrequest(print_request); |
86 | m_callback_friendmessage(print_message); | 109 | m_callback_friendmessage(print_message); |
87 | 110 | ||
@@ -103,16 +126,19 @@ int main(int argc, char *argv[]) | |||
103 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 126 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
104 | 127 | ||
105 | perror("Initialization"); | 128 | perror("Initialization"); |
106 | IP_Port bootstrap_ip_port; | 129 | |
107 | bootstrap_ip_port.port = htons(atoi(argv[2])); | ||
108 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); | ||
109 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | ||
110 | |||
111 | while(1) | 130 | while(1) |
112 | { | 131 | { |
113 | m_sendmessage(num, (uint8_t*)"Test", 5); | 132 | m_sendmessage(num, (uint8_t*)"Test", 5); |
114 | doMessenger(); | 133 | doMessenger(); |
115 | c_sleep(30); | 134 | c_sleep(30); |
135 | FILE *file = fopen("Save.bak", "wb"); | ||
136 | if ( file==NULL ){return 1;} | ||
137 | uint8_t * buffer = malloc(Messenger_size()); | ||
138 | Messenger_save(buffer); | ||
139 | fwrite(buffer, 1, Messenger_size(), file); | ||
140 | free(buffer); | ||
141 | fclose(file); | ||
116 | } | 142 | } |
117 | 143 | ||
118 | } | 144 | } |