[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] branch master updated: use nimble's default di
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] branch master updated: use nimble's default directory structure |
Date: |
Sat, 03 Nov 2018 20:36:52 +0100 |
This is an automated email from the git hooks/post-receive script.
lurchi pushed a commit to branch master
in repository gnunet-nim.
The following commit(s) were added to refs/heads/master by this push:
new f8b52fb use nimble's default directory structure
f8b52fb is described below
commit f8b52fb3f844658d5398722a7bda24a29f8dd8e9
Author: lurchi <address@hidden>
AuthorDate: Sat Nov 3 20:36:31 2018 +0100
use nimble's default directory structure
---
gnunet_application.nim | 108 ---------------------
gnunet-nim.nimble => gnunet_nim.nimble | 10 +-
gnunet_utils.nim | 13 ---
src/gnunet_nim.nim | 64 ++++++++++++
asynccadet.nim => src/gnunet_nim/cadet.nim | 15 +--
.../gnunet_nim/gnunet_cadet_service.nim | 0
.../gnunet_nim/gnunet_common.nim | 0
.../gnunet_nim/gnunet_configuration_lib.nim | 0
.../gnunet_nim/gnunet_crypto_lib.nim | 0
.../gnunet_nim/gnunet_mq_lib.nim | 0
.../gnunet_nim/gnunet_protocols.nim | 0
.../gnunet_nim/gnunet_scheduler_lib.nim | 0
.../gnunet_nim/gnunet_time_lib.nim | 0
.../gnunet_nim/gnunet_types.nim | 0
src/gnunet_nim/scheduler.nim | 65 +++++++++++++
15 files changed, 143 insertions(+), 132 deletions(-)
diff --git a/gnunet_application.nim b/gnunet_application.nim
deleted file mode 100644
index 83f253e..0000000
--- a/gnunet_application.nim
+++ /dev/null
@@ -1,108 +0,0 @@
-import gnunet_types
-import gnunet_scheduler_lib
-import gnunet_time_lib
-import gnunet_configuration_lib
-import asyncdispatch, tables, logging
-
-type
- GnunetApplication* = object
- timeoutUs: uint64
- tasks: Table[ptr GNUNET_SCHEDULER_Task, ptr GNUNET_SCHEDULER_FdInfo]
- schedulerDriver: GNUNET_SCHEDULER_Driver
- schedulerHandle: ptr GNUNET_SCHEDULER_Handle
- configHandle*: ptr GNUNET_CONFIGURATION_Handle
- connectFutures*: Table[string, FutureBase]
-
-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)
- let app = cast[ptr GnunetApplication](cls)
- debug("adding fd ", fdi.sock)
- 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)
- let addReadResult =
- addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_IN, addRead)
- let addWriteResult =
- addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_OUT, addWrite)
- debug("added read fd: ", addReadResult, ", added write fd: ", addWriteResult)
- if addReadResult or addWriteResult:
- app.tasks.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
- let app = cast[ptr GnunetApplication](cls)
- var fdi: ptr GNUNET_SCHEDULER_FdInfo
- if app.tasks.take(task, fdi):
- for v in app.tasks.values():
- if v.sock == fdi.sock:
- return GNUNET_OK
- unregister(AsyncFD(fdi.sock))
- return GNUNET_OK
- echo("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
- let app = cast[ptr GnunetApplication](cls)
- debug("setting new timeout: ", dt.abs_value_us)
- app.timeoutUs = dt.abs_value_us
-
-proc cleanup(app: ref GnunetApplication) =
- echo "destroying GnunetApplication"
- GNUNET_SCHEDULER_driver_done(app.schedulerHandle)
- GNUNET_CONFIGURATION_destroy(app.configHandle)
-
-proc initGnunetApplication*(configFile: string): ref GnunetApplication =
- var app: ref GnunetApplication
- new(app, cleanup)
- app.timeoutUs = GNUNET_TIME_absolute_get_forever().abs_value_us
- app.tasks = initTable[ptr GNUNET_SCHEDULER_Task, ptr
GNUNET_SCHEDULER_FdInfo]()
- app.schedulerDriver = GNUNET_SCHEDULER_Driver(cls: addr app[],
- add: schedulerAdd,
- del: schedulerDelete,
- set_wakeup: schedulerSetWakeup)
- app.schedulerHandle = GNUNET_SCHEDULER_driver_init(addr app.schedulerDriver)
- app.configHandle = GNUNET_CONFIGURATION_create()
- app.connectFutures = initTable[string, FutureBase]()
- let loadResult = GNUNET_CONFIGURATION_load(app.configHandle, configFile)
- assert(GNUNET_SYSERR != loadResult)
- return app
-
-proc shutdownGnunetApplication*() =
- GNUNET_SCHEDULER_shutdown()
-
-proc doWork*(app: ref GnunetApplication) =
- discard GNUNET_SCHEDULER_do_work(app.schedulerHandle) #FIXME: don't discard
-
-proc microsecondsUntilTimeout*(app: ref GnunetApplication): int =
- ## get the duration until timeout in microseconds
- let now = GNUNET_TIME_absolute_get()
- if app.timeoutUs < now.abs_value_us:
- return 0
- elif app.timeoutUs == 0xff_ff_ff_ff_ff_ff_ff_ff'u64: # high(uint64) not
implemented
- return -1
- return int(min(app.timeoutUs - now.abs_value_us, uint64(high(cint))))
-
-proc millisecondsUntilTimeout*(app: ref GnunetApplication): int =
- ## get the duration until timeout in milliseconds
- let timeoutUs = app.microsecondsUntilTimeout()
- if timeoutUs < 0:
- return -1
- return timeoutUs div 1_000
diff --git a/gnunet-nim.nimble b/gnunet_nim.nimble
similarity index 70%
rename from gnunet-nim.nimble
rename to gnunet_nim.nimble
index 3a29ac4..a870eae 100644
--- a/gnunet-nim.nimble
+++ b/gnunet_nim.nimble
@@ -3,14 +3,14 @@ version = "0.0.0"
author = "secushare"
description = "GNUnet Nim bindings"
license = "AGPL3"
-# srcDir = ""
+srcDir = "src"
# dependencies:
-requires = "nim >= 0.18.0"
+requires "nim >= 0.18.0"
-when defined(nimdistros):
- import distros
- foreignDep "gnunet"
+#when defined(nimdistros):
+# import distros
+# foreignDep "gnunet"
# targets/tasks:
diff --git a/gnunet_utils.nim b/gnunet_utils.nim
deleted file mode 100644
index b74ad60..0000000
--- a/gnunet_utils.nim
+++ /dev/null
@@ -1,13 +0,0 @@
-import gnunet_common, gnunet_crypto_lib
-
-proc peerId*(peer: GNUNET_PeerIdentity): string =
- let peerId = GNUNET_i2s(unsafeAddr peer)
- let peerIdLen = peerId.len()
- result = newString(peerIdLen)
- copyMem(addr result[0], peerId, peerIdLen)
-
-proc fullPeerId*(peer: GNUNET_PeerIdentity): string =
- let peerId = GNUNET_i2s_full(unsafeAddr peer)
- let peerIdLen = peerId.len()
- result = newString(peerIdLen)
- copyMem(addr result[0], peerId, peerIdLen)
diff --git a/src/gnunet_nim.nim b/src/gnunet_nim.nim
new file mode 100644
index 0000000..af482b6
--- /dev/null
+++ b/src/gnunet_nim.nim
@@ -0,0 +1,64 @@
+import gnunet_nim/gnunet_types
+import gnunet_nim/gnunet_scheduler_lib
+import gnunet_nim/gnunet_time_lib
+import gnunet_nim/gnunet_configuration_lib
+import gnunet_nim/gnunet_crypto_lib
+import gnunet_nim/gnunet_common
+import gnunet_nim/scheduler
+import asyncdispatch, tables, logging
+
+export GnunetApplication
+
+proc peerId*(peer: GNUNET_PeerIdentity): string =
+ let peerId = GNUNET_i2s(unsafeAddr peer)
+ let peerIdLen = peerId.len()
+ result = newString(peerIdLen)
+ copyMem(addr result[0], peerId, peerIdLen)
+
+proc fullPeerId*(peer: GNUNET_PeerIdentity): string =
+ let peerId = GNUNET_i2s_full(unsafeAddr peer)
+ let peerIdLen = peerId.len()
+ result = newString(peerIdLen)
+ copyMem(addr result[0], peerId, peerIdLen)
+
+proc initGnunetApplication*(configFile: string): ref GnunetApplication =
+ var app: ref GnunetApplication
+ proc cleanup(app: ref GnunetApplication) =
+ echo "destroying GnunetApplication"
+ GNUNET_SCHEDULER_driver_done(app.schedulerHandle)
+ GNUNET_CONFIGURATION_destroy(app.configHandle)
+ new(app, cleanup)
+ app.timeoutUs = GNUNET_TIME_absolute_get_forever().abs_value_us
+ app.tasks = initTable[ptr GNUNET_SCHEDULER_Task, ptr
GNUNET_SCHEDULER_FdInfo]()
+ app.schedulerDriver = GNUNET_SCHEDULER_Driver(cls: addr app[],
+ add: schedulerAdd,
+ del: schedulerDelete,
+ set_wakeup: schedulerSetWakeup)
+ app.schedulerHandle = GNUNET_SCHEDULER_driver_init(addr app.schedulerDriver)
+ app.configHandle = GNUNET_CONFIGURATION_create()
+ app.connectFutures = initTable[string, FutureBase]()
+ let loadResult = GNUNET_CONFIGURATION_load(app.configHandle, configFile)
+ assert(GNUNET_SYSERR != loadResult)
+ return app
+
+proc shutdownGnunetApplication*() =
+ GNUNET_SCHEDULER_shutdown()
+
+proc doWork*(app: ref GnunetApplication) =
+ discard GNUNET_SCHEDULER_do_work(app.schedulerHandle) #FIXME: don't discard
+
+proc microsecondsUntilTimeout*(app: ref GnunetApplication): int =
+ ## get the duration until timeout in microseconds
+ let now = GNUNET_TIME_absolute_get()
+ if app.timeoutUs < now.abs_value_us:
+ return 0
+ elif app.timeoutUs == 0xff_ff_ff_ff_ff_ff_ff_ff'u64: # high(uint64) not
implemented
+ return -1
+ return int(min(app.timeoutUs - now.abs_value_us, uint64(high(cint))))
+
+proc millisecondsUntilTimeout*(app: ref GnunetApplication): int =
+ ## get the duration until timeout in milliseconds
+ let timeoutUs = app.microsecondsUntilTimeout()
+ if timeoutUs < 0:
+ return -1
+ return timeoutUs div 1_000
diff --git a/asynccadet.nim b/src/gnunet_nim/cadet.nim
similarity index 96%
rename from asynccadet.nim
rename to src/gnunet_nim/cadet.nim
index bb57571..8663fd2 100644
--- a/asynccadet.nim
+++ b/src/gnunet_nim/cadet.nim
@@ -1,9 +1,12 @@
-import
- gnunet_cadet_service, gnunet_types, gnunet_mq_lib, gnunet_crypto_lib,
gnunet_protocols, gnunet_scheduler_lib, gnunet_configuration_lib
-import
- gnunet_application, gnunet_utils
-import
- asyncdispatch, posix, tables, logging
+import gnunet_cadet_service
+import gnunet_types
+import gnunet_mq_lib
+import gnunet_crypto_lib
+import gnunet_protocols
+import gnunet_scheduler_lib
+import gnunet_configuration_lib
+import scheduler
+import asyncdispatch, posix, tables, logging
type
CadetHandle* = object
diff --git a/gnunet_cadet_service.nim b/src/gnunet_nim/gnunet_cadet_service.nim
similarity index 100%
rename from gnunet_cadet_service.nim
rename to src/gnunet_nim/gnunet_cadet_service.nim
diff --git a/gnunet_common.nim b/src/gnunet_nim/gnunet_common.nim
similarity index 100%
rename from gnunet_common.nim
rename to src/gnunet_nim/gnunet_common.nim
diff --git a/gnunet_configuration_lib.nim
b/src/gnunet_nim/gnunet_configuration_lib.nim
similarity index 100%
rename from gnunet_configuration_lib.nim
rename to src/gnunet_nim/gnunet_configuration_lib.nim
diff --git a/gnunet_crypto_lib.nim b/src/gnunet_nim/gnunet_crypto_lib.nim
similarity index 100%
rename from gnunet_crypto_lib.nim
rename to src/gnunet_nim/gnunet_crypto_lib.nim
diff --git a/gnunet_mq_lib.nim b/src/gnunet_nim/gnunet_mq_lib.nim
similarity index 100%
rename from gnunet_mq_lib.nim
rename to src/gnunet_nim/gnunet_mq_lib.nim
diff --git a/gnunet_protocols.nim b/src/gnunet_nim/gnunet_protocols.nim
similarity index 100%
rename from gnunet_protocols.nim
rename to src/gnunet_nim/gnunet_protocols.nim
diff --git a/gnunet_scheduler_lib.nim b/src/gnunet_nim/gnunet_scheduler_lib.nim
similarity index 100%
rename from gnunet_scheduler_lib.nim
rename to src/gnunet_nim/gnunet_scheduler_lib.nim
diff --git a/gnunet_time_lib.nim b/src/gnunet_nim/gnunet_time_lib.nim
similarity index 100%
rename from gnunet_time_lib.nim
rename to src/gnunet_nim/gnunet_time_lib.nim
diff --git a/gnunet_types.nim b/src/gnunet_nim/gnunet_types.nim
similarity index 100%
rename from gnunet_types.nim
rename to src/gnunet_nim/gnunet_types.nim
diff --git a/src/gnunet_nim/scheduler.nim b/src/gnunet_nim/scheduler.nim
new file mode 100644
index 0000000..ee737bb
--- /dev/null
+++ b/src/gnunet_nim/scheduler.nim
@@ -0,0 +1,65 @@
+import gnunet_scheduler_lib
+import gnunet_configuration_lib
+import gnunet_time_lib
+import gnunet_types
+import asyncdispatch, tables, logging
+
+type
+ GnunetApplication* = object
+ timeoutUs*: uint64
+ tasks*: Table[ptr GNUNET_SCHEDULER_Task, ptr GNUNET_SCHEDULER_FdInfo]
+ schedulerDriver*: GNUNET_SCHEDULER_Driver
+ schedulerHandle*: ptr GNUNET_SCHEDULER_Handle
+ configHandle*: ptr GNUNET_CONFIGURATION_Handle
+ connectFutures*: Table[string, FutureBase]
+
+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)
+ let app = cast[ptr GnunetApplication](cls)
+ debug("adding fd ", fdi.sock)
+ 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)
+ let addReadResult =
+ addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_IN, addRead)
+ let addWriteResult =
+ addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_OUT, addWrite)
+ debug("added read fd: ", addReadResult, ", added write fd: ", addWriteResult)
+ if addReadResult or addWriteResult:
+ app.tasks.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
+ let app = cast[ptr GnunetApplication](cls)
+ var fdi: ptr GNUNET_SCHEDULER_FdInfo
+ if app.tasks.take(task, fdi):
+ for v in app.tasks.values():
+ if v.sock == fdi.sock:
+ return GNUNET_OK
+ unregister(AsyncFD(fdi.sock))
+ return GNUNET_OK
+ echo("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
+ let app = cast[ptr GnunetApplication](cls)
+ debug("setting new timeout: ", dt.abs_value_us)
+ app.timeoutUs = dt.abs_value_us
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet-nim] branch master updated: use nimble's default directory structure,
gnunet <=