2018-01-29 20:37:26 +01:00
|
|
|
package reflector
|
2017-08-11 00:25:42 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha512"
|
|
|
|
"encoding/hex"
|
2018-01-24 17:45:18 +01:00
|
|
|
|
2018-02-22 19:48:46 +01:00
|
|
|
"github.com/lbryio/lbry.go/errors"
|
2017-08-11 00:25:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DefaultPort = 5566
|
|
|
|
|
2018-01-29 20:37:26 +01:00
|
|
|
maxBlobSize = 2 * 1024 * 1024
|
2017-08-11 00:25:42 +02:00
|
|
|
|
2018-01-24 17:45:18 +01:00
|
|
|
protocolVersion1 = 0
|
|
|
|
protocolVersion2 = 1
|
2017-08-11 00:25:42 +02:00
|
|
|
)
|
|
|
|
|
2018-01-24 17:45:18 +01:00
|
|
|
var ErrBlobExists = errors.Base("blob exists on server")
|
2017-08-11 00:25:42 +02:00
|
|
|
|
|
|
|
type errorResponse struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type handshakeRequestResponse struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type sendBlobRequest struct {
|
2017-08-15 22:02:18 +02:00
|
|
|
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"`
|
2017-08-11 00:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type sendBlobResponse struct {
|
|
|
|
SendBlob bool `json:"send_blob"`
|
|
|
|
}
|
|
|
|
|
2017-08-15 22:02:18 +02:00
|
|
|
type sendSdBlobResponse struct {
|
|
|
|
SendSdBlob bool `json:"send_sd_blob"`
|
|
|
|
NeededBlobs []string `json:"needed_blobs,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-08-11 00:25:42 +02:00
|
|
|
type blobTransferResponse struct {
|
|
|
|
ReceivedBlob bool `json:"received_blob"`
|
|
|
|
}
|
|
|
|
|
2017-08-15 22:02:18 +02:00
|
|
|
type sdBlobTransferResponse struct {
|
|
|
|
ReceivedSdBlob bool `json:"received_sd_blob"`
|
|
|
|
}
|
|
|
|
|
2017-08-11 00:25:42 +02:00
|
|
|
func getBlobHash(blob []byte) string {
|
|
|
|
hashBytes := sha512.Sum384(blob)
|
|
|
|
return hex.EncodeToString(hashBytes[:])
|
|
|
|
}
|