Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does peer to peer actually work network/port wise?

Tags:

c++

sockets

p2p

So I've been looking into sockets and stuff, mostly c++. I've learned (not yet executed cuz I'm lazy) non-blocking IO, and once I actually start working on my project I may just have a really nice overall structure for the server to hold a lot of clients.

With the server it was always a given I'd have to port forward. And clients don't need to. But that got me thinking. Torrent clients in general don't seem to need router port forwarding, and they're peer to peer. So how does that work?? Multiple times around the client you see "Port Forwarding". But what kind of port forwarding is that?

Am I missing something really freaking obvious here or just asking the wrong question? I can't seem to be able to find any answers to this.

So how does port forwarding for peer to peer work? If that's the right thing to even ask.

Thank you for your time!

like image 430
TrisT Avatar asked Jun 27 '16 14:06

TrisT


Video Answer


1 Answers

Ok, so pay mentioned hole-punching which seems to be one of the techniques of NAT traversal, which basically "bypasses" or "goes through" NAT(and therefore port-forwarding).

I've now read a bit on this. Basically NAT makes it so traffic is routed to the specific system in question inside the network to which the port is open. As techniques such as hole-punching don't go though this system, there is no real way of knowing for and from which system inside the internal network it came from. One could just do something like using a key and encrypting traffic so that the only a certain computer inside the network with that key could decrypt it (would sorta be like a CA). Or if it's not sensitive info you could aswell just use random ports to connect to in each different system. A fairly big problem with this is that NATs may be different across routers so you might have to use different techniques and compatibility isn't assured.

Ok, so Hasturkun mentioned UPNP. I've also read a lil and basically it's a protocol that allows for your apps/programs to communicate with the router and set specific NAT rules for themselves, so it's like it basically does the port forwarding for you. It also means that unlike traversal techniques it drives the traffic directly to the desired system. One disadvantage is that it might not be active by default on your router, so then you can't use it at all. It's fairly "global" from what I've read, also unlike traversal.

All around IMO you should use both as an insurance policy, seems to me it'd be a hell of a lot of work, but anyways and as always, laziness leads nowhere.

I hope this could help someone as it helped me, have a nice day :D

like image 69
TrisT Avatar answered Oct 15 '22 02:10

TrisT