mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01: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:
|
||||
Daemon_Singleton_Private() : httpServer(nullptr), httpProxy(nullptr),
|
||||
socksProxy(nullptr), ircTunnel(nullptr) { };
|
||||
socksProxy(nullptr), ircTunnel(nullptr), serverTunnel (nullptr) { };
|
||||
~Daemon_Singleton_Private() {
|
||||
delete httpServer;
|
||||
delete httpProxy;
|
||||
delete socksProxy;
|
||||
delete ircTunnel;
|
||||
delete serverTunnel;
|
||||
};
|
||||
|
||||
i2p::util::HTTPServer *httpServer;
|
||||
i2p::proxy::HTTPProxy *httpProxy;
|
||||
i2p::proxy::SOCKSProxy *socksProxy;
|
||||
i2p::stream::I2PClientTunnel * ircTunnel;
|
||||
i2p::stream::I2PServerTunnel * serverTunnel;
|
||||
};
|
||||
|
||||
Daemon_Singleton::Daemon_Singleton() : running(1), d(*new Daemon_Singleton_Private()) {};
|
||||
|
@ -117,6 +119,16 @@ namespace i2p
|
|||
d.ircTunnel->Start ();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -147,6 +159,14 @@ namespace i2p
|
|||
d.ircTunnel = nullptr;
|
||||
LogPrint("IRC tunnel stoped");
|
||||
}
|
||||
if (d.serverTunnel)
|
||||
{
|
||||
d.serverTunnel->Stop ();
|
||||
delete d.serverTunnel;
|
||||
d.serverTunnel = nullptr;
|
||||
LogPrint("Server tunnel stoped");
|
||||
}
|
||||
|
||||
StopLog ();
|
||||
|
||||
delete d.socksProxy; d.socksProxy = nullptr;
|
||||
|
|
|
@ -46,6 +46,14 @@ namespace data
|
|||
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:
|
||||
|
||||
union // 8 bytes alignment
|
||||
|
@ -156,6 +164,7 @@ namespace data
|
|||
const uint8_t * GetSigningPrivateKey () const { return m_SigningPrivateKey; };
|
||||
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 ToBuffer (uint8_t * buf, size_t len) const;
|
||||
|
||||
|
|
|
@ -53,5 +53,7 @@ Options
|
|||
* --socksproxyport= - The port to listen on (SOCKS Proxy)
|
||||
* --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
|
||||
|
||||
* --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);
|
||||
m_Keys.FromBuffer (buf, len);
|
||||
delete[] buf;
|
||||
LogPrint ("Local address ", m_Keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p loaded");
|
||||
}
|
||||
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);
|
||||
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
||||
|
@ -627,7 +640,7 @@ namespace stream
|
|||
m_SharedLocalDestination = new StreamingDestination (m_Service);
|
||||
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
||||
}
|
||||
LoadLocalDestinations ();
|
||||
// LoadLocalDestinations ();
|
||||
|
||||
m_IsRunning = true;
|
||||
m_Thread = new std::thread (std::bind (&StreamingDestinations::Run, this));
|
||||
|
@ -671,7 +684,7 @@ namespace stream
|
|||
it->path();
|
||||
#endif
|
||||
auto localDestination = new StreamingDestination (m_Service, fullPath);
|
||||
m_Destinations[localDestination->GetIdentity ().GetIdentHash ()] = localDestination;
|
||||
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
||||
numDestinations++;
|
||||
}
|
||||
}
|
||||
|
@ -679,6 +692,13 @@ namespace stream
|
|||
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)
|
||||
{
|
||||
if (!m_SharedLocalDestination) return nullptr;
|
||||
|
@ -753,6 +773,11 @@ namespace stream
|
|||
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)
|
||||
{
|
||||
uint32_t length = be32toh (*(uint32_t *)buf);
|
||||
|
|
|
@ -193,6 +193,7 @@ namespace stream
|
|||
void DeleteStream (Stream * stream);
|
||||
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||||
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -217,6 +218,7 @@ namespace stream
|
|||
void StopStreaming ();
|
||||
StreamingDestination * GetSharedLocalDestination ();
|
||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
||||
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
||||
|
||||
// assuming data is I2CP message
|
||||
void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len);
|
||||
|
|
Loading…
Reference in a new issue