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] sdHash := args[1]
s := store.NewCachingBlobStore( s := store.NewCachingBlobStore(
peer.NewStore(addr), peer.NewStore(peer.StoreOpts{Address: addr}),
store.NewDiskBlobStore("/tmp/lbry_downloaded_blobs", 2), store.NewDiskBlobStore("/tmp/lbry_downloaded_blobs", 2),
) )

View file

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