Browse Source

store LeaseSet as shared_ptr

pull/151/head
orignal 10 years ago
parent
commit
d1d6797d3e
  1. 4
      AddressBook.cpp
  2. 2
      BOB.cpp
  3. 2
      BOB.h
  4. 18
      Destination.cpp
  5. 6
      Destination.h
  6. 4
      HTTPServer.cpp
  7. 2
      HTTPServer.h
  8. 4
      I2PTunnel.cpp
  9. 2
      I2PTunnel.h
  10. 9
      NetDb.cpp
  11. 4
      NetDb.h
  12. 12
      SAM.cpp
  13. 2
      SAM.h
  14. 10
      Streaming.cpp
  15. 8
      Streaming.h
  16. 2
      api.cpp

4
AddressBook.cpp

@ -435,7 +435,7 @@ namespace client
{ {
std::condition_variable newDataReceived; std::condition_variable newDataReceived;
std::mutex newDataReceivedMutex; std::mutex newDataReceivedMutex;
const i2p::data::LeaseSet * leaseSet = i2p::data::netdb.FindLeaseSet (ident); auto leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident);
if (!leaseSet) if (!leaseSet)
{ {
bool found = false; bool found = false;
@ -462,7 +462,7 @@ namespace client
if (m_LastModified.length () > 0) // if-modfief-since if (m_LastModified.length () > 0) // if-modfief-since
request << i2p::util::http::IF_MODIFIED_SINCE << ": " << m_LastModified << "\r\n"; request << i2p::util::http::IF_MODIFIED_SINCE << ": " << m_LastModified << "\r\n";
request << "\r\n"; // end of header request << "\r\n"; // end of header
auto stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (*leaseSet, u.port_); auto stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (leaseSet, u.port_);
stream->Send ((uint8_t *)request.str ().c_str (), request.str ().length ()); stream->Send ((uint8_t *)request.str ().c_str (), request.str ().length ());
uint8_t buf[4095]; uint8_t buf[4095];

2
BOB.cpp

@ -132,7 +132,7 @@ namespace client
delete receiver; delete receiver;
} }
void BOBI2PInboundTunnel::CreateConnection (AddressReceiver * receiver, const i2p::data::LeaseSet * leaseSet) void BOBI2PInboundTunnel::CreateConnection (AddressReceiver * receiver, std::shared_ptr<const i2p::data::LeaseSet> leaseSet)
{ {
LogPrint ("New BOB inbound connection"); LogPrint ("New BOB inbound connection");
auto connection = std::make_shared<I2PTunnelConnection>(this, receiver->socket, leaseSet); auto connection = std::make_shared<I2PTunnelConnection>(this, receiver->socket, leaseSet);

2
BOB.h

@ -84,7 +84,7 @@ namespace client
void HandleDestinationRequestTimer (const boost::system::error_code& ecode, AddressReceiver * receiver, i2p::data::IdentHash ident); void HandleDestinationRequestTimer (const boost::system::error_code& ecode, AddressReceiver * receiver, i2p::data::IdentHash ident);
void CreateConnection (AddressReceiver * receiver, const i2p::data::LeaseSet * leaseSet); void CreateConnection (AddressReceiver * receiver, std::shared_ptr<const i2p::data::LeaseSet> leaseSet);
private: private:

18
Destination.cpp

@ -57,8 +57,6 @@ namespace client
Stop (); Stop ();
for (auto it: m_LeaseSetRequests) for (auto it: m_LeaseSetRequests)
delete it.second; delete it.second;
for (auto it: m_RemoteLeaseSets)
delete it.second;
if (m_Pool) if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool); i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
if (m_StreamingDestination) if (m_StreamingDestination)
@ -126,7 +124,7 @@ namespace client
} }
} }
const i2p::data::LeaseSet * ClientDestination::FindLeaseSet (const i2p::data::IdentHash& ident) std::shared_ptr<const i2p::data::LeaseSet> ClientDestination::FindLeaseSet (const i2p::data::IdentHash& ident)
{ {
auto it = m_RemoteLeaseSets.find (ident); auto it = m_RemoteLeaseSets.find (ident);
if (it != m_RemoteLeaseSets.end ()) if (it != m_RemoteLeaseSets.end ())
@ -141,7 +139,7 @@ namespace client
auto ls = i2p::data::netdb.FindLeaseSet (ident); auto ls = i2p::data::netdb.FindLeaseSet (ident);
if (ls) if (ls)
{ {
ls = new i2p::data::LeaseSet (*ls); ls = std::make_shared<i2p::data::LeaseSet> (*ls);
m_RemoteLeaseSets[ident] = ls; m_RemoteLeaseSets[ident] = ls;
return ls; return ls;
} }
@ -232,7 +230,7 @@ namespace client
else else
{ {
LogPrint (eLogDebug, "New remote LeaseSet added"); LogPrint (eLogDebug, "New remote LeaseSet added");
m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = new i2p::data::LeaseSet (buf + offset, len - offset); m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset);
} }
} }
else else
@ -391,9 +389,9 @@ namespace client
void ClientDestination::CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, int port) { void ClientDestination::CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, int port) {
assert(streamRequestComplete); assert(streamRequestComplete);
const i2p::data::LeaseSet * leaseSet = FindLeaseSet (dest); auto leaseSet = FindLeaseSet (dest);
if (leaseSet) if (leaseSet)
streamRequestComplete(CreateStream (*leaseSet, port)); streamRequestComplete(CreateStream (leaseSet, port));
else else
{ {
RequestDestination (dest, RequestDestination (dest,
@ -403,9 +401,9 @@ namespace client
streamRequestComplete (nullptr); streamRequestComplete (nullptr);
else else
{ {
const i2p::data::LeaseSet * leaseSet = FindLeaseSet (dest); auto leaseSet = FindLeaseSet (dest);
if (leaseSet) if (leaseSet)
streamRequestComplete(CreateStream (*leaseSet, port)); streamRequestComplete(CreateStream (leaseSet, port));
else else
streamRequestComplete (nullptr); streamRequestComplete (nullptr);
} }
@ -413,7 +411,7 @@ namespace client
} }
} }
std::shared_ptr<i2p::stream::Stream> ClientDestination::CreateStream (const i2p::data::LeaseSet& remote, int port) std::shared_ptr<i2p::stream::Stream> ClientDestination::CreateStream (std::shared_ptr<const i2p::data::LeaseSet> remote, int port)
{ {
if (m_StreamingDestination) if (m_StreamingDestination)
return m_StreamingDestination->CreateNewOutgoingStream (remote, port); return m_StreamingDestination->CreateNewOutgoingStream (remote, port);

6
Destination.h

@ -64,13 +64,13 @@ namespace client
boost::asio::io_service& GetService () { return m_Service; }; boost::asio::io_service& GetService () { return m_Service; };
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () { return m_Pool; }; std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () { return m_Pool; };
bool IsReady () const { return m_LeaseSet && m_LeaseSet->HasNonExpiredLeases (); }; bool IsReady () const { return m_LeaseSet && m_LeaseSet->HasNonExpiredLeases (); };
const i2p::data::LeaseSet * FindLeaseSet (const i2p::data::IdentHash& ident); std::shared_ptr<const i2p::data::LeaseSet> FindLeaseSet (const i2p::data::IdentHash& ident);
bool RequestDestination (const i2p::data::IdentHash& dest, RequestComplete requestComplete = nullptr); bool RequestDestination (const i2p::data::IdentHash& dest, RequestComplete requestComplete = nullptr);
// streaming // streaming
i2p::stream::StreamingDestination * GetStreamingDestination () const { return m_StreamingDestination; }; i2p::stream::StreamingDestination * GetStreamingDestination () const { return m_StreamingDestination; };
void CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, int port = 0); void CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, int port = 0);
std::shared_ptr<i2p::stream::Stream> CreateStream (const i2p::data::LeaseSet& remote, int port = 0); std::shared_ptr<i2p::stream::Stream> CreateStream (std::shared_ptr<const i2p::data::LeaseSet> remote, int port = 0);
void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor); void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor);
void StopAcceptingStreams (); void StopAcceptingStreams ();
bool IsAcceptingStreams () const; bool IsAcceptingStreams () const;
@ -120,7 +120,7 @@ namespace client
boost::asio::io_service::work m_Work; boost::asio::io_service::work m_Work;
i2p::data::PrivateKeys m_Keys; i2p::data::PrivateKeys m_Keys;
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
std::map<i2p::data::IdentHash, i2p::data::LeaseSet *> m_RemoteLeaseSets; std::map<i2p::data::IdentHash, std::shared_ptr<i2p::data::LeaseSet> > m_RemoteLeaseSets;
std::map<i2p::data::IdentHash, LeaseSetRequest *> m_LeaseSetRequests; std::map<i2p::data::IdentHash, LeaseSetRequest *> m_LeaseSetRequests;
std::shared_ptr<i2p::tunnel::TunnelPool> m_Pool; std::shared_ptr<i2p::tunnel::TunnelPool> m_Pool;

