mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
create SAM session
This commit is contained in:
parent
2914bb67f1
commit
393d4bc231
4 changed files with 119 additions and 1 deletions
49
SAM.cpp
49
SAM.cpp
|
@ -1,5 +1,6 @@
|
|||
#include <string.h>
|
||||
#include <boost/bind.hpp>
|
||||
#include "base64.h"
|
||||
#include "Log.h"
|
||||
#include "SAM.h"
|
||||
|
||||
|
@ -14,7 +15,11 @@ namespace stream
|
|||
|
||||
SAMSocket::~SAMSocket ()
|
||||
{
|
||||
delete m_Stream;
|
||||
if (m_Stream)
|
||||
{
|
||||
m_Stream->Close ();
|
||||
delete m_Stream;
|
||||
}
|
||||
}
|
||||
|
||||
void SAMSocket::Terminate ()
|
||||
|
@ -201,5 +206,47 @@ namespace stream
|
|||
if (ecode != boost::asio::error::operation_aborted)
|
||||
Accept ();
|
||||
}
|
||||
|
||||
bool SAMBridge::CreateSession (const std::string& id, const char * destination, size_t len)
|
||||
{
|
||||
if (m_Sessions.find (id) != m_Sessions.end ()) // session exists
|
||||
return false;
|
||||
|
||||
StreamingDestination * localDestination = nullptr;
|
||||
if (destination)
|
||||
{
|
||||
uint8_t * buf = new uint8_t[len];
|
||||
size_t l = i2p::data::Base64ToByteStream (destination, len, buf, len);
|
||||
i2p::data::PrivateKeys keys;
|
||||
keys.FromBuffer (buf, l);
|
||||
delete[] buf;
|
||||
localDestination = GetLocalDestination (keys);
|
||||
}
|
||||
else // transient
|
||||
localDestination = CreateNewLocalDestination ();
|
||||
if (localDestination)
|
||||
{
|
||||
SAMSession session;
|
||||
session.localDestination = localDestination;
|
||||
session.isTransient = !destination;
|
||||
m_Sessions[id] = session;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SAMBridge::CloseSession (const std::string& id)
|
||||
{
|
||||
auto it = m_Sessions.find (id);
|
||||
if (it != m_Sessions.end ())
|
||||
{
|
||||
for (auto it1 : it->second.sockets)
|
||||
delete it1;
|
||||
it->second.sockets.clear ();
|
||||
if (it->second.isTransient)
|
||||
DeleteLocalDestination (it->second.localDestination);
|
||||
m_Sessions.erase (it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue