Browse Source

Reduce usage of "new".

cl-refactor
chriseth 10 years ago
parent
commit
b78ee4c18c
  1. 5
      libethereum/BlockChainSync.h
  2. 4
      libethereum/Client.cpp
  3. 2
      libethereum/Executive.cpp
  4. 19
      libp2p/Host.cpp
  5. 2
      libp2p/Host.h
  6. 5
      libp2p/HostCapability.h
  7. 7
      libp2p/Network.cpp
  8. 8
      libp2p/NodeTable.cpp
  9. 2
      libp2p/RLPxHandshake.h
  10. 4
      libp2p/UPnP.cpp
  11. 4
      libp2p/UPnP.h
  12. 2
      libwebthree/WebThree.cpp
  13. 4
      test/libp2p/capability.cpp
  14. 8
      test/libwhisper/shhrpc.cpp
  15. 12
      test/libwhisper/whisperDB.cpp
  16. 22
      test/libwhisper/whisperTopic.cpp

5
libethereum/BlockChainSync.h

@ -113,6 +113,9 @@ protected:
/// Request blocks from peer if needed /// Request blocks from peer if needed
void requestBlocks(std::shared_ptr<EthereumPeer> _peer); void requestBlocks(std::shared_ptr<EthereumPeer> _peer);
private:
EthereumHost& m_host;
protected: protected:
Handler<> m_bqRoomAvailable; ///< Triggered once block queue Handler<> m_bqRoomAvailable; ///< Triggered once block queue
mutable RecursiveMutex x_sync; mutable RecursiveMutex x_sync;
@ -124,8 +127,6 @@ private:
static char const* const s_stateNames[static_cast<int>(SyncState::Size)]; static char const* const s_stateNames[static_cast<int>(SyncState::Size)];
bool invariants() const override = 0; bool invariants() const override = 0;
void logNewBlock(h256 const& _h); void logNewBlock(h256 const& _h);
EthereumHost& m_host;
}; };

4
libethereum/Client.cpp

