[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 24/61: command line parsing; application code
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 24/61: command line parsing; application code for creating channel |
Date: |
Sat, 13 Apr 2019 13:35:59 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnunet-nim.
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
- [GNUnet-SVN] [gnunet-nim] 19/61: make the cleanup proc the finalizer (no explicit call necessary anymore), (continued)
- [GNUnet-SVN] [gnunet-nim] 19/61: make the cleanup proc the finalizer (no explicit call necessary anymore), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 13/61: connection to cadet service successful, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 15/61: use the bundled gnunet.conf, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 20/61: let's try out ports and channels, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 11/61: make cadetConnect an async proc, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 39/61: add shutdown procedure, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 30/61: gitignore: add gnunet generated files and folders, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 27/61: cli option: add option to specify gnunet config, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 14/61: don't use AsyncEvent but store Futures in GnunetApplication, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 22/61: we get notified about an incoming CADET channel (and then we crash), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 24/61: command line parsing; application code for creating channel,
gnunet <=
- [GNUnet-SVN] [gnunet-nim] 17/61: Merge branch 'master' of ssh://gnunet.org/gnunet-nim, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 16/61: disconnect after connecting (shuts down the application), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 12/61: fix segfaults using heap allocation, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 08/61: Merge branch 'master' of ssh://gnunet.org/gnunet-nim, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 18/61: make the cleanup proc the finalizer (no explicit call necessary anymore), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 35/61: use nicer new syntax, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 31/61: use ref object where we only use heap allocation, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 29/61: fix crashes, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 38/61: comment: explain why we're reading from stdin in a nasty way, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 28/61: newline behaviour like in gnunet-cadet, gnunet, 2019/04/13