Add options for peer.NewStore to allow for setting TCP timeout

This commit is contained in:
Andrey Beletsky 2019-11-22 18:53:42 +07:00
parent 86a553b876
commit 834733b675
2 changed files with 15 additions and 4 deletions

View file

@ -28,7 +28,7 @@ func getStreamCmd(cmd *cobra.Command, args []string) {
sdHash := args[1]
s := store.NewCachingBlobStore(
peer.NewStore(addr),
peer.NewStore(peer.StoreOpts{Address: addr}),
store.NewDiskBlobStore("/tmp/lbry_downloaded_blobs", 2),
)

View file

@ -1,6 +1,8 @@
package peer
import (
"time"
"github.com/lbryio/lbry.go/v2/extras/errors"
"github.com/lbryio/lbry.go/v2/stream"
)
@ -12,10 +14,19 @@ type Store struct {
connErr error
}
// StoreOpts allows to set options for a new Store.
type StoreOpts struct {
Address string
Timeout time.Duration
}
// NewStore makes a new peer store.
func NewStore(clientAddress string) *Store {
c := &Client{}
err := c.Connect(clientAddress)
func NewStore(opts StoreOpts) *Store {
if opts.Timeout == 0 {
opts.Timeout = time.Second * 5
}
c := &Client{Timeout: opts.Timeout}
err := c.Connect(opts.Address)
return &Store{client: c, connErr: err}
}