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 @@ -460,18 +460,15 @@ namespace client
auto leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident);
if (!leaseSet)
{
bool found = false;
std::unique_lock<std::mutex> l(newDataReceivedMutex);
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 ();
});
if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout)
LogPrint (eLogError, "Subscription LeseseSet request timeout expired");
if (found)
leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident);
}
if (leaseSet)
{

28
BOB.cpp

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

2
BOB.h

@ -82,7 +82,7 @@ namespace client @@ -82,7 +82,7 @@ namespace client
void HandleReceivedAddress (const boost::system::error_code& ecode, std::size_t bytes_transferred,
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);

19
Datagram.cpp

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

2
Datagram.h

@ -38,7 +38,7 @@ namespace datagram @@ -38,7 +38,7 @@ namespace datagram
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);
void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote);

29
Destination.cpp

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

3
Destination.h

@ -42,7 +42,8 @@ namespace client @@ -42,7 +42,8 @@ namespace client
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
{
LeaseSetRequest (boost::asio::io_service& service): requestTime (0), requestTimeoutTimer (service) {};

12
SAM.cpp

@ -349,7 +349,7 @@ namespace client @@ -349,7 +349,7 @@ namespace client
{
m_Session->localDestination->RequestDestination (dest.GetIdentHash (),
std::bind (&SAMSocket::HandleConnectLeaseSetRequestComplete,
shared_from_this (), std::placeholders::_1, dest.GetIdentHash ()));
shared_from_this (), std::placeholders::_1));
}
}
else
@ -366,11 +366,8 @@ namespace client @@ -366,11 +366,8 @@ namespace client
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)
Connect (leaseSet);
else
@ -486,11 +483,8 @@ namespace client @@ -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)
{
context.GetAddressBook ().InsertAddress (leaseSet->GetIdentity ());

4
SAM.h

@ -109,9 +109,9 @@ namespace client @@ -109,9 +109,9 @@ namespace client
void ExtractParams (char * buf, std::map<std::string, std::string>& params);
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 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 SendSessionCreateReplyOk ();

Loading…
Cancel
Save