reflector.go/reflector/shared.go

57 lines
1.1 KiB
Go
Raw Normal View History

2018-01-29 20:37:26 +01:00
package reflector
import (
"crypto/sha512"
"encoding/hex"
2018-02-22 19:48:46 +01:00
"github.com/lbryio/lbry.go/errors"
)
const (
DefaultPort = 5566
2018-01-29 20:37:26 +01:00
maxBlobSize = 2 * 1024 * 1024
protocolVersion1 = 0
protocolVersion2 = 1
)
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 {
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"`
}
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"`
}
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"`
}
func getBlobHash(blob []byte) string {
hashBytes := sha512.Sum384(blob)
return hex.EncodeToString(hashBytes[:])
}