Browse Source

use shared ClientDestination

pull/503/head
orignal 8 years ago
parent
commit
c7173d5e1c
  1. 2
      Datagram.cpp
  2. 6
      Datagram.h
  3. 8
      Destination.cpp
  4. 4
      Destination.h
  5. 2
      Streaming.cpp
  6. 8
      Streaming.h

2
Datagram.cpp

@ -11,7 +11,7 @@ namespace i2p
{ {
namespace datagram namespace datagram
{ {
DatagramDestination::DatagramDestination (std::shared_ptr<i2p::client::LeaseSetDestination> owner): DatagramDestination::DatagramDestination (std::shared_ptr<i2p::client::ClientDestination> owner):
m_Owner (owner), m_Receiver (nullptr) m_Owner (owner), m_Receiver (nullptr)
{ {
} }

6
Datagram.h

@ -14,7 +14,7 @@ namespace i2p
{ {
namespace client namespace client
{ {
class LeaseSetDestination; class ClientDestination;
} }
namespace datagram namespace datagram
{ {
@ -25,7 +25,7 @@ namespace datagram
public: public:
DatagramDestination (std::shared_ptr<i2p::client::LeaseSetDestination> owner); DatagramDestination (std::shared_ptr<i2p::client::ClientDestination> owner);
~DatagramDestination (); ~DatagramDestination ();
void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort = 0, uint16_t toPort = 0); void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort = 0, uint16_t toPort = 0);
@ -47,7 +47,7 @@ namespace datagram
private: private:
std::shared_ptr<i2p::client::LeaseSetDestination> m_Owner; std::shared_ptr<i2p::client::ClientDestination> m_Owner;
Receiver m_Receiver; // default Receiver m_Receiver; // default
std::map<uint16_t, Receiver> m_ReceiversByPorts; std::map<uint16_t, Receiver> m_ReceiversByPorts;

8
Destination.cpp

@ -662,7 +662,7 @@ namespace client
{ {
if (LeaseSetDestination::Start ()) if (LeaseSetDestination::Start ())
{ {
m_StreamingDestination = std::make_shared<i2p::stream::StreamingDestination> (shared_from_this ()); // TODO: m_StreamingDestination = std::make_shared<i2p::stream::StreamingDestination> (GetSharedFromThis ()); // TODO:
m_StreamingDestination->Start (); m_StreamingDestination->Start ();
for (auto it: m_StreamingDestinationsByPorts) for (auto it: m_StreamingDestinationsByPorts)
it.second->Start (); it.second->Start ();
@ -735,7 +735,7 @@ namespace client
streamRequestComplete(CreateStream (leaseSet, port)); streamRequestComplete(CreateStream (leaseSet, port));
else else
{ {
auto s = std::static_pointer_cast<ClientDestination>(shared_from_this ()); auto s = GetSharedFromThis ();
RequestDestination (dest, RequestDestination (dest,
[s, streamRequestComplete, port](std::shared_ptr<i2p::data::LeaseSet> ls) [s, streamRequestComplete, port](std::shared_ptr<i2p::data::LeaseSet> ls)
{ {
@ -788,7 +788,7 @@ namespace client
std::shared_ptr<i2p::stream::StreamingDestination> ClientDestination::CreateStreamingDestination (int port, bool gzip) std::shared_ptr<i2p::stream::StreamingDestination> ClientDestination::CreateStreamingDestination (int port, bool gzip)
{ {
auto dest = std::make_shared<i2p::stream::StreamingDestination> (shared_from_this (), port, gzip); auto dest = std::make_shared<i2p::stream::StreamingDestination> (GetSharedFromThis (), port, gzip);
if (port) if (port)
m_StreamingDestinationsByPorts[port] = dest; m_StreamingDestinationsByPorts[port] = dest;
else // update default else // update default
@ -799,7 +799,7 @@ namespace client
i2p::datagram::DatagramDestination * ClientDestination::CreateDatagramDestination () i2p::datagram::DatagramDestination * ClientDestination::CreateDatagramDestination ()
{ {
if (!m_DatagramDestination) if (!m_DatagramDestination)
m_DatagramDestination = new i2p::datagram::DatagramDestination (shared_from_this ()); m_DatagramDestination = new i2p::datagram::DatagramDestination (GetSharedFromThis ());
return m_DatagramDestination; return m_DatagramDestination;
} }

4
Destination.h

@ -174,7 +174,9 @@ namespace client
private: private:
void PersistTemporaryKeys (); void PersistTemporaryKeys ();
std::shared_ptr<ClientDestination> GetSharedFromThis ()
{ return std::static_pointer_cast<ClientDestination>(shared_from_this ()); }
private: private:
i2p::data::PrivateKeys m_Keys; i2p::data::PrivateKeys m_Keys;

2
Streaming.cpp

@ -780,7 +780,7 @@ namespace stream
m_CurrentRemoteLease = nullptr; m_CurrentRemoteLease = nullptr;
} }
StreamingDestination::StreamingDestination (std::shared_ptr<i2p::client::LeaseSetDestination> owner, uint16_t localPort, bool gzip): StreamingDestination::StreamingDestination (std::shared_ptr<i2p::client::ClientDestination> owner, uint16_t localPort, bool gzip):
m_Owner (owner), m_LocalPort (localPort), m_Gzip (gzip), m_Owner (owner), m_LocalPort (localPort), m_Gzip (gzip),
m_PendingIncomingTimer (m_Owner->GetService ()) m_PendingIncomingTimer (m_Owner->GetService ())
{ {

8
Streaming.h

@ -23,7 +23,7 @@ namespace i2p
{ {
namespace client namespace client
{ {
class LeaseSetDestination; class ClientDestination;
} }
namespace stream namespace stream
{ {
@ -193,7 +193,7 @@ namespace stream
typedef std::function<void (std::shared_ptr<Stream>)> Acceptor; typedef std::function<void (std::shared_ptr<Stream>)> Acceptor;
StreamingDestination (std::shared_ptr<i2p::client::LeaseSetDestination> owner, uint16_t localPort = 0, bool gzip = true); StreamingDestination (std::shared_ptr<i2p::client::ClientDestination> owner, uint16_t localPort = 0, bool gzip = true);
~StreamingDestination (); ~StreamingDestination ();
void Start (); void Start ();
@ -204,7 +204,7 @@ namespace stream
void SetAcceptor (const Acceptor& acceptor); void SetAcceptor (const Acceptor& acceptor);
void ResetAcceptor (); void ResetAcceptor ();
bool IsAcceptorSet () const { return m_Acceptor != nullptr; }; bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
std::shared_ptr<i2p::client::LeaseSetDestination> GetOwner () const { return m_Owner; }; std::shared_ptr<i2p::client::ClientDestination> GetOwner () const { return m_Owner; };
uint16_t GetLocalPort () const { return m_LocalPort; }; uint16_t GetLocalPort () const { return m_LocalPort; };
void HandleDataMessagePayload (const uint8_t * buf, size_t len); void HandleDataMessagePayload (const uint8_t * buf, size_t len);
@ -218,7 +218,7 @@ namespace stream
private: private:
std::shared_ptr<i2p::client::LeaseSetDestination> m_Owner; std::shared_ptr<i2p::client::ClientDestination> m_Owner;
uint16_t m_LocalPort; uint16_t m_LocalPort;
bool m_Gzip; // gzip compression of data messages bool m_Gzip; // gzip compression of data messages
std::mutex m_StreamsMutex; std::mutex m_StreamsMutex;

Loading…
Cancel
Save