tox.*, Messenger.*:

- initialisation: argument added to enable/disable ipv6 as socket

Messenger_test.c:
- initialisation: ipv4 hardcoded for now
- delegating IP resolution to DHT_bootstrap_ex()
This commit is contained in:
Coren[m] 2013-09-09 20:14:24 +02:00
parent a77253c79b
commit f932fd400c
5 changed files with 20 additions and 8 deletions

View File

@ -100,7 +100,8 @@ int main(int argc, char *argv[])
exit(0); exit(0);
} }
m = initMessenger(); /* IPv6: maybe allow from cmdline --ipv6? sticking to IPv4 for now */
m = initMessenger(0);
if ( !m ) { if ( !m ) {
fputs("Failed to allocate messenger datastructure\n", stderr); fputs("Failed to allocate messenger datastructure\n", stderr);
@ -108,10 +109,8 @@ int main(int argc, char *argv[])
} }
if (argc > 3) { if (argc > 3) {
IP_Port bootstrap_ip_port; uint16_t port = htons(atoi(argv[2]));
bootstrap_ip_port.port = htons(atoi(argv[2])); DHT_bootstrap_ex(m->dht, argv[1], port, hex_string_to_bin(argv[3]));
bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]);
DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
} else { } else {
FILE *file = fopen(argv[1], "rb"); FILE *file = fopen(argv[1], "rb");

View File

@ -650,15 +650,21 @@ static void LANdiscovery(Messenger *m)
} }
/* Run this at startup. */ /* Run this at startup. */
Messenger *initMessenger(void) Messenger *initMessenger(uint8_t ipv6enabled)
{ {
Messenger *m = calloc(1, sizeof(Messenger)); Messenger *m = calloc(1, sizeof(Messenger));
if ( ! m ) if ( ! m )
return NULL; return NULL;
#ifdef NETWORK_IP_PORT_IS_IPV6
IPAny ip;
memset(&ip, 0, sizeof(ip));
ip.family = ipv6enabled ? AF_INET6 : AF_INET;
#else
IP4 ip; IP4 ip;
ip.uint32 = 0; ip.uint32 = 0;
#endif
m->net = new_networking(ip, PORT); m->net = new_networking(ip, PORT);
if (m->net == NULL) { if (m->net == NULL) {

View File

@ -367,7 +367,7 @@ void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, in
* return allocated instance of Messenger on success. * return allocated instance of Messenger on success.
* return 0 if there are problems. * return 0 if there are problems.
*/ */
Messenger *initMessenger(void); Messenger *initMessenger(uint8_t ipv6enabled);
/* Run this before closing shop /* Run this before closing shop
* Free all datastructures. * Free all datastructures.

View File

@ -394,9 +394,13 @@ int tox_isconnected(void *tox)
* return allocated instance of tox on success. * return allocated instance of tox on success.
* return 0 if there are problems. * return 0 if there are problems.
*/ */
void *tox_new_ex(uint8_t ipv6enabled)
{
return initMessenger(ipv6enabled);
}
void *tox_new(void) void *tox_new(void)
{ {
return initMessenger(); return tox_new_ex(0);
} }
/* Run this before closing shop. /* Run this before closing shop.

View File

@ -50,6 +50,8 @@ typedef struct {
uint16_t padding; uint16_t padding;
} tox_IP_Port; } tox_IP_Port;
#define TOX_IP_IS_IPV6 0
/* Errors for m_addfriend /* Errors for m_addfriend
* FAERR - Friend Add Error * FAERR - Friend Add Error
*/ */
@ -307,6 +309,7 @@ int tox_isconnected(Tox *tox);
* return 0 if there are problems. * return 0 if there are problems.
*/ */
Tox *tox_new(void); Tox *tox_new(void);
Tox *tox_new_ex(uint8_t ipv6enabled);
/* Run this before closing shop. /* Run this before closing shop.
* Free all datastructures. */ * Free all datastructures. */