From 4eb80a4f22c5f34ba5c3388facd9f68ce671ba74 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Thu, 14 Jan 2021 12:13:17 -0800 Subject: [PATCH] Added new command 'MeshCommand_AgentCommitDate' --- meshcore/agentcore.c | 8 +++++++- meshcore/agentcore.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 53ddabe..3319ec2 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -28,6 +28,7 @@ limitations under the License. #include "signcheck.h" #include "meshdefines.h" #include "meshinfo.h" +#include "microscript/ILibDuktape_Commit.h" #include "microscript/ILibDuktape_Polyfills.h" #include "microscript/ILibDuktape_Helpers.h" #include "microscript/ILibDuktape_SHA256.h" @@ -199,7 +200,6 @@ typedef struct MeshCommand_BinaryPacket_CoreModule }MeshCommand_BinaryPacket_CoreModule; #pragma pack(pop) - #define ScriptContainerSettingsKey "\xFF_ScriptContainerSettings" ScriptContainerSettings* ScriptEngine_GetSettings(duk_context *ctx) @@ -3407,6 +3407,12 @@ void MeshServer_OnResponse(ILibWebClient_StateObject WebStateObject, int Interru ILibWebClient_SetTimeout(WebStateObject, agent->controlChannel_idleTimeout_seconds, MeshServer_ControlChannel_IdleTimeout, agent); ILibWebClient_WebSocket_SetPingPongHandler(WebStateObject, MeshServer_ControlChannel_PingSink, MeshServer_ControlChannel_PongSink, agent); + // Send Agent Commit Date to server. This is useful in case the server needs to adjust control flow based on agent build + char commitPacket[sizeof(uint16_t) + sizeof(SOURCE_COMMIT_DATE)] = { 0 }; + ((uint16_t*)commitPacket)[0] = htons(MeshCommand_AgentCommitDate); + strcpy_s(commitPacket + sizeof(uint16_t), sizeof(SOURCE_COMMIT_DATE), SOURCE_COMMIT_DATE); + ILibWebClient_WebSocket_Send(WebStateObject, ILibWebClient_WebSocket_DataType_BINARY, (char*)commitPacket, sizeof(commitPacket), ILibAsyncSocket_MemoryOwnership_USER, ILibWebClient_WebSocket_FragmentFlag_Complete); + #ifndef MICROSTACK_NOTLS X509* peer = ILibWebClient_SslGetCert(WebStateObject); agent->serverAuthState = 0; // We are not authenticated. Bitmask: 1 = Server Auth, 2 = Agent Auth. diff --git a/meshcore/agentcore.h b/meshcore/agentcore.h index fe8fffb..77866a8 100644 --- a/meshcore/agentcore.h +++ b/meshcore/agentcore.h @@ -114,6 +114,7 @@ typedef enum MeshCommands_Binary MeshCommand_CoreModule = 10, // New core modules to be used instead of the old one, if empty, remove the core module MeshCommand_CompressedCoreModule = 20, MeshCommand_CoreModuleHash = 11, // Request/return the SHA384 hash of the core module + MeshCommand_AgentCommitDate = 30, // Commit Date that the agent was built with MeshCommand_AgentHash = 12, // Request/return the SHA384 hash of the agent executable MeshCommand_AgentUpdate = 13, // Indicate the start and end of the mesh agent binary transfer MeshCommand_AgentUpdateBlock = 14, // Part of the mesh agent sent from the server to the agent, confirmation/flowcontrol from agent to server