[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] branch master updated (172522a -> 4eb7568)
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] branch master updated (172522a -> 4eb7568) |
Date: |
Wed, 08 Aug 2018 23:52:34 +0200 |
This is an automated email from the git hooks/post-receive script.
lurchi pushed a change to branch master
in repository gnunet-nim.
from 172522a Merge branch 'master' of ssh://gnunet.org/gnunet-nim
new 5852e7b add peer ID string functions
new 4eb7568 use peer IDs as chat identifiers
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
asynccadet.nim | 4 +-
examples/groupchat.nim | 16 ++++--
gnunet_common.nim | 148 +++++++++++++++++++++++++++++++++++++++++++++++++
gnunet_crypto_lib.nim | 11 +---
gnunet_types.nim | 11 ----
gnunet_utils.nim | 13 +++++
6 files changed, 174 insertions(+), 29 deletions(-)
create mode 100644 gnunet_common.nim
create mode 100644 gnunet_utils.nim
diff --git a/asynccadet.nim b/asynccadet.nim
index 409b636..92b421a 100644
--- a/asynccadet.nim
+++ b/asynccadet.nim
@@ -1,7 +1,7 @@
import
gnunet_cadet_service, gnunet_types, gnunet_mq_lib, gnunet_crypto_lib,
gnunet_protocols, gnunet_scheduler_lib, gnunet_configuration_lib
import
- gnunet_application
+ gnunet_application, gnunet_utils
import
asyncdispatch, posix, tables, logging
@@ -16,7 +16,7 @@ type
CadetChannel* = object
handle: ptr GNUNET_CADET_Channel
- peer: GNUNET_PeerIdentity
+ peer*: GNUNET_PeerIdentity
messages*: FutureStream[string]
proc channelDisconnectCb(cls: pointer,
diff --git a/examples/groupchat.nim b/examples/groupchat.nim
index c2786b0..0ee3b9e 100644
--- a/examples/groupchat.nim
+++ b/examples/groupchat.nim
@@ -1,5 +1,5 @@
-import ../gnunet_application, ../asynccadet
-import asyncdispatch, asyncfile, parseopt, strutils
+import ../gnunet_application, ../asynccadet, ../gnunet_utils
+import asyncdispatch, asyncfile, parseopt, strutils, sequtils
type Chat = object
channels: seq[ref CadetChannel]
@@ -7,7 +7,7 @@ type Chat = object
proc publish(chat: ref Chat, message: string, sender: ref CadetChannel = nil) =
let message =
if sender.isNil(): message.strip(leading = false)
- else: "[Alice] " & message.strip(leading = false)
+ else: "[" & sender.peer.peerId() & "] " & message.strip(leading = false)
echo message
for c in chat.channels:
c.sendMessage(message)
@@ -52,14 +52,18 @@ proc firstTask(gnunetApp: ref GnunetApplication,
let (hasChannel, channel) = await cadetPort.channels.read()
if not hasChannel:
break
- chat.publish(message = "X joined\n")
+ let peerId = channel.peer.peerId()
+ chat.publish(message = peerId & " joined\n")
+ let listParticipants =
+ chat.channels.map(proc(c: ref CadetChannel): string = c.peer.peerId)
+ channel.sendMessage("Wlcome " & peerId & "! participants: " &
$listParticipants)
chat.channels.add(channel)
- channel.sendMessage("Welcome X! You are talking with: \n")
closureScope:
let channel = channel
+ let peerId = peerId
proc channelDisconnected(future: Future[void]) =
chat.channels.delete(chat.channels.find(channel))
- chat.publish(message = "X left\n")
+ chat.publish(message = peerId & " left\n")
processClientMessages(channel, chat).addCallback(channelDisconnected)
proc main() =
diff --git a/gnunet_common.nim b/gnunet_common.nim
new file mode 100644
index 0000000..be72fab
--- /dev/null
+++ b/gnunet_common.nim
@@ -0,0 +1,148 @@
+ {.deadCodeElim: on.}
+when defined(windows):
+ const
+ libname* = "libgnunetcadet.dll"
+elif defined(macosx):
+ const
+ libname* = "libgnunetcadet.dylib"
+else:
+ const
+ libname* = "libgnunetcadet.so"
+
+
+import gnunet_crypto_lib, gnunet_types
+
+type
+ GNUNET_FileNameCallback* = proc (cls: pointer; filename: cstring): cint
{.cdecl.}
+
+
+type
+ GNUNET_ContinuationCallback* = proc (cls: pointer) {.cdecl.}
+
+
+type
+ GNUNET_ResultCallback* = proc (cls: pointer; result_code: int64; data:
pointer;
+ data_size: uint16) {.cdecl.}
+
+
+type
+ GNUNET_ErrorType* {.size: sizeof(cint).} = enum
+ GNUNET_ERROR_TYPE_UNSPECIFIED = -1, GNUNET_ERROR_TYPE_NONE = 0,
+ GNUNET_ERROR_TYPE_ERROR = 1, GNUNET_ERROR_TYPE_WARNING = 2,
+ GNUNET_ERROR_TYPE_MESSAGE = 4, GNUNET_ERROR_TYPE_INFO = 8,
+ GNUNET_ERROR_TYPE_DEBUG = 16, GNUNET_ERROR_TYPE_INVALID = 32,
+ GNUNET_ERROR_TYPE_BULK = 64
+
+
+
+type
+ GNUNET_Logger* = proc (cls: pointer; kind: GNUNET_ErrorType; component:
cstring;
+ date: cstring; message: cstring) {.cdecl.}
+
+
+proc GNUNET_get_log_skip*(): cint {.cdecl, importc: "GNUNET_get_log_skip",
+ dynlib: libname.}
+when not defined(GNUNET_CULL_LOGGING):
+ proc GNUNET_get_log_call_status*(caller_level: cint; comp: cstring; file:
cstring;
+ function: cstring; line: cint): cint {.cdecl,
+ importc: "GNUNET_get_log_call_status", dynlib: libname.}
+
+proc GNUNET_log_from_nocheck*(kind: GNUNET_ErrorType; comp: cstring; message:
cstring) {.
+ varargs, cdecl, importc: "GNUNET_log_from_nocheck", dynlib: libname.}
+
+proc GNUNET_log_config_missing*(kind: GNUNET_ErrorType; section: cstring;
+ option: cstring) {.cdecl,
+ importc: "GNUNET_log_config_missing", dynlib: libname.}
+
+proc GNUNET_log_config_invalid*(kind: GNUNET_ErrorType; section: cstring;
+ option: cstring; required: cstring) {.cdecl,
+ importc: "GNUNET_log_config_invalid", dynlib: libname.}
+
+proc GNUNET_log_skip*(n: cint; check_reset: cint) {.cdecl, importc:
"GNUNET_log_skip",
+ dynlib: libname.}
+
+proc GNUNET_log_setup*(comp: cstring; loglevel: cstring; logfile: cstring):
cint {.
+ cdecl, importc: "GNUNET_log_setup", dynlib: libname.}
+
+proc GNUNET_logger_add*(logger: GNUNET_Logger; logger_cls: pointer) {.cdecl,
+ importc: "GNUNET_logger_add", dynlib: libname.}
+
+proc GNUNET_logger_remove*(logger: GNUNET_Logger; logger_cls: pointer) {.cdecl,
+ importc: "GNUNET_logger_remove", dynlib: libname.}
+
+proc GNUNET_sh2s*(shc: ptr GNUNET_ShortHashCode): cstring {.cdecl,
+ importc: "GNUNET_sh2s", dynlib: libname.}
+
+proc GNUNET_h2s*(hc: ptr GNUNET_HashCode): cstring {.cdecl, importc:
"GNUNET_h2s",
+ dynlib: libname.}
+
+proc GNUNET_h2s2*(hc: ptr GNUNET_HashCode): cstring {.cdecl, importc:
"GNUNET_h2s2",
+ dynlib: libname.}
+
+proc GNUNET_h2s_full*(hc: ptr GNUNET_HashCode): cstring {.cdecl,
+ importc: "GNUNET_h2s_full", dynlib: libname.}
+
+type
+ GNUNET_CRYPTO_EddsaPublicKey* {.bycopy.} = object
+
+
+
+type
+ GNUNET_CRYPTO_EcdhePublicKey* {.bycopy.} = object
+
+
+
+proc GNUNET_p2s*(p: ptr GNUNET_CRYPTO_EddsaPublicKey): cstring {.cdecl,
+ importc: "GNUNET_p2s", dynlib: libname.}
+
+proc GNUNET_p2s2*(p: ptr GNUNET_CRYPTO_EddsaPublicKey): cstring {.cdecl,
+ importc: "GNUNET_p2s2", dynlib: libname.}
+
+proc GNUNET_e2s*(p: ptr GNUNET_CRYPTO_EcdhePublicKey): cstring {.cdecl,
+ importc: "GNUNET_e2s", dynlib: libname.}
+
+proc GNUNET_e2s2*(p: ptr GNUNET_CRYPTO_EcdhePublicKey): cstring {.cdecl,
+ importc: "GNUNET_e2s2", dynlib: libname.}
+
+proc GNUNET_i2s*(pid: ptr GNUNET_PeerIdentity): cstring {.cdecl,
+ importc: "GNUNET_i2s", dynlib: libname.}
+
+proc GNUNET_i2s2*(pid: ptr GNUNET_PeerIdentity): cstring {.cdecl,
+ importc: "GNUNET_i2s2", dynlib: libname.}
+
+proc GNUNET_i2s_full*(pid: ptr GNUNET_PeerIdentity): cstring {.cdecl,
+ importc: "GNUNET_i2s_full", dynlib: libname.}
+
+proc GNUNET_error_type_to_string*(kind: GNUNET_ErrorType): cstring {.cdecl,
+ importc: "GNUNET_error_type_to_string", dynlib: libname.}
+
+proc GNUNET_htonll*(n: uint64): uint64 {.cdecl, importc: "GNUNET_htonll",
+ dynlib: libname.}
+
+proc GNUNET_ntohll*(n: uint64): uint64 {.cdecl, importc: "GNUNET_ntohll",
+ dynlib: libname.}
+
+proc GNUNET_hton_double*(d: cdouble): cdouble {.cdecl, importc:
"GNUNET_hton_double",
+ dynlib: libname.}
+
+proc GNUNET_ntoh_double*(d: cdouble): cdouble {.cdecl, importc:
"GNUNET_ntoh_double",
+ dynlib: libname.}
+
+proc GNUNET_snprintf*(buf: cstring; size: csize; format: cstring): cint
{.varargs, cdecl,
+ importc: "GNUNET_snprintf", dynlib: libname.}
+
+proc GNUNET_asprintf*(buf: cstringArray; format: cstring): cint {.varargs,
cdecl,
+ importc: "GNUNET_asprintf", dynlib: libname.}
+
+proc GNUNET_copy_message*(msg: ptr GNUNET_MessageHeader): ptr
GNUNET_MessageHeader {.
+ cdecl, importc: "GNUNET_copy_message", dynlib: libname.}
+
+type
+ 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
+
+
diff --git a/gnunet_crypto_lib.nim b/gnunet_crypto_lib.nim
index 5b98536..01506ee 100644
--- a/gnunet_crypto_lib.nim
+++ b/gnunet_crypto_lib.nim
@@ -21,10 +21,7 @@ type
bits*: array[256 div 8 div sizeof((uint32)), uint32]
-
-import
- gnunet_types, gnunet_configuration_lib
-
+import gnunet_configuration_lib
const
GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH* = 126
@@ -242,12 +239,6 @@ type
-proc GNUNET_CRYPTO_hash_file*(priority: GNUNET_SCHEDULER_Priority;
- filename: cstring; blocksize: csize;
- callback: GNUNET_CRYPTO_HashCompletedCallback;
- callback_cls: pointer): ptr
GNUNET_CRYPTO_FileHashContext {.
- cdecl, importc: "GNUNET_CRYPTO_hash_file", dynlib: libname.}
-
proc GNUNET_CRYPTO_hash_file_cancel*(fhc: ptr GNUNET_CRYPTO_FileHashContext) {.
cdecl, importc: "GNUNET_CRYPTO_hash_file_cancel", dynlib: libname.}
diff --git a/gnunet_types.nim b/gnunet_types.nim
index a92fdee..9ff6773 100644
--- a/gnunet_types.nim
+++ b/gnunet_types.nim
@@ -27,14 +27,3 @@ type
type
GNUNET_NETWORK_Handle* {.bycopy.} = object
-
-
-type
- 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
-
-
diff --git a/gnunet_utils.nim b/gnunet_utils.nim
new file mode 100644
index 0000000..b74ad60
--- /dev/null
+++ b/gnunet_utils.nim
@@ -0,0 +1,13 @@
+import gnunet_common, gnunet_crypto_lib
+
+proc peerId*(peer: GNUNET_PeerIdentity): string =
+ let peerId = GNUNET_i2s(unsafeAddr peer)
+ let peerIdLen = peerId.len()
+ result = newString(peerIdLen)
+ copyMem(addr result[0], peerId, peerIdLen)
+
+proc fullPeerId*(peer: GNUNET_PeerIdentity): string =
+ let peerId = GNUNET_i2s_full(unsafeAddr peer)
+ let peerIdLen = peerId.len()
+ result = newString(peerIdLen)
+ copyMem(addr result[0], peerId, peerIdLen)
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet-nim] branch master updated (172522a -> 4eb7568),
gnunet <=