Skip to content

Commit

Permalink
Implement hello back in IPC protocol (#7334)
Browse files Browse the repository at this point in the history
* Update VS Code config for Windows daemon debugging

* Update CL

* Implement hello back in IPC protocol

* Update CL
  • Loading branch information
nbolton committed Jan 23, 2024
1 parent fb908d6 commit 9e2fc61
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
13 changes: 1 addition & 12 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Enhancements:
- #7277 Change all errors that cause crash are FATAL
- #7282 Improve error handling for thread jobs
- #7284 Change session ID info log message to DEBUG2

Tasks:

- #7283 Update all workflows and fix broken macOS workflows
- #7313 Fix CodeQL workflow: Failed to perl 404 Not Found
- #7317 Bump sonar-scanner-cli to 5.0.1.3006
Expand All @@ -31,6 +28,7 @@ Tasks:
- #7331 Script to install deps (Windows only for now)
- #7332 Static link OpenSSL libs in CMake preset for Windows
- #7333 Update VS Code config for Windows daemon debugging
- #7334 Implement hello back in IPC protocol

# 1.14.6

Expand Down Expand Up @@ -62,9 +60,6 @@ Enhancements:
- #7193 Support for maintenance licenses in China
- #7197 Special contributor mentions on the about screen
- #7203 License registration for Business edition

CI changes:

- #7210 Update macos workflow to use macos-latest
- #7213 Update azure pipelines to use macos-latest

Expand All @@ -86,9 +81,6 @@ Enhancements:
- #7188 Synergy Basic\Pro accepts business licenses
- #7166 Replace language notifications with warnings in logs
- #7181 Fedora 36 support to CI system

CI changes:

- #7177 Create workflow for flatpak build support
- #7148 Fix unstable build for Windows core
- #7156 Change binary storage server
Expand Down Expand Up @@ -135,9 +127,6 @@ Enhancements:
- #7068 Restart when settings changed
- #7072 Run synergy as a pre-login agent
- #7074 Restart when server settings changed

CI changes:

- #1043 Upload to S3 feature on all OS
- #7098 Apple M1 runner
- #7103 Fix core builds
Expand Down
1 change: 1 addition & 0 deletions src/lib/ipc/Ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ipc/Ipc.h"

const char* kIpcMsgHello = "IHEL%1i";
const char* kIpcMsgHelloBack = "IHEL";
const char* kIpcMsgLogLine = "ILOG%s";
const char* kIpcMsgCommand = "ICMD%s%1i";
const char* kIpcMsgShutdown = "ISDN";
Expand Down
7 changes: 6 additions & 1 deletion src/lib/ipc/Ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

enum EIpcMessage {
kIpcHello,
kIpcHelloBack,
kIpcLogLine,
kIpcCommand,
kIpcShutdown,
Expand All @@ -32,13 +33,17 @@ enum EIpcMessage {
enum EIpcClientType {
kIpcClientUnknown,
kIpcClientGui,
kIpcClientNode,
kIpcClientNode
};

// handshake: node/gui -> daemon
// $1 = type, the client identifies it's self as gui or node (synergyc/s).
extern const char* kIpcMsgHello;

// handshake: daemon -> node/gui
// the daemon responds to the handshake.
extern const char* kIpcMsgHelloBack;

// log line: daemon -> gui
// $1 = aggregate log lines collected from synergys/c or the daemon itself.
extern const char* kIpcMsgLogLine;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/ipc/IpcClientProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ IpcClientProxy::send(const IpcMessage& message)
ProtocolUtil::writef(&m_stream, kIpcMsgShutdown);
break;

case kIpcHelloBack:
ProtocolUtil::writef(&m_stream, kIpcMsgHelloBack);
break;

default:
LOG((CLOG_ERR "ipc message not supported: %d", message.type()));
break;
Expand Down
9 changes: 9 additions & 0 deletions src/lib/ipc/IpcMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ IpcHelloMessage::~IpcHelloMessage()
{
}

IpcHelloBackMessage::IpcHelloBackMessage() :
IpcMessage(kIpcHelloBack)
{
}

IpcHelloBackMessage::~IpcHelloBackMessage()
{
}

IpcShutdownMessage::IpcShutdownMessage() :
IpcMessage(kIpcShutdown)
{
Expand Down
6 changes: 6 additions & 0 deletions src/lib/ipc/IpcMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class IpcHelloMessage : public IpcMessage {
EIpcClientType m_clientType;
};

class IpcHelloBackMessage : public IpcMessage {
public:
IpcHelloBackMessage();
virtual ~IpcHelloBackMessage();
};

class IpcShutdownMessage : public IpcMessage {
public:
IpcShutdownMessage();
Expand Down
16 changes: 16 additions & 0 deletions src/lib/synergy/DaemonApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "synergy/DaemonApp.h"

#include "ipc/Ipc.h"
#include "synergy/App.h"
#include "synergy/ArgParser.h"
#include "synergy/ServerArgs.h"
Expand All @@ -37,6 +38,7 @@
#include "base/EventQueue.h"
#include "base/log_outputters.h"
#include "base/Log.h"
#include "synergy/protocol_types.h"

#if SYSAPI_WIN32

Expand Down Expand Up @@ -145,6 +147,7 @@ DaemonApp::run(int argc, char** argv)
try
{
#if SYSAPI_WIN32
// TODO: maybe we should only add this if not using /f?
// sends debug messages to visual studio console window.
log.insert(new MSWindowsDebugOutputter());
#endif
Expand All @@ -164,11 +167,13 @@ DaemonApp::run(int argc, char** argv)
}
#if SYSAPI_WIN32
else if (arg == "/install") {
LOG((CLOG_PRINT "installing windows daemon"));
uninstall = true;
arch.installDaemon();
return kExitSuccess;
}
else if (arg == "/uninstall") {
LOG((CLOG_PRINT "uninstalling windows daemon"));
arch.uninstallDaemon();
return kExitSuccess;
}
Expand All @@ -182,14 +187,18 @@ DaemonApp::run(int argc, char** argv)
}

if (foreground) {
LOG((CLOG_PRINT "starting daemon in foreground"));

// run process in foreground instead of daemonizing.
// useful for debugging.
mainLoop(false, foreground);
}
else {
#if SYSAPI_WIN32
LOG((CLOG_PRINT "daemonizing windows service"));
arch.daemonize("Synergy", winMainLoopStatic);
#elif SYSAPI_UNIX
LOG((CLOG_PRINT "daemonizing unix service"));
arch.daemonize("Synergy", unixMainLoopStatic);
#endif
}
Expand Down Expand Up @@ -399,6 +408,13 @@ DaemonApp::handleIpcMessage(const Event& e, void*)

LOG((CLOG_DEBUG "ipc hello, type=%s", type.c_str()));

// TODO: implement hello back handling in s1 gui and node (server/client).
if (hm->clientType() == kIpcClientGui) {
LOG((CLOG_DEBUG "sending ipc hello back"));
IpcHelloBackMessage hbm;
m_ipcServer->send(hbm, hm->clientType());
}

#if SYSAPI_WIN32
String watchdogStatus = m_watchdog->isProcessActive() ? "active" : "idle";
LOG((CLOG_INFO "service status: %s", watchdogStatus.c_str()));
Expand Down

0 comments on commit 9e2fc61

Please sign in to comment.