diff --git a/Makefile b/Makefile index 74f4fbf66..031807c6d 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,9 @@ BUILD_ROOT = $(REPO)/build CONFIG_CMD = $(shell /bin/echo -n "cd '$(BUILD_ROOT)' && " ; /bin/echo -n "cmake -DUSE_LIBABYSS=$(JSONRPC) '$(REPO)'") +SCAN_BUILD ?= scan-build +ANALYZE_CMD = $(shell /bin/echo -n "cd '$(BUILD_ROOT)' && " ; /bin/echo -n "$(SCAN_BUILD) cmake -DUSE_LIBABYSS=$(JSONRPC) '$(REPO)' && cd '$(BUILD_ROOT)' && $(SCAN_BUILD) $(MAKE)") + TARGETS = $(REPO)/lokinet SIGS = $(TARGETS:=.sig) EXE = $(BUILD_ROOT)/lokinet @@ -126,6 +129,9 @@ abyss: debug format: clang-format -i $$(find daemon llarp include | grep -E '\.[h,c](pp)?$$') +analyze: + $(ANALYZE_CMD) + lint: $(LINT_CHECK) %.cpp-check: %.cpp diff --git a/llarp/ev.cpp b/llarp/ev.cpp index ae5a53a4a..e70eec782 100644 --- a/llarp/ev.cpp +++ b/llarp/ev.cpp @@ -120,17 +120,16 @@ bool llarp_tcp_conn_async_write(struct llarp_tcp_conn *conn, const void *pkt, size_t sz) { - constexpr size_t buffsz = llarp::ev_io::WriteBuffer::BufferSize; const byte_t *ptr = (const byte_t *)pkt; llarp::tcp_conn *impl = static_cast< llarp::tcp_conn * >(conn->impl); if(impl->_shouldClose) return false; - while(sz > buffsz) + while(sz > EV_WRITE_BUF_SZ) { - if(!impl->queue_write((const byte_t *)ptr, buffsz)) + if(!impl->queue_write((const byte_t *)ptr, EV_WRITE_BUF_SZ)) return false; - ptr += buffsz; - sz -= buffsz; + ptr += EV_WRITE_BUF_SZ; + sz -= EV_WRITE_BUF_SZ; } return impl->queue_write(ptr, sz); } @@ -163,8 +162,11 @@ llarp_tcp_acceptor_close(struct llarp_tcp_acceptor *tcp) bool llarp_ev_tun_async_write(struct llarp_tun_io *tun, const void *buf, size_t sz) { - if(sz > llarp::ev_io::WriteBuffer::BufferSize) + if(sz > EV_WRITE_BUF_SZ) + { + llarp::LogWarn("packet too big, ", sz, " > ", EV_WRITE_BUF_SZ); return false; + } return static_cast< llarp::ev_io * >(tun->impl)->queue_write( (const byte_t *)buf, sz); } diff --git a/llarp/ev.hpp b/llarp/ev.hpp index 8c04f0030..5c932e425 100644 --- a/llarp/ev.hpp +++ b/llarp/ev.hpp @@ -22,17 +22,20 @@ #ifndef EV_READ_BUF_SZ #define EV_READ_BUF_SZ (4 * 1024) #endif +#ifndef EV_WRITE_BUF_SZ +#define EV_WRITE_BUF_SZ (2 * 1024) +#endif namespace llarp { struct ev_io - { + { struct WriteBuffer { - static constexpr size_t BufferSize = 2048; + llarp_time_t timestamp = 0; size_t bufsz; - byte_t buf[BufferSize]; + byte_t buf[EV_WRITE_BUF_SZ]; WriteBuffer() = default;