[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 10/61: fix compilation (2)
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 10/61: fix compilation (2) |
Date: |
Sat, 13 Apr 2019 13:35:45 +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 c24442b0c4470d3fea1925f7aa5e743a4075b015
Author: lurchi <address@hidden>
AuthorDate: Sun Jul 22 20:56:40 2018 +0200
fix compilation (2)
---
asynccadet.nim | 74 ++++++++++++++++++++++------------------
gnunet_cadet_service.nim | 2 +-
gnunet_nim.nim | 87 ++++--------------------------------------------
gnunet_types.nim | 18 +++++-----
4 files changed, 58 insertions(+), 123 deletions(-)
diff --git a/asynccadet.nim b/asynccadet.nim
index 388c9b0..e3148f8 100644
--- a/asynccadet.nim
+++ b/asynccadet.nim
@@ -1,5 +1,9 @@
-import gnunet_cadet_service, gnunet_types, gnunet_mq_lib, gnunet_protocols
-import asyncdispatch, posix
+import
+ gnunet_cadet_service, gnunet_types, gnunet_mq_lib, gnunet_crypto_lib,
gnunet_protocols
+import
+ gnunet_application
+import
+ asyncdispatch, posix
type
CadetHandle = object
@@ -11,7 +15,7 @@ type
CadetChannel = object
handle: ptr GNUNET_CADET_Channel
- peer: ptr GNUNET_PeerIdentity
+ peer: GNUNET_PeerIdentity
messages*: FutureStream[seq[byte]]
proc channelDisconnectCb(cls: pointer,
@@ -21,23 +25,21 @@ proc channelDisconnectCb(cls: pointer,
proc channelConnectCb(cls: pointer,
gnunetChannel: ptr GNUNET_CADET_Channel,
- source: ptr GNUNET_PeerIdentity) {.cdecl.} =
+ source: ptr GNUNET_PeerIdentity): pointer {.cdecl.} =
var port = cast[ptr CadetPort](cls)
var channel = CadetChannel(handle: gnunetChannel,
- peer: source,
+ peer: GNUNET_PeerIdentity(public_key:
source.public_key),
messages: newFutureStream[seq[byte]]())
asyncCheck port.channels.write(channel)
+ return addr channel
proc channelMessageCb(cls: pointer,
messageHeader: ptr GNUNET_MessageHeader) {.cdecl.} =
var channel = cast[ptr CadetChannel](cls)
- # FIXME: is there a less ugly way of doing pointer arithmetic?
- let payload = cast[pointer](
- cast[uint](messageHeader) + uint(sizeof(GNUNET_MessageHeader))
- )
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], payload, payloadLen)
+ copyMem(addr payloadBuf[0], addr messageHeader[1], payloadLen)
asyncCheck channel.messages.write(payloadBuf)
proc channelMessageCheckCb(cls: pointer,
@@ -58,8 +60,9 @@ proc messageHandlers(): array[2, GNUNET_MQ_MessageHandler] =
expected_size: 0)
]
-proc portHash(port: string): GNUNET_HashCode =
- GNUNET_CRYPTO_hash(addr port[0], port.len(), addr result) # FIXME
+proc hashString(port: string): GNUNET_HashCode =
+ var port: cstring = port
+ GNUNET_CRYPTO_hash(addr port, port.len(), addr result)
proc sendMessage*(channel: CadetChannel, payload: seq[byte]) =
let messageLen = uint16(payload.len() + sizeof(GNUNET_MessageHeader))
@@ -69,36 +72,41 @@ proc sendMessage*(channel: CadetChannel, payload:
seq[byte]) =
GNUNET_MESSAGE_TYPE_CADET_CLI)
GNUNET_MQ_send(GNUNET_CADET_get_mq(channel.handle), envelope)
-proc connect*(): CadetHandle =
- var configHandle = #FIXME
- result = CadetHandle(handle: GNUNET_CADET_connect(configHandle))
+proc connectCadet*(app: GnunetApplication): CadetHandle =
+ result = CadetHandle(handle: GNUNET_CADET_connect(app.configHandle))
proc openPort*(handle: CadetHandle, port: string): CadetPort =
result = CadetPort(handle: nil,
channels: newFutureStream[CadetChannel]())
- let handlers = messageHandlers()
+ var handlers = messageHandlers()
+ var port = hashString(port)
result.handle = GNUNET_CADET_open_port(handle.handle,
- port: portHash(port),
- connects: channelConnectCb,
- connects_cls: addr result,
- window_changes: nil,
- disconnects: channelDisconnectCb,
- handlers: handlers)
+ addr port,
+ channelConnectCb,
+ addr result,
+ nil,
+ channelDisconnectCb,
+ addr handlers[0])
proc close*(port: CadetPort) =
GNUNET_CADET_close_port(port.handle)
-proc createChannel*(handle: CadetHandle, peer: GnunetPeer, port: string):
CadetChannel =
+proc createChannel*(handle: CadetHandle, peer: string, port: string):
CadetChannel =
+ var peerIdentity: GNUNET_PeerIdentity
+ discard GNUNET_CRYPTO_eddsa_public_key_from_string(peer, #FIXME: don't
discard
+ peer.len(),
+ addr
peerIdentity.public_key)
result = CadetChannel(handle: nil,
- peer: peer,
+ peer: peerIdentity,
messages: newFutureStream[seq[byte]]("createChannel"))
- let handlers = messageHandlers()
- result.handle = GNUNET_CADET_channel_create(h: handle.handle,
- channel_cls: addr result,
- destination: peer.peerId,
- port: portHash(port),
- options:
GNUNET_CADET_OPTION_DEFAULT,
- window_changes: nil,
- disconnects: channelDisconnectCb,
- handlers: handlers)
+ var handlers = messageHandlers()
+ var port = hashString(port)
+ result.handle = GNUNET_CADET_channel_create(handle.handle,
+ addr result,
+ addr result.peer,
+ addr port,
+ GNUNET_CADET_OPTION_DEFAULT,
+ nil,
+ channelDisconnectCb,
+ addr handlers[0])
diff --git a/gnunet_cadet_service.nim b/gnunet_cadet_service.nim
index 458e9a8..5dc6e9a 100644
--- a/gnunet_cadet_service.nim
+++ b/gnunet_cadet_service.nim
@@ -10,7 +10,7 @@ else:
libname* = "libgnunetcadet.so"
import
- gnunet_types, gnunet_mq_lib, gnunet_configuration_lib
+ gnunet_types, gnunet_mq_lib, gnunet_crypto_lib, gnunet_configuration_lib
const
diff --git a/gnunet_nim.nim b/gnunet_nim.nim
index 27ecd1a..362ae81 100644
--- a/gnunet_nim.nim
+++ b/gnunet_nim.nim
@@ -1,90 +1,17 @@
-import gnunet_types
-import gnunet_scheduler_lib
-import gnunet_time_lib
-import gnunet_configuration_lib
+import gnunet_application
import asyncdispatch
-#import asynccadet
-import logging
-import tables
-
-type Scheduler = object
- timeoutUs: uint64
- gnunetTasks: Table[ptr GNUNET_SCHEDULER_Task, ptr GNUNET_SCHEDULER_FdInfo]
-
-proc microsecondsUntilTimeout(scheduler: Scheduler): int =
- ## get the duration until timeout in microseconds
- let now = GNUNET_TIME_absolute_get()
- if scheduler.timeoutUs < now.abs_value_us:
- return 0
- return int(scheduler.timeoutUs - now.abs_value_us)
-
-proc millisecondsUntilTimeout(scheduler: Scheduler): int =
- ## get the duration until timeout in milliseconds
- return scheduler.microsecondsUntilTimeout() div 1_000
-
-proc schedulerAdd(cls: pointer,
- task: ptr GNUNET_SCHEDULER_Task,
- fdi: ptr GNUNET_SCHEDULER_FdInfo): cint {.cdecl.} =
- ## callback allowing GNUnet to add a file descriptor to the event loop
- type AddProc = proc(fd: AsyncFD, cb: proc(fd: AsyncFD): bool)
- var scheduler = cast[ptr Scheduler](cls)
- let fd = AsyncFD(fdi.sock)
- proc addByInterest(interest: GNUNET_SCHEDULER_EventType, addProc: AddProc) :
bool =
- result = false
- if (cast[int](fdi.et) and cast[int](interest)) != 0:
- result = true
- if not getGlobalDispatcher().contains(fd):
- register(fd)
- proc callback(fd: AsyncFD): bool =
- result = true
- 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):
- scheduler.gnunetTasks.add(task, fdi)
- return GNUNET_OK
- error("Cannot add file descriptor because the event type is not supported")
- return GNUNET_SYSERR
-
-proc schedulerDelete(cls: pointer,
- task: ptr GNUNET_SCHEDULER_Task): cint {.cdecl.} =
- ## callback allowing GNUnet to delete a file descriptor from the event loop
- var scheduler = cast[ptr Scheduler](cls)
- var fdi: ptr GNUNET_SCHEDULER_FdInfo
- if scheduler.gnunetTasks.take(task, fdi):
- unregister(AsyncFD(fdi.sock))
- return GNUNET_OK
- error("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 scheduler = cast[ptr Scheduler](cls)
- scheduler.timeoutUs = dt.abs_value_us
+import asynccadet
proc main() =
- var scheduler = Scheduler(
- timeoutUs: GNUNET_TIME_absolute_get_forever().abs_value_us,
- gnunetTasks: initTable[ptr GNUNET_SCHEDULER_Task, ptr
GNUNET_SCHEDULER_FdInfo]()
- )
- var configHandle = GNUNET_CONFIGURATION_create()
- assert(GNUNET_SYSERR != GNUNET_CONFIGURATION_load(configHandle,
"gnunet.conf"))
- var driver = GNUNET_SCHEDULER_Driver(cls: addr scheduler,
- add: schedulerAdd,
- del: schedulerDelete,
- set_wakeup: schedulerSetWakeup)
- let schedulerHandle = GNUNET_SCHEDULER_driver_init(addr driver)
+ var gnunetApp = initGnunetApplication("~/.gnunet/gnunet.conf")
+ var cadet = gnunetApp.connectCadet()
try:
while true:
- poll(scheduler.millisecondsUntilTimeout())
- var work_result = GNUNET_SCHEDULER_do_work(schedulerHandle)
- echo "work_result: ", work_result
+ poll(gnunetApp.millisecondsUntilTimeout())
+ gnunetApp.doWork()
except ValueError:
discard
- GNUNET_SCHEDULER_driver_done(schedulerHandle)
- GNUNET_CONFIGURATION_destroy(configHandle)
+ gnunetApp.cleanup()
echo "quitting"
main()
diff --git a/gnunet_types.nim b/gnunet_types.nim
index 091042e..a92fdee 100644
--- a/gnunet_types.nim
+++ b/gnunet_types.nim
@@ -21,20 +21,20 @@ type
type
- GNUNET_HashCode* {.bycopy.} = object
- bits*: array[512 div 8 div sizeof((uint32)), uint32]
+ GNUNET_DISK_FileHandle* {.bycopy.} = object
+ fd*: cint
type
- GNUNET_PeerIdentity* {.bycopy.} = object
- public_key*: GNUNET_CRYPTO_EddsaPublicKey
+ GNUNET_NETWORK_Handle* {.bycopy.} = object
type
- GNUNET_DISK_FileHandle* {.bycopy.} = object
- fd*: cint
-
+ GNUNET_SCHEDULER_Priority* {.size: sizeof(cint).} = enum
+ GNUNET_SCHEDULER_PRIORITY_KEEP = 0, GNUNET_SCHEDULER_PRIORITY_IDLE = 1,
+ GNUNET_SCHEDULER_PRIORITY_BACKGROUND = 2,
+ GNUNET_SCHEDULER_PRIORITY_DEFAULT = 3, GNUNET_SCHEDULER_PRIORITY_HIGH = 4,
+ GNUNET_SCHEDULER_PRIORITY_UI = 5, GNUNET_SCHEDULER_PRIORITY_URGENT = 6,
+ GNUNET_SCHEDULER_PRIORITY_SHUTDOWN = 7, GNUNET_SCHEDULER_PRIORITY_COUNT = 8
-type
- GNUNET_NETWORK_Handle* {.bycopy.} = object
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet-nim] 56/61: gnunet_nim.nim: fix import paths to point to parent dir, (continued)
- [GNUnet-SVN] [gnunet-nim] 56/61: gnunet_nim.nim: fix import paths to point to parent dir, gnunet, 2019/04/13
- [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 <=
- [GNUnet-SVN] [gnunet-nim] 23/61: receiving of cadet messages possible now, gnunet, 2019/04/13
- [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