mirror of
https://github.com/CPunch/Laika.git
synced 2025-09-25 19:30:22 +00:00
Lib: minor refactoring, more lcontent.c boilerplate
This commit is contained in:
@@ -22,4 +22,20 @@
|
||||
# define LAIKA_FORCEINLINE __forceinline
|
||||
#endif
|
||||
|
||||
#define MIN(a, b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
|
||||
#define MAX(a, b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
|
||||
struct sLaika_peer;
|
||||
struct sLaika_socket;
|
||||
struct sLaika_pollList;
|
||||
struct sLaika_task;
|
||||
struct sLaika_taskService;
|
||||
|
||||
#endif
|
@@ -1,7 +1,8 @@
|
||||
#ifndef LAIKA_CONTENT_H
|
||||
#define LAIKA_CONTENT_H
|
||||
|
||||
#include "lpeer.h"
|
||||
#include "laika.h"
|
||||
#include "lpacket.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
@@ -18,29 +19,31 @@ enum {
|
||||
|
||||
typedef uint8_t CONTENT_TYPE;
|
||||
typedef uint8_t CONTENT_ERRCODE;
|
||||
typedef uint16_t CONTENT_ID;
|
||||
|
||||
struct sLaika_content {
|
||||
struct sLaika_content *next;
|
||||
FILE *fd;
|
||||
uint32_t sz; /* content size */
|
||||
uint32_t processed;
|
||||
uint16_t id;
|
||||
CONTENT_ID id;
|
||||
CONTENT_TYPE type;
|
||||
struct sLaika_content *next;
|
||||
};
|
||||
|
||||
struct sLaika_contentContext {
|
||||
struct sLaika_peer *peer;
|
||||
struct sLaika_content *headIn; /* receiving from peer */
|
||||
struct sLaika_content *headOut; /* sending to peer */
|
||||
uint16_t nextID;
|
||||
CONTENT_ID nextID;
|
||||
};
|
||||
|
||||
void laikaF_initContext(struct sLaika_contentContext *context, struct sLaika_peer *peer);
|
||||
void laikaF_initContext(struct sLaika_contentContext *context);
|
||||
void laikaF_cleanContext(struct sLaika_contentContext *context);
|
||||
|
||||
int laikaF_newOutContent(struct sLaika_contentContext *context, FILE *fd, CONTENT_TYPE type);
|
||||
void laikaF_newInContent(struct sLaika_contentContext *context, uint16_t id, uint32_t sz, CONTENT_TYPE type);
|
||||
int laikaF_newOutContent(struct sLaika_peer *peer, FILE *fd, CONTENT_TYPE type);
|
||||
void laikaF_newInContent(struct sLaika_peer *peer, CONTENT_ID id, uint32_t sz, CONTENT_TYPE type);
|
||||
|
||||
void laikaF_poll(struct sLaika_contentContext *context);
|
||||
void laikaF_pollContent(struct sLaika_peer *peer);
|
||||
|
||||
void laikaF_handleContentChunk(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData);
|
||||
|
||||
#endif
|
@@ -6,6 +6,7 @@
|
||||
#include "lpacket.h"
|
||||
#include "lpolllist.h"
|
||||
#include "lsodium.h"
|
||||
#include "lcontent.h"
|
||||
|
||||
typedef enum {
|
||||
PEER_UNKNWN,
|
||||
@@ -30,7 +31,6 @@ typedef enum {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
struct sLaika_peer;
|
||||
typedef void (*PeerPktHandler)(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData);
|
||||
|
||||
struct sLaika_peerPacketInfo {
|
||||
@@ -43,6 +43,7 @@ struct sLaika_peerPacketInfo {
|
||||
|
||||
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 */
|
||||
struct sLaika_contentContext context;
|
||||
uint8_t peerPub[crypto_kx_PUBLICKEYBYTES]; /* connected peer's public key */
|
||||
uint8_t inKey[crypto_kx_SESSIONKEYBYTES], outKey[crypto_kx_SESSIONKEYBYTES];
|
||||
char hostname[LAIKA_HOSTNAME_LEN], inet[LAIKA_INET_LEN], ipv4[LAIKA_IPV4_LEN];
|
||||
|
@@ -51,6 +51,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "laika.h"
|
||||
#include "lsodium.h"
|
||||
|
||||
typedef enum {
|
||||
@@ -60,7 +61,6 @@ typedef enum {
|
||||
RAWSOCK_POLL
|
||||
} RAWSOCKCODE;
|
||||
|
||||
struct sLaika_socket;
|
||||
typedef bool (*pollEvent)(struct sLaika_socket *sock);
|
||||
typedef void (*pollFailEvent)(struct sLaika_socket *sock, void *uData);
|
||||
|
||||
|
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
struct sLaika_task;
|
||||
struct sLaika_taskService;
|
||||
#include "laika.h"
|
||||
|
||||
typedef void (*taskCallback)(struct sLaika_taskService *service, struct sLaika_task *task, clock_t currTick, void *uData);
|
||||
|
||||
struct sLaika_task {
|
||||
|
Reference in New Issue
Block a user