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 */
|
2022-02-10 22:56:40 +00:00
|
|
|
PEER_PANEL /* authorized peers can send commands to cnc */
|
2022-01-27 19:36:36 +00:00
|
|
|
} 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-02-03 22:25:49 +00:00
|
|
|
uint8_t peerPub[crypto_kx_PUBLICKEYBYTES]; /* connected peer's public key */
|
2022-02-04 02:51:32 +00:00
|
|
|
uint8_t inKey[crypto_kx_SESSIONKEYBYTES], outKey[crypto_kx_SESSIONKEYBYTES];
|
2022-02-10 22:56:40 +00:00
|
|
|
struct sLaika_pollList *pList; /* pollList we're activeList 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
|
|
|
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-02-04 02:51:32 +00:00
|
|
|
int outStart; /* index of pktID for out packet */
|
|
|
|
int inStart; /* index of pktID for in packet */
|
2022-01-25 02:50:14 +00:00
|
|
|
bool setPollOut; /* is EPOLLOUT/POLLOUT is set on sock's pollfd ? */
|
2022-02-04 02:51:32 +00:00
|
|
|
bool useSecure; /* if true, peer will transmit/receive encrypted data using inKey & outKey */
|
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-02-04 02:51:32 +00:00
|
|
|
void laikaS_setSecure(struct sLaika_peer *peer, bool flag);
|
|
|
|
void laikaS_startOutPacket(struct sLaika_peer *peer, uint8_t id);
|
|
|
|
int laikaS_endOutPacket(struct sLaika_peer *peer);
|
|
|
|
void laikaS_startInPacket(struct sLaika_peer *peer);
|
|
|
|
int laikaS_endInPacket(struct sLaika_peer *peer);
|
2022-01-24 03:28:16 +00:00
|
|
|
bool laikaS_handlePeerIn(struct sLaika_peer *peer);
|
|
|
|
bool laikaS_handlePeerOut(struct sLaika_peer *peer);
|
|
|
|
|
|
|
|
#endif
|