Impl basic ws binary proto with data and execution state manipulation
This commit is contained in:
11
inc/proto/dial.h
Normal file
11
inc/proto/dial.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef __PROTO_DIAL_H__
|
||||
#define __PROTO_DIAL_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "context.h"
|
||||
|
||||
void broadcastClients(EmulContext* emulContext, uint8_t* msg, size_t msgLen);
|
||||
void dispatchOutgoingMessage(OutgoingBuffers* outBufs, ClientContext* client, uint8_t* msg, size_t msgLen);
|
||||
|
||||
#endif
|
||||
37
inc/proto/enums.h
Normal file
37
inc/proto/enums.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef __PROTO_ENUMS_H__
|
||||
#define __PROTO_ENUMS_H__
|
||||
|
||||
|
||||
#define REG_EVTYPE_CONNECT 1
|
||||
#define REG_EVTYPE_AUTH 2
|
||||
#define REG_EVTYPE_CLOSE 3
|
||||
|
||||
|
||||
|
||||
|
||||
#define PACKET_TYPE_CTRL 0b0001
|
||||
#define PACKET_TYPE_STREAM 0b0010
|
||||
#define PACKET_TYPE_MEM 0b0011
|
||||
|
||||
|
||||
#define CTRL_TYPE_EXEC 0b0001
|
||||
#define CTRL_TYPE_NOTIF_STATE 0b0010
|
||||
#define CTRL_TYPE_LIST_ORPHANED 0b1001
|
||||
#define CTRL_TYPE_LOAD_FAILED 0b1010
|
||||
#define CTRL_TYPE_SETUP_CONNECTION 0b1011
|
||||
|
||||
#define NOTIF_TYPE_EXEC 0b0000
|
||||
|
||||
#define STREAM_TYPE_REG_REQUEST 0b001
|
||||
#define STREAM_TYPE_REG_DISCARD 0b011
|
||||
#define STREAM_TYPE_REG_CONFIRM 0b101
|
||||
#define STREAM_TYPE_SEND 0b000
|
||||
|
||||
#define MEM_TYPE_READ_REQ 0b0000
|
||||
#define MEM_TYPE_READ_RESP 0b0001
|
||||
#define MEM_TYPE_WRITE_PUSH 0b0010
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //ifndef __PROTO_ENUMS_H__
|
||||
11
inc/proto/handlers.h
Normal file
11
inc/proto/handlers.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef __PROTO_HANDLERS_H__
|
||||
#define __PROTO_HANDLERS_H__
|
||||
|
||||
#include "events.h"
|
||||
|
||||
|
||||
void handleRegEvent(EmulContext* emulContext, ClientRegistrationEvent* ev);
|
||||
void handleAllClients(EmulContext* emulContext);
|
||||
|
||||
|
||||
#endif //ifndef __PROTO_HANDLERS_H__
|
||||
11
inc/proto/handlers/auth.h
Normal file
11
inc/proto/handlers/auth.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef __PROTO_HANDLERS_AUTH_H__
|
||||
#define __PROTO_HANDLERS_AUTH_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "context.h"
|
||||
|
||||
uint8_t handle_auth(ClientContext* cctx, ws_cli_conn_t client, const uint8_t* msg, uint64_t msgSize, int msgType);
|
||||
LinkedListEntry* disconnectDueTimeout(EmulContext* emulContext, LinkedListEntry* clientEntry);
|
||||
void handleOnClientAuthDone(ClientContext* ctx, EmulContext* emulContext);
|
||||
|
||||
#endif //ifndef __PROTO_HANDLERS_AUTH_H__
|
||||
10
inc/proto/handlers/control.h
Normal file
10
inc/proto/handlers/control.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __PROTO_HANDLERS_CONTROL_H__
|
||||
#define __PROTO_HANDLERS_CONTROL_H__
|
||||
|
||||
#include "proto/msg.h"
|
||||
#include "proto/dial.h"
|
||||
|
||||
void handleIncomingControlMessage(BaseMessage* msg, ClientContext* ctx, EmulContext* emulContext);
|
||||
|
||||
|
||||
#endif //ifndef __PROTO_HANDLERS_CONTROL_H__
|
||||
10
inc/proto/handlers/mem.h
Normal file
10
inc/proto/handlers/mem.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __PROTO_HANDLERS_MEM_H__
|
||||
#define __PROTO_HANDLERS_MEM_H__
|
||||
|
||||
#include "proto/msg.h"
|
||||
#include "proto/dial.h"
|
||||
|
||||
void handleIncomingMemMessage(BaseMessage* msg, ClientContext* ctx, EmulContext* emulContext);
|
||||
|
||||
#endif //ifndef __PROTO_HANDLERS_MEM_H__
|
||||
|
||||
12
inc/proto/handlers/stream.h
Normal file
12
inc/proto/handlers/stream.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __PROTO_HANDLERS_STREAM_H__
|
||||
#define __PROTO_HANDLERS_STREAM_H__
|
||||
|
||||
#include "proto/msg.h"
|
||||
#include "proto/dial.h"
|
||||
|
||||
|
||||
void unregisterClientStream(EmulContext* emulContext, ClientContext* ctx, uint32_t regId);
|
||||
void unregisterClientStreams(EmulContext* emulContext, ClientContext* ctx);
|
||||
void handleIncomingStreamMessage(BaseMessage* msg, ClientContext* ctx, EmulContext* emulContext);
|
||||
|
||||
#endif //ifndef __PROTO_HANDLERS_STREAM_H__
|
||||
10
inc/proto/handlers/ws.h
Normal file
10
inc/proto/handlers/ws.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __PROTO_HANDLERS_WS_H__
|
||||
#define __PROTO_HANDLERS_WS_H__
|
||||
|
||||
#include "wsServer/include/ws.h"
|
||||
|
||||
void onWsMessage(ws_cli_conn_t client, const unsigned char *msg, uint64_t size, int type);
|
||||
void onWsClose(ws_cli_conn_t client);
|
||||
void onWsOpen(ws_cli_conn_t client);
|
||||
|
||||
#endif //ifndef __PROTO_HANDLERS_WS_H__
|
||||
29
inc/proto/msg.h
Normal file
29
inc/proto/msg.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef __PROTO_MSG_H__
|
||||
#define __PROTO_MSG_H__
|
||||
|
||||
#include "wsServer/include/ws.h"
|
||||
#include <stdlib.h>
|
||||
#include "client.h"
|
||||
|
||||
typedef struct {
|
||||
ClientContext* client;
|
||||
uint8_t* msg;
|
||||
size_t msgLen;
|
||||
} OutgoingMessage;
|
||||
|
||||
typedef struct {
|
||||
uint64_t nonce;
|
||||
uint8_t packetType;
|
||||
uint8_t payloadHeader;
|
||||
const void* payload;
|
||||
size_t payloadLen;
|
||||
} BaseMessage;
|
||||
|
||||
BaseMessage* parseMessage(const uint8_t* bytes, size_t size);
|
||||
void fillHead(uint64_t nonce, uint8_t packetType, uint8_t payloadHeader, uint8_t* outmsg);
|
||||
uint8_t* createControlNotifyMessage(uint64_t nonce, uint64_t clockCounter, uint8_t newEmulState, size_t* lenOut);
|
||||
uint8_t* createDoneRegMessage(uint64_t nonce, uint8_t X, uint64_t devId, uint64_t segId, uint64_t startAddr, uint64_t segLength, uint32_t regId, size_t* lenOut);
|
||||
uint8_t* createStreamSegmentPush(uint8_t mode, uint32_t regId, uint64_t clockCounter, uint8_t* payload, size_t payloadLen, size_t* lenOut);
|
||||
uint8_t* createClientSetup(uint64_t nonce, ClientContext* ctx, size_t* lenOut);
|
||||
|
||||
#endif //ifndef __PROTO_MSG_H__
|
||||
30
inc/proto/pack.h
Normal file
30
inc/proto/pack.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef __PROTO_PACK_H__
|
||||
#define __PROTO_PACK_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
uint64_t decodeBytesToU64(const uint8_t* bytes);
|
||||
uint32_t decodeBytesToU32(const uint8_t* bytes);
|
||||
uint16_t decodeBytesToU16(const uint8_t* bytes);
|
||||
|
||||
|
||||
|
||||
void encodeUint8ToBytes(uint8_t num, uint8_t* tgt);
|
||||
void encodeUint16ToBytes(uint16_t num, uint8_t* tgt);
|
||||
void encodeUint32ToBytes(uint32_t num, uint8_t* tgt);
|
||||
void encodeUint64ToBytes(uint64_t num, uint8_t* tgt);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define encodeUintToBytes(num, tgt) _Generic((num), \
|
||||
uint8_t: encodeUint8ToBytes, \
|
||||
uint16_t: encodeUint16ToBytes, \
|
||||
uint32_t: encodeUint32ToBytes, \
|
||||
uint64_t: encodeUint64ToBytes \
|
||||
)(num, tgt)
|
||||
|
||||
#endif //ifndef __PROTO_PACK_H__
|
||||
Reference in New Issue
Block a user