[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 01/01: initial commit
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 01/01: initial commit |
Date: |
Fri, 13 Jul 2018 18:15:30 +0200 |
This is an automated email from the git hooks/post-receive script.
lurchi pushed a commit to branch master
in repository gnunet-nim.
commit 9e663f0cca2bb6fabd2468e43d007f73de6a7c44
Author: lurchi <address@hidden>
AuthorDate: Thu Jul 12 22:06:07 2018 +0200
initial commit
---
asynccadet.nim | 3 +
gnunet_cadet_service.nim | 126 ++++++++++++++++++++++++++++++
gnunet_configuration_lib.nim | 30 ++++++++
gnunet_mq_lib.nim | 180 +++++++++++++++++++++++++++++++++++++++++++
gnunet_nim.nim | 90 ++++++++++++++++++++++
gnunet_scheduler_lib.nim | 83 ++++++++++++++++++++
gnunet_time_lib.nim | 29 +++++++
gnunet_types.nim | 40 ++++++++++
8 files changed, 581 insertions(+)
diff --git a/asynccadet.nim b/asynccadet.nim
new file mode 100644
index 0000000..43a22ab
--- /dev/null
+++ b/asynccadet.nim
@@ -0,0 +1,3 @@
+import gnunet_cadet_service
+
+#cadet_connect
diff --git a/gnunet_cadet_service.nim b/gnunet_cadet_service.nim
new file mode 100644
index 0000000..458e9a8
--- /dev/null
+++ b/gnunet_cadet_service.nim
@@ -0,0 +1,126 @@
+ {.deadCodeElim: on.}
+when defined(windows):
+ const
+ libname* = "libgnunetcadet.dll"
+elif defined(macosx):
+ const
+ libname* = "libgnunetcadet.dylib"
+else:
+ const
+ libname* = "libgnunetcadet.so"
+
+import
+ gnunet_types, gnunet_mq_lib, gnunet_configuration_lib
+
+
+const
+ GNUNET_CADET_VERSION* = 0x00000005
+
+
+type
+ GNUNET_CADET_Handle* {.bycopy.} = object
+
+
+
+type
+ GNUNET_CADET_Channel* {.bycopy.} = object
+
+
+
+type
+ GNUNET_CADET_Port* {.bycopy.} = object
+
+
+
+type
+ GNUNET_CADET_ChannelOption* {.size: sizeof(cint).} = enum
+ GNUNET_CADET_OPTION_DEFAULT = 0x00000000,
+ GNUNET_CADET_OPTION_NOBUFFER = 0x00000001,
+ GNUNET_CADET_OPTION_RELIABLE = 0x00000002,
+ GNUNET_CADET_OPTION_OUT_OF_ORDER = 0x00000004,
+ GNUNET_CADET_OPTION_PEER = 0x00000008
+
+
+
+type
+ GNUNET_CADET_ConnectEventHandler* = proc (cls: pointer;
+ channel: ptr GNUNET_CADET_Channel; source: ptr GNUNET_PeerIdentity):
pointer {.
+ cdecl.}
+
+
+type
+ GNUNET_CADET_DisconnectEventHandler* = proc (cls: pointer;
+ channel: ptr GNUNET_CADET_Channel) {.cdecl.}
+
+
+type
+ GNUNET_CADET_WindowSizeEventHandler* = proc (cls: pointer;
+ channel: ptr GNUNET_CADET_Channel; window_size: cint) {.cdecl.}
+
+
+proc GNUNET_CADET_connect*(cfg: ptr GNUNET_CONFIGURATION_Handle): ptr
GNUNET_CADET_Handle {.
+ cdecl, importc: "GNUNET_CADET_connect", dynlib: libname.}
+
+proc GNUNET_CADET_disconnect*(handle: ptr GNUNET_CADET_Handle) {.cdecl,
+ importc: "GNUNET_CADET_disconnect", dynlib: libname.}
+
+proc GNUNET_CADET_open_port*(h: ptr GNUNET_CADET_Handle; port: ptr
GNUNET_HashCode;
+ connects: GNUNET_CADET_ConnectEventHandler;
+ connects_cls: pointer; window_changes:
GNUNET_CADET_WindowSizeEventHandler;
+ disconnects: GNUNET_CADET_DisconnectEventHandler;
+ handlers: ptr GNUNET_MQ_MessageHandler): ptr
GNUNET_CADET_Port {.
+ cdecl, importc: "GNUNET_CADET_open_port", dynlib: libname.}
+
+proc GNUNET_CADET_close_port*(p: ptr GNUNET_CADET_Port) {.cdecl,
+ importc: "GNUNET_CADET_close_port", dynlib: libname.}
+
+proc GNUNET_CADET_channel_create*(h: ptr GNUNET_CADET_Handle; channel_cls:
pointer;
+ destination: ptr GNUNET_PeerIdentity;
+ port: ptr GNUNET_HashCode;
+ options: GNUNET_CADET_ChannelOption;
+ window_changes: GNUNET_CADET_WindowSizeEventHandler; disconnects:
GNUNET_CADET_DisconnectEventHandler;
+ handlers: ptr GNUNET_MQ_MessageHandler): ptr
GNUNET_CADET_Channel {.
+ cdecl, importc: "GNUNET_CADET_channel_create", dynlib: libname.}
+
+proc GNUNET_CADET_channel_destroy*(channel: ptr GNUNET_CADET_Channel) {.cdecl,
+ importc: "GNUNET_CADET_channel_destroy", dynlib: libname.}
+
+proc GNUNET_CADET_get_mq*(channel: ptr GNUNET_CADET_Channel): ptr
GNUNET_MQ_Handle {.
+ cdecl, importc: "GNUNET_CADET_get_mq", dynlib: libname.}
+
+proc GNUNET_CADET_receive_done*(channel: ptr GNUNET_CADET_Channel) {.cdecl,
+ importc: "GNUNET_CADET_receive_done", dynlib: libname.}
+
+proc GC_u2h*(port: uint32): ptr GNUNET_HashCode {.cdecl, importc: "GC_u2h",
+ dynlib: libname.}
+
+type
+ GNUNET_CADET_ChannelInfo* {.bycopy.} = object {.union.}
+ yes_no*: cint
+ peer*: GNUNET_PeerIdentity
+
+
+
+type
+ GNUNET_CADET_PeersCB* = proc (cls: pointer; peer: ptr GNUNET_PeerIdentity;
+ tunnel: cint; n_paths: cuint; best_path: cuint)
{.cdecl.}
+
+
+type
+ GNUNET_CADET_PeerCB* = proc (cls: pointer; peer: ptr GNUNET_PeerIdentity;
+ tunnel: cint; neighbor: cint; n_paths: cuint;
+ paths: ptr GNUNET_PeerIdentity; offset: cint;
+ finished_with_paths: cint) {.cdecl.}
+
+
+proc GNUNET_CADET_get_peers*(h: ptr GNUNET_CADET_Handle;
+ callback: GNUNET_CADET_PeersCB; callback_cls:
pointer): cint {.
+ cdecl, importc: "GNUNET_CADET_get_peers", dynlib: libname.}
+
+proc GNUNET_CADET_get_peers_cancel*(h: ptr GNUNET_CADET_Handle): pointer
{.cdecl,
+ importc: "GNUNET_CADET_get_peers_cancel", dynlib: libname.}
+
+proc GNUNET_CADET_get_peer*(h: ptr GNUNET_CADET_Handle; id: ptr
GNUNET_PeerIdentity;
+ callback: GNUNET_CADET_PeerCB; callback_cls:
pointer): cint {.
+ cdecl, importc: "GNUNET_CADET_get_peer", dynlib: libname.}
+
diff --git a/gnunet_configuration_lib.nim b/gnunet_configuration_lib.nim
new file mode 100644
index 0000000..210c892
--- /dev/null
+++ b/gnunet_configuration_lib.nim
@@ -0,0 +1,30 @@
+ {.deadCodeElim: on.}
+when defined(windows):
+ const
+ libname* = "libgnunetutil.dll"
+elif defined(macosx):
+ const
+ libname* = "libgnunetutil.dylib"
+else:
+ const
+ libname* = "libgnunetutil.so"
+
+import
+ gnunet_time_lib
+
+
+type
+ GNUNET_CONFIGURATION_Handle* {.bycopy.} = object
+
+
+
+proc GNUNET_CONFIGURATION_create*(): ptr GNUNET_CONFIGURATION_Handle {.cdecl,
+ importc: "GNUNET_CONFIGURATION_create", dynlib: libname.}
+
+proc GNUNET_CONFIGURATION_destroy*(cfg: ptr GNUNET_CONFIGURATION_Handle)
{.cdecl,
+ importc: "GNUNET_CONFIGURATION_destroy", dynlib: libname.}
+
+proc GNUNET_CONFIGURATION_load*(cfg: ptr GNUNET_CONFIGURATION_Handle;
+ filename: cstring): cint {.cdecl,
+ importc: "GNUNET_CONFIGURATION_load", dynlib: libname.}
+
diff --git a/gnunet_mq_lib.nim b/gnunet_mq_lib.nim
new file mode 100644
index 0000000..45950c5
--- /dev/null
+++ b/gnunet_mq_lib.nim
@@ -0,0 +1,180 @@
+ {.deadCodeElim: on.}
+when defined(windows):
+ const
+ libname* = "libgnunetutil.dll"
+elif defined(macosx):
+ const
+ libname* = "libgnunetutil.dylib"
+else:
+ const
+ libname* = "libgnunetutil.so"
+
+
+import gnunet_types, gnunet_scheduler_lib, gnunet_configuration_lib
+
+
+type
+ GNUNET_MQ_Envelope* {.bycopy.} = object
+
+
+
+proc GNUNET_MQ_env_get_msg*(env: ptr GNUNET_MQ_Envelope): ptr
GNUNET_MessageHeader {.
+ cdecl, importc: "GNUNET_MQ_env_get_msg", dynlib: libname.}
+
+proc GNUNET_MQ_env_next*(env: ptr GNUNET_MQ_Envelope): ptr GNUNET_MQ_Envelope
{.cdecl,
+ importc: "GNUNET_MQ_env_next", dynlib: libname.}
+
+type
+ GNUNET_MQ_Handle* {.bycopy.} = object
+
+
+
+type
+ GNUNET_MQ_Error* {.size: sizeof(cint).} = enum
+ GNUNET_MQ_ERROR_READ = 1, GNUNET_MQ_ERROR_WRITE = 2,
GNUNET_MQ_ERROR_TIMEOUT = 4,
+ GNUNET_MQ_ERROR_MALFORMED = 8, GNUNET_MQ_ERROR_NO_MATCH = 16
+
+
+
+type
+ GNUNET_MQ_MessageCallback* = proc (cls: pointer; msg: ptr
GNUNET_MessageHeader) {.
+ cdecl.}
+
+
+type
+ GNUNET_MQ_MessageValidationCallback* = proc (cls: pointer;
+ msg: ptr GNUNET_MessageHeader): cint {.cdecl.}
+
+
+type
+ GNUNET_MQ_SendImpl* = proc (mq: ptr GNUNET_MQ_Handle; msg: ptr
GNUNET_MessageHeader;
+ impl_state: pointer) {.cdecl.}
+
+
+type
+ GNUNET_MQ_DestroyImpl* = proc (mq: ptr GNUNET_MQ_Handle; impl_state:
pointer) {.cdecl.}
+
+
+type
+ GNUNET_MQ_CancelImpl* = proc (mq: ptr GNUNET_MQ_Handle; impl_state: pointer)
{.cdecl.}
+
+
+type
+ GNUNET_MQ_ErrorHandler* = proc (cls: pointer; error: GNUNET_MQ_Error)
{.cdecl.}
+
+
+proc GNUNET_MQ_dll_insert_tail*(env_head: ptr ptr GNUNET_MQ_Envelope;
+ env_tail: ptr ptr GNUNET_MQ_Envelope;
+ env: ptr GNUNET_MQ_Envelope) {.cdecl,
+ importc: "GNUNET_MQ_dll_insert_tail", dynlib: libname.}
+
+proc GNUNET_MQ_dll_remove*(env_head: ptr ptr GNUNET_MQ_Envelope;
+ env_tail: ptr ptr GNUNET_MQ_Envelope;
+ env: ptr GNUNET_MQ_Envelope) {.cdecl,
+ importc: "GNUNET_MQ_dll_remove", dynlib: libname.}
+
+type
+ GNUNET_MQ_MessageHandler* {.bycopy.} = object
+ mv*: GNUNET_MQ_MessageValidationCallback
+ cb*: GNUNET_MQ_MessageCallback
+ cls*: pointer
+ `type`*: uint16
+ expected_size*: uint16
+
+proc GNUNET_MQ_copy_handlers*(handlers: ptr GNUNET_MQ_MessageHandler): ptr
GNUNET_MQ_MessageHandler {.
+ cdecl, importc: "GNUNET_MQ_copy_handlers", dynlib: libname.}
+
+proc GNUNET_MQ_copy_handlers2*(handlers: ptr GNUNET_MQ_MessageHandler;
+ agpl_handler: GNUNET_MQ_MessageCallback;
+ agpl_cls: pointer): ptr GNUNET_MQ_MessageHandler
{.
+ cdecl, importc: "GNUNET_MQ_copy_handlers2", dynlib: libname.}
+
+proc GNUNET_MQ_count_handlers*(handlers: ptr GNUNET_MQ_MessageHandler): cuint
{.
+ cdecl, importc: "GNUNET_MQ_count_handlers", dynlib: libname.}
+
+proc GNUNET_MQ_msg_copy*(hdr: ptr GNUNET_MessageHeader): ptr
GNUNET_MQ_Envelope {.
+ cdecl, importc: "GNUNET_MQ_msg_copy", dynlib: libname.}
+
+proc GNUNET_MQ_discard*(mqm: ptr GNUNET_MQ_Envelope) {.cdecl,
+ importc: "GNUNET_MQ_discard", dynlib: libname.}
+
+proc GNUNET_MQ_get_current_envelope*(mq: ptr GNUNET_MQ_Handle): ptr
GNUNET_MQ_Envelope {.
+ cdecl, importc: "GNUNET_MQ_get_current_envelope", dynlib: libname.}
+
+proc GNUNET_MQ_env_copy*(env: ptr GNUNET_MQ_Envelope): ptr GNUNET_MQ_Envelope
{.cdecl,
+ importc: "GNUNET_MQ_env_copy", dynlib: libname.}
+
+proc GNUNET_MQ_get_last_envelope*(mq: ptr GNUNET_MQ_Handle): ptr
GNUNET_MQ_Envelope {.
+ cdecl, importc: "GNUNET_MQ_get_last_envelope", dynlib: libname.}
+
+proc GNUNET_MQ_env_set_options*(env: ptr GNUNET_MQ_Envelope; flags: uint64;
+ extra: pointer) {.cdecl,
+ importc: "GNUNET_MQ_env_set_options", dynlib: libname.}
+
+proc GNUNET_MQ_env_get_options*(env: ptr GNUNET_MQ_Envelope; flags: ptr
uint64): pointer {.
+ cdecl, importc: "GNUNET_MQ_env_get_options", dynlib: libname.}
+
+proc GNUNET_MQ_unsent_head*(mq: ptr GNUNET_MQ_Handle): ptr GNUNET_MQ_Envelope
{.cdecl,
+ importc: "GNUNET_MQ_unsent_head", dynlib: libname.}
+
+proc GNUNET_MQ_set_options*(mq: ptr GNUNET_MQ_Handle; flags: uint64; extra:
pointer) {.
+ cdecl, importc: "GNUNET_MQ_set_options", dynlib: libname.}
+
+proc GNUNET_MQ_get_length*(mq: ptr GNUNET_MQ_Handle): cuint {.cdecl,
+ importc: "GNUNET_MQ_get_length", dynlib: libname.}
+
+proc GNUNET_MQ_send*(mq: ptr GNUNET_MQ_Handle; ev: ptr GNUNET_MQ_Envelope)
{.cdecl,
+ importc: "GNUNET_MQ_send", dynlib: libname.}
+
+proc GNUNET_MQ_send_copy*(mq: ptr GNUNET_MQ_Handle; ev: ptr
GNUNET_MQ_Envelope) {.
+ cdecl, importc: "GNUNET_MQ_send_copy", dynlib: libname.}
+
+proc GNUNET_MQ_send_cancel*(ev: ptr GNUNET_MQ_Envelope) {.cdecl,
+ importc: "GNUNET_MQ_send_cancel", dynlib: libname.}
+
+proc GNUNET_MQ_assoc_add*(mq: ptr GNUNET_MQ_Handle; assoc_data: pointer):
uint32 {.
+ cdecl, importc: "GNUNET_MQ_assoc_add", dynlib: libname.}
+
+proc GNUNET_MQ_assoc_get*(mq: ptr GNUNET_MQ_Handle; request_id: uint32):
pointer {.
+ cdecl, importc: "GNUNET_MQ_assoc_get", dynlib: libname.}
+
+proc GNUNET_MQ_assoc_remove*(mq: ptr GNUNET_MQ_Handle; request_id: uint32):
pointer {.
+ cdecl, importc: "GNUNET_MQ_assoc_remove", dynlib: libname.}
+
+proc GNUNET_MQ_notify_sent*(ev: ptr GNUNET_MQ_Envelope;
+ cb: GNUNET_SCHEDULER_TaskCallback; cb_cls: pointer)
{.
+ cdecl, importc: "GNUNET_MQ_notify_sent", dynlib: libname.}
+
+proc GNUNET_MQ_destroy*(mq: ptr GNUNET_MQ_Handle) {.cdecl,
+ importc: "GNUNET_MQ_destroy", dynlib: libname.}
+
+type
+ GNUNET_MQ_DestroyNotificationHandle* {.bycopy.} = object
+
+
+
+proc GNUNET_MQ_destroy_notify*(mq: ptr GNUNET_MQ_Handle;
+ cb: GNUNET_SCHEDULER_TaskCallback; cb_cls:
pointer): ptr GNUNET_MQ_DestroyNotificationHandle {.
+ cdecl, importc: "GNUNET_MQ_destroy_notify", dynlib: libname.}
+
+proc GNUNET_MQ_destroy_notify_cancel*(dnh: ptr
GNUNET_MQ_DestroyNotificationHandle) {.
+ cdecl, importc: "GNUNET_MQ_destroy_notify_cancel", dynlib: libname.}
+
+proc GNUNET_MQ_inject_message*(mq: ptr GNUNET_MQ_Handle;
+ mh: ptr GNUNET_MessageHeader) {.cdecl,
+ importc: "GNUNET_MQ_inject_message", dynlib: libname.}
+
+proc GNUNET_MQ_inject_error*(mq: ptr GNUNET_MQ_Handle; error: GNUNET_MQ_Error)
{.
+ cdecl, importc: "GNUNET_MQ_inject_error", dynlib: libname.}
+
+proc GNUNET_MQ_impl_send_continue*(mq: ptr GNUNET_MQ_Handle) {.cdecl,
+ importc: "GNUNET_MQ_impl_send_continue", dynlib: libname.}
+
+proc GNUNET_MQ_impl_send_in_flight*(mq: ptr GNUNET_MQ_Handle) {.cdecl,
+ importc: "GNUNET_MQ_impl_send_in_flight", dynlib: libname.}
+
+proc GNUNET_MQ_impl_state*(mq: ptr GNUNET_MQ_Handle): pointer {.cdecl,
+ importc: "GNUNET_MQ_impl_state", dynlib: libname.}
+
+proc GNUNET_MQ_impl_current*(mq: ptr GNUNET_MQ_Handle): ptr
GNUNET_MessageHeader {.
+ cdecl, importc: "GNUNET_MQ_impl_current", dynlib: libname.}
diff --git a/gnunet_nim.nim b/gnunet_nim.nim
new file mode 100644
index 0000000..bcb9be3
--- /dev/null
+++ b/gnunet_nim.nim
@@ -0,0 +1,90 @@
+import gnunet_types
+import gnunet_scheduler_lib
+import gnunet_time_lib
+import gnunet_configuration_lib
+import asyncdispatch
+import asynccadet
+import logging
+import tables
+
+type Scheduler = object
+ timeoutUs: uint64
+ gnunetTasks: Table[ptr GNUNET_SCHEDULER_Task, ptr GNUNET_SCHEDULER_FdInfo]
+
+proc microsecondsUntilTimeout(scheduler: Scheduler): int =
+ ## get the duration until timeout in microseconds
+ let now = GNUNET_TIME_absolute_get()
+ if scheduler.timeoutUs < now.abs_value_us:
+ return 0
+ return int(scheduler.timeoutUs - now.abs_value_us)
+
+proc millisecondsUntilTimeout(scheduler: Scheduler): int =
+ ## get the duration until timeout in milliseconds
+ return scheduler.microsecondsUntilTimeout() div 1_000
+
+proc schedulerAdd(cls: pointer,
+ task: ptr GNUNET_SCHEDULER_Task,
+ fdi: ptr GNUNET_SCHEDULER_FdInfo): cint {.cdecl.} =
+ ## callback allowing GNUnet to add a file descriptor to the event loop
+ type AddProc = proc(fd: AsyncFD, cb: proc(fd: AsyncFD): bool)
+ var scheduler = cast[ptr Scheduler](cls)
+ let fd = AsyncFD(fdi.sock)
+ proc addByInterest(interest: GNUNET_SCHEDULER_EventType, addProc: AddProc) :
bool =
+ result = false
+ if (cast[int](fdi.et) and cast[int](interest)) != 0:
+ result = true
+ if not getGlobalDispatcher().contains(fd):
+ register(fd)
+ proc callback(fd: AsyncFD): bool =
+ result = true
+ fdi.et = interest
+ GNUNET_SCHEDULER_task_ready(task, fdi)
+ addProc(fd, callback)
+ if addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_IN, addRead)
or
+ addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_OUT,
addWrite):
+ scheduler.gnunetTasks.add(task, fdi)
+ return GNUNET_OK
+ error("Cannot add file descriptor because the event type is not supported")
+ return GNUNET_SYSERR
+
+proc schedulerDelete(cls: pointer,
+ task: ptr GNUNET_SCHEDULER_Task): cint {.cdecl.} =
+ ## callback allowing GNUnet to delete a file descriptor from the event loop
+ var scheduler = cast[ptr Scheduler](cls)
+ var fdi: ptr GNUNET_SCHEDULER_FdInfo
+ if scheduler.gnunetTasks.take(task, fdi):
+ unregister(AsyncFD(fdi.sock))
+ return GNUNET_OK
+ error("Cannot remove file descriptor because it has not been added or is
already gone")
+ return GNUNET_SYSERR
+
+proc schedulerSetWakeup(cls: pointer,
+ dt: GNUNET_TIME_Absolute) {.cdecl.} =
+ ## callback allowing GNUnet to set a new wakeup time
+ var scheduler = cast[ptr Scheduler](cls)
+ scheduler.timeoutUs = dt.abs_value_us
+
+proc main() =
+ var scheduler = Scheduler(
+ timeoutUs: GNUNET_TIME_absolute_get_forever().abs_value_us,
+ gnunetTasks: initTable[ptr GNUNET_SCHEDULER_Task, ptr
GNUNET_SCHEDULER_FdInfo]()
+ )
+ var configHandle = GNUNET_CONFIGURATION_create()
+ assert(GNUNET_SYSERR != GNUNET_CONFIGURATION_load(configHandle,
"gnunet.conf"))
+ var driver = GNUNET_SCHEDULER_Driver(cls: addr scheduler,
+ add: schedulerAdd,
+ del: schedulerDelete,
+ set_wakeup: schedulerSetWakeup)
+ let schedulerHandle = GNUNET_SCHEDULER_driver_init(addr driver)
+ try:
+ while true:
+ poll(scheduler.millisecondsUntilTimeout())
+ var work_result = GNUNET_SCHEDULER_do_work(schedulerHandle)
+ echo "work_result: ", work_result
+ except ValueError:
+ discard
+ GNUNET_SCHEDULER_driver_done(schedulerHandle)
+ GNUNET_CONFIGURATION_destroy(configHandle)
+ echo "quitting"
+
+main()
diff --git a/gnunet_scheduler_lib.nim b/gnunet_scheduler_lib.nim
new file mode 100644
index 0000000..ecd54ac
--- /dev/null
+++ b/gnunet_scheduler_lib.nim
@@ -0,0 +1,83 @@
+ {.deadCodeElim: on.}
+when defined(windows):
+ const
+ libname* = "libgnunetutil.dll"
+elif defined(macosx):
+ const
+ libname* = "libgnunetutil.dylib"
+else:
+ const
+ libname* = "libgnunetutil.so"
+
+
+type
+ GNUNET_SCHEDULER_Task* {.bycopy.} = object
+
+
+
+type
+ GNUNET_SCHEDULER_Reason* {.size: sizeof(cint).} = enum
+ GNUNET_SCHEDULER_REASON_NONE = 0, GNUNET_SCHEDULER_REASON_STARTUP = 1,
+ GNUNET_SCHEDULER_REASON_SHUTDOWN = 2, GNUNET_SCHEDULER_REASON_TIMEOUT = 4,
+ GNUNET_SCHEDULER_REASON_READ_READY = 8,
+ GNUNET_SCHEDULER_REASON_WRITE_READY = 16,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE = 32
+
+
+import
+ gnunet_types, gnunet_time_lib
+
+
+type
+ GNUNET_SCHEDULER_EventType* {.size: sizeof(cint).} = enum
+ GNUNET_SCHEDULER_ET_NONE = 0, GNUNET_SCHEDULER_ET_IN = 1,
+ GNUNET_SCHEDULER_ET_OUT = 2, GNUNET_SCHEDULER_ET_HUP = 4,
+ GNUNET_SCHEDULER_ET_ERR = 8, GNUNET_SCHEDULER_ET_PRI = 16,
+ GNUNET_SCHEDULER_ET_NVAL = 32
+
+
+
+type
+ GNUNET_SCHEDULER_FdInfo* {.bycopy.} = object
+ fd*: ptr GNUNET_NETWORK_Handle
+ fh*: ptr GNUNET_DISK_FileHandle
+ et*: GNUNET_SCHEDULER_EventType
+ sock*: cint
+
+
+
+proc GNUNET_SCHEDULER_task_ready*(task: ptr GNUNET_SCHEDULER_Task;
+ fdi: ptr GNUNET_SCHEDULER_FdInfo) {.cdecl,
+ importc: "GNUNET_SCHEDULER_task_ready", dynlib: libname.}
+
+type
+ GNUNET_SCHEDULER_Handle* {.bycopy.} = object
+
+
+
+proc GNUNET_SCHEDULER_do_work*(sh: ptr GNUNET_SCHEDULER_Handle): cint {.cdecl,
+ importc: "GNUNET_SCHEDULER_do_work", dynlib: libname.}
+
+type
+ GNUNET_SCHEDULER_Driver* {.bycopy.} = object
+ cls*: pointer
+ add*: proc (cls: pointer; task: ptr GNUNET_SCHEDULER_Task;
+ fdi: ptr GNUNET_SCHEDULER_FdInfo): cint {.cdecl.}
+ del*: proc (cls: pointer; task: ptr GNUNET_SCHEDULER_Task): cint {.cdecl.}
+ set_wakeup*: proc (cls: pointer; dt: GNUNET_TIME_Absolute) {.cdecl.}
+
+
+
+type
+ GNUNET_SCHEDULER_TaskCallback* = proc (cls: pointer) {.cdecl.}
+
+
+proc GNUNET_SCHEDULER_driver_init*(driver: ptr GNUNET_SCHEDULER_Driver): ptr
GNUNET_SCHEDULER_Handle {.
+ cdecl, importc: "GNUNET_SCHEDULER_driver_init", dynlib: libname.}
+
+proc GNUNET_SCHEDULER_driver_done*(sh: ptr GNUNET_SCHEDULER_Handle) {.cdecl,
+ importc: "GNUNET_SCHEDULER_driver_done", dynlib: libname.}
+
+proc GNUNET_SCHEDULER_shutdown*() {.cdecl, importc:
"GNUNET_SCHEDULER_shutdown",
+ dynlib: libname.}
+
diff --git a/gnunet_time_lib.nim b/gnunet_time_lib.nim
new file mode 100644
index 0000000..00d0822
--- /dev/null
+++ b/gnunet_time_lib.nim
@@ -0,0 +1,29 @@
+ {.deadCodeElim: on.}
+when defined(windows):
+ const
+ libname* = "libgnunetutil.dll"
+elif defined(macosx):
+ const
+ libname* = "libgnunetutil.dylib"
+else:
+ const
+ libname* = "libgnunetutil.so"
+
+type
+ GNUNET_TIME_Absolute* {.bycopy.} = object
+ abs_value_us*: uint64
+
+
+
+type
+ GNUNET_TIME_Relative* {.bycopy.} = object
+ rel_value_us*: uint64
+
+
+
+proc GNUNET_TIME_absolute_get_forever*(): GNUNET_TIME_Absolute {.cdecl,
+ importc: "GNUNET_TIME_absolute_get_forever_", dynlib: libname.}
+
+proc GNUNET_TIME_absolute_get*(): GNUNET_TIME_Absolute {.cdecl,
+ importc: "GNUNET_TIME_absolute_get", dynlib: libname.}
+
diff --git a/gnunet_types.nim b/gnunet_types.nim
new file mode 100644
index 0000000..091042e
--- /dev/null
+++ b/gnunet_types.nim
@@ -0,0 +1,40 @@
+const
+ GNUNET_OK* = 1
+ GNUNET_SYSERR* = -1
+ GNUNET_YES* = 1
+ GNUNET_NO* = 0
+
+type
+ GNUNET_MessageHeader* = object
+ size*: uint16
+ msg_type*: uint16
+
+
+type
+ GNUNET_CRYPTO_EddsaPublicKey* {.bycopy.} = object
+ q_y*: array[256 div 8, cuchar]
+
+
+type
+ GNUNET_CRYPTO_EcdsaPublicKey* {.bycopy.} = object
+ q_y*: array[256 div 8, cuchar]
+
+
+type
+ GNUNET_HashCode* {.bycopy.} = object
+ bits*: array[512 div 8 div sizeof((uint32)), uint32]
+
+
+type
+ GNUNET_PeerIdentity* {.bycopy.} = object
+ public_key*: GNUNET_CRYPTO_EddsaPublicKey
+
+
+type
+ GNUNET_DISK_FileHandle* {.bycopy.} = object
+ fd*: cint
+
+
+type
+ GNUNET_NETWORK_Handle* {.bycopy.} = object
+
--
To stop receiving notification emails like this one, please contact
address@hidden