1 // Copyright (c) 2009-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_NETBASE_H
6 #define BITCOIN_NETBASE_H
8 #if defined(HAVE_CONFIG_H)
9 #include "config/bitcoin-config.h"
13 #include "netaddress.h"
14 #include "serialize.h"
20 extern int nConnectTimeout
;
21 extern bool fNameLookup
;
24 static const int DEFAULT_CONNECT_TIMEOUT
= 5000;
26 static const int DEFAULT_NAME_LOOKUP
= true;
31 proxyType(): randomize_credentials(false) {}
32 proxyType(const CService
&_proxy
, bool _randomize_credentials
=false): proxy(_proxy
), randomize_credentials(_randomize_credentials
) {}
34 bool IsValid() const { return proxy
.IsValid(); }
37 bool randomize_credentials
;
40 enum Network
ParseNetwork(std::string net
);
41 std::string
GetNetworkName(enum Network net
);
42 void SplitHostPort(std::string in
, int &portOut
, std::string
&hostOut
);
43 bool SetProxy(enum Network net
, const proxyType
&addrProxy
);
44 bool GetProxy(enum Network net
, proxyType
&proxyInfoOut
);
45 bool IsProxy(const CNetAddr
&addr
);
46 bool SetNameProxy(const proxyType
&addrProxy
);
48 bool LookupHost(const char *pszName
, std::vector
<CNetAddr
>& vIP
, unsigned int nMaxSolutions
, bool fAllowLookup
);
49 bool LookupHost(const char *pszName
, CNetAddr
& addr
, bool fAllowLookup
);
50 bool Lookup(const char *pszName
, CService
& addr
, int portDefault
, bool fAllowLookup
);
51 bool Lookup(const char *pszName
, std::vector
<CService
>& vAddr
, int portDefault
, bool fAllowLookup
, unsigned int nMaxSolutions
);
52 CService
LookupNumeric(const char *pszName
, int portDefault
= 0);
53 bool LookupSubNet(const char *pszName
, CSubNet
& subnet
);
54 bool ConnectSocket(const CService
&addr
, SOCKET
& hSocketRet
, int nTimeout
, bool *outProxyConnectionFailed
= 0);
55 bool ConnectSocketByName(CService
&addr
, SOCKET
& hSocketRet
, const char *pszDest
, int portDefault
, int nTimeout
, bool *outProxyConnectionFailed
= 0);
56 /** Return readable error string for a network error code */
57 std::string
NetworkErrorString(int err
);
58 /** Close socket and set hSocket to INVALID_SOCKET */
59 bool CloseSocket(SOCKET
& hSocket
);
60 /** Disable or enable blocking-mode for a socket */
61 bool SetSocketNonBlocking(SOCKET
& hSocket
, bool fNonBlocking
);
63 * Convert milliseconds to a struct timeval for e.g. select.
65 struct timeval
MillisToTimeval(int64_t nTimeout
);
66 void InterruptSocks5(bool interrupt
);
68 #endif // BITCOIN_NETBASE_H