mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.05k stars 990 forks source link

Distinguish between two types of p2p nodes #1797

Closed hashmap closed 5 years ago

hashmap commented 6 years ago

In peer to peer network nodes act as clients (initiates a connection) and servers (accepts connections) at the same time. However in reality some nodes can't play both roles, because they are behind nat/firewall etc.

We may want to distinguish between fully capable nodes (supernodes) and restricted ones. Why it may be useful?

To achieve this goal I'd suggest to extend Direction enum, now it has 2 variants Inbound and Outbound. Currently it reflects the fact which node initiated connection. We could add Duplex and treat it a bit differently:

During the handshake a peer which accepts the connection tries to establish a new connection to the client and if it succeeds closes the socket and marks the peer's direction as Duplex.

Only Duplex peers are discoverable in regular peer discovery we have now and future route discovery.

What do you think?

quentinlesceller commented 6 years ago

Very interesting idea @hashmap. I wonder if other cryptocurrencies have implemented such logic? Also could we simply check with a basic handshake if an Inbound peer is reachable before advertising it?

hashmap commented 6 years ago

It’s in my weekend reading/watching list.

Yes, that’s what I tried to describe, we need to open a backward connection for a short period of time for that.

garyyu commented 6 years ago

How about add NAT feature and make all nodes support Duplex? instead of increasing node type complexity.

hashmap commented 6 years ago

You mean NAT traversal? I spent some time researching it, currently I'm not sure we should support it at the moment.

So as bare minimum we need to support restricted nodes, nat traversal would be a nice addition.

sesam commented 6 years ago

Useful, and we can implement this incrementally. No new wire protocol assumptions, right? If we short term complicate peer directory, it can be changed without partitioning the network. Realistically it'll get even more complex with optimal NAT STUN etc.

Also remember that Dandelion stem connection choice still needs to know it doesn't pick for outgoing stem path a node that "called us". Because it is then too easy to be a Sybil.

dewdeded commented 6 years ago

A common way (a lot of coins and projects do that) to make nodes, that can't be reached inbound over the public internet, into a "full" bi-directional nodes: 1.) Is by using an IP overlay network (like TOR, I2P) or/and 2.) an rendezvous protocol (e.g. SIP, Freenet, JXTA).

ignopeverell commented 6 years ago

It seems straightforward enough, but I'm not sure it leads to a fruitful longer-term path. So now you have a network of "supernodes" that can do routing. Do you make everyone route for you, opening yourself to spam? Or do assign minimal point-to-point routes? Either way it seems it'll become more complex than STUN, UDP hole punching or any of those rather quickly.