Skip to content

Commit

Permalink
Squashed 'airdcpp-core/' changes from 387ca5f..875173e
Browse files Browse the repository at this point in the history
875173e Fix connecting when allow untrusted clients option is disabled
883fc53 Fix invalid grouping in transfer view
a28563c Cleanup

git-subtree-dir: airdcpp-core
git-subtree-split: 875173e4e07da89de737304cf80e8b5cfd62be0f
  • Loading branch information
maksis committed Feb 9, 2016
1 parent 9f9ff49 commit c023bd9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
8 changes: 3 additions & 5 deletions airdcpp/ConnectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void ConnectionManager::attemptDownloads(uint64_t aTick, StringList& removedToke
continue;
}

cqi->setLastBundle(Util::toString(bundleToken));
cqi->setLastBundle(bundleToken != 0 ? Util::toString(bundleToken) : Util::emptyString);
cqi->setHubUrl(hubHint);

if (cqi->getState() == ConnectionQueueItem::WAITING) {
Expand Down Expand Up @@ -571,13 +571,11 @@ void ConnectionManager::adcConnect(const OnlineUser& aUser, const string& aPort,

try {
if (aUser.getIdentity().getConnectMode() == Identity::MODE_ACTIVE_DUAL) {
uc->connect(Socket::AddressInfo(aUser.getIdentity().getIp4(), aUser.getIdentity().getIp6()), aPort, localPort, natRole);
uc->connect(Socket::AddressInfo(aUser.getIdentity().getIp4(), aUser.getIdentity().getIp6()), aPort, localPort, natRole, aUser);
} else {
auto ai = Socket::AddressInfo(aUser.getIdentity().getIp(), aUser.getIdentity().allowV6Connections() ? Socket::AddressInfo::TYPE_V6 : Socket::AddressInfo::TYPE_V4);
uc->connect(move(ai), aPort, localPort, natRole);
uc->connect(move(ai), aPort, localPort, natRole, aUser);
}

uc->setUser(aUser);
} catch(const Exception&) {
putConnection(uc);
delete uc;
Expand Down
11 changes: 6 additions & 5 deletions airdcpp/QueueManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ void QueueManager::removeFileSource(QueueItemPtr& q, const UserPtr& aUser, Flags
}
}

void QueueManager::removeSource(const UserPtr& aUser, Flags::MaskType reason, std::function<bool (const QueueItemPtr&) > excludeF /*nullptr*/) noexcept {
int QueueManager::removeSource(const UserPtr& aUser, Flags::MaskType reason, std::function<bool (const QueueItemPtr&) > excludeF /*nullptr*/) noexcept {
// @todo remove from finished items
QueueItemList ql;

Expand All @@ -2056,6 +2056,7 @@ void QueueManager::removeSource(const UserPtr& aUser, Flags::MaskType reason, st
}

fire(QueueManagerListener::SourceFilesUpdated(), aUser);
return static_cast<int>(ql.size());
}

void QueueManager::setBundlePriority(QueueToken aBundleToken, QueueItemBase::Priority p) noexcept {
Expand Down Expand Up @@ -3920,19 +3921,19 @@ void QueueManager::removeBundleLists(BundlePtr& aBundle) noexcept{
removeQI(qi);
}

MemoryInputStream* QueueManager::generateTTHList(QueueToken aBundleToken, bool isInSharingHub) throw(QueueException) {
MemoryInputStream* QueueManager::generateTTHList(QueueToken aBundleToken, bool isInSharingHub, BundlePtr& bundle_) throw(QueueException) {
if(!isInSharingHub)
throw QueueException(UserConnection::FILE_NOT_AVAILABLE);

string tths;
StringOutputStream tthList(tths);
{
RLock l(cs);
BundlePtr b = bundleQueue.findBundle(aBundleToken);
if (b) {
bundle_ = bundleQueue.findBundle(aBundleToken);
if (bundle_) {
//write finished items
string tmp2;
for(auto& q: b->getFinishedFiles()) {
for(auto& q: bundle_->getFinishedFiles()) {
if (q->isSet(QueueItem::FLAG_MOVED)) {
tmp2.clear();
tthList.write(q->getTTH().toBase32(tmp2) + " ");
Expand Down
5 changes: 3 additions & 2 deletions airdcpp/QueueManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class QueueManager : public Singleton<QueueManager>, public Speaker<QueueManager
void removeFileSource(const string& aTarget, const UserPtr& aUser, Flags::MaskType reason, bool removeConn = true) noexcept;

// Remove source from all files. excludeF can be used to filter certain files from removal.
void removeSource(const UserPtr& aUser, Flags::MaskType reason, std::function<bool (const QueueItemPtr&) > excludeF = nullptr) noexcept;
// Returns the number of files from which the source was removed
int removeSource(const UserPtr& aUser, Flags::MaskType reason, std::function<bool (const QueueItemPtr&) > excludeF = nullptr) noexcept;

// Set priority for all bundles
// Won't affect bundles that are added later
Expand Down Expand Up @@ -265,7 +266,7 @@ class QueueManager : public Singleton<QueueManager>, public Speaker<QueueManager

// Queue a TTH list from the user containing the supplied TTH
void addBundleTTHList(const HintedUser& aUser, const string& aRemoteBundleToken, const TTHValue& tth) throw(QueueException);
MemoryInputStream* generateTTHList(QueueToken aBundleToken, bool isInSharingHub) throw(QueueException);
MemoryInputStream* generateTTHList(QueueToken aBundleToken, bool isInSharingHub, BundlePtr& bundle_) throw(QueueException);

//Bundle download failed due to Ex. disk full
void bundleDownloadFailed(BundlePtr& aBundle, const string& aError);
Expand Down
7 changes: 4 additions & 3 deletions airdcpp/UploadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,14 @@ bool UploadManager::prepareFile(UserConnection& aSource, const string& aType, co
// Partial file list
if (tthList) {
if (aFile[0] != '/') {
auto token = Util::toUInt32(aFile);
mis.reset(QueueManager::getInstance()->generateTTHList(token, *profile != SP_HIDDEN));
BundlePtr bundle = nullptr;
mis.reset(QueueManager::getInstance()->generateTTHList(Util::toUInt32(aFile), *profile != SP_HIDDEN, bundle));

// We don't want to show the token in transfer view
auto bundle = QueueManager::getInstance()->findBundle(token);
if (bundle) {
sourceFile = bundle->getName();
} else {
dcassert(0);
}
} else {
mis.reset(ShareManager::getInstance()->generateTTHList(aFile, listRecursive, *profile));
Expand Down
18 changes: 14 additions & 4 deletions airdcpp/UserConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,18 @@ void UserConnection::on(BufferedSocketListener::Line, const string& aLine) throw
}
}

void UserConnection::connect(const Socket::AddressInfo& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole) {
void UserConnection::connect(const Socket::AddressInfo& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole, const UserPtr& aUser /*nullptr*/) {
dcassert(!socket);

socket = BufferedSocket::getSocket(0);
socket->addListener(this);

// TODO: verify that this KeyPrint was mediated by a trusted hub?
string expKP = user ? ClientManager::getInstance()->getField(user->getCID(), hubUrl, "KP") : Util::emptyString;
string expKP;
if (aUser) {
expKP = ClientManager::getInstance()->getField(aUser->getCID(), hubUrl, "KP");
setUser(aUser);
}

socket->connect(aServer, aPort, localPort, natRole, secure, SETTING(ALLOW_UNTRUSTED_CLIENTS), true, expKP);
}

Expand Down Expand Up @@ -203,7 +207,13 @@ void UserConnection::accept(const Socket& aServer) {
dcassert(!socket);
socket = BufferedSocket::getSocket(0);
socket->addListener(this);
socket->accept(aServer, secure, SETTING(ALLOW_UNTRUSTED_CLIENTS));

/*
Technically only one side needs to verify KeyPrint,
also since we most likely requested to be connected to (and we have insufficient info otherwise) deal with TLS options check post handshake
-> SSLSocket::verifyKeyprint does full certificate verification after INF
*/
socket->accept(aServer, secure, true);
}

void UserConnection::inf(bool withToken, int mcnSlots) {
Expand Down
2 changes: 1 addition & 1 deletion airdcpp/UserConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class UserConnection : public Speaker<UserConnectionListener>,
void setDataMode(int64_t aBytes = -1) { dcassert(socket); socket->setDataMode(aBytes); }
void setLineMode(size_t rollback) { dcassert(socket); socket->setLineMode(rollback); }

void connect(const Socket::AddressInfo& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole);
void connect(const Socket::AddressInfo& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole, const UserPtr& aUser = nullptr);
void accept(const Socket& aServer);

void handlePM(const AdcCommand& c, bool echo) noexcept;
Expand Down

0 comments on commit c023bd9

Please sign in to comment.