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.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package reflector
|
|
|
|
import (
|
|
"crypto/sha512"
|
|
"encoding/hex"
|
|
|
|
"github.com/lbryio/lbry.go/errors"
|
|
)
|
|
|
|
const (
|
|
// DefaultPort is the port the reflector server listens on if not passed in.
|
|
DefaultPort = 5566
|
|
|
|
maxBlobSize = 2 * 1024 * 1024
|
|
|
|
protocolVersion1 = 0
|
|
protocolVersion2 = 1
|
|
)
|
|
|
|
// ErrBlobExists is a default error for when a blob already exists on the reflector server.
|
|
var ErrBlobExists = errors.Base("blob exists on server")
|
|
|
|
type errorResponse struct {
|
|
Error string `json:"error"`
|
|
}
|
|
|
|
type handshakeRequestResponse struct {
|
|
Version int `json:"version"`
|
|
}
|
|
|
|
type sendBlobRequest struct {
|
|
BlobHash string `json:"blob_hash,omitempty"`
|
|
BlobSize int `json:"blob_size,omitempty"`
|
|
SdBlobHash string `json:"sd_blob_hash,omitempty"`
|
|
SdBlobSize int `json:"sd_blob_size,omitempty"`
|
|
}
|
|
|
|
type sendBlobResponse struct {
|
|
SendBlob bool `json:"send_blob"`
|
|
}
|
|
|
|
type sendSdBlobResponse struct {
|
|
SendSdBlob bool `json:"send_sd_blob"`
|
|
NeededBlobs []string `json:"needed_blobs,omitempty"`
|
|
}
|
|
|
|
type blobTransferResponse struct {
|
|
ReceivedBlob bool `json:"received_blob"`
|
|
}
|
|
|
|
type sdBlobTransferResponse struct {
|
|
ReceivedSdBlob bool `json:"received_sd_blob"`
|
|
}
|
|
|
|
func getBlobHash(blob []byte) string {
|
|
hashBytes := sha512.Sum384(blob)
|
|
return hex.EncodeToString(hashBytes[:])
|
|
}
|