whyrusleeping / gx

A package management tool
MIT License
1.88k stars 110 forks source link

gx import not working in mainland China #181

Open bluescv opened 6 years ago

bluescv commented 6 years ago

I'm trying to read the source code of ipfs and learned that ipfs uses gx as its package manager. However, due to the existence of GFW, the gx import always fail after a timeout like:

ERROR: from shell.Get(): Post http://127.0.0.1:5001/api/v0/get?arg=QmYM2pipuZdMKKgU6m8wNN7F7sL64ipaCCf3p6VJpKHdb1&encoding=json&stream-channels=true: net/http: request canceled (Client.Timeout exceeded while awaiting headers) retrying fetch QmYM2pipuZdMKKgU6m8wNN7F7sL64ipaCCf3p6VJpKHdb1 after a second...

My suspicion is that the gx command has to reslove ipfs.io which is blocked by the GFW. Is there any way I can overcome this problem? Is there any way gx work as a pure decentralized tool?

Stebalien commented 6 years ago

What's the output of echo "$IPFS_API" and are you running the ipfs daemon?

Basically, gx is designed to use your local IPFS daemon when the IPFS_API environment variable is set. In your case, it looks like IPFS_API is set (that's why it's trying to use 127.0.0.1:5001). That's why I asked if you're already running the daemon.


TL;DR: If you set IPFS_API='127.0.0.1:5001' in your environment and runipfs daemonin the background,gx` should use that instead of fetching from ipfs.io.

bluescv commented 6 years ago

Basically, gx is designed to use your local IPFS daemon when the IPFS_API environment variable is set. In your case, it looks like IPFS_API is set (that's why it's trying to use 127.0.0.1:5001). That's why I asked if you're already running the daemon.

The output of echo "$IPFS_API" is blank but I'm pretty sure the IPFS daemon is running and gx is connected to the daemon. I've seen someone claimed that when using daemon, IPFS still have to resolve ipfs.io, and his solution is to modify shell.go to use proxy:

    c := &gohttp.Client{
            Transport: &gohttp.Transport{
                    Proxy: gohttp.ProxyFromEnvironment, // The new line to use system proxy
                    DisableKeepAlives: true,
            },
    }
    return NewShellWithClient(url, c)

I don't have a proxy right now so I didn't try this out. Any other possible solutions? Is that true the IPFS network has to resolve ipfs.io to get working? Thanks in advance.

Stebalien commented 6 years ago

I don't have a proxy right now so I didn't try this out. Any other possible solutions?

That only applies if you're trying to use our gateway (at ipfs.io). If you're using your own daemon, you won't need that.

Is that true the IPFS network has to resolve ipfs.io to get working?

No although the daemon does need to connect to some of our bootstrap nodes to find the rest of the network. If you have any friends running IPFS, you can bootstrap off of them by adding them to the list (using ipfs bootstrap add).

The output of echo "$IPFS_API" is blank but I'm pretty sure the IPFS daemon is running and gx is connected to the daemon.

Are you running the daemon? What's the output of ipfs id?

bluescv commented 6 years ago

Are you running the daemon? What's the output of ipfs id?

Yes I started daemon by using command ipfs daemon. The output of ipfs id:

{
    "ID": "QmYSDi7fjWgF1yRPjTwiukhNKfoSvNosAT7STkWPLkKoaL",
    "PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC9p1wHLj8zLCruilCWhQ2Fm2idLjPU5n87rSQWsyNNKqHeg+/C5OCiCzbvJ2fPbM9WWtYcH7K9KXvwwunkYxmFhHuQd+qiA6DMmM4DdfNaz4hL3bTguzjqTCyoyixOiyyaqwnKwtbBobeCk0wVl89BTRD7SaiGqs/nwBAjPhXZaDdlshNY+122Ghu1ICn2AUWP3yaJTDmLV9uN8o3/c3FFcrJTu39MPUCRF2fHZwnun6ym1dTgpQ+8w1o0bInf+36iyGeNzriYmda+RECg5Vix82KZQRJD3l0yQZvSmonu9Uy5ZYc5nqDvDQhNqTptZcZy5nUJDN10FR74EYWWC2i1AgMBAAE=",
    "Addresses": [
        "/ip4/127.0.0.1/tcp/4001/ipfs/QmYSDi7fjWgF1yRPjTwiukhNKfoSvNosAT7STkWPLkKoaL",
        "/ip4/192.168.19.200/tcp/4001/ipfs/QmYSDi7fjWgF1yRPjTwiukhNKfoSvNosAT7STkWPLkKoaL",
        "/ip4/172.17.0.1/tcp/4001/ipfs/QmYSDi7fjWgF1yRPjTwiukhNKfoSvNosAT7STkWPLkKoaL",
        "/ip4/172.19.0.1/tcp/4001/ipfs/QmYSDi7fjWgF1yRPjTwiukhNKfoSvNosAT7STkWPLkKoaL",
        "/ip4/172.18.0.1/tcp/4001/ipfs/QmYSDi7fjWgF1yRPjTwiukhNKfoSvNosAT7STkWPLkKoaL",
        "/ip6/::1/tcp/4001/ipfs/QmYSDi7fjWgF1yRPjTwiukhNKfoSvNosAT7STkWPLkKoaL"
    ],
    "AgentVersion": "go-ipfs/0.4.9/",
    "ProtocolVersion": "ipfs/0.1.0"
}

Also the command ipfs swarm peers shows that I've connected to a lot of peers. I tried obtain file from IPFS network and publish a file to IPFS and they both work fine. I'm running IPFS daemon in an VM but I suppose that makes no differences .

Stebalien commented 6 years ago

I'm running IPFS daemon in an VM but I suppose that makes no differences.

As long as gx can talk to it. By default, the API only listens on localhost so if you're using gx outside of the VM, you'll probably have to expose it somehow.

I assume you ran the ipfs id command inside the VM.

raphaelsoul commented 6 years ago

https://github.com/ipfs/go-ipfs/issues/5430

related issue by me here. How can I download from a custom gateway? My problem solved there.