From 9c57ca03d97c9bff464cc7cb7da2939c340d4635 Mon Sep 17 00:00:00 2001 From: yaohcn Date: Thu, 31 Oct 2019 18:21:37 +0800 Subject: [PATCH] use IPFS_GATEWAY --- build/paramfetch.go | 20 ++++++++++++-------- cli/params.go | 2 +- cmd/lotus-storage-miner/init.go | 2 +- cmd/lotus-storage-miner/main.go | 5 ----- cmd/lotus-storage-miner/run.go | 2 +- cmd/lotus/daemon.go | 2 +- cmd/lotus/main.go | 5 ----- lib/sectorbuilder/sectorbuilder_test.go | 2 +- 8 files changed, 17 insertions(+), 23 deletions(-) diff --git a/build/paramfetch.go b/build/paramfetch.go index 97ae76d74..39e6ffda6 100644 --- a/build/paramfetch.go +++ b/build/paramfetch.go @@ -21,7 +21,7 @@ import ( var log = logging.Logger("build") //const gateway = "http://198.211.99.118/ipfs/" -const GateWay = "https://ipfs.io/ipfs/" +const gateway = "https://ipfs.io/ipfs/" const paramdir = "/var/tmp/filecoin-proof-parameters" type paramFile struct { @@ -37,7 +37,7 @@ type fetch struct { errs []error } -func GetParams(storage bool, gateway string) error { +func GetParams(storage bool) error { if err := os.Mkdir(paramdir, 0755); err != nil && !os.IsExist(err) { return err } @@ -59,13 +59,13 @@ func GetParams(storage bool, gateway string) error { continue } - ft.maybeFetchAsync(name, info, gateway) + ft.maybeFetchAsync(name, info) } return ft.wait() } -func (ft *fetch) maybeFetchAsync(name string, info paramFile, gateway string) { +func (ft *fetch) maybeFetchAsync(name string, info paramFile) { ft.wg.Add(1) go func() { @@ -84,7 +84,7 @@ func (ft *fetch) maybeFetchAsync(name string, info paramFile, gateway string) { ft.fetchLk.Lock() defer ft.fetchLk.Unlock() - if err := doFetch(path, info, gateway); err != nil { + if err := doFetch(path, info); err != nil { ft.errs = append(ft.errs, xerrors.Errorf("fetching file %s: %w", path, err)) } }() @@ -116,10 +116,14 @@ func (ft *fetch) wait() error { return multierr.Combine(ft.errs...) } -func doFetch(out string, info paramFile, gateway string) error { - log.Infof("Fetching %s from %s", out, gateway) +func doFetch(out string, info paramFile) error { + gw := os.Getenv("IPFS_GATEWAY") + if gw == "" { + gw = gateway + } + log.Infof("Fetching %s from %s", out, gw) - resp, err := http.Get(gateway + info.Cid) + resp, err := http.Get(gw + info.Cid) if err != nil { return err } diff --git a/cli/params.go b/cli/params.go index 8aadebe58..6f6017ca3 100644 --- a/cli/params.go +++ b/cli/params.go @@ -10,7 +10,7 @@ var fetchParamCmd = &cli.Command{ Name: "fetch-params", Usage: "Fetch proving parameters", Action: func(cctx *cli.Context) error { - if err := build.GetParams(true, cctx.String("gateway")); err != nil { + if err := build.GetParams(true); err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index a6d5e7527..54d488a1b 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -59,7 +59,7 @@ var initCmd = &cli.Command{ log.Info("Initializing lotus storage miner") log.Info("Checking proof parameters") - if err := build.GetParams(true, cctx.String("gateway")); err != nil { + if err := build.GetParams(true); err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index d6a2afac1..b6aad1d73 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -65,11 +65,6 @@ func main() { EnvVars: []string{"LOTUS_STORAGE_PATH"}, Value: "~/.lotusstorage", // TODO: Consider XDG_DATA_HOME }, - &cli.StringFlag{ - Name: "gateway", - EnvVars: []string{"GATE_WAY"}, - Value: build.GateWay, - }, }, Commands: append(local, lcli.Commands...), diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 717047bbd..d0806eb16 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -34,7 +34,7 @@ var runCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if err := build.GetParams(true, cctx.String("gateway")); err != nil { + if err := build.GetParams(true); err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 1a08320e3..62b579eb1 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -58,7 +58,7 @@ var DaemonCmd = &cli.Command{ return err } - if err := build.GetParams(false, cctx.String("gateway")); err != nil { + if err := build.GetParams(false); err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index f6797a43d..38fc478ac 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -55,11 +55,6 @@ func main() { Hidden: true, Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME }, - &cli.StringFlag{ - Name: "gateway", - EnvVars: []string{"GATE_WAY"}, - Value: build.GateWay, - }, }, Commands: append(local, lcli.Commands...), diff --git a/lib/sectorbuilder/sectorbuilder_test.go b/lib/sectorbuilder/sectorbuilder_test.go index 92cac305d..b40a0b9cd 100644 --- a/lib/sectorbuilder/sectorbuilder_test.go +++ b/lib/sectorbuilder/sectorbuilder_test.go @@ -22,7 +22,7 @@ func TestSealAndVerify(t *testing.T) { t.Skip("this is slow") build.SectorSizes = []uint64{sectorSize} - if err := build.GetParams(true, build.GateWay); err != nil { + if err := build.GetParams(true); err != nil { t.Fatal(err) }