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

examples:https-proxy:on a separate machine #248

Closed
outprog opened this issue Nov 27, 2017 · 10 comments
Closed

examples:https-proxy:on a separate machine #248

outprog opened this issue Nov 27, 2017 · 10 comments

Comments

@outprog
Copy link

outprog commented Nov 27, 2017

i run ./http_proxy on machine A, output:

Proxy server is ready
libp2p-peer addresses:
/ip4/192.168.254.62/tcp/12000/ipfs/QmXBuLYVmDK2cKGLUnnku3TkJytQopeqip6SfUJzggjuyy

then, run

./http_proxy -d /ip4/192.168.254.62/tcp/12000/ipfs/QmXBuLYVmDK2cKGLUnnku3TkJytQopeqip6SfUJzggjuyy

on machine B, output:

Proxy server is ready
libp2p-peer addresses:
/ip4/127.0.0.1/tcp/12001/ipfs/QmNd9xzbysiAfqhavp1SYUPKiccvR4GiBqkfwANHEeQC8Q
proxy listening on  127.0.0.1:9900

now, type

curl -x "127.0.0.1:9900" "http://ipfs.io/ipfs/QmfUX75pGRBRDnjeoMkQzuQczuCup2aYbeLxz5NzeSu9G6"

on machine B, it's not work. output:

2017/11/27 11:45:45 dial attempt failed: <peer.ID Nd9xzb> --> <peer.ID XBuLYV> dial attempt failed: operation timed out

is this network problem? how can i fix it? thank u!

@Stebalien
Copy link
Member

Probably. You'll have open tcp/12000 on machine A's firewall (and this will only work if those machines are on the same network as you're using private IP addresses).

@zqqq
Copy link

zqqq commented Nov 29, 2017

I have the same err,
After my test, not a firewall problem!

func makeRandomHost(port int) host.Host {
	priv, pub, err := crypto.GenerateKeyPair(crypto.RSA, 2048)
	if err != nil {
		log.Fatalln(err)
	}
	pid, err := peer.IDFromPublicKey(pub)
	if err != nil {
		log.Fatalln(err)
	}
	//	listen, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", port))
	//	if err != nil {
	//		log.Fatalln(err)
	//	}
	ps := ps.NewPeerstore()
	ps.AddPrivKey(pid, priv)
	ps.AddPubKey(pid, pub)

        //listen nil
	n, err := swarm.NewNetwork(context.Background(),
		nil, pid, ps, nil)
	if err != nil {
		log.Fatalln(err)
	}
	return bhost.New(n)
}

on makeRandomHost
Initialization, do not listen, such as initialization is completed, and then listen alone, so that you can connect successfully.

// If we have a destination peer we will start a local server
	if *destPeer != "" {
		// We use p2pport+1 in order to not collide if the user
		// is running the remote peer locally on that port
		host := makeRandomHost(*p2pport + 1)
		// Make sure our host knows how to reach destPeer
		destPeerID := addAddrToPeerstore(host, *destPeer)
		proxyAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", *port))
		if err != nil {
			log.Fatalln(err)
		}
		// Create the proxy service and start the http server
		proxy := NewProxyService(host, proxyAddr, destPeerID)
		proxy.Serve() // serve hangs forever
	} else {
		host := makeRandomHost(*p2pport)
                //here is add
		addr, _ := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", *p2pport))
		err := host.Network().Listen(addr)
		if err != nil {
			panic(err)
		}

		// In this case we only need to make sure our host
		// knows how to handle incoming proxied requests from
		// another peer.
		_ = NewProxyService(host, nil, "")
		<-make(chan struct{}) // hang forever
	}

@outprog
Copy link
Author

outprog commented Dec 1, 2017

yes, it's not a firewall problem. First time, i just change proxy.go on remote peer(remote machine)

...
listen, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", port))
...
proxyAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", *port))
...

to

...
listen, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", port))
...
proxyAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", *port))
...

use 0.0.0.0 can listen all ip. but it's not work.
last, i change proxy.go on both peer(remote machine and local machine), it's work. All machines use 0.0.0.0.

@Stebalien
Copy link
Member

I see. Yeah, that's either a bug or something that should be documented clearly. It looks like you can't dial out of an interface you're not listening on.

@Stebalien
Copy link
Member

Scratch that, it should still work (we have a fallback dialer).

@Stebalien
Copy link
Member

Could you try changing only the listen address, not the proxy address, and see what happens?

@outprog
Copy link
Author

outprog commented Dec 1, 2017

@Stebalien
Yes, only the listen address, it's work. I think if want other meachine use peer's http proxy, then need change the proxy address.

@outprog
Copy link
Author

outprog commented Dec 1, 2017

By the same, ./example/echo, if we want to run it on a separate machine, must changing ip on both local and remote.

@Stebalien
Copy link
Member

@whyrusleeping is this intended?

@whyrusleeping
Copy link
Contributor

@Stebalien Its not necessarily intended. I just generally restrict demo applications to only listen on localhost

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

No branches or pull requests

4 participants