[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 23/61: receiving of cadet messages possible no
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 23/61: receiving of cadet messages possible now |
Date: |
Sat, 13 Apr 2019 13:35:58 +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 a00c5b042e6a4d910f35e1b25ed70b00d878321c
Author: lurchi <address@hidden>
AuthorDate: Fri Aug 3 23:45:55 2018 +0200
receiving of cadet messages possible now
---
asynccadet.nim | 40 +++++++++++++++++++++++-----------------
gnunet_application.nim | 3 +--
gnunet_nim.nim | 25 ++++++++++++++++++++-----
3 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/asynccadet.nim b/asynccadet.nim
index 02a852a..5c9f9da 100644
--- a/asynccadet.nim
+++ b/asynccadet.nim
@@ -6,18 +6,19 @@ import
asyncdispatch, posix, tables, logging
type
- CadetHandle = object
+ CadetHandle* = object
handle: ptr GNUNET_CADET_Handle
openPorts: seq[ref CadetPort]
- CadetPort = object
+ CadetPort* = object
handle: ptr GNUNET_CADET_Port
- channels*: FutureStream[CadetChannel]
+ channels*: FutureStream[ref CadetChannel]
+ activeChannels: seq[ref CadetChannel]
- CadetChannel = object
+ CadetChannel* = object
handle: ptr GNUNET_CADET_Channel
peer: GNUNET_PeerIdentity
- messages*: FutureStream[seq[byte]]
+ messages*: FutureStream[string]
proc channelDisconnectCb(cls: pointer,
gnunetChannel: ptr GNUNET_CADET_Channel) {.cdecl.} =
@@ -28,20 +29,24 @@ proc channelConnectCb(cls: pointer,
gnunetChannel: ptr GNUNET_CADET_Channel,
source: ptr GNUNET_PeerIdentity): pointer {.cdecl.} =
var port = cast[ptr CadetPort](cls)
- var channel = CadetChannel(handle: gnunetChannel,
- peer: GNUNET_PeerIdentity(public_key:
source.public_key),
- messages: newFutureStream[seq[byte]]())
- asyncCheck port.channels.write(channel)
- return addr channel
+ var channel: ref CadetChannel
+ new(channel)
+ channel.handle = gnunetChannel
+ channel.peer = GNUNET_PeerIdentity(public_key: source.public_key)
+ channel.messages = newFutureStream[string]()
+ port.activeChannels.add(channel)
+ waitFor port.channels.write(channel)
+ return addr channel[]
proc channelMessageCb(cls: pointer,
messageHeader: ptr GNUNET_MessageHeader) {.cdecl.} =
var channel = cast[ptr CadetChannel](cls)
+ GNUNET_CADET_receive_done(channel.handle)
let payloadLen = int(ntohs(messageHeader.size)) -
sizeof(GNUNET_MessageHeader)
- let messageHeader = cast[ptr array[2, GNUNET_MessageHeader]](messageHeader)
- var payloadBuf = newSeq[byte](payloadLen)
- copyMem(addr payloadBuf[0], addr messageHeader[1], payloadLen)
- asyncCheck channel.messages.write(payloadBuf)
+ let payload = cast[ptr
GNUNET_MessageHeader](cast[ByteAddress](messageHeader) +
sizeof(GNUNET_MessageHeader))
+ var payloadBuf = newString(payloadLen)
+ copyMem(addr payloadBuf[0], payload, payloadLen)
+ waitFor channel.messages.write(payloadBuf)
proc channelMessageCheckCb(cls: pointer,
messageHeader: ptr GNUNET_MessageHeader): cint
{.cdecl.} =
@@ -73,7 +78,7 @@ proc hashString(port: string): GNUNET_HashCode =
var port: cstring = port
GNUNET_CRYPTO_hash(port, csize(port.len()), addr result)
-proc sendMessage*(channel: CadetChannel, payload: seq[byte]) =
+proc sendMessage*(channel: CadetChannel, payload: string) =
let messageLen = uint16(payload.len() + sizeof(GNUNET_MessageHeader))
var messageHeader: ptr GNUNET_MessageHeader
var envelope = GNUNET_MQ_msg(addr messageHeader,
@@ -86,7 +91,7 @@ proc openPort*(handle: var CadetHandle, port: string): ref
CadetPort =
var port = hashString(port)
var openPort: ref CadetPort
new(openPort)
- openPort.channels = newFutureStream[CadetChannel]()
+ openPort.channels = newFutureStream[ref CadetChannel]()
openPort.handle = GNUNET_CADET_open_port(handle.handle,
addr port,
channelConnectCb,
@@ -94,6 +99,7 @@ proc openPort*(handle: var CadetHandle, port: string): ref
CadetPort =
nil,
channelDisconnectCb,
addr handlers[0])
+ openPort.activeChannels = newSeq[ref CadetChannel]()
handle.openPorts.add(openPort)
return openPort
@@ -109,7 +115,7 @@ proc createChannel*(handle: CadetHandle, peer: string,
port: string): CadetChann
addr
peerIdentity.public_key)
result = CadetChannel(handle: nil,
peer: peerIdentity,
- messages: newFutureStream[seq[byte]]("createChannel"))
+ messages: newFutureStream[string]("createChannel"))
var handlers = messageHandlers()
var port = hashString(port)
result.handle = GNUNET_CADET_channel_create(handle.handle,
diff --git a/gnunet_application.nim b/gnunet_application.nim
index d15aca2..777289e 100644
--- a/gnunet_application.nim
+++ b/gnunet_application.nim
@@ -36,10 +36,9 @@ proc schedulerAdd(cls: pointer,
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
+ debug("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
diff --git a/gnunet_nim.nim b/gnunet_nim.nim
index 88bc024..9c71af3 100644
--- a/gnunet_nim.nim
+++ b/gnunet_nim.nim
@@ -8,12 +8,27 @@ proc firstTask(gnunetApp: ref GnunetApplication) {.async.} =
echo "connected"
let port = cadet.openPort("test")
echo "port opened"
- let (finished, channel) = await port.channels.read()
- echo "incoming connection!"
- if not finished:
- let (finished, message) = await channel.messages.read()
- if not finished:
+ let (hasChannel, channel) = await port.channels.read()
+ if hasChannel:
+ echo "incoming connection!"
+ while true:
+ let (hasData, message) = await channel.messages.read()
+ 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"
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet-nim] 37/61: disconnect from the cadet service when CadetHandle is destroyed, (continued)
- [GNUnet-SVN] [gnunet-nim] 37/61: disconnect from the cadet service when CadetHandle is destroyed, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 53/61: restructure groupchat application, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 44/61: add peer ID string functions, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 45/61: use peer IDs as chat identifiers, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 48/61: Makefile to clean the build., gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 52/61: workaround for missing notification about disconnected cadet channels, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 09/61: fix compilation, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 60/61: Start of a nimble file, should probably drop nake later on., gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 49/61: added date and time string to output, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 10/61: fix compilation (2), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 23/61: receiving of cadet messages possible now,
gnunet <=
- [GNUnet-SVN] [gnunet-nim] 51/61: Merge branch 'master' of ssh://gnunet.org/gnunet-nim, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 50/61: load config file in release mode too (fixes segfault), gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 36/61: use immutable variables where possible, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 33/61: add support for input and output file, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 54/61: try out nimbox, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 55/61: Revert "try out nimbox", gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 57/61: Add nakefile, nim.cfg, and ignore more things, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 47/61: examples/{start, stop}_peers: Use /bin/sh, tested and checked against Bash and shellcheck., gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 61/61: nimble, gnunet, 2019/04/13
- [GNUnet-SVN] [gnunet-nim] 42/61: add first version of groupchat application, gnunet, 2019/04/13