Browse Source

pass LeaseSet to callback of RequestDestination

pull/177/head
orignal 10 years ago
parent
commit
634976cdde
  1. 7
      AddressBook.cpp
  2. 28
      BOB.cpp
  3. 2
      BOB.h
  4. 19
      Datagram.cpp
  5. 2
      Datagram.h
  6. 29
      Destination.cpp
  7. 3
      Destination.h
  8. 12
      SAM.cpp
  9. 4
      SAM.h

7
AddressBook.cpp

@ -460,18 +460,15 @@ namespace client
auto leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident); auto leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident);
if (!leaseSet) if (!leaseSet)
{ {
bool found = false;
std::unique_lock<std::mutex> l(newDataReceivedMutex); std::unique_lock<std::mutex> l(newDataReceivedMutex);
i2p::client::context.GetSharedLocalDestination ()->RequestDestination (ident, i2p::client::context.GetSharedLocalDestination ()->RequestDestination (ident,
[&newDataReceived, &found](bool success) [&newDataReceived, &leaseSet](std::shared_ptr<i2p::data::LeaseSet> ls)
{ {
found = success; leaseSet = ls;
newDataReceived.notify_all (); newDataReceived.notify_all ();
}); });
if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout) if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout)
LogPrint (eLogError, "Subscription LeseseSet request timeout expired"); LogPrint (eLogError, "Subscription LeseseSet request timeout expired");
if (found)
leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident);
} }
if (leaseSet) if (leaseSet)
{ {

28
BOB.cpp

@ -85,7 +85,7 @@ namespace client
else else
GetLocalDestination ()->RequestDestination (ident, GetLocalDestination ()->RequestDestination (ident,
std::bind (&BOBI2PInboundTunnel::HandleDestinationRequestComplete, std::bind (&BOBI2PInboundTunnel::HandleDestinationRequestComplete,
this, std::placeholders::_1, receiver, ident)); this, std::placeholders::_1, receiver));
} }
else else
{ {
@ -97,16 +97,12 @@ namespace client
} }
} }
void BOBI2PInboundTunnel::HandleDestinationRequestComplete (bool success, std::shared_ptr<AddressReceiver> receiver, i2p::data::IdentHash ident) void BOBI2PInboundTunnel::HandleDestinationRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, std::shared_ptr<AddressReceiver> receiver)
{ {
if (success) if (leaseSet)
{ CreateConnection (receiver, leaseSet);
auto leaseSet = GetLocalDestination ()->FindLeaseSet (ident); else
if (leaseSet) LogPrint ("LeaseSet for BOB inbound destination not found");
CreateConnection (receiver, leaseSet);
else
LogPrint ("LeaseSet for BOB inbound destination not found");
}
} }
void BOBI2PInboundTunnel::CreateConnection (std::shared_ptr<AddressReceiver> receiver, std::shared_ptr<const i2p::data::LeaseSet> leaseSet) void BOBI2PInboundTunnel::CreateConnection (std::shared_ptr<AddressReceiver> receiver, std::shared_ptr<const i2p::data::LeaseSet> leaseSet)
@ -486,16 +482,10 @@ namespace client
{ {
auto s = shared_from_this (); auto s = shared_from_this ();
m_CurrentDestination->GetLocalDestination ()->RequestDestination (ident, m_CurrentDestination->GetLocalDestination ()->RequestDestination (ident,
[s, ident, localDestination](bool success) [s, localDestination](std::shared_ptr<i2p::data::LeaseSet> ls)
{ {
if (success) if (ls)
{ s->SendReplyOK (ls->GetIdentity ().ToBase64 ().c_str ());
auto leaseSet = localDestination->FindLeaseSet (ident);
if (leaseSet)
s->SendReplyOK (leaseSet->GetIdentity ().ToBase64 ().c_str ());
else
s->SendReplyError ("Missing LeaseSet");
}
else else
s->SendReplyError ("LeaseSet Not found"); s->SendReplyError ("LeaseSet Not found");
} }

2
BOB.h

@ -82,7 +82,7 @@ namespace client
void HandleReceivedAddress (const boost::system::error_code& ecode, std::size_t bytes_transferred, void HandleReceivedAddress (const boost::system::error_code& ecode, std::size_t bytes_transferred,
std::shared_ptr<AddressReceiver> receiver); std::shared_ptr<AddressReceiver> receiver);
void HandleDestinationRequestComplete (bool success, std::shared_ptr<AddressReceiver> receiver, i2p::data::IdentHash ident); void HandleDestinationRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, std::shared_ptr<AddressReceiver> receiver);
void CreateConnection (std::shared_ptr<AddressReceiver> receiver, std::shared_ptr<const i2p::data::LeaseSet> leaseSet); void CreateConnection (std::shared_ptr<AddressReceiver> receiver, std::shared_ptr<const i2p::data::LeaseSet> leaseSet);

19
Datagram.cpp

@ -41,22 +41,15 @@ namespace datagram
if (remote) if (remote)
m_Owner.GetService ().post (std::bind (&DatagramDestination::SendMsg, this, msg, remote)); m_Owner.GetService ().post (std::bind (&DatagramDestination::SendMsg, this, msg, remote));
else else
m_Owner.RequestDestination (ident, std::bind (&DatagramDestination::HandleLeaseSetRequestComplete, m_Owner.RequestDestination (ident, std::bind (&DatagramDestination::HandleLeaseSetRequestComplete, this, std::placeholders::_1, msg));
this, std::placeholders::_1, msg, ident));
} }
void DatagramDestination::HandleLeaseSetRequestComplete (bool success, I2NPMessage * msg, i2p::data::IdentHash ident) void DatagramDestination::HandleLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> remote, I2NPMessage * msg)
{ {
if (success) if (remote)
{ SendMsg (msg, remote);
auto remote = m_Owner.FindLeaseSet (ident); else
if (remote) DeleteI2NPMessage (msg);
{
SendMsg (msg, remote);
return;
}
}
DeleteI2NPMessage (msg);
} }
void DatagramDestination::SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote) void DatagramDestination::SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote)

