Skip to content
Browse files

[daemon/router/Asset]Fail immediately if no upstreams available to bi…

…nd to.
  • Loading branch information...
1 parent ebab9f3 commit ce4f6302fd7a2e7f89a2028ecb6e293d5d3c12ff @rawler committed
Showing with 19 additions and 24 deletions.
  1. +17 −12 bithorded/router/asset.cpp
  2. +1 −1 bithorded/router/asset.hpp
  3. +1 −10 bithorded/router/router.cpp
  4. +0 −1 bithorded/router/router.hpp
View
29 bithorded/router/asset.cpp
@@ -17,6 +17,7 @@
#include "asset.hpp"
+#include <boost/foreach.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <utility>
@@ -30,18 +31,22 @@ bool bithorded::router::ForwardedAsset::hasUpstream(const std::string peername)
return _upstream.count(peername);
}
-void bithorded::router::ForwardedAsset::bindUpstream(const bithorded::Client::Ptr& f, uint64_t uuid)
+void bithorded::router::ForwardedAsset::bindUpstreams(const std::map< string, bithorded::Client::Ptr >& friends, uint64_t uuid)
{
- if (f->requestsAsset(_ids)) // This path surely doesn't have the asset.
- return;
- auto upstream = new bithorde::ReadAsset(f, _ids);
- auto peername = f->peerName();
- upstream->statusUpdate.connect(boost::bind(&ForwardedAsset::onUpstreamStatus, this, peername, bithorde::ASSET_ARG_STATUS));
- upstream->dataArrived.connect(boost::bind(&ForwardedAsset::onData, this,
- bithorde::ASSET_ARG_OFFSET, bithorde::ASSET_ARG_DATA, bithorde::ASSET_ARG_TAG));
- auto& upstream_ = _upstream[peername];
- upstream_.reset(upstream);
- f->bind(*upstream_, uuid);
+ BOOST_FOREACH(auto f_, friends) {
+ auto f = f_.second;
+ if (f->requestsAsset(_ids)) // This path surely doesn't have the asset.
+ continue;
+ auto upstream = new bithorde::ReadAsset(f, _ids);
+ auto peername = f->peerName();
+ upstream->statusUpdate.connect(boost::bind(&ForwardedAsset::onUpstreamStatus, this, peername, bithorde::ASSET_ARG_STATUS));
+ upstream->dataArrived.connect(boost::bind(&ForwardedAsset::onData, this,
+ bithorde::ASSET_ARG_OFFSET, bithorde::ASSET_ARG_DATA, bithorde::ASSET_ARG_TAG));
+ auto& upstream_ = _upstream[peername];
+ upstream_.reset(upstream);
+ f->bind(*upstream_, uuid);
+ }
+ updateStatus();
}
void bithorded::router::ForwardedAsset::onUpstreamStatus(const string& peername, const bithorde::AssetStatus& status)
@@ -62,7 +67,7 @@ void bithorded::router::ForwardedAsset::onUpstreamStatus(const string& peername,
DLOG(INFO) << "Failed upstream " << peername;
_upstream.erase(peername);
}
- updateStatus();
+ updateStatus();
}
void bithorded::router::ForwardedAsset::updateStatus() {
View
2 bithorded/router/asset.hpp
@@ -57,7 +57,7 @@ class ForwardedAsset : public bithorded::Asset
{}
bool hasUpstream(const std::string peername);
- void bindUpstream(const bithorded::Client::Ptr& f, uint64_t uuid);
+ void bindUpstreams(const std::map<std::string, Client::Ptr>& friends, uint64_t uuid);
virtual size_t can_read(uint64_t offset, size_t size);
virtual bool getIds(BitHordeIds& ids);
View
11 bithorded/router/router.cpp
@@ -128,19 +128,10 @@ bithorded::Asset::Ptr bithorded::router::Router::findAsset(const bithorde::BindR
auto asset = boost::make_shared<ForwardedAsset, Router&, const BitHordeIds&>(*this, req.ids());
_sessionMap[req.uuid()] = asset;
- bindAsset(asset, req.uuid());
+ asset->bindUpstreams(_connectedFriends, req.uuid());
return asset;
}
-void Router::bindAsset(const bithorded::router::ForwardedAsset::Ptr& asset, uint64_t uuid)
-{
- for (auto iter = _connectedFriends.begin(); iter != _connectedFriends.end(); iter++) {
- auto f = iter->second;
- if (!asset->hasUpstream(f->peerName()))
- asset->bindUpstream(f, uuid);
- }
-}
-
View
1 bithorded/router/router.hpp
@@ -54,7 +54,6 @@ class Router
void onDisconnected(const bithorded::Client::Ptr& client);
bithorded::Asset::Ptr findAsset(const bithorde::BindRead& req);
- void bindAsset(const bithorded::router::ForwardedAsset::Ptr& asset, uint64_t uuid);
};
}}

0 comments on commit ce4f630

Please sign in to comment.
Something went wrong with that request. Please try again.