[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 02/02: we get notified about an incoming CADET
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 02/02: we get notified about an incoming CADET channel (and then we crash) |
Date: |
Tue, 31 Jul 2018 00:00:49 +0200 |
This is an automated email from the git hooks/post-receive script.
lurchi 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