mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
fix datagram bugs
This commit is contained in:
parent
4f1dfe2ef7
commit
d91c7e5e79
19
Datagram.cpp
19
Datagram.cpp
@ -255,9 +255,11 @@ namespace datagram
|
|||||||
}
|
}
|
||||||
if(m_CurrentRemoteLease && m_CurrentRemoteLease->ExpiresWithin(DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW)) {
|
if(m_CurrentRemoteLease && m_CurrentRemoteLease->ExpiresWithin(DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW)) {
|
||||||
// bad lease, switch to next one
|
// bad lease, switch to next one
|
||||||
|
if(m_RemoteLeaseSet && m_RemoteLeaseSet->IsExpired())
|
||||||
|
m_RemoteLeaseSet = m_LocalDestination->FindLeaseSet(m_RemoteIdent);
|
||||||
if(m_RemoteLeaseSet) {
|
if(m_RemoteLeaseSet) {
|
||||||
auto ls = m_RemoteLeaseSet->GetNonExpiredLeasesExcluding([&](const i2p::data::Lease& l) -> bool {
|
auto ls = m_RemoteLeaseSet->GetNonExpiredLeasesExcluding([&](const i2p::data::Lease& l) -> bool {
|
||||||
return l.tunnelGateway == m_CurrentRemoteLease->tunnelGateway;
|
return l.tunnelID == m_CurrentRemoteLease->tunnelID;
|
||||||
});
|
});
|
||||||
auto sz = ls.size();
|
auto sz = ls.size();
|
||||||
if (sz) {
|
if (sz) {
|
||||||
@ -278,7 +280,7 @@ namespace datagram
|
|||||||
m_CurrentOutboundTunnel = m_LocalDestination->GetTunnelPool()->GetNextOutboundTunnel(m_CurrentOutboundTunnel);
|
m_CurrentOutboundTunnel = m_LocalDestination->GetTunnelPool()->GetNextOutboundTunnel(m_CurrentOutboundTunnel);
|
||||||
}
|
}
|
||||||
// switch lease if bad
|
// switch lease if bad
|
||||||
if(m_CurrentRemoteLease == nullptr || m_CurrentRemoteLease->ExpiresWithin(DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW)) {
|
if(m_CurrentRemoteLease && m_CurrentRemoteLease->ExpiresWithin(DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW)) {
|
||||||
if(!m_RemoteLeaseSet) {
|
if(!m_RemoteLeaseSet) {
|
||||||
m_RemoteLeaseSet = m_LocalDestination->FindLeaseSet(m_RemoteIdent);
|
m_RemoteLeaseSet = m_LocalDestination->FindLeaseSet(m_RemoteIdent);
|
||||||
}
|
}
|
||||||
@ -299,6 +301,17 @@ namespace datagram
|
|||||||
LogPrint(eLogWarning, "DatagramSession: no remote lease set found for ", m_RemoteIdent.ToBase32());
|
LogPrint(eLogWarning, "DatagramSession: no remote lease set found for ", m_RemoteIdent.ToBase32());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
} else if (!m_CurrentRemoteLease) {
|
||||||
|
if(!m_RemoteLeaseSet) m_RemoteLeaseSet = m_LocalDestination->FindLeaseSet(m_RemoteIdent);
|
||||||
|
if (m_RemoteLeaseSet)
|
||||||
|
{
|
||||||
|
auto ls = m_RemoteLeaseSet->GetNonExpiredLeases();
|
||||||
|
auto sz = ls.size();
|
||||||
|
if (sz) {
|
||||||
|
auto idx = rand() % sz;
|
||||||
|
m_CurrentRemoteLease = ls[idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
path->outboundTunnel = m_CurrentOutboundTunnel;
|
path->outboundTunnel = m_CurrentOutboundTunnel;
|
||||||
path->remoteLease = m_CurrentRemoteLease;
|
path->remoteLease = m_CurrentRemoteLease;
|
||||||
@ -346,7 +359,7 @@ namespace datagram
|
|||||||
|
|
||||||
void DatagramSession::ScheduleFlushSendQueue()
|
void DatagramSession::ScheduleFlushSendQueue()
|
||||||
{
|
{
|
||||||
boost::posix_time::milliseconds dlt(100);
|
boost::posix_time::milliseconds dlt(10);
|
||||||
m_SendQueueTimer.expires_from_now(dlt);
|
m_SendQueueTimer.expires_from_now(dlt);
|
||||||
auto self = shared_from_this();
|
auto self = shared_from_this();
|
||||||
m_SendQueueTimer.async_wait([self](const boost::system::error_code & ec) { if(ec) return; self->FlushSendQueue(); });
|
m_SendQueueTimer.async_wait([self](const boost::system::error_code & ec) { if(ec) return; self->FlushSendQueue(); });
|
||||||
|
@ -26,7 +26,7 @@ namespace datagram
|
|||||||
// milliseconds interval a routing path is used before switching
|
// milliseconds interval a routing path is used before switching
|
||||||
const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 20 * 60 * 1000;
|
const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 20 * 60 * 1000;
|
||||||
// milliseconds before lease expire should we try switching leases
|
// milliseconds before lease expire should we try switching leases
|
||||||
const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW = 10 * 1000;
|
const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW = 30 * 1000;
|
||||||
// milliseconds fudge factor for leases handover
|
// milliseconds fudge factor for leases handover
|
||||||
const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_FUDGE = 1000;
|
const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_FUDGE = 1000;
|
||||||
// milliseconds minimum time between path switches
|
// milliseconds minimum time between path switches
|
||||||
|
@ -30,7 +30,8 @@ namespace data
|
|||||||
bool ExpiresWithin( const uint64_t t, const uint64_t fudge = 1000 ) const {
|
bool ExpiresWithin( const uint64_t t, const uint64_t fudge = 1000 ) const {
|
||||||
auto expire = i2p::util::GetMillisecondsSinceEpoch ();
|
auto expire = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
if(fudge) expire += rand() % fudge;
|
if(fudge) expire += rand() % fudge;
|
||||||
return endDate - expire >= t;
|
if (endDate < expire) return true;
|
||||||
|
return (endDate - expire) < t;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ namespace client
|
|||||||
m_ResolveTimer = std::make_shared<boost::asio::deadline_timer>(GetService());
|
m_ResolveTimer = std::make_shared<boost::asio::deadline_timer>(GetService());
|
||||||
GetTunnelPool()->SetCustomPeerSelector(this);
|
GetTunnelPool()->SetCustomPeerSelector(this);
|
||||||
ResolveCurrentLeaseSet();
|
ResolveCurrentLeaseSet();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user