Module ppspp_datagram

Library for PPSPP over UDP, aka Swift protocol.

Description

This module implements a library of functions necessary to handle the wire-protocol of PPSPP over UDP, including functions for encoding and decoding datagrams.

Data Types

datagram()

abstract datatype: datagram()

endpoint()

abstract datatype: endpoint()

uri()


uri() = string()

Function Index

get_endpoint/1get endpoint from datagram.
get_messages/1get messages from datagram.
get_peer_channel/1
get_peer_uri/1given an endpoint, returns the associated data e.g.
get_swarm_options/1Requested Swarm options should match Available swarm options.
handle_datagram/2Handle a fully unpacked datagram.
handle_packet/1receives datagram from peer_worker, parses and delivers to matching channel.
pack/1
unpack/3unpack a UDP packet into a PPSPP datagram using erlang term format A single datagram MAY contain multiple PPSPP messages; these will be handled recursively as needed.

Function Details

get_endpoint/1


get_endpoint(X1 :: datagram()) -> endpoint()

get endpoint from datagram

get_messages/1


get_messages(X1 :: datagram()) -> ppspp_message:messages()

get messages from datagram

get_peer_channel/1


get_peer_channel(Peer :: endpoint()) -> ppspp_channel:channel()

get_peer_uri/1


get_peer_uri(Peer :: endpoint()) -> uri()

given an endpoint, returns the associated data e.g. uri or channel

get_swarm_options/1


get_swarm_options(Datagram :: datagram()) ->ppspp_options:options()

Requested Swarm options should match Available swarm options

handle_datagram/2


handle_datagram(Datagram :: datagram(),Swarm_Options :: ppspp_options:options()) ->ok

Handle a fully unpacked datagram. Each PPSPP datagram is complete in itself - relies only on the swarm state for deciding what responses are needed. This handle function should be called from a separate channel_worker process.

handle_packet/1


handle_packet(X1 ::{udp,inet:socket(),inet:ip_address(),inet:port_number(),binary()}) ->ok

receives datagram from peer_worker, parses and delivers to matching channel. It’s usually called from a spawned process, so return values are eventually ignored.

pack/1


pack(Datagram :: datagram()) -> binary()

unpack/3


unpack(Raw_Datagram :: binary(),Endpoint :: endpoint(),Swarm_Options :: ppspp_options:options()) ->datagram()

unpack a UDP packet into a PPSPP datagram using erlang term format A single datagram MAY contain multiple PPSPP messages; these will be handled recursively as needed.