35f98ce162
-Added travis support -updated travis to analyze code beneath the root. -refactored upload.go to fix travis errors. -gocyclo should ignore test files. $GOFILES needed to be adjusted. -fix rows.Close() ignoring error. Created func to handle so defer can be used when needed also. -fixed ignored errors. -fixed unit test that was not passing correctly to anonymous function. -fixed govet error for passing param inside go func. -removed returned error, in favor of logging instead. -added error logging for ignored error. -fixed potential race conditions. -removed unused append -fixed time usage to align with go standards. -removed unused variables -made changes for code review. -code comments for exported functions. -Documented bitmap.go and insert into contact list. -Documented dht, message, bootstrap -Fixed comment typos -Documented message,node, routing_table, testing in DHT package. -Documented server, client, prism, server and shared in peer and reflector packages. -Documented the stores in Store package. -made defer adjustments inline and deleted the separate function. -adjusted method in upload to take the only parameter it requires.
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package store
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/lbryio/lbry.go/errors"
|
|
"github.com/lbryio/reflector.go/db"
|
|
"github.com/lbryio/reflector.go/types"
|
|
)
|
|
|
|
// DBBackedS3Store is an instance of an S3 Store that is backed by a DB for what is stored.
|
|
type DBBackedS3Store struct {
|
|
s3 *S3BlobStore
|
|
db db.DB
|
|
}
|
|
|
|
// NewDBBackedS3Store returns an initialized store pointer.
|
|
func NewDBBackedS3Store(s3 *S3BlobStore, db db.DB) *DBBackedS3Store {
|
|
return &DBBackedS3Store{s3: s3, db: db}
|
|
}
|
|
|
|
// Has returns T/F or Error ( if the DB errors ) if store contains the blob.
|
|
func (d *DBBackedS3Store) Has(hash string) (bool, error) {
|
|
return d.db.HasBlob(hash)
|
|
}
|
|
|
|
// Get returns the byte slice of the blob or an error.
|
|
func (d *DBBackedS3Store) Get(hash string) ([]byte, error) {
|
|
return d.s3.Get(hash)
|
|
}
|
|
|
|
// Put stores the blob in the S3 store and stores the blob information in the DB.
|
|
func (d *DBBackedS3Store) Put(hash string, blob []byte) error {
|
|
err := d.s3.Put(hash, blob)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return d.db.AddBlob(hash, len(blob), true)
|
|
}
|
|
|
|
// PutSD stores the SDBlob in the S3 store. It will return an error if the sd blob is missing the stream hash or if
|
|
// there is an error storing the blob information in the DB.
|
|
func (d *DBBackedS3Store) PutSD(hash string, blob []byte) error {
|
|
var blobContents types.SdBlob
|
|
err := json.Unmarshal(blob, &blobContents)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if blobContents.StreamHash == "" {
|
|
return errors.Err("sd blob is missing stream hash")
|
|
}
|
|
|
|
err = d.s3.PutSD(hash, blob)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return d.db.AddSDBlob(hash, len(blob), blobContents)
|
|
}
|