[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-nim] 01/02: add peer ID string functions
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-nim] 01/02: add peer ID string functions |
Date: |
Wed, 08 Aug 2018 23:52:35 +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 5852e7b7bbc8ff5464d8dfd86d8d07f8fd49ceb0
Author: lurchi <address@hidden>
AuthorDate: Wed Aug 8 23:51:49 2018 +0200
add peer ID string functions
---
asynccadet.nim | 4 +-
gnunet_common.nim | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++
gnunet_crypto_lib.nim | 11 +---
gnunet_types.nim | 11 ----
gnunet_utils.nim | 13 +++++
5 files changed, 164 insertions(+), 23 deletions(-)
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/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