Commit 14224558 authored by David Vorick's avatar David Vorick

Merge branch 'read-cancellation-token' into 'master'

Read the cancellation token

See merge request !4552
parents 4e942b5e 9454d00c
Pipeline #152505549 failed with stages
in 29 minutes and 9 seconds
......@@ -434,8 +434,8 @@ func (p *renterHostPair) managedExecuteProgram(epr modules.RPCExecuteProgramRequ
}
// Read the cancellation token.
ct := make([]byte, modules.MDMCancellationTokenLen)
_, err = io.ReadFull(stream, ct)
var ct modules.MDMCancellationToken
err = modules.RPCRead(stream, &ct)
if err != nil {
return nil, limit, err
}
......
......@@ -109,12 +109,8 @@ func (h *Host) managedRPCExecuteProgram(stream siamux.Stream) error {
}
// Return 16 bytes of data as a placeholder for a future cancellation token.
// NOTE: We write this to a buffer to save one call to `Write`. In the
// future we might reconsider this once we actually implement cancellation
// since this means the token is only returned after the first instruction
// is done executing.
buffer := bytes.NewBuffer(nil)
_, err = buffer.Write(make([]byte, modules.MDMCancellationTokenLen))
var ct modules.MDMCancellationToken
err = modules.RPCWrite(stream, ct)
if err != nil {
return errors.AddContext(err, "Failed to write cancellation token")
}
......@@ -159,6 +155,9 @@ func (h *Host) managedRPCExecuteProgram(stream siamux.Stream) error {
// Remember that the execution wasn't successful.
executionFailed = output.Error != nil
// Create a buffer
buffer := bytes.NewBuffer(nil)
// Send the response to the peer.
err = modules.RPCWrite(buffer, resp)
if err != nil {
......
......@@ -151,7 +151,7 @@ func TestExecuteReadSectorProgram(t *testing.T) {
// this particular program on the "renter" side. This way we can test that
// the bandwidth measured by the renter is large enough to be accepted by
// the host.
expectedDownload := uint64(5840) // download
expectedDownload := uint64(7300) // download
expectedUpload := uint64(10220) // upload
downloadCost := pt.DownloadBandwidthCost.Mul64(expectedDownload)
uploadCost := pt.UploadBandwidthCost.Mul64(expectedUpload)
......@@ -439,7 +439,7 @@ func TestExecuteHasSectorProgram(t *testing.T) {
// this particular program on the "renter" side. This way we can test that
// the bandwidth measured by the renter is large enough to be accepted by
// the host.
expectedDownload := uint64(2920) // download
expectedDownload := uint64(4380) // download
expectedUpload := uint64(10220) // upload
downloadCost := pt.DownloadBandwidthCost.Mul64(expectedDownload)
uploadCost := pt.UploadBandwidthCost.Mul64(expectedUpload)
......
......@@ -25,6 +25,10 @@ type (
Program []Instruction
// ProgramData contains the raw byte data for the program.
ProgramData []byte
// MDMCancellationToken is a token that can be used to request cancellation
// of a program
MDMCancellationToken [MDMCancellationTokenLen]byte
)
const (
......
......@@ -84,6 +84,13 @@ func (w *worker) managedExecuteProgram(p modules.Program, data []byte, fcid type
return
}
// read the cancellation token.
var ct modules.MDMCancellationToken
err = modules.RPCRead(stream, &ct)
if err != nil {
return
}
// read the responses.
responses = make([]programResponse, len(epr.Program))
for i := range responses {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment