mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
UDP can now be disabled.
new_messenger() now takes an options struct as an argument.
This commit is contained in:
parent
dbab15cf0c
commit
1298932deb
|
@ -335,7 +335,9 @@ int main(int argc, char *argv[])
|
|||
bad_id = hex_string_to_bin(bad_id_str);
|
||||
|
||||
/* IPv6 status from global define */
|
||||
m = new_messenger(TOX_ENABLE_IPV6_DEFAULT);
|
||||
Messenger_Options options = {0};
|
||||
options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
|
||||
m = new_messenger(&options);
|
||||
|
||||
/* setup a default friend and friendnum */
|
||||
if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0)
|
||||
|
|
|
@ -110,7 +110,9 @@ int main(int argc, char *argv[])
|
|||
exit(0);
|
||||
}
|
||||
|
||||
m = new_messenger(ipv6enabled);
|
||||
Messenger_Options options = {0};
|
||||
options.ipv6enabled = ipv6enabled;
|
||||
m = new_messenger(&options);
|
||||
|
||||
if ( !m ) {
|
||||
fputs("Failed to allocate messenger datastructure\n", stderr);
|
||||
|
|
|
@ -1827,16 +1827,21 @@ static int handle_new_connections(void *object, New_Connection *n_c)
|
|||
|
||||
|
||||
/* Run this at startup. */
|
||||
Messenger *new_messenger(uint8_t ipv6enabled)
|
||||
Messenger *new_messenger(Messenger_Options *options)
|
||||
{
|
||||
Messenger *m = calloc(1, sizeof(Messenger));
|
||||
|
||||
if ( ! m )
|
||||
return NULL;
|
||||
|
||||
IP ip;
|
||||
ip_init(&ip, ipv6enabled);
|
||||
m->net = new_networking(ip, TOX_PORT_DEFAULT);
|
||||
if (options->udp_disabled) {
|
||||
/* this is the easiest way to completely disable UDP without changing too much code. */
|
||||
m->net = calloc(1, sizeof(Networking_Core));
|
||||
} else {
|
||||
IP ip;
|
||||
ip_init(&ip, options->ipv6enabled);
|
||||
m->net = new_networking(ip, TOX_PORT_DEFAULT);
|
||||
}
|
||||
|
||||
if (m->net == NULL) {
|
||||
free(m);
|
||||
|
@ -1850,7 +1855,12 @@ Messenger *new_messenger(uint8_t ipv6enabled)
|
|||
free(m);
|
||||
return NULL;
|
||||
}
|
||||
m->net_crypto = new_net_crypto(m->dht, 0);
|
||||
|
||||
if (options->proxy_enabled) {
|
||||
m->net_crypto = new_net_crypto(m->dht, &options->proxy_info);
|
||||
} else {
|
||||
m->net_crypto = new_net_crypto(m->dht, 0);
|
||||
}
|
||||
|
||||
if (m->net_crypto == NULL) {
|
||||
kill_networking(m->net);
|
||||
|
@ -1876,6 +1886,7 @@ Messenger *new_messenger(uint8_t ipv6enabled)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
m->options = *options;
|
||||
friendreq_init(&(m->fr), m->onion_c);
|
||||
LANdiscovery_init(m->dht);
|
||||
set_nospam(&(m->fr), random_int());
|
||||
|
@ -2385,9 +2396,11 @@ void do_messenger(Messenger *m)
|
|||
{
|
||||
unix_time_update();
|
||||
|
||||
networking_poll(m->net);
|
||||
if (!m->options.udp_disabled) {
|
||||
networking_poll(m->net);
|
||||
do_DHT(m->dht);
|
||||
}
|
||||
|
||||
do_DHT(m->dht);
|
||||
do_net_crypto(m->net_crypto);
|
||||
do_onion_client(m->onion_c);
|
||||
do_friends(m);
|
||||
|
|
|
@ -67,6 +67,13 @@
|
|||
#define PACKET_ID_LOSSLESS_RANGE_START 160
|
||||
#define PACKET_ID_LOSSLESS_RANGE_SIZE 32
|
||||
|
||||
typedef struct {
|
||||
uint8_t ipv6enabled;
|
||||
uint8_t udp_disabled;
|
||||
uint8_t proxy_enabled;
|
||||
TCP_Proxy_Info proxy_info;
|
||||
} Messenger_Options;
|
||||
|
||||
/* Status definitions. */
|
||||
enum {
|
||||
NOFRIEND,
|
||||
|
@ -252,6 +259,7 @@ typedef struct Messenger {
|
|||
void (*msi_packet)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
||||
void *msi_packet_userdata;
|
||||
|
||||
Messenger_Options options;
|
||||
} Messenger;
|
||||
|
||||
/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
|
||||
|
@ -740,12 +748,12 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
|
|||
* return allocated instance of Messenger on success.
|
||||
* return 0 if there are problems.
|
||||
*/
|
||||
Messenger *new_messenger(uint8_t ipv6enabled);
|
||||
Messenger *new_messenger(Messenger_Options *options);
|
||||
|
||||
/* Run this before closing shop
|
||||
* Free all datastructures.
|
||||
*/
|
||||
void kill_messenger(Messenger *M);
|
||||
void kill_messenger(Messenger *m);
|
||||
|
||||
/* The main loop that needs to be run at least 20 times per second. */
|
||||
void do_messenger(Messenger *m);
|
||||
|
|
|
@ -283,6 +283,9 @@ uint64_t current_time_monotonic(void)
|
|||
*/
|
||||
int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint32_t length)
|
||||
{
|
||||
if (net->family == 0) /* Socket not initialized */
|
||||
return -1;
|
||||
|
||||
/* socket AF_INET, but target IP NOT: can't send */
|
||||
if ((net->family == AF_INET) && (ip_port.ip.family != AF_INET))
|
||||
return -1;
|
||||
|
@ -400,6 +403,9 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl
|
|||
|
||||
void networking_poll(Networking_Core *net)
|
||||
{
|
||||
if (net->family == 0) /* Socket not initialized */
|
||||
return;
|
||||
|
||||
unix_time_update();
|
||||
|
||||
IP_Port ip_port;
|
||||
|
@ -628,7 +634,9 @@ Networking_Core *new_networking(IP ip, uint16_t port)
|
|||
/* Function to cleanup networking stuff. */
|
||||
void kill_networking(Networking_Core *net)
|
||||
{
|
||||
kill_sock(net->sock);
|
||||
if (net->family != 0) /* Socket not initialized */
|
||||
kill_sock(net->sock);
|
||||
|
||||
free(net);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -818,7 +818,9 @@ uint32_t tox_do_interval(Tox *tox)
|
|||
Tox *tox_new(uint8_t ipv6enabled)
|
||||
{
|
||||
LOGGER_INIT(LOGGER_OUTPUT_FILE, LOGGER_LEVEL);
|
||||
return new_messenger(ipv6enabled);
|
||||
Messenger_Options options = {0};
|
||||
options.ipv6enabled = ipv6enabled;
|
||||
return new_messenger(&options);
|
||||
}
|
||||
|
||||
/* Run this before closing shop.
|
||||
|
|
Loading…
Reference in New Issue
Block a user