mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
publish local destinations created by SAM session
This commit is contained in:
parent
05148a2579
commit
d04957bd15
4 changed files with 33 additions and 29 deletions
3
SAM.cpp
3
SAM.cpp
|
@ -186,7 +186,8 @@ namespace stream
|
||||||
size_t l = session->localDestination->GetPrivateKeys ().ToBuffer (ident, 1024);
|
size_t l = session->localDestination->GetPrivateKeys ().ToBuffer (ident, 1024);
|
||||||
size_t l1 = i2p::data::ByteStreamToBase64 (ident, l, m_Buffer + sizeof (SAM_SESSION_CREATE_REPLY_OK),
|
size_t l1 = i2p::data::ByteStreamToBase64 (ident, l, m_Buffer + sizeof (SAM_SESSION_CREATE_REPLY_OK),
|
||||||
SAM_SOCKET_BUFFER_SIZE - sizeof (SAM_SESSION_CREATE_REPLY_OK));
|
SAM_SOCKET_BUFFER_SIZE - sizeof (SAM_SESSION_CREATE_REPLY_OK));
|
||||||
SendMessageReply (m_Buffer, sizeof (SAM_SESSION_CREATE_REPLY_OK) + l1, false);
|
m_Buffer[sizeof (SAM_SESSION_CREATE_REPLY_OK) + l1] = '\n';
|
||||||
|
SendMessageReply (m_Buffer, sizeof (SAM_SESSION_CREATE_REPLY_OK) + l1 + 1, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, sizeof(SAM_SESSION_CREATE_DUPLICATED_ID), true);
|
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, sizeof(SAM_SESSION_CREATE_DUPLICATED_ID), true);
|
||||||
|
|
12
SAM.h
12
SAM.h
|
@ -16,15 +16,15 @@ namespace stream
|
||||||
const size_t SAM_SOCKET_BUFFER_SIZE = 4096;
|
const size_t SAM_SOCKET_BUFFER_SIZE = 4096;
|
||||||
const int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds
|
const int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds
|
||||||
const char SAM_HANDSHAKE[] = "HELLO VERSION";
|
const char SAM_HANDSHAKE[] = "HELLO VERSION";
|
||||||
const char SAM_HANDSHAKE_REPLY[] = "HELLO REPLY RESULT=OK VERSION=3.1";
|
const char SAM_HANDSHAKE_REPLY[] = "HELLO REPLY RESULT=OK VERSION=3.1\n";
|
||||||
const char SAM_SESSION_CREATE[] = "SESSION CREATE";
|
const char SAM_SESSION_CREATE[] = "SESSION CREATE";
|
||||||
const char SAM_SESSION_CREATE_REPLY_OK[] = "SESSION STATUS RESULT=OK DESTINATION=";
|
const char SAM_SESSION_CREATE_REPLY_OK[] = "SESSION STATUS RESULT=OK DESTINATION=";
|
||||||
const char SAM_SESSION_CREATE_DUPLICATED_ID[] = "SESSION STATUS RESULT=DUPLICATED_ID";
|
const char SAM_SESSION_CREATE_DUPLICATED_ID[] = "SESSION STATUS RESULT=DUPLICATED_ID\n";
|
||||||
const char SAM_STREAM_CONNECT[] = "STREAM CONNECT";
|
const char SAM_STREAM_CONNECT[] = "STREAM CONNECT";
|
||||||
const char SAM_STREAM_STATUS_OK[] = "STREAM STATUS RESULT=OK";
|
const char SAM_STREAM_STATUS_OK[] = "STREAM STATUS RESULT=OK\n";
|
||||||
const char SAM_STREAM_STATUS_INVALID_ID[] = "STREAM STATUS RESULT=INVALID_ID";
|
const char SAM_STREAM_STATUS_INVALID_ID[] = "STREAM STATUS RESULT=INVALID_ID\n";
|
||||||
const char SAM_STREAM_STATUS_CANT_REACH_PEER[] = "STREAM STATUS RESULT=CANT_REACH_PEER";
|
const char SAM_STREAM_STATUS_CANT_REACH_PEER[] = "STREAM STATUS RESULT=CANT_REACH_PEER\n";
|
||||||
const char SAM_STREAM_STATUS_I2P_ERROR[] = "STREAM STATUS RESULT=I2P_ERROR";
|
const char SAM_STREAM_STATUS_I2P_ERROR[] = "STREAM STATUS RESULT=I2P_ERROR\n";
|
||||||
const char SAM_STREAM_ACCEPT[] = "STREAM ACCEPT";
|
const char SAM_STREAM_ACCEPT[] = "STREAM ACCEPT";
|
||||||
const char SAM_PARAM_STYLE[] = "STYLE";
|
const char SAM_PARAM_STYLE[] = "STYLE";
|
||||||
const char SAM_PARAM_ID[] = "ID";
|
const char SAM_PARAM_ID[] = "ID";
|
||||||
|
|
|
@ -508,13 +508,15 @@ namespace stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StreamingDestination::StreamingDestination (boost::asio::io_service& service):
|
StreamingDestination::StreamingDestination (boost::asio::io_service& service, bool isPublic):
|
||||||
m_Service (service), m_LeaseSet (nullptr), m_IsPublic (false)
|
m_Service (service), m_LeaseSet (nullptr), m_IsPublic (isPublic)
|
||||||
{
|
{
|
||||||
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (/*i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256*/); // uncomment for ECDSA
|
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (/*i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256*/); // uncomment for ECDSA
|
||||||
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);
|
||||||
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
||||||
|
if (m_IsPublic)
|
||||||
|
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created");
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination::StreamingDestination (boost::asio::io_service& service, const std::string& fullPath):
|
StreamingDestination::StreamingDestination (boost::asio::io_service& service, const std::string& fullPath):
|
||||||
|
@ -530,13 +532,12 @@ 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");
|
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p loaded");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint ("Can't open file ", fullPath, " Creating new one");
|
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*/);
|
||||||
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
|
|
||||||
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
|
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
|
||||||
size_t len = m_Keys.GetFullLen ();
|
size_t len = m_Keys.GetFullLen ();
|
||||||
uint8_t * buf = new uint8_t[len];
|
uint8_t * buf = new uint8_t[len];
|
||||||
|
@ -552,12 +553,14 @@ namespace stream
|
||||||
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination::StreamingDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys):
|
StreamingDestination::StreamingDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys, bool isPublic):
|
||||||
m_Service (service), m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (false)
|
m_Service (service), m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic)
|
||||||
{
|
{
|
||||||
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);
|
||||||
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
||||||
|
if (m_IsPublic)
|
||||||
|
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created");
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination::~StreamingDestination ()
|
StreamingDestination::~StreamingDestination ()
|
||||||
|
@ -655,7 +658,7 @@ namespace stream
|
||||||
{
|
{
|
||||||
if (!m_SharedLocalDestination)
|
if (!m_SharedLocalDestination)
|
||||||
{
|
{
|
||||||
m_SharedLocalDestination = new StreamingDestination (m_Service);
|
m_SharedLocalDestination = new StreamingDestination (m_Service, false); // non-public
|
||||||
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
||||||
}
|
}
|
||||||
// LoadLocalDestinations ();
|
// LoadLocalDestinations ();
|
||||||
|
@ -717,9 +720,9 @@ namespace stream
|
||||||
return localDestination;
|
return localDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination * StreamingDestinations::CreateNewLocalDestination ()
|
StreamingDestination * StreamingDestinations::CreateNewLocalDestination (bool isPublic)
|
||||||
{
|
{
|
||||||
auto localDestination = new StreamingDestination (m_Service);
|
auto localDestination = new StreamingDestination (m_Service, isPublic);
|
||||||
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
||||||
return localDestination;
|
return localDestination;
|
||||||
}
|
}
|
||||||
|
@ -735,12 +738,12 @@ namespace stream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination * StreamingDestinations::GetLocalDestination (const i2p::data::PrivateKeys& keys)
|
StreamingDestination * StreamingDestinations::GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||||||
{
|
{
|
||||||
auto it = m_Destinations.find (keys.GetPublic ().GetIdentHash ());
|
auto it = m_Destinations.find (keys.GetPublic ().GetIdentHash ());
|
||||||
if (it != m_Destinations.end ())
|
if (it != m_Destinations.end ())
|
||||||
return it->second;
|
return it->second;
|
||||||
auto localDestination = new StreamingDestination (m_Service, keys);
|
auto localDestination = new StreamingDestination (m_Service, keys, isPublic);
|
||||||
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
|
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
|
||||||
return localDestination;
|
return localDestination;
|
||||||
}
|
}
|
||||||
|
@ -814,9 +817,9 @@ namespace stream
|
||||||
return destinations.GetSharedLocalDestination ();
|
return destinations.GetSharedLocalDestination ();
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination * CreateNewLocalDestination ()
|
StreamingDestination * CreateNewLocalDestination (bool isPublic)
|
||||||
{
|
{
|
||||||
return destinations.CreateNewLocalDestination ();
|
return destinations.CreateNewLocalDestination (isPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteLocalDestination (StreamingDestination * destination)
|
void DeleteLocalDestination (StreamingDestination * destination)
|
||||||
|
@ -824,9 +827,9 @@ namespace stream
|
||||||
destinations.DeleteLocalDestination (destination);
|
destinations.DeleteLocalDestination (destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys)
|
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||||||
{
|
{
|
||||||
return destinations.GetLocalDestination (keys);
|
return destinations.GetLocalDestination (keys, isPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination)
|
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination)
|
||||||
|
|
12
Streaming.h
12
Streaming.h
|
@ -141,9 +141,9 @@ namespace stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
StreamingDestination (boost::asio::io_service& service);
|
StreamingDestination (boost::asio::io_service& service, bool isPublic);
|
||||||
StreamingDestination (boost::asio::io_service& service, const std::string& fullPath);
|
StreamingDestination (boost::asio::io_service& service, const std::string& fullPath);
|
||||||
StreamingDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys);
|
StreamingDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||||
~StreamingDestination ();
|
~StreamingDestination ();
|
||||||
|
|
||||||
const i2p::data::LeaseSet * GetLeaseSet ();
|
const i2p::data::LeaseSet * GetLeaseSet ();
|
||||||
|
@ -197,9 +197,9 @@ namespace stream
|
||||||
Stream * CreateClientStream (const i2p::data::LeaseSet& remote);
|
Stream * CreateClientStream (const i2p::data::LeaseSet& remote);
|
||||||
void DeleteStream (Stream * stream);
|
void DeleteStream (Stream * stream);
|
||||||
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||||
StreamingDestination * CreateNewLocalDestination ();
|
StreamingDestination * CreateNewLocalDestination (bool isPublic);
|
||||||
void DeleteLocalDestination (StreamingDestination * destination);
|
void DeleteLocalDestination (StreamingDestination * destination);
|
||||||
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys);
|
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||||||
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
||||||
|
|
||||||
|
@ -225,9 +225,9 @@ namespace stream
|
||||||
void StartStreaming ();
|
void StartStreaming ();
|
||||||
void StopStreaming ();
|
void StopStreaming ();
|
||||||
StreamingDestination * GetSharedLocalDestination ();
|
StreamingDestination * GetSharedLocalDestination ();
|
||||||
StreamingDestination * CreateNewLocalDestination ();
|
StreamingDestination * CreateNewLocalDestination (bool isPublic = true);
|
||||||
void DeleteLocalDestination (StreamingDestination * destination);
|
void DeleteLocalDestination (StreamingDestination * destination);
|
||||||
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys);
|
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
|
||||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
||||||
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
StreamingDestination * LoadLocalDestination (const std::string& filename);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue