Skip to content

Commit

Permalink
fixed a few reflector issues, added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lyoshenka committed Aug 9, 2018
1 parent 3855d5c commit 73f3ace
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 189 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@
[[constraint]]
branch = "master"
name = "github.com/uber-go/atomic"

[[constraint]]
branch = "master"
name = "github.com/phayes/freeport"
6 changes: 4 additions & 2 deletions cmd/reflector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/lbryio/reflector.go/db"
"github.com/lbryio/reflector.go/reflector"
"github.com/lbryio/reflector.go/store"
log "github.com/sirupsen/logrus"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -26,7 +26,9 @@ func init() {
func reflectorCmd(cmd *cobra.Command, args []string) {
db := new(db.SQL)
err := db.Connect(globalConfig.DBConn)
checkErr(err)
if err != nil {
log.Fatal(err)
}

s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
combo := store.NewDBBackedS3Store(s3, db)
Expand Down
1 change: 1 addition & 0 deletions dht/dht_announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/lbryio/lbry.go/errors"
"github.com/lbryio/reflector.go/dht/bits"

"golang.org/x/time/rate"
)

Expand Down
15 changes: 10 additions & 5 deletions reflector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
log "github.com/sirupsen/logrus"
)

// ErrBlobExists is a default error for when a blob already exists on the reflector server.
var ErrBlobExists = errors.Base("blob exists on server")

// Client is an instance of a client connected to a server.
type Client struct {
conn net.Conn
Expand All @@ -18,7 +21,7 @@ type Client struct {
// Connect connects to a specific clients and errors if it cannot be contacted.
func (c *Client) Connect(address string) error {
var err error
c.conn, err = net.Dial("tcp", address)
c.conn, err = net.Dial(network, address)
if err != nil {
return err
}
Expand All @@ -38,8 +41,10 @@ func (c *Client) SendBlob(blob []byte) error {
return errors.Err("not connected")
}

if len(blob) != maxBlobSize {
return errors.Err("blob must be exactly " + strconv.Itoa(maxBlobSize) + " bytes")
if len(blob) > maxBlobSize {
return errors.Err("blob must be at most " + strconv.Itoa(maxBlobSize) + " bytes")
} else if len(blob) == 0 {
return errors.Err("blob is empty")
}

blobHash := getBlobHash(blob)
Expand All @@ -50,6 +55,7 @@ func (c *Client) SendBlob(blob []byte) error {
if err != nil {
return err
}

_, err = c.conn.Write(sendRequest)
if err != nil {
return err
Expand Down Expand Up @@ -102,8 +108,7 @@ func (c *Client) doHandshake(version int) error {
}

var resp handshakeRequestResponse
dec := json.NewDecoder(c.conn)
err = dec.Decode(&resp)
err = json.NewDecoder(c.conn).Decode(&resp)
if err != nil {
return err
} else if resp.Version != version {
Expand Down
70 changes: 0 additions & 70 deletions reflector/client_test.go

This file was deleted.

Loading

0 comments on commit 73f3ace

Please sign in to comment.