mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
don't create SAM session is local destination exists
This commit is contained in:
parent
c047544cdb
commit
30233bed77
21
SAM.cpp
21
SAM.cpp
|
@ -204,6 +204,12 @@ namespace stream
|
|||
std::string& id = params[SAM_PARAM_ID];
|
||||
std::string& destination = params[SAM_PARAM_DESTINATION];
|
||||
m_ID = id;
|
||||
if (m_Owner.FindSession (id))
|
||||
{
|
||||
// session exists
|
||||
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), true);
|
||||
return;
|
||||
}
|
||||
auto session = m_Owner.CreateSession (id, destination == SAM_VALUE_TRANSIENT ? "" : destination);
|
||||
if (session)
|
||||
{
|
||||
|
@ -217,7 +223,7 @@ namespace stream
|
|||
SendMessageReply (m_Buffer, l + l2 + 1, false);
|
||||
}
|
||||
else
|
||||
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), true);
|
||||
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_DEST, strlen(SAM_SESSION_CREATE_DUPLICATED_DEST), true);
|
||||
}
|
||||
|
||||
void SAMSocket::ProcessStreamConnect (char * buf, size_t len)
|
||||
|
@ -474,9 +480,6 @@ namespace stream
|
|||
|
||||
SAMSession * SAMBridge::CreateSession (const std::string& id, const std::string& destination)
|
||||
{
|
||||
if (m_Sessions.find (id) != m_Sessions.end ()) // session exists
|
||||
return nullptr;
|
||||
|
||||
StreamingDestination * localDestination = nullptr;
|
||||
if (destination != "")
|
||||
{
|
||||
|
@ -485,7 +488,7 @@ namespace stream
|
|||
i2p::data::PrivateKeys keys;
|
||||
keys.FromBuffer (buf, l);
|
||||
delete[] buf;
|
||||
localDestination = GetLocalDestination (keys);
|
||||
localDestination = CreateNewLocalDestination (keys);
|
||||
}
|
||||
else // transient
|
||||
localDestination = CreateNewLocalDestination ();
|
||||
|
@ -493,9 +496,10 @@ namespace stream
|
|||
{
|
||||
SAMSession session;
|
||||
session.localDestination = localDestination;
|
||||
session.isTransient = destination == "";
|
||||
m_Sessions[id] = session;
|
||||
return &m_Sessions[id];
|
||||
auto ret = m_Sessions.insert (std::pair<std::string, SAMSession>(id, session));
|
||||
if (!ret.second)
|
||||
LogPrint ("Session ", id, " already exists");
|
||||
return &(ret.first->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -508,7 +512,6 @@ namespace stream
|
|||
for (auto it1 : it->second.sockets)
|
||||
delete it1;
|
||||
it->second.sockets.clear ();
|
||||
if (it->second.isTransient)
|
||||
DeleteLocalDestination (it->second.localDestination);
|
||||
m_Sessions.erase (it);
|
||||
}
|
||||
|
|
2
SAM.h
2
SAM.h
|
@ -20,6 +20,7 @@ namespace stream
|
|||
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\n";
|
||||
const char SAM_SESSION_CREATE_DUPLICATED_DEST[] = "SESSION STATUS RESULT=DUPLICATED_DEST\n";
|
||||
const char SAM_STREAM_CONNECT[] = "STREAM CONNECT";
|
||||
const char SAM_STREAM_STATUS_OK[] = "STREAM STATUS RESULT=OK\n";
|
||||
const char SAM_STREAM_STATUS_INVALID_ID[] = "STREAM STATUS RESULT=INVALID_ID\n";
|
||||
|
@ -94,7 +95,6 @@ namespace stream
|
|||
{
|
||||
StreamingDestination * localDestination;
|
||||
std::list<SAMSocket *> sockets;
|
||||
bool isTransient;
|
||||
};
|
||||
|
||||
class SAMBridge
|
||||
|
|
|
@ -738,13 +738,13 @@ namespace stream
|
|||
}
|
||||
}
|
||||
|
||||
StreamingDestination * StreamingDestinations::GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||||
StreamingDestination * StreamingDestinations::CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||||
{
|
||||
auto it = m_Destinations.find (keys.GetPublic ().GetIdentHash ());
|
||||
if (it != m_Destinations.end ())
|
||||
{
|
||||
LogPrint ("Local destination ", keys.GetPublic ().GetIdentHash ().ToBase32 (), ".b32.i2p exists");
|
||||
return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
auto localDestination = new StreamingDestination (m_Service, keys, isPublic);
|
||||
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
|
||||
|
@ -825,16 +825,16 @@ namespace stream
|
|||
return destinations.CreateNewLocalDestination (isPublic);
|
||||
}
|
||||
|
||||
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||||
{
|
||||
return destinations.CreateNewLocalDestination (keys, isPublic);
|
||||
}
|
||||
|
||||
void DeleteLocalDestination (StreamingDestination * destination)
|
||||
{
|
||||
destinations.DeleteLocalDestination (destination);
|
||||
}
|
||||
|
||||
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||||
{
|
||||
return destinations.GetLocalDestination (keys, isPublic);
|
||||
}
|
||||
|
||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination)
|
||||
{
|
||||
return destinations.FindLocalDestination (destination);
|
||||
|
|
|
@ -199,8 +199,8 @@ namespace stream
|
|||
void DeleteStream (Stream * stream);
|
||||
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||
StreamingDestination * CreateNewLocalDestination (bool isPublic);
|
||||
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||
void DeleteLocalDestination (StreamingDestination * destination);
|
||||
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||||
StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
||||
|
||||
|
@ -231,8 +231,8 @@ namespace stream
|
|||
void StopStreaming ();
|
||||
StreamingDestination * GetSharedLocalDestination ();
|
||||
StreamingDestination * CreateNewLocalDestination (bool isPublic = true);
|
||||
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
|
||||
void DeleteLocalDestination (StreamingDestination * destination);
|
||||
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
|
||||
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
||||
StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
||||
// for HTTP
|
||||
|
|
Loading…
Reference in a new issue