From 06f7a3df52ac7f5c1153f54ddccd7df9507790aa Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Mon, 21 May 2018 12:39:52 +0000 Subject: [PATCH 1/2] fix prototype --- include/llarp/exit_info.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/llarp/exit_info.h b/include/llarp/exit_info.h index bc507d53d..3243e4005 100644 --- a/include/llarp/exit_info.h +++ b/include/llarp/exit_info.h @@ -19,7 +19,7 @@ bool llarp_xi_bencode(struct llarp_xi *xi, llarp_buffer_t *buf); struct llarp_xi_list; -struct llarp_xi_list *llarp_xi_list_new(); +struct llarp_xi_list *llarp_xi_list_new(struct llarp_alloc * mem); void llarp_xi_list_free(struct llarp_xi_list **l); bool llarp_xi_list_bdecode(struct llarp_xi_list *l, llarp_buffer_t *buf); From 4e19ce8191c77219f7e8e1f8fcf93fd443714f50 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 21 May 2018 09:17:07 -0400 Subject: [PATCH 2/2] add buffer helper --- llarp/buffer.hpp | 22 ++++++++++++++++++++++ llarp/router.cpp | 12 ++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 llarp/buffer.hpp diff --git a/llarp/buffer.hpp b/llarp/buffer.hpp new file mode 100644 index 000000000..bf5d49a96 --- /dev/null +++ b/llarp/buffer.hpp @@ -0,0 +1,22 @@ +#ifndef LLARP_BUFFER_HPP +#define LLARP_BUFFER_HPP + +#include + +namespace llarp +{ + /** initialize llarp_buffer_t from stack allocated buffer */ + template + llarp_buffer_t StackBuffer(T & stack) + { + llarp_buffer_t buff; + buff.base = (char*) stack; + buff.cur = (char*) stack; + buff.sz = sizeof(stack); + return buff; + } +} + + + +#endif diff --git a/llarp/router.cpp b/llarp/router.cpp index b1ad4fe9e..88e7fe545 100644 --- a/llarp/router.cpp +++ b/llarp/router.cpp @@ -6,6 +6,7 @@ #include #include #include "str.hpp" +#include "buffer.hpp" #include @@ -67,10 +68,8 @@ bool llarp_router::SaveRC() printf(" OK.\n"); uint8_t tmp[MAX_RC_SIZE]; - llarp_buffer_t buf; - buf.base = (char*)tmp; - buf.cur = (char*) tmp; - buf.sz = sizeof(tmp); + auto buf = llarp::StackBuffer(tmp); + if(llarp_rc_bencode(&rc, &buf)) { std::ofstream f(our_rc_file, std::ios::binary); @@ -135,11 +134,8 @@ void llarp_run_router(struct llarp_router *router) { memcpy(router->rc.pubkey, router->pubkey(), 32); // sign router contact - llarp_buffer_t signbuf; char buf[MAX_RC_SIZE]; - signbuf.base = buf; - signbuf.cur = buf; - signbuf.sz = sizeof(buf); + auto signbuf = llarp::StackBuffer(buf); // encode if(llarp_rc_bencode(&router->rc, &signbuf)) {