#include "Transports.h"
#include "TunnelBase.h"
namespace i2p
{
namespace tunnel
{
void TunnelTransportSender::SendMessagesTo (const i2p::data::IdentHash& to,
std::list<std::shared_ptr<I2NPMessage> >&& msgs)
{
if (msgs.empty ()) return;
auto currentTransport = m_CurrentTransport.lock ();
if (!currentTransport)
{
if (m_PendingTransport.valid ()) {
if (m_PendingTransport.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
currentTransport = m_PendingTransport.get (); if (currentTransport)
{
if (currentTransport->IsEstablished ())
m_CurrentTransport = currentTransport;
else
currentTransport = nullptr;
}
}
else {
i2p::transport::transports.SendMessages (to, std::move (msgs));
return;
}
}
}
if (currentTransport) currentTransport->SendI2NPMessages (msgs);
else m_PendingTransport = i2p::transport::transports.SendMessages (to, std::move (msgs));
}
void TunnelTransportSender::SendMessagesTo (const i2p::data::IdentHash& to,
std::list<std::shared_ptr<I2NPMessage> >& msgs)
{
std::list<std::shared_ptr<i2p::I2NPMessage> > msgs1;
msgs.swap (msgs1);
SendMessagesTo (to, std::move (msgs1));
}
void TunnelTransportSender::Reset ()
{
m_CurrentTransport.reset ();
if (m_PendingTransport.valid ())
m_PendingTransport = std::future<std::shared_ptr<i2p::transport::TransportSession> >();
}
}
}