[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 22/61: we get notified about an incoming CADET
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 22/61: we get notified about an incoming CADET channel (and then we crash) |
Date: |
Sat, 13 Apr 2019 13:35:57 +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 a34544055478d04deaf7e210f2097c4a96108fc6
Author: lurchi <address@hidden>
AuthorDate: Tue Jul 31 00:00:32 2018 +0200
we get notified about an incoming CADET channel (and then we crash)
---
asynccadet.nim | 5 ++---
gnunet_application.nim | 17 +++++++++++++----
gnunet_nim.nim | 3 ++-
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/asynccadet.nim b/asynccadet.nim
index 1d4366a..02a852a 100644
--- a/asynccadet.nim
+++ b/asynccadet.nim
@@ -49,7 +49,6 @@ proc channelMessageCheckCb(cls: pointer,
proc cadetConnectCb(cls: pointer) {.cdecl.} =
let app = cast[ptr GnunetApplication](cls)
- echo "cadetConnectCb"
var future: FutureBase
if app.connectFutures.take("cadet", future):
let cadetHandle = CadetHandle(handle:
GNUNET_CADET_connect(app.configHandle),
@@ -72,7 +71,7 @@ proc messageHandlers(): array[2, GNUNET_MQ_MessageHandler] =
proc hashString(port: string): GNUNET_HashCode =
var port: cstring = port
- GNUNET_CRYPTO_hash(addr port, port.len(), addr result)
+ GNUNET_CRYPTO_hash(port, csize(port.len()), addr result)
proc sendMessage*(channel: CadetChannel, payload: seq[byte]) =
let messageLen = uint16(payload.len() + sizeof(GNUNET_MessageHeader))
@@ -91,7 +90,7 @@ proc openPort*(handle: var CadetHandle, port: string): ref
CadetPort =
openPort.handle = GNUNET_CADET_open_port(handle.handle,
addr port,
channelConnectCb,
- addr openPort,
+ addr openPort[],
nil,
channelDisconnectCb,
addr handlers[0])
diff --git a/gnunet_application.nim b/gnunet_application.nim
index d72069c..d15aca2 100644
--- a/gnunet_application.nim
+++ b/gnunet_application.nim
@@ -19,6 +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
let fd = AsyncFD(fdi.sock)
proc addByInterest(interest: GNUNET_SCHEDULER_EventType, addProc: AddProc) :
bool =
result = false
@@ -31,9 +32,14 @@ proc schedulerAdd(cls: pointer,
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):
+ let addReadResult =
+ addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_IN, addRead)
+ let addWriteResult =
+ addByInterest(GNUNET_SCHEDULER_EventType.GNUNET_SCHEDULER_ET_OUT, addWrite)
+ echo "added read fd: ", addReadResult, ", added write fd: ", addWriteResult
+ if addReadResult or addWriteResult:
app.tasks.add(task, fdi)
+ echo "added ok"
return GNUNET_OK
error("Cannot add file descriptor because the event type is not supported")
return GNUNET_SYSERR
@@ -44,16 +50,19 @@ proc schedulerDelete(cls: pointer,
var 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
- error("Cannot remove file descriptor because it has not been added or is
already gone")
+ 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
var app = cast[ptr GnunetApplication](cls)
- debug("setting new timeout: ", dt.abs_value_us)
+ echo("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 65cf0a6..88bc024 100644
--- a/gnunet_nim.nim
+++ b/gnunet_nim.nim
@@ -7,9 +7,10 @@ proc firstTask(gnunetApp: ref GnunetApplication) {.async.} =
var cadet = await gnunetApp.connectCadet()
echo "connected"
let port = cadet.openPort("test")
+ echo "port opened"
let (finished, channel) = await port.channels.read()
+ echo "incoming connection!"
if not finished:
- echo "incoming connection!"
let (finished, message) = await channel.messages.read()
if not finished:
echo "got message: ", message
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet-nim] 07/61: add asynccadet code (does not compile yet), (continued)
- [GNUnet-SVN] [gnunet-nim] 07/61: add asynccadet code (does not compile yet), gnunet, 2019/04/13
- [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 <=
- [GNUnet-SVN] [gnunet-nim] 24/61: command line parsing; application code for creating channel, gnunet, 2019/04/13
- [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