summaryrefslogtreecommitdiff
path: root/testing/Messenger_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/Messenger_test.c')
-rw-r--r--testing/Messenger_test.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index e85a85a2..14d9ca20 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -95,27 +95,40 @@ void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t len
95 95
96int main(int argc, char *argv[]) 96int main(int argc, char *argv[])
97{ 97{
98 if (argc < 4 && argc != 2) { 98 /* let user override default by cmdline */
99 printf("usage %s ip port public_key (of the DHT bootstrap node)\n or\n %s Save.bak\n", argv[0], argv[0]); 99 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
100 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
101 if (argvoffset < 0)
102 exit(1);
103
104 /* with optional --ipvx, now it can be 1-4 arguments... */
105 if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) {
106 printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]);
107 printf("or\n");
108 printf(" %s [--ipv4|--ipv6] Save.bak (to read Save.bak as state file)\n", argv[0], argv[0]);
100 exit(0); 109 exit(0);
101 } 110 }
102 111
103 m = initMessenger(); 112 m = initMessenger(ipv6enabled);
104 113
105 if ( !m ) { 114 if ( !m ) {
106 fputs("Failed to allocate messenger datastructure\n", stderr); 115 fputs("Failed to allocate messenger datastructure\n", stderr);
107 exit(0); 116 exit(0);
108 } 117 }
109 118
110 if (argc > 3) { 119 if (argc == argvoffset + 4) {
111 IP_Port bootstrap_ip_port; 120 uint16_t port = htons(atoi(argv[argvoffset + 2]));
112 bootstrap_ip_port.port = htons(atoi(argv[2])); 121 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
113 bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); 122 int res = DHT_bootstrap_ex(m->dht, argv[argvoffset + 1], ipv6enabled, port, bootstrap_key);
114 DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3])); 123 free(bootstrap_key);
124 if (!res) {
125 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
126 exit(1);
127 }
115 } else { 128 } else {
116 FILE *file = fopen(argv[1], "rb"); 129 FILE *file = fopen(argv[argvoffset + 1], "rb");
117
118 if ( file == NULL ) { 130 if ( file == NULL ) {
131 printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]);
119 return 1; 132 return 1;
120 } 133 }
121 134