use IPFS_GATEWAY
This commit is contained in:
parent
a51cbe4081
commit
9c57ca03d9
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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...),
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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...),
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user