Raven Core  3.0.0
P2P Digital Currency
netbase.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef RAVEN_NETBASE_H
7 #define RAVEN_NETBASE_H
8 
9 #if defined(HAVE_CONFIG_H)
10 #include "config/raven-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 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 char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
50 bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
51 bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
52 bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
53 CService LookupNumeric(const char *pszName, int portDefault = 0);
54 bool LookupSubNet(const char *pszName, CSubNet& subnet);
55 bool ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRet, int nTimeout);
56 bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, 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);
70 
71 #endif // RAVEN_NETBASE_H
bool ConnectThroughProxy(const proxyType &proxy, const std::string &strDest, int port, SOCKET &hSocketRet, int nTimeout, bool *outProxyConnectionFailed)
Definition: netbase.cpp:591
bool CloseSocket(SOCKET &hSocket)
Close socket and set hSocket to INVALID_SOCKET.
Definition: netbase.cpp:687
bool SetProxy(enum Network net, const proxyType &addrProxy)
Definition: netbase.cpp:543
bool SetSocketNonBlocking(const SOCKET &hSocket, bool fNonBlocking)
Disable or enable blocking-mode for a socket.
Definition: netbase.cpp:700
bool SetSocketNoDelay(const SOCKET &hSocket)
Set the TCP_NODELAY flag on a socket.
Definition: netbase.cpp:727
bool HaveNameProxy()
Definition: netbase.cpp:577
enum Network ParseNetwork(std::string net)
Definition: netbase.cpp:44
proxyType(const CService &_proxy, bool _randomize_credentials=false)
Definition: netbase.h:33
proxyType()
Definition: netbase.h:32
void InterruptSocks5(bool interrupt)
Definition: netbase.cpp:734
bool Lookup(const char *pszName, CService &addr, int portDefault, bool fAllowLookup)
Definition: netbase.cpp:160
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
Definition: netbase.cpp:180
bool LookupSubNet(const char *pszName, CSubNet &subnet)
Definition: netbase.cpp:615
int nConnectTimeout
Definition: netbase.cpp:37
bool IsProxy(const CNetAddr &addr)
Definition: netbase.cpp:582
bool IsValid() const
Definition: netaddress.cpp:198
bool randomize_credentials
Definition: netbase.h:38
bool LookupHost(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
Definition: netbase.cpp:119
bool ConnectSocketDirectly(const CService &addrConnect, SOCKET &hSocketRet, int nTimeout)
Definition: netbase.cpp:456
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:141
Network
Definition: netaddress.h:20
bool SetNameProxy(const proxyType &addrProxy)
Definition: netbase.cpp:561
bool fNameLookup
Definition: netbase.cpp:38
unsigned int SOCKET
Definition: compat.h:52
CService LookupNumeric(const char *pszName, int portDefault=0)
Definition: netbase.cpp:170
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netaddress.h:32
CService proxy
Definition: netbase.h:37
bool IsValid() const
Definition: netbase.h:35
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:52
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
Definition: netbase.cpp:669
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:552
bool GetNameProxy(proxyType &nameProxyOut)
Definition: netbase.cpp:569