From 4ba309d9ac4ac98e075a7dfc9a2609f5278cab4a Mon Sep 17 00:00:00 2001 From: subtly Date: Mon, 5 Jan 2015 17:43:06 +0100 Subject: [PATCH] code review fixes. remove std::, fix improper naming of class members, camelCase ivars for readability. --- libp2p/Host.cpp | 18 +++++++++--------- libp2p/NodeTable.cpp | 38 +++++++++++++++++++------------------- libp2p/UDP.h | 28 ++++++++++++++-------------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 4a99ac90f..d1c3cd19b 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -272,15 +272,15 @@ void Host::determinePublic(string const& _publicAddress, bool _upnp) // if user supplied address is a public address then we use it // if user supplied address is private, and localnetworking is enabled, we use it - bi::address reqpublicaddr(bi::address(_publicAddress.empty() ? bi::address() : bi::address::from_string(_publicAddress))); - bi::tcp::endpoint reqpublic(reqpublicaddr, m_listenPort); - bool isprivate = isPrivateAddress(reqpublicaddr); - bool ispublic = !isprivate && !isLocalHostAddress(reqpublicaddr); - if (!reqpublicaddr.is_unspecified() && (ispublic || (isprivate && m_netPrefs.localNetworking))) + bi::address reqPublicAddr(bi::address(_publicAddress.empty() ? bi::address() : bi::address::from_string(_publicAddress))); + bi::tcp::endpoint reqPublic(reqPublicAddr, m_listenPort); + bool isprivate = isPrivateAddress(reqPublicAddr); + bool ispublic = !isprivate && !isLocalHostAddress(reqPublicAddr); + if (!reqPublicAddr.is_unspecified() && (ispublic || (isprivate && m_netPrefs.localNetworking))) { - if (!m_peerAddresses.count(reqpublicaddr)) - m_peerAddresses.insert(reqpublicaddr); - m_tcpPublic = reqpublic; + if (!m_peerAddresses.count(reqPublicAddr)) + m_peerAddresses.insert(reqPublicAddr); + m_tcpPublic = reqPublic; return; } @@ -307,7 +307,7 @@ void Host::determinePublic(string const& _publicAddress, bool _upnp) } // or if no address provided, use private ipv4 address if local networking is enabled - if (reqpublicaddr.is_unspecified()) + if (reqPublicAddr.is_unspecified()) if (m_netPrefs.localNetworking) for (auto addr: m_peerAddresses) if (addr.is_v4() && isPrivateAddress(addr)) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 20f9f5fdf..bcaea2555 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -55,13 +55,13 @@ void NodeTable::join() doFindNode(m_node.id); } -std::list NodeTable::nodes() const +list NodeTable::nodes() const { - std::list nodes; + list nodes; Guard l(x_nodes); for (auto& i: m_nodes) nodes.push_back(i.second->id); - return std::move(nodes); + return move(nodes); } list NodeTable::state() const @@ -87,7 +87,7 @@ void NodeTable::requestNeighbors(NodeEntry const& _node, NodeId _target) const m_socketPtr->send(p); } -void NodeTable::doFindNode(NodeId _node, unsigned _round, std::shared_ptr>> _tried) +void NodeTable::doFindNode(NodeId _node, unsigned _round, shared_ptr>> _tried) { if (!m_socketPtr->isOpen() || _round == s_maxSteps) return; @@ -99,10 +99,10 @@ void NodeTable::doFindNode(NodeId _node, unsigned _round, std::shared_ptr>()); + _tried.reset(new set>()); auto nearest = findNearest(_node); - std::list> tried; + list> tried; for (unsigned i = 0; i < nearest.size() && tried.size() < s_alpha; i++) if (!_tried->count(nearest[i])) { @@ -135,14 +135,14 @@ void NodeTable::doFindNode(NodeId _node, unsigned _round, std::shared_ptr> NodeTable::findNearest(NodeId _target) +vector> NodeTable::findNearest(NodeId _target) { // send s_alpha FindNode packets to nodes we know, closest to target static unsigned lastBin = s_bins - 1; unsigned head = dist(m_node.id, _target); unsigned tail = head == 0 ? lastBin : (head - 1) % s_bins; - std::map>> found; + map>> found; unsigned count = 0; // if d is 0, then we roll look forward, if last, we reverse, else, spread from d @@ -202,11 +202,11 @@ std::vector> NodeTable::findNearest(NodeId tail--; } - std::vector> ret; + vector> ret; for (auto& nodes: found) for (auto n: nodes.second) ret.push_back(n); - return std::move(ret); + return move(ret); } void NodeTable::ping(bi::udp::endpoint _to) const @@ -222,7 +222,7 @@ void NodeTable::ping(NodeEntry* _n) const ping(_n->endpoint.udp); } -void NodeTable::evict(std::shared_ptr _leastSeen, std::shared_ptr _new) +void NodeTable::evict(shared_ptr _leastSeen, shared_ptr _new) { if (!m_socketPtr->isOpen()) return; @@ -242,7 +242,7 @@ void NodeTable::noteNode(Public const& _pubk, bi::udp::endpoint const& _endpoint if (_pubk == m_node.address()) return; - std::shared_ptr node; + shared_ptr node; { Guard l(x_nodes); auto n = m_nodes.find(_pubk); @@ -264,13 +264,13 @@ void NodeTable::noteNode(Public const& _pubk, bi::udp::endpoint const& _endpoint noteNode(node); } -void NodeTable::noteNode(std::shared_ptr _n) +void NodeTable::noteNode(shared_ptr _n) { - std::shared_ptr contested; + shared_ptr contested; { NodeBucket& s = bucket(_n.get()); Guard l(x_state); - s.nodes.remove_if([&_n](std::weak_ptr n) + s.nodes.remove_if([&_n](weak_ptr n) { if (n.lock() == _n) return true; @@ -294,12 +294,12 @@ void NodeTable::noteNode(std::shared_ptr _n) evict(contested, _n); } -void NodeTable::dropNode(std::shared_ptr _n) +void NodeTable::dropNode(shared_ptr _n) { NodeBucket &s = bucket(_n.get()); { Guard l(x_state); - s.nodes.remove_if([&_n](std::weak_ptr n) { return n.lock() == _n; }); + s.nodes.remove_if([&_n](weak_ptr n) { return n.lock() == _n; }); } Guard l(x_nodes); m_nodes.erase(_n->id); @@ -365,7 +365,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes // clog(NodeTableMessageSummary) << "Received FindNode from " << _from.address().to_string() << ":" << _from.port(); FindNode in = FindNode::fromBytesConstRef(_from, rlpBytes); - std::vector> nearest = findNearest(in.target); + vector> nearest = findNearest(in.target); static unsigned const nlimit = (m_socketPtr->maxDatagramSize - 11) / 86; for (unsigned offset = 0; offset < nearest.size(); offset += nlimit) { @@ -412,7 +412,7 @@ void NodeTable::doCheckEvictions(boost::system::error_code const& _ec) return; bool evictionsRemain = false; - std::list> drop; + list> drop; { Guard le(x_evictions); Guard ln(x_nodes); diff --git a/libp2p/UDP.h b/libp2p/UDP.h index ac4afb0b1..0c878a3de 100644 --- a/libp2p/UDP.h +++ b/libp2p/UDP.h @@ -142,13 +142,13 @@ protected: bi::udp::endpoint m_endpoint; ///< Endpoint which we listen to. Mutex x_sendQ; - std::deque sendQ; ///< Queue for egress data. - std::array recvData; ///< Buffer for ingress data. - bi::udp::endpoint recvEndpoint; ///< Endpoint data was received from. + std::deque m_sendQ; ///< Queue for egress data. + std::array m_recvData; ///< Buffer for ingress data. + bi::udp::endpoint m_recvEndpoint; ///< Endpoint data was received from. bi::udp::socket m_socket; ///< Boost asio udp socket. Mutex x_socketError; ///< Mutex for error which can be set from host or IO thread. - boost::system::error_code socketError; ///< Set when shut down due to error. + boost::system::error_code m_socketError; ///< Set when shut down due to error. }; template @@ -163,7 +163,7 @@ void UDPSocket::connect() // clear write queue so reconnect doesn't send stale messages Guard l(x_sendQ); - sendQ.clear(); + m_sendQ.clear(); m_closed = false; doRead(); @@ -176,8 +176,8 @@ bool UDPSocket::send(UDPDatagram const& _datagram) return false; Guard l(x_sendQ); - sendQ.push_back(_datagram); - if (sendQ.size() == 1) + m_sendQ.push_back(_datagram); + if (m_sendQ.size() == 1) doWrite(); return true; @@ -190,13 +190,13 @@ void UDPSocket::doRead() return; auto self(UDPSocket::shared_from_this()); - m_socket.async_receive_from(boost::asio::buffer(recvData), recvEndpoint, [this, self](boost::system::error_code _ec, size_t _len) + m_socket.async_receive_from(boost::asio::buffer(m_recvData), m_recvEndpoint, [this, self](boost::system::error_code _ec, size_t _len) { if (_ec) return disconnectWithError(_ec); assert(_len); - m_host.onReceived(this, recvEndpoint, bytesConstRef(recvData.data(), _len)); + m_host.onReceived(this, m_recvEndpoint, bytesConstRef(m_recvData.data(), _len)); doRead(); }); } @@ -207,7 +207,7 @@ void UDPSocket::doWrite() if (m_closed) return; - const UDPDatagram& datagram = sendQ[0]; + const UDPDatagram& datagram = m_sendQ[0]; auto self(UDPSocket::shared_from_this()); m_socket.async_send_to(boost::asio::buffer(datagram.data), datagram.endpoint(), [this, self](boost::system::error_code _ec, std::size_t) { @@ -216,8 +216,8 @@ void UDPSocket::doWrite() else { Guard l(x_sendQ); - sendQ.pop_front(); - if (sendQ.empty()) + m_sendQ.pop_front(); + if (m_sendQ.empty()) return; } doWrite(); @@ -235,9 +235,9 @@ void UDPSocket::disconnectWithError(boost::system::erro { // disconnect-operation following prior non-zero errors are ignored Guard l(x_socketError); - if (socketError != boost::system::error_code()) + if (m_socketError != boost::system::error_code()) return; - socketError = _ec; + m_socketError = _ec; } // TODO: (if non-zero error) schedule high-priority writes