From a51cbe408167c982e22829bbad8667fee3e6ee8f Mon Sep 17 00:00:00 2001 From: yaohcn Date: Thu, 31 Oct 2019 17:41:11 +0800 Subject: [PATCH] specific ipfs gateway --- build/paramfetch.go | 14 +++++++------- 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 | 5 +++-- cmd/lotus/main.go | 5 +++++ lib/sectorbuilder/sectorbuilder_test.go | 2 +- 8 files changed, 24 insertions(+), 13 deletions(-) diff --git a/build/paramfetch.go b/build/paramfetch.go index abfeca08b..97ae76d74 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) error { +func GetParams(storage bool, gateway string) error { if err := os.Mkdir(paramdir, 0755); err != nil && !os.IsExist(err) { return err } @@ -59,13 +59,13 @@ func GetParams(storage bool) error { continue } - ft.maybeFetchAsync(name, info) + ft.maybeFetchAsync(name, info, gateway) } return ft.wait() } -func (ft *fetch) maybeFetchAsync(name string, info paramFile) { +func (ft *fetch) maybeFetchAsync(name string, info paramFile, gateway string) { ft.wg.Add(1) go func() { @@ -84,7 +84,7 @@ func (ft *fetch) maybeFetchAsync(name string, info paramFile) { ft.fetchLk.Lock() defer ft.fetchLk.Unlock() - if err := doFetch(path, info); err != nil { + if err := doFetch(path, info, gateway); err != nil { ft.errs = append(ft.errs, xerrors.Errorf("fetching file %s: %w", path, err)) } }() @@ -116,8 +116,8 @@ func (ft *fetch) wait() error { return multierr.Combine(ft.errs...) } -func doFetch(out string, info paramFile) error { - log.Infof("Fetching %s", out) +func doFetch(out string, info paramFile, gateway string) error { + log.Infof("Fetching %s from %s", out, gateway) resp, err := http.Get(gateway + info.Cid) if err != nil { diff --git a/cli/params.go b/cli/params.go index 6f6017ca3..8aadebe58 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); err != nil { + if err := build.GetParams(true, cctx.String("gateway")); 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 54d488a1b..a6d5e7527 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); err != nil { + if err := build.GetParams(true, cctx.String("gateway")); 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 b6aad1d73..d6a2afac1 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -65,6 +65,11 @@ 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 d0806eb16..717047bbd 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); err != nil { + if err := build.GetParams(true, cctx.String("gateway")); err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index c9b736c72..1a08320e3 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -4,9 +4,10 @@ package main import ( "context" - "github.com/filecoin-project/lotus/peermgr" "io/ioutil" + "github.com/filecoin-project/lotus/peermgr" + "github.com/multiformats/go-multiaddr" "golang.org/x/xerrors" "gopkg.in/urfave/cli.v2" @@ -57,7 +58,7 @@ var DaemonCmd = &cli.Command{ return err } - if err := build.GetParams(false); err != nil { + if err := build.GetParams(false, cctx.String("gateway")); err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index 38fc478ac..f6797a43d 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -55,6 +55,11 @@ 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 b40a0b9cd..92cac305d 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); err != nil { + if err := build.GetParams(true, build.GateWay); err != nil { t.Fatal(err) }