#ifndef DAT_NET_H
#define DAT_NET_H

#include <stdint.h>
#include <stddef.h>
#include <sys/socket.h>

#define DATNET_PORT 3282
#define DATNET_MAX_PACKET 1400
#define DATNET_TOPIC_BYTES 32
#define DATNET_PEERID_BYTES 32

typedef struct {
	int fd;
	struct sockaddr_storage addr;
	socklen_t addrlen;
	uint8_t id[DATNET_PEERID_BYTES];
} dat_peer_t;

typedef struct {
	int sock;
	uint8_t topic[DATNET_TOPIC_BYTES];
	uint8_t peerid[DATNET_PEERID_BYTES];
	void (*on_message)(dat_peer_t *peer, const uint8_t *msg, size_t len);
} datnet_t;

int datnet_init();
int datnet_bind();
int datnet_poll();
int datnet_send();
int datnet_close(datnet_t *net);

#endif /* DAT_NET_H */
