Skip to content
Snippets Groups Projects
dap_client_pvt.h 3.52 KiB
/*
 * Authors:
 * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
 * DeM Labs Inc.   https://demlabs.net
 * Kelvin Project https://github.com/kelvinblockchain
 * Copyright  (c) 2017-2019
 * All rights reserved.

 This file is part of DAP (Deus Applications Prototypes) the open source project

    DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DAP is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include <stdbool.h>
#include <stdint.h>
#include "dap_client.h"
#include "dap_stream.h"
#include "dap_events_socket.h"
typedef struct dap_enc_key dap_enc_key_t;
typedef struct dap_http_client dap_http_client_t;

typedef struct dap_client_internal
{
    dap_client_t * client;

    dap_http_client_t * http_client;

    dap_events_socket_t * stream_es;
    int stream_socket;
    dap_stream_session_t * stream_session;
    dap_stream_t* stream;
    dap_events_t * events;

    dap_enc_key_t * session_key_open; // Open assymetric keys exchange
    dap_enc_key_t * session_key; // Symmetric private key for session encryption
    dap_enc_key_t * stream_key; // Stream private key for stream encryption
    char stream_id[25];


    char  * session_key_id;


    char * last_parsed_node;
    char  * uplink_addr;
    char * active_channels;
    uint16_t uplink_port;
    uint32_t uplink_protocol_version;


    dap_client_stage_t stage_target;
    dap_client_callback_t stage_target_done_callback;

    dap_client_stage_t stage;
    dap_client_stage_status_t stage_status;
    dap_client_error_t last_error;

    dap_client_callback_t stage_status_callback;
    dap_client_callback_t stage_status_done_callback;
    dap_client_callback_t stage_status_error_callback;

    bool is_encrypted;
    bool is_close_session;// the last request in session, in the header will be added "SessionCloseAfterRequest: true"
    dap_client_callback_data_size_t request_response_callback;
    dap_client_callback_int_t request_error_callback;
} dap_client_pvt_t;

#define DAP_CLIENT_PVT(a) ((dap_client_pvt_t*) a->_internal )

int dap_client_pvt_init();
void dap_client_pvt_deinit();

void dap_client_pvt_stage_transaction_begin(dap_client_pvt_t * dap_client_pvt_t, dap_client_stage_t a_stage_next,
                                                 dap_client_callback_t a_done_callback);

void dap_client_pvt_request(dap_client_pvt_t * a_client_internal, const char * a_path, void * a_request,
                    size_t a_request_size,  dap_client_callback_data_size_t a_response_proc, dap_client_callback_int_t a_response_error);

void dap_client_pvt_request_enc(dap_client_pvt_t * a_client_internal, const char * a_path, const char * a_sub_url,
                                     const char * a_query, void * a_request, size_t a_request_size,
                                dap_client_callback_data_size_t a_response_proc,
                                     dap_client_callback_int_t a_error_proc);

void dap_client_pvt_new(dap_client_pvt_t * a_client_internal);
void dap_client_pvt_delete(dap_client_pvt_t * a_client_pvts);