Make local_request fetches work when zomp is locally hosted

https://gitlab.com/zxq9/zx/-/issues/86
This commit is contained in:
Craig Everett 2020-06-16 15:33:50 +09:00
parent fac2aaf6b6
commit 4a5fe74660
49 changed files with 72 additions and 23 deletions

View File

@ -1 +1 @@
0.10.7 0.10.8

View File

@ -1,6 +1,6 @@
{application,zx, {application,zx,
[{description,"An Erlang development tool and Zomp user client"}, [{description,"An Erlang development tool and Zomp user client"},
{vsn,"0.10.7"}, {vsn,"0.10.8"},
{applications,[stdlib,kernel]}, {applications,[stdlib,kernel]},
{modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key, {modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key,
zx_lib,zx_local,zx_net,zx_peer,zx_peer_man, zx_lib,zx_local,zx_net,zx_peer,zx_peer_man,

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -24,7 +24,7 @@
%%% @end %%% @end
-module(zx). -module(zx).
-vsn("0.10.7"). -vsn("0.10.8").
-behavior(application). -behavior(application).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -9,7 +9,7 @@
%%% @end %%% @end
-module(zx_auth). -module(zx_auth).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end %%% @end
-module(zx_conn). -module(zx_conn).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end %%% @end
-module(zx_conn_sup). -module(zx_conn_sup).
-vsn("0.10.7"). -vsn("0.10.8").
-behavior(supervisor). -behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -138,7 +138,7 @@
%%% @end %%% @end
-module(zx_daemon). -module(zx_daemon).
-vsn("0.10.7"). -vsn("0.10.8").
-behavior(gen_server). -behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
@ -1406,6 +1406,14 @@ eval_queue(Actions, State) ->
local_dispatch([], State) -> local_dispatch([], State) ->
State; State;
local_dispatch([{request, Pid, ID, {fetch, R, N, V}} | Rest], State) ->
Result =
case zomp_realm_man:lookup(R) of
{ok, RealmPID} -> local_fetch(RealmPID, {R, N, V});
Error -> Error
end,
Pid ! {result, ID, Result},
local_dispatch(Rest, State);
local_dispatch([{request, Pid, ID, Message} | Rest], State) -> local_dispatch([{request, Pid, ID, Message} | Rest], State) ->
Realm = element(2, Message), Realm = element(2, Message),
Result = Result =
@ -1452,6 +1460,46 @@ local_request(R, {list_sysops}) -> zomp_realm:list_sysops(R);
local_request(R, {list_type, T}) -> zomp_realm:list_type(R, T). local_request(R, {list_type, T}) -> zomp_realm:list_type(R, T).
local_fetch(RealmPID, PackageID = {_, N, V}) ->
{ok, PackageString} = zx_lib:package_string(PackageID),
ok = tell("Fetching ~s", [PackageString]),
case zomp_realm:fetch(RealmPID, {N, V}) of
{ok, Bin} -> do_import_package(Bin);
upstream -> local_fetch_upstream(PackageID, 0);
Error -> Error
end.
local_fetch_upstream(PackageID, Tries) ->
Realm = element(1, PackageID),
case zomp_node_man:lookup(Realm) of
{ok, NodePID} ->
ok = tell("Found node connector at ~p", [NodePID]),
ok = zomp_node:fetch(NodePID, PackageID),
wait_hops(PackageID);
wait ->
wait_upstream_node(PackageID, Tries);
error ->
{error, bad_realm}
end.
wait_hops(PackageID) ->
receive
{ok, PackageID, Bin} ->
do_import_package(Bin);
{hops, PackageID, Distance} ->
ok = tell("Fetch in progress. Hops: ~w", [Distance]),
wait_hops(PackageID)
after 60000 ->
{error, timeout}
end.
wait_upstream_node(PackageID, Tries) when Tries < 10 ->
_ = erlang:send_after(1000, self(), retry),
receive retry -> local_fetch_upstream(PackageID, Tries + 1) end;
wait_upstream_node(_, _) ->
{error, timeout}.
remote_dispatch([], State) -> remote_dispatch([], State) ->
State; State;
remote_dispatch([Action = {request, Pid, ID, Message} | Rest], remote_dispatch([Action = {request, Pid, ID, Message} | Rest],
@ -1628,7 +1676,8 @@ do_fetch(PackageID, Requestor, State = #s{id = ID}) ->
Action = {fetch, Realm, Name, Version}, Action = {fetch, Realm, Name, Version},
do_request(Requestor, Action, State); do_request(Requestor, Action, State);
Error -> Error ->
Requestor ! {result, ID, Error} Requestor ! {result, ID, Error},
State
end. end.
do_fetch2(Bin, Requestor, ID) -> do_fetch2(Bin, Requestor, ID) ->

View File

@ -8,7 +8,7 @@
%%% @end %%% @end
-module(zx_key). -module(zx_key).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -10,7 +10,7 @@
%%% @end %%% @end
-module(zx_lib). -module(zx_lib).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -6,7 +6,7 @@
%%% @end %%% @end
-module(zx_local). -module(zx_local).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end %%% @end
-module(zx_net). -module(zx_net).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -8,7 +8,7 @@
%%% @end %%% @end
-module(zx_peer). -module(zx_peer).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").
@ -166,7 +166,7 @@ handle_message(<<Command:8, Bin/binary>>) ->
9 -> deferred(fun zx_daemon:search/1, Payload); 9 -> deferred(fun zx_daemon:search/1, Payload);
10 -> deferred(fun zx_daemon:list_deps/1, Payload); 10 -> deferred(fun zx_daemon:list_deps/1, Payload);
11 -> deferred(fun zx_daemon:list_sysops/1, Payload); 11 -> deferred(fun zx_daemon:list_sysops/1, Payload);
12 -> zx_daemon:fetch(Payload); 12 -> deferred(fun zx_daemon:fetch/1, Payload);
13 -> zx_daemon:keychain(Payload); 13 -> zx_daemon:keychain(Payload);
14 -> zx_daemon:install(Payload); 14 -> zx_daemon:install(Payload);
15 -> zx_daemon:build(Payload); 15 -> zx_daemon:build(Payload);

View File

@ -9,7 +9,7 @@
%%% @end %%% @end
-module(zx_peer_man). -module(zx_peer_man).
-vsn("0.10.7"). -vsn("0.10.8").
-behavior(gen_server). -behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -6,7 +6,7 @@
%%% @end %%% @end
-module(zx_peer_sup). -module(zx_peer_sup).
-vsn("0.10.7"). -vsn("0.10.8").
-behaviour(supervisor). -behaviour(supervisor).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -10,7 +10,7 @@
%%% @end %%% @end
-module(zx_peers). -module(zx_peers).
-vsn("0.10.7"). -vsn("0.10.8").
-behavior(supervisor). -behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -5,7 +5,7 @@
%%% @end %%% @end
-module(zx_proxy). -module(zx_proxy).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end %%% @end
-module(zx_sup). -module(zx_sup).
-vsn("0.10.7"). -vsn("0.10.8").
-behavior(supervisor). -behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -6,7 +6,7 @@
%%% @end %%% @end
-module(zx_tty). -module(zx_tty).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end %%% @end
-module(zx_userconf). -module(zx_userconf).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end %%% @end
-module(zx_zsp). -module(zx_zsp).
-vsn("0.10.7"). -vsn("0.10.8").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0"). -license("GPL-3.0").

View File

@ -9,7 +9,7 @@
{license,"MIT"}. {license,"MIT"}.
{modules,[]}. {modules,[]}.
{name,"zx"}. {name,"zx"}.
{package_id,{"otpr","zx",{0,10,7}}}. {package_id,{"otpr","zx",{0,10,8}}}.
{prefix,"zx_"}. {prefix,"zx_"}.
{repo_url,"https://gitlab.com/zxq9/zx"}. {repo_url,"https://gitlab.com/zxq9/zx"}.
{tags,["tools","package manager","erlang"]}. {tags,["tools","package manager","erlang"]}.