#pragma once
#include <event2/event.h>
#include <openssl/ssl.h>
#include <tfe_future.h>

struct keyring
{
	EVP_PKEY *key;
	X509 *cert;
	STACK_OF(X509) * chain;
};
struct key_keeper_stat
{
	long long ask_times;
	long long new_issue;
	long long cached_num;
};
struct key_keeper;

struct key_keeper * key_keeper_init(const char * profile, const char* section, void* logger);

void key_keeper_destroy(struct key_keeper *keeper);

struct keyring* key_keeper_release_keyring(future_result_t* result);

void key_keeper_free_keyring(struct keyring* cert);

struct evhttp_connection* key_keeper_evhttp_init(struct event_base * evbase, struct evdns_base* dnsbase, struct key_keeper * key_keeper_handler);

void key_keeper_async_ask(struct future * f, struct key_keeper * keeper, const char* sni, int keyring_id, 
	X509 * origin_cert, int is_cert_valid, struct event_base * evbase, struct evdns_base* dnsbase, struct evhttp_connection *evhttp);

void key_keeper_statistic(struct key_keeper *keeper, struct key_keeper_stat* result);

