2018-05-30 15:19:13 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/util: dnsresolver.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
2018-11-11 14:42:48 -05:00
|
|
|
* Copyright (C) 2017 Retroshare Team <retroshare.project@gmail.com> *
|
2018-05-30 15:19:13 -04:00
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2011-01-24 17:05:10 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "pqi/pqinetwork.h"
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include "util/rsthreads.h"
|
|
|
|
|
|
|
|
struct sockaddr ;
|
|
|
|
|
|
|
|
class DNSResolver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DNSResolver() ;
|
|
|
|
~DNSResolver() ;
|
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
bool getIPAddressFromString(const std::string& server_name,struct sockaddr_storage &addr) ;
|
2011-01-24 17:05:10 -05:00
|
|
|
|
|
|
|
void start_request() ;
|
|
|
|
void reset() ;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum { DNS_DONT_HAVE,DNS_SEARCHING, DNS_HAVE, DNS_LOOKUP_ERROR } ;
|
|
|
|
|
|
|
|
struct AddrInfo
|
|
|
|
{
|
|
|
|
uint32_t state ; // state: Looked-up, not found, have
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t last_lookup_time ; // last lookup time
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage addr ;
|
2011-01-24 17:05:10 -05:00
|
|
|
};
|
|
|
|
friend void *solveDNSEntries(void *p) ;
|
|
|
|
|
|
|
|
RsMutex _rdnsMtx ;
|
|
|
|
bool *_thread_running ;
|
|
|
|
std::map<std::string, AddrInfo> *_addr_map ;
|
|
|
|
};
|