PIVX Core  5.6.99
P2P Digital Currency
netbase.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2015 The Bitcoin developers
2 // Copyright (c) 2017-2022 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_NETBASE_H
7 #define PIVX_NETBASE_H
8 
9 #if defined(HAVE_CONFIG_H)
10 #include "config/pivx-config.h"
11 #endif
12 
13 #include "compat.h"
14 #include "netaddress.h"
15 #include "serialize.h"
16 
17 #include <stdint.h>
18 #include <string>
19 #include <vector>
20 
21 extern int nConnectTimeout;
22 extern bool fNameLookup;
23 
25 static const int DEFAULT_CONNECT_TIMEOUT = 5000;
27 static const int DEFAULT_NAME_LOOKUP = true;
28 
29 class proxyType
30 {
31 public:
33  explicit proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
34 
35  bool IsValid() const { return proxy.IsValid(); }
36 
39 };
40 
41 enum Network ParseNetwork(std::string net);
42 std::string GetNetworkName(enum Network net);
43 void SplitHostPort(std::string in, int& portOut, std::string& hostOut);
44 bool SetProxy(enum Network net, const proxyType &addrProxy);
45 bool GetProxy(enum Network net, proxyType& proxyInfoOut);
46 bool IsProxy(const CNetAddr& addr);
47 bool SetNameProxy(const proxyType &addrProxy);
48 bool HaveNameProxy();
49 bool GetNameProxy(proxyType& nameProxyOut);
50 bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, 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, bool fAllowLookup);
53 bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
54 CService LookupNumeric(const std::string& name, int portDefault = 0);
55 bool LookupSubNet(const std::string& name, CSubNet& subnet);
56 SOCKET CreateSocket(const CService &addrConnect);
57 bool ConnectSocketDirectly(const CService& addrConnect, const SOCKET& hSocketRet, int nTimeout, bool manual_connection);
58 bool ConnectThroughProxy(const proxyType& proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool* outProxyConnectionFailed);
60 std::string NetworkErrorString(int err);
62 bool CloseSocket(SOCKET& hSocket);
64 bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking);
66 bool SetSocketNoDelay(SOCKET& hSocket);
70 struct timeval MillisToTimeval(int64_t nTimeout);
71 void InterruptSocks5(bool interrupt);
72 
73 #endif // PIVX_NETBASE_H
false
Definition: bls_dkg.cpp:151
Network address.
Definition: netaddress.h:120
bool IsValid() const
Definition: netaddress.cpp:418
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:484
bool IsValid() const
Definition: netbase.h:35
CService proxy
Definition: netbase.h:37
proxyType()
Definition: netbase.h:32
bool randomize_credentials
Definition: netbase.h:38
proxyType(const CService &_proxy, bool _randomize_credentials=false)
Definition: netbase.h:33
u_int SOCKET
Definition: compat.h:53
Network
A network type.
Definition: netaddress.h:44
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
Definition: netbase.cpp:222
bool LookupSubNet(const std::string &name, CSubNet &subnet)
Definition: netbase.cpp:673
bool GetNameProxy(proxyType &nameProxyOut)
Definition: netbase.cpp:624
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
Definition: netbase.cpp:71
bool SetSocketNoDelay(SOCKET &hSocket)
Set the TCP_NODELAY flag on a socket.
Definition: netbase.cpp:784
enum Network ParseNetwork(std::string net)
Definition: netbase.cpp:46
CService LookupNumeric(const std::string &name, int portDefault=0)
Definition: netbase.cpp:209
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:55
bool HaveNameProxy()
Definition: netbase.cpp:633
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:605
bool SetSocketNonBlocking(SOCKET &hSocket, bool fNonBlocking)
Disable or enable blocking-mode for a socket.
Definition: netbase.cpp:755
void InterruptSocks5(bool interrupt)
Definition: netbase.cpp:791
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
Definition: netbase.cpp:724
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
Definition: netbase.cpp:149
bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET &hSocketRet, int nTimeout, bool manual_connection)
Definition: netbase.cpp:535
bool fNameLookup
Definition: netbase.cpp:40
int nConnectTimeout
Definition: netbase.cpp:39
bool SetNameProxy(const proxyType &addrProxy)
Definition: netbase.cpp:615
bool ConnectThroughProxy(const proxyType &proxy, const std::string &strDest, int port, const SOCKET &hSocketRet, int nTimeout, bool *outProxyConnectionFailed)
Definition: netbase.cpp:649
bool Lookup(const std::string &name, CService &addr, int portDefault, bool fAllowLookup)
Definition: netbase.cpp:196
bool CloseSocket(SOCKET &hSocket)
Close socket and set hSocket to INVALID_SOCKET.
Definition: netbase.cpp:742
bool IsProxy(const CNetAddr &addr)
Definition: netbase.cpp:639
SOCKET CreateSocket(const CService &addrConnect)
Definition: netbase.cpp:490
bool SetProxy(enum Network net, const proxyType &addrProxy)
Definition: netbase.cpp:595
const char * name
Definition: rest.cpp:37