Bitcoin ABC  0.24.7
P2P Digital Currency
netbase.h
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 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)
9 #include <config/bitcoin-config.h>
10 #endif
11 
12 #include <compat.h>
13 #include <netaddress.h>
14 #include <serialize.h>
15 
16 #include <cstdint>
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 public:
31  explicit proxyType(const CService &_proxy,
32  bool _randomize_credentials = false)
33  : proxy(_proxy), randomize_credentials(_randomize_credentials) {}
34 
35  bool IsValid() const { return proxy.IsValid(); }
36 
39 };
40 
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);
78 
79 #endif // BITCOIN_NETBASE_H
GetNameProxy
bool GetNameProxy(proxyType &nameProxyOut)
Definition: netbase.cpp:818
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:514
proxyType::IsValid
bool IsValid() const
Definition: netbase.h:35
InterruptSocks5
void InterruptSocks5(bool interrupt)
Definition: netbase.cpp:1013
LookupHost
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:165
LookupSubNet
bool LookupSubNet(const std::string &strSubnet, CSubNet &subnet)
Parse and resolve a specified subnet string into the appropriate internal representation.
Definition: netbase.cpp:891
ConnectSocketDirectly
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:684
SetSocketNonBlocking
bool SetSocketNonBlocking(const SOCKET &hSocket, bool fNonBlocking)
Disable or enable blocking-mode for a socket.
Definition: netbase.cpp:980
CNetAddr
Network address.
Definition: netaddress.h:117
SetSocketNoDelay
bool SetSocketNoDelay(const SOCKET &hSocket)
Set the TCP_NODELAY flag on a socket.
Definition: netbase.cpp:1006
MillisToTimeval
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
Definition: netbase.cpp:284
Network
Network
A network type.
Definition: netaddress.h:43
IsProxy
bool IsProxy(const CNetAddr &addr)
Definition: netbase.cpp:832
HaveNameProxy
bool HaveNameProxy()
Definition: netbase.cpp:827
proxyType
Definition: netbase.h:28
nConnectTimeout
int nConnectTimeout
Definition: netbase.cpp:33
compat.h
fNameLookup
bool fNameLookup
Definition: netbase.cpp:34
netaddress.h
LookupNumeric
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:271
ParseNetwork
enum Network ParseNetwork(const std::string &net)
Definition: netbase.cpp:41
ConnectThroughProxy
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:857
CNetAddr::IsValid
bool IsValid() const
Definition: netaddress.cpp:438
CSubNet
Definition: netaddress.h:465
proxyType::proxyType
proxyType()
Definition: netbase.h:30
proxyType::proxyType
proxyType(const CService &_proxy, bool _randomize_credentials=false)
Definition: netbase.h:31
DEFAULT_CONNECT_TIMEOUT
static const int DEFAULT_CONNECT_TIMEOUT
-timeout default
Definition: netbase.h:24
SetNameProxy
bool SetNameProxy(const proxyType &addrProxy)
Set the name proxy to use for all connections to nodes specified by a hostname.
Definition: netbase.cpp:809
name
const char * name
Definition: rest.cpp:43
DEFAULT_NAME_LOOKUP
static const int DEFAULT_NAME_LOOKUP
-dns default
Definition: netbase.h:26
GetProxy
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:783
proxyType::randomize_credentials
bool randomize_credentials
Definition: netbase.h:38
Lookup
bool Lookup(const std::string &name, CService &addr, int portDefault, bool fAllowLookup)
Resolve a service string to its first corresponding service.
Definition: netbase.cpp:247
NetworkErrorString
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
Definition: netbase.cpp:941
serialize.h
CloseSocket
bool CloseSocket(SOCKET &hSocket)
Close socket and set hSocket to INVALID_SOCKET.
Definition: netbase.cpp:963
SetProxy
bool SetProxy(enum Network net, const proxyType &addrProxy)
Definition: netbase.cpp:773
GetNetworkName
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:60
CreateSocket
SOCKET CreateSocket(const CService &addrConnect)
Try to create a socket file descriptor with specific properties in the communications domain (address...
Definition: netbase.cpp:614
proxyType::proxy
CService proxy
Definition: netbase.h:37
SOCKET
unsigned int SOCKET
Definition: compat.h:44