specific ipfs gateway

This commit is contained in:
yaohcn 2019-10-31 17:41:11 +08:00
parent 790ac7b510
commit a51cbe4081
8 changed files with 24 additions and 13 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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...),

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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...),

View File

@ -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)
}