2018-01-02 14:12:05 -03:00
|
|
|
// Copyright (c) 2009-2017 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 10:02:28 -04:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2013-04-13 02:13:08 -03:00
|
|
|
|
2012-01-03 19:33:31 -03:00
|
|
|
#ifndef BITCOIN_NETBASE_H
|
|
|
|
#define BITCOIN_NETBASE_H
|
|
|
|
|
2013-05-27 19:55:01 -04:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <config/bitcoin-config.h>
|
2013-05-27 19:55:01 -04:00
|
|
|
#endif
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <compat.h>
|
|
|
|
#include <netaddress.h>
|
|
|
|
#include <serialize.h>
|
2013-04-13 02:13:08 -03:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2012-01-03 19:33:31 -03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
extern int nConnectTimeout;
|
2014-05-31 06:04:34 -04:00
|
|
|
extern bool fNameLookup;
|
2012-01-03 19:33:31 -03:00
|
|
|
|
2015-11-09 15:16:38 -03:00
|
|
|
//! -timeout default
|
2014-09-25 04:01:54 -03:00
|
|
|
static const int DEFAULT_CONNECT_TIMEOUT = 5000;
|
2015-11-09 15:16:38 -03:00
|
|
|
//! -dns default
|
|
|
|
static const int DEFAULT_NAME_LOOKUP = true;
|
2014-09-25 04:01:54 -03:00
|
|
|
|
2015-03-16 12:30:49 -03:00
|
|
|
class proxyType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
proxyType(): randomize_credentials(false) {}
|
2017-08-01 06:22:41 -04:00
|
|
|
explicit proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
|
2015-03-16 12:30:49 -03:00
|
|
|
|
|
|
|
bool IsValid() const { return proxy.IsValid(); }
|
|
|
|
|
|
|
|
CService proxy;
|
|
|
|
bool randomize_credentials;
|
|
|
|
};
|
2012-09-23 07:55:05 -03:00
|
|
|
|
2012-05-24 13:02:21 -04:00
|
|
|
enum Network ParseNetwork(std::string net);
|
2014-07-30 09:32:36 -04:00
|
|
|
std::string GetNetworkName(enum Network net);
|
2015-03-16 12:30:49 -03:00
|
|
|
bool SetProxy(enum Network net, const proxyType &addrProxy);
|
2012-09-23 07:55:05 -03:00
|
|
|
bool GetProxy(enum Network net, proxyType &proxyInfoOut);
|
2012-05-24 13:02:21 -04:00
|
|
|
bool IsProxy(const CNetAddr &addr);
|
2015-03-16 12:30:49 -03:00
|
|
|
bool SetNameProxy(const proxyType &addrProxy);
|
2012-09-23 07:55:05 -03:00
|
|
|
bool HaveNameProxy();
|
2017-06-22 14:01:04 -04:00
|
|
|
bool GetNameProxy(proxyType &nameProxyOut);
|
2016-04-12 21:23:16 -03:00
|
|
|
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
|
2016-05-31 13:05:52 -04:00
|
|
|
bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
|
2016-04-12 21:23:16 -03:00
|
|
|
bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
|
|
|
|
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
|
2016-08-04 16:37:49 -04:00
|
|
|
CService LookupNumeric(const char *pszName, int portDefault = 0);
|
2016-05-31 15:50:24 -04:00
|
|
|
bool LookupSubNet(const char *pszName, CSubNet& subnet);
|
2017-09-18 19:45:51 -03:00
|
|
|
SOCKET CreateSocket(const CService &addrConnect);
|
2018-02-28 17:15:01 -03:00
|
|
|
bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocketRet, int nTimeout, bool manual_connection);
|
2017-10-02 17:37:36 -03:00
|
|
|
bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
|
2014-05-08 08:15:19 -04:00
|
|
|
/** Return readable error string for a network error code */
|
|
|
|
std::string NetworkErrorString(int err);
|
2014-07-10 06:13:03 -04:00
|
|
|
/** Close socket and set hSocket to INVALID_SOCKET */
|
|
|
|
bool CloseSocket(SOCKET& hSocket);
|
2014-07-09 05:00:00 -04:00
|
|
|
/** Disable or enable blocking-mode for a socket */
|
2017-07-18 10:24:46 -04:00
|
|
|
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
|
2017-03-23 02:02:02 -03:00
|
|
|
/** Set the TCP_NODELAY flag on a socket */
|
2017-07-18 10:24:46 -04:00
|
|
|
bool SetSocketNoDelay(const SOCKET& hSocket);
|
2015-08-25 15:12:08 -03:00
|
|
|
/**
|
|
|
|
* Convert milliseconds to a struct timeval for e.g. select.
|
|
|
|
*/
|
|
|
|
struct timeval MillisToTimeval(int64_t nTimeout);
|
2016-12-27 19:13:31 -03:00
|
|
|
void InterruptSocks5(bool interrupt);
|
2012-01-03 19:33:31 -03:00
|
|
|
|
2014-08-28 16:21:03 -04:00
|
|
|
#endif // BITCOIN_NETBASE_H
|