anchor.diff:  
   %% ------------------------------------------------------------------
   
  -service_control_channel_request(_, State) ->
  -	State.
  -%service_control_channel_request(#request{login = Login} = Request, State) when is_record(Login, login) ->
  -%	?info("starting authentication"),
  -%	% TODO actually ask an authentication system if they should be let in.
  -%	#request{id = ReqId} = Request,
  -%	#state{cookie = Cookie} = State,
  -%	%Cookie = lists:flatten(io_lib:format("~p", [erlang:make_ref()])),
  -%	#state{udp_socket = UdpSocket} = State,
  -%	{ok, UdpPort} = inet:port(UdpSocket),
  -%	LoginRep = #loginreply{
  -%		cookie = Cookie,
  -%		udp_port = UdpPort,
  -%		tcp_port = 6007,
  -%		channels = [#channel{channel_name = "control", connection_type = 'SSL'}]
  -%	},
  -%	Response = #response{
  -%		inresponseto = ReqId,
  -%		confirm = true,
  -%		login = LoginRep
  -%	},
  -%	OutBin = wrap_for_send("control", Response),
  -%	SendRes = ssl:send(State#state.ssl_socket, OutBin),
  -%	?debug("authentiation ssl:send result:  ~p", [SendRes]),
  -%	State#state{cookie = Cookie, tcp_socket = Cookie,
  -%		udp_remote_info = undefined
  -%	}.
  -
  -wrap_for_send(Channel, Recthing) ->
  -	Base = #envelope{channel = Channel},
  -	OutRec = Base,
  -%	OutRec = case Recthing of
  -%		X when is_record(X, response) ->
  -%			Base#envelope{response = X};
  -%		X when is_record(X, request) ->
  -%			Base#envelope{request = X};
  -%		X when is_record(X, event) ->
  -%			Base#envelope{event = X}
  -%	end,
  -	netstring:encode(encode_envelope(OutRec)).
  -
  -%% ------------------------------------------------------------------
  -
  -encode_envelope(_) ->
  -	<<>>.
  -
  -decode_envelope(_) ->
  -	#envelope{}.
  +service_control_channel_request(Id, <<"login">>, {struct, Props}, State) ->
  +	?info("starting authentication"),
  +	% TODO actually ask an authentication system if they should be let in.
  +	#state{cookie = Cookie} = State,
  +	#state{udp_socket = UdpSocket} = State,
  +	{ok, UdpPort} = inet:port(UdpSocket),
  +	LoginRep = {struct, [
  +		{cookie, Cookie},
  +		{udp_port, UdpPort},
  +		{tcp_port, 6007},
  +		{channels = [{struct, [{channel_name, <<"control">>},
  +			{connection_type, 'SSL'}]}]}
  +	]},
  +	Response = #envelope{id = Id, type = response, contents = LoginRep, 
  +		channel = <<"control">>},
  +	OutBin = wrap_for_send(Response),
  +	SendRes = ssl:send(State#state.ssl_socket, OutBin),
  +	?debug("authentiation ssl:send result:  ~p", [SendRes]),
  +	State#state{cookie = Cookie, tcp_socket = Cookie,
  +		udp_remote_info = undefined
  +	}.
  +
  +wrap_for_send(Recthing) ->
  +	Json = envelope_to_json(Recthing),
  +	JsonEnc = mochijson2:encode(Json),
  +	Binary = list_to_binary(lists:flatten(JsonEnc)),
  +	netstring:encode(Binary).
  +
  +%% ------------------------------------------------------------------
  +
  +envelope_to_json(Envelope) ->
  +	Props = [{<<"type">>, Envelope#envelope.type},
  +		{<<"channel">>, Envelope#envelope.channel},
  +		{<<"contents">>, Envelope#envelope.contents}
  +	],
  +	case Envelope#envelope.id of
  +		undefined -> {struct, Props};
  +		Id -> {struct, [{<<"id">>, Id} | Props]}
  +	end.
  +
  +json_to_envelope(Json) when is_binary(Json) ->
  +	json_to_envelope(mochijson2:decode(Json));
  +
  +json_to_envelope({struct, Props}) ->
  +	Type = proplists:get_value(<<"type">>, Props, <<>>),
  +	Type0 = check_envelope_type(Type),
  +	Id = proplists:get_value(<<"id">>, Props),
  +	Content = proplists:get_value(<<"contents">>, Props),
  +	Channel = proplists:get_value(<<"channel">>, Props),
  +	#envelope{type = Type0, id = Id, contents = Content, channel = Channel}.
  +
  +check_envelope_type(<<"request">>) -> request;
  +check_envelope_type(<<"response">>) -> response;
  +check_envelope_type(<<"event">>) -> event.
   
   %% ------------------------------------------------------------------
   %% Tests
  
positive.code: -type(message_id() :: 'undefined' | binary()).
  -type(json() :: integer() | float() | binary() | {struct, [{binary(), json()}]} | [json()]).
  -record(envelope, {type :: message_type(), id :: message_id(),
  	channel :: binary(), content :: json()}).
  
  %% ------------------------------------------------------------------
  %% API Function Exports
  
negative.code: %% ------------------------------------------------------------------
  
  service_request(Binary, State) when is_binary(Binary) ->
  	Json = mochijson2:decode(Binary),
  	Rec = json_to_envelope(Json),
  	service_request(Rec, State);
  
  service_request(#envelope{channel = "control"} = Envelope, State) ->
  