fix message

This commit is contained in:
anlicheng 2025-09-18 11:14:16 +08:00
parent cec0a25e7c
commit 900314a6b6
5 changed files with 13 additions and 146 deletions

View File

@ -1,133 +0,0 @@
%% -*- coding: utf-8 -*-
%% Automatically generated, do not edit
%% Generated by gpb_compile version 4.21.1
-ifndef(message_pb).
-define(message_pb, true).
-define(message_pb_gpb_version, "4.21.1").
-ifndef('AUTH_REQUEST_PB_H').
-define('AUTH_REQUEST_PB_H', true).
-record(auth_request,
{uuid = <<>> :: unicode:chardata() | undefined, % = 1, optional
username = <<>> :: unicode:chardata() | undefined, % = 2, optional
salt = <<>> :: unicode:chardata() | undefined, % = 4, optional
token = <<>> :: unicode:chardata() | undefined, % = 5, optional
timestamp = 0 :: non_neg_integer() | undefined % = 6, optional, 32 bits
}).
-endif.
-ifndef('AUTH_REPLY_PB_H').
-define('AUTH_REPLY_PB_H', true).
-record(auth_reply,
{code = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
message = <<>> :: unicode:chardata() | undefined % = 2, optional
}).
-endif.
-ifndef('PUB_PB_H').
-define('PUB_PB_H', true).
-record(pub,
{topic = <<>> :: unicode:chardata() | undefined, % = 1, optional
content = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('COMMAND_PB_H').
-define('COMMAND_PB_H', true).
-record(command,
{command_type = <<>> :: unicode:chardata() | undefined, % = 1, optional
command = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('RPC_DEPLOY_PB_H').
-define('RPC_DEPLOY_PB_H', true).
-record(rpc_deploy,
{packet_id = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
task_id = 0 :: non_neg_integer() | undefined, % = 2, optional, 32 bits
config = <<>> :: unicode:chardata() | undefined % = 3, optional
}).
-endif.
-ifndef('RPC_START_CONTAINER_PB_H').
-define('RPC_START_CONTAINER_PB_H', true).
-record(rpc_start_container,
{packet_id = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
container_name = <<>> :: unicode:chardata() | undefined % = 2, optional
}).
-endif.
-ifndef('RPC_STOP_CONTAINER_PB_H').
-define('RPC_STOP_CONTAINER_PB_H', true).
-record(rpc_stop_container,
{packet_id = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
container_name = <<>> :: unicode:chardata() | undefined % = 2, optional
}).
-endif.
-ifndef('RPC_CONFIG_CONTAINER_PB_H').
-define('RPC_CONFIG_CONTAINER_PB_H', true).
-record(rpc_config_container,
{packet_id = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
container_name = <<>> :: unicode:chardata() | undefined, % = 2, optional
config = <<>> :: iodata() | undefined % = 3, optional
}).
-endif.
-ifndef('FETCH_TASK_LOG_PB_H').
-define('FETCH_TASK_LOG_PB_H', true).
-record(fetch_task_log,
{task_id = 0 :: non_neg_integer() | undefined % = 1, optional, 32 bits
}).
-endif.
-ifndef('CONTAINER_CONFIG_PB_H').
-define('CONTAINER_CONFIG_PB_H', true).
-record(container_config,
{container_name = <<>> :: unicode:chardata() | undefined, % = 1, optional
config = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('DATA_PB_H').
-define('DATA_PB_H', true).
-record(data,
{service_id = <<>> :: unicode:chardata() | undefined, % = 1, optional
device_uuid = <<>> :: unicode:chardata() | undefined, % = 2, optional
route_key = <<>> :: unicode:chardata() | undefined, % = 3, optional
metric = <<>> :: iodata() | undefined % = 4, optional
}).
-endif.
-ifndef('EVENT_PB_H').
-define('EVENT_PB_H', true).
-record(event,
{service_id = <<>> :: unicode:chardata() | undefined, % = 1, optional
event_type = 0 :: non_neg_integer() | undefined, % = 2, optional, 32 bits
params = <<>> :: unicode:chardata() | undefined % = 3, optional
}).
-endif.
-ifndef('PING_PB_H').
-define('PING_PB_H', true).
-record(ping,
{adcode = <<>> :: unicode:chardata() | undefined, % = 1, optional
boot_time = 0 :: non_neg_integer() | undefined, % = 2, optional, 32 bits
province = <<>> :: unicode:chardata() | undefined, % = 3, optional
city = <<>> :: unicode:chardata() | undefined, % = 4, optional
efka_version = <<>> :: unicode:chardata() | undefined, % = 5, optional
kernel_arch = <<>> :: unicode:chardata() | undefined, % = 6, optional
ips = [] :: [unicode:chardata()] | undefined, % = 7, repeated
cpu_core = 0 :: non_neg_integer() | undefined, % = 8, optional, 32 bits
cpu_load = 0 :: non_neg_integer() | undefined, % = 9, optional, 32 bits
cpu_temperature = 0.0 :: float() | integer() | infinity | '-infinity' | nan | undefined, % = 10, optional
disk = [] :: [integer()] | undefined, % = 11, repeated, 32 bits
memory = [] :: [integer()] | undefined, % = 12, repeated, 32 bits
interfaces = <<>> :: unicode:chardata() | undefined % = 13, optional
}).
-endif.
-endif.

View File

@ -8,7 +8,7 @@
%%%-------------------------------------------------------------------
-module(efka_remote_agent).
-author("anlicheng").
-include("efka.hrl").
-include("message.hrl").
-include("efka_tables.hrl").
-behaviour(gen_statem).
@ -83,7 +83,7 @@ callback_mode() ->
%% , mnesia
handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, ?STATE_ACTIVATED, State = #state{transport_pid = TransportPid}) ->
Packet = efka_codec:encode(?MESSAGE_DATA, #data{
Packet = message_codec:encode(?MESSAGE_DATA, #data{
service_id = ServiceId,
device_uuid = DeviceUUID,
route_key = RouteKey,
@ -93,7 +93,7 @@ handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, ?STAT
{keep_state, State};
handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, _, State) ->
Packet = efka_codec:encode(?MESSAGE_DATA, #data{
Packet = message_codec:encode(?MESSAGE_DATA, #data{
service_id = ServiceId,
device_uuid = DeviceUUID,
route_key = RouteKey,
@ -104,7 +104,7 @@ handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, _, St
%%
handle_event(cast, {event, ServiceId, EventType, Params}, ?STATE_ACTIVATED, State = #state{transport_pid = TransportPid}) ->
EventPacket = efka_codec:encode(?MESSAGE_EVENT, #event{
EventPacket = message_codec:encode(?MESSAGE_EVENT, #event{
service_id = ServiceId,
event_type = EventType,
params = Params
@ -112,7 +112,7 @@ handle_event(cast, {event, ServiceId, EventType, Params}, ?STATE_ACTIVATED, Stat
efka_transport:send(TransportPid, EventPacket),
{keep_state, State};
handle_event(cast, {event, ServiceId, EventType, Params}, ?STATE_ACTIVATED, State) ->
EventPacket = efka_codec:encode(?MESSAGE_EVENT, #event{
EventPacket = message_codec:encode(?MESSAGE_EVENT, #event{
service_id = ServiceId,
event_type = EventType,
params = Params
@ -332,7 +332,7 @@ auth_request() ->
Salt = proplists:get_value(salt, AuthInfo),
Token = proplists:get_value(token, AuthInfo),
efka_codec:encode(?MESSAGE_AUTH_REQUEST, #auth_request{
message_codec:encode(?MESSAGE_AUTH_REQUEST, #auth_request{
uuid = unicode:characters_to_binary(UUID),
username = unicode:characters_to_binary(Username),
salt = unicode:characters_to_binary(Salt),

View File

@ -8,7 +8,7 @@
%%%-------------------------------------------------------------------
-module(efka_transport).
-author("anlicheng").
-include("efka.hrl").
-include("message.hrl").
-behaviour(gen_server).
@ -118,7 +118,7 @@ handle_cast({auth_request, AuthRequestBin}, State = #state{parent_pid = ParentPi
%% auth返回的结果
receive
{ssl, Socket, <<?PACKET_RESPONSE, PacketId:32, ReplyBin/binary>>} ->
{ok, #auth_reply{} = Reply} = efka_codec:decode(ReplyBin),
{ok, #auth_reply{} = Reply} = message_codec:decode(ReplyBin),
ParentPid ! {auth_reply, {ok, Reply}},
{noreply, State};
{ssl, Socket, Info} ->
@ -147,17 +147,17 @@ handle_cast({rpc_reply, PacketId, Response}, State = #state{socket = Socket}) ->
{stop, Reason :: term(), NewState :: #state{}}).
%% packetId的是要求返回的0
handle_info({ssl, Socket, <<?PACKET_COMMAND, CommandBin/binary>>}, State = #state{socket = Socket, parent_pid = ParentPid}) ->
{ok, #command{} = Command} = efka_codec:decode(CommandBin),
{ok, #command{} = Command} = message_codec:decode(CommandBin),
ParentPid ! {server_command, Command},
{noreply, State};
handle_info({ssl, Socket, <<?PACKET_PUB, PubBin/binary>>}, State = #state{socket = Socket, parent_pid = ParentPid}) ->
{ok, #pub{} = Pub} = efka_codec:decode(PubBin),
{ok, #pub{} = Pub} = message_codec:decode(PubBin),
ParentPid ! {server_pub, Pub},
{noreply, State};
handle_info({ssl, Socket, <<?PACKET_RPC, PacketId:32, RPCRequestBin/binary>>}, State = #state{socket = Socket, parent_pid = ParentPid}) ->
{ok, RPCRequest} = efka_codec:decode(RPCRequestBin),
{ok, RPCRequest} = message_codec:decode(RPCRequestBin),
ParentPid ! {server_rpc, PacketId, RPCRequest},
{noreply, State};

View File

@ -6,9 +6,9 @@
%%% @end
%%% Created : 17. 9 2025 16:05
%%%-------------------------------------------------------------------
-module(efka_codec).
-module(message_codec).
-author("anlicheng").
-include("efka.hrl").
-include("message.hrl").
-define(I32, 1).
-define(Bytes, 2).