barrel_p2p_dist_protocol (barrel_p2p v0.1.0)

View Source

Summary

Functions

Decode an authentication message The HELLO node name is returned as a *validated binary*, not an atom. Atomising peer-controlled bytes here would let an unauthenticated peer flood the (never-GC'd) atom table; the caller mints the atom only after the Ed25519 signature is verified. See barrel_p2p_dist_auth_stream.

Encode AUTH_CHALLENGE message Format: <<Type:8, Nonce:32/binary, Timestamp:64/big>>

Encode AUTH_FAIL message Format: <<Type:8, ReasonLen:16/big, Reason/binary>>

Encode AUTH_HELLO message Format: <<Type:8, Version:8, NodeNameLen:16/big, NodeName/binary, PubKey:32/binary>>

Encode AUTH_OK message Format: <<Type:8>>

Encode AUTH_RESPONSE message Format: <<Type:8, Signature:64/binary>>

Validate a node name binary. Returns ok if the bytes form a well-shaped name@host atom by Erlang dist conventions.

Functions

decode(_)

-spec decode(binary()) ->
                {hello, binary(), binary()} |
                {challenge, binary(), integer()} |
                {response, binary()} |
                ok |
                {fail, binary()} |
                {error, term()}.

Decode an authentication message The HELLO node name is returned as a *validated binary*, not an atom. Atomising peer-controlled bytes here would let an unauthenticated peer flood the (never-GC'd) atom table; the caller mints the atom only after the Ed25519 signature is verified. See barrel_p2p_dist_auth_stream.

encode_challenge(Nonce, Timestamp)

-spec encode_challenge(binary(), integer()) -> binary().

Encode AUTH_CHALLENGE message Format: <<Type:8, Nonce:32/binary, Timestamp:64/big>>

encode_fail(Reason)

-spec encode_fail(binary()) -> binary().

Encode AUTH_FAIL message Format: <<Type:8, ReasonLen:16/big, Reason/binary>>

encode_hello(NodeName, PubKey)

-spec encode_hello(node(), binary()) -> binary().

Encode AUTH_HELLO message Format: <<Type:8, Version:8, NodeNameLen:16/big, NodeName/binary, PubKey:32/binary>>

encode_ok()

-spec encode_ok() -> binary().

Encode AUTH_OK message Format: <<Type:8>>

encode_response(Signature)

-spec encode_response(binary()) -> binary().

Encode AUTH_RESPONSE message Format: <<Type:8, Signature:64/binary>>

validate_node_name(Bin)

-spec validate_node_name(binary()) -> ok | {error, invalid_node_name}.

Validate a node name binary. Returns ok if the bytes form a well-shaped name@host atom by Erlang dist conventions.