Bitcoin Core  21.99.0
P2P Digital Currency
Go to the documentation of this file.
1 // Copyright (c) 2009-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or
8 #if defined(HAVE_CONFIG_H)
10 #endif
12 #include <compat.h>
13 #include <netaddress.h>
14 #include <serialize.h>
16 #include <stdint.h>
17 #include <string>
18 #include <vector>
20 extern int nConnectTimeout;
21 extern bool fNameLookup;
24 static const int DEFAULT_CONNECT_TIMEOUT = 5000;
26 static const int DEFAULT_NAME_LOOKUP = true;
28 class proxyType
29 {
30 public:
32  explicit proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
34  bool IsValid() const { return proxy.IsValid(); }
38 };
40 enum Network ParseNetwork(const 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 std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
49 bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup);
50 bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup);
51 bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
52 CService LookupNumeric(const std::string& name, int portDefault = 0);
53 bool LookupSubNet(const std::string& strSubnet, 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);
71 #endif // BITCOIN_NETBASE_H
bool CloseSocket(SOCKET &hSocket)
Close socket and set hSocket to INVALID_SOCKET.
Definition: netbase.cpp:907
bool SetProxy(enum Network net, const proxyType &addrProxy)
Definition: netbase.cpp:718
bool SetSocketNonBlocking(const SOCKET &hSocket, bool fNonBlocking)
Disable or enable blocking-mode for a socket.
Definition: netbase.cpp:923
bool SetSocketNoDelay(const SOCKET &hSocket)
Set the TCP_NODELAY flag on a socket.
Definition: netbase.cpp:950
bool HaveNameProxy()
Definition: netbase.cpp:768
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
Resolve a host string to its corresponding network addresses.
Definition: netbase.cpp:159
bool LookupSubNet(const std::string &strSubnet, CSubNet &subnet)
Parse and resolve a specified subnet string into the appropriate internal representation.
Definition: netbase.cpp:831
proxyType(const CService &_proxy, bool _randomize_credentials=false)
Definition: netbase.h:32
Definition: netbase.h:31
bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET &hSocketRet, int nTimeout, bool manual_connection)
Try to connect to the specified service on the specified socket.
Definition: netbase.cpp:638
void InterruptSocks5(bool interrupt)
Definition: netbase.cpp:957
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
Definition: netbase.cpp:274
int nConnectTimeout
Definition: netbase.cpp:36
enum Network ParseNetwork(const std::string &net)
Definition: netbase.cpp:43
bool IsProxy(const CNetAddr &addr)
Definition: netbase.cpp:773
bool IsValid() const
Definition: netaddress.cpp:432
bool ConnectThroughProxy(const proxyType &proxy, const std::string &strDest, int port, const SOCKET &hSocketRet, int nTimeout, bool &outProxyConnectionFailed)
Connect to a specified destination service through a SOCKS5 proxy by first connecting to the SOCKS5 p...
Definition: netbase.cpp:797
bool randomize_credentials
Definition: netbase.h:37
const char * name
Definition: rest.cpp:41
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:523
A network type.
Definition: netaddress.h:43
bool SetNameProxy(const proxyType &addrProxy)
Set the name proxy to use for all connections to nodes specified by a hostname.
Definition: netbase.cpp:752
bool fNameLookup
Definition: netbase.cpp:37
static const int DEFAULT_NAME_LOOKUP
-dns default
Definition: netbase.h:26
CService LookupNumeric(const std::string &name, int portDefault=0)
Resolve a service string with a numeric IP to its first corresponding service.
Definition: netbase.cpp:261
unsigned int SOCKET
Definition: compat.h:41
Network address.
Definition: netaddress.h:119
CService proxy
Definition: netbase.h:36
bool IsValid() const
Definition: netbase.h:34
-timeout default
Definition: netbase.h:24
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:55
SOCKET CreateSocket(const CService &addrConnect)
Try to create a socket file descriptor with specific properties in the communications domain (address...
Definition: netbase.cpp:575
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
Definition: netbase.cpp:889
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:727
bool Lookup(const std::string &name, CService &addr, int portDefault, bool fAllowLookup)
Resolve a service string to its first corresponding service.
Definition: netbase.cpp:238
bool GetNameProxy(proxyType &nameProxyOut)
Definition: netbase.cpp:760