Browse Source

pass destination by reference

pull/102/head
orignal 10 years ago
parent
commit
d5c26316df
  1. 6
      Destination.cpp
  2. 24
      Streaming.cpp
  3. 8
      Streaming.h

6
Destination.cpp

@ -121,7 +121,7 @@ namespace stream @@ -121,7 +121,7 @@ namespace stream
Stream * StreamingDestination::CreateNewOutgoingStream (const i2p::data::LeaseSet& remote)
{
Stream * s = new Stream (m_Service, this, remote);
Stream * s = new Stream (m_Service, *this, remote);
std::unique_lock<std::mutex> l(m_StreamsMutex);
m_Streams[s->GetRecvStreamID ()] = s;
return s;
@ -129,7 +129,7 @@ namespace stream @@ -129,7 +129,7 @@ namespace stream
Stream * StreamingDestination::CreateNewIncomingStream ()
{
Stream * s = new Stream (m_Service, this);
Stream * s = new Stream (m_Service, *this);
std::unique_lock<std::mutex> l(m_StreamsMutex);
m_Streams[s->GetRecvStreamID ()] = s;
return s;
@ -320,7 +320,7 @@ namespace stream @@ -320,7 +320,7 @@ namespace stream
void StreamingDestinations::DeleteStream (Stream * stream)
{
if (stream)
stream->GetLocalDestination ()->DeleteStream (stream);
stream->GetLocalDestination ().DeleteStream (stream);
}
StreamingDestination * StreamingDestinations::FindLocalDestination (const i2p::data::IdentHash& destination) const

24
Streaming.cpp

@ -10,7 +10,7 @@ namespace i2p @@ -10,7 +10,7 @@ namespace i2p
{
namespace stream
{
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local,
Stream::Stream (boost::asio::io_service& service, StreamingDestination& local,
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
m_LeaseSetUpdated (true), m_LocalDestination (local), m_RemoteLeaseSet (&remote),
@ -20,7 +20,7 @@ namespace stream @@ -20,7 +20,7 @@ namespace stream
UpdateCurrentRemoteLease ();
}
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local):
Stream::Stream (boost::asio::io_service& service, StreamingDestination& local):
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
m_IsOpen (false), m_LeaseSetUpdated (true), m_LocalDestination (local),
m_RemoteLeaseSet (nullptr), m_RoutingSession (nullptr),
@ -102,7 +102,7 @@ namespace stream @@ -102,7 +102,7 @@ namespace stream
{
// we have received duplicate. Most likely our outbound tunnel is dead
LogPrint ("Duplicate message ", receivedSeqn, " received");
m_LocalDestination->ResetCurrentOutboundTunnel (); // pick another outbound tunnel
m_LocalDestination.ResetCurrentOutboundTunnel (); // pick another outbound tunnel
UpdateCurrentRemoteLease (); // pick another lease
SendQuickAck (); // resend ack for previous message again
delete packet; // packet dropped
@ -259,11 +259,11 @@ namespace stream @@ -259,11 +259,11 @@ namespace stream
if (isNoAck) flags |= PACKET_FLAG_NO_ACK;
*(uint16_t *)(packet + size) = htobe16 (flags);
size += 2; // flags
size_t identityLen = m_LocalDestination->GetIdentity ().GetFullLen ();
size_t signatureLen = m_LocalDestination->GetIdentity ().GetSignatureLen ();
size_t identityLen = m_LocalDestination.GetIdentity ().GetFullLen ();
size_t signatureLen = m_LocalDestination.GetIdentity ().GetSignatureLen ();
*(uint16_t *)(packet + size) = htobe16 (identityLen + signatureLen + 2); // identity + signature + packet size
size += 2; // options size
m_LocalDestination->GetIdentity ().ToBuffer (packet + size, identityLen);
m_LocalDestination.GetIdentity ().ToBuffer (packet + size, identityLen);
size += identityLen; // from
*(uint16_t *)(packet + size) = htobe16 (STREAMING_MTU);
size += 2; // max packet size
@ -276,7 +276,7 @@ namespace stream @@ -276,7 +276,7 @@ namespace stream
buf += sentLen;
len -= sentLen;
size += sentLen; // payload
m_LocalDestination->Sign (packet, size, signature);
m_LocalDestination.Sign (packet, size, signature);
}
else
{
@ -347,13 +347,13 @@ namespace stream @@ -347,13 +347,13 @@ namespace stream
size++; // resend delay
*(uint16_t *)(packet + size) = htobe16 (PACKET_FLAG_CLOSE | PACKET_FLAG_SIGNATURE_INCLUDED);
size += 2; // flags
size_t signatureLen = m_LocalDestination->GetIdentity ().GetSignatureLen ();
size_t signatureLen = m_LocalDestination.GetIdentity ().GetSignatureLen ();
*(uint16_t *)(packet + size) = htobe16 (signatureLen); // signature only
size += 2; // options size
uint8_t * signature = packet + size;
memset (packet + size, 0, signatureLen);
size += signatureLen; // signature
m_LocalDestination->Sign (packet, size, signature);
m_LocalDestination.Sign (packet, size, signature);
p->len = size;
SendPacket (p);
@ -413,7 +413,7 @@ namespace stream @@ -413,7 +413,7 @@ namespace stream
const i2p::data::LeaseSet * leaseSet = nullptr;
if (m_LeaseSetUpdated)
{
leaseSet = m_LocalDestination->GetLeaseSet ();
leaseSet = m_LocalDestination.GetLeaseSet ();
m_LeaseSetUpdated = false;
}
@ -436,7 +436,7 @@ namespace stream @@ -436,7 +436,7 @@ namespace stream
});
leaseSet = nullptr; // send leaseSet only one time
}
m_LocalDestination->SendTunnelDataMsgs (msgs);
m_LocalDestination.SendTunnelDataMsgs (msgs);
}
else
LogPrint ("All leases are expired");
@ -469,7 +469,7 @@ namespace stream @@ -469,7 +469,7 @@ namespace stream
}
if (packets.size () > 0)
{
m_LocalDestination->ResetCurrentOutboundTunnel (); // pick another outbound tunnel
m_LocalDestination.ResetCurrentOutboundTunnel (); // pick another outbound tunnel
UpdateCurrentRemoteLease (); // pick another lease
SendPackets (packets);
}

