diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 51d1ef4..9ef2ccf 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -2501,7 +2501,8 @@ void MeshServer_ServerAuthenticated(ILibWebClient_StateObject WebStateObject, Me } } -void MeshServer_SendAgentInfo(MeshAgentHostContainer* agent, ILibWebClient_StateObject WebStateObject) { +void MeshServer_SendAgentInfo(MeshAgentHostContainer* agent, ILibWebClient_StateObject WebStateObject) +{ int hostnamelen = (int)strnlen_s(agent->hostname, sizeof(agent->hostname)); // Send to the server information about this agent @@ -2514,8 +2515,16 @@ void MeshServer_SendAgentInfo(MeshAgentHostContainer* agent, ILibWebClient_State info->platformType = htonl(((agent->batteryState != MeshAgentHost_BatteryInfo_NONE) && (agent->batteryState != MeshAgentHost_BatteryInfo_UNKNOWN)) ? MeshCommand_AuthInfo_PlatformType_LAPTOP : MeshCommand_AuthInfo_PlatformType_DESKTOP); memcpy_s(info->MeshID, sizeof(info->MeshID), agent->meshId, sizeof(agent->meshId)); info->capabilities = htonl(agent->capabilities); - info->hostnameLen = htons(hostnamelen); - memcpy_s(info->hostname, sizeof(ILibScratchPad2) - sizeof(MeshCommand_BinaryPacket_AuthInfo), agent->hostname, hostnamelen); + + if ((info->hostnameLen = htons(ILibSimpleDataStore_Get(agent->masterDb, "agentName", info->hostname, sizeof(ILibScratchPad2) - sizeof(info)))) == 0) + { + info->hostnameLen = htons(hostnamelen); + memcpy_s(info->hostname, sizeof(ILibScratchPad2) - sizeof(MeshCommand_BinaryPacket_AuthInfo), agent->hostname, hostnamelen); + } + else + { + hostnamelen = ntohs(info->hostnameLen) - 1; + } // Send mesh agent information to the server ILibWebClient_WebSocket_Send(WebStateObject, ILibWebClient_WebSocket_DataType_BINARY, (char*)info, sizeof(MeshCommand_BinaryPacket_AuthInfo) + hostnamelen, ILibAsyncSocket_MemoryOwnership_USER, ILibWebClient_WebSocket_FragmentFlag_Complete); diff --git a/meshcore/agentcore.h b/meshcore/agentcore.h index b193d62..e8e90b3 100644 --- a/meshcore/agentcore.h +++ b/meshcore/agentcore.h @@ -233,6 +233,7 @@ char* MeshAgent_MakeAbsolutePath(char *basePath, char *localPath); * * AgentCapabilities: Integer Mask, specifying supported Agent Capabilities +agentName If set, this will be sent to the server instead of the hostname controlChannelDebug: If set, will log/display controlChannel messages (Except for JSON messages) controlChannelIdleTimeout: Integer value specifying the idle timeout in seconds, to send Ping/Pong to server, to keep connection alive coreDumpEnabled: If set, a dump file will be written when the agent crashes