View Source Exrpc.MFALookup (exrpc v0.3.6)
Function allowlist and lookup table.
Unlike :rpc
, we don't transmit module and function names over the wire.
Each function is assigned a unique integer ID, and the client sends the ID based on this lookup table.
# Instantiate a new lookup table: iex> Exrpc.MFALookup.create([])
iex> {:ok, lookup} = Exrpc.MFALookup.create([{Greeter, :hello, 1}, {Greeter, :goodbye, 1}, {Adder, :add, 2}])
# Route to ID and vice-versa: iex> Exrpc.MFALookup.mfa_to_id(lookup, {Greeter, :hello, 1}) 0 iex> Exrpc.MFALookup.mfa_to_id(lookup, {Greeter, :goodbye, 1}) 1 iex> Exrpc.MFALookup.mfa_to_id(lookup, {Adder, :add, 2}) 2 iex> Exrpc.MFALookup.mfa_to_id(lookup, {Greeter, :howdy, 1}) nil iex> Exrpc.MFALookup.id_to_mfa(lookup, 0) {Greeter, :hello, 1} iex> Exrpc.MFALookup.id_to_mfa(lookup, 1) {Greeter, :goodbye, 1} iex> Exrpc.MFALookup.id_to_mfa(lookup, 2) {Adder, :add, 2} iex> Exrpc.MFALookup.id_to_mfa(lookup, 3) nil # Convert lookup table to list (for transmitting to clients): iex> Exrpc.MFALookup.to_list(lookup) [{Greeter, :hello, 1}, {Greeter, :goodbye, 1}, {Adder, :add, 2}]