anchor.diff:  -endif.
   
   %% api
  --export([start_link/1,
  -         start_link/2,
  +-export([start_link/2,
            stop/1]).
   
   %% callbacks
  
positive.code: -ifdef(TEST).
  -spec start_test() -> term().
  start_test() ->
      {ok, _} = ?MODULE:start_link(?SWIRL_PORT).
  -endif.
  
negative.code: %% api
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% @doc start the server with a port number, and ppspp options which includes
  %% the root hash and chunk addressing specification. These are required during
  %% subsequent packet parsing, even if the peer supports multiple swarms.
  %% If start_link/2 is called with a root hash, the default ppspp options are
  %% assumed.
  -spec start_link(inet:port_number(), ppspp_options:options()) ->
      ignore | {error,_} | {ok,pid()}.
  start_link(Port, Swarm_Options) when is_integer(Port) ->
      Registration = {via, gproc, {n, l, {?MODULE, Port}}},
      gen_server:start_link(Registration, ?MODULE,
                            [Port, Swarm_Options], []).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% @doc Stops the server.
  
  -spec stop(inet:port_number()) -> ok.
  stop(Port) ->
      gen_server:call(gproc:lookup_local_name({?MODULE, Port}), stop).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% callbacks
  
  -spec init(nonempty_string()) -> {ok,[state(), ...]}.
  init([Port, Swarm_Options]) ->
      process_flag(trap_exit, true),
      {ok, Socket} = gen_udp:open(Port,  [binary,
                                          {reuseaddr, true},
                                          {active, true} ]),
      ?INFO("peer: ~p listening on udp:~p~n  options: ~p~n",
            [self(), Port, Swarm_Options]),
      {ok, [#state{port = Port, socket = Socket, options= Swarm_Options}] }.
  
  -spec handle_call(_,_,_) ->
      {stop,{error,{unknown_call,_}},_}.
  