Skip to content

Commit

Permalink
Merge commit '1788075368b62e153e7a7c24b0156a57d588dad9' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Aug 31, 2024
2 parents 7ecb9fc + 1788075 commit f8b5616
Show file tree
Hide file tree
Showing 36 changed files with 978 additions and 674 deletions.
1 change: 1 addition & 0 deletions airdcpp-core/airdcpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
<ClInclude Include="airdcpp\Hasher.h" />
<ClInclude Include="airdcpp\HashManagerListener.h" />
<ClInclude Include="airdcpp\MessageHighlight.h" />
<ClInclude Include="airdcpp\QueueDownloadInfo.h" />
<ClInclude Include="airdcpp\RegexUtil.h" />
<ClInclude Include="airdcpp\SearchTypes.h" />
<ClInclude Include="airdcpp\ShareDirectory.h" />
Expand Down
3 changes: 3 additions & 0 deletions airdcpp-core/airdcpp.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,9 @@
<ClInclude Include="airdcpp\HubEntry.h">
<Filter>Header Files\favorites</Filter>
</ClInclude>
<ClInclude Include="airdcpp\QueueDownloadInfo.h">
<Filter>Header Files\queue</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="airdcpp\StringDefs.h">
Expand Down
8 changes: 4 additions & 4 deletions airdcpp-core/airdcpp/Bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,20 @@ bool Bundle::addUserQueue(const QueueItemPtr& qi, const HintedUser& aUser, bool
}
}

