mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
server tunnel parameters
This commit is contained in:
parent
72d52d61bc
commit
b3e389a67c
22
Daemon.cpp
22
Daemon.cpp
@ -26,18 +26,20 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Daemon_Singleton_Private() : httpServer(nullptr), httpProxy(nullptr),
|
Daemon_Singleton_Private() : httpServer(nullptr), httpProxy(nullptr),
|
||||||
socksProxy(nullptr), ircTunnel(nullptr) { };
|
socksProxy(nullptr), ircTunnel(nullptr), serverTunnel (nullptr) { };
|
||||||
~Daemon_Singleton_Private() {
|
~Daemon_Singleton_Private() {
|
||||||
delete httpServer;
|
delete httpServer;
|
||||||
delete httpProxy;
|
delete httpProxy;
|
||||||
delete socksProxy;
|
delete socksProxy;
|
||||||
delete ircTunnel;
|
delete ircTunnel;
|
||||||
|
delete serverTunnel;
|
||||||
};
|
};
|
||||||
|
|
||||||
i2p::util::HTTPServer *httpServer;
|
i2p::util::HTTPServer *httpServer;
|
||||||
i2p::proxy::HTTPProxy *httpProxy;
|
i2p::proxy::HTTPProxy *httpProxy;
|
||||||
i2p::proxy::SOCKSProxy *socksProxy;
|
i2p::proxy::SOCKSProxy *socksProxy;
|
||||||
i2p::stream::I2PClientTunnel * ircTunnel;
|
i2p::stream::I2PClientTunnel * ircTunnel;
|
||||||
|
i2p::stream::I2PServerTunnel * serverTunnel;
|
||||||
};
|
};
|
||||||
|
|
||||||
Daemon_Singleton::Daemon_Singleton() : running(1), d(*new Daemon_Singleton_Private()) {};
|
Daemon_Singleton::Daemon_Singleton() : running(1), d(*new Daemon_Singleton_Private()) {};
|
||||||
@ -117,6 +119,16 @@ namespace i2p
|
|||||||
d.ircTunnel->Start ();
|
d.ircTunnel->Start ();
|
||||||
LogPrint("IRC tunnel started");
|
LogPrint("IRC tunnel started");
|
||||||
}
|
}
|
||||||
|
std::string eepKeys = i2p::util::config::GetArg("-eepkeys", "");
|
||||||
|
if (eepKeys.length () > 0) // eepkeys file is presented
|
||||||
|
{
|
||||||
|
auto localDestination = i2p::stream::LoadLocalDestination (eepKeys);
|
||||||
|
d.serverTunnel = new i2p::stream::I2PServerTunnel (d.socksProxy->GetService (),
|
||||||
|
i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80),
|
||||||
|
localDestination->GetIdentHash ());
|
||||||
|
d.serverTunnel->Start ();
|
||||||
|
LogPrint("Server tunnel started");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +159,14 @@ namespace i2p
|
|||||||
d.ircTunnel = nullptr;
|
d.ircTunnel = nullptr;
|
||||||
LogPrint("IRC tunnel stoped");
|
LogPrint("IRC tunnel stoped");
|
||||||
}
|
}
|
||||||
|
if (d.serverTunnel)
|
||||||
|
{
|
||||||
|
d.serverTunnel->Stop ();
|
||||||
|
delete d.serverTunnel;
|
||||||
|
d.serverTunnel = nullptr;
|
||||||
|
LogPrint("Server tunnel stoped");
|
||||||
|
}
|
||||||
|
|
||||||
StopLog ();
|
StopLog ();
|
||||||
|
|
||||||
delete d.socksProxy; d.socksProxy = nullptr;
|
delete d.socksProxy; d.socksProxy = nullptr;
|
||||||
|
11
Identity.h
11
Identity.h
@ -46,6 +46,14 @@ namespace data
|
|||||||
return std::string (str);
|
return std::string (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ToBase32 () const
|
||||||
|
{
|
||||||
|
char str[sz*2];
|
||||||
|
int l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2);
|
||||||
|
str[l] = 0;
|
||||||
|
return std::string (str);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
union // 8 bytes alignment
|
union // 8 bytes alignment
|
||||||
@ -155,7 +163,8 @@ namespace data
|
|||||||
const uint8_t * GetPrivateKey () const { return m_PrivateKey; };
|
const uint8_t * GetPrivateKey () const { return m_PrivateKey; };
|
||||||
const uint8_t * GetSigningPrivateKey () const { return m_SigningPrivateKey; };
|
const uint8_t * GetSigningPrivateKey () const { return m_SigningPrivateKey; };
|
||||||
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
||||||
|
|
||||||
|
size_t GetFullLen () const { return m_Public.GetFullLen () + 256 + m_Public.GetSignatureLen ()/2; };
|
||||||
size_t FromBuffer (const uint8_t * buf, size_t len);
|
size_t FromBuffer (const uint8_t * buf, size_t len);
|
||||||
size_t ToBuffer (uint8_t * buf, size_t len) const;
|
size_t ToBuffer (uint8_t * buf, size_t len) const;
|
||||||
|
|
||||||
|
@ -53,5 +53,7 @@ Options
|
|||||||
* --socksproxyport= - The port to listen on (SOCKS Proxy)
|
* --socksproxyport= - The port to listen on (SOCKS Proxy)
|
||||||
* --ircport= - The local port of IRC tunnel to listen on. 6668 by default
|
* --ircport= - The local port of IRC tunnel to listen on. 6668 by default
|
||||||
* --ircdest= - I2P destination address of IRC server. For example irc.postman.i2p
|
* --ircdest= - I2P destination address of IRC server. For example irc.postman.i2p
|
||||||
|
* --eepkeys= - File name containing destination keys. For example privKeys.dat
|
||||||
|
* --eephost= - Address incoming trafic forward to. 127.0.0.1 by default
|
||||||
|
* --eepport= - Port incoming trafic forward to. 80 by default
|
||||||
|
|
||||||
|
@ -527,9 +527,22 @@ namespace stream
|
|||||||
s.read ((char *)buf, len);
|
s.read ((char *)buf, len);
|
||||||
m_Keys.FromBuffer (buf, len);
|
m_Keys.FromBuffer (buf, len);
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
|
LogPrint ("Local address ", m_Keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p loaded");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint ("Can't open file ", fullPath);
|
{
|
||||||
|
LogPrint ("Can't open file ", fullPath, " Creating new one");
|
||||||
|
// new eepsites use ECDSA
|
||||||
|
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
|
||||||
|
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
|
||||||
|
size_t len = m_Keys.GetFullLen ();
|
||||||
|
uint8_t * buf = new uint8_t[len];
|
||||||
|
len = m_Keys.ToBuffer (buf, len);
|
||||||
|
f.write ((char *)buf, len);
|
||||||
|
delete[] buf;
|
||||||
|
|
||||||
|
LogPrint ("New private keys file ", fullPath, " for ", m_Keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p created");
|
||||||
|
}
|
||||||
|
|
||||||
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||||||
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
||||||
@ -627,7 +640,7 @@ namespace stream
|
|||||||
m_SharedLocalDestination = new StreamingDestination (m_Service);
|
m_SharedLocalDestination = new StreamingDestination (m_Service);
|
||||||
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
||||||
}
|
}
|
||||||
LoadLocalDestinations ();
|
// LoadLocalDestinations ();
|
||||||
|
|
||||||
m_IsRunning = true;
|
m_IsRunning = true;
|
||||||
m_Thread = new std::thread (std::bind (&StreamingDestinations::Run, this));
|
m_Thread = new std::thread (std::bind (&StreamingDestinations::Run, this));
|
||||||
@ -671,7 +684,7 @@ namespace stream
|
|||||||
it->path();
|
it->path();
|
||||||
#endif
|
#endif
|
||||||
auto localDestination = new StreamingDestination (m_Service, fullPath);
|
auto localDestination = new StreamingDestination (m_Service, fullPath);
|
||||||
m_Destinations[localDestination->GetIdentity ().GetIdentHash ()] = localDestination;
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
||||||
numDestinations++;
|
numDestinations++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -679,6 +692,13 @@ namespace stream
|
|||||||
LogPrint (numDestinations, " local destinations loaded");
|
LogPrint (numDestinations, " local destinations loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamingDestination * StreamingDestinations::LoadLocalDestination (const std::string& filename)
|
||||||
|
{
|
||||||
|
auto localDestination = new StreamingDestination (m_Service, i2p::util::filesystem::GetFullPath (filename));
|
||||||
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
||||||
|
return localDestination;
|
||||||
|
}
|
||||||
|
|
||||||
Stream * StreamingDestinations::CreateClientStream (const i2p::data::LeaseSet& remote)
|
Stream * StreamingDestinations::CreateClientStream (const i2p::data::LeaseSet& remote)
|
||||||
{
|
{
|
||||||
if (!m_SharedLocalDestination) return nullptr;
|
if (!m_SharedLocalDestination) return nullptr;
|
||||||
@ -722,7 +742,7 @@ namespace stream
|
|||||||
return it->second;
|
return it->second;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream * CreateStream (const i2p::data::LeaseSet& remote)
|
Stream * CreateStream (const i2p::data::LeaseSet& remote)
|
||||||
{
|
{
|
||||||
return destinations.CreateClientStream (remote);
|
return destinations.CreateClientStream (remote);
|
||||||
@ -753,6 +773,11 @@ namespace stream
|
|||||||
return destinations.FindLocalDestination (destination);
|
return destinations.FindLocalDestination (destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamingDestination * LoadLocalDestination (const std::string& filename)
|
||||||
|
{
|
||||||
|
return destinations.LoadLocalDestination (filename);
|
||||||
|
}
|
||||||
|
|
||||||
void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len)
|
void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t length = be32toh (*(uint32_t *)buf);
|
uint32_t length = be32toh (*(uint32_t *)buf);
|
||||||
|
@ -193,6 +193,7 @@ namespace stream
|
|||||||
void DeleteStream (Stream * stream);
|
void DeleteStream (Stream * stream);
|
||||||
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||||||
|
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -216,7 +217,8 @@ namespace stream
|
|||||||
void StartStreaming ();
|
void StartStreaming ();
|
||||||
void StopStreaming ();
|
void StopStreaming ();
|
||||||
StreamingDestination * GetSharedLocalDestination ();
|
StreamingDestination * GetSharedLocalDestination ();
|
||||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
||||||
|
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
||||||
|
|
||||||
// assuming data is I2CP message
|
// assuming data is I2CP message
|
||||||
void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len);
|
void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user