enoise more or less just works

This commit is contained in:
Peter Harpending
2026-09-02 02:45:21 -07:00
parent e5436c2e3e
commit 17cca5ecfe
5 changed files with 50 additions and 101 deletions
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env escript
-mode(compile).
% john state
-record(js,
{tsock = none :: gen_tcp:socket(),
nsock = none :: enoise:noise_socket()}).
main([]) ->
TcpOpts = [binary, {packet, 0}, {active, once}],
{ok, TSock} = gen_tcp:connect("localhost", 6969, TcpOpts),
ok = inet:setopts(TSock, [{active, once}]),
{ok, NSock, _HandshakeState} = enoise:connect(TSock, noise_options()),
j_loop(#js{tsock = TSock, nsock = NSock}).
noise_options() ->
% totally safe crypto
KP = enoise_keypair:new(dh25519),
[{noise, "Noise_NN_25519_ChaChaPoly_BLAKE2b"},
{e, KP}].
j_loop(JS = #js{nsock = NSock}) ->
receive
{noise, NSock, Bytes} ->
ok = io:format("< ~tp~n", [Bytes]),
j_loop(JS);
Unknown ->
ok = io:format("~tp unknown message, killing self: ~tp~n",
[self(), Unknown]),
exit(normal)
end.