anchor.diff:          _     -> verify_secret([null, null])
     end.
   
  -connect(#connect{session = Session, api_key = ApiKey}, State = #state{outbound_connection = OutboundConnection}) ->
  -  [Id, Secret] = verify_secret(Session),
  -
  -  IsValidKey = ctl_handler:lookup_priv(ApiKey),
  -  initialize_state(IsValidKey, Id, Secret,  State).
  -
   initialize_state(ApiKey = false, Id, _, State) ->
     gateway_error:no_valid_api_key(),
     State#state{sessionid = Id};
  
positive.code: 
  handle_cast({msg, RawData}, State) ->
    {ok, Struct} = gateway_util:decode(RawData),
    Record = gateway_messages:struct_to_record(Struct),
    {noreply, case Record of
      #send{} ->
        send(Record, State);
      #join_workerpool{} ->
        join_worker_pool(Record, State);
      #leave_workerpool{} ->
        leave_worker_pool(Record, State);
      #join_channel{} ->
        join_channel(Record, State);
      #get_channel{} ->
        get_channel(Record, State);
      #leave_channel{} ->
        leave_channel(Record, State);
      #connect{} ->
        connect(Record, State);
      #get_ops{} ->
        getops(Record, State);
      _ ->
        gen_server:cast(self(), {error, 221, ["Unrecognized Command"]}),
        State
    end};
  
  handle_cast({send, Data}, State = #state{outbound_connection = OutboundConnection = #gateway_connection{callback_module = Mod}, api_key = ApiKey}) ->
    case ctl_handler:update_metering(ApiKey) of
  
negative.code: call_callback(CBRef, Args, State) ->
    CBRef2 = gateway_reference:set_method(CBRef, <<"callback">>),
    invoke_rpc(CBRef2, Args, State).
  
  
  make_hookchannel_reference(ClientRef) ->
    SessionId = gateway_reference:get_destination_id(ClientRef),
    SystemRef = gateway_reference:client_reference(SessionId, <<"system">>),
  