2
Datagram.h

@ -38,7 +38,7 @@ namespace datagram
private: private:
void HandleLeaseSetRequestComplete (bool success, I2NPMessage * msg, i2p::data::IdentHash ident); void HandleLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, I2NPMessage * msg);
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort); I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort);
void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote); void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote);

29
Destination.cpp

@ -222,19 +222,22 @@ namespace client
LogPrint (eLogInfo, "Reply token is ignored for DatabaseStore"); LogPrint (eLogInfo, "Reply token is ignored for DatabaseStore");
offset += 36; offset += 36;
} }
std::shared_ptr<i2p::data::LeaseSet> leaseSet;
if (buf[DATABASE_STORE_TYPE_OFFSET] == 1) // LeaseSet if (buf[DATABASE_STORE_TYPE_OFFSET] == 1) // LeaseSet
{ {
LogPrint (eLogDebug, "Remote LeaseSet"); LogPrint (eLogDebug, "Remote LeaseSet");
auto it = m_RemoteLeaseSets.find (buf + DATABASE_STORE_KEY_OFFSET); auto it = m_RemoteLeaseSets.find (buf + DATABASE_STORE_KEY_OFFSET);
if (it != m_RemoteLeaseSets.end ()) if (it != m_RemoteLeaseSets.end ())
{ {
it->second->Update (buf + offset, len - offset); leaseSet = it->second;
leaseSet->Update (buf + offset, len - offset);
LogPrint (eLogDebug, "Remote LeaseSet updated"); LogPrint (eLogDebug, "Remote LeaseSet updated");
} }
else else
{ {
LogPrint (eLogDebug, "New remote LeaseSet added"); LogPrint (eLogDebug, "New remote LeaseSet added");
m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset); leaseSet = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset);
m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = leaseSet;
} }
} }
else else
@ -244,7 +247,7 @@ namespace client
if (it1 != m_LeaseSetRequests.end ()) if (it1 != m_LeaseSetRequests.end ())
{ {
it1->second->requestTimeoutTimer.cancel (); it1->second->requestTimeoutTimer.cancel ();
if (it1->second->requestComplete) it1->second->requestComplete (true); if (it1->second->requestComplete) it1->second->requestComplete (leaseSet);
delete it1->second; delete it1->second;
m_LeaseSetRequests.erase (it1); m_LeaseSetRequests.erase (it1);
} }
@ -285,7 +288,7 @@ namespace client
LogPrint (eLogInfo, key.ToBase64 (), " was not found on ", MAX_NUM_FLOODFILLS_PER_REQUEST," floodfills"); LogPrint (eLogInfo, key.ToBase64 (), " was not found on ", MAX_NUM_FLOODFILLS_PER_REQUEST," floodfills");
if (!found) if (!found)
{ {
if (request->requestComplete) request->requestComplete (false); if (request->requestComplete) request->requestComplete (nullptr);
delete request; delete request;
m_LeaseSetRequests.erase (key); m_LeaseSetRequests.erase (key);
} }
@ -404,18 +407,12 @@ namespace client
else else
{ {
RequestDestination (dest, RequestDestination (dest,
[this, streamRequestComplete, dest, port](bool success) [this, streamRequestComplete, port](std::shared_ptr<i2p::data::LeaseSet> ls)
{ {
if (!success) if (ls)
streamRequestComplete (nullptr); streamRequestComplete(CreateStream (ls, port));
else else
{ streamRequestComplete (nullptr);
auto leaseSet = FindLeaseSet (dest);
if (leaseSet)
streamRequestComplete(CreateStream (leaseSet, port));
else
streamRequestComplete (nullptr);
}
}); });
} }
} }
@ -501,7 +498,7 @@ namespace client
if (!SendLeaseSetRequest (dest, floodfill, request)) if (!SendLeaseSetRequest (dest, floodfill, request))
{ {
// request failed // request failed
if (request->requestComplete) request->requestComplete (false); if (request->requestComplete) request->requestComplete (nullptr);
delete request; delete request;
m_LeaseSetRequests.erase (dest); m_LeaseSetRequests.erase (dest);
} }
@ -510,7 +507,7 @@ namespace client
{ {
LogPrint (eLogError, "Request of ", dest.ToBase64 (), " is pending already"); LogPrint (eLogError, "Request of ", dest.ToBase64 (), " is pending already");
// TODO: queue up requests // TODO: queue up requests
if (request->requestComplete) request->requestComplete (false); if (request->requestComplete) request->requestComplete (nullptr);
delete request; delete request;
} }
} }

