streaming api functions added

This commit is contained in:
orignal 2014-11-18 09:33:58 -05:00
parent 72c0d8443a
commit 77b7fff5ed
5 changed files with 62 additions and 26 deletions

View file

@ -14,11 +14,9 @@ namespace i2p
{
namespace api
{
static std::map<i2p::data::IdentHash, i2p::client::ClientDestination *> g_Destinations;
void InitI2P (int argc, char* argv[])
void InitI2P (int argc, char* argv[], const char * appName)
{
i2p::util::filesystem::SetAppName ("i2papi");
i2p::util::filesystem::SetAppName (appName);
i2p::util::config::OptionParser(argc, argv);
i2p::context.Init ();
}
@ -43,29 +41,19 @@ namespace api
LogPrint("Transports stoped");
i2p::data::netdb.Stop();
LogPrint("NetDB stoped");
for (auto it: g_Destinations)
{
it.second->Stop ();
delete it.second;
}
g_Destinations.clear ();
LogPrint("Local destinations deleted");
StopLog ();
}
i2p::client::ClientDestination * CreateLocalDestination (const i2p::data::PrivateKeys& keys)
i2p::client::ClientDestination * CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
{
auto localDestination = new i2p::client::ClientDestination (keys, true); // public
g_Destinations[localDestination->GetIdentHash ()] = localDestination;
auto localDestination = new i2p::client::ClientDestination (keys, isPublic);
localDestination->Start ();
return localDestination;
}
i2p::client::ClientDestination * CreateLocalDestination (i2p::data::SigningKeyType sigType)
i2p::client::ClientDestination * CreateLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
{
auto localDestination = new i2p::client::ClientDestination (true, sigType); // public
g_Destinations[localDestination->GetIdentHash ()] = localDestination;
auto localDestination = new i2p::client::ClientDestination (isPublic, sigType);
localDestination->Start ();
return localDestination;
}
@ -75,10 +63,46 @@ namespace api
if (dest)
{
dest->Stop ();
g_Destinations.erase (dest->GetIdentHash ());
delete dest;
}
}
void RequestLeaseSet (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote)
{
if (dest)
i2p::data::netdb.RequestDestination (remote, true, dest->GetTunnelPool ());
}
i2p::stream::Stream * CreateStream (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote)
{
auto leaseSet = i2p::data::netdb.FindLeaseSet (remote);
if (leaseSet)
{
auto stream = dest->CreateStream (*leaseSet);
stream->Send (nullptr, 0); // connect
return stream;
}
else
{
RequestLeaseSet (dest, remote);
return nullptr;
}
}
void AcceptStream (i2p::client::ClientDestination * dest, const i2p::stream::StreamingDestination::Acceptor& acceptor)
{
if (dest)
dest->AcceptStreams (acceptor);
}
void DestroyStream (i2p::stream::Stream * stream)
{
if (stream)
{
stream->Close ();
i2p::stream::DeleteStream (stream);
}
}
}
}