Browse Source

don't copy received datagram

pull/1717/head
orignal 3 years ago
parent
commit
5d924cd35a
  1. 31
      libi2pd_client/SAM.cpp
  2. 6
      libi2pd_client/SAM.h

31
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 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -1115,19 +1115,9 @@ namespace client
if (ep) if (ep)
{ {
// udp forward enabled // udp forward enabled
size_t bsz = base64.size(); const char lf = '\n';
size_t sz = bsz + 1 + len; // send to remote endpoint, { destination, linefeed, payload }
// build datagram body m_Owner.SendTo({ {(const uint8_t *)base64.c_str(), base64.size()}, {(const uint8_t *)&lf, 1}, {buf, len} }, *ep);
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;
} }
else else
{ {
@ -1156,7 +1146,7 @@ namespace client
auto ep = session->UDPEndpoint; auto ep = session->UDPEndpoint;
if (ep) if (ep)
// udp forward enabled // udp forward enabled
m_Owner.SendTo(buf, len, ep); m_Owner.SendTo({ {buf, len} }, *ep);
else else
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
@ -1453,14 +1443,11 @@ namespace client
return list; return list;
} }
void SAMBridge::SendTo(const uint8_t * buf, size_t len, std::shared_ptr<boost::asio::ip::udp::endpoint> remote) void SAMBridge::SendTo (const std::vector<boost::asio::const_buffer>& bufs, const boost::asio::ip::udp::endpoint& ep)
{ {
if(remote) m_DatagramSocket.send_to (bufs, ep);
{ }
m_DatagramSocket.send_to(boost::asio::buffer(buf, len), *remote);
}
}
void SAMBridge::ReceiveDatagram () void SAMBridge::ReceiveDatagram ()
{ {
m_DatagramSocket.async_receive_from ( m_DatagramSocket.async_receive_from (

6
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 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -249,8 +249,8 @@ namespace client
std::list<std::shared_ptr<SAMSocket> > ListSockets(const std::string & id) const; std::list<std::shared_ptr<SAMSocket> > ListSockets(const std::string & id) const;
/** send raw data to remote endpoint from our UDP Socket */ /** send raw data to remote endpoint from our UDP Socket */
void SendTo(const uint8_t * buf, size_t len, std::shared_ptr<boost::asio::ip::udp::endpoint> remote); void SendTo (const std::vector<boost::asio::const_buffer>& bufs, const boost::asio::ip::udp::endpoint& ep);
void AddSocket(std::shared_ptr<SAMSocket> socket); void AddSocket(std::shared_ptr<SAMSocket> socket);
void RemoveSocket(const std::shared_ptr<SAMSocket> & socket); void RemoveSocket(const std::shared_ptr<SAMSocket> & socket);

Loading…
Cancel
Save