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") var log = logging.Logger("build")
//const gateway = "http://198.211.99.118/ipfs/" //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" const paramdir = "/var/tmp/filecoin-proof-parameters"
type paramFile struct { type paramFile struct {
@ -37,7 +37,7 @@ type fetch struct {
errs []error 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) { if err := os.Mkdir(paramdir, 0755); err != nil && !os.IsExist(err) {
return err return err
} }
@ -59,13 +59,13 @@ func GetParams(storage bool) error {
continue continue
} }
ft.maybeFetchAsync(name, info) ft.maybeFetchAsync(name, info, gateway)
} }
return ft.wait() 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) ft.wg.Add(1)
go func() { go func() {
@ -84,7 +84,7 @@ func (ft *fetch) maybeFetchAsync(name string, info paramFile) {
ft.fetchLk.Lock() ft.fetchLk.Lock()
defer ft.fetchLk.Unlock() 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)) 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...) return multierr.Combine(ft.errs...)
} }
func doFetch(out string, info paramFile) error { func doFetch(out string, info paramFile, gateway string) error {
log.Infof("Fetching %s", out) log.Infof("Fetching %s from %s", out, gateway)
resp, err := http.Get(gateway + info.Cid) resp, err := http.Get(gateway + info.Cid)
if err != nil { if err != nil {

View File

@ -10,7 +10,7 @@ var fetchParamCmd = &cli.Command{
Name: "fetch-params", Name: "fetch-params",
Usage: "Fetch proving parameters", Usage: "Fetch proving parameters",
Action: func(cctx *cli.Context) error { 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) 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("Initializing lotus storage miner")
log.Info("Checking proof parameters") 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) return xerrors.Errorf("fetching proof parameters: %w", err)
} }

View File

@ -65,6 +65,11 @@ func main() {
EnvVars: []string{"LOTUS_STORAGE_PATH"}, EnvVars: []string{"LOTUS_STORAGE_PATH"},
Value: "~/.lotusstorage", // TODO: Consider XDG_DATA_HOME Value: "~/.lotusstorage", // TODO: Consider XDG_DATA_HOME
}, },
&cli.StringFlag{
Name: "gateway",
EnvVars: []string{"GATE_WAY"},
Value: build.GateWay,
},
}, },
Commands: append(local, lcli.Commands...), Commands: append(local, lcli.Commands...),

View File

@ -34,7 +34,7 @@ var runCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { 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) return xerrors.Errorf("fetching proof parameters: %w", err)
} }

View File

@ -4,9 +4,10 @@ package main
import ( import (
"context" "context"
"github.com/filecoin-project/lotus/peermgr"
"io/ioutil" "io/ioutil"
"github.com/filecoin-project/lotus/peermgr"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -57,7 +58,7 @@ var DaemonCmd = &cli.Command{
return err 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) return xerrors.Errorf("fetching proof parameters: %w", err)
} }

View File

@ -55,6 +55,11 @@ func main() {
Hidden: true, Hidden: true,
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
}, },
&cli.StringFlag{
Name: "gateway",
EnvVars: []string{"GATE_WAY"},
Value: build.GateWay,
},
}, },
Commands: append(local, lcli.Commands...), Commands: append(local, lcli.Commands...),

View File

@ -22,7 +22,7 @@ func TestSealAndVerify(t *testing.T) {
t.Skip("this is slow") t.Skip("this is slow")
build.SectorSizes = []uint64{sectorSize} build.SectorSizes = []uint64{sectorSize}
if err := build.GetParams(true); err != nil { if err := build.GetParams(true, build.GateWay); err != nil {
t.Fatal(err) t.Fatal(err)
} }