anchor.diff:    LD.
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  -%% gen_serv callbacks
  +%% gen_server callbacks
   
  +%% boilerplate
  +terminate(_Reason,_State) ->
  +  ok.
  +
  +code_change(_OldVsn,State,_Extra) ->
  +  {ok,State}.
  +
  +handle_cast(_What,State) ->
  +  {noreply,State}.
  +
  +%% not boilerplate
   -record(ld,{port,
               acceptor,
               udp_socket,
  
positive.code:             msg=orddict:new(),
              secret}).
  
  rec_info(ld) -> record_info(fields,ld);
  rec_info(_)  -> [].
  
  init([]) ->
    #ld{}.
  
  handle_call({config,{port,Port}},_,LD) ->
    {[],LD#ld{acceptor=accept(Port),udp_socket=udp_open(Port)}};
  
  handle_call({config,{secret,Secret}},_,LD) ->
    {[],LD#ld{secret=Secret}};
  
  handle_call(get_data,_,LD) ->
    {LD#ld.msg,LD#ld{msg=orddict:new()}}.
  
  handle_info({new_socket,Sock},LD) ->
    %% we accepted a socket towards a producer.
    LD#ld{tcp_sockets=[Sock|LD#ld.tcp_sockets]};
  handle_info({tcp,Sock,Bin},LD) ->
    case lists:member(Sock,LD#ld.tcp_sockets) of
      true ->
        %% got data from a known socket. this is good
        decrypt(Bin,LD);
      false->
        %% got data from unknown socket. wtf?
        ?log([{data_from,Sock},{bytes,byte_size(Bin)}]),
        LD
    end;
  handle_info({tcp_closed, Sock},LD) ->
    case lists:member(Sock,LD#ld.tcp_sockets) of
      true ->
        LD#ld{tcp_sockets=LD#ld.tcp_sockets--[Sock]};
      false ->
        ?log([{unknown_socket_exited,Sock}]),
        LD
    end;
  handle_info({tcp_error, Sock, Reason},LD) ->
    ?log([{tcp_error,Reason},{socket,Sock}]),
    LD;
  handle_info({udp,Socket,_IP,_Port,Bin},LD) ->
    case Socket == LD#ld.udp_socket of
      true ->
        inet:setopts(Socket,[{active,once}]),
        decrypt(Bin,LD);
      false ->
        %% got data from unknown socket. wtf?
        ?log([{unknown_socket,Socket},{bytes,byte_size(Bin)}]),
        LD
    end;
  handle_info(Msg,LD) ->
    ?log([{unrec,Msg}]),
    LD.
  
  decrypt(Bin,LD) ->
    case LD#ld.secret of
  
negative.code: %% prf callbacks, runs in the prfTarg process
  
  collect(init) ->
    gen_server:start_link({local,?MODULE},?MODULE,[],[]),
    {[],{?MODULE,[]}};
  collect(LD) ->
    {LD,{?MODULE,gen_server:call(?MODULE,get_data)}}.
  