Browse Source

abstract overriding tcp endpoint

cl-refactor
subtly 10 years ago
parent
commit
5959a58071
  1. 6
      libp2p/Common.cpp
  2. 3
      libp2p/Common.h
  3. 14
      libp2p/NodeTable.cpp

6
libp2p/Common.cpp

@ -109,3 +109,9 @@ std::string p2p::reasonOf(DisconnectReason _r)
default: return "Unknown reason.";
}
}
void Node::cullEndpoint()
{
if (!isPublicAddress(endpoint.tcp.address()) && isPublicAddress(endpoint.udp.address()))
endpoint.tcp.address(endpoint.udp.address());
}

3
libp2p/Common.h

@ -175,6 +175,9 @@ struct Node
virtual NodeId const& address() const { return id; }
virtual Public const& publicKey() const { return id; }
/// Replace TCP address with UDP address if TCP addr is private and UDP is public. Temp. until protocol update.
void cullEndpoint();
NodeId id;
/// Endpoints by which we expect to reach node.

14
libp2p/NodeTable.cpp

@ -98,12 +98,9 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node)
return m_nodes[_node.id];
}
// TODO: SECURITY - Temporary until packets are updated.
NodeIPEndpoint ep(_node.endpoint.udp, _node.endpoint.tcp);
if (!isPublicAddress(ep.tcp.address()) && isPublicAddress(ep.udp.address()))
ep.tcp.address(_node.endpoint.udp.address());
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, ep));
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, NodeIPEndpoint(_node.endpoint.udp, _node.endpoint.tcp)));
m_nodes[_node.id] = ret;
ret->cullEndpoint();
PingNode p(_node.endpoint.udp, m_node.endpoint.udp.address().to_string(), m_node.endpoint.udp.port());
p.sign(m_secret);
m_socketPointer->send(p);
@ -315,14 +312,9 @@ void NodeTable::noteActiveNode(Public const& _pubk, bi::udp::endpoint const& _en
if (!!node && !node->pending)
{
clog(NodeTableConnect) << "Noting active node:" << _pubk.abridged() << _endpoint.address().to_string() << ":" << _endpoint.port();
// TODO: SECURITY - Temporary until packets are updated.
// update udp endpoint and override tcp endpoint if tcp endpoint isn't public
// (for the rare case where NAT port is mapped but
node->endpoint.udp.address(_endpoint.address());
node->endpoint.udp.port(_endpoint.port());
if (!isPublicAddress(node->endpoint.tcp.address()) && isPublicAddress(node->endpoint.udp.address()))
node->endpoint.tcp.address(_endpoint.address());
node->cullEndpoint();
shared_ptr<NodeEntry> contested;
{

Loading…
Cancel
Save