4
HTTPServer.cpp

@ -901,10 +901,10 @@ namespace util
} }
} }
void HTTPConnection::SendToDestination (const i2p::data::LeaseSet * remote, int port, const char * buf, size_t len) void HTTPConnection::SendToDestination (std::shared_ptr<const i2p::data::LeaseSet> remote, int port, const char * buf, size_t len)
{ {
if (!m_Stream) if (!m_Stream)
m_Stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (*remote, port); m_Stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (remote, port);
if (m_Stream) if (m_Stream)
{ {
m_Stream->Send ((uint8_t *)buf, len); m_Stream->Send ((uint8_t *)buf, len);

2
HTTPServer.h

@ -93,7 +93,7 @@ namespace util
void SendToAddress (const std::string& address, int port, const char * buf, size_t len); void SendToAddress (const std::string& address, int port, const char * buf, size_t len);
void HandleDestinationRequestTimeout (const boost::system::error_code& ecode, void HandleDestinationRequestTimeout (const boost::system::error_code& ecode,
i2p::data::IdentHash destination, int port, const char * buf, size_t len); i2p::data::IdentHash destination, int port, const char * buf, size_t len);
void SendToDestination (const i2p::data::LeaseSet * remote, int port, const char * buf, size_t len); void SendToDestination (std::shared_ptr<const i2p::data::LeaseSet> remote, int port, const char * buf, size_t len);
public: public:

4
I2PTunnel.cpp

@ -10,11 +10,11 @@ namespace i2p
namespace client namespace client
{ {
I2PTunnelConnection::I2PTunnelConnection (I2PService * owner, I2PTunnelConnection::I2PTunnelConnection (I2PService * owner,
boost::asio::ip::tcp::socket * socket, const i2p::data::LeaseSet * leaseSet): boost::asio::ip::tcp::socket * socket, std::shared_ptr<const i2p::data::LeaseSet> leaseSet):
I2PServiceHandler(owner), m_Socket (socket), m_RemoteEndpoint (socket->remote_endpoint ()), I2PServiceHandler(owner), m_Socket (socket), m_RemoteEndpoint (socket->remote_endpoint ()),
m_IsQuiet (true) m_IsQuiet (true)
{ {
m_Stream = GetOwner()->GetLocalDestination ()->CreateStream (*leaseSet); m_Stream = GetOwner()->GetLocalDestination ()->CreateStream (leaseSet);
} }
I2PTunnelConnection::I2PTunnelConnection (I2PService * owner, I2PTunnelConnection::I2PTunnelConnection (I2PService * owner,

2
I2PTunnel.h

@ -25,7 +25,7 @@ namespace client
public: public:
I2PTunnelConnection (I2PService * owner, boost::asio::ip::tcp::socket * socket, I2PTunnelConnection (I2PService * owner, boost::asio::ip::tcp::socket * socket,
const i2p::data::LeaseSet * leaseSet); // to I2P std::shared_ptr<const i2p::data::LeaseSet> leaseSet); // to I2P
I2PTunnelConnection (I2PService * owner, boost::asio::ip::tcp::socket * socket, I2PTunnelConnection (I2PService * owner, boost::asio::ip::tcp::socket * socket,
std::shared_ptr<i2p::stream::Stream> stream); // to I2P using simplified API :) std::shared_ptr<i2p::stream::Stream> stream); // to I2P using simplified API :)
I2PTunnelConnection (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream, boost::asio::ip::tcp::socket * socket, I2PTunnelConnection (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream, boost::asio::ip::tcp::socket * socket,

9
NetDb.cpp

@ -116,8 +116,6 @@ namespace data
delete m_Thread; delete m_Thread;
m_Thread = 0; m_Thread = 0;
} }
for (auto l: m_LeaseSets)
delete l.second;
m_LeaseSets.clear(); m_LeaseSets.clear();
for (auto r: m_RequestedDestinations) for (auto r: m_RequestedDestinations)
delete r.second; delete r.second;
@ -254,7 +252,7 @@ namespace data
else else
{ {
LogPrint ("New LeaseSet added"); LogPrint ("New LeaseSet added");
m_LeaseSets[ident] = new LeaseSet (buf, len); m_LeaseSets[ident] = std::make_shared<LeaseSet> (buf, len);
} }
} }
} }
@ -269,7 +267,7 @@ namespace data
return nullptr; return nullptr;
} }
LeaseSet * NetDb::FindLeaseSet (const IdentHash& destination) const std::shared_ptr<LeaseSet> NetDb::FindLeaseSet (const IdentHash& destination) const
{ {
auto it = m_LeaseSets.find (destination); auto it = m_LeaseSets.find (destination);
if (it != m_LeaseSets.end ()) if (it != m_LeaseSets.end ())
@ -641,7 +639,7 @@ namespace data
if (leaseSet) // we don't send back our LeaseSets if (leaseSet) // we don't send back our LeaseSets
{ {
LogPrint ("Requested LeaseSet ", key, " found"); LogPrint ("Requested LeaseSet ", key, " found");
replyMsg = CreateDatabaseStoreMsg (leaseSet); replyMsg = CreateDatabaseStoreMsg (leaseSet.get ());
} }
} }
if (!replyMsg) if (!replyMsg)
@ -862,7 +860,6 @@ namespace data
if (it->second->HasNonExpiredLeases ()) // all leases expired if (it->second->HasNonExpiredLeases ()) // all leases expired
{ {
LogPrint ("LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired"); LogPrint ("LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired");
delete it->second;
it = m_LeaseSets.erase (it); it = m_LeaseSets.erase (it);
} }
else else

4
NetDb.h

@ -68,7 +68,7 @@ namespace data
void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len); void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from); void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from);
std::shared_ptr<RouterInfo> FindRouter (const IdentHash& ident) const; std::shared_ptr<RouterInfo> FindRouter (const IdentHash& ident) const;
LeaseSet * FindLeaseSet (const IdentHash& destination) const; std::shared_ptr<LeaseSet> FindLeaseSet (const IdentHash& destination) const;
void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr); void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr);
@ -110,7 +110,7 @@ namespace data
private: private:
std::map<IdentHash, LeaseSet *> m_LeaseSets; std::map<IdentHash, std::shared_ptr<LeaseSet> > m_LeaseSets;
mutable std::mutex m_RouterInfosMutex; mutable std::mutex m_RouterInfosMutex;
std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos; std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos;
mutable std::mutex m_FloodfillsMutex; mutable std::mutex m_FloodfillsMutex;

