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: command line parsing; a


From: gnunet
Subject: [GNUnet-SVN] [gnunet-nim] branch master updated: command line parsing; application code for creating channel
Date: Sat, 04 Aug 2018 16:15:00 +0200

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 8fe1352  command line parsing; application code for creating channel
8fe1352 is described below

commit 8fe13527600ea05bbb626e98e2e59b5da061881f
Author: lurchi <address@hidden>
AuthorDate: Sat Aug 4 16:14:43 2018 +0200

    command line parsing; application code for creating channel
---
 gnunet.conf            |  3 ---
 gnunet_application.nim |  4 ++--
 gnunet_nim.nim         | 53 +++++++++++++++++++++++++++++++-------------------
 3 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/gnunet.conf b/gnunet.conf
index cb8af47..6dd01ee 100644
--- a/gnunet.conf
+++ b/gnunet.conf
@@ -7,9 +7,6 @@ GNUNET_USER_RUNTIME_DIR = ./gnunet_user_runtime_dir
 [arm]
 GLOBAL_POSTFIX = -L WARNING -l $GNUNET_HOME/gnunet.log
 
-[cadet]
-GLOBAL_POSTFIX = -L DEBUG
-
 [fs]
 IMMEDIATE_START = NO
 
diff --git a/gnunet_application.nim b/gnunet_application.nim
index 777289e..bcad17b 100644
--- a/gnunet_application.nim
+++ b/gnunet_application.nim
@@ -19,7 +19,7 @@ proc schedulerAdd(cls: pointer,
   ## callback allowing GNUnet to add a file descriptor to the event loop
   type AddProc = proc(fd: AsyncFD, cb: proc(fd: AsyncFD): bool)
   var app = cast[ptr GnunetApplication](cls)
-  echo "adding fd ", fdi.sock
+  debug("adding fd ", fdi.sock)
   let fd = AsyncFD(fdi.sock)
   proc addByInterest(interest: GNUNET_SCHEDULER_EventType, addProc: AddProc) : 
bool =
     result = false
@@ -61,7 +61,7 @@ proc schedulerSetWakeup(cls: pointer,
                         dt: GNUNET_TIME_Absolute) {.cdecl.} =
   ## callback allowing GNUnet to set a new wakeup time
   var app = cast[ptr GnunetApplication](cls)
-  echo("setting new timeout: ", dt.abs_value_us)
+  debug("setting new timeout: ", dt.abs_value_us)
   app.timeoutUs = dt.abs_value_us
 
 proc cleanup(app: ref GnunetApplication) =
diff --git a/gnunet_nim.nim b/gnunet_nim.nim
index 9c71af3..d22c35e 100644
--- a/gnunet_nim.nim
+++ b/gnunet_nim.nim
@@ -1,14 +1,15 @@
 import gnunet_application
 import asyncdispatch
 import asynccadet
+import parseopt
 
-proc firstTask(gnunetApp: ref GnunetApplication) {.async.} =
+proc cadetListen(gnunetApp: ref GnunetApplication, port: string) {.async.} =
   echo "connecting Cadet"
   var cadet = await gnunetApp.connectCadet()
   echo "connected"
-  let port = cadet.openPort("test")
+  let cadetPort = cadet.openPort(port)
   echo "port opened"
-  let (hasChannel, channel) = await port.channels.read()
+  let (hasChannel, channel) = await cadetPort.channels.read()
   if hasChannel:
     echo "incoming connection!"
     while true:
@@ -16,28 +17,40 @@ proc firstTask(gnunetApp: ref GnunetApplication) {.async.} =
       if not hasData:
         break;
       echo "got message: ", message
-  #while true:
-  #  echo "reading future"
-  #  let (hasChannel, channel) = await port.channels.read()
-  #  if not hasChannel:
-  #    break
-  #  echo "incoming connection!"
-  #  while true:
-  #    let (hasData, message) = await channel.messages.read()
-  #    echo "message?"
-  #    if not hasData:
-  #      break;
-  #    echo "got message: ", message
-  echo "disconnecting"
-  cadet.disconnect()
-  echo "disconnected"
+
+proc cadetConnect(gnunetApp: ref GnunetApplication,
+                  peer: string,
+                  port: string) {.async.} =
+  var cadet = await gnunetApp.connectCadet()
+  let cadetChannel = cadet.createChannel(peer, port)
+  cadetChannel.sendMessage("hello!")
+  while true:
+    let (hasData, message) = await cadetChannel.messages.read()
+    if not hasData:
+      break;
+    echo "got message: ", message
 
 proc main() =
+  var peer, port: string
+  var optParser = initOptParser()
+  for kind, key, value in optParser.getopt():
+    case kind
+    of cmdArgument:
+      peer = key
+    of cmdLongOption, cmdShortOption:
+      case key
+      of "port", "p": port = value
+    of cmdEnd:
+      assert(false)
   var gnunetApp = initGnunetApplication("gnunet.conf")
-  asyncCheck firstTask(gnunetApp)
+  echo "peer = ", peer, ", port = ", port
+  if peer.isNil() and not port.isNil():
+    asyncCheck cadetListen(gnunetApp, port)
+  elif not peer.isNil() and not port.isNil():
+    asyncCheck cadetConnect(gnunetApp, peer, port)
   try:
     while true:
-      echo "polling, timeout = ", gnunetApp.millisecondsUntilTimeout()
+      #echo "polling, timeout = ", gnunetApp.millisecondsUntilTimeout()
       poll(gnunetApp.millisecondsUntilTimeout())
       gnunetApp.doWork()
   except ValueError:

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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