anchor.diff:  %% @private
   -spec send_message(state(), message()) ->
       {ok, state()} | {error, Reason :: term()}.
  -send_message(State, #client_message{} = ClientMessage) ->
  -    send_client_message(State, ClientMessage);
  -send_message(State, #server_message{} = ServerMessage) ->
  -    send_server_message(State, ServerMessage).
  +send_message(#state{type = outgoing} = State, #client_message{} = Msg) ->
  +    send_client_message(State, Msg);
  +send_message(#state{type = incoming} = State, #server_message{} = Msg) ->
  +    send_server_message(State, Msg);
  +send_message(#state{type = ConnType}, Msg) ->
  +    ?warning("Attempt to send msg ~p via incorrect connection ~p", [
  +        Msg, ConnType
  +    ]),
  +    {error, sending_msg_via_wrong_connection}.
   
   
   %% @private
  
positive.code:             {stop, Reason, State}
      end;
  
  handle_info({Ok, Socket, Data}, State = #state{status = upgrading_protocol, ok = Ok}) ->
      case protocol_utils:verify_protocol_upgrade_response(Data) of
          false ->
              ?error("Received invalid protocol upgrade response: ~p", [Data]),
              {stop, normal, State};
          true ->
              {ok, MsgId} = message_id:generate(self()),
              {ok, Nonce} = authorization_nonce:create(),
              ClientMsg = #client_message{
                  message_id = MsgId,
                  message_body = #provider_handshake_request{
                      provider_id = oneprovider:get_id(),
                      nonce = Nonce
                  }
              },
              #state{socket = Socket, transport = Transport} = State,
              ok = Transport:setopts(Socket, [binary, {packet, ?PACKET_VALUE}]),
              case send_client_message(State, ClientMsg) of
                  {ok, State1} ->
                      State2 = State1#state{status = performing_handshake},
                      activate_socket_once(State2),
                      {noreply, State2, ?PROTO_CONNECTION_TIMEOUT};
                  {error, Reason} ->
                      {stop, Reason, State}
              end
      end;
  
  handle_info({Ok, Socket, Data}, #state{status = performing_handshake, socket = Socket, ok = Ok} = State) ->
  
negative.code:         ok ->
              {ok, State};
          {ok, ServerMsg} ->
              send_server_message(State, ServerMsg);
          {error, Reason} ->
              ?warning("Message ~p handling error: ~p", [Msg, Reason]),
              {ok, State}
  