5

it's being said that a peer to peer network is not server-base for routing and processing data and only uses server for getting the up to date nodes addresses (probably their internet IP address) to connect to other node directly without no intermediate server. so my question is, how computer(node) A can establish a connection with node B over the internet. the IPs that ISP gives us is invalid and isn't reachable. so how does this p2p work with these invalid node IP address over internet?

Mehrdad Dadvand
  • 151
  • 1
  • 4

1 Answers1

4

Assuming the question is about home/residential connections:


Most wired ISPs do in fact give a publicly reachable IPv4 address to their customers. That address is assigned to the customer's home router, and that router can receive packets and forward them to whichever internal device the customer specifies. (It already has to do this in order to correctly deliver inbound replies belonging to a regular outbound connection – it remembers which connection's packets need to be sent to which internal host.)

For P2P, either a) the customer adds a static rule ("port forwarding" aka DNAT) to always send packets for specified TCP/UDP port towards their computer (node A). Other nodes can then simply use the public address of the router and it'll forward packets internally to node A.

(Programs can even use NAT-PMP and/or UPnP IGD to add "port forwarding" rules automatically.)

Or b) the program can use various "NAT traversal" / "hole punching" mechanisms, such as STUN (which uses a 'helper' server for the initial handshake). These mechanisms usually involve tricking the routers' automatic connection tracking to make it look like each node is connecting outwards to the other at the same time, on the same pair of ports.


For ISPs which use CGNAT and don't give customers a public IPv4 address at all, option a) is generally not possible, and option b) sometimes works, sometimes doesn't. AFAIK, two CGNAT'ed nodes generally cannot communicate directly.

(Note that even CGNAT'ed nodes can still make outgoing connections to any node that has a public address, so they're not completely isolated. I mean, if they couldn't do that, then they couldn't access web/mail/game servers either?)

However, at least some of those ISPs provide IPv6 support alongside the CGNAT IPv4 service. Generally IPv6 provides a public address to every device, so when both nodes are IPv6-capable, they can use each other's public IPv6 address directly.

(They might still need hole-punching or manual router configuration, but that's because a firewall is usually in the way, and not because of routing/addressing anymore.)

grawity
  • 501,077