fix
This commit is contained in:
parent
a6ebd84272
commit
9c81a7c2be
@ -104,7 +104,7 @@ handle_event(internal, do_init, initializing, State=#state{conn = Conn, max_pack
|
||||
max_packet_size = MaxPacketSize,
|
||||
heartbeat_sec = HeartbeatSec
|
||||
}),
|
||||
{ok, _} = quicer:send(Stream, <<?PACKET_WELCOME, WelcomePkt/binary>>),
|
||||
quic_send(Stream, <<?PACKET_WELCOME, WelcomePkt/binary>>),
|
||||
logger:debug("[sdlan_quic_channel] get stream: ~p, send welcome", [Stream]),
|
||||
|
||||
{next_state, initialized, State#state{stream = Stream}};
|
||||
@ -151,23 +151,23 @@ handle_event(info, {frame, <<?PACKET_REGISTER_SUPER, Body/binary>>}, initialized
|
||||
}),
|
||||
|
||||
%% 发送确认信息
|
||||
{ok, _} = quicer:send(Stream, <<?PACKET_REGISTER_SUPER_ACK, RegisterSuperAck/binary>>),
|
||||
quic_send(Stream, <<?PACKET_REGISTER_SUPER_ACK, RegisterSuperAck/binary>>),
|
||||
%% 设置节点的在线状态
|
||||
Result = sdlan_api:node_online(ClientId, NetworkId, sdlan_ipaddr:int_to_ipv4(Ip)),
|
||||
logger:debug("[sdlan_register_worker] client_id: ~p, set none online result is: ~p", [ClientId, Result]),
|
||||
{next_state, registered, State#state{network_id = NetworkId, network_pid = NetworkPid, client_id = ClientId, mac = Mac, ip = Ip}};
|
||||
undefined ->
|
||||
logger:warning("[sdlan_register_worker] client_id: ~p, register get error: network not found", [ClientId]),
|
||||
{ok, _} = quicer:send(Stream, register_nak_reply(PktId, ?NAK_INTERNAL_FAULT, <<"Internal Error">>)),
|
||||
quic_send(Stream, register_nak_reply(PktId, ?NAK_INTERNAL_FAULT, <<"Internal Error">>)),
|
||||
{stop, normal, State}
|
||||
end;
|
||||
{ok, #{<<"error">> := #{<<"code">> := Code, <<"message">> := Message}}} ->
|
||||
logger:warning("[sdlan_register_worker] network_id: ~p, client_id: ~p, register get error: ~ts, error_code: ~p", [NetworkId, ClientId, Message, Code]),
|
||||
{ok, _} = quicer:send(Stream, register_nak_reply(PktId, Code, Message)),
|
||||
quic_send(Stream, register_nak_reply(PktId, Code, Message)),
|
||||
{stop, normal, State};
|
||||
{error, Reason} ->
|
||||
logger:warning("[sdlan_register_worker] network_id: ~p, client_id: ~p, register get error: ~p", [NetworkId, ClientId, Reason]),
|
||||
{ok, _} = quicer:send(Stream, register_nak_reply(PktId, ?NAK_NETWORK_FAULT, <<"Network Error">>)),
|
||||
quic_send(Stream, register_nak_reply(PktId, ?NAK_NETWORK_FAULT, <<"Network Error">>)),
|
||||
{stop, normal, State}
|
||||
end;
|
||||
|
||||
@ -181,7 +181,7 @@ handle_event(info, {frame, <<?PACKET_QUERY_INFO, Body/binary>>}, registered, #st
|
||||
EmptyResponse = sdlan_pb:encode_msg(#sdl_empty{
|
||||
pkt_id = PktId
|
||||
}),
|
||||
{ok, _} = quicer:send(Stream, <<?PACKET_PEER_INFO, EmptyResponse/binary>>),
|
||||
quic_send(Stream, <<?PACKET_PEER_INFO, EmptyResponse/binary>>),
|
||||
keep_state_and_data;
|
||||
{ok, {NatPeer = {{Ip0, Ip1, Ip2, Ip3}, NatPort}, NatType}, V6Info} ->
|
||||
logger:debug("[sdlan_channel] query_info src_mac is: ~p, dst_mac: ~p, nat_peer: ~p",
|
||||
@ -197,12 +197,12 @@ handle_event(info, {frame, <<?PACKET_QUERY_INFO, Body/binary>>}, registered, #st
|
||||
},
|
||||
v6_info = V6Info
|
||||
}),
|
||||
{ok, _} = quicer:send(Stream, <<?PACKET_PEER_INFO, PeerInfo/binary>>),
|
||||
quic_send(Stream, <<?PACKET_PEER_INFO, PeerInfo/binary>>),
|
||||
keep_state_and_data
|
||||
end;
|
||||
|
||||
handle_event(info, {frame, <<?PACKET_PING>>}, registered, State = #state{stream = Stream, ping_counter = PingCounter}) ->
|
||||
{ok, _} = quicer:send(Stream, <<?PACKET_PONG>>),
|
||||
quic_send(Stream, <<?PACKET_PONG>>),
|
||||
{keep_state, State#state{ping_counter = PingCounter + 1}};
|
||||
|
||||
handle_event(info, {timeout, _, ping_ticker}, _, State = #state{client_id = ClientId, ping_counter = PingCounter}) ->
|
||||
@ -219,7 +219,7 @@ handle_event(info, {timeout, _, ping_ticker}, _, State = #state{client_id = Clie
|
||||
%% 发送指令信息
|
||||
handle_event(info, {send_event, EventType, Event}, registered, #state{stream = Stream, client_id = ClientId}) ->
|
||||
logger:debug("[sdlan_channel] client_id: ~p, will send eventType: ~p, event: ~p", [ClientId, EventType, Event]),
|
||||
{ok, _} = quicer:send(Stream, <<?PACKET_EVENT, EventType, Event/binary>>),
|
||||
quic_send(Stream, <<?PACKET_EVENT, EventType, Event/binary>>),
|
||||
keep_state_and_data;
|
||||
|
||||
%% 取消注册
|
||||
@ -291,4 +291,9 @@ register_nak_reply(PacketId, ErrorCode, ErrorMsg) when is_integer(PacketId), is_
|
||||
<<?PACKET_REGISTER_SUPER_NAK, RegisterNakReply/binary>>.
|
||||
|
||||
rsa_encode(PlainText, RsaPubKey) when is_binary(PlainText) ->
|
||||
iolist_to_binary(sdlan_cipher:rsa_encrypt(PlainText, RsaPubKey)).
|
||||
iolist_to_binary(sdlan_cipher:rsa_encrypt(PlainText, RsaPubKey)).
|
||||
|
||||
-spec quic_send(Stream :: quicer:stream_handle(), Packet :: binary()) -> no_return().
|
||||
quic_send(Stream, Packet) when is_binary(Packet) ->
|
||||
Len = byte_size(Packet),
|
||||
{ok, _} = quicer:send(Stream, <<Len:16, Packet/binary>>).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user