8
Streaming.h

@ -77,8 +77,8 @@ namespace stream @@ -77,8 +77,8 @@ namespace stream
{
public:
Stream (boost::asio::io_service& service, StreamingDestination * local, const i2p::data::LeaseSet& remote); // outgoing
Stream (boost::asio::io_service& service, StreamingDestination * local); // incoming
Stream (boost::asio::io_service& service, StreamingDestination& local, const i2p::data::LeaseSet& remote); // outgoing
Stream (boost::asio::io_service& service, StreamingDestination& local); // incoming
~Stream ();
uint32_t GetSendStreamID () const { return m_SendStreamID; };
@ -87,7 +87,7 @@ namespace stream @@ -87,7 +87,7 @@ namespace stream
const i2p::data::IdentityEx& GetRemoteIdentity () const { return m_RemoteIdentity; };
bool IsOpen () const { return m_IsOpen; };
bool IsEstablished () const { return m_SendStreamID; };
StreamingDestination * GetLocalDestination () { return m_LocalDestination; };
StreamingDestination& GetLocalDestination () { return m_LocalDestination; };
void HandleNextPacket (Packet * packet);
size_t Send (const uint8_t * buf, size_t len);
@ -124,7 +124,7 @@ namespace stream @@ -124,7 +124,7 @@ namespace stream
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
int32_t m_LastReceivedSequenceNumber;
bool m_IsOpen, m_LeaseSetUpdated;
StreamingDestination * m_LocalDestination;
StreamingDestination& m_LocalDestination;
i2p::data::IdentityEx m_RemoteIdentity;
const i2p::data::LeaseSet * m_RemoteLeaseSet;
i2p::garlic::GarlicRoutingSession * m_RoutingSession;

Loading…
Cancel
Save