mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
2.6 KiB
111 lines
2.6 KiB
10 years ago
|
#include <string>
|
||
|
#include <map>
|
||
|
#include "Log.h"
|
||
|
#include "NetDb.h"
|
||
|
#include "Transports.h"
|
||
|
#include "Tunnel.h"
|
||
|
#include "RouterContext.h"
|
||
|
#include "Identity.h"
|
||
|
#include "Destination.h"
|
||
|
#include "util.h"
|
||
10 years ago
|
#include "api.h"
|
||
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
namespace api
|
||
|
{
|
||
10 years ago
|
void InitI2P (int argc, char* argv[], const char * appName)
|
||
10 years ago
|
{
|
||
10 years ago
|
i2p::util::filesystem::SetAppName (appName);
|
||
10 years ago
|
i2p::util::config::OptionParser(argc, argv);
|
||
|
i2p::context.Init ();
|
||
|
}
|
||
|
|
||
10 years ago
|
void StartI2P (std::ostream * logStream)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (logStream)
|
||
|
StartLog (logStream);
|
||
|
else
|
||
|
StartLog (i2p::util::filesystem::GetAppName () + ".log");
|
||
10 years ago
|
i2p::data::netdb.Start();
|
||
|
LogPrint("NetDB started");
|
||
|
i2p::transport::transports.Start();
|
||
|
LogPrint("Transports started");
|
||
|
i2p::tunnel::tunnels.Start();
|
||
|
LogPrint("Tunnels started");
|
||
|
}
|
||
|
|
||
|
void StopI2P ()
|
||
|
{
|
||
|
LogPrint("Shutdown started.");
|
||
|
i2p::tunnel::tunnels.Stop();
|
||
|
LogPrint("Tunnels stoped");
|
||
|
i2p::transport::transports.Stop();
|
||
|
LogPrint("Transports stoped");
|
||
|
i2p::data::netdb.Stop();
|
||
|
LogPrint("NetDB stoped");
|
||
|
StopLog ();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
i2p::client::ClientDestination * CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||
10 years ago
|
{
|
||
10 years ago
|
auto localDestination = new i2p::client::ClientDestination (keys, isPublic);
|
||
10 years ago
|
localDestination->Start ();
|
||
|
return localDestination;
|
||
|
}
|
||
|
|
||
10 years ago
|
i2p::client::ClientDestination * CreateLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
|
||
10 years ago
|
{
|
||
10 years ago
|
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType);
|
||
|
auto localDestination = new i2p::client::ClientDestination (keys, isPublic);
|
||
10 years ago
|
localDestination->Start ();
|
||
|
return localDestination;
|
||
|
}
|
||
|
|
||
|
void DestroyLocalDestination (i2p::client::ClientDestination * dest)
|
||
|
{
|
||
|
if (dest)
|
||
|
{
|
||
|
dest->Stop ();
|
||
|
delete dest;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
|
void RequestLeaseSet (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote)
|
||
|
{
|
||
|
if (dest)
|
||
|
i2p::data::netdb.RequestDestination (remote, true, dest->GetTunnelPool ());
|
||
|
}
|
||
|
|
||
10 years ago
|
std::shared_ptr<i2p::stream::Stream> CreateStream (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (!dest) return nullptr;
|
||
|
auto leaseSet = dest->FindLeaseSet (remote);
|
||
10 years ago
|
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);
|
||
|
}
|
||
|
|
||
10 years ago
|
void DestroyStream (std::shared_ptr<i2p::stream::Stream> stream)
|
||
10 years ago
|
{
|
||
|
if (stream)
|
||
|
stream->Close ();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|