mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
publish local destinations created by SAM session
This commit is contained in:
parent
05148a2579
commit
d04957bd15
3
SAM.cpp
3
SAM.cpp
@ -186,7 +186,8 @@ namespace stream
|
||||
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),
|
||||
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
|
||||
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 int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds
|
||||
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_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_STATUS_OK[] = "STREAM STATUS RESULT=OK";
|
||||
const char SAM_STREAM_STATUS_INVALID_ID[] = "STREAM STATUS RESULT=INVALID_ID";
|
||||
const char SAM_STREAM_STATUS_CANT_REACH_PEER[] = "STREAM STATUS RESULT=CANT_REACH_PEER";
|
||||
const char SAM_STREAM_STATUS_I2P_ERROR[] = "STREAM STATUS RESULT=I2P_ERROR";
|
||||
const char SAM_STREAM_STATUS_OK[] = "STREAM STATUS RESULT=OK\n";
|
||||
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\n";
|
||||
const char SAM_STREAM_STATUS_I2P_ERROR[] = "STREAM STATUS RESULT=I2P_ERROR\n";
|
||||
const char SAM_STREAM_ACCEPT[] = "STREAM ACCEPT";
|
||||
const char SAM_PARAM_STYLE[] = "STYLE";
|
||||
const char SAM_PARAM_ID[] = "ID";
|
||||
|
@ -508,13 +508,15 @@ namespace stream
|
||||
}
|
||||
|
||||
|
||||
StreamingDestination::StreamingDestination (boost::asio::io_service& service):
|
||||
m_Service (service), m_LeaseSet (nullptr), m_IsPublic (false)
|
||||
StreamingDestination::StreamingDestination (boost::asio::io_service& service, bool isPublic):
|
||||
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
|
||||
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||||
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
||||
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):
|
||||
@ -530,13 +532,12 @@ 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");
|
||||
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p loaded");
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
size_t len = m_Keys.GetFullLen ();
|
||||
uint8_t * buf = new uint8_t[len];
|
||||
@ -552,12 +553,14 @@ namespace stream
|
||||
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
||||
}
|
||||
|
||||
StreamingDestination::StreamingDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys):
|
||||
m_Service (service), m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (false)
|
||||
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 (isPublic)
|
||||
{
|
||||
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||||
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
||||
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel
|
||||
if (m_IsPublic)
|
||||
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created");
|
||||
}
|
||||
|
||||
StreamingDestination::~StreamingDestination ()
|
||||
@ -655,7 +658,7 @@ namespace stream
|
||||
{
|
||||
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;
|
||||
}
|
||||
// LoadLocalDestinations ();
|
||||
@ -717,9 +720,9 @@ namespace stream
|
||||
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;
|
||||
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 ());
|
||||
if (it != m_Destinations.end ())
|
||||
return it->second;
|
||||
auto localDestination = new StreamingDestination (m_Service, keys);
|
||||
auto localDestination = new StreamingDestination (m_Service, keys, isPublic);
|
||||
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
|
||||
return localDestination;
|
||||
}
|
||||
@ -814,9 +817,9 @@ namespace stream
|
||||
return destinations.GetSharedLocalDestination ();
|
||||
}
|
||||
|
||||
StreamingDestination * CreateNewLocalDestination ()
|
||||
StreamingDestination * CreateNewLocalDestination (bool isPublic)
|
||||
{
|
||||
return destinations.CreateNewLocalDestination ();
|
||||
return destinations.CreateNewLocalDestination (isPublic);
|
||||
}
|
||||
|
||||
void DeleteLocalDestination (StreamingDestination * destination)
|
||||
@ -824,9 +827,9 @@ namespace stream
|
||||
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)
|
||||
|
12
Streaming.h
12
Streaming.h
@ -141,9 +141,9 @@ namespace stream
|
||||
{
|
||||
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 i2p::data::PrivateKeys& keys);
|
||||
StreamingDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||
~StreamingDestination ();
|
||||
|
||||
const i2p::data::LeaseSet * GetLeaseSet ();
|
||||
@ -197,9 +197,9 @@ namespace stream
|
||||
Stream * CreateClientStream (const i2p::data::LeaseSet& remote);
|
||||
void DeleteStream (Stream * stream);
|
||||
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||
StreamingDestination * CreateNewLocalDestination ();
|
||||
StreamingDestination * CreateNewLocalDestination (bool isPublic);
|
||||
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 * LoadLocalDestination (const std::string& filename);
|
||||
|
||||
@ -225,9 +225,9 @@ namespace stream
|
||||
void StartStreaming ();
|
||||
void StopStreaming ();
|
||||
StreamingDestination * GetSharedLocalDestination ();
|
||||
StreamingDestination * CreateNewLocalDestination ();
|
||||
StreamingDestination * CreateNewLocalDestination (bool isPublic = true);
|
||||
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 * LoadLocalDestination (const std::string& filename);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user