From 7e79c4393fc75b271b45f7a8b82d751b180da1c5 Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Mon, 28 May 2018 08:33:04 +0900 Subject: [PATCH] foo --- zomp/etc/otpr/realm.conf | 4 + zomp/etc/sys.conf | 5 + zomp/etc/version.txt | 1 + zomp/key/otpr/otpr.1.package.pub.der | Bin 2062 -> 0 bytes zomp/key/otpr/otpr.1.realm.pub.der | Bin 2062 -> 0 bytes zomp/key/otpr/zxq9-root.pub.der | Bin 0 -> 2062 bytes zomp/lib/otpr/zx/0.1.0/make_zx | 39 ++++ zomp/lib/otpr/zx/0.1.0/src/zx.erl | 9 +- zomp/lib/otpr/zx/0.1.0/src/zx_conf_sys.erl | 251 +++++++++++++++++++++ zomp/lib/otpr/zx/0.1.0/src/zx_conn.erl | 86 ++++--- zomp/lib/otpr/zx/0.1.0/src/zx_daemon.erl | 48 ++-- zomp/lib/otpr/zx/0.1.0/src/zx_lib.erl | 90 ++++++-- zomp/lib/otpr/zx/0.1.0/zmake | 48 ---- zomp/otpr.realm | 20 -- zomp/zx | 11 +- zomp/zx.cmd | 9 + zx_dev | 18 +- 17 files changed, 478 insertions(+), 161 deletions(-) create mode 100644 zomp/etc/otpr/realm.conf create mode 100644 zomp/etc/sys.conf create mode 100644 zomp/etc/version.txt delete mode 100644 zomp/key/otpr/otpr.1.package.pub.der delete mode 100644 zomp/key/otpr/otpr.1.realm.pub.der create mode 100644 zomp/key/otpr/zxq9-root.pub.der create mode 100755 zomp/lib/otpr/zx/0.1.0/make_zx create mode 100644 zomp/lib/otpr/zx/0.1.0/src/zx_conf_sys.erl delete mode 100755 zomp/lib/otpr/zx/0.1.0/zmake delete mode 100644 zomp/otpr.realm create mode 100644 zomp/zx.cmd diff --git a/zomp/etc/otpr/realm.conf b/zomp/etc/otpr/realm.conf new file mode 100644 index 0000000..fbff7c3 --- /dev/null +++ b/zomp/etc/otpr/realm.conf @@ -0,0 +1,4 @@ +{realm, "otpr"}. +{prime, {"otpr.psychobitch.party",11311}}. +{sysop, "zxq9"}. +{key, "zxq9-root"}. diff --git a/zomp/etc/sys.conf b/zomp/etc/sys.conf new file mode 100644 index 0000000..aeeb3d0 --- /dev/null +++ b/zomp/etc/sys.conf @@ -0,0 +1,5 @@ +{timeout, 5}. +{retry, 3}. +{maxconn, 5}. +{managed, []}. +{mirrors, []}. diff --git a/zomp/etc/version.txt b/zomp/etc/version.txt new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/zomp/etc/version.txt @@ -0,0 +1 @@ +0.1.0 diff --git a/zomp/key/otpr/otpr.1.package.pub.der b/zomp/key/otpr/otpr.1.package.pub.der deleted file mode 100644 index e844a3bfb704c026ff00c05bee00a3db78380102..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2062 zcmV+p2=VtYf(Qx%f(QWs+4~Y8{hu^D9WI+v*(Kd+X^!qnl?)??wZi+0@JH$Oz(Wl} zmx4lZ0Y8K&cm(U1LMGHmB$^ihD37Jxlp|hZ!*lp>Llr;cl)*NGrgBC$bnj!fj-4gF zW%d9ZSV<6~Ke=CS3Fs*qvX>pO;4+!!p^iPDWax%<9>X7-0mKY+d9d~(t$Y1cLqO66-b1>y8=E+$m;awhr=q)#Nj6T6C)I!SF$RIsmvI8{MT|vo$Ac!4})M*KvtGBOPQ0N+mYf$&#r@KziaCHdMndI%AOo#1QkDst8Hre?w%#AW*31G9-k*pjHIpbdpR zdjbc8d;r{qyqbV6)f~f~N> z6~(@spo)B}cYW*g5*il2-d` zvb9Lo5J%I!kcg0rO9M%y(%Dz3`~{mIIu|YvrXInA*5*>7PFJJpH{Ro%}Z$7dazfY(s<%X+jspz zXMDYdIWFBf%&GjV(YSc}RTOtgYNCA;E4~c?g=>|ag&d;t5QAeJIM^mye$$}?8D4)U z>wJ5Z(G_CWFB>Q0S z^;h4Rc7y79nS)cI+FPi7&)Yz}mYpD84wu~iI3yJ0ERj)jxK9>mG^mFx;Uqa7 z$r*d20JQSRJ(r5idk?~W@pVs=?TXOxZTQuO&V}xe8KET4%TN)l% zsYD~|3x-d5dPg{ZrnvE^(9<3mbCWJC?1NAYJy?RUW}A!-qlT41-s*H$*bZe1l)ab= zE=+qW(XhW+Q^9@fm(3KZhGb%uP_U0>xQP`k^ocG$AtwOUFuSSAUx#U#_5;-H%Kw$d zuM=u{UVGl$mJ|MY#O>HRzT{F{?^J*x`xvXJJ<|wY1KyC8LkpTZ4#F~Bd6E76pwTFg z&z!E&tEx<~_NyS`HX7n<9;qj1@Y2sGwqTws_-#Idb{^{e28qY<48Cp|5jc@I=3yyAIJj4CH(UU zz;X$kuqK2H9z8PLOBwwg^CDZP+`O55WFuKnbP3f5 z9H-b%q&3&CdW?DXBs05f7OP6Iei(_~>leOY+yqmkIdJi$c;0rukwlMST=HE%FK@^D(4fFbBoOuJr>ggG5lv->1dy`#o(h$B?~%7#8?(&zDa+8F&2ksPp2e?9I|y=1JO=yRERjZTA7nFtyL8Ie!ZEf! zwgP@cG-JRMh9;3ADx)RqqgL`>Up%YMti~Q)qdqNNA8(-ST!OlJKBFGFzR|V%klVaa zck(C=wpA#&H4Dfx7xP&C$dcg)1DnNfM7aMgN9kmgFo^r25%xE9!x6`K%oQ;QZA6(S z$t{lF-3Tv)6hI_Rz32BCcy3Ejm4DVir9Ulese!Ez@I4MSBf5wBE@Z>Cv&?=;G+=9Y zCva~%8v#WONS&FEu2-WQK@WS3h^&M0e8q$H1piC##28aBg**T72gOIo^Xofy7f>H# zfQ7{p4tl8HC{_yikXy^dn$X=(BR`dTY{y2nJA(r=VY_^~otvwOCGnLlOb=~m#*?LZ zLOz~s!Y*+WgmZQQLTHW#LMQG)MYd+-Tak9PD+y@SRlFD>#rg|u2uBc7^Eo2R5#;Nk sc&wqfkxHKrMYU40l%%>V!Z diff --git a/zomp/key/otpr/otpr.1.realm.pub.der b/zomp/key/otpr/otpr.1.realm.pub.der deleted file mode 100644 index a4df4cb9b6fa962bbbd555ad8b528d4ad389aceb..0000000000000000000000000000000000000000 GIT binary pat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;(rdla8>^2Q9J|BwT|(paWbiK?g&^JV@q&J+Xna0~pLzkwE3 zN;o{59kA23Y3G8Q4De$L!NgCcpf()5I-QQFda#Cf3)+tuY~j%mT&}J+JM<82l3_om z>Bk_u$)g7JS4wC~GmI3@wcs0~MXTEM^)h|lDQ^IpKP^ASAt!6=ome$6haNX!qJ8{Il2Jc=EeY%K ztT@^ZOz9HPy}C%d9^^SP*s%trjHHK^H282XODxu5;U-QXcOP`|)1+fHI`cDd@wdy) z_p_4;Rc1r1TD#Zea7n~@FHkEz{bYoP=Ps>lFwWo=eC^Qi`d|~~|JxW}-&>$Rr%;Eq zM)C6C3;xwv6ATu;QD!2`-NJlG=F@p&D&qQ_f*QPJv$U|D^Zbq7UO@KnizNsH3(@F` zF*?R&Ru`5Xxop&dhHkxv0#_gg)OHd1n>yRuF~q|1aAaS&5al)QJ0Pm{!qX|2RkR|B zl$j6f0D(WDml2VTQaM>2e<+_ipl-f@pH8!N*iWW_$+< z#_7)qITNJLj-HsRZN(-K^$E$#5Ue%fR-+Fg{WohSe}Z@R3Ln4KQql sRdp>M(2%ki%p0K)%tT#GhZ%uSQhE^rl;rv(C96lz;ei_g0s{d60Ra=~`v3p{ literal 0 HcmV?d00001 diff --git a/zomp/lib/otpr/zx/0.1.0/make_zx b/zomp/lib/otpr/zx/0.1.0/make_zx new file mode 100755 index 0000000..1ca8077 --- /dev/null +++ b/zomp/lib/otpr/zx/0.1.0/make_zx @@ -0,0 +1,39 @@ +#! /usr/bin/env escript + +-mode(compile). + +main(Args) -> + true = code:add_patha("ebin"), + up_to_date = make:all(), + ok = lists:foreach(fun dispatch/1, Args), + halt(0). + + +dispatch("edoc") -> + ok = edoc(); +dispatch("dialyze") -> + ok = dialyze(); +dispatch("test") -> + ok = test(); +dispatch(Unknown) -> + ok = io:format("make_zx: Unknown directive: ~tp~n", [Unknown]), + halt(1). + + +edoc() -> + ok = io:format("EDOC: Writing docs...~n"), + edoc:application(zx, ".", []). + + +dialyze() -> + case dialyzer:run([{from, src_code}, {files_rec, ["./src"]}]) of + [] -> + io:format("Dialyzer found no errors and returned no warnings! Yay!~n"); + Warnings -> + Messages = [dialyzer:format_warning(W) || W <- Warnings], + lists:foreach(fun io:format/1, Messages) + end. + + +test() -> + io:format("TEST: If I only had a brain.~n"). diff --git a/zomp/lib/otpr/zx/0.1.0/src/zx.erl b/zomp/lib/otpr/zx/0.1.0/src/zx.erl index 7f93cbb..0cc4b4d 100644 --- a/zomp/lib/otpr/zx/0.1.0/src/zx.erl +++ b/zomp/lib/otpr/zx/0.1.0/src/zx.erl @@ -29,7 +29,7 @@ option/0, host/0, key_id/0, key_name/0, key_data/0, - user/0, username/0, lower0_9/0, label/0, + user_id/0, user_name/0, lower0_9/0, label/0, package_meta/0]). -include("zx_logger.hrl"). @@ -46,7 +46,6 @@ -type version() :: {Major :: non_neg_integer() | z, Minor :: non_neg_integer() | z, Patch :: non_neg_integer() | z}. --type identifier() :: realm() | package() | package_id(). -type option() :: {string(), term()}. -type host() :: {string() | inet:ip_address(), inet:port_number()}. -type key_id() :: {realm(), key_name()}. @@ -1312,7 +1311,7 @@ connect_auth(Realm) -> -spec connect_auth(Socket, Realm, User, KeyID, Key) -> Result when Socket :: gen_tcp:socket(), Realm :: realm(), - User :: user(), + User :: user_id(), KeyID :: key_id(), Key :: term(), Result :: {ok, gen_tcp:socket()} @@ -1393,7 +1392,7 @@ confirm_auth(Socket) -> -spec prep_auth(Realm, RealmConf) -> {User, KeyID, Key} | no_return() when Realm :: realm(), RealmConf :: [term()], - User :: user(), + User :: user_id(), KeyID :: key_id(), Key :: term(). %% @private @@ -1790,7 +1789,7 @@ dialyze() -> %%% Create Realm & Sysop --spec create_user(realm(), username()) -> no_return(). +-spec create_user(realm(), user_name()) -> no_return(). %% @private %% Validate the realm and username provided, prompt the user to either select a keypair %% to use or generate a new one, and bundle a .zuser file for conveyance of the user diff --git a/zomp/lib/otpr/zx/0.1.0/src/zx_conf_sys.erl b/zomp/lib/otpr/zx/0.1.0/src/zx_conf_sys.erl new file mode 100644 index 0000000..d487626 --- /dev/null +++ b/zomp/lib/otpr/zx/0.1.0/src/zx_conf_sys.erl @@ -0,0 +1,251 @@ +%%% @doc +%%% zx_conf_sys: An interface to etc/sys.conf +%%% +%%% It may seem overkill to write an interface module for a config file that only tracks +%%% five things, but scattering this all around the project is just a bit too l33t for +%%% an infrastructure project like ZX. +%%% +%%% Each exported function that is named after an attribute has two versions, one of +%%% arity-1 and one of arity-2. The arity-1 version is a "getter", and the arity-2 +%%% version is a "setter". Other functions deal with the data in a way that returns +%%% an answer and updates the state accordingly. +%%% +%%% Bad configuration data causes a reset to defaults so that the system can function. +%%% @end + +-module(zx_conf_sys). +-author("Craig Everett "). +-copyright("Craig Everett "). +-license("GPL-3.0"). + +-export([load/0, save/1, + timeout/1, timeout/2, + retries/1, retries/2, retry/1, retries_left/1, + maxconn/1, maxconn/2, + managed/1, managed/2, add_managed/2, rem_managed/2, + mirrors/1, mirrors/2, add_mirror/2, rem_mirror/2, next_mirror/1, + reset/0]). + +-export_type([data/0]). + +-include("zx_logger.hrl"). + + + +%%% Type Definitions + +-record(d, + {timeout = 5 :: pos_integer(), + retries = {0, 3} :: non_neg_integer(), + maxconn = 5 :: pos_integer(), + managed = sets:new() :: sets:set(zx:realm()), + mirrors = queue:new() :: queue:queue(zx:host())}). + +-opaque data() :: #d{}. + + + +%%% Interface functions + +-spec load() -> data(). +%% @doc +%% Read from etc/sys.conf and return a populated data() record if it exists, or +%% populate default values and write a new one if it does not. If a damaged sys.conf +%% is discovered it will be repaired. This function is side-effecty so should only +%% be called by zx_daemon and utility code. + +load() -> + case file:consult(path()) of + {ok, List} -> + populate_data(List); + {error, Reason} -> + ok = log(error, "Load etc/sys.conf failed with: ~tp", [Reason]), + Data = #d{}, + ok = save(Data), + Data + end. + + +populate_data(List) -> + Timeout = + case proplists:get_value(timeout, List, 5) of + V when is_integer(V) and V > 0 -> V; + _ -> 5 + end, + Retry = + case proplists:get_value(retry, List, 3) of + V when is_integer(V) and V > 0 -> V; + _ -> 3 + end, + MaxConn = + case proplists:get_value(maxconn, List, 5) of + V when is_integer(V) and V > 0 -> V; + _ -> 5 + end, + Managed = + case proplists:get_value(managed, List, []) of + V when is_list(V) -> sets:from_list(V); + _ -> sets:new() + end, + Mirrors = + case proplists:get_value(mirrors, List, []) of + V when is_list(V) -> queue:from_list(V); + _ -> queue:new() + end, + #d{timeout = Timeout, + retries = Retries, + maxconn = MaxConn, + managed = Managed, + mirrors = Mirrors}. + + +-spec save(data()) -> ok. +%% @doc +%% Save the current etc/sys.conf to disk. + +save(#d{timeout = Timeout, + retries = {_, Retries}, + maxconn = MaxConn, + managed = Managed, + mirrors = Mirrors}) -> + Terms = + [{timeout, Timeout}, + {retries, Retries}, + {maxconn, MaxConn}, + {managed, sets:to_list(Managed)}, + {mirrors, queue:to_list(Mirrors)}], + ok = zx_lib:write_terms(path(), Terms), + log(info, "Wrote etc/sys.conf"). + + +-spec timeout(data()) -> pos_integer(). +%% @doc +%% Return the timeout value. + +timeout(#d{timeout = Timeout}) -> + Timeout. + + +-spec timeout(Data, Value) -> NewData + when Data :: data(), + Value :: pos_integer(), + NewData :: data(). +%% @doc +%% Set the timeout attribute to a new value. + +timeout(Data, Value) + when is_integer(Value) and Value > 0 -> + Data#d{timeout = Value}. + + +-spec retries(data()) -> non_neg_integer(). +%% @doc +%% Return the retries value. + +retries(#d{retries = Retries}) -> + Retries. + + +-spec retries(Data, Value) -> NewData + when Data :: data(), + Value :: non_neg_integer(), + NewData :: data(). +%% @doc +%% Set the retries attribute to a new value. + +retries(Data = #d{retries = {Remaining, _}, Value) -> + when is_integer(Value) and Value >= 0 -> + Data#d{retries = {Remaining, Value}}. + + +-spec retry(Data) -> Result + when Data :: data(), + Result :: {ok, NewData} + | no_retries, + NewData :: data(). +%% @doc +%% Tell the caller whether there are any more retries remaining or return `ok' and +%% update the state. + +retry(#d{retries = {0, _}}) -> + no_retries; +retry(Data = #d{retries = {Remaining, Setting}}) -> + NewRemaining = Current - 1, + NewData = Data#d{retries = {NewRemaining, Setting}}, + {ok, NewData}. + + +-spec retries_left(data()) -> non_neg_integer(). +%% @doc +%% Return the number of retries remaining. + +retries_left(#d{retries = {Remaining, _}}) -> + Remaining. + + +-spec maxconn(data()) -> pos_integer(). +%% @doc +%% Return the value of maxconn. + +maxconn(#d{maxconn = MaxConn}) -> + MaxConn. + + +-spec maxconn(Data, Value) -> NewData + when Data :: data(), + Value :: pos_integer(), + NewData :: data(). +%% @doc +%% Set the value of maxconn. + +maxconn(Data, Value) + when is_integer(Value) and Value > 0 -> + Data#d{maxconn = Value}. + + +-spec managed(data()) -> list(zx:realm()). +%% @doc +%% Return the list of realms managed by the current node. + +managed(#d{managed = Managed}) -> + sets:to_list(Managed). + + +-spec managed(Data, List) -> NewData + when Data :: data(), + List :: [zx:realm()], + NewData :: data(). +%% @doc +%% Reset the set of managed realms entirely. +%% The realms must be configured on the current realm at a minimum. + +managed(Data, List) -> + Scrubbed = scrub_realms(List), + NewManaged = sets:from_list(Scrubbed), + Data#d{managed = NewManaged}. + + +scrub_realms(List) -> + %... + []. + + +-spec add_managed(Data, Realm) -> {ok, + when Data :: data(), + Realm :: zx:realm(), + NewData :: data(). +%% @doc +%% Add a new realm to the list of managed realms. The new realm must be configured on +%% the current node. + +add_managed(Data = #d{managed = Managed}, Realm) -> + case zx_lib:valid_lower0_9(Realm) of + + + +-spec path() -> file:filename(). +%% @private +%% Return the path to $ZOMP_DIR/etc/sys.conf. + +path() -> + filename:join(zx_lib:path(etc), "sys.conf"). diff --git a/zomp/lib/otpr/zx/0.1.0/src/zx_conn.erl b/zomp/lib/otpr/zx/0.1.0/src/zx_conn.erl index 119c27e..1c84891 100644 --- a/zomp/lib/otpr/zx/0.1.0/src/zx_conn.erl +++ b/zomp/lib/otpr/zx/0.1.0/src/zx_conn.erl @@ -266,27 +266,49 @@ handle_message(Socket, Bin) -> handle_request(Socket, Action) -> ok = zx_net:send(Socket, Action), - case element(1, Action) of - list -> - do_list(Action, Socket); - latest -> - do_latest(Action, Socket); - fetch -> - do_fetch(Action, Socket); - key -> - do_key(Action, Socket); - pending -> - do_pending(Action, Socket); - packagers -> - do_packagers(Action, Socket); - maintainers -> - do_maintainers(Action, Socket); - sysops -> - do_sysops(Action, Socket) + Response = + case element(1, Action) of + list -> + do_list(Action, Socket); + latest -> + do_latest(Action, Socket); + fetch -> + do_fetch(Action, Socket); + key -> + do_key(Action, Socket); + pending -> + do_pending(Action, Socket); + packagers -> + do_packagers(Action, Socket); + maintainers -> + do_maintainers(Action, Socket); + sysops -> + do_sysops(Action, Socket) end, handle_response(Socket, Response). +handle_fetch(_, _) -> {error, nyi}. + +handle_query(_, _) -> {error, nyi}. + +do_list(_, _) -> {error, nyi}. + +do_latest(_, _) -> {error, nyi}. + +do_fetch(_, _) -> {error, nyi}. + +do_key(_, _) -> {error, nyi}. + +do_pending(_, _) -> {error, nyi}. + +do_packagers(_, _) -> {error, nyi}. + +do_maintainers(_, _) -> {error, nyi}. + +do_sysops(_, _) -> {error, nyi}. + + handle_response(Socket, Command) -> receive @@ -305,21 +327,21 @@ interpret_response(Socket, ping, Command) -> handle_response(Socket, Command); interpret_response(Socket, {sub, Channel, Message}, Command) -> ok = zx_daemon:notify(Channel, Message), - handle_response(Socket, Command); -interpret_response(Socket, {update, Message}, Command) -> -interpret_response(Socket, Response, list) -> -interpret_response(Socket, Response, latest) -> -interpret_response(Socket, Response, fetch) -> -interpret_response(Socket, Response, key) -> -interpret_response(Socket, Response, pending) -> -interpret_response(Socket, Response, packagers) -> -interpret_response(Socket, Response, maintainers) -> -interpret_response(Socket, Response, sysops) -> - - - - case element(1, Action) of - end, + handle_response(Socket, Command). +%interpret_response(Socket, {update, Message}, Command) -> +%interpret_response(Socket, Response, list) -> +%interpret_response(Socket, Response, latest) -> +%interpret_response(Socket, Response, fetch) -> +%interpret_response(Socket, Response, key) -> +%interpret_response(Socket, Response, pending) -> +%interpret_response(Socket, Response, packagers) -> +%interpret_response(Socket, Response, maintainers) -> +%interpret_response(Socket, Response, sysops) -> +% +% +% +% case element(1, Action) of +% end, -spec fetch(Socket, PackageID) -> Result diff --git a/zomp/lib/otpr/zx/0.1.0/src/zx_daemon.erl b/zomp/lib/otpr/zx/0.1.0/src/zx_daemon.erl index cc78934..86296c1 100644 --- a/zomp/lib/otpr/zx/0.1.0/src/zx_daemon.erl +++ b/zomp/lib/otpr/zx/0.1.0/src/zx_daemon.erl @@ -5,13 +5,13 @@ %%% %%% The daemon resides in the background once started and awaits query requests and %%% subscriptions from other processes. The daemon is only capable of handling -%%% unprivileged (user) actions. +%%% unprivileged ("leaf") actions. %%% %%% %%% Discrete state and local abstract data types %%% -%%% The daemon must keep track of requestors, subscribers, and zx_conn processes by -%%% using monitors. Because these various types of clients are found in different +%%% The daemon must keep track of requestors, subscribers, peers, and zx_conn processes +%%% by using monitors. Because these various types of clients are found in different %%% structures the monitors are maintained in a data type called monitor_index(), %%% shortened to "mx" throughout the module. This structure is treated as an opaque %%% data type and is handled by a set of functions defined toward the end of the module @@ -20,18 +20,23 @@ %%% Node connections (zx_conn processes) must also be tracked for status and realm %%% availability. This is done using a type called conn_index(), shortened to "cx" %%% throughout the module. conn_index() is treated as an abstract, opaque datatype -%%% throughout the module, and is handled via a set of cx_*/N functions (after the +%%% throughout the module and is handled via a set of cx_*/N functions (after the %%% mx_*/N section). %%% %%% Do NOT directly access data within these structures, use (or write) an accessor -%%% function that does what you want. Accessor functions MUST be pure with the sole -%%% exception of the mx_* functions that create and destroy monitors. +%%% function that does what you want. Accessor functions MUST be pure with the +%%% exception of mx_add_monitor/3 and mx_del_monitor/3 that create and destroy +%%% monitors. %%% %%% %%% Connection handling %%% %%% The daemon is structured as a service manager in a service -> worker structure. %%% http://zxq9.com/archives/1311 +%%% This allows it to abstract the servicing of tasks at a high level, making it +%%% unnecessary for other processes to talk directly to any zx_conn processes or care +%%% whether the current runtime is the host's zx proxy or a peer instance. +%%% %%% It is in charge of the high-level task of servicing requested actions and returning %%% responses to callers as well as mapping successful connections to configured realms %%% and repairing failed connections to nodes that reduce availability of configured @@ -40,8 +45,9 @@ %%% When the zx_daemon is started it checks local configuration and cache files to %%% determine what realms must be available and what cached Zomp nodes it is aware of. %%% It populates the CX (conn_index(), mentioned above) with realm config and host -%%% cache data, and then immediately initiates three connection attempts to cached -%%% nodes for each realm configured if possible (see init_connections/0). +%%% cache data, and then initiates a connection attempt to each configured prime node +%%% and up to maxconn connection attempts to cached nodes for each realm as well. +%%% (See init_connections/0). %%% %%% Once connection attempts have been initiated the daemon waits in receive for %%% either a connection report (success or failure) or an action request from @@ -83,6 +89,7 @@ %%% should not be cases where the work queue stalls on active requests. %%% %%% Requestors sending either download or realm query requests are given a reference +%%% (an integer, not an Erlang reference, as the message may cross node boundaries) %%% to match on for receipt of their result messages or to be used to cancel the %%% requested work (timeouts are handled by the caller, not by the daemon). %%% @@ -105,7 +112,7 @@ %%% within a host system. %%% %%% When zx starts the daemon will attempt an exclusive write to a lock file called -%%% $ZOMP_HOME/zomp.lock using file:open(LockFile, [exclusive]), writing a system +%%% $ZOMP_DIR/john.locke using file:open(LockFile, [exclusive]), writing a system %%% timestamp. If the write succeeds then the daemon knows it is the master for the %%% system and will begin initiating connections as described above as well as open a %%% local socket to listen for other zx instances which will need to proxy their own @@ -140,7 +147,7 @@ -export([pass_meta/3, subscribe/1, unsubscribe/1, list/0, list/1, list/2, list/3, latest/1, - fetch/1, key/1, + fetch_zsp/1, fetch_key/1, pending/1, packagers/1, maintainers/1, sysops/1]). -export([report/1, result/2, notify/2]). -export([start_link/0, stop/0]). @@ -162,15 +169,16 @@ %%% Type Definitions -record(s, - {meta = none :: none | zx:package_meta(), - home = none :: none | file:filename(), - argv = none :: none | [string()], - id = 0 :: id(), - actions = [] :: [request()], - requests = maps:new() :: requests(), - dropped = maps:new() :: requests(), - mx = mx_new() :: monitor_index(), - cx = cx_load() :: conn_index()}). + {meta = none :: none | zx:package_meta(), + home = none :: none | file:filename(), + argv = none :: none | [string()], + sys_conf = zx_conf_sys:load() :: zx_conf_sys:data(), + id = 0 :: id(), + actions = [] :: [request()], + requests = maps:new() :: requests(), + dropped = maps:new() :: requests(), + mx = mx_new() :: monitor_index(), + cx = cx_load() :: conn_index()}). -record(cx, @@ -438,7 +446,7 @@ latest({Realm, Name, Version}) -> request({latest, Realm, Name, Version}). --spec fetch(PackageID) -> {ok, RequestID} +-spec fetch_zsp(PackageID) -> {ok, RequestID} when PackageID :: zx:package_id(), RequestID :: integer(). %% @doc diff --git a/zomp/lib/otpr/zx/0.1.0/src/zx_lib.erl b/zomp/lib/otpr/zx/0.1.0/src/zx_lib.erl index 935821c..afd1665 100644 --- a/zomp/lib/otpr/zx/0.1.0/src/zx_lib.erl +++ b/zomp/lib/otpr/zx/0.1.0/src/zx_lib.erl @@ -14,7 +14,8 @@ -copyright("Craig Everett "). -license("GPL-3.0"). --export([zomp_home/0, find_zomp_home/0, +-export([zomp_dir/0, find_zomp_dir/0, + path/1, path/2, path/3, hosts_cache_file/1, get_prime/1, realm_meta/1, read_project_meta/0, read_project_meta/1, read_package_meta/1, write_project_meta/1, write_project_meta/2, @@ -33,41 +34,92 @@ %%% Functions -zomp_home() -> - case os:getenv("ZOMP_HOME") of +-spec zomp_dir() -> file:filename(). +%% @doc +%% Return the path to the Zomp/ZX installation directory. + +zomp_dir() -> + case os:getenv("ZOMP_DIR") of false -> - ZompHome = find_zomp_home(), - true = os:putenv("ZOMP_HOME", ZompHome), - ZompHome; - ZompHome -> - ZompHome + ZompDir = find_zomp_dir(), + true = os:putenv("ZOMP_DIR", ZompDir), + ZompDir; + ZompDir -> + ZompDir end. --spec find_zomp_home() -> file:filename(). +-spec find_zomp_dir() -> file:filename(). %% @private %% Check the host OS and return the absolute path to the zomp filesystem root. -find_zomp_home() -> +find_zomp_dir() -> case os:type() of {unix, _} -> Home = os:getenv("HOME"), Dir = "zomp", filename:join(Home, Dir); {win32, _} -> - Drive = os:getenv("HOMEDRIVE"), - Path = os:getenv("HOMEPATH"), + Home = os:getenv("LOCALAPPDATA"), Dir = "zomp", - filename:join([Drive, Path, Dir]) + filename:join(Home, Dir) end. +-spec path(Type) -> Result + when Type :: etc + | var + | tmp + | log + | lib, + Result :: file:filename(). +%% @doc +%% Return the top-level path of the given type in the Zomp/ZX system. + +path(etc) -> filename:join(zomp_dir(), "etc"); +path(var) -> filename:join(zomp_dir(), "var"); +path(tmp) -> filename:join(zomp_dir(), "tmp"); +path(log) -> filename:join(zomp_dir(), "log"); +path(lib) -> filename:join(zomp_dir(), "lib"). + + +-spec path(Type, Realm) -> Result + when Type :: etc + | var + | tmp + | log + | lib, + Realm :: zx:realm(), + Result :: file:filename(). +%% @doc +%% Return the realm-level path of the given type in the Zomp/ZX system. + +path(Type, Realm) -> + filename:join(path(Type), Realm). + + +-spec path(Type, Realm, Name) -> Result + when Type :: etc + | var + | tmp + | log + | lib, + Realm :: zx:realm(), + Name :: zx:name(), + Result :: file:filename(). +%% @doc +%% Return the package-level path of the given type in the Zomp/ZX system. + +path(Type, Realm, Name) -> + filename:join([path(Type), Realm, Name]). + + -spec hosts_cache_file(zx:realm()) -> file:filename(). %% @private %% Given a Realm name, construct a realm's .hosts filename and return it. hosts_cache_file(Realm) -> - filename:join(zomp_home(), Realm ++ ".hosts"). + filename:join(zomp_dir(), Realm ++ ".hosts"). -spec get_prime(Realm) -> Result @@ -99,7 +151,7 @@ get_prime(Realm) -> %% the file. realm_meta(Realm) -> - RealmFile = filename:join(zomp_home(), Realm ++ ".realm"), + RealmFile = filename:join(zomp_dir(), Realm ++ ".realm"), file:consult(RealmFile). @@ -139,7 +191,7 @@ read_project_meta(Dir) -> read_package_meta({Realm, Name, Version}) -> {ok, VersionString} = version_to_string(Version), - Path = filename:join([zomp_home(), "lib", Realm, Name, VersionString]), + Path = filename:join([zomp_dir(), "lib", Realm, Name, VersionString]), read_project_meta(Path). @@ -449,7 +501,7 @@ package_dir({Realm, Name, Version = {X, Y, Z}}) when is_integer(X), is_integer(Y), is_integer(Z) -> {ok, PackageDir} = package_string({Realm, Name}), {ok, VersionDir} = version_to_string(Version), - filename:join([zomp_home(), "lib", PackageDir, VersionDir]). + filename:join([zomp_dir(), "lib", PackageDir, VersionDir]). -spec package_dir(Prefix, Package) -> PackageDataDir @@ -461,7 +513,7 @@ package_dir({Realm, Name, Version = {X, Y, Z}}) package_dir(Prefix, {Realm, Name}) -> PackageString = package_string({Realm, Name, {z, z, z}}), - filename:join([zomp_home(), Prefix, PackageString]). + filename:join([zomp_dir(), Prefix, PackageString]). -spec namify_zrp(PackageID) -> ZrpFileName @@ -568,5 +620,5 @@ realm_conf(Realm) -> %% Load the config for the given realm or halt with an error. load_realm_conf(Realm) -> - Path = filename:join(zx_lib:zomp_home(), realm_conf(Realm)), + Path = filename:join(zomp_dir(), realm_conf(Realm)), file:consult(Path). diff --git a/zomp/lib/otpr/zx/0.1.0/zmake b/zomp/lib/otpr/zx/0.1.0/zmake deleted file mode 100755 index 75f3a21..0000000 --- a/zomp/lib/otpr/zx/0.1.0/zmake +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env escript - --mode(compile). - -main(Args) -> - ok = make(), - ok = lists:foreach(fun dispatch/1, Args), - halt(0). - - -dispatch("edoc") -> - ok = edoc(); -dispatch("dialyze") -> - ok = dialyze(); -dispatch("test") -> - ok = test(); -dispatch(Unknown) -> - ok = io:format("zmake: Unknown directive: ~tp~n", [Unknown]), - halt(1). - - -make() -> - true = code:add_patha("ebin"), - up_to_date = make:all(), - halt(0). - - -edoc() -> - ok = io:format("EDOC: Writing docs...~n"), - ok = edoc:application(zomp, ".", []), - halt(0). - - -dialyze() -> - ok = - case dialyzer:run([{from, src_code}, {files_rec, ["./src"]}]) of - [] -> - io:format("Dialyzer found no errors and returned no warnings! Yay!~n"); - Warnings -> - Messages = [dialyzer:format_warning(W) || W <- Warnings], - lists:foreach(fun io:format/1, Messages) - end, - halt(0). - - -test() -> - ok = io:format("TEST: If I only had a brain.~n"), - halt(0). diff --git a/zomp/otpr.realm b/zomp/otpr.realm deleted file mode 100644 index c0c267c..0000000 --- a/zomp/otpr.realm +++ /dev/null @@ -1,20 +0,0 @@ -{realm,"otpr"}. -{revision,0}. -{prime,{"otpr.psychobitch.party",11311}}. -{sysops,[{{"otpr","zxq9"},["zxq9.1"],"zxq9@zxq9.com","Craig Everett"}]}. -{realm_keys,[{{"otpr","otpr.1.realm"}, - realm, - {realm,"otpr"}, - <<206,129,232,15,23,149,65,167,9,157,25,210,91,113,55,56,14,12, - 153,218,37,83,148,3,89,208,61,43,95,89,51,228,245,78,115,52,15, - 82,23,100,53,189,136,19,104,58,222,216,184,87,75,231,151,18,90, - 243,115,160,244,32,232,71,57,95>>, - {{2018,1,10},{6,36,41}}}]}. -{package_keys,[{{"otpr","otpr.1.package"}, - package, - {realm,"otpr"}, - <<77,10,171,53,73,87,21,251,153,215,83,119,244,217,207,77,44, - 210,177,77,46,86,52,232,16,64,23,109,214,94,207,140,12,145, - 23,130,151,151,37,82,61,240,82,146,142,199,95,114,77,219,148, - 200,140,85,128,77,110,142,179,137,169,188,223,192>>, - {{2018,1,10},{6,36,41}}}]}. diff --git a/zomp/zx b/zomp/zx index c93a206..8f3cea1 100755 --- a/zomp/zx +++ b/zomp/zx @@ -1,13 +1,10 @@ #!/bin/sh -set -x - ZOMP_DIR="$HOME/zomp" -ORIGIN="$(pwd)" -VERSION="$(ls $ZOMP_DIR/lib/otpr/zx/ | sort --field-separator=. --reverse | head --lines=1)" +VERSION=$(cat "$ZOMP_DIR/etc/version.txt") ZX_DIR="$ZOMP_DIR/lib/otpr/zx/$VERSION" -cd "$ZX_DIR" -./zmake -cd "$ZOMP_DIR" +pushd "$ZX_DIR" +./make_zx +popd erl -pa "$ZX_DIR/ebin" -run zx start $@ diff --git a/zomp/zx.cmd b/zomp/zx.cmd new file mode 100644 index 0000000..a7ed5a3 --- /dev/null +++ b/zomp/zx.cmd @@ -0,0 +1,9 @@ +REM Prepare the environment for ZX and launch it + +set ZOMP_DIR="%LOCALAPPDATA%\zomp" +set VERSION=<"%ZOMP_DIR%\etc\version.txt" +set ZX_DIR="%ZOMP_DIR%\lib\otpr\zx\%VERSION%" +pushd "%ZX_DIR%" +escript.exe make_zx +popd +erl.exe -pa "%ZX_DIR%/ebin" -run zx start "%*" diff --git a/zx_dev b/zx_dev index 6a1d577..596b40b 100755 --- a/zx_dev +++ b/zx_dev @@ -1,13 +1,11 @@ -#!/bin/sh +#!/bin/bash -set -x +ZX_DEV_ROOT=$(dirname $BASH_SOURCE) +ZOMP_DIR="$ZX_DEV_ROOT/zomp" +VERSION=$(cat "$ZOMP_DIR/etc/version.txt") +ZX_DIR="$ZOMP_DIR/lib/otpr/zx/$VERSION" -ZOMP_DIR="$HOME/vcs/zx/zomp" -ORIGIN="$(pwd)" -VERSION="$(ls $ZOMP_DIR/lib/otpr-zx/ | sort --field-separator=. --reverse | head --lines=1)" -ZX_DIR="$ZOMP_DIR/lib/otpr-zx/$VERSION" - -cd "$ZX_DIR" -./zmake -cd "$ZOMP_DIR" +pushd "$ZX_DIR" +./make_zx +popd erl -pa "$ZX_DIR/ebin" -run zx start $@