12
SAM.cpp

@ -322,7 +322,7 @@ namespace client
context.GetAddressBook ().InsertAddress (dest); context.GetAddressBook ().InsertAddress (dest);
auto leaseSet = i2p::data::netdb.FindLeaseSet (dest.GetIdentHash ()); auto leaseSet = i2p::data::netdb.FindLeaseSet (dest.GetIdentHash ());
if (leaseSet) if (leaseSet)
Connect (*leaseSet); Connect (leaseSet);
else else
{ {
m_Session->localDestination->RequestDestination (dest.GetIdentHash (), m_Session->localDestination->RequestDestination (dest.GetIdentHash (),
@ -334,7 +334,7 @@ namespace client
SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true); SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true);
} }
void SAMSocket::Connect (const i2p::data::LeaseSet& remote) void SAMSocket::Connect (std::shared_ptr<const i2p::data::LeaseSet> remote)
{ {
m_SocketType = eSAMSocketTypeStream; m_SocketType = eSAMSocketTypeStream;
m_Session->sockets.push_back (shared_from_this ()); m_Session->sockets.push_back (shared_from_this ());
@ -346,11 +346,11 @@ namespace client
void SAMSocket::HandleConnectLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident) void SAMSocket::HandleConnectLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident)
{ {
const i2p::data::LeaseSet * leaseSet = nullptr; std::shared_ptr<const i2p::data::LeaseSet> leaseSet;
if (success) // timeout expired if (success) // timeout expired
leaseSet = m_Session->localDestination->FindLeaseSet (ident); leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet) if (leaseSet)
Connect (*leaseSet); Connect (leaseSet);
else else
{ {
LogPrint ("SAM destination to connect not found"); LogPrint ("SAM destination to connect not found");
@ -418,7 +418,7 @@ namespace client
else if (m_Session && m_Session->localDestination && else if (m_Session && m_Session->localDestination &&
context.GetAddressBook ().GetIdentHash (name, ident)) context.GetAddressBook ().GetIdentHash (name, ident))
{ {
auto leaseSet = i2p::data::netdb.FindLeaseSet (ident); auto leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet) if (leaseSet)
SendNamingLookupReply (leaseSet->GetIdentity ()); SendNamingLookupReply (leaseSet->GetIdentity ());
else else
@ -440,7 +440,7 @@ namespace client
void SAMSocket::HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident) void SAMSocket::HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident)
{ {
const i2p::data::LeaseSet * leaseSet = nullptr; std::shared_ptr<const i2p::data::LeaseSet> leaseSet;
if (success) if (success)
leaseSet = m_Session->localDestination->FindLeaseSet (ident); leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet) if (leaseSet)

2
SAM.h

@ -104,7 +104,7 @@ namespace client
void ProcessNamingLookup (char * buf, size_t len); void ProcessNamingLookup (char * buf, size_t len);
void ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& params); void ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& params);
void Connect (const i2p::data::LeaseSet& remote); void Connect (std::shared_ptr<const i2p::data::LeaseSet> remote);
void HandleConnectLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident); void HandleConnectLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident);
void SendNamingLookupReply (const i2p::data::IdentityEx& identity); void SendNamingLookupReply (const i2p::data::IdentityEx& identity);
void HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident); void HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident);