3
Destination.h

@ -42,7 +42,8 @@ namespace client
class ClientDestination: public i2p::garlic::GarlicDestination class ClientDestination: public i2p::garlic::GarlicDestination
{ {
typedef std::function<void (bool success)> RequestComplete; typedef std::function<void (std::shared_ptr<i2p::data::LeaseSet> leaseSet)> RequestComplete;
// leaseSet = nullptr means not found
struct LeaseSetRequest struct LeaseSetRequest
{ {
LeaseSetRequest (boost::asio::io_service& service): requestTime (0), requestTimeoutTimer (service) {}; LeaseSetRequest (boost::asio::io_service& service): requestTime (0), requestTimeoutTimer (service) {};

12
SAM.cpp

@ -349,7 +349,7 @@ namespace client
{ {
m_Session->localDestination->RequestDestination (dest.GetIdentHash (), m_Session->localDestination->RequestDestination (dest.GetIdentHash (),
std::bind (&SAMSocket::HandleConnectLeaseSetRequestComplete, std::bind (&SAMSocket::HandleConnectLeaseSetRequestComplete,
shared_from_this (), std::placeholders::_1, dest.GetIdentHash ())); shared_from_this (), std::placeholders::_1));
} }
} }
else else
@ -366,11 +366,8 @@ namespace client
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false);
} }
void SAMSocket::HandleConnectLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident) void SAMSocket::HandleConnectLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet)
{ {
std::shared_ptr<const i2p::data::LeaseSet> leaseSet;
if (success)
leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet) if (leaseSet)
Connect (leaseSet); Connect (leaseSet);
else else
@ -486,11 +483,8 @@ namespace client
} }
} }
void SAMSocket::HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident) void SAMSocket::HandleNamingLookupLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, i2p::data::IdentHash ident)
{ {
std::shared_ptr<const i2p::data::LeaseSet> leaseSet;
if (success)
leaseSet = m_Session->localDestination->FindLeaseSet (ident);
if (leaseSet) if (leaseSet)
{ {
context.GetAddressBook ().InsertAddress (leaseSet->GetIdentity ()); context.GetAddressBook ().InsertAddress (leaseSet->GetIdentity ());

4
SAM.h

@ -109,9 +109,9 @@ namespace client
void ExtractParams (char * buf, std::map<std::string, std::string>& params); void ExtractParams (char * buf, std::map<std::string, std::string>& params);
void Connect (std::shared_ptr<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 (std::shared_ptr<i2p::data::LeaseSet> leaseSet);
void SendNamingLookupReply (const i2p::data::IdentityEx& identity); void SendNamingLookupReply (const i2p::data::IdentityEx& identity);
void HandleNamingLookupLeaseSetRequestComplete (bool success, i2p::data::IdentHash ident); void HandleNamingLookupLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, i2p::data::IdentHash ident);
void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode); void HandleSessionReadinessCheckTimer (const boost::system::error_code& ecode);
void SendSessionCreateReplyOk (); void SendSessionCreateReplyOk ();

Loading…
Cancel
Save