tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit fed0429355edea309d795101fa670b12d81a3ece
parent c1244f4e38f1d46d25d10688a8ea921cac7cc8ba
Author: parazyd <parazyd@dyne.org>
Date:   Mon, 29 Oct 2018 14:23:00 +0100

Add the Zenroom dependency and implement a ZenroomExec wrapper.

Diffstat:
MREADME.md | 13+++++++++++++
Mpkg/damlib/helpers.go | 11+++++++++++
Apkg/damlib/zenroom.h | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -25,6 +25,7 @@ github.com/go-redis/redis ``` #### Python 3 + ``` https://stem.torproject.org/ ``` @@ -46,3 +47,15 @@ to create hidden services and retrieve hidden service descriptors. Redis is our storage backend where information about nodes is held. Working configurations are provided in the `contrib` directory. + + +#### Zenroom + +``` +https://github.com/decodeproject/zenroom +``` + +The shared library can be acquired by cloning the above repository and +running `make linux-go`, which will compile a `.so` located in +`build/go/libzenroomgo.so`. You will then need to install it on your +system to a place such as `/usr/lib/`. diff --git a/pkg/damlib/helpers.go b/pkg/damlib/helpers.go @@ -20,6 +20,12 @@ package damlib * along with this source code. If not, see <http://www.gnu.org/licenses/>. */ +// #cgo LDFLAGS: -lzenroomgo +// +// #include <stdlib.h> +// #include "zenroom.h" +import "C" + import ( "bytes" "compress/gzip" @@ -79,3 +85,8 @@ func ParseDirs(sl []string, data []byte) []string { } return sl } + +func ZenroomExec(script, conf, keys, data string, verbosity int) int { + return int(C.zenroom_exec(C.CString(script), C.CString(conf), + C.CString(keys), C.CString(data), C.int(verbosity))) +} diff --git a/pkg/damlib/zenroom.h b/pkg/damlib/zenroom.h @@ -0,0 +1,103 @@ +/* Zenroom (DECODE project) + * + * (c) Copyright 2017-2018 Dyne.org foundation + * designed, written and maintained by Denis Roio <jaromil@dyne.org> + * + * This source code is free software; you can redistribute it and/or + * modify it under the terms of the GNU Public License as published + * by the Free Software Foundation; either version 3 of the License, + * or (at your option) any later version. + * + * This source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * Please refer to the GNU Public License for more details. + * + * You should have received a copy of the GNU Public License along + * with this source code; if not, write to: Free Software Foundation, + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __ZENROOM_H__ +#define __ZENROOM_H__ + +///////////////////////////////////////// +// high level api: one simple call + +int zenroom_exec(char *script, char *conf, char *keys, + char *data, int verbosity); + +// in case buffers should be used instead of stdout/err file +// descriptors, this call defines where to print out the output and +// the maximum sizes allowed for it. Output is NULL terminated. +int zenroom_exec_tobuf(char *script, char *conf, char *keys, + char *data, int verbosity, + char *stdout_buf, size_t stdout_len, + char *stderr_buf, size_t stderr_len); + +// to obtain the Abstract Syntax Tree (AST) of a script +// (output is in metalua formatted as JSON) +int zenroom_parse_ast(char *script, int verbosity, + char *stdout_buf, size_t stdout_len, + char *stderr_buf, size_t stderr_len); + +void set_debug(int lev); + +//////////////////////////////////////// + + +// lower level api: init (exec_line*) teardown + +// heap initialised by the memory manager +typedef struct { + void* (*malloc)(size_t size); + void* (*realloc)(void *ptr, size_t size); + void (*free)(void *ptr); + void* (*sys_malloc)(size_t size); + void* (*sys_realloc)(void *ptr, size_t size); + void (*sys_free)(void *ptr); + char *heap; + size_t heap_size; +} zen_mem_t; + +// zenroom context, also available as "_Z" global in lua space +// contents are opaque in lua and available only as lightuserdata +typedef struct { + void *lua; // (lua_State*) + zen_mem_t *mem; // memory manager heap + + char *stdout_buf; + size_t stdout_len; + size_t stdout_pos; + char *stderr_buf; + size_t stderr_len; + size_t stderr_pos; + + int errorlevel; + void *userdata; // anything passed at init (reserved for caller) +} zenroom_t; + + +zenroom_t *zen_init(const char *conf, char *keys, char *data); +int zen_exec_script(zenroom_t *Z, const char *script); +void zen_teardown(zenroom_t *zenroom); + +#define UMM_HEAP (64*1024) // 64KiB (masked with 0x7fff) +#define MAX_FILE (64*1024) // load max 64KiB files +#ifndef MAX_STRING +#define MAX_STRING 4097 // max 4KiB strings +#endif +#define MAX_OCTET 2049 // max 2KiB octets + +#define LUA_BASELIBNAME "_G" + +#define ZEN_BITS 8 +#ifndef SIZE_MAX +#if ZEN_BITS == 32 +#define SIZE_MAX 4294967296 +#elif ZEN_BITS == 8 +#define SIZE_MAX 65536 +#endif +#endif + +#endif