mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-31 09:04:14 +00:00
give preference to direct connection
This commit is contained in:
parent
f67c38d8d2
commit
c5a1e8cac8
@ -247,6 +247,7 @@ namespace data
|
|||||||
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
|
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
|
||||||
bool IsReachableBy (CompatibleTransports transports) const { return m_ReachableTransports & transports; };
|
bool IsReachableBy (CompatibleTransports transports) const { return m_ReachableTransports & transports; };
|
||||||
CompatibleTransports GetCompatibleTransports (bool incoming) const { return incoming ? m_ReachableTransports : m_SupportedTransports; };
|
CompatibleTransports GetCompatibleTransports (bool incoming) const { return incoming ? m_ReachableTransports : m_SupportedTransports; };
|
||||||
|
CompatibleTransports GetPublishedTransports () const { return m_PublishedTransports; };
|
||||||
bool HasValidAddresses () const { return m_SupportedTransports; };
|
bool HasValidAddresses () const { return m_SupportedTransports; };
|
||||||
bool IsHidden () const { return m_Caps & eHidden; };
|
bool IsHidden () const { return m_Caps & eHidden; };
|
||||||
bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; };
|
bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; };
|
||||||
|
@ -626,13 +626,26 @@ namespace transport
|
|||||||
if (!peer.router) return;
|
if (!peer.router) return;
|
||||||
auto compatibleTransports = context.GetRouterInfo ().GetCompatibleTransports (false) &
|
auto compatibleTransports = context.GetRouterInfo ().GetCompatibleTransports (false) &
|
||||||
peer.router->GetCompatibleTransports (true);
|
peer.router->GetCompatibleTransports (true);
|
||||||
|
auto directTransports = compatibleTransports & peer.router->GetPublishedTransports ();
|
||||||
peer.numAttempts = 0;
|
peer.numAttempts = 0;
|
||||||
peer.priority.clear ();
|
peer.priority.clear ();
|
||||||
bool ssu2 = peer.router->GetProfile ()->IsReal () ? (rand () & 1) : false; // try NTCP2 if router is not confirmed real
|
bool ssu2 = peer.router->GetProfile ()->IsReal () ? (rand () & 1) : false; // try NTCP2 if router is not confirmed real
|
||||||
const auto& priority = ssu2 ? ssu2Priority : ntcp2Priority;
|
const auto& priority = ssu2 ? ssu2Priority : ntcp2Priority;
|
||||||
for (auto transport: priority)
|
if (directTransports)
|
||||||
if (transport & compatibleTransports)
|
{
|
||||||
peer.priority.push_back (transport);
|
// direct connections have higher priority
|
||||||
|
for (auto transport: priority)
|
||||||
|
if (transport & directTransports)
|
||||||
|
peer.priority.push_back (transport);
|
||||||
|
compatibleTransports &= ~directTransports;
|
||||||
|
}
|
||||||
|
if (compatibleTransports)
|
||||||
|
{
|
||||||
|
// then remaining
|
||||||
|
for (auto transport: priority)
|
||||||
|
if (transport & compatibleTransports)
|
||||||
|
peer.priority.push_back (transport);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transports::RequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, const i2p::data::IdentHash& ident)
|
void Transports::RequestComplete (std::shared_ptr<const i2p::data::RouterInfo> r, const i2p::data::IdentHash& ident)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user