10
Streaming.cpp

@ -12,10 +12,10 @@ 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, int port): m_Service (service), m_SendStreamID (0), std::shared_ptr<const i2p::data::LeaseSet> remote, int port): 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_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local), m_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local),
m_RemoteLeaseSet (&remote), m_CurrentOutboundTunnel (nullptr), m_RemoteLeaseSet (remote), m_CurrentOutboundTunnel (nullptr),
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service), m_ReceiveTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service),
m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (port) m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (port)
{ {
@ -26,8 +26,8 @@ namespace stream
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_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local), m_IsOpen (false), m_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local),
m_RemoteLeaseSet (nullptr), m_CurrentOutboundTunnel (nullptr), m_CurrentOutboundTunnel (nullptr), m_ReceiveTimer (m_Service),
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service),
m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (0) m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (0)
{ {
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (); m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
@ -692,7 +692,7 @@ namespace stream
} }
} }
std::shared_ptr<Stream> StreamingDestination::CreateNewOutgoingStream (const i2p::data::LeaseSet& remote, int port) std::shared_ptr<Stream> StreamingDestination::CreateNewOutgoingStream (std::shared_ptr<const i2p::data::LeaseSet> remote, int port)
{ {
auto s = std::make_shared<Stream> (m_Owner.GetService (), *this, remote, port); auto s = std::make_shared<Stream> (m_Owner.GetService (), *this, remote, port);
std::unique_lock<std::mutex> l(m_StreamsMutex); std::unique_lock<std::mutex> l(m_StreamsMutex);

8
Streaming.h

@ -86,13 +86,13 @@ namespace stream
public: public:
Stream (boost::asio::io_service& service, StreamingDestination& local, Stream (boost::asio::io_service& service, StreamingDestination& local,
const i2p::data::LeaseSet& remote, int port = 0); // outgoing std::shared_ptr<const i2p::data::LeaseSet> remote, int port = 0); // 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; };
uint32_t GetRecvStreamID () const { return m_RecvStreamID; }; uint32_t GetRecvStreamID () const { return m_RecvStreamID; };
const i2p::data::LeaseSet * GetRemoteLeaseSet () const { return m_RemoteLeaseSet; }; std::shared_ptr<const i2p::data::LeaseSet> GetRemoteLeaseSet () const { return m_RemoteLeaseSet; };
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; };
@ -144,7 +144,7 @@ namespace stream
bool m_IsOpen, m_IsReset, m_IsAckSendScheduled; bool m_IsOpen, m_IsReset, m_IsAckSendScheduled;
StreamingDestination& m_LocalDestination; StreamingDestination& m_LocalDestination;
i2p::data::IdentityEx m_RemoteIdentity; i2p::data::IdentityEx m_RemoteIdentity;
const i2p::data::LeaseSet * m_RemoteLeaseSet; std::shared_ptr<const i2p::data::LeaseSet> m_RemoteLeaseSet;
std::shared_ptr<i2p::garlic::GarlicRoutingSession> m_RoutingSession; std::shared_ptr<i2p::garlic::GarlicRoutingSession> m_RoutingSession;
i2p::data::Lease m_CurrentRemoteLease; i2p::data::Lease m_CurrentRemoteLease;
i2p::tunnel::OutboundTunnel * m_CurrentOutboundTunnel; i2p::tunnel::OutboundTunnel * m_CurrentOutboundTunnel;
@ -171,7 +171,7 @@ namespace stream
void Start (); void Start ();
void Stop (); void Stop ();
std::shared_ptr<Stream> CreateNewOutgoingStream (const i2p::data::LeaseSet& remote, int port = 0); std::shared_ptr<Stream> CreateNewOutgoingStream (std::shared_ptr<const i2p::data::LeaseSet> remote, int port = 0);
void DeleteStream (std::shared_ptr<Stream> stream); void DeleteStream (std::shared_ptr<Stream> stream);
void SetAcceptor (const Acceptor& acceptor) { m_Acceptor = acceptor; }; void SetAcceptor (const Acceptor& acceptor) { m_Acceptor = acceptor; };
void ResetAcceptor () { m_Acceptor = nullptr; }; void ResetAcceptor () { m_Acceptor = nullptr; };

2
api.cpp

@ -85,7 +85,7 @@ namespace api
auto leaseSet = dest->FindLeaseSet (remote); auto leaseSet = dest->FindLeaseSet (remote);
if (leaseSet) if (leaseSet)
{ {
auto stream = dest->CreateStream (*leaseSet); auto stream = dest->CreateStream (leaseSet);
stream->Send (nullptr, 0); // connect stream->Send (nullptr, 0); // connect
return stream; return stream;
} }

Loading…
Cancel
Save