More descriptive disconnected event, client info
This commit is contained in:
parent
8e795da00d
commit
2078ae7115
@ -1,6 +1,6 @@
|
|||||||
{application,gmhive_client,
|
{application,gmhive_client,
|
||||||
[{description,"Gajumaru Hive Client"},
|
[{description,"Gajumaru Hive Client"},
|
||||||
{vsn,"0.9.3"},
|
{vsn,"0.10.0"},
|
||||||
{registered,[]},
|
{registered,[]},
|
||||||
{applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
|
{applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
|
||||||
gmconfig,gmhive_protocol,gmhive_worker]},
|
gmconfig,gmhive_protocol,gmhive_worker]},
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
-spec start([{atom(), any()}]) -> {ok, [atom()]} | {error, any()}.
|
-spec start([{atom(), any()}]) -> {ok, [atom()]} | {error, any()}.
|
||||||
start(Opts) ->
|
start(Opts) ->
|
||||||
application:load(gmhive_client),
|
application:load(gmhive_client),
|
||||||
{error,_} = application:stop(gmhive_client),
|
_ = application:stop(gmhive_client),
|
||||||
_ = lists:foreach(fun({K, V}) ->
|
_ = lists:foreach(fun({K, V}) ->
|
||||||
application:set_env(gmhive_client, K, V)
|
application:set_env(gmhive_client, K, V)
|
||||||
end, Opts),
|
end, Opts),
|
||||||
|
|||||||
@ -57,6 +57,7 @@
|
|||||||
, auto_connect = true :: boolean()
|
, auto_connect = true :: boolean()
|
||||||
, econn
|
, econn
|
||||||
, connected = false :: boolean()
|
, connected = false :: boolean()
|
||||||
|
, status = disconnected :: disconnected | connecting | connected
|
||||||
, reconnect = true :: boolean()
|
, reconnect = true :: boolean()
|
||||||
, reconnect_timer :: timer_ref() | 'undefined'
|
, reconnect_timer :: timer_ref() | 'undefined'
|
||||||
, recache_timer :: reference() | 'undefined'
|
, recache_timer :: reference() | 'undefined'
|
||||||
@ -295,8 +296,9 @@ try_connect_(Opts0, S) ->
|
|||||||
case try_noise_connect(maps:merge(Opts0, PoolOpts)) of
|
case try_noise_connect(maps:merge(Opts0, PoolOpts)) of
|
||||||
{ok, EConn, Opts1} ->
|
{ok, EConn, Opts1} ->
|
||||||
S1 = protocol_connect(Opts1, S#st{ econn = EConn
|
S1 = protocol_connect(Opts1, S#st{ econn = EConn
|
||||||
|
, status = connecting
|
||||||
, reconnect_timer = undefined }),
|
, reconnect_timer = undefined }),
|
||||||
{ok, S1};
|
{ok, S1#st{status = connected}};
|
||||||
{error, _} = Error ->
|
{error, _} = Error ->
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
@ -442,14 +444,14 @@ protocol_connect(Opts, #st{econn = EConn} = S) ->
|
|||||||
Type = to_atom(opt(type, Opts, [<<"type">>])),
|
Type = to_atom(opt(type, Opts, [<<"type">>])),
|
||||||
RId = erlang:unique_integer(),
|
RId = erlang:unique_integer(),
|
||||||
Vsns = gmhp_msgs:versions(),
|
Vsns = gmhp_msgs:versions(),
|
||||||
%% Client = client_name(),
|
Client = client_name(),
|
||||||
Protocols = gmhp_msgs:protocols(hd(Vsns)),
|
Protocols = gmhp_msgs:protocols(hd(Vsns)),
|
||||||
ConnectReq = #{ protocols => Protocols
|
ConnectReq = #{ protocols => Protocols
|
||||||
, versions => Vsns
|
, versions => Vsns
|
||||||
, pool_id => PoolId
|
, pool_id => PoolId
|
||||||
, pubkey => Pubkey
|
, pubkey => Pubkey
|
||||||
, extra_pubkeys => Extra
|
, extra_pubkeys => Extra
|
||||||
%% , client => Client
|
, client => Client
|
||||||
, type => Type
|
, type => Type
|
||||||
, nonces => gmhc_server:total_nonces()
|
, nonces => gmhc_server:total_nonces()
|
||||||
, signature => ""},
|
, signature => ""},
|
||||||
@ -484,7 +486,10 @@ send_connect(EConn, RId, Msg, #{pubkey := Pubkey,
|
|||||||
notify_connected(S1#st{protocol = P, version = V, opts = Opts1});
|
notify_connected(S1#st{protocol = P, version = V, opts = Opts1});
|
||||||
#{error := #{code := _, message := ErrMsg}} = ErrReply ->
|
#{error := #{code := _, message := ErrMsg}} = ErrReply ->
|
||||||
?LOG_ERROR("Connect error: ~s", [ErrMsg]),
|
?LOG_ERROR("Connect error: ~s", [ErrMsg]),
|
||||||
disconnected(S#st.id, ErrReply, S),
|
%% TODO: fix the flow so that we send one disconnected event,
|
||||||
|
%% and set the reconnect in the right place. For now, stuff
|
||||||
|
%% the `reconnect = false`.
|
||||||
|
disconnected(S#st.id, ErrReply, S#st{reconnect = false}),
|
||||||
gmhc_eureka:invalidate_cache(),
|
gmhc_eureka:invalidate_cache(),
|
||||||
error(rejected)
|
error(rejected)
|
||||||
end
|
end
|
||||||
@ -493,37 +498,20 @@ send_connect(EConn, RId, Msg, #{pubkey := Pubkey,
|
|||||||
error(protocol_connect_timeout)
|
error(protocol_connect_timeout)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% client_name() ->
|
client_name() ->
|
||||||
%% MyStr = app_string(gmhive_client),
|
MyStr = app_string(gmhive_client),
|
||||||
%% case app_string(gajumine) of
|
case app_string(gajumine) of
|
||||||
%% <<>> -> MyStr;
|
<<>> -> MyStr;
|
||||||
%% GMStr -> <<MyStr/binary,",",GMStr/binary>>
|
GMStr -> <<MyStr/binary,",",GMStr/binary>>
|
||||||
%% end.
|
end.
|
||||||
%% %% {ok, Vsn} = application:get_key(gmhive_client, vsn),
|
|
||||||
%% %% maybe_add_gajumine(unicode:characters_to_binary(["gmhive_client-", Vsn])).
|
|
||||||
|
|
||||||
%% maybe_add_gajumine(Str) ->
|
app_string(App) ->
|
||||||
%% case setup_zomp:is_zomp_context() of
|
case application:get_key(App, vsn) of
|
||||||
%% true ->
|
undefined ->
|
||||||
%% case zx_daemon:meta() of
|
<<>>;
|
||||||
%% #{package_id := {"qpq","gajumine",_} = PId} ->
|
{ok, Vsn} ->
|
||||||
%% {ok, PStr} = zx_lib:package_string(PId),
|
unicode:characters_to_binary([atom_to_binary(App),"-",Vsn])
|
||||||
%% GMStr = unicode:characters_to_binary([",", PStr]),
|
end.
|
||||||
%% <<Str/binary, GMStr/binary>>;
|
|
||||||
%% _ ->
|
|
||||||
%% Str
|
|
||||||
%% end;
|
|
||||||
%% false ->
|
|
||||||
%% Str
|
|
||||||
%% end.
|
|
||||||
|
|
||||||
%% app_string(App) ->
|
|
||||||
%% case application:get_key(App, vsn) of
|
|
||||||
%% undefined ->
|
|
||||||
%% <<>>;
|
|
||||||
%% {ok, Vsn} ->
|
|
||||||
%% unicode:characters_to_binary([atom_to_binary(App),"-",Vsn])
|
|
||||||
%% end.
|
|
||||||
|
|
||||||
to_bin(A) when is_atom(A) ->
|
to_bin(A) when is_atom(A) ->
|
||||||
atom_to_binary(A, utf8);
|
atom_to_binary(A, utf8);
|
||||||
@ -541,10 +529,11 @@ connected(Id, Type, S) when Type==worker; Type==monitor ->
|
|||||||
disconnected(Id, S) ->
|
disconnected(Id, S) ->
|
||||||
disconnected(Id, #{}, S).
|
disconnected(Id, #{}, S).
|
||||||
|
|
||||||
disconnected(Id, Msg, S) ->
|
disconnected(_, _, #st{status = disconnected} = S) -> S;
|
||||||
gmhc_events:publish(disconnected, Msg#{id => Id}),
|
disconnected(Id, Msg, #st{reconnect = Bool} = S) ->
|
||||||
|
gmhc_events:publish(disconnected, Msg#{id => Id, reconnecting => Bool}),
|
||||||
gmhc_server:disconnected(Id),
|
gmhc_server:disconnected(Id),
|
||||||
S#st{connected = false}.
|
S#st{connected = false, status = disconnected}.
|
||||||
|
|
||||||
opt_autoconnect(#{auto_connect := Bool}) when is_boolean(Bool) ->
|
opt_autoconnect(#{auto_connect := Bool}) when is_boolean(Bool) ->
|
||||||
Bool;
|
Bool;
|
||||||
|
|||||||
@ -4,8 +4,8 @@
|
|||||||
{prefix,"gmhc"}.
|
{prefix,"gmhc"}.
|
||||||
{author,"Ulf Wiger, QPQ AG"}.
|
{author,"Ulf Wiger, QPQ AG"}.
|
||||||
{desc,"Gajumaru Hive Client"}.
|
{desc,"Gajumaru Hive Client"}.
|
||||||
{package_id,{"uwiger","gmhive_client",{0,9,3}}}.
|
{package_id,{"uwiger","gmhive_client",{0,10,0}}}.
|
||||||
{deps,[{"uwiger","gmhive_protocol",{0,2,0}},
|
{deps,[{"uwiger","gmhive_protocol",{0,3,1}},
|
||||||
{"uwiger","gmhive_worker",{0,5,1}},
|
{"uwiger","gmhive_worker",{0,5,1}},
|
||||||
{"uwiger","gmcuckoo",{1,2,4}},
|
{"uwiger","gmcuckoo",{1,2,4}},
|
||||||
{"otpr","eblake2",{1,0,1}},
|
{"otpr","eblake2",{1,0,1}},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user