diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-10 16:44:49 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-11 11:59:14 +0000 |
commit | 2fbed5b4c55ca92edbd436d4d0fa0a35506855c3 (patch) | |
tree | f9cee9b3eb13d47789ec0340a59ae105dce0a07a /toxcore/network.c | |
parent | c84daff5413c45fb9e87fa5dbb7ae228564cfd2f (diff) |
Move Networking_Core struct into the .c file.
To make it an abstract type everywhere except in network.c.
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index c3efba81..fb4748d4 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -388,6 +388,31 @@ static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, | |||
388 | } | 388 | } |
389 | } | 389 | } |
390 | 390 | ||
391 | typedef struct { | ||
392 | packet_handler_callback function; | ||
393 | void *object; | ||
394 | } Packet_Handler; | ||
395 | |||
396 | struct Networking_Core { | ||
397 | Logger *log; | ||
398 | Packet_Handler packethandlers[256]; | ||
399 | |||
400 | Family family; | ||
401 | uint16_t port; | ||
402 | /* Our UDP socket. */ | ||
403 | Socket sock; | ||
404 | }; | ||
405 | |||
406 | Family net_family(const Networking_Core *net) | ||
407 | { | ||
408 | return net->family; | ||
409 | } | ||
410 | |||
411 | uint16_t net_port(const Networking_Core *net) | ||
412 | { | ||
413 | return net->port; | ||
414 | } | ||
415 | |||
391 | /* Basic network functions: | 416 | /* Basic network functions: |
392 | * Function to send packet(data) of length length to ip_port. | 417 | * Function to send packet(data) of length length to ip_port. |
393 | */ | 418 | */ |
@@ -816,6 +841,20 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 | |||
816 | return NULL; | 841 | return NULL; |
817 | } | 842 | } |
818 | 843 | ||
844 | Networking_Core *new_networking_no_udp(Logger *log) | ||
845 | { | ||
846 | /* this is the easiest way to completely disable UDP without changing too much code. */ | ||
847 | Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core)); | ||
848 | |||
849 | if (net == NULL) { | ||
850 | return NULL; | ||
851 | } | ||
852 | |||
853 | net->log = log; | ||
854 | |||
855 | return net; | ||
856 | } | ||
857 | |||
819 | /* Function to cleanup networking stuff. */ | 858 | /* Function to cleanup networking stuff. */ |
820 | void kill_networking(Networking_Core *net) | 859 | void kill_networking(Networking_Core *net) |
821 | { | 860 | { |