storj/cmd/overlay/cache.go

36 lines
992 B
Go
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"fmt"
"github.com/zeebo/errs"
2019-02-14 21:55:21 +00:00
"go.uber.org/zap"
"storj.io/storj/pkg/overlay"
"storj.io/storj/satellite/satellitedb"
)
type cacheConfig struct {
NodesPath string `help:"the path to a JSON file containing an object with IP keys and nodeID values"`
Database string `help:"overlay database connection string" default:"sqlite3://$CONFDIR/master.db"`
}
func (c cacheConfig) open(ctx context.Context) (cache *overlay.Cache, dbClose func(), err error) {
2019-02-14 21:55:21 +00:00
database, err := satellitedb.New(zap.L().Named("db"), c.Database)
if err != nil {
return nil, nil, errs.New("error connecting to database: %+v", err)
}
dbClose = func() {
err := database.Close()
if err != nil {
fmt.Printf("error closing connection to database: %+v\n", err)
}
}
2018-11-16 16:31:14 +00:00
2019-03-23 08:06:11 +00:00
return overlay.NewCache(zap.L(), database.OverlayCache(), database.StatDB(), overlay.NodeSelectionConfig{}), dbClose, nil
}