use new connections for each action
reduce timeout
This commit is contained in:
parent
a80599413c
commit
e0da2674a1
2 changed files with 20 additions and 15 deletions
|
@ -59,12 +59,12 @@ func reflectorCmd(cmd *cobra.Command, args []string) {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
blobStore = peer.NewStore(peer.StoreOpts{
|
blobStore = peer.NewStore(peer.StoreOpts{
|
||||||
Address: reflectorServerAddress + ":" + reflectorServerPort,
|
Address: reflectorServerAddress + ":" + reflectorServerPort,
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
})
|
})
|
||||||
case "udp":
|
case "udp":
|
||||||
blobStore = quic.NewStore(quic.StoreOpts{
|
blobStore = quic.NewStore(quic.StoreOpts{
|
||||||
Address: reflectorServerAddress + ":" + reflectorServerPort,
|
Address: reflectorServerAddress + ":" + reflectorServerPort,
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,8 +10,7 @@ import (
|
||||||
// Store is a blob store that gets blobs from a peer.
|
// Store is a blob store that gets blobs from a peer.
|
||||||
// It satisfies the store.BlobStore interface but cannot put or delete blobs.
|
// It satisfies the store.BlobStore interface but cannot put or delete blobs.
|
||||||
type Store struct {
|
type Store struct {
|
||||||
client *Client
|
opts StoreOpts
|
||||||
connErr error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StoreOpts allows to set options for a new Store.
|
// StoreOpts allows to set options for a new Store.
|
||||||
|
@ -22,27 +21,33 @@ type StoreOpts struct {
|
||||||
|
|
||||||
// NewStore makes a new peer store.
|
// NewStore makes a new peer store.
|
||||||
func NewStore(opts StoreOpts) *Store {
|
func NewStore(opts StoreOpts) *Store {
|
||||||
c := &Client{Timeout: opts.Timeout}
|
return &Store{opts: opts}
|
||||||
err := c.Connect(opts.Address)
|
}
|
||||||
return &Store{client: c, connErr: err}
|
|
||||||
|
func (p *Store) getClient() (*Client, error) {
|
||||||
|
c := &Client{Timeout: p.opts.Timeout}
|
||||||
|
err := c.Connect(p.opts.Address)
|
||||||
|
return c, errors.Prefix("connection error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has asks the peer if they have a hash
|
// Has asks the peer if they have a hash
|
||||||
func (p *Store) Has(hash string) (bool, error) {
|
func (p *Store) Has(hash string) (bool, error) {
|
||||||
if p.connErr != nil {
|
c, err := p.getClient()
|
||||||
return false, errors.Prefix("connection error", p.connErr)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
}
|
}
|
||||||
|
defer c.Close()
|
||||||
return p.client.HasBlob(hash)
|
return c.HasBlob(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get downloads the blob from the peer
|
// Get downloads the blob from the peer
|
||||||
func (p *Store) Get(hash string) (stream.Blob, error) {
|
func (p *Store) Get(hash string) (stream.Blob, error) {
|
||||||
if p.connErr != nil {
|
c, err := p.getClient()
|
||||||
return nil, errors.Prefix("connection error", p.connErr)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer c.Close()
|
||||||
return p.client.GetBlob(hash)
|
return c.GetBlob(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put is not supported
|
// Put is not supported
|
||||||
|
|
Loading…
Reference in a new issue