gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet-nim] branch master updated (265eb49 -> 6ea7792)


From: gnunet
Subject: [GNUnet-SVN] [gnunet-nim] branch master updated (265eb49 -> 6ea7792)
Date: Mon, 15 Apr 2019 01:31:53 +0200

This is an automated email from the git hooks/post-receive script.

dvn pushed a change to branch master
in repository gnunet-nim.

    from 265eb49  nimble
     new 610f2dd  make groupchat compi│····· le with nim-0.19
     new f8b52fb  use nimble's default directory structure
     new 4af5ed0  changed GNUNET_CADET_ChannelOption to 
GNUNET_CADET_OPTION_RELIABLE
     new cd773df  Add a .dir-locals,el for configuring emacs for this project
     new 6ea7792  Remove groupchat files, as there is now a seperate repo

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .dir-locals.el                                     |  16 +++
 examples/Makefile                                  |   5 -
 examples/groupchat.nim                             |  97 ------------------
 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         |  17 ++--
 .../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 +++++++++++++
 18 files changed, 160 insertions(+), 235 deletions(-)
 create mode 100644 .dir-locals.el
 delete mode 100644 examples/Makefile
 delete mode 100644 examples/groupchat.nim
 delete mode 100644 gnunet_application.nim
 rename gnunet-nim.nimble => gnunet_nim.nimble (70%)
 delete mode 100644 gnunet_utils.nim
 create mode 100644 src/gnunet_nim.nim
 rename asynccadet.nim => src/gnunet_nim/cadet.nim (96%)
 rename gnunet_cadet_service.nim => src/gnunet_nim/gnunet_cadet_service.nim 
(100%)
 rename gnunet_common.nim => src/gnunet_nim/gnunet_common.nim (100%)
 rename gnunet_configuration_lib.nim => 
src/gnunet_nim/gnunet_configuration_lib.nim (100%)
 rename gnunet_crypto_lib.nim => src/gnunet_nim/gnunet_crypto_lib.nim (100%)
 rename gnunet_mq_lib.nim => src/gnunet_nim/gnunet_mq_lib.nim (100%)
 rename gnunet_protocols.nim => src/gnunet_nim/gnunet_protocols.nim (100%)
 rename gnunet_scheduler_lib.nim => src/gnunet_nim/gnunet_scheduler_lib.nim 
(100%)
 rename gnunet_time_lib.nim => src/gnunet_nim/gnunet_time_lib.nim (100%)
 rename gnunet_types.nim => src/gnunet_nim/gnunet_types.nim (100%)
 create mode 100644 src/gnunet_nim/scheduler.nim

diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000..6878638
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,16 @@
+;; Per-directory local variables for GNU Emacs 23 and later.
+
+((nil
+  . ((fill-column . 78)
+     (tab-width   .  4)
+     (indent-tabs-mode . nil)
+     (show-trailing-whitespace . t)
+     (c-basic-offset . 2)
+     (ispell-check-comments . exclusive)
+     (ispell-local-dictionary . "american")
+     (safe-local-variable-values
+         '((c-default-style . "gnu")
+           (sentence-end-double-space . f)
+        (eval add-hook 'prog-mode-hook #'flyspell-prog-mode)
+        (flyspell-issue-message-flag . f) ; avoid messages for every word
+        )))))
diff --git a/examples/Makefile b/examples/Makefile
deleted file mode 100644
index e583032..0000000
--- a/examples/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-groupchat: groupchat.nim
-       nim compile $<
-
-run:
-       ./groupchat -p=23014 -c=gnunet1.conf
diff --git a/examples/groupchat.nim b/examples/groupchat.nim
deleted file mode 100644
index d6ef46d..0000000
--- a/examples/groupchat.nim
+++ /dev/null
@@ -1,97 +0,0 @@
-import ../gnunet_application, ../asynccadet, ../gnunet_utils
-import asyncdispatch, asyncfile, parseopt, strutils, sequtils, times, os
-
-type Chat = object
-  channels: seq[ref CadetChannel]
-
-proc publish(chat: ref Chat, message: string, sender: ref CadetChannel = nil) =
-  let message =
-    if sender.isNil(): message.strip(leading = false)
-    else: "[" & sender.peer.peerId() & "] " & message.strip(leading = false)
-  echo getDatestr(), " ", getClockStr(), " ", message
-  for c in chat.channels:
-    c.sendMessage(message)
-
-proc processClientMessages(channel: ref CadetChannel,
-                           chat: ref Chat) {.async.} =
-  while true:
-    let (hasData, message) = await channel.messages.read()
-    if not hasData:
-      break
-    chat.publish(message = message, sender = channel)
-
-proc processServerMessages(channel: ref CadetChannel) {.async.} =
-  while true:
-    let (hasData, message) = await channel.messages.read()
-    if not hasData:
-      shutdownGnunetApplication()
-      return
-    echo getDateStr()," ",getClockStr()," ",message
-
-proc processInput(inputFile: AsyncFile, channel: ref CadetChannel) {.async.} =
-  while true:
-    let input = await inputFile.readline()
-    channel.sendMessage(input)
-
-proc firstTask(gnunetApp: ref GnunetApplication,
-               server: string,
-               port: string) {.async.} =
-  let cadet = await gnunetApp.initCadet()
-  var chat = new(Chat)
-  chat.channels = newSeq[ref CadetChannel]()
-  if not server.isNil():
-    let inputFile = openAsync("/dev/stdin", fmRead)
-    let channel = cadet.createChannel(server, port)
-    await processServerMessages(channel) or processInput(inputFile, channel)
-    inputFile.close()
-  else:
-    let cadetPort = cadet.openPort(port)
-    while true:
-      let (hasChannel, channel) = await cadetPort.channels.read()
-      if not hasChannel:
-        break
-      let peerId = channel.peer.peerId()
-      chat.publish(message = peerId & " joined\n")
-      let listParticipants =
-        chat.channels.map(proc(c: ref CadetChannel): string = c.peer.peerId)
-      channel.sendMessage("Welcome " & peerId & "! participants: " & 
$listParticipants)
-      chat.channels.add(channel)
-      closureScope:
-        let channel = channel
-        let peerId = peerId
-        proc channelDisconnected(future: Future[void]) =
-          chat.channels.delete(chat.channels.find(channel))
-          chat.publish(message = peerId & " left\n")
-        processClientMessages(channel, chat).addCallback(channelDisconnected)
-
-proc main() =
-  var server, port, configfile: string
-  var optParser = initOptParser()
-  for kind, key, value in optParser.getopt():
-    case kind
-    of cmdLongOption, cmdShortOption:
-      case key
-      of "config", "c": configfile = value
-      of "server", "s": server = value
-      of "port", "p": port = value
-    else:
-      assert(false)
-  if configfile.isNil():
-    echo "I need a config file to use."
-    echo "  Add -c=<gnunet.conf>"
-    return
-  if port.isNil():
-    echo "I need a shared secret port to use."
-    echo "  Add -p=<sharedsecret>"
-    return
-  if server.isNil():
-    echo "Entering server mode."
-  var gnunetApp = initGnunetApplication(configfile)
-  asyncCheck firstTask(gnunetApp, server, port)
-  while hasPendingOperations():
-    poll(gnunetApp.millisecondsUntilTimeout())
-    gnunetApp.doWork()
-  echo "Quitting."
-
-main()
-GC_fullCollect()
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..b9fe0b7 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
@@ -118,7 +121,7 @@ proc createChannel*(handle: ref CadetHandle,
                                                addr channel[],
                                                addr channel.peer,
                                                unsafeAddr port,
-                                               GNUNET_CADET_OPTION_DEFAULT,
+                                               GNUNET_CADET_OPTION_RELIABLE,
                                                nil,
                                                channelDisconnectCb,
                                                unsafeAddr handlers[0])
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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]