Bitcoin ABC  0.23.2
P2P Digital Currency
Go to the documentation of this file.
1 // Copyright (c) 2009-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or
8 #if defined(HAVE_CONFIG_H)
9 #include <config/bitcoin-config.h>
10 #endif
12 #include <compat.h>
13 #include <netaddress.h>
14 #include <serialize.h>
16 #include <cstdint>
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 public:
31  explicit proxyType(const CService &_proxy,
32  bool _randomize_credentials = false)
33  : proxy(_proxy), randomize_credentials(_randomize_credentials) {}
35  bool IsValid() const { return proxy.IsValid(); }
39 };
41 enum Network ParseNetwork(const std::string &net);
42 std::string GetNetworkName(enum Network net);
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);
47 bool HaveNameProxy();
48 bool GetNameProxy(proxyType &nameProxyOut);
49 bool LookupHost(const std::string &name, std::vector<CNetAddr> &vIP,
50  unsigned int nMaxSolutions, bool fAllowLookup);
51 bool LookupHost(const std::string &name, CNetAddr &addr, bool fAllowLookup);
52 bool Lookup(const std::string &name, CService &addr, int portDefault,
53  bool fAllowLookup);
54 bool Lookup(const std::string &name, std::vector<CService> &vAddr,
55  int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
56 CService LookupNumeric(const std::string &name, int portDefault = 0);
57 bool LookupSubNet(const std::string &strSubnet, CSubNet &subnet);
58 SOCKET CreateSocket(const CService &addrConnect);
59 bool ConnectSocketDirectly(const CService &addrConnect,
60  const SOCKET &hSocketRet, int nTimeout,
61  bool manual_connection);
62 bool ConnectThroughProxy(const proxyType &proxy, const std::string &strDest,
63  int port, const SOCKET &hSocketRet, int nTimeout,
64  bool &outProxyConnectionFailed);
66 std::string NetworkErrorString(int err);
68 bool CloseSocket(SOCKET &hSocket);
70 bool SetSocketNonBlocking(const SOCKET &hSocket, bool fNonBlocking);
72 bool SetSocketNoDelay(const SOCKET &hSocket);
76 struct timeval MillisToTimeval(int64_t nTimeout);
77 void InterruptSocks5(bool interrupt);
79 #endif // BITCOIN_NETBASE_H
bool CloseSocket(SOCKET &hSocket)
Close socket and set hSocket to INVALID_SOCKET.
Definition: netbase.cpp:962
bool SetProxy(enum Network net, const proxyType &addrProxy)
Definition: netbase.cpp:772
bool SetSocketNonBlocking(const SOCKET &hSocket, bool fNonBlocking)
Disable or enable blocking-mode for a socket.
Definition: netbase.cpp:979
bool SetSocketNoDelay(const SOCKET &hSocket)
Set the TCP_NODELAY flag on a socket.
Definition: netbase.cpp:1005
bool HaveNameProxy()
Definition: netbase.cpp:826
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:164
bool LookupSubNet(const std::string &strSubnet, CSubNet &subnet)
Parse and resolve a specified subnet string into the appropriate internal representation.
Definition: netbase.cpp:890
proxyType(const CService &_proxy, bool _randomize_credentials=false)
Definition: netbase.h:31
Definition: netbase.h:30
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:683
void InterruptSocks5(bool interrupt)
Definition: netbase.cpp:1012
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
Definition: netbase.cpp:283
int nConnectTimeout
Definition: netbase.cpp:32
enum Network ParseNetwork(const std::string &net)
Definition: netbase.cpp:40
bool IsProxy(const CNetAddr &addr)
Definition: netbase.cpp:831
bool IsValid() const
Definition: netaddress.cpp:438
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:856
bool randomize_credentials
Definition: netbase.h:38
const char * name
Definition: rest.cpp:43
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:505
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:808
bool fNameLookup
Definition: netbase.cpp:33
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:270
unsigned int SOCKET
Definition: compat.h:44
Network address.
Definition: netaddress.h:117
CService proxy
Definition: netbase.h:37
bool IsValid() const
Definition: netbase.h:35
-timeout default
Definition: netbase.h:24
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:59
SOCKET CreateSocket(const CService &addrConnect)
Try to create a socket file descriptor with specific properties in the communications domain (address...
Definition: netbase.cpp:613
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
Definition: netbase.cpp:940
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:782
bool Lookup(const std::string &name, CService &addr, int portDefault, bool fAllowLookup)
Resolve a service string to its first corresponding service.
Definition: netbase.cpp:246
bool GetNameProxy(proxyType &nameProxyOut)
Definition: netbase.cpp:817