Line data Source code
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 : 24 : /** -timeout default */ 25 : static const int DEFAULT_CONNECT_TIMEOUT = 5000; 26 : //! -dns default 27 : static const int DEFAULT_NAME_LOOKUP = true; 28 : 29 4440 : class proxyType 30 : { 31 : public: 32 4373 : proxyType(): randomize_credentials(false) {} 33 5 : explicit proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {} 34 : 35 8756 : bool IsValid() const { return proxy.IsValid(); } 36 : 37 : CService proxy; 38 : bool randomize_credentials; 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); 59 : /** Return readable error string for a network error code */ 60 : std::string NetworkErrorString(int err); 61 : /** Close socket and set hSocket to INVALID_SOCKET */ 62 : bool CloseSocket(SOCKET& hSocket); 63 : /** Disable or enable blocking-mode for a socket */ 64 : bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking); 65 : /** 66 : * Convert milliseconds to a struct timeval for e.g. select. 67 : */ 68 : struct timeval MillisToTimeval(int64_t nTimeout); 69 : void InterruptSocks5(bool interrupt); 70 : 71 : #endif // PIVX_NETBASE_H