Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Could you add a "port forwarding" example? #324

Open
diyism opened this issue May 3, 2018 · 14 comments
Open

[feature request] Could you add a "port forwarding" example? #324

diyism opened this issue May 3, 2018 · 14 comments
Labels
topic/docs Documentation

Comments

@diyism
Copy link

diyism commented May 3, 2018

Could you do me a favor to add a "port forwarding" example?
Currently only there is a "http-proxy" example(https://github.com/libp2p/go-libp2p/tree/master/examples/http-proxy)
If we have "port forwarding" example, we can port-forward to any service port, for example sniproxy, nginx etc.

Edit:
#324 (comment)

@diyism
Copy link
Author

diyism commented May 7, 2018

There is one example based on ZeroTier: https://github.com/selvakn/p2p-port-forward

But p2p-port-forward sometimes crash with "double free or corruption (fasttop)".

@diyism
Copy link
Author

diyism commented May 7, 2018

There is one based on Tox: https://github.com/gjedeer/tuntox
But tuntox sometimes won't traverse the NAT (for example, one side:Port Restricted Cone and the other side: Open)

@hsanjuan
Copy link
Contributor

hsanjuan commented May 9, 2018

Hey @diyism , it should be pretty straight forward to port-forward (or tunnel) something using https://github.com/hsanjuan/go-libp2p-gostream

Just like they do here: https://zupzup.org/go-port-forwarding/ but using the Dial and Listen provided by go-libp2p-gostream as you see fit. i.e.:

Client

standard tcp listener accepts connection-A
gostream dialer provides connection-B to destination peer
forwarder copies A-to-B

Server

gostream Listen accepts connection C from client
standard tcp dialer opens connection D to tcp destination
forwarder copies  C-to-D

Hope it helps

@diyism
Copy link
Author

diyism commented May 22, 2018

IPFS has experimental commands to tunnel tcp stream:
"ipfs p2p listener open" and "ipfs p2p stream dial"

ipfs/kubo#3397 (comment)

If the IPFS peer tcp tunnel can be built on go-libp2p-kcp finally, the tunnel will be perfect in performance:
paralin/go-libp2p-kcp#1

@diyism
Copy link
Author

diyism commented May 23, 2018

What a pity, ipfs p2p TCP tunnel breaks after every request: ipfs/kubo#5032

@Stebalien
Copy link
Member

It's being fixed: ipfs/kubo#4929

@Stebalien
Copy link
Member

We're also going to start work on a libp2p "daemon" in the near future so you don't have to run a full go-ipfs node.

@Stebalien Stebalien removed the feature label Mar 27, 2021
@Stebalien Stebalien added the topic/docs Documentation label Jul 22, 2021
@diyism
Copy link
Author

diyism commented Mar 21, 2022

$ ipfs version
ipfs version 0.12.1
ipfs id       # get the server ipfs peer id

#server side( oracle VPS in south korea):
ipfs config --json Experimental.Libp2pStreamMounting true
while true; do nohup /usr/bin/ssh -o ServerAliveInterval=10 -o ServerAliveCountMax=6 -CND 127.0.0.1:8081 127.0.0.1 >/dev/null 2>&1; sleep 1; done &
ipfs p2p listen /x/my-p2p/1 /ip4/127.0.0.1/tcp/8081

#client side (china shanghai home):
ipfs config --json Experimental.Libp2pStreamMounting true
ipfs p2p forward /x/my-p2p/1 /ip4/127.0.0.1/tcp/18081 /p2p/<server ipfs peer id>
time curl --socks5 127.0.0.1:18081 https://www.google.com/ncr
real	0m2.238s
user	0m0.025s
sys	0m0.013s

Great, "ipfs p2p forward" works very well in ipfs v0.12.1 now.
tested in china, the band width is about 0.5MB/s while the naive proxy (to the same server) is 5MB/s

@Winterhuman
Copy link

Winterhuman commented Mar 25, 2022

@diyism You might want to check out the performance compared to https://github.com/hyprspace/hyprspace, they had an update which significantly boosted bandwidth performance which would be good to compare against ipfs p2p.

@diyism
Copy link
Author

diyism commented Mar 25, 2022

@diyism You might want to check out the performance compared to https://github.com/hyprspace/hyprspace, they had an update which significantly boosted bandwidth performance which would be good to compare against ipfs p2p.

I've tested hyperspace, its bandwith is about 0.6MB/s from china to southkorea, it's same to the bandwidth of "ipfs p2p forwarding", so currently, it seems there's no advantage compared to ipfs p2p currently.

@Winterhuman
Copy link

Ah I see, seems ipfs p2p does the Hyprspace optimisations already then, thanks for confirming regardless!

@dvasanth
Copy link

@diyism Extended the proxy sample to support HTTP/HTTPS tunneling over libp2p. Check the sample here:
https://github.com/dvasanth/portforward-over-libp2p/
You can modify it for your portforwarding requirements for other applications.

@diyism
Copy link
Author

diyism commented Nov 1, 2022

@diyism Extended the proxy sample to support HTTP/HTTPS tunneling over libp2p. Check the sample here: https://github.com/dvasanth/portforward-over-libp2p/ You can modify it for your portforwarding requirements for other applications.

Great, I've test it, the http proxy of your portforward-over-libp2p is OK, it's very convenient, thanks.

@hsanjuan
Copy link
Contributor

@dvasanth note the existence of https://github.com/libp2p/go-libp2p-http, which you could just wrap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/docs Documentation
Projects
None yet
Development

No branches or pull requests

5 participants