summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-01-10 16:44:49 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-01-11 11:59:14 +0000
commit2fbed5b4c55ca92edbd436d4d0fa0a35506855c3 (patch)
treef9cee9b3eb13d47789ec0340a59ae105dce0a07a /toxcore/network.c
parentc84daff5413c45fb9e87fa5dbb7ae228564cfd2f (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.c39
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
391typedef struct {
392 packet_handler_callback function;
393 void *object;
394} Packet_Handler;
395
396struct 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
406Family net_family(const Networking_Core *net)
407{
408 return net->family;
409}
410
411uint16_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
844Networking_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. */
820void kill_networking(Networking_Core *net) 859void kill_networking(Networking_Core *net)
821{ 860{