Module swarm_worker

A managed PPSPP Swarm server.

Behaviours: gen_server.

Description

This modules implements a PPSPP swarm server, including registering the unique swarm_id and associated PPPSPP options, and provides lookup services to locate the swarm_worker, and retrieve configuration such as swarm options.

Data Types

state()


state() = {ppspp_options:swarm_id(), ppspp_options:options()}

Function Index

code_change/3Default gen_server API.
get_swarm_options/1Given a swarm id, either as string or binary, returns the associated PPSPP options from the gproc registry.
handle_call/3Default gen_server API.
handle_cast/2Default gen_server API.
handle_info/2Default gen_server API.
init/1Starts a swarm_worker with given swarm id and PPSPP options.
start_link/1Start the server with a given set of PPSPP options that must include the swarm's root hash.
stop/1Stops the server.
terminate/2Closes down the swarm_worker.
where_is/1Looks up the pid for a given swarm id.

Function Details

code_change/3


code_change(OldVsn :: term(), State :: state(), Extra :: term()) ->{ok, state()}

Default gen_server API.

get_swarm_options/1


get_swarm_options(Swarm_id :: ppspp_options:swarm_id()) ->{ok, ppspp_options:options()} |{error, any()}

Given a swarm id, either as string or binary, returns the associated PPSPP options from the gproc registry.

handle_call/3


handle_call(Message :: any(),From :: {pid(), any()},State :: state()) ->{reply, ok, state()}

Default gen_server API.

handle_cast/2


handle_cast(Message :: stop | any(), State :: state()) ->{noreply, state()}

Default gen_server API.

handle_info/2


handle_info(Message :: term(), State :: state()) ->{noreply, state()} |{stop, {error, {unknown_info, term()}}, term()}

Default gen_server API.

init/1


init(X1 :: [ppspp_options:swarm_id() | ppspp_options:options()]) ->{ok, state()}

Starts a swarm_worker with given swarm id and PPSPP options.


start_link(Swarm_Options :: ppspp_options:options()) ->ignore | {error, term()} | {ok, pid()}

Start the server with a given set of PPSPP options that must include the swarm’s root hash.

stop/1


stop(Swarm_id :: ppspp_options:swarm_id()) -> ok | {error, any()}

Stops the server.

terminate/2


terminate(Reason :: term(), State :: state()) -> ok

Closes down the swarm_worker. Returns reason and brief statistics.

where_is/1


where_is(Swarm_id :: ppspp_options:swarm_id()) ->{ok, pid()} | {error, term()}

Looks up the pid for a given swarm id.