@ -116,9 +116,9 @@ void Client::init(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _
m_gp->update(bc()); m_gp->update(bc());
auto host = _extNet->registerCapability(new EthereumHost(bc(), m_tq, m_bq, _networkId)); auto host = _extNet->registerCapability(make_shared<EthereumHost>(bc(), m_tq, m_bq, _networkId));
m_host = host; m_host = host;
_extNet->addCapability(host, EthereumHost::staticName(), EthereumHost::c_oldProtocolVersion); //TODO: remove this one v61+ protocol is common _extNet->addCapability(host, EthereumHost::staticName(), EthereumHost::c_oldProtocolVersion); //TODO: remove this once v61+ protocol is common
if (_dbPath.size()) if (_dbPath.size())
Defaults::setDBPath(_dbPath); Defaults::setDBPath(_dbPath);

2
libethereum/Executive.cpp

@ -39,7 +39,7 @@ const char* VMTraceChannel::name() { return "EVM"; }
const char* ExecutiveWarnChannel::name() { return WarnChannel::name(); } const char* ExecutiveWarnChannel::name() { return WarnChannel::name(); }
StandardTrace::StandardTrace(): StandardTrace::StandardTrace():
m_trace(new Json::Value(Json::arrayValue)) m_trace(make_shared<Json::Value>(Json::arrayValue))
{} {}
bool changesMemory(Instruction _inst) bool changesMemory(Instruction _inst)

19
libp2p/Host.cpp

@ -237,9 +237,9 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameCoder*
{ {
// peer doesn't exist, try to get port info from node table // peer doesn't exist, try to get port info from node table
if (Node n = m_nodeTable->node(_id)) if (Node n = m_nodeTable->node(_id))
p.reset(new Peer(n)); p = make_shared<Peer>(n);
else else
p.reset(new Peer(Node(_id, UnspecifiedNodeIPEndpoint))); p = make_shared<Peer>(Node(_id, UnspecifiedNodeIPEndpoint));
m_peers[_id] = p; m_peers[_id] = p;
} }
} }
@ -294,7 +294,7 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameCoder*
for (auto const& i: caps) for (auto const& i: caps)
if (haveCapability(i)) if (haveCapability(i))
{ {
ps->m_capabilities[i] = shared_ptr<Capability>(m_capabilities[i]->newPeerCapability(ps, o, i)); ps->m_capabilities[i] = m_capabilities[i]->newPeerCapability(ps, o, i);
o += m_capabilities[i]->messageCount(); o += m_capabilities[i]->messageCount();
} }
ps->start(); ps->start();
@ -323,7 +323,7 @@ void Host::onNodeTableEvent(NodeId const& _n, NodeTableEventType const& _e)
} }
else else
{ {
p.reset(new Peer(n)); p = make_shared<Peer>(n);
m_peers[_n] = p; m_peers[_n] = p;
clog(NetP2PNote) << "p2p.host.peers.events.peerAdded " << _n << p->endpoint; clog(NetP2PNote) << "p2p.host.peers.events.peerAdded " << _n << p->endpoint;
} }
@ -491,14 +491,14 @@ void Host::requirePeer(NodeId const& _n, NodeIPEndpoint const& _endpoint)
} }
else else
{ {
p.reset(new Peer(node)); p = make_shared<Peer>(node);
m_peers[_n] = p; m_peers[_n] = p;
} }
} }
else if (m_nodeTable) else if (m_nodeTable)
{ {
m_nodeTable->addNode(node); m_nodeTable->addNode(node);
shared_ptr<boost::asio::deadline_timer> t(new boost::asio::deadline_timer(m_ioService)); auto t = make_shared<boost::asio::deadline_timer>(m_ioService);
t->expires_from_now(boost::posix_time::milliseconds(600)); t->expires_from_now(boost::posix_time::milliseconds(600));
t->async_wait([this, _n](boost::system::error_code const& _ec) t->async_wait([this, _n](boost::system::error_code const& _ec)
{ {
@ -712,7 +712,12 @@ void Host::startedWorking()
else else
clog(NetP2PNote) << "p2p.start.notice id:" << id() << "TCP Listen port is invalid or unavailable."; clog(NetP2PNote) << "p2p.start.notice id:" << id() << "TCP Listen port is invalid or unavailable.";
shared_ptr<NodeTable> nodeTable(new NodeTable(m_ioService, m_alias, NodeIPEndpoint(bi::address::from_string(listenAddress()), listenPort(), listenPort()), m_netPrefs.discovery)); auto nodeTable = make_shared<NodeTable>(
m_ioService,
m_alias,
NodeIPEndpoint(bi::address::from_string(listenAddress()), listenPort(), listenPort()),
m_netPrefs.discovery
);
nodeTable->setEventHandler(new HostNodeTableHandler(*this)); nodeTable->setEventHandler(new HostNodeTableHandler(*this));
m_nodeTable = nodeTable; m_nodeTable = nodeTable;
restoreNetwork(&m_restoreNetwork); restoreNetwork(&m_restoreNetwork);

2
libp2p/Host.h

@ -161,7 +161,7 @@ public:
static std::unordered_map<Public, std::string> const& pocHosts(); static std::unordered_map<Public, std::string> const& pocHosts();
/// Register a peer-capability; all new peer connections will have this capability. /// Register a peer-capability; all new peer connections will have this capability.
template <class T> std::shared_ptr<T> registerCapability(T* _t) { _t->m_host = this; std::shared_ptr<T> ret(_t); m_capabilities[std::make_pair(T::staticName(), T::staticVersion())] = ret; return ret; } template <class T> std::shared_ptr<T> registerCapability(std::shared_ptr<T> const& _t) { _t->m_host = this; m_capabilities[std::make_pair(T::staticName(), T::staticVersion())] = _t; return _t; }
template <class T> void addCapability(std::shared_ptr<T> const & _p, std::string const& _name, u256 const& _version) { m_capabilities[std::make_pair(_name, _version)] = _p; } template <class T> void addCapability(std::shared_ptr<T> const & _p, std::string const& _name, u256 const& _version) { m_capabilities[std::make_pair(_name, _version)] = _p; }
bool haveCapability(CapDesc const& _name) const { return m_capabilities.count(_name) != 0; } bool haveCapability(CapDesc const& _name) const { return m_capabilities.count(_name) != 0; }

5
libp2p/HostCapability.h

@ -23,6 +23,7 @@
#pragma once #pragma once
#include <memory>
#include "Peer.h" #include "Peer.h"
#include "Common.h" #include "Common.h"
@ -53,7 +54,7 @@ protected:
virtual u256 version() const = 0; virtual u256 version() const = 0;
CapDesc capDesc() const { return std::make_pair(name(), version()); } CapDesc capDesc() const { return std::make_pair(name(), version()); }
virtual unsigned messageCount() const = 0; virtual unsigned messageCount() const = 0;
virtual Capability* newPeerCapability(std::shared_ptr<Session> _s, unsigned _idOffset, CapDesc const& _cap) = 0; virtual std::shared_ptr<Capability> newPeerCapability(std::shared_ptr<Session> const& _s, unsigned _idOffset, CapDesc const& _cap) = 0;
virtual void onStarting() {} virtual void onStarting() {}
virtual void onStopping() {} virtual void onStopping() {}
@ -77,7 +78,7 @@ protected:
virtual std::string name() const { return PeerCap::name(); } virtual std::string name() const { return PeerCap::name(); }
virtual u256 version() const { return PeerCap::version(); } virtual u256 version() const { return PeerCap::version(); }
virtual unsigned messageCount() const { return PeerCap::messageCount(); } virtual unsigned messageCount() const { return PeerCap::messageCount(); }
virtual Capability* newPeerCapability(std::shared_ptr<Session> _s, unsigned _idOffset, CapDesc const& _cap) { return new PeerCap(_s, this, _idOffset, _cap); } virtual std::shared_ptr<Capability> newPeerCapability(std::shared_ptr<Session> const& _s, unsigned _idOffset, CapDesc const& _cap) { return std::make_shared<PeerCap>(_s, this, _idOffset, _cap); }
}; };
} }

7
libp2p/Network.cpp

@ -169,10 +169,10 @@ bi::tcp::endpoint Network::traverseNAT(std::set<bi::address> const& _ifAddresses
{ {
asserts(_listenPort != 0); asserts(_listenPort != 0);
UPnP* upnp = nullptr; unique_ptr<UPnP> upnp;
try try
{ {
upnp = new UPnP; upnp.reset(new UPnP);
} }
// let m_upnp continue as null - we handle it properly. // let m_upnp continue as null - we handle it properly.
catch (...) {} catch (...) {}
@ -200,9 +200,6 @@ bi::tcp::endpoint Network::traverseNAT(std::set<bi::address> const& _ifAddresses
} }
else else
clog(NetWarn) << "Couldn't punch through NAT (or no NAT in place)."; clog(NetWarn) << "Couldn't punch through NAT (or no NAT in place).";
if (upnp)
delete upnp;
} }
return upnpEP; return upnpEP;

8
libp2p/NodeTable.cpp

@ -43,7 +43,7 @@ NodeEntry::NodeEntry(NodeId const& _src, Public const& _pubk, NodeIPEndpoint con
NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint const& _endpoint, bool _enabled): NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint const& _endpoint, bool _enabled):
m_node(Node(_alias.pub(), _endpoint)), m_node(Node(_alias.pub(), _endpoint)),
m_secret(_alias.sec()), m_secret(_alias.sec()),
m_socket(new NodeSocket(_io, *this, (bi::udp::endpoint)m_node.endpoint)), m_socket(make_shared<NodeSocket>(_io, *reinterpret_cast<UDPSocketEvents*>(this), (bi::udp::endpoint)m_node.endpoint)),
m_socketPointer(m_socket.get()), m_socketPointer(m_socket.get()),
m_timers(_io) m_timers(_io)
{ {
@ -81,7 +81,7 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node, NodeRelation _relati
{ {
if (_relation == Known) if (_relation == Known)
{ {
shared_ptr<NodeEntry> ret(new NodeEntry(m_node.id, _node.id, _node.endpoint)); auto ret = make_shared<NodeEntry>(m_node.id, _node.id, _node.endpoint);
ret->pending = false; ret->pending = false;
DEV_GUARDED(x_nodes) DEV_GUARDED(x_nodes)
m_nodes[_node.id] = ret; m_nodes[_node.id] = ret;
@ -107,7 +107,7 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node, NodeRelation _relati
if (m_nodes.count(_node.id)) if (m_nodes.count(_node.id))
return m_nodes[_node.id]; return m_nodes[_node.id];
shared_ptr<NodeEntry> ret(new NodeEntry(m_node.id, _node.id, _node.endpoint)); auto ret = make_shared<NodeEntry>(m_node.id, _node.id, _node.endpoint);
DEV_GUARDED(x_nodes) DEV_GUARDED(x_nodes)
m_nodes[_node.id] = ret; m_nodes[_node.id] = ret;
clog(NodeTableConnect) << "addNode pending for" << _node.endpoint; clog(NodeTableConnect) << "addNode pending for" << _node.endpoint;
@ -167,7 +167,7 @@ void NodeTable::doDiscover(NodeId _node, unsigned _round, shared_ptr<set<shared_
} }
else if (!_round && !_tried) else if (!_round && !_tried)
// initialized _tried on first round // initialized _tried on first round
_tried.reset(new set<shared_ptr<NodeEntry>>()); _tried = make_shared<set<shared_ptr<NodeEntry>>>();
auto nearest = nearestNodeEntries(_node); auto nearest = nearestNodeEntries(_node);
list<shared_ptr<NodeEntry>> tried; list<shared_ptr<NodeEntry>> tried;

2
libp2p/RLPxHandshake.h

@ -130,4 +130,4 @@ protected:
}; };
} }
} }

4
libp2p/UPnP.cpp

@ -40,8 +40,8 @@ using namespace dev::p2p;
UPnP::UPnP() UPnP::UPnP()
{ {
#if ETH_MINIUPNPC #if ETH_MINIUPNPC
m_urls.reset(new UPNPUrls); m_urls = make_shared<UPNPUrls>();
m_data.reset(new IGDdatas); m_data = make_shared<IGDdatas>();
m_ok = false; m_ok = false;

4
libp2p/UPnP.h

@ -50,8 +50,8 @@ public:
private: private:
std::set<int> m_reg; std::set<int> m_reg;
bool m_ok; bool m_ok;
std::shared_ptr<struct UPNPUrls> m_urls; std::shared_ptr<UPNPUrls> m_urls;
std::shared_ptr<struct IGDdatas> m_data; std::shared_ptr<IGDdatas> m_data;
}; };
} }

2
libwebthree/WebThree.cpp

@ -64,7 +64,7 @@ WebThreeDirect::WebThreeDirect(
} }
if (_interfaces.count("shh")) if (_interfaces.count("shh"))
m_whisper = m_net.registerCapability<WhisperHost>(new WhisperHost); m_whisper = m_net.registerCapability(make_shared<WhisperHost>());
} }
WebThreeDirect::~WebThreeDirect() WebThreeDirect::~WebThreeDirect()

