Module channel_worker

A managed PPSPP Channel that represents a remote PPSPP Peer.

Behaviours: gen_server.

Description

The state for a specific channel includes the associated remote peer, the swarm, and the channel itself. Within swirl, these three are bound together as a unique value, and the channel ID as the key. The channel_worker provides registration and lookups to allow a given peer_worker to route messages for a specific remote peer to it, given only the correct channel_id. This functionality is used extensively by other modules to decode, process, encode, and send PPSPP datagrams over the wire.

Function Index

code_change/3Default gen_server API.
handle/2Post message into the mailbox.
handle_call/3Default gen_server API.
handle_cast/2Default gen_server API.
handle_info/2Default gen_server API.
init/1As the channel id is not known at time of process spawning, it is done during init phase, using gproc.
start/2start a PPSPP channel, using the supplied peer info.
start_link/2Start the channel using provided peer info, typically a udp endpoint.
stop/1Stops the server, given a channel.
terminate/2Default gen_server API.
where_is/1Looks up the pid for a given channel.

Function Details

code_change/3

code_change(OldVsn, State, Extra) -> any()

Default gen_server API.

handle/2


handle(Pid :: pid(), Message :: any()) -> ok

Post message into the mailbox. All PPSPP messages arrive through here, and then are re-dispatched back into their respective ppspp_<message_type>.erl modules to be processed.

handle_call/3

handle_call(Request, From, State) -> any()

Default gen_server API.

handle_cast/2

handle_cast(Msg, State) -> any()

Default gen_server API.

handle_info/2

handle_info(Info, State) -> any()

Default gen_server API.

init/1


init(Swarm_id :: ppspp_options:swarm_id()) ->{ok, ppspp_channel:channel()}

As the channel id is not known at time of process spawning, it is done during init phase, using gproc. The following values are registered:


  {{peer, Peer URI}, Peer}
  {{channel, Channel id}, Swarm ID}

Peer is the opaque data type used in the datagram module that uniquely identifies a remote peer. TODO change registration of peers to allow multiplexed peers per remote address, and therefore multiple swarms on the same IP. TODO enable updating the registration of the URI to match the acquired channel that will accommodate all future datagrams from this peer.

start/2


start(Peer_endpoint :: ppspp_datagram:endpoint(),Swarm_options :: ppspp_options:options()) ->{ok, pid()} | {error, term()}

start a PPSPP channel, using the supplied peer info.


start_link(Peer :: ppspp_datagram:endpoint(),Swarm_id :: ppspp_options:swarm_id()) ->ignore | {error, term()} | {ok, pid()}

Start the channel using provided peer info, typically a udp endpoint. For channel 0, i.e. the initial handshake contact from a remote peer. We effectively block any re-registration by registering this name, until the first received registration completes successfully.

stop/1


stop(Channel :: ppspp_channel:channel()) -> ok | {error, any()}

Stops the server, given a channel.

terminate/2

terminate(Reason, State) -> any()

Default gen_server API.

where_is/1


where_is(Channel :: ppspp_channel:channel()) ->{ok, pid()} | {error, term()}

Looks up the pid for a given channel.