diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_sendfiletest.c | 60 | ||||
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 40 | ||||
-rw-r--r-- | testing/Lossless_UDP_testserver.c | 22 | ||||
-rw-r--r-- | testing/nTox.c | 50 |
4 files changed, 83 insertions, 89 deletions
diff --git a/testing/DHT_sendfiletest.c b/testing/DHT_sendfiletest.c index 5b5d6c9f..873a73f8 100644 --- a/testing/DHT_sendfiletest.c +++ b/testing/DHT_sendfiletest.c | |||
@@ -96,78 +96,72 @@ int main(int argc, char *argv[]) | |||
96 | uint8_t buffer2[128]; | 96 | uint8_t buffer2[128]; |
97 | int read2 = 0; | 97 | int read2 = 0; |
98 | FILE *file1 = fopen(argv[4], "rb"); | 98 | FILE *file1 = fopen(argv[4], "rb"); |
99 | if ( file1==NULL ){printf("Error opening file.\n");return 1;} | 99 | if (file1 == NULL) { |
100 | printf("Error opening file.\n"); | ||
101 | return 1; | ||
102 | } | ||
100 | FILE *file2 = fopen("received.txt", "wb"); | 103 | FILE *file2 = fopen("received.txt", "wb"); |
101 | if ( file2==NULL ){return 1;} | 104 | if (file2 == NULL) |
105 | return 1; | ||
106 | |||
102 | read1 = fread(buffer1, 1, 128, file1); | 107 | read1 = fread(buffer1, 1, 128, file1); |
103 | 108 | ||
104 | while(1) { | 109 | while (1) { |
105 | 110 | while (receivepacket(&ip_port, data, &length) != -1) { | |
106 | while(receivepacket(&ip_port, data, &length) != -1) { | 111 | if (rand() % 3 != 1) { /* simulate packet loss */ |
107 | if(rand() % 3 != 1) { /* simulate packet loss */ | 112 | if (DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) |
108 | if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) { | 113 | printf("Received unhandled packet with length: %u\n", length); /* if packet is not recognized */ |
109 | /* if packet is not recognized */ | 114 | else |
110 | printf("Received unhandled packet with length: %u\n", length); | ||
111 | } else { | ||
112 | printf("Received handled packet with length: %u\n", length); | 115 | printf("Received handled packet with length: %u\n", length); |
113 | } | ||
114 | } | 116 | } |
115 | } | 117 | } |
116 | friend_ip = DHT_getfriendip((uint8_t *)argv[3]); | 118 | friend_ip = DHT_getfriendip((uint8_t *)argv[3]); |
117 | if(friend_ip.ip.i != 0) { | 119 | if (friend_ip.ip.i != 0) { |
118 | if(connection == -1) { | 120 | if (connection == -1) { |
119 | printf("Started connecting to friend:"); | 121 | printf("Started connecting to friend:"); |
120 | printip(friend_ip); | 122 | printip(friend_ip); |
121 | connection = new_connection(friend_ip); | 123 | connection = new_connection(friend_ip); |
122 | } | 124 | } |
123 | } | 125 | } |
124 | if(inconnection == -1) { | 126 | if (inconnection == -1) { |
125 | inconnection = incoming_connection(); | 127 | inconnection = incoming_connection(); |
126 | if(inconnection != -1) { | 128 | if (inconnection != -1) { |
127 | printf("Someone connected to us:"); | 129 | printf("Someone connected to us:"); |
128 | printip(connection_ip(inconnection)); | 130 | printip(connection_ip(inconnection)); |
129 | } | 131 | } |
130 | } | 132 | } |
131 | /* if someone connected to us write what he sends to a file */ | 133 | /* if someone connected to us write what he sends to a file */ |
132 | /* also send him our file. */ | 134 | /* also send him our file. */ |
133 | if(inconnection != -1) { | 135 | if (inconnection != -1) { |
134 | if(write_packet(inconnection, buffer1, read1)) { | 136 | if (write_packet(inconnection, buffer1, read1)) { |
135 | printf("Wrote data.\n"); | 137 | printf("Wrote data.\n"); |
136 | read1 = fread(buffer1, 1, 128, file1); | 138 | read1 = fread(buffer1, 1, 128, file1); |
137 | } | 139 | } |
138 | read2 = read_packet(inconnection, buffer2); | 140 | read2 = read_packet(inconnection, buffer2); |
139 | if(read2 != 0) { | 141 | if (read2 != 0) { |
140 | printf("Received data.\n"); | 142 | printf("Received data.\n"); |
141 | if(!fwrite(buffer2, read2, 1, file2)) { | 143 | if (!fwrite(buffer2, read2, 1, file2)) |
142 | printf("file write error\n"); | 144 | printf("file write error\n"); |
143 | } | 145 | if (read2 < 128) { |
144 | if(read2 < 128) { | ||
145 | fclose(file2); | 146 | fclose(file2); |
146 | } | 147 | } |
147 | } | 148 | } |
148 | } | 149 | } |
149 | /* if we are connected to a friend send him data from the file. | 150 | /* if we are connected to a friend send him data from the file. |
150 | * also put what he sends us in a file. */ | 151 | * also put what he sends us in a file. */ |
151 | if(is_connected(connection) == 3) | 152 | if (is_connected(connection) == 3) { |
152 | { | 153 | if (write_packet(0, buffer1, read1)) { |
153 | if(write_packet(0, buffer1, read1)) | ||
154 | { | ||
155 | printf("Wrote data.\n"); | 154 | printf("Wrote data.\n"); |
156 | read1 = fread(buffer1, 1, 128, file1); | 155 | read1 = fread(buffer1, 1, 128, file1); |
157 | } | 156 | } |
158 | read2 = read_packet(0, buffer2); | 157 | read2 = read_packet(0, buffer2); |
159 | if(read2 != 0) | 158 | if (read2 != 0) { |
160 | { | ||
161 | printf("Received data.\n"); | 159 | printf("Received data.\n"); |
162 | if(!fwrite(buffer2, read2, 1, file2)) | 160 | if(!fwrite(buffer2, read2, 1, file2)) |
163 | { | 161 | printf("file write error\n"); |
164 | printf("file write error\n"); | ||
165 | } | ||
166 | if(read2 < 128) | 162 | if(read2 < 128) |
167 | { | ||
168 | fclose(file2); | 163 | fclose(file2); |
169 | } | 164 | } |
170 | } | ||
171 | } | 165 | } |
172 | doDHT(); | 166 | doDHT(); |
173 | doLossless_UDP(); | 167 | doLossless_UDP(); |
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 8f23528c..c1eaa69d 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -44,13 +44,13 @@ | |||
44 | 44 | ||
45 | #define PORT 33446 | 45 | #define PORT 33446 |
46 | 46 | ||
47 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | 47 | void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) |
48 | { | 48 | { |
49 | uint32_t i; | 49 | uint32_t i; |
50 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 50 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
51 | printf("--------------------BEGIN-----------------------------\n"); | 51 | printf("--------------------BEGIN-----------------------------\n"); |
52 | for(i = 0; i < length; i++) { | 52 | for (i = 0; i < length; i++) { |
53 | if(data[i] < 16) | 53 | if (data[i] < 16) |
54 | printf("0"); | 54 | printf("0"); |
55 | printf("%hhX",data[i]); | 55 | printf("%hhX",data[i]); |
56 | } | 56 | } |
@@ -59,7 +59,7 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | |||
59 | 59 | ||
60 | void printip(IP_Port ip_port) | 60 | void printip(IP_Port ip_port) |
61 | { | 61 | { |
62 | printf("\nIP: %u.%u.%u.%u Port: %u",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port)); | 62 | printf("\nIP: %u.%u.%u.%u Port: %u", ip_port.ip.c[0], ip_port.ip.c[1], ip_port.ip.c[2], ip_port.ip.c[3], ntohs(ip_port.port)); |
63 | } | 63 | } |
64 | /* | 64 | /* |
65 | void printpackets(Data test) | 65 | void printpackets(Data test) |
@@ -123,16 +123,15 @@ void Lossless_UDP() | |||
123 | IP_Port ip_port; | 123 | IP_Port ip_port; |
124 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 124 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
125 | uint32_t length; | 125 | uint32_t length; |
126 | while(receivepacket(&ip_port, data, &length) != -1) { | 126 | while (receivepacket(&ip_port, data, &length) != -1) { |
127 | printf("packet with length: %u\n", length); | 127 | printf("packet with length: %u\n", length); |
128 | /* if(rand() % 3 != 1)//add packet loss | 128 | /* if(rand() % 3 != 1)//add packet loss |
129 | { */ | 129 | { */ |
130 | if(LosslessUDP_handlepacket(data, length, ip_port)) { | 130 | if (LosslessUDP_handlepacket(data, length, ip_port)) |
131 | printpacket(data, length, ip_port); | 131 | printpacket(data, length, ip_port); |
132 | } else { | 132 | else |
133 | //printconnection(0); | 133 | printf("Received handled packet with length: %u\n", length); //printconnection(0); |
134 | printf("Received handled packet with length: %u\n", length); | 134 | |
135 | } | ||
136 | /* } */ | 135 | /* } */ |
137 | } | 136 | } |
138 | 137 | ||
@@ -151,7 +150,8 @@ int main(int argc, char *argv[]) | |||
151 | int read; | 150 | int read; |
152 | 151 | ||
153 | FILE *file = fopen(argv[3], "rb"); | 152 | FILE *file = fopen(argv[3], "rb"); |
154 | if ( file==NULL ){return 1;} | 153 | if (file == NULL) |
154 | return 1; | ||
155 | 155 | ||
156 | 156 | ||
157 | /* initialize networking */ | 157 | /* initialize networking */ |
@@ -166,14 +166,14 @@ int main(int argc, char *argv[]) | |||
166 | printip(serverip); | 166 | printip(serverip); |
167 | int connection = new_connection(serverip); | 167 | int connection = new_connection(serverip); |
168 | uint64_t timer = current_time(); | 168 | uint64_t timer = current_time(); |
169 | while(1) { | 169 | while (1) { |
170 | /* printconnection(connection); */ | 170 | /* printconnection(connection); */ |
171 | Lossless_UDP(); | 171 | Lossless_UDP(); |
172 | if(is_connected(connection) == 3) { | 172 | if (is_connected(connection) == 3) { |
173 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); | 173 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); |
174 | break; | 174 | break; |
175 | } | 175 | } |
176 | if(is_connected(connection) == 0) { | 176 | if (is_connected(connection) == 0) { |
177 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); | 177 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); |
178 | return 1; | 178 | return 1; |
179 | } | 179 | } |
@@ -185,19 +185,19 @@ int main(int argc, char *argv[]) | |||
185 | /*read first part of file */ | 185 | /*read first part of file */ |
186 | read = fread(buffer, 1, 512, file); | 186 | read = fread(buffer, 1, 512, file); |
187 | 187 | ||
188 | while(1) { | 188 | while (1) { |
189 | /* printconnection(connection); */ | 189 | /* printconnection(connection); */ |
190 | Lossless_UDP(); | 190 | Lossless_UDP(); |
191 | if(is_connected(connection) == 3) { | 191 | if (is_connected(connection) == 3) { |
192 | 192 | ||
193 | if(write_packet(connection, buffer, read)) { | 193 | if (write_packet(connection, buffer, read)) { |
194 | /* printf("Wrote data.\n"); */ | 194 | /* printf("Wrote data.\n"); */ |
195 | read = fread(buffer, 1, 512, file); | 195 | read = fread(buffer, 1, 512, file); |
196 | 196 | ||
197 | } | 197 | } |
198 | /* printf("%u\n", sendqueue(connection)); */ | 198 | /* printf("%u\n", sendqueue(connection)); */ |
199 | if(sendqueue(connection) == 0) { | 199 | if (sendqueue(connection) == 0) { |
200 | if(read == 0) { | 200 | if (read == 0) { |
201 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); | 201 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); |
202 | break; | 202 | break; |
203 | } | 203 | } |
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index a8097048..4b437f0e 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c | |||
@@ -45,12 +45,12 @@ | |||
45 | 45 | ||
46 | #define PORT 33445 | 46 | #define PORT 33445 |
47 | 47 | ||
48 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | 48 | void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) |
49 | { | 49 | { |
50 | uint32_t i; | 50 | uint32_t i; |
51 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 51 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
52 | printf("--------------------BEGIN-----------------------------\n"); | 52 | printf("--------------------BEGIN-----------------------------\n"); |
53 | for(i = 0; i < length; i++) { | 53 | for (i = 0; i < length; i++) { |
54 | if(data[i] < 16) | 54 | if(data[i] < 16) |
55 | printf("0"); | 55 | printf("0"); |
56 | printf("%hhX",data[i]); | 56 | printf("%hhX",data[i]); |
@@ -120,10 +120,10 @@ void Lossless_UDP() | |||
120 | IP_Port ip_port; | 120 | IP_Port ip_port; |
121 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 121 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
122 | uint32_t length; | 122 | uint32_t length; |
123 | while(receivepacket(&ip_port, data, &length) != -1) { | 123 | while (receivepacket(&ip_port, data, &length) != -1) { |
124 | //if(rand() % 3 != 1)//add packet loss | 124 | //if(rand() % 3 != 1)//add packet loss |
125 | //{ | 125 | //{ |
126 | if(LosslessUDP_handlepacket(data, length, ip_port)) { | 126 | if (LosslessUDP_handlepacket(data, length, ip_port)) { |
127 | printpacket(data, length, ip_port); | 127 | printpacket(data, length, ip_port); |
128 | } else { | 128 | } else { |
129 | //printconnection(0); | 129 | //printconnection(0); |
@@ -147,7 +147,8 @@ int main(int argc, char *argv[]) | |||
147 | int read; | 147 | int read; |
148 | 148 | ||
149 | FILE *file = fopen(argv[1], "wb"); | 149 | FILE *file = fopen(argv[1], "wb"); |
150 | if ( file==NULL ){return 1;} | 150 | if (file == NULL) |
151 | return 1; | ||
151 | 152 | ||
152 | 153 | ||
153 | //initialize networking | 154 | //initialize networking |
@@ -161,7 +162,7 @@ int main(int argc, char *argv[]) | |||
161 | uint64_t timer = current_time(); | 162 | uint64_t timer = current_time(); |
162 | 163 | ||
163 | 164 | ||
164 | while(1) { | 165 | while (1) { |
165 | Lossless_UDP(); | 166 | Lossless_UDP(); |
166 | connection = incoming_connection(); | 167 | connection = incoming_connection(); |
167 | if(connection != -1) { | 168 | if(connection != -1) { |
@@ -176,17 +177,16 @@ int main(int argc, char *argv[]) | |||
176 | 177 | ||
177 | timer = current_time(); | 178 | timer = current_time(); |
178 | 179 | ||
179 | while(1) { | 180 | while (1) { |
180 | //printconnection(0); | 181 | //printconnection(0); |
181 | Lossless_UDP(); | 182 | Lossless_UDP(); |
182 | if(is_connected(connection) >= 2) { | 183 | if (is_connected(connection) >= 2) { |
183 | kill_connection_in(connection, 3000000); | 184 | kill_connection_in(connection, 3000000); |
184 | read = read_packet(connection, buffer); | 185 | read = read_packet(connection, buffer); |
185 | if(read != 0) { | 186 | if (read != 0) { |
186 | // printf("Recieved data.\n"); | 187 | // printf("Recieved data.\n"); |
187 | if(!fwrite(buffer, read, 1, file)) { | 188 | if (!fwrite(buffer, read, 1, file)) |
188 | printf("file write error\n"); | 189 | printf("file write error\n"); |
189 | } | ||
190 | } | 190 | } |
191 | } | 191 | } |
192 | if(is_connected(connection) == 4) { | 192 | if(is_connected(connection) == 4) { |
diff --git a/testing/nTox.c b/testing/nTox.c index 3a5e9bb3..27654191 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -39,9 +39,9 @@ int nick_before; | |||
39 | void new_lines(char *line) | 39 | void new_lines(char *line) |
40 | { | 40 | { |
41 | int i; | 41 | int i; |
42 | for (i = HISTORY-1; i > 0; i--) { | 42 | for (i = HISTORY-1; i > 0; i--) |
43 | strcpy(lines[i],lines[i-1]); | 43 | strcpy(lines[i],lines[i-1]); |
44 | } | 44 | |
45 | strcpy(lines[0],line); | 45 | strcpy(lines[0],line); |
46 | do_refresh(); | 46 | do_refresh(); |
47 | } | 47 | } |
@@ -53,8 +53,7 @@ unsigned char * hex_string_to_bin(char hex_string[]) | |||
53 | unsigned char * val = malloc(len); | 53 | unsigned char * val = malloc(len); |
54 | char * pos = hex_string; | 54 | char * pos = hex_string; |
55 | int i=0; | 55 | int i=0; |
56 | while(i < len) | 56 | while(i < len) { |
57 | { | ||
58 | sscanf(pos,"%2hhx",&val[i]); | 57 | sscanf(pos,"%2hhx",&val[i]); |
59 | pos+=2; | 58 | pos+=2; |
60 | i++; | 59 | i++; |
@@ -71,17 +70,18 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
71 | if (line[1] == 'f') { // add friend command: /f ID | 70 | if (line[1] == 'f') { // add friend command: /f ID |
72 | int i; | 71 | int i; |
73 | char temp_id[128]; | 72 | char temp_id[128]; |
74 | for (i=0; i<128; i++) { | 73 | for (i=0; i<128; i++) |
75 | temp_id[i] = line[i+3]; | 74 | temp_id[i] = line[i+3]; |
76 | } | ||
77 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 75 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
78 | char numstring[100]; | 76 | char numstring[100]; |
79 | sprintf(numstring, "[i] added friend %d", num); | 77 | sprintf(numstring, "[i] added friend %d", num); |
80 | new_lines(numstring); | 78 | new_lines(numstring); |
81 | do_refresh(); | 79 | do_refresh(); |
82 | } else if (line[1] == 'd') { | 80 | } |
81 | else if (line[1] == 'd') { | ||
83 | doMessenger(); | 82 | doMessenger(); |
84 | } else if (line[1] == 'm') { //message command: /m friendnumber messsage | 83 | } |
84 | else if (line[1] == 'm') { //message command: /m friendnumber messsage | ||
85 | int i; | 85 | int i; |
86 | size_t len = strlen(line); | 86 | size_t len = strlen(line); |
87 | char numstring[len-3]; | 87 | char numstring[len-3]; |
@@ -91,15 +91,15 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
91 | numstring[i] = line[i+3]; | 91 | numstring[i] = line[i+3]; |
92 | } else { | 92 | } else { |
93 | int j; | 93 | int j; |
94 | for (j=i+1; j<len; j++) { | 94 | for (j=i+1; j<len; j++) |
95 | message[j-i-1] = line[j+3]; | 95 | message[j-i-1] = line[j+3]; |
96 | } | ||
97 | break; | 96 | break; |
98 | } | 97 | } |
99 | } | 98 | } |
100 | int num = atoi(numstring); | 99 | int num = atoi(numstring); |
101 | m_sendmessage(num, (uint8_t*) message, sizeof(message)); | 100 | m_sendmessage(num, (uint8_t*) message, sizeof(message)); |
102 | } else if (line[1] == 'n') { | 101 | } |
102 | else if (line[1] == 'n') { | ||
103 | uint8_t name[MAX_NAME_LENGTH]; | 103 | uint8_t name[MAX_NAME_LENGTH]; |
104 | int i = 0; | 104 | int i = 0; |
105 | size_t len = strlen(line); | 105 | size_t len = strlen(line); |
@@ -112,7 +112,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
112 | char numstring[100]; | 112 | char numstring[100]; |
113 | sprintf(numstring, "[i] changed nick to %s", (char*)name); | 113 | sprintf(numstring, "[i] changed nick to %s", (char*)name); |
114 | new_lines(numstring); | 114 | new_lines(numstring); |
115 | } else if (line[1] == 's') { | 115 | } |
116 | else if (line[1] == 's') { | ||
116 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 117 | uint8_t status[MAX_USERSTATUS_LENGTH]; |
117 | int i = 0; | 118 | int i = 0; |
118 | size_t len = strlen(line); | 119 | size_t len = strlen(line); |
@@ -125,7 +126,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
125 | char numstring[100]; | 126 | char numstring[100]; |
126 | sprintf(numstring, "[i] changed status to %s", (char*)status); | 127 | sprintf(numstring, "[i] changed status to %s", (char*)status); |
127 | new_lines(numstring); | 128 | new_lines(numstring); |
128 | } else if (line[1] == 'q') { //exit | 129 | } |
130 | else if (line[1] == 'q') { //exit | ||
129 | endwin(); | 131 | endwin(); |
130 | exit(EXIT_SUCCESS); | 132 | exit(EXIT_SUCCESS); |
131 | } | 133 | } |
@@ -139,7 +141,7 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) | |||
139 | int i = 0; | 141 | int i = 0; |
140 | strcpy(output,input); | 142 | strcpy(output,input); |
141 | size_t len = strlen(output); | 143 | size_t len = strlen(output); |
142 | for (i=line_width; i < len; i = i + line_width) { | 144 | for (i = line_width; i < len; i = i + line_width) { |
143 | while (output[i] != ' ' && i != 0) { | 145 | while (output[i] != ' ' && i != 0) { |
144 | i--; | 146 | i--; |
145 | } | 147 | } |
@@ -155,9 +157,8 @@ int count_lines(char *string) | |||
155 | int i; | 157 | int i; |
156 | int count = 1; | 158 | int count = 1; |
157 | for (i=0; i < len; i++) { | 159 | for (i=0; i < len; i++) { |
158 | if (string[i] == '\n') { | 160 | if (string[i] == '\n') |
159 | count++; | 161 | count++; |
160 | } | ||
161 | } | 162 | } |
162 | return count; | 163 | return count; |
163 | } | 164 | } |
@@ -196,11 +197,11 @@ void do_refresh() | |||
196 | refresh(); | 197 | refresh(); |
197 | } | 198 | } |
198 | 199 | ||
199 | void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) | 200 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) |
200 | { | 201 | { |
201 | new_lines("[i] received friend request"); | 202 | new_lines("[i] received friend request"); |
202 | do_refresh(); | 203 | do_refresh(); |
203 | if(memcmp(data , "Install Gentoo", sizeof("Install Gentoo")) == 0 ) | 204 | if (memcmp(data , "Install Gentoo", sizeof("Install Gentoo")) == 0) |
204 | //if the request contained the message of peace the person is obviously a friend so we add him. | 205 | //if the request contained the message of peace the person is obviously a friend so we add him. |
205 | { | 206 | { |
206 | new_lines("[i] friend request accepted"); | 207 | new_lines("[i] friend request accepted"); |
@@ -298,15 +299,14 @@ int main(int argc, char *argv[]) | |||
298 | uint32_t i; | 299 | uint32_t i; |
299 | for(i = 0; i < 32; i++) | 300 | for(i = 0; i < 32; i++) |
300 | { | 301 | { |
301 | if(self_public_key[i] < 16) { | 302 | if(self_public_key[i] < 16) |
302 | strcpy(idstring1[i],"0"); | 303 | strcpy(idstring1[i],"0"); |
303 | } else { | 304 | else |
304 | strcpy(idstring1[i], ""); | 305 | strcpy(idstring1[i], ""); |
305 | } | ||
306 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 306 | sprintf(idstring2[i], "%hhX",self_public_key[i]); |
307 | } | 307 | } |
308 | strcpy(idstring0,"[i] your ID: "); | 308 | strcpy(idstring0,"[i] your ID: "); |
309 | for(i=0; i<32; i++) { | 309 | for (i=0; i<32; i++) { |
310 | strcat(idstring0,idstring1[i]); | 310 | strcat(idstring0,idstring1[i]); |
311 | strcat(idstring0,idstring2[i]); | 311 | strcat(idstring0,idstring2[i]); |
312 | } | 312 | } |
@@ -320,11 +320,11 @@ int main(int argc, char *argv[]) | |||
320 | IP_Port bootstrap_ip_port; | 320 | IP_Port bootstrap_ip_port; |
321 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 321 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
322 | int resolved_address = resolve_addr(argv[1]); | 322 | int resolved_address = resolve_addr(argv[1]); |
323 | if (resolved_address != -1) { | 323 | if (resolved_address != -1) |
324 | bootstrap_ip_port.ip.i = resolved_address; | 324 | bootstrap_ip_port.ip.i = resolved_address; |
325 | } else { | 325 | else |
326 | exit(1); | 326 | exit(1); |
327 | } | 327 | |
328 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 328 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
329 | nodelay(stdscr, TRUE); | 329 | nodelay(stdscr, TRUE); |
330 | while(true) { | 330 | while(true) { |