From 5d924cd35ace95da626bd5fc374de6bcc2f1c384 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 4 Dec 2021 19:32:18 -0500 Subject: [PATCH] don't copy received datagram --- libi2pd_client/SAM.cpp | 31 +++++++++---------------------- libi2pd_client/SAM.h | 6 +++--- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/libi2pd_client/SAM.cpp b/libi2pd_client/SAM.cpp index d58a5128..d5c62d79 100644 --- a/libi2pd_client/SAM.cpp +++ b/libi2pd_client/SAM.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2020, The PurpleI2P Project +* Copyright (c) 2013-2021, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -1115,19 +1115,9 @@ namespace client if (ep) { // udp forward enabled - size_t bsz = base64.size(); - size_t sz = bsz + 1 + len; - // build datagram body - uint8_t * data = new uint8_t[sz]; - // Destination - memcpy(data, base64.c_str(), bsz); - // linefeed - data[bsz] = '\n'; - // Payload - memcpy(data+bsz+1, buf, len); - // send to remote endpoint - m_Owner.SendTo(data, sz, ep); - delete [] data; + const char lf = '\n'; + // send to remote endpoint, { destination, linefeed, payload } + m_Owner.SendTo({ {(const uint8_t *)base64.c_str(), base64.size()}, {(const uint8_t *)&lf, 1}, {buf, len} }, *ep); } else { @@ -1156,7 +1146,7 @@ namespace client auto ep = session->UDPEndpoint; if (ep) // udp forward enabled - m_Owner.SendTo(buf, len, ep); + m_Owner.SendTo({ {buf, len} }, *ep); else { #ifdef _MSC_VER @@ -1453,14 +1443,11 @@ namespace client return list; } - void SAMBridge::SendTo(const uint8_t * buf, size_t len, std::shared_ptr remote) + void SAMBridge::SendTo (const std::vector& bufs, const boost::asio::ip::udp::endpoint& ep) { - if(remote) - { - m_DatagramSocket.send_to(boost::asio::buffer(buf, len), *remote); - } - } - + m_DatagramSocket.send_to (bufs, ep); + } + void SAMBridge::ReceiveDatagram () { m_DatagramSocket.async_receive_from ( diff --git a/libi2pd_client/SAM.h b/libi2pd_client/SAM.h index a969b76c..c18ec46a 100644 --- a/libi2pd_client/SAM.h +++ b/libi2pd_client/SAM.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2020, The PurpleI2P Project +* Copyright (c) 2013-2021, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -249,8 +249,8 @@ namespace client std::list > ListSockets(const std::string & id) const; /** send raw data to remote endpoint from our UDP Socket */ - void SendTo(const uint8_t * buf, size_t len, std::shared_ptr remote); - + void SendTo (const std::vector& bufs, const boost::asio::ip::udp::endpoint& ep); + void AddSocket(std::shared_ptr socket); void RemoveSocket(const std::shared_ptr & socket);