Show connections in About

This commit is contained in:
Michael Theall 2024-01-10 16:41:18 -06:00
parent 4a8925fef3
commit 889283aa91
3 changed files with 67 additions and 2 deletions

View File

@ -3,7 +3,7 @@
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// Copyright (C) 2023 Michael Theall
// Copyright (C) 2024 Michael Theall
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -47,6 +47,9 @@ public:
/// \brief Draw session status
void draw ();
/// \brief Draw session connections
void drawConnections ();
/// \brief Create session
/// \param config_ FTP config
/// \param commandSocket_ Command socket

View File

@ -736,6 +736,14 @@ void FtpServer::showAbout ()
ImGui::CloseCurrentPopup ();
}
ImGui::Separator ();
if (ImGui::TreeNode ("Connections"))
{
for (auto const &session : m_sessions)
session->drawConnections ();
ImGui::TreePop ();
}
ImGui::Separator ();
if (ImGui::TreeNode (g_dearImGuiVersion))
{

View File

@ -3,7 +3,7 @@
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// Copyright (C) 2023 Michael Theall
// Copyright (C) 2024 Michael Theall
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -398,6 +398,60 @@ void FtpSession::draw ()
#endif
}
void FtpSession::drawConnections ()
{
#ifndef CLASSIC
#ifdef NO_IPV6
char peerName[INET_ADDRSTRLEN];
char sockName[INET_ADDRSTRLEN];
#else
char peerName[INET6_ADDRSTRLEN];
char sockName[INET6_ADDRSTRLEN];
#endif
static char const *const stateStrings[] = {
"Command",
"Data Connect",
"Data Transfer",
};
ImGui::TextWrapped ("State: %s", stateStrings[static_cast<int> (m_state)]);
if (m_commandSocket)
{
m_commandSocket->peerName ().name (peerName, sizeof (peerName));
m_commandSocket->sockName ().name (sockName, sizeof (sockName));
if (m_commandSocket == m_dataSocket)
ImGui::TextWrapped ("Command/Data %s -> %s", peerName, sockName);
else
ImGui::TextWrapped ("Command %s -> %s", peerName, sockName);
}
if (m_pasvSocket)
{
m_pasvSocket->sockName ().name (sockName, sizeof (sockName));
ImGui::TextWrapped ("PASV %s", sockName);
}
if (m_dataSocket && m_dataSocket != m_commandSocket)
{
m_dataSocket->peerName ().name (peerName, sizeof (peerName));
m_dataSocket->sockName ().name (sockName, sizeof (sockName));
ImGui::TextWrapped ("Data %s -> %s", peerName, sockName);
}
for (auto const &sock : m_pendingCloseSocket)
{
if (!sock)
continue;
sock->peerName ().name (peerName, sizeof (peerName));
sock->sockName ().name (sockName, sizeof (sockName));
ImGui::TextWrapped ("Closing %s -> %s", peerName, sockName);
}
#endif
}
UniqueFtpSession FtpSession::create (FtpConfig &config_, UniqueSocket commandSocket_)
{
return UniqueFtpSession (new FtpSession (config_, std::move (commandSocket_)));