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