Bitcoin
netbase.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2018 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.
4 
5 #ifndef BITCOIN_NETBASE_H
6 #define BITCOIN_NETBASE_H
7 
8 #if defined(HAVE_CONFIG_H)
10 #endif
11 
12 #include <compat.h>
13 #include <netaddress.h>
14 #include <serialize.h>
15 
16 #include <stdint.h>
17 #include <string>
18 #include <vector>
19 
20 extern int nConnectTimeout;
21 extern bool fNameLookup;
22 
24 static const int DEFAULT_CONNECT_TIMEOUT = 5000;
26 static const int DEFAULT_NAME_LOOKUP = true;
27 
28 class proxyType
29 {
30 public:
32  explicit proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
33 
34  bool IsValid() const { return proxy.IsValid(); }
35 
38 };
39 
40 enum Network ParseNetwork(std::string net);
41 std::string GetNetworkName(enum Network net);
42 bool SetProxy(enum Network net, const proxyType &addrProxy);
43 bool GetProxy(enum Network net, proxyType &proxyInfoOut);
44 bool IsProxy(const CNetAddr &addr);
45 bool SetNameProxy(const proxyType &addrProxy);
46 bool HaveNameProxy();
47 bool GetNameProxy(proxyType &nameProxyOut);
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 SOCKET CreateSocket(const CService &addrConnect);
55 bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocketRet, int nTimeout, bool manual_connection);
56 bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
58 std::string NetworkErrorString(int err);
60 bool CloseSocket(SOCKET& hSocket);
62 bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
64 bool SetSocketNoDelay(const SOCKET& hSocket);
68 struct timeval MillisToTimeval(int64_t nTimeout);
69 void InterruptSocks5(bool interrupt);
70 
71 #endif // BITCOIN_NETBASE_H
bool CloseSocket(SOCKET &hSocket)
Definition: netbase.cpp:880
bool SetProxy(enum Network net, const proxyType &addrProxy)
Definition: netbase.cpp:692
bool randomize_credentials
Definition: netbase.h:37
bool SetSocketNonBlocking(const SOCKET &hSocket, bool fNonBlocking)
Definition: netbase.cpp:896
bool IsValid() const
Definition: netbase.h:34
bool SetSocketNoDelay(const SOCKET &hSocket)
Definition: netbase.cpp:923
bool HaveNameProxy()
Definition: netbase.cpp:742
enum Network ParseNetwork(std::string net)
Definition: netbase.cpp:40
Definition: netaddress.h:32
bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET &hSocketRet, int nTimeout, bool manual_connection)
Definition: netbase.cpp:612
void InterruptSocks5(bool interrupt)
Definition: netbase.cpp:930
bool Lookup(const char *pszName, CService &addr, int portDefault, bool fAllowLookup)
Definition: netbase.cpp:218
bool IsValid() const
Definition: netaddress.cpp:247
struct timeval MillisToTimeval(int64_t nTimeout)
Definition: netbase.cpp:248
bool LookupSubNet(const char *pszName, CSubNet &subnet)
Definition: netbase.cpp:806
int nConnectTimeout
Definition: netbase.cpp:33
Definition: netbase.h:28
CService proxy
Definition: netbase.h:36
bool IsProxy(const CNetAddr &addr)
Definition: netbase.cpp:747
proxyType()
Definition: netbase.h:31
bool LookupHost(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
Definition: netbase.cpp:146
Network
Definition: netaddress.h:20
bool ConnectThroughProxy(const proxyType &proxy, const std::string &strDest, int port, const SOCKET &hSocketRet, int nTimeout, bool *outProxyConnectionFailed)
Definition: netbase.cpp:771
bool SetNameProxy(const proxyType &addrProxy)
Definition: netbase.cpp:726
bool fNameLookup
Definition: netbase.cpp:34
static const int DEFAULT_NAME_LOOKUP
-dns default
Definition: netbase.h:26
unsigned int SOCKET
Definition: compat.h:48
CService LookupNumeric(const char *pszName, int portDefault=0)
Definition: netbase.cpp:238
Definition: netaddress.h:102
proxyType(const CService &_proxy, bool _randomize_credentials=false)
Definition: netbase.h:32
err
Definition: extract_strings_qt.py:62
static const int DEFAULT_CONNECT_TIMEOUT
-timeout default
Definition: netbase.h:24
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:52
Definition: netaddress.h:140
SOCKET CreateSocket(const CService &addrConnect)
Definition: netbase.cpp:549
signed long long int64_t
Definition: stdint.h:18
std::string NetworkErrorString(int err)
Definition: netbase.cpp:862
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:701
int port
Definition: zmq_sub.py:37
bool GetNameProxy(proxyType &nameProxyOut)
Definition: netbase.cpp:734