Browse Source

don't create SAM session is local destination exists

pull/102/head
orignal 10 years ago
parent
commit
30233bed77
  1. 23
      SAM.cpp
  2. 2
      SAM.h
  3. 12
      Streaming.cpp
  4. 4
      Streaming.h

23
SAM.cpp

@ -204,6 +204,12 @@ namespace stream @@ -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 @@ -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 @@ -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 @@ -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 @@ -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,8 +512,7 @@ namespace stream @@ -508,8 +512,7 @@ namespace stream
for (auto it1 : it->second.sockets)
delete it1;
it->second.sockets.clear ();
if (it->second.isTransient)
DeleteLocalDestination (it->second.localDestination);
DeleteLocalDestination (it->second.localDestination);
m_Sessions.erase (it);
}
}

2
SAM.h

@ -20,6 +20,7 @@ namespace stream @@ -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 @@ -94,7 +95,6 @@ namespace stream
{
StreamingDestination * localDestination;
std::list<SAMSocket *> sockets;
bool isTransient;
};
class SAMBridge

12
Streaming.cpp

@ -738,13 +738,13 @@ namespace stream @@ -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,14 +825,14 @@ namespace stream @@ -825,14 +825,14 @@ namespace stream
return destinations.CreateNewLocalDestination (isPublic);
}
void DeleteLocalDestination (StreamingDestination * destination)
StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
{
destinations.DeleteLocalDestination (destination);
return destinations.CreateNewLocalDestination (keys, isPublic);
}
StreamingDestination * GetLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
void DeleteLocalDestination (StreamingDestination * destination)
{
return destinations.GetLocalDestination (keys, isPublic);
destinations.DeleteLocalDestination (destination);
}
StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination)

4
Streaming.h

@ -199,8 +199,8 @@ namespace stream @@ -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 @@ -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…
Cancel
Save