introduced ClientContext

This commit is contained in:
orignal 2014-10-15 20:52:17 -04:00
parent 18d6a2c70e
commit 89e5b56a19
13 changed files with 234 additions and 221 deletions

View file

@ -353,158 +353,5 @@ namespace stream
}
return nullptr;
}
StreamingDestinations destinations;
void StreamingDestinations::Start ()
{
if (!m_SharedLocalDestination)
{
m_SharedLocalDestination = new StreamingDestination (false, i2p::data::SIGNING_KEY_TYPE_DSA_SHA1); // non-public, DSA
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
m_SharedLocalDestination->Start ();
}
}
void StreamingDestinations::Stop ()
{
for (auto it: m_Destinations)
{
it.second->Stop ();
delete it.second;
}
m_Destinations.clear ();
m_SharedLocalDestination = 0; // deleted through m_Destination
}
void StreamingDestinations::LoadLocalDestinations ()
{
int numDestinations = 0;
boost::filesystem::path p (i2p::util::filesystem::GetDataDir());
boost::filesystem::directory_iterator end;
for (boost::filesystem::directory_iterator it (p); it != end; ++it)
{
if (boost::filesystem::is_regular_file (*it) && it->path ().extension () == ".dat")
{
auto fullPath =
#if BOOST_VERSION > 10500
it->path().string();
#else
it->path();
#endif
auto localDestination = new StreamingDestination (fullPath, true);
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
numDestinations++;
}
}
if (numDestinations > 0)
LogPrint (numDestinations, " local destinations loaded");
}
StreamingDestination * StreamingDestinations::LoadLocalDestination (const std::string& filename, bool isPublic)
{
auto localDestination = new StreamingDestination (i2p::util::filesystem::GetFullPath (filename), isPublic);
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
localDestination->Start ();
return localDestination;
}
StreamingDestination * StreamingDestinations::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
{
auto localDestination = new StreamingDestination (isPublic, sigType);
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
localDestination->Start ();
return localDestination;
}
void StreamingDestinations::DeleteLocalDestination (StreamingDestination * destination)
{
if (!destination) return;
auto it = m_Destinations.find (destination->GetIdentHash ());
if (it != m_Destinations.end ())
{
auto d = it->second;
{
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations.erase (it);
}
d->Stop ();
delete d;
}
}
StreamingDestination * StreamingDestinations::CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
{
auto it = m_Destinations.find (keys.GetPublic ().GetIdentHash ());
if (it != m_Destinations.end ())
{
LogPrint ("Local destination ", keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p exists");
if (!it->second->IsRunning ())
{
it->second->Start ();
return it->second;
}
return nullptr;
}
auto localDestination = new StreamingDestination (keys, isPublic);
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
localDestination->Start ();
return localDestination;
}
StreamingDestination * StreamingDestinations::FindLocalDestination (const i2p::data::IdentHash& destination) const
{
auto it = m_Destinations.find (destination);
if (it != m_Destinations.end ())
return it->second;
return nullptr;
}
void StartStreaming ()
{
destinations.Start ();
}
void StopStreaming ()
{
destinations.Stop ();
}
StreamingDestination * GetSharedLocalDestination ()
{
return destinations.GetSharedLocalDestination ();
}
StreamingDestination * CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
{
return destinations.CreateNewLocalDestination (isPublic, sigType);
}
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
{
return destinations.CreateNewLocalDestination (keys, isPublic);
}
void DeleteLocalDestination (StreamingDestination * destination)
{
destinations.DeleteLocalDestination (destination);
}
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination)
{
return destinations.FindLocalDestination (destination);
}
StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic)
{
return destinations.LoadLocalDestination (filename, isPublic);
}
const StreamingDestinations& GetLocalDestinations ()
{
return destinations;
}
}
}