Browse Source

delete deprecated SendPacket

pull/93/head
orignal 10 years ago
parent
commit
2e1a8552bf
  1. 72
      Streaming.cpp
  2. 1
      Streaming.h

72
Streaming.cpp

@ -289,7 +289,8 @@ namespace stream
void Stream::SendQuickAck () void Stream::SendQuickAck ()
{ {
uint8_t packet[MAX_PACKET_SIZE]; Packet p;
uint8_t * packet = p.GetBuffer ();
size_t size = 0; size_t size = 0;
*(uint32_t *)(packet + size) = htobe32 (m_SendStreamID); *(uint32_t *)(packet + size) = htobe32 (m_SendStreamID);
size += 4; // sendStreamID size += 4; // sendStreamID
@ -306,9 +307,10 @@ namespace stream
size += 2; // flags size += 2; // flags
*(uint16_t *)(packet + size) = 0; // no options *(uint16_t *)(packet + size) = 0; // no options
size += 2; // options size size += 2; // options size
p.len = size;
if (SendPacket (packet, size)) std::vector<Packet *> { &p };
LogPrint ("Quick Ack sent"); LogPrint ("Quick Ack sent");
} }
void Stream::Close () void Stream::Close ()
@ -368,69 +370,17 @@ namespace stream
{ {
if (packet) if (packet)
{ {
bool ret = SendPacket (packet->GetBuffer (), packet->GetLength ()); SendPackets (std::vector<Packet *> { packet });
if (ret) bool isEmpty = m_SentPackets.empty ();
{ m_SentPackets.insert (packet);
bool isEmpty = m_SentPackets.empty (); if (isEmpty)
m_SentPackets.insert (packet); ScheduleResend ();
if (isEmpty) return true;
ScheduleResend ();
}
else
delete packet;
return ret;
} }
else else
return false; return false;
} }
bool Stream::SendPacket (const uint8_t * buf, size_t len)
{
if (!m_RemoteLeaseSet)
{
UpdateCurrentRemoteLease ();
if (!m_RemoteLeaseSet)
{
LogPrint ("Can't send packet. Missing remote LeaseSet");
return false;
}
}
I2NPMessage * leaseSet = nullptr;
if (m_LeaseSetUpdated)
{
leaseSet = m_LocalDestination->GetLeaseSetMsg ();
m_LeaseSetUpdated = false;
}
I2NPMessage * msg = i2p::garlic::routing.WrapMessage (*m_RemoteLeaseSet,
CreateDataMessage (this, buf, len), leaseSet);
auto outboundTunnel = m_LocalDestination->GetTunnelPool ()->GetNextOutboundTunnel ();
if (outboundTunnel)
{
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
if (ts >= m_CurrentRemoteLease.endDate)
UpdateCurrentRemoteLease ();
if (ts < m_CurrentRemoteLease.endDate)
{
outboundTunnel->SendTunnelDataMsg (m_CurrentRemoteLease.tunnelGateway, m_CurrentRemoteLease.tunnelID, msg);
return true;
}
else
{
LogPrint ("All leases are expired");
DeleteI2NPMessage (msg);
}
}
else
{
LogPrint ("No outbound tunnels in the pool");
DeleteI2NPMessage (msg);
}
return false;
}
void Stream::SendPackets (const std::vector<Packet *>& packets) void Stream::SendPackets (const std::vector<Packet *>& packets)
{ {
if (!m_RemoteLeaseSet) if (!m_RemoteLeaseSet)

1
Streaming.h

@ -103,7 +103,6 @@ namespace stream
void SendQuickAck (); void SendQuickAck ();
bool SendPacket (Packet * packet); bool SendPacket (Packet * packet);
bool SendPacket (const uint8_t * buf, size_t len); // TODO: remove
void SendPackets (const std::vector<Packet *>& packets); void SendPackets (const std::vector<Packet *>& packets);
void SavePacket (Packet * packet); void SavePacket (Packet * packet);

Loading…
Cancel
Save