From 834733b6756610222747358eab3458284804d934 Mon Sep 17 00:00:00 2001 From: Andrey Beletsky Date: Fri, 22 Nov 2019 18:53:42 +0700 Subject: [PATCH] Add options for peer.NewStore to allow for setting TCP timeout --- cmd/getstream.go | 2 +- peer/store.go | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/getstream.go b/cmd/getstream.go index 7a2f217..a009ab2 100644 --- a/cmd/getstream.go +++ b/cmd/getstream.go @@ -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), ) diff --git a/peer/store.go b/peer/store.go index a8dee0b..2917d1b 100644 --- a/peer/store.go +++ b/peer/store.go @@ -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} }