Browse Source

show SAM sessions through web interface

pull/163/head
orignal 10 years ago
parent
commit
05e49bbeab
  1. 1
      ClientContext.h
  2. 62
      HTTPServer.cpp
  3. 2
      HTTPServer.h
  4. 2
      SAM.cpp
  5. 10
      SAM.h

1
ClientContext.h

@ -47,6 +47,7 @@ namespace client @@ -47,6 +47,7 @@ namespace client
ClientDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
AddressBook& GetAddressBook () { return m_AddressBook; };
const SAMBridge * GetSAMBridge () const { return m_SamBridge; };
private:

62
HTTPServer.cpp

@ -469,6 +469,9 @@ namespace util @@ -469,6 +469,9 @@ namespace util
const char HTTP_COMMAND_LOCAL_DESTINATIONS[] = "local_destinations";
const char HTTP_COMMAND_LOCAL_DESTINATION[] = "local_destination";
const char HTTP_PARAM_BASE32_ADDRESS[] = "b32";
const char HTTP_COMMAND_SAM_SESSIONS[] = "sam_sessions";
const char HTTP_COMMAND_SAM_SESSION[] = "sam_session";
const char HTTP_PARAM_SAM_SESSION_ID[] = "id";
namespace misc_strings
{
@ -673,7 +676,10 @@ namespace util @@ -673,7 +676,10 @@ namespace util
s << "<br><b><a href=/?" << HTTP_COMMAND_LOCAL_DESTINATIONS << ">Local destinations</a></b>";
s << "<br><b><a href=/?" << HTTP_COMMAND_TUNNELS << ">Tunnels</a></b>";
s << "<br><b><a href=/?" << HTTP_COMMAND_TRANSIT_TUNNELS << ">Transit tunnels</a></b>";
s << "<br><b><a href=/?" << HTTP_COMMAND_TRANSPORTS << ">Transports</a></b><br>";
s << "<br><b><a href=/?" << HTTP_COMMAND_TRANSPORTS << ">Transports</a></b>";
if (i2p::client::context.GetSAMBridge ())
s << "<br><b><a href=/?" << HTTP_COMMAND_SAM_SESSIONS << ">SAM sessions</a></b>";
s << "<br>";
if (i2p::context.AcceptsTunnels ())
s << "<br><b><a href=/?" << HTTP_COMMAND_STOP_ACCEPTING_TUNNELS << ">Stop accepting tunnels</a></b><br>";
@ -706,6 +712,15 @@ namespace util @@ -706,6 +712,15 @@ namespace util
auto b32 = params[HTTP_PARAM_BASE32_ADDRESS];
ShowLocalDestination (b32, s);
}
else if (cmd == HTTP_COMMAND_SAM_SESSIONS)
ShowSAMSessions (s);
else if (cmd == HTTP_COMMAND_SAM_SESSION)
{
std::map<std::string, std::string> params;
ExtractParams (command.substr (paramsPos), params);
auto id = params[HTTP_PARAM_SAM_SESSION_ID];
ShowSAMSession (id, s);
}
}
void HTTPConnection::ShowTransports (std::stringstream& s)
@ -851,6 +866,51 @@ namespace util @@ -851,6 +866,51 @@ namespace util
}
}
void HTTPConnection::ShowSAMSessions (std::stringstream& s)
{
auto sam = i2p::client::context.GetSAMBridge ();
if (sam)
{
for (auto& it: sam->GetSessions ())
{
s << "<a href=/?" << HTTP_COMMAND_SAM_SESSION;
s << "&" << HTTP_PARAM_SAM_SESSION_ID << "=" << it.first << ">";
s << it.first << "</a><br>" << std::endl;
}
}
}
void HTTPConnection::ShowSAMSession (const std::string& id, std::stringstream& s)
{
auto sam = i2p::client::context.GetSAMBridge ();
if (sam)
{
auto session = sam->FindSession (id);
if (session)
{
for (auto it: session->sockets)
{
switch (it->GetSocketType ())
{
case i2p::client::eSAMSocketTypeSession:
s << "session";
break;
case i2p::client::eSAMSocketTypeStream:
s << "stream";
break;
case i2p::client::eSAMSocketTypeAcceptor:
s << "acceptor";
break;
default:
s << "unknown";
}
s << " [" << it->GetSocket ().remote_endpoint() << "]";
s << "<br>" << std::endl;
}
}
}
}
void HTTPConnection::StartAcceptingTunnels (std::stringstream& s)
{
i2p::context.SetAcceptsTunnels (true);

2
HTTPServer.h

@ -69,6 +69,8 @@ namespace util @@ -69,6 +69,8 @@ namespace util
void ShowTransitTunnels (std::stringstream& s);
void ShowLocalDestinations (std::stringstream& s);
void ShowLocalDestination (const std::string& b32, std::stringstream& s);
void ShowSAMSessions (std::stringstream& s);
void ShowSAMSession (const std::string& id, std::stringstream& s);
void StartAcceptingTunnels (std::stringstream& s);
void StopAcceptingTunnels (std::stringstream& s);
void FillContent (std::stringstream& s);

2
SAM.cpp

@ -738,7 +738,7 @@ namespace client @@ -738,7 +738,7 @@ namespace client
}
}
SAMSession * SAMBridge::FindSession (const std::string& id)
SAMSession * SAMBridge::FindSession (const std::string& id) const
{
std::unique_lock<std::mutex> l(m_SessionsMutex);
auto it = m_Sessions.find (id);

10
SAM.h

@ -79,6 +79,7 @@ namespace client @@ -79,6 +79,7 @@ namespace client
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
void ReceiveHandshake ();
void SetSocketType (SAMSocketType socketType) { m_SocketType = socketType; };
SAMSocketType GetSocketType () const { return m_SocketType; };
private:
@ -150,7 +151,7 @@ namespace client @@ -150,7 +151,7 @@ namespace client
SAMSession * CreateSession (const std::string& id, const std::string& destination, // empty string means transient
const std::map<std::string, std::string> * params);
void CloseSession (const std::string& id);
SAMSession * FindSession (const std::string& id);
SAMSession * FindSession (const std::string& id) const;
private:
@ -170,9 +171,14 @@ namespace client @@ -170,9 +171,14 @@ namespace client
boost::asio::ip::tcp::acceptor m_Acceptor;
boost::asio::ip::udp::endpoint m_DatagramEndpoint, m_SenderEndpoint;
boost::asio::ip::udp::socket m_DatagramSocket;
std::mutex m_SessionsMutex;
mutable std::mutex m_SessionsMutex;
std::map<std::string, SAMSession *> m_Sessions;
uint8_t m_DatagramReceiveBuffer[i2p::datagram::MAX_DATAGRAM_SIZE+1];
public:
// for HTTP
const decltype(m_Sessions)& GetSessions () const { return m_Sessions; };
};
}
}

Loading…
Cancel
Save