From 7dfd83e8f5bfe8ef084e9afd23890b2e1b11bc9e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 16 Nov 2014 12:59:16 +0100 Subject: [PATCH] Whisper API change for topics. Don't keep dead nodes. --- libp2p/Host.cpp | 6 +++--- libwhisper/Common.cpp | 2 +- libwhisper/Common.h | 7 +------ 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 4b28a63a3..be9f2f7ae 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -778,7 +778,7 @@ bytes Host::saveNodes() const { Node const& n = *(i.second); // TODO: PoC-7: Figure out why it ever shares these ports.//n.address.port() >= 30300 && n.address.port() <= 30305 && - if (!n.dead && n.address.port() > 0 && n.address.port() < /*49152*/32768 && n.id != id() && !isPrivateAddress(n.address.address())) + if (!n.dead && chrono::system_clock::now() - n.lastConnected < chrono::seconds(3600 * 48) && n.address.port() > 0 && n.address.port() < /*49152*/32768 && n.id != id() && !isPrivateAddress(n.address.address())) { nodes.appendList(10); if (n.address.address().is_v4()) @@ -786,8 +786,8 @@ bytes Host::saveNodes() const else nodes << n.address.address().to_v6().to_bytes(); nodes << n.address.port() << n.id << (int)n.idOrigin - << std::chrono::duration_cast(n.lastConnected.time_since_epoch()).count() - << std::chrono::duration_cast(n.lastAttempted.time_since_epoch()).count() + << chrono::duration_cast(n.lastConnected.time_since_epoch()).count() + << chrono::duration_cast(n.lastAttempted.time_since_epoch()).count() << n.failedAttempts << (unsigned)n.lastDisconnect << n.score << n.rating; count++; } diff --git a/libwhisper/Common.cpp b/libwhisper/Common.cpp index 83f289875..0d54af089 100644 --- a/libwhisper/Common.cpp +++ b/libwhisper/Common.cpp @@ -69,7 +69,7 @@ TopicMask BuildTopicMask::toTopicMask() const TopicMask ret; ret.reserve(m_parts.size()); for (auto const& h: m_parts) - ret.push_back(make_pair(TopicPart(h), h ? ~TopicPart() : TopicPart())); + ret.push_back(make_pair(TopicPart(h), ~TopicPart())); return ret; } diff --git a/libwhisper/Common.h b/libwhisper/Common.h index 312cbf6d3..a704a2896 100644 --- a/libwhisper/Common.h +++ b/libwhisper/Common.h @@ -114,17 +114,12 @@ private: class BuildTopicMask: BuildTopic { public: - enum EmptyType { Empty }; - - BuildTopicMask() { shift(); } - BuildTopicMask(EmptyType) {} + template BuildTopicMask() {} template BuildTopicMask(T const& _t) { shift(_t); } template BuildTopicMask& shift(T const& _r) { BuildTopic::shift(_r); return *this; } BuildTopicMask& shiftRaw(h256 const& _h) { BuildTopic::shiftRaw(_h); return *this; } - BuildTopic& shift() { m_parts.push_back(h256()); return *this; } - BuildTopicMask& operator()() { shift(); return *this; } template BuildTopicMask& operator()(T const& _t) { shift(_t); return *this; } operator TopicMask() const { return toTopicMask(); }