implement PING command
Some checks failed
Build Debian packages / bookworm (push) Has been cancelled
Build Debian packages / bullseye (push) Has been cancelled
Build Debian packages / trixie (push) Has been cancelled
Build on FreeBSD / with UPnP (push) Has been cancelled
Build on OSX / With USE_UPNP=no (push) Has been cancelled
Build on OSX / With USE_UPNP=yes (push) Has been cancelled
Build on Windows / clang-x86_64 (push) Has been cancelled
Build on Windows / i686 (push) Has been cancelled
Build on Windows / ucrt-x86_64 (push) Has been cancelled
Build on Windows / x86_64 (push) Has been cancelled
Build on Windows / CMake clang-x86_64 (push) Has been cancelled
Build on Windows / CMake i686 (push) Has been cancelled
Build on Windows / CMake ucrt-x86_64 (push) Has been cancelled
Build on Windows / CMake x86_64 (push) Has been cancelled
Build on Windows / XP (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=no (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=yes (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Has been cancelled
Build containers / Building container for linux/amd64 (push) Has been cancelled
Build containers / Building container for linux/arm64 (push) Has been cancelled
Build containers / Building container for linux/arm/v7 (push) Has been cancelled
Build containers / Building container for linux/386 (push) Has been cancelled
Build containers / Pushing merged manifest (push) Has been cancelled

This commit is contained in:
orignal 2025-08-31 17:50:02 -04:00
parent 1d7c7ac148
commit 3522a3180b
2 changed files with 19 additions and 1 deletions

View file

@ -248,6 +248,14 @@ namespace client
char * separator = strchr (m_Buffer, ' '); char * separator = strchr (m_Buffer, ' ');
if (separator) if (separator)
{ {
// one word command
if (std::string_view (m_Buffer, separator - m_Buffer) == SAM_PING)
{
ProcessPing ({ separator + 1, (size_t)(eol - separator - 1) });
return;
}
// two words command
size_t l = 0; size_t l = 0;
separator = strchr (separator + 1, ' '); separator = strchr (separator + 1, ' ');
if (separator) if (separator)
@ -955,6 +963,12 @@ namespace client
SendSessionI2PError ("Wrong session type"); SendSessionI2PError ("Wrong session type");
} }
void SAMSocket::ProcessPing (std::string_view text)
{
LogPrint (eLogDebug, "SAM: Ping ", text);
SendReplyWithMessage (SAM_PONG, std::string (text));
}
void SAMSocket::SendReplyWithMessage (const char * reply, const std::string & msg) void SAMSocket::SendReplyWithMessage (const char * reply, const std::string & msg)
{ {
#ifdef _MSC_VER #ifdef _MSC_VER

View file

@ -91,6 +91,9 @@ namespace client
constexpr std::string_view SAM_VALUE_RAW { "RAW" }; constexpr std::string_view SAM_VALUE_RAW { "RAW" };
constexpr std::string_view SAM_VALUE_MASTER { "MASTER" }; constexpr std::string_view SAM_VALUE_MASTER { "MASTER" };
constexpr std::string_view SAM_PING { "PING" };
const char SAM_PONG[] = "PONG %s\n";
constexpr int MAKE_SAM_VERSION_NUMBER (int major, int minor) { return major*10 + minor; } constexpr int MAKE_SAM_VERSION_NUMBER (int major, int minor) { return major*10 + minor; }
constexpr int MIN_SAM_VERSION = MAKE_SAM_VERSION_NUMBER (3, 0); constexpr int MIN_SAM_VERSION = MAKE_SAM_VERSION_NUMBER (3, 0);
constexpr int MAX_SAM_VERSION = MAKE_SAM_VERSION_NUMBER (3, 3); constexpr int MAX_SAM_VERSION = MAKE_SAM_VERSION_NUMBER (3, 3);
@ -153,6 +156,7 @@ namespace client
void ProcessNamingLookup (std::string_view buf); void ProcessNamingLookup (std::string_view buf);
void ProcessSessionAdd (std::string_view buf); void ProcessSessionAdd (std::string_view buf);
void ProcessSessionRemove (std::string_view buf); void ProcessSessionRemove (std::string_view buf);
void ProcessPing (std::string_view text);
void SendReplyWithMessage (const char * reply, const std::string & msg); void SendReplyWithMessage (const char * reply, const std::string & msg);
void SendSessionI2PError(const std::string & msg); void SendSessionI2PError(const std::string & msg);
void SendStreamI2PError(const std::string & msg); void SendStreamI2PError(const std::string & msg);