View Source Exrpc.MFALookup (exrpc v0.4.0)
Function allowlist and lookup table.
Each functions exposed to clients is assigned a unique integer ID, This allows the server to enforce a function allowlist and the client can make RPC call by transmitting function ID instead of module and function atoms.
Internal details: the lookup table is a tuple of two ETS tables, {mfa2id, id2mfa}
, both of which are owned by the pid that created the table. The first table maps MFAs to IDs, the second table vice versa.
Example
iex> {:ok, lookup} = Exrpc.MFALookup.create([
...> {Greeter, :hello, 1},
...> {Greeter, :goodbye, 1}
...> ])
iex> Exrpc.MFALookup.mfa_to_id(lookup, {Greeter, :hello, 1})
0
iex> Exrpc.MFALookup.id_to_mfa(lookup, 0)
{Greeter, :hello, 1}
Summary
Functions
Create a lookup table from a list of MFAs.
Get MFA by ID.
Get the ID of an MFA.
Get a list of MFAs.
Types
Functions
Create a lookup table from a list of MFAs.
Examples
iex> Exrpc.MFALookup.create([])
{:error, :empty_list}
iex> {:ok, {_mfa2id, _id2mfa}} = Exrpc.MFALookup.create([
...> {Greeter, :hello, 1},
...> {Greeter, :goodbye, 1}
...> ])
Get MFA by ID.
Examples
iex> {:ok, lookup} = Exrpc.MFALookup.create([
...> {Greeter, :hello, 1},
...> {Greeter, :goodbye, 1}
...> ])
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)
nil
Get the ID of an MFA.
Examples
iex> {:ok, lookup} = Exrpc.MFALookup.create([
...> {Greeter, :hello, 1},
...> {Greeter, :goodbye, 1}
...> ])
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, {Greeter, :heyyyy, 1})
nil
Get a list of MFAs.
Examples
iex> {:ok, lookup} = Exrpc.MFALookup.create([
...> {Greeter, :hello, 1},
...> {Greeter, :goodbye, 1}
...> ])
iex> Exrpc.MFALookup.to_list(lookup)
[{Greeter, :hello, 1}, {Greeter, :goodbye, 1}]