Fabcoin Core  0.16.2
P2P Digital Currency
Network.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
23 #pragma once
24 
25 #include <memory>
26 #include <vector>
27 #include <deque>
28 #include <array>
29 #include <libdevcore/RLP.h>
30 #include <libdevcore/Guards.h>
31 #include "Common.h"
32 namespace ba = boost::asio;
33 namespace bi = ba::ip;
34 
35 namespace dev
36 {
37 namespace p2p
38 {
39 
40 static const unsigned short c_defaultListenPort = 30303;
41 
43 {
44  // Default Network Preferences
45  NetworkPreferences(unsigned short lp = c_defaultListenPort): listenPort(lp) {}
46 
47  // Network Preferences with specific Listen IP
48  NetworkPreferences(std::string const& l, unsigned short lp = c_defaultListenPort, bool u = true): publicIPAddress(), listenIPAddress(l), listenPort(lp), traverseNAT(u) {}
49 
50  // Network Preferences with intended Public IP
51  NetworkPreferences(std::string const& publicIP, std::string const& l = std::string(), unsigned short lp = c_defaultListenPort, bool u = true): publicIPAddress(publicIP), listenIPAddress(l), listenPort(lp), traverseNAT(u) { if (!publicIPAddress.empty() && !isPublicAddress(publicIPAddress)) BOOST_THROW_EXCEPTION(InvalidPublicIPAddress()); }
52 
54 
55  std::string publicIPAddress;
56  std::string listenIPAddress;
57  unsigned short listenPort = c_defaultListenPort;
58 
59 
61 
62  bool traverseNAT = true;
63  bool discovery = true; // Discovery is activated with network.
64  bool pin = false; // Only accept or connect to trusted peers.
65 };
66 
71 class Network
72 {
73 public:
75  static std::set<bi::address> getInterfaceAddresses();
76 
78  static int tcp4Listen(bi::tcp::acceptor& _acceptor, NetworkPreferences const& _netPrefs);
79 
81  static bi::tcp::endpoint traverseNAT(std::set<bi::address> const& _ifAddresses, unsigned short _listenPort, bi::address& o_upnpInterfaceAddr);
82 
84  static bi::tcp::endpoint resolveHost(std::string const& _host);
85 };
86 
87 }
88 }
std::string listenIPAddress
Definition: Network.h:56
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
NetworkPreferences(unsigned short lp=c_defaultListenPort)
Definition: Network.h:45
bool isPublicAddress(bi::address const &_addressToCheck)
Definition: Common.cpp:76
NetworkPreferences(std::string const &publicIP, std::string const &l=std::string(), unsigned short lp=c_defaultListenPort, bool u=true)
Definition: Network.h:51
unsigned short listenPort
Definition: Network.h:57
Network Class Static network operations and interface(s).
Definition: Network.h:71
bool traverseNAT
Preferences.
Definition: Network.h:62
NetworkPreferences(std::string const &l, unsigned short lp=c_defaultListenPort, bool u=true)
Definition: Network.h:48
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
std::string publicIPAddress
Addressing.
Definition: Network.h:55