committing to cleanup

This commit is contained in:
Peter Harpending
2026-09-04 19:40:44 -07:00
parent edf2030b34
commit c23eed3a4d
6 changed files with 126 additions and 15 deletions
+4 -4
View File
@@ -2,7 +2,7 @@
* Rubicon contract * Rubicon contract
* *
* Author: Peter Harpending <peterharpending@qpq.swiss> * Author: Peter Harpending <peterharpending@qpq.swiss>
* Date: 2026-08-12 * Date: 2026-09-04
*/ */
contract Rubicon = contract Rubicon =
// this could/should be a record, but records aren't really // this could/should be a record, but records aren't really
@@ -13,11 +13,11 @@ contract Rubicon =
// port : int, // port : int,
// protocol : string, // "tcp", "udp", "sctp", etc // protocol : string, // "tcp", "udp", "sctp", etc
// noise : string, // Noise_Foo_Bar_Baz_Quux // noise : string, // Noise_Foo_Bar_Baz_Quux
// pubkey : bytes, // responder static pubkey (noise rs field) // pubkey : address, // responder static pubkey (noise rs field)
// prologue : bytes} // noise prologue (empty = no prologue) // prologue : option(bytes)} // noise prologue (empty = no prologue)
// (ip, port, protocol, noise, pubkey, prologue) // (ip, port, protocol, noise, pubkey, prologue)
type rbx_tuple = string * int * string * string * bytes * bytes type rbx_tuple = string * int * string * string * address * option(bytes)
type state = list(rbx_tuple) type state = list(rbx_tuple)
entrypoint init(tuples: list(rbx_tuple)): state = entrypoint init(tuples: list(rbx_tuple)): state =
+38 -3
View File
@@ -4,7 +4,6 @@
-author("Peter Harpending"). -author("Peter Harpending").
-copyright("Peter Harpending"). -copyright("Peter Harpending").
-export([start/1]). -export([start/1]).
@@ -13,7 +12,43 @@
start(ArgV) -> start(ArgV) ->
ok = application:ensure_started(hakuzaru), ok = application:ensure_started(hakuzaru),
ok = hz:chain_nodes([{"testnet.tsuriai.jp", 3013}, ok = hz:tls(true),
{"testnet.gajumaru.io", 3013}]), ok = hz:chain_nodes(hz_nodes()),
ok = io:format("Hello, World! Args: ~tp~n", [ArgV]), ok = io:format("Hello, World! Args: ~tp~n", [ArgV]),
ok = io:format("hz status: ~tp~n", [hz:status()]),
ok = io:format("rbx_tuples: ~tp~n", [rbx_tuples()]),
ok = io:format("my akstr:~n~ts~n~n", [dummy_akstr()]),
zx:silent_stop(). zx:silent_stop().
dummy_seed() ->
crypto:hash(sha3_512, <<"p@ssw0rd">>).
dummy_keypair() ->
ecu_eddsa:sign_seed_keypair(dummy_seed()).
% bytes32
dummy_pubkey32() ->
maps:get(public, dummy_keypair()).
dummy_akstr() ->
unicode:characters_to_list(gmser_api_encoder:encode(account_pubkey, dummy_pubkey32())).
hz_nodes() ->
[ {"tsuriai.jp", 4013}
%, {"testnet.gajumaru.io", 4013}
].
rbx_tuples() ->
NoiseStr = "Noise_NK_25519_ChaChaPoly_BLAKE2b",
ServicePubkey =
<<116, 159, 91, 248, 138, 250, 73, 40, 231, 50,
81, 110, 137, 163, 44, 76, 48, 130, 225, 95,
168, 121, 93, 44, 148, 42, 180, 103, 11, 40,
168, 96>>
,
NoisePrologue = <<>>,
[{"127.0.0.1", 6969, "tcp", NoiseStr, ServicePubkey, <<>>}].
+5 -1
View File
@@ -6,7 +6,11 @@
{prefix,none}. {prefix,none}.
{desc,[]}. {desc,[]}.
{package_id,{"otpr","rq",{0,1,0}}}. {package_id,{"otpr","rq",{0,1,0}}}.
{deps,[{"otpr","hakuzaru",{0,9,1}}]}. {deps,[{"otpr","base58",{0,1,1}},
{"otpr","eblake2",{1,0,1}},
{"otpr","gmserialization",{0,1,3}},
{"otpr","ec_utils",{1,0,0}},
{"otpr","hakuzaru",{0,9,1}}]}.
{key_name,none}. {key_name,none}.
{a_email,[]}. {a_email,[]}.
{c_email,[]}. {c_email,[]}.
+19
View File
@@ -0,0 +1,19 @@
-module(duml).
-export([shuffle/1]).
shuffle([]) ->
[];
shuffle([X]) ->
[X];
shuffle(Items) ->
N = rand:uniform(length(Items)),
{Nth, Rest} = inverse_nth(N, Items),
[Nth | shuffle(Rest)].
inverse_nth(N, Items) ->
inverse_nth([], N, Items).
inverse_nth(Stk, 1, [X | Rest]) ->
{X, lists:reverse(Stk, Rest)};
inverse_nth(Stk, N, [X | Rest]) when N > 1 ->
inverse_nth([X | Stk], N-1, Rest).
+57 -4
View File
@@ -31,15 +31,17 @@ main([PortNum]) ->
p_init(list_to_integer(PortNum)). p_init(list_to_integer(PortNum)).
% static keypair is static, ephemeral is ephemeral
noise_options() -> noise_options() ->
% totally safe crypto
Secret = crypto:hash(sha3_256, <<"alice">>), Secret = crypto:hash(sha3_256, <<"alice">>),
Public = <<116, 159, 91, 248, 138, 250, 73, 40, 231, 50, 81, 110, Public = <<116, 159, 91, 248, 138, 250, 73, 40, 231, 50, 81, 110,
137, 163, 44, 76, 48, 130, 225, 95, 168, 121, 93, 44, 137, 163, 44, 76, 48, 130, 225, 95, 168, 121, 93, 44,
148, 42, 180, 103, 11, 40, 168, 96>>, 148, 42, 180, 103, 11, 40, 168, 96>>,
KP = enoise_keypair:new(dh25519, Secret, Public), SKP = enoise_keypair:new(dh25519, Secret, Public),
[{noise, "Noise_NN_25519_ChaChaPoly_BLAKE2b"}, EKP = enoise_keypair:new(dh25519),
{s, KP}]. [{noise, "Noise_NK_25519_ChaChaPoly_BLAKE2b"},
{s, SKP},
{e, EKP}].
% pimp process startup % pimp process startup
@@ -209,6 +211,9 @@ h_send(Name, NSock, Msg) ->
init_ho_names() -> init_ho_names() ->
shuffle(plain_ho_names()).
plain_ho_names() ->
["Crystal", "Tiffany", "Amber", "Brandy", "Lola", "Angel", ["Crystal", "Tiffany", "Amber", "Brandy", "Lola", "Angel",
"Ginger", "Candy", "Charity", "Anastasia", "Cherry", "Kitty", "Ginger", "Candy", "Charity", "Anastasia", "Cherry", "Kitty",
"Jade", "Destiny", "Devon", "Chastity", "Raven", "Scarlett", "Jade", "Destiny", "Devon", "Chastity", "Raven", "Scarlett",
@@ -221,3 +226,51 @@ init_ho_names() ->
recycle([N | Ns]) -> recycle([N | Ns]) ->
{N, Ns ++ [N]}. {N, Ns ++ [N]}.
%% @private
%% naive shuffle because we aren't cool enough to have
%% `rand:shuffle/1' yet`()'
%%
%% for list of length `N', there there are `N!' permutations
%%
%% ```
%% [<N options>, <N-1 options>, ..., <2 options>, <1 options>]
%% '''
%%
%% so we simply do the stupid
%%
%% conceptually: pick a sequence of integers at random
%%
%% ```
%% [(1..N), (1..N-1), (1..N-2), ... (1..2), 1]
%% '''
%%
%% which determines a permuation of the list
shuffle([]) ->
[];
shuffle([X]) ->
[X];
shuffle(Items) ->
N = rand:uniform(length(Items)),
{Nth, Rest} = inverse_nth(N, Items),
[Nth | shuffle(Rest)].
inverse_nth(N, Items) ->
inverse_nth([], N, Items).
inverse_nth(Stk, 1, [X | Rest]) ->
{X, lists:reverse(Stk, Rest)};
inverse_nth(Stk, N, [X | Rest]) when N > 1 ->
inverse_nth([X | Stk], N-1, Rest).
%% haven't thought about this, but faster because doesn't involve any
%% lists:reverse calls
% fshuf([]) -> [];
% fshuf([X]) -> [X];
% fshuf(Items) -> [X];
% N = rand:uniform(length(Items)),
% fshuf_ii(N, Items)
% shuffle(Items) ->
+1 -1
View File
@@ -5,7 +5,7 @@ pubkey:
rbx_tuple = rbx_tuple =
<<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>> <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>
[{"127.0.0.1", 6969, "tcp", "Noise_NN_25519_ChaChaPoly_BLAKE2b", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}] [{"127.0.0.1", 6969, "tcp", "Noise_NK_25519_ChaChaPoly_BLAKE2b", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}]
{"127.0.0.1", 6970, "tcp", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}, {"127.0.0.1", 6970, "tcp", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>},
{"127.0.0.1", 6971, "tcp", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}] {"127.0.0.1", 6971, "tcp", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}]