textileio / go-textile

[DEPRECATED] Textile is a set of tools and infrastructure for building composable apps and services on the IPFS network
https://textile.io
MIT License
357 stars 43 forks source link

Expose simple p2p direct message API #885

Closed carsonfarmer closed 4 years ago

carsonfarmer commented 5 years ago

It would be extremely useful to be able to send small, direct p2p messages between Textile peers using their underlying libp2p clients. This would be for ephemeral, small messages that wouldn't need to be pinned or stored on IPFS. These would be direct dials, and if the peers aren't connected, would/could likely just fail. The usecase here is sending information between peers that are on the same network, but need to share contact information or credentials outside their usual handshakes.

xlab commented 5 years ago

It's a great thing to have, pretty easy to implement with methods of the IPFS node object. On the "server" side core.IpfsNode.P2P.ForwardRemote should be used, on the "dialer" side core.IpfsNode.P2P.ForwardLocal should be used.

The only problem that exists here is that both require a local port opened, since it's a pipe between two already bound ports. I hoped that IPFS would introduce a method that accepts net.Listener but that didn't happen yet. The ForwardLocal side can bind its end to /ip4/127.0.0.1/tcp/0 for now.

I believe, the latter issue can be avoided by introducing custom logic based on

that will take net.Listener instead of a multiaddr to bind / dial.