4
test/libp2p/capability.cpp

@ -110,11 +110,11 @@ BOOST_AUTO_TEST_CASE(capability)
NetworkPreferences prefs2(localhost, 30302, false); NetworkPreferences prefs2(localhost, 30302, false);
Host host1("Test", prefs1); Host host1("Test", prefs1);
auto thc1 = host1.registerCapability(new TestHostCapability()); auto thc1 = host1.registerCapability(make_shared<TestHostCapability>());
host1.start(); host1.start();
Host host2("Test", prefs2); Host host2("Test", prefs2);
auto thc2 = host2.registerCapability(new TestHostCapability()); auto thc2 = host2.registerCapability(make_shared<TestHostCapability>());
host2.start(); host2.start();
int const step = 10; int const step = 10;

8
test/libwhisper/shhrpc.cpp

@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(basic)
NetworkPreferences prefs2("127.0.0.1", port2, false); NetworkPreferences prefs2("127.0.0.1", port2, false);
string const version2 = "shhrpc-host2"; string const version2 = "shhrpc-host2";
Host host2(version2, prefs2); Host host2(version2, prefs2);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
for (unsigned i = 0; i < 3000 && !host2.haveNetwork(); i += step) for (unsigned i = 0; i < 3000 && !host2.haveNetwork(); i += step)
@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(send)
Host host2("shhrpc-host2", NetworkPreferences("127.0.0.1", port2, false)); Host host2("shhrpc-host2", NetworkPreferences("127.0.0.1", port2, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
web3->startNetwork(); web3->startNetwork();
@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(receive)
uint16_t port2 = 30338; uint16_t port2 = 30338;
Host host2("shhrpc-host2", NetworkPreferences("127.0.0.1", port2, false)); Host host2("shhrpc-host2", NetworkPreferences("127.0.0.1", port2, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
web3->startNetwork(); web3->startNetwork();
@ -379,7 +379,7 @@ BOOST_AUTO_TEST_CASE(server)
uint16_t port2 = 30339; uint16_t port2 = 30339;
Host host2("shhrpc-host2", NetworkPreferences("127.0.0.1", port2, false)); Host host2("shhrpc-host2", NetworkPreferences("127.0.0.1", port2, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
b = jsonrpcServer->admin_net_start(sess2); b = jsonrpcServer->admin_net_start(sess2);

12
test/libwhisper/whisperDB.cpp

@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(messages)
{ {
p2p::Host h("Test"); p2p::Host h("Test");
auto wh = h.registerCapability(new WhisperHost(true)); auto wh = h.registerCapability(make_shared<WhisperHost>(true));
preexisting = wh->all(); preexisting = wh->all();
cnote << preexisting.size() << "preexisting messages in DB"; cnote << preexisting.size() << "preexisting messages in DB";
wh->installWatch(BuildTopic("test")); wh->installWatch(BuildTopic("test"));
@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(messages)
{ {
p2p::Host h("Test"); p2p::Host h("Test");
auto wh = h.registerCapability(new WhisperHost(true)); auto wh = h.registerCapability(make_shared<WhisperHost>(true));
map<h256, Envelope> m2 = wh->all(); map<h256, Envelope> m2 = wh->all();
wh->installWatch(BuildTopic("test")); wh->installWatch(BuildTopic("test"));
BOOST_REQUIRE_EQUAL(m1.size(), m2.size()); BOOST_REQUIRE_EQUAL(m1.size(), m2.size());
@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(corruptedData)
{ {
p2p::Host h("Test"); p2p::Host h("Test");
auto wh = h.registerCapability(new WhisperHost(true)); auto wh = h.registerCapability(make_shared<WhisperHost>(true));
m = wh->all(); m = wh->all();
BOOST_REQUIRE(m.end() == m.find(x)); BOOST_REQUIRE(m.end() == m.find(x));
} }
@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(filters)
{ {
WhisperFiltersDB db; WhisperFiltersDB db;
p2p::Host h("Test"); p2p::Host h("Test");
auto wh = h.registerCapability(new WhisperHost()); auto wh = h.registerCapability(make_shared<WhisperHost>());
wh->installWatch(BuildTopic("t1")); wh->installWatch(BuildTopic("t1"));
wh->installWatch(BuildTopic("t2")); wh->installWatch(BuildTopic("t2"));
db.saveTopicsToDB(*wh, persistID); db.saveTopicsToDB(*wh, persistID);
@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(filters)
Host host1("Test", NetworkPreferences("127.0.0.1", port1, false)); Host host1("Test", NetworkPreferences("127.0.0.1", port1, false));
host1.setIdealPeerCount(1); host1.setIdealPeerCount(1);
auto whost1 = host1.registerCapability(new WhisperHost()); auto whost1 = host1.registerCapability(make_shared<WhisperHost>());
host1.start(); host1.start();
WhisperFiltersDB db; WhisperFiltersDB db;
auto watches = db.restoreTopicsFromDB(whost1.get(), persistID); auto watches = db.restoreTopicsFromDB(whost1.get(), persistID);
@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(filters)
Host host2("Test", NetworkPreferences("127.0.0.1", 30309, false)); Host host2("Test", NetworkPreferences("127.0.0.1", 30309, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
for (unsigned i = 0; i < 3000 && !host1.haveNetwork(); i += step) for (unsigned i = 0; i < 3000 && !host1.haveNetwork(); i += step)

22
test/libwhisper/whisperTopic.cpp

@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(topic)
uint16_t port1 = 30311; uint16_t port1 = 30311;
Host host1("Test", NetworkPreferences("127.0.0.1", port1, false)); Host host1("Test", NetworkPreferences("127.0.0.1", port1, false));
host1.setIdealPeerCount(1); host1.setIdealPeerCount(1);
auto whost1 = host1.registerCapability(new WhisperHost()); auto whost1 = host1.registerCapability(make_shared<WhisperHost>());
host1.start(); host1.start();
bool host1Ready = false; bool host1Ready = false;
@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(topic)
Host host2("Test", NetworkPreferences("127.0.0.1", 30310, false)); Host host2("Test", NetworkPreferences("127.0.0.1", 30310, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
for (unsigned i = 0; i < 3000 && (!host1.haveNetwork() || !host2.haveNetwork()); i += step) for (unsigned i = 0; i < 3000 && (!host1.haveNetwork() || !host2.haveNetwork()); i += step)
@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(forwarding)
uint16_t port1 = 30312; uint16_t port1 = 30312;
Host host1("Listner", NetworkPreferences("127.0.0.1", port1, false)); Host host1("Listner", NetworkPreferences("127.0.0.1", port1, false));
host1.setIdealPeerCount(1); host1.setIdealPeerCount(1);
auto whost1 = host1.registerCapability(new WhisperHost()); auto whost1 = host1.registerCapability(make_shared<WhisperHost>());
host1.start(); host1.start();
while (!host1.haveNetwork()) while (!host1.haveNetwork())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(forwarding)
uint16_t port2 = 30313; uint16_t port2 = 30313;
Host host2("Forwarder", NetworkPreferences("127.0.0.1", port2, false)); Host host2("Forwarder", NetworkPreferences("127.0.0.1", port2, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
while (!host2.haveNetwork()) while (!host2.haveNetwork())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(forwarding)
Host ph("Sender", NetworkPreferences("127.0.0.1", 30314, false)); Host ph("Sender", NetworkPreferences("127.0.0.1", 30314, false));
ph.setIdealPeerCount(1); ph.setIdealPeerCount(1);
shared_ptr<WhisperHost> wh = ph.registerCapability(new WhisperHost()); shared_ptr<WhisperHost> wh = ph.registerCapability(make_shared<WhisperHost>());
ph.start(); ph.start();
ph.addNode(host2.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), port2, port2)); ph.addNode(host2.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), port2, port2));
while (!ph.haveNetwork()) while (!ph.haveNetwork())
@ -237,7 +237,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding)
uint16_t port1 = 30315; uint16_t port1 = 30315;
Host host1("Forwarder", NetworkPreferences("127.0.0.1", port1, false)); Host host1("Forwarder", NetworkPreferences("127.0.0.1", port1, false));
host1.setIdealPeerCount(1); host1.setIdealPeerCount(1);
auto whost1 = host1.registerCapability(new WhisperHost()); auto whost1 = host1.registerCapability(make_shared<WhisperHost>());
host1.start(); host1.start();
while (!host1.haveNetwork()) while (!host1.haveNetwork())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding)
{ {
Host host2("Sender", NetworkPreferences("127.0.0.1", 30316, false)); Host host2("Sender", NetworkPreferences("127.0.0.1", 30316, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
shared_ptr<WhisperHost> whost2 = host2.registerCapability(new WhisperHost()); shared_ptr<WhisperHost> whost2 = host2.registerCapability(make_shared<WhisperHost>());
host2.start(); host2.start();
while (!host2.haveNetwork()) while (!host2.haveNetwork())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding)
{ {
Host ph("Listener", NetworkPreferences("127.0.0.1", 30317, false)); Host ph("Listener", NetworkPreferences("127.0.0.1", 30317, false));
ph.setIdealPeerCount(1); ph.setIdealPeerCount(1);
shared_ptr<WhisperHost> wh = ph.registerCapability(new WhisperHost()); shared_ptr<WhisperHost> wh = ph.registerCapability(make_shared<WhisperHost>());
ph.start(); ph.start();
while (!ph.haveNetwork()) while (!ph.haveNetwork())
this_thread::sleep_for(chrono::milliseconds(2)); this_thread::sleep_for(chrono::milliseconds(2));
@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(topicAdvertising)
Host host1("first", NetworkPreferences("127.0.0.1", 30319, false)); Host host1("first", NetworkPreferences("127.0.0.1", 30319, false));
host1.setIdealPeerCount(1); host1.setIdealPeerCount(1);
auto whost1 = host1.registerCapability(new WhisperHost()); auto whost1 = host1.registerCapability(make_shared<WhisperHost>());
host1.start(); host1.start();
while (!host1.haveNetwork()) while (!host1.haveNetwork())
this_thread::sleep_for(chrono::milliseconds(10)); this_thread::sleep_for(chrono::milliseconds(10));
@ -328,7 +328,7 @@ BOOST_AUTO_TEST_CASE(topicAdvertising)
uint16_t port2 = 30318; uint16_t port2 = 30318;
Host host2("second", NetworkPreferences("127.0.0.1", port2, false)); Host host2("second", NetworkPreferences("127.0.0.1", port2, false));
host2.setIdealPeerCount(1); host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost()); auto whost2 = host2.registerCapability(make_shared<WhisperHost>());
unsigned w2 = whost2->installWatch(BuildTopicMask("test2")); unsigned w2 = whost2->installWatch(BuildTopicMask("test2"));
host2.start(); host2.start();
@ -399,7 +399,7 @@ BOOST_AUTO_TEST_CASE(selfAddressed)
BuildTopicMask mask(text); BuildTopicMask mask(text);
Host host("first", NetworkPreferences("127.0.0.1", 30320, false)); Host host("first", NetworkPreferences("127.0.0.1", 30320, false));
auto wh = host.registerCapability(new WhisperHost()); auto wh = host.registerCapability(make_shared<WhisperHost>());
auto watch = wh->installWatch(BuildTopicMask(text)); auto watch = wh->installWatch(BuildTopicMask(text));
unsigned const sample = 0xFEED; unsigned const sample = 0xFEED;

Loading…
Cancel
Save