mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
pass destination by reference
This commit is contained in:
parent
3de29143bc
commit
d5c26316df
|
@ -121,7 +121,7 @@ namespace stream
|
||||||
|
|
||||||
Stream * StreamingDestination::CreateNewOutgoingStream (const i2p::data::LeaseSet& remote)
|
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);
|
std::unique_lock<std::mutex> l(m_StreamsMutex);
|
||||||
m_Streams[s->GetRecvStreamID ()] = s;
|
m_Streams[s->GetRecvStreamID ()] = s;
|
||||||
return s;
|
return s;
|
||||||
|
@ -129,7 +129,7 @@ namespace stream
|
||||||
|
|
||||||
Stream * StreamingDestination::CreateNewIncomingStream ()
|
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);
|
std::unique_lock<std::mutex> l(m_StreamsMutex);
|
||||||
m_Streams[s->GetRecvStreamID ()] = s;
|
m_Streams[s->GetRecvStreamID ()] = s;
|
||||||
return s;
|
return s;
|
||||||
|
@ -320,7 +320,7 @@ namespace stream
|
||||||
void StreamingDestinations::DeleteStream (Stream * stream)
|
void StreamingDestinations::DeleteStream (Stream * stream)
|
||||||
{
|
{
|
||||||
if (stream)
|
if (stream)
|
||||||
stream->GetLocalDestination ()->DeleteStream (stream);
|
stream->GetLocalDestination ().DeleteStream (stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination * StreamingDestinations::FindLocalDestination (const i2p::data::IdentHash& destination) const
|
StreamingDestination * StreamingDestinations::FindLocalDestination (const i2p::data::IdentHash& destination) const
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace stream
|
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),
|
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
||||||
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
|
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
|
||||||
m_LeaseSetUpdated (true), m_LocalDestination (local), m_RemoteLeaseSet (&remote),
|
m_LeaseSetUpdated (true), m_LocalDestination (local), m_RemoteLeaseSet (&remote),
|
||||||
|
@ -20,7 +20,7 @@ namespace stream
|
||||||
UpdateCurrentRemoteLease ();
|
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_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
|
||||||
m_IsOpen (false), m_LeaseSetUpdated (true), m_LocalDestination (local),
|
m_IsOpen (false), m_LeaseSetUpdated (true), m_LocalDestination (local),
|
||||||
m_RemoteLeaseSet (nullptr), m_RoutingSession (nullptr),
|
m_RemoteLeaseSet (nullptr), m_RoutingSession (nullptr),
|
||||||
|
@ -102,7 +102,7 @@ namespace stream
|
||||||
{
|
{
|
||||||
// we have received duplicate. Most likely our outbound tunnel is dead
|
// we have received duplicate. Most likely our outbound tunnel is dead
|
||||||
LogPrint ("Duplicate message ", receivedSeqn, " received");
|
LogPrint ("Duplicate message ", receivedSeqn, " received");
|
||||||
m_LocalDestination->ResetCurrentOutboundTunnel (); // pick another outbound tunnel
|
m_LocalDestination.ResetCurrentOutboundTunnel (); // pick another outbound tunnel
|
||||||
UpdateCurrentRemoteLease (); // pick another lease
|
UpdateCurrentRemoteLease (); // pick another lease
|
||||||
SendQuickAck (); // resend ack for previous message again
|
SendQuickAck (); // resend ack for previous message again
|
||||||
delete packet; // packet dropped
|
delete packet; // packet dropped
|
||||||
|
@ -259,11 +259,11 @@ namespace stream
|
||||||
if (isNoAck) flags |= PACKET_FLAG_NO_ACK;
|
if (isNoAck) flags |= PACKET_FLAG_NO_ACK;
|
||||||
*(uint16_t *)(packet + size) = htobe16 (flags);
|
*(uint16_t *)(packet + size) = htobe16 (flags);
|
||||||
size += 2; // flags
|
size += 2; // flags
|
||||||
size_t identityLen = m_LocalDestination->GetIdentity ().GetFullLen ();
|
size_t identityLen = m_LocalDestination.GetIdentity ().GetFullLen ();
|
||||||
size_t signatureLen = m_LocalDestination->GetIdentity ().GetSignatureLen ();
|
size_t signatureLen = m_LocalDestination.GetIdentity ().GetSignatureLen ();
|
||||||
*(uint16_t *)(packet + size) = htobe16 (identityLen + signatureLen + 2); // identity + signature + packet size
|
*(uint16_t *)(packet + size) = htobe16 (identityLen + signatureLen + 2); // identity + signature + packet size
|
||||||
size += 2; // options size
|
size += 2; // options size
|
||||||
m_LocalDestination->GetIdentity ().ToBuffer (packet + size, identityLen);
|
m_LocalDestination.GetIdentity ().ToBuffer (packet + size, identityLen);
|
||||||
size += identityLen; // from
|
size += identityLen; // from
|
||||||
*(uint16_t *)(packet + size) = htobe16 (STREAMING_MTU);
|
*(uint16_t *)(packet + size) = htobe16 (STREAMING_MTU);
|
||||||
size += 2; // max packet size
|
size += 2; // max packet size
|
||||||
|
@ -276,7 +276,7 @@ namespace stream
|
||||||
buf += sentLen;
|
buf += sentLen;
|
||||||
len -= sentLen;
|
len -= sentLen;
|
||||||
size += sentLen; // payload
|
size += sentLen; // payload
|
||||||
m_LocalDestination->Sign (packet, size, signature);
|
m_LocalDestination.Sign (packet, size, signature);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -347,13 +347,13 @@ namespace stream
|
||||||
size++; // resend delay
|
size++; // resend delay
|
||||||
*(uint16_t *)(packet + size) = htobe16 (PACKET_FLAG_CLOSE | PACKET_FLAG_SIGNATURE_INCLUDED);
|
*(uint16_t *)(packet + size) = htobe16 (PACKET_FLAG_CLOSE | PACKET_FLAG_SIGNATURE_INCLUDED);
|
||||||
size += 2; // flags
|
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
|
*(uint16_t *)(packet + size) = htobe16 (signatureLen); // signature only
|
||||||
size += 2; // options size
|
size += 2; // options size
|
||||||
uint8_t * signature = packet + size;
|
uint8_t * signature = packet + size;
|
||||||
memset (packet + size, 0, signatureLen);
|
memset (packet + size, 0, signatureLen);
|
||||||
size += signatureLen; // signature
|
size += signatureLen; // signature
|
||||||
m_LocalDestination->Sign (packet, size, signature);
|
m_LocalDestination.Sign (packet, size, signature);
|
||||||
|
|
||||||
p->len = size;
|
p->len = size;
|
||||||
SendPacket (p);
|
SendPacket (p);
|
||||||
|
@ -413,7 +413,7 @@ namespace stream
|
||||||
const i2p::data::LeaseSet * leaseSet = nullptr;
|
const i2p::data::LeaseSet * leaseSet = nullptr;
|
||||||
if (m_LeaseSetUpdated)
|
if (m_LeaseSetUpdated)
|
||||||
{
|
{
|
||||||
leaseSet = m_LocalDestination->GetLeaseSet ();
|
leaseSet = m_LocalDestination.GetLeaseSet ();
|
||||||
m_LeaseSetUpdated = false;
|
m_LeaseSetUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ namespace stream
|
||||||
});
|
});
|
||||||
leaseSet = nullptr; // send leaseSet only one time
|
leaseSet = nullptr; // send leaseSet only one time
|
||||||
}
|
}
|
||||||
m_LocalDestination->SendTunnelDataMsgs (msgs);
|
m_LocalDestination.SendTunnelDataMsgs (msgs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint ("All leases are expired");
|
LogPrint ("All leases are expired");
|
||||||
|
@ -469,7 +469,7 @@ namespace stream
|
||||||
}
|
}
|
||||||
if (packets.size () > 0)
|
if (packets.size () > 0)
|
||||||
{
|
{
|
||||||
m_LocalDestination->ResetCurrentOutboundTunnel (); // pick another outbound tunnel
|
m_LocalDestination.ResetCurrentOutboundTunnel (); // pick another outbound tunnel
|
||||||
UpdateCurrentRemoteLease (); // pick another lease
|
UpdateCurrentRemoteLease (); // pick another lease
|
||||||
SendPackets (packets);
|
SendPackets (packets);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,8 @@ namespace stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Stream (boost::asio::io_service& service, StreamingDestination * local, const i2p::data::LeaseSet& remote); // outgoing
|
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); // incoming
|
||||||
|
|
||||||
~Stream ();
|
~Stream ();
|
||||||
uint32_t GetSendStreamID () const { return m_SendStreamID; };
|
uint32_t GetSendStreamID () const { return m_SendStreamID; };
|
||||||
|
@ -87,7 +87,7 @@ namespace stream
|
||||||
const i2p::data::IdentityEx& GetRemoteIdentity () const { return m_RemoteIdentity; };
|
const i2p::data::IdentityEx& GetRemoteIdentity () const { return m_RemoteIdentity; };
|
||||||
bool IsOpen () const { return m_IsOpen; };
|
bool IsOpen () const { return m_IsOpen; };
|
||||||
bool IsEstablished () const { return m_SendStreamID; };
|
bool IsEstablished () const { return m_SendStreamID; };
|
||||||
StreamingDestination * GetLocalDestination () { return m_LocalDestination; };
|
StreamingDestination& GetLocalDestination () { return m_LocalDestination; };
|
||||||
|
|
||||||
void HandleNextPacket (Packet * packet);
|
void HandleNextPacket (Packet * packet);
|
||||||
size_t Send (const uint8_t * buf, size_t len);
|
size_t Send (const uint8_t * buf, size_t len);
|
||||||
|
@ -124,7 +124,7 @@ namespace stream
|
||||||
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
|
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
|
||||||
int32_t m_LastReceivedSequenceNumber;
|
int32_t m_LastReceivedSequenceNumber;
|
||||||
bool m_IsOpen, m_LeaseSetUpdated;
|
bool m_IsOpen, m_LeaseSetUpdated;
|
||||||
StreamingDestination * m_LocalDestination;
|
StreamingDestination& m_LocalDestination;
|
||||||
i2p::data::IdentityEx m_RemoteIdentity;
|
i2p::data::IdentityEx m_RemoteIdentity;
|
||||||
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
||||||
i2p::garlic::GarlicRoutingSession * m_RoutingSession;
|
i2p::garlic::GarlicRoutingSession * m_RoutingSession;
|
||||||
|
|
Loading…
Reference in a new issue