Esempio n. 1
0
IAsset::Ptr AssetStore::openAsset(const bithorde::BindRead& req)
{
	auto tigerId = findBithordeId(req.ids(), bithorde::HashType::TREE_TIGER);
	if (tigerId.empty())
		return IAsset::Ptr();
	auto assetId = _index.lookupTiger(tigerId);
	if (assetId.empty())
		return IAsset::Ptr();

	auto assetPath = _assetsFolder / assetId;
	try {
		if (auto res = openAsset(assetPath)) {
			updateAsset(res->status->ids(), static_pointer_cast<StoredAsset>(res));
			return res;
		} else {
			removeAsset(assetPath);
		}
	} catch (const boost::system::system_error& e) {
		if (e.code().value() == bsys::errc::no_such_file_or_directory) {
			BOOST_LOG_SEV(storeLog, error) << "Linked asset " << assetPath << "broken. Purging...";
			removeAsset(assetPath);
		} else if (e.code().value() == bsys::errc::file_exists) {
			BOOST_LOG_SEV(storeLog, error) << "Linked asset " << assetPath << "exists with wrong size. Purging...";
			removeAsset(assetPath);
		} else {
			BOOST_LOG_SEV(storeLog, error) << "Failed to open " << assetPath << " with unknown error " << e.what();
		}
	} catch (const std::ios::failure& e) {
		BOOST_LOG_SEV(storeLog, error) << "Failed to open " << assetPath << " with unknown error " << e.what();
	}
	return IAsset::Ptr();
}
Esempio n. 2
0
bithorded::IAsset::Ptr bithorded::router::Router::openAsset(const bithorde::BindRead& req)
{
	BOOST_ASSERT(req.has_uuid());
	int timeout = req.has_timeout() ? req.timeout()-20 : 500; // TODO: Find actual reasonable time message has been in air. Use DEFAULT_ASSET_TIMEOUT from library.
	if (timeout <= 0)
		return bithorded::IAsset::Ptr();

	auto asset = boost::make_shared<ForwardedAsset, Router&, const BitHordeIds&>(*this, req.ids());

	asset->bindUpstreams(_connectedFriends, req.uuid(), timeout);
	return asset;
}
Esempio n. 3
0
IAsset::Ptr AssetStore::openAsset(const bithorde::BindRead& req)
{
	auto assetPath = resolveIds(req.ids());
	if (assetPath.empty())
		return IAsset::Ptr();
	else try {
		return openAsset(assetPath);
	} catch (const boost::system::system_error& e) {
		if (e.code().value() == bsys::errc::no_such_file_or_directory) {
			LOG4CPLUS_ERROR(storeLog, "Linked asset " << assetPath << "broken. Purging...");
			unlinkAndRemove(req.ids());
		} else if (e.code().value() == bsys::errc::file_exists) {
			LOG4CPLUS_ERROR(storeLog, "Linked asset " << assetPath << "exists with wrong size. Purging...");
			unlinkAndRemove(req.ids());
		} else {
			LOG4CPLUS_ERROR(storeLog, "Failed to open " << assetPath << " with unknown error " << e.what());
		}
	} catch (const std::ios::failure& e) {
		LOG4CPLUS_ERROR(storeLog, "Failed to open " << assetPath << " with unknown error " << e.what());
	}
	return IAsset::Ptr();
}
Esempio n. 4
0
bithorded::UpstreamRequestBinding::Ptr bithorded::AssetSessions::findAsset(const bithorde::BindRead& req)
{
	auto tigerId = findBithordeId(req.ids(), bithorde::HashType::TREE_TIGER);
	if (tigerId.empty())
		return UpstreamRequestBinding::Ptr();
	if (auto active = _tigerCache[tigerId])
		return active;

	UpstreamRequestBinding::Ptr res;
	if (auto asset = openAsset(req)) {
		res = boost::make_shared<UpstreamRequestBinding>(asset);
		add(tigerId, res);
	}
	return res;
}