mirror of
https://github.com/logos-messaging/nim-sds.git
synced 2026-01-02 14:13:07 +00:00
restructuring
This commit is contained in:
parent
a1835cc678
commit
07329d70da
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,3 +5,5 @@ nph
|
|||||||
docs
|
docs
|
||||||
for_reference
|
for_reference
|
||||||
do_not_commit
|
do_not_commit
|
||||||
|
build/*
|
||||||
|
sds.nims
|
||||||
|
|||||||
19
Makefile
19
Makefile
@ -1,4 +1,19 @@
|
|||||||
.PHONY: libsds
|
.PHONY: libsds
|
||||||
|
|
||||||
libsds:
|
sds.nims:
|
||||||
nim c --app:lib --mm:refc --outdir:build library/libsds.nim
|
ln -s sds.nimble $@
|
||||||
|
|
||||||
|
deps: | sds.nims
|
||||||
|
|
||||||
|
|
||||||
|
STATIC ?= 0
|
||||||
|
|
||||||
|
libsds: deps
|
||||||
|
rm -f build/libwaku*
|
||||||
|
ifeq ($(STATIC), 1)
|
||||||
|
echo -e $(BUILD_MSG) "build/$@.a" && \
|
||||||
|
$(ENV_SCRIPT) nim libsdsStatic $(NIM_PARAMS) sds.nims
|
||||||
|
else
|
||||||
|
echo -e $(BUILD_MSG) "build/$@.so" && \
|
||||||
|
$(ENV_SCRIPT) nim libsdsDynamic $(NIM_PARAMS) sds.nims
|
||||||
|
endif
|
||||||
133
library/libsds.h
133
library/libsds.h
@ -1,56 +1,24 @@
|
|||||||
#ifndef BINDINGS_H
|
|
||||||
#define BINDINGS_H
|
|
||||||
|
|
||||||
#include <stddef.h> // For size_t
|
// Generated manually and inspired by the one generated by the Nim Compiler.
|
||||||
#include <stdint.h> // For standard integer types
|
// In order to see the header file generated by Nim just run `make libsds`
|
||||||
#include <stdbool.h> // For bool type
|
// from the root repo folder and the header should be created in
|
||||||
|
// nimcache/release/libsds/libsds.h
|
||||||
|
#ifndef __libsds__
|
||||||
|
#define __libsds__
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// The possible returned values for the functions that return int
|
||||||
|
#define RET_OK 0
|
||||||
|
#define RET_ERR 1
|
||||||
|
#define RET_MISSING_CALLBACK 2
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef void (*SdsCallBack) (int callerRet, const char* msg, size_t len, void* userData);
|
||||||
// Opaque struct declaration (handle replaces direct pointer usage)
|
|
||||||
typedef struct ReliabilityManager ReliabilityManager; // Keep forward declaration
|
|
||||||
|
|
||||||
// Define MessageID as a C string
|
|
||||||
typedef const char* MessageID; // Keep const for the typedef itself
|
|
||||||
|
|
||||||
// --- Result Types ---
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool is_ok;
|
|
||||||
char* error_message;
|
|
||||||
} CResult;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
CResult base_result;
|
|
||||||
unsigned char* message;
|
|
||||||
size_t message_len;
|
|
||||||
MessageID* missing_deps;
|
|
||||||
size_t missing_deps_count;
|
|
||||||
} CUnwrapResult;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
CResult base_result;
|
|
||||||
unsigned char* message;
|
|
||||||
size_t message_len;
|
|
||||||
} CWrapResult;
|
|
||||||
|
|
||||||
|
|
||||||
// --- Callback Function Pointer Types ---
|
|
||||||
|
|
||||||
// Define event types (enum or constants)
|
|
||||||
typedef enum {
|
|
||||||
EVENT_MESSAGE_READY = 1,
|
|
||||||
EVENT_MESSAGE_SENT = 2,
|
|
||||||
EVENT_MISSING_DEPENDENCIES = 3,
|
|
||||||
EVENT_PERIODIC_SYNC = 4
|
|
||||||
} CEventType;
|
|
||||||
|
|
||||||
// Single callback type for all events
|
|
||||||
// Nim will call this, passing the handle and event-specific data
|
|
||||||
typedef void (*CEventCallback)(void* handle, CEventType eventType, void* data1, void* data2, size_t data3);
|
|
||||||
|
|
||||||
|
|
||||||
// --- Core API Functions ---
|
// --- Core API Functions ---
|
||||||
@ -60,73 +28,16 @@ typedef void (*CEventCallback)(void* handle, CEventType eventType, void* data1,
|
|||||||
* @param channelId A unique identifier for the communication channel.
|
* @param channelId A unique identifier for the communication channel.
|
||||||
* @return An opaque handle (void*) representing the instance, or NULL on failure.
|
* @return An opaque handle (void*) representing the instance, or NULL on failure.
|
||||||
*/
|
*/
|
||||||
void* NewReliabilityManager(char* channelId);
|
void* sds_reliability_manager_new(char* channelId);
|
||||||
|
|
||||||
/**
|
/* void* waku_new(
|
||||||
* @brief Cleans up resources associated with a ReliabilityManager instance.
|
const char* configJson,
|
||||||
* @param handle The opaque handle (void*) of the instance to clean up.
|
WakuCallBack callback,
|
||||||
*/
|
void* userData); */
|
||||||
void CleanupReliabilityManager(void* handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Resets the ReliabilityManager instance.
|
|
||||||
* @param handle The opaque handle (void*) of the instance.
|
|
||||||
* @return CResult indicating success or failure.
|
|
||||||
*/
|
|
||||||
CResult ResetReliabilityManager(void* handle);
|
|
||||||
/**
|
|
||||||
* @brief Wraps an outgoing message.
|
|
||||||
* @param handle The opaque handle (void*) of the instance.
|
|
||||||
* @param message Pointer to the raw message content.
|
|
||||||
* @param messageLen Length of the raw message content.
|
|
||||||
* @param messageId A unique identifier for this message.
|
|
||||||
* @return CWrapResult containing the wrapped message or an error.
|
|
||||||
*/
|
|
||||||
CWrapResult WrapOutgoingMessage(void* handle, void* message, size_t messageLen, char* messageId);
|
|
||||||
/**
|
|
||||||
* @brief Unwraps a received message.
|
|
||||||
* @param handle The opaque handle (void*) of the instance.
|
|
||||||
* @param message Pointer to the received message data.
|
|
||||||
* @param messageLen Length of the received message data.
|
|
||||||
* @return CUnwrapResult containing the unwrapped content, missing dependencies, or an error.
|
|
||||||
*/
|
|
||||||
CUnwrapResult UnwrapReceivedMessage(void* handle, void* message, size_t messageLen);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Marks specified message dependencies as met.
|
|
||||||
* @param handle The opaque handle (void*) of the instance.
|
|
||||||
* @param messageIDs An array of message IDs to mark as met.
|
|
||||||
* @param count The number of message IDs in the array.
|
|
||||||
* @return CResult indicating success or failure.
|
|
||||||
*/
|
|
||||||
CResult MarkDependenciesMet(void* handle, char** messageIDs, size_t count); // Reverted to char**
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Registers callback functions.
|
|
||||||
* @param handle The opaque handle (void*) of the instance.
|
|
||||||
* @param messageReady Callback for when a message is ready.
|
|
||||||
* @param messageSent Callback for when an outgoing message is acknowledged.
|
|
||||||
* @param eventCallback The single callback function to handle all events.
|
|
||||||
* @param user_data A pointer to user-defined data (optional, could be managed in Go).
|
|
||||||
*/
|
|
||||||
void RegisterCallback(void* handle, CEventCallback eventCallback, void* user_data); // Renamed and simplified
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Starts the background periodic tasks.
|
|
||||||
* @param handle The opaque handle (void*) of the instance.
|
|
||||||
*/
|
|
||||||
void StartPeriodicTasks(void* handle);
|
|
||||||
|
|
||||||
|
|
||||||
// --- Memory Freeing Functions ---
|
|
||||||
|
|
||||||
void FreeCResultError(CResult result);
|
|
||||||
void FreeCWrapResult(CWrapResult result);
|
|
||||||
void FreeCUnwrapResult(CUnwrapResult result);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // BINDINGS_H
|
#endif /* __libsds__ */
|
||||||
@ -1,29 +0,0 @@
|
|||||||
# Package
|
|
||||||
version = "0.1.0"
|
|
||||||
author = "Waku Team"
|
|
||||||
description = "E2E Reliability Protocol API"
|
|
||||||
license = "MIT"
|
|
||||||
srcDir = "src"
|
|
||||||
|
|
||||||
# Dependencies
|
|
||||||
requires "nim >= 2.0.8"
|
|
||||||
requires "chronicles"
|
|
||||||
requires "libp2p"
|
|
||||||
|
|
||||||
# Tasks
|
|
||||||
task test, "Run the test suite":
|
|
||||||
exec "nim c -r tests/test_bloom.nim"
|
|
||||||
exec "nim c -r tests/test_reliability.nim"
|
|
||||||
|
|
||||||
task bindings, "Generate bindings":
|
|
||||||
proc compile(libName: string, flags = "") =
|
|
||||||
exec "nim c -f " & flags & " -d:release --app:lib --mm:arc --tlsEmulation:off --out:" & libName & " --outdir:build library/libsds.nim"
|
|
||||||
|
|
||||||
when defined(windows):
|
|
||||||
compile "reliability.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
compile "libsds.dylib.arm", "--cpu:arm64 -l:'-target arm64-apple-macos11' -t:'-target arm64-apple-macos11'"
|
|
||||||
compile "libsds.dylib.x64", "--cpu:amd64 -l:'-target x86_64-apple-macos10.12' -t:'-target x86_64-apple-macos10.12'"
|
|
||||||
exec "lipo build/libsds.dylib.arm build/libsds.dylib.x64 -output build/libsds.dylib -create"
|
|
||||||
else:
|
|
||||||
compile "libsds.so"
|
|
||||||
39
sds.nimble
Normal file
39
sds.nimble
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# Package
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "Waku Team"
|
||||||
|
description = "E2E Reliability Protocol API"
|
||||||
|
license = "MIT"
|
||||||
|
srcDir = "src"
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
requires "nim >= 2.0.8"
|
||||||
|
requires "chronicles"
|
||||||
|
requires "libp2p"
|
||||||
|
|
||||||
|
proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") =
|
||||||
|
if not dirExists "build":
|
||||||
|
mkDir "build"
|
||||||
|
# allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims"
|
||||||
|
var extra_params = params
|
||||||
|
for i in 2 ..< paramCount():
|
||||||
|
extra_params &= " " & paramStr(i)
|
||||||
|
if `type` == "static":
|
||||||
|
exec "nim c" & " --out:build/" & name &
|
||||||
|
".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header --undef:metrics --nimMainPrefix:libsds --skipParentCfg:on " &
|
||||||
|
extra_params & " " & srcDir & name & ".nim"
|
||||||
|
else:
|
||||||
|
exec "nim c" & " --out:build/" & name &
|
||||||
|
".so --threads:on --app:lib --opt:size --noMain --mm:refc --header --undef:metrics --nimMainPrefix:libsds --skipParentCfg:on " &
|
||||||
|
extra_params & " " & srcDir & name & ".nim"
|
||||||
|
|
||||||
|
# Tasks
|
||||||
|
task test, "Run the test suite":
|
||||||
|
exec "nim c -r tests/test_bloom.nim"
|
||||||
|
exec "nim c -r tests/test_reliability.nim"
|
||||||
|
|
||||||
|
task libsdsDynamic, "Generate bindings":
|
||||||
|
let name = "libsds"
|
||||||
|
buildLibrary name,
|
||||||
|
"library/",
|
||||||
|
"",
|
||||||
|
"dynamic"
|
||||||
@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -I${SRCDIR}/library
|
#cgo CFLAGS: -I${SRCDIR}/library
|
||||||
#cgo LDFLAGS: -L${SRCDIR}/build -lbindings
|
#cgo LDFLAGS: -L${SRCDIR}/build -llibsds
|
||||||
#cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/build
|
#cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/build
|
||||||
|
|
||||||
#include <stdlib.h> // For C.free
|
#include <stdlib.h> // For C.free
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user