Skip to content

Commit

Permalink
rhp/v4: Rename streaming RPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Oct 28, 2024
1 parent 8319d41 commit 79ba0d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
21 changes: 5 additions & 16 deletions rhp/v4/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,40 +501,29 @@ func (r *RPCReadSectorRequest) maxLen() int {

func (r *RPCReadSectorResponse) encodeTo(e *types.Encoder) {
types.EncodeSlice(e, r.Proof)
e.WriteBytes(r.Sector)
e.WriteUint64(r.DataLength)
}
func (r *RPCReadSectorResponse) decodeFrom(d *types.Decoder) {
types.DecodeSlice(d, &r.Proof)
r.Sector = d.ReadBytes()
}
func (r *RPCReadSectorResponse) maxLen() int {
return reasonableObjectSize + 8 + SectorSize
}

func (r *RPCReadSectorStreamedResponse) encodeTo(e *types.Encoder) {
panic("use RPCReadSectorResponse") // developer error
}
func (r *RPCReadSectorStreamedResponse) decodeFrom(d *types.Decoder) {
types.DecodeSlice(d, &r.Proof)
r.DataLength = d.ReadUint64()
}
func (r *RPCReadSectorStreamedResponse) maxLen() int {
func (r *RPCReadSectorResponse) maxLen() int {
return reasonableObjectSize + 8 + SectorSize
}

func (r RPCWriteSectorStreamingRequest) encodeTo(e *types.Encoder) {
func (r RPCWriteSectorRequest) encodeTo(e *types.Encoder) {
r.Prices.EncodeTo(e)
r.Token.encodeTo(e)
e.WriteUint64(r.Duration)
e.WriteUint64(r.DataLength)
}
func (r *RPCWriteSectorStreamingRequest) decodeFrom(d *types.Decoder) {
func (r *RPCWriteSectorRequest) decodeFrom(d *types.Decoder) {
r.Prices.DecodeFrom(d)
r.Token.decodeFrom(d)
r.Duration = d.ReadUint64()
r.DataLength = d.ReadUint64()
}
func (r *RPCWriteSectorStreamingRequest) maxLen() int {
func (r *RPCWriteSectorRequest) maxLen() int {
return sizeofPrices + sizeofAccountToken + 8 + 8
}

Expand Down
18 changes: 2 additions & 16 deletions rhp/v4/rhp.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,32 +416,18 @@ type (

// RPCReadSectorResponse implements Object.
RPCReadSectorResponse struct {
Proof []types.Hash256 `json:"proof"`
Sector []byte `json:"sector"`
}

// RPCReadSectorStreamedResponse implements Object.
RPCReadSectorStreamedResponse struct {
Proof []types.Hash256 `json:"proof"`
DataLength uint64 `json:"dataLength"`
}

// RPCWriteSectorStreamingRequest implements Object.
RPCWriteSectorStreamingRequest struct {
// RPCWriteSectorRequest implements Object.
RPCWriteSectorRequest struct {
Prices HostPrices `json:"prices"`
Token AccountToken `json:"token"`
Duration uint64 `json:"duration"`
DataLength uint64 `json:"dataLength"` // extended to SectorSize by host
}

// RPCWriteSectorRequest implements Object.
RPCWriteSectorRequest struct {
Prices HostPrices `json:"prices"`
Token AccountToken `json:"token"`
Duration uint64 `json:"duration"`
Sector []byte `json:"sector"` // extended to SectorSize by host
}

// RPCWriteSectorResponse implements Object.
RPCWriteSectorResponse struct {
Root types.Hash256 `json:"root"`
Expand Down
2 changes: 1 addition & 1 deletion rhp/v4/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (req *RPCReadSectorRequest) Validate(pk types.PublicKey) error {
}

// Validate validates a write sector request.
func (req *RPCWriteSectorStreamingRequest) Validate(pk types.PublicKey, maxDuration uint64) error {
func (req *RPCWriteSectorRequest) Validate(pk types.PublicKey, maxDuration uint64) error {
if err := req.Prices.Validate(pk); err != nil {
return fmt.Errorf("prices are invalid: %w", err)
} else if err := req.Token.Validate(); err != nil {
Expand Down

0 comments on commit 79ba0d1

Please sign in to comment.