2018-07-16 12:48:04 +00:00
|
|
|
#ifndef LIBLLARP_DNSC_HPP
|
|
|
|
#define LIBLLARP_DNSC_HPP
|
|
|
|
|
2018-07-25 00:35:11 +00:00
|
|
|
#include <llarp/ev.h> // for sockaadr
|
|
|
|
#include "dns.hpp" // get protocol structs
|
2018-07-22 03:34:28 +00:00
|
|
|
|
|
|
|
// internal, non-public functions
|
|
|
|
// well dnsc init/stop are public...
|
|
|
|
|
|
|
|
struct dnsc_answer_request;
|
|
|
|
|
2018-08-01 09:04:40 +00:00
|
|
|
/// hook function to handle an dns client request
|
2018-07-22 03:34:28 +00:00
|
|
|
// should we pass by llarp::Addr
|
|
|
|
// not as long as we're supporting raw
|
|
|
|
typedef void (*dnsc_answer_hook_func)(dnsc_answer_request *request);
|
|
|
|
|
2018-08-01 09:04:40 +00:00
|
|
|
/// struct for dns client requests
|
2018-07-22 03:34:28 +00:00
|
|
|
struct dnsc_answer_request
|
|
|
|
{
|
|
|
|
/// sock type
|
|
|
|
void *sock; // pts to udp...
|
|
|
|
/// customizable (used for hook (outer request))
|
|
|
|
void *user;
|
|
|
|
/// storage
|
|
|
|
dns_msg_question question;
|
|
|
|
/// hook
|
|
|
|
dnsc_answer_hook_func resolved;
|
|
|
|
/// result
|
|
|
|
bool found;
|
|
|
|
struct sockaddr result;
|
|
|
|
// a reference to dnsc_context incase of multiple contexts
|
|
|
|
struct dnsc_context *context;
|
|
|
|
};
|
|
|
|
|
2018-08-01 09:04:40 +00:00
|
|
|
/// event handler for processing DNS responses
|
2018-07-22 03:34:28 +00:00
|
|
|
void
|
|
|
|
llarp_handle_dnsc_recvfrom(struct llarp_udp_io *udp,
|
|
|
|
const struct sockaddr *saddr, const void *buf,
|
|
|
|
ssize_t sz);
|
|
|
|
|
2018-08-01 09:04:40 +00:00
|
|
|
/// generic handler for processing DNS responses
|
2018-07-22 03:34:28 +00:00
|
|
|
void
|
|
|
|
raw_handle_recvfrom(int *sockfd, const struct sockaddr *saddr, const void *buf,
|
|
|
|
ssize_t sz);
|
|
|
|
|
2018-08-01 09:04:40 +00:00
|
|
|
/// DNS client context (one needed per upstream DNS server)
|
2018-07-22 03:34:28 +00:00
|
|
|
struct dnsc_context
|
|
|
|
{
|
|
|
|
/// Target: DNS server hostname/port to use
|
2018-08-02 12:51:49 +00:00
|
|
|
// FIXME: ipv6 it & make it a vector
|
2018-07-22 03:34:28 +00:00
|
|
|
sockaddr *server;
|
2018-08-01 09:04:40 +00:00
|
|
|
/// tracker
|
|
|
|
struct dns_tracker *tracker;
|
|
|
|
/// sock type
|
|
|
|
void *sock;
|
2018-07-22 03:34:28 +00:00
|
|
|
// where to create the new sockets
|
|
|
|
struct llarp_udp_io *udp;
|
|
|
|
};
|
|
|
|
|
2018-08-01 09:04:40 +00:00
|
|
|
/// async resolve a hostname using generic socks
|
|
|
|
void
|
|
|
|
raw_resolve_host(struct dnsc_context *dnsc, const char *url,
|
2018-08-08 12:40:54 +00:00
|
|
|
dnsc_answer_hook_func resolved, void *user);
|
2018-08-01 09:04:40 +00:00
|
|
|
|
|
|
|
/// async resolve a hostname using llarp platform framework
|
|
|
|
bool
|
|
|
|
llarp_resolve_host(struct dnsc_context *dns, const char *url,
|
|
|
|
dnsc_answer_hook_func resolved, void *user);
|
|
|
|
|
|
|
|
/// cleans up request structure allocations
|
|
|
|
void
|
|
|
|
llarp_host_resolved(dnsc_answer_request *request);
|
|
|
|
|
2018-07-22 03:34:28 +00:00
|
|
|
/// initialize dns subsystem and bind socket
|
|
|
|
/// returns true on bind success otherwise returns false
|
|
|
|
bool
|
|
|
|
llarp_dnsc_init(struct dnsc_context *dnsc, struct llarp_udp_io *udp,
|
|
|
|
const char *dnsc_hostname, uint16_t dnsc_port);
|
|
|
|
|
2018-08-01 09:04:40 +00:00
|
|
|
/// shutdowns any events, and deallocates for this context
|
2018-07-22 03:34:28 +00:00
|
|
|
bool
|
|
|
|
llarp_dnsc_stop(struct dnsc_context *dnsc);
|
2018-07-16 12:48:04 +00:00
|
|
|
|
|
|
|
#endif
|