QueueItemPtr Bundle::getNextQI(const UserPtr& aUser, const OrderedStringSet& aOnlineHubs, string& aLastError, Priority aMinPrio, int64_t aWantedSize, int64_t aLastSpeed, QueueItemBase::DownloadType aType, bool aAllowOverlap) noexcept {
QueueItemPtr Bundle::getNextQI(const QueueDownloadQuery& aQuery, string& lastError_, bool aAllowOverlap) noexcept {
int p = static_cast<int>(Priority::LAST) - 1;
do {
auto i = userQueue[p].find(aUser);
auto i = userQueue[p].find(aQuery.user);
if(i != userQueue[p].end()) {
dcassert(!i->second.empty());
for(auto& qi: i->second) {
if (qi->hasSegment(aUser, aOnlineHubs, aLastError, aWantedSize, aLastSpeed, aType, aAllowOverlap)) {
if (qi->hasSegment(aQuery, lastError_, aAllowOverlap)) {
return qi;
}
}
}
p--;
} while(p >= static_cast<int>(aMinPrio));
} while(p >= static_cast<int>(aQuery.minPrio));

return nullptr;
}
Expand Down
3 changes: 2 additions & 1 deletion airdcpp-core/airdcpp/Bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "MerkleTree.h"
#include "User.h"

#include "QueueDownloadInfo.h"
#include "QueueItemBase.h"

namespace dcpp {
Expand Down Expand Up @@ -215,7 +216,7 @@ class Bundle : public QueueItemBase {
/** All queue items indexed by user */
void addUserQueue(const QueueItemPtr& qi) noexcept;
bool addUserQueue(const QueueItemPtr& qi, const HintedUser& aUser, bool aIsBad = false) noexcept;
QueueItemPtr getNextQI(const UserPtr& aUser, const OrderedStringSet& aOnlineHubs, string& aLastError, Priority aMinPrio, int64_t aWantedSize, int64_t aLastSpeed, QueueItemBase::DownloadType aType, bool allowOverlap) noexcept;
QueueItemPtr getNextQI(const QueueDownloadQuery& aQuery, string& lastError_, bool aAllowOverlap) noexcept;
void getItems(const UserPtr& aUser, QueueItemList& ql) const noexcept;

QueueItemList getFailedItems() const noexcept;
Expand Down
53 changes: 26 additions & 27 deletions airdcpp-core/airdcpp/ClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,72 +755,71 @@ OnlineUserPtr ClientManager::findOnlineUser(const CID& cid, const string& hintUr
return aAllowFallback ? p.first->second : nullptr;
}

bool ClientManager::connect(const UserPtr& aUser, const string& aToken, bool aAllowUrlChange, string& lastError_, string& hubHint_, bool& isProtocolError_, ConnectionType aConnType) const noexcept {
ClientManager::ConnectResult ClientManager::connect(const HintedUser& aUser, const string& aToken, bool aAllowUrlChange, ConnectionType aConnType) const noexcept {
ConnectResult result;

RLock l(cs);
auto op = onlineUsers.equal_range(const_cast<CID*>(&aUser->getCID()));
auto op = onlineUsers.equal_range(const_cast<CID*>(&aUser.user->getCID()));

auto connectUser = [&] (OnlineUser* ou) -> bool {
isProtocolError_ = false;
result.resetError();
// result.isProtocolError = false;

auto ret = ou->getClient()->connect(*ou, aToken, lastError_);
string connectError;
auto ret = ou->getClient()->connect(*ou, aToken, connectError);
if (ret == AdcCommand::SUCCESS) {
return true;
}

//get the error string
if (ret == AdcCommand::ERROR_TLS_REQUIRED) {
isProtocolError_ = true;
lastError_ = STRING(SOURCE_NO_ENCRYPTION);
result.onProtocolError(STRING(SOURCE_NO_ENCRYPTION));
} else if (ret == AdcCommand::ERROR_PROTOCOL_UNSUPPORTED) {
isProtocolError_ = true;
lastError_ = STRING_F(REMOTE_PROTOCOL_UNSUPPORTED, lastError_);
result.onProtocolError(STRING_F(REMOTE_PROTOCOL_UNSUPPORTED, connectError));
} else if (ret == AdcCommand::ERROR_BAD_STATE) {
lastError_ = STRING(CONNECTING_IN_PROGRESS);
result.onMinorError(STRING(CONNECTING_IN_PROGRESS));
} else if (ret == AdcCommand::ERROR_FEATURE_MISSING) {
isProtocolError_ = true;
lastError_ = STRING(NO_NATT_SUPPORT);
result.onProtocolError(STRING(NO_NATT_SUPPORT));
} else if (ret == AdcCommand::ERROR_PROTOCOL_GENERIC) {
isProtocolError_ = true;
lastError_ = STRING(UNABLE_CONNECT_USER);
result.onProtocolError(STRING(UNABLE_CONNECT_USER));
}

return false;
};

if (aConnType == CONNECTION_TYPE_PM) {
if (!aUser->isSet(User::TLS)) {
isProtocolError_ = true;
lastError_ = STRING(SOURCE_NO_ENCRYPTION);
return false;
if (!aUser.user->isSet(User::TLS)) {
result.onProtocolError(STRING(SOURCE_NO_ENCRYPTION));
return result;
}

// We don't care which hub we use to establish the connection all we need to know is the user supports the CCPM feature.
if (!aUser->isSet(User::CCPM)) {
isProtocolError_ = true;
lastError_ = STRING(CCPM_NOT_SUPPORTED);
return false;
if (!aUser.user->isSet(User::CCPM)) {
result.onProtocolError(STRING(CCPM_NOT_SUPPORTED));
return result;
}
}

// Prefer the hinted hub
auto p = ranges::find_if(op | pair_to_range, [&hubHint_](const auto& ouc) { return ouc.second->getHubUrl() == hubHint_; });
auto p = ranges::find_if(op | pair_to_range, [&aUser](const auto& ouc) { return ouc.second->getHubUrl() == aUser.hint; });
if (p != op.second && connectUser(p->second)) {
return true;
result.onSuccess(aUser.hint);
return result;
}

if (!aAllowUrlChange) {
return false;
return result;
}

// Connect via any available hub
for (auto i = op.first; i != op.second; ++i) {
if (connectUser(i->second)) {
hubHint_ = i->second->getHubUrl();
return true;
result.onSuccess(i->second->getHubUrl());
return result;
}
}

return false;
return result;
}

bool ClientManager::privateMessageHooked(const HintedUser& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho) noexcept {
Expand Down
32 changes: 31 additions & 1 deletion airdcpp-core/airdcpp/ClientManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,37 @@ class ClientManager : public Speaker<ClientManagerListener>,
bool sendUDPHooked(AdcCommand& c, const CID& to, bool aNoCID = false, bool aNoPassive = false, const string& aEncryptionKey = Util::emptyString, const string& aHubUrl = Util::emptyString) noexcept;
bool sendUDP(const string& aData, const string& aIP, const string& aPort) noexcept;

bool connect(const UserPtr& aUser, const string& aToken, bool aAllowUrlChange, string& lastError_, string& hubHint_, bool& isProtocolError_, ConnectionType type = CONNECTION_TYPE_LAST) const noexcept;
struct ConnectResult {
public:
void onSuccess(const string& aHubHint) noexcept {
success = true;
hubHint = aHubHint;
}

void onMinorError(const string& aError) noexcept {
lastError = aError;
protocolError = false;
}

void onProtocolError(const string& aError) noexcept {
lastError = aError;
protocolError = true;
}

void resetError() noexcept {
lastError = Util::emptyString;
protocolError = false;
}


GETPROP(string, lastError, Error);
IGETPROP(bool, protocolError, IsProtocolError, false);

GETPROP(string, hubHint, HubHint);
IGETPROP(bool, success, IsSuccess, false);
};

ConnectResult connect(const HintedUser& aUser, const string& aToken, bool aAllowUrlChange, ConnectionType type = CONNECTION_TYPE_LAST) const noexcept;
bool privateMessageHooked(const HintedUser& aUser, const OutgoingChatMessage& aMessage, string& error_, bool aEcho = true) noexcept;
void userCommand(const HintedUser& aUser, const UserCommand& uc, ParamMap& params_, bool aCompatibility) noexcept;

Expand Down
Loading

0 comments on commit f8b5616

Please sign in to comment.