-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf!: Changed tuplelist deserialization. #76
base: master
Are you sure you want to change the base?
Changes from all commits
1ea1f13
853e30e
9e8a846
f741d69
0511e55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,21 @@ | |
package castor | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/google/uuid" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
"strconv" | ||
|
||
"github.com/google/uuid" | ||
|
||
"github.com/asaskevich/govalidator" | ||
) | ||
|
||
// AbstractClient is an interface for castor tuple client. | ||
type AbstractClient interface { | ||
GetTuples(tupleCount int32, tupleType TupleType, requestID uuid.UUID) (*TupleList, error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
GetTuples(tupleCount int32, tupleType TupleType, requestID uuid.UUID) ([]byte, error) | ||
} | ||
|
||
// NewClient returns a new Castor client for the given endpoint | ||
|
@@ -48,7 +48,7 @@ const countParam = "count" | |
const reservationIDParam = "reservationId" | ||
|
||
// GetTuples retrieves a list of tuples matching the given criteria from Castor | ||
func (c *Client) GetTuples(count int32, tt TupleType, requestID uuid.UUID) (*TupleList, error) { | ||
func (c *Client) GetTuples(count int32, tt TupleType, requestID uuid.UUID) ([]byte, error) { | ||
values := url.Values{} | ||
values.Add(tupleTypeParam, tt.Name) | ||
values.Add(countParam, strconv.Itoa(int(count))) | ||
|
@@ -66,17 +66,16 @@ func (c *Client) GetTuples(count int32, tt TupleType, requestID uuid.UUID) (*Tup | |
if err != nil { | ||
return nil, fmt.Errorf("communication with castor failed: %s", err) | ||
} | ||
bodyBytes, err := ioutil.ReadAll(resp.Body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly as an additional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one could utilize io.Copy for implementation |
||
if resp.StatusCode != http.StatusOK { | ||
bodyBytes, err := ioutil.ReadAll(resp.Body) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
return nil, fmt.Errorf("getting tuples failed for \"%s\" with response code #%d: %s", req.URL, resp.StatusCode, string(bodyBytes)) | ||
} | ||
tuples := &TupleList{} | ||
err = json.NewDecoder(resp.Body).Decode(tuples) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's unnecessary code now, isn't it? |
||
return nil, fmt.Errorf("castor has returned an invalid response body: %s", err) | ||
} | ||
return tuples, nil | ||
return bodyBytes, nil | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update Copyright header |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update Copyright header |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
package io | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/binary" | ||
"errors" | ||
"fmt" | ||
|
@@ -273,15 +272,11 @@ func (ts *CastorTupleStreamer) bufferData(terminateCh chan struct{}, streamerErr | |
func (ts *CastorTupleStreamer) getTupleData() ([]byte, error) { | ||
requestID := uuid.NewMD5(ts.baseRequestID, []byte(strconv.Itoa(ts.requestCycle))) | ||
ts.requestCycle++ | ||
tupleList, err := ts.castorClient.GetTuples(ts.stockSize, ts.tupleType, requestID) | ||
tupleData, err := ts.castorClient.GetTuples(ts.stockSize, ts.tupleType, requestID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ts.logger.Debugw("Fetched new tuples from Castor", "RequestID", requestID) | ||
tupleData, err := ts.tupleListToByteArray(tupleList) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should at least check whether received data fits to the requested tuple parameters (length of array equals number of requested tuples x length of requested tuple type, or sth like that) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must be part of the client if |
||
if err != nil { | ||
return nil, fmt.Errorf("error parsing received tuple list: %v", err) | ||
} | ||
return tupleData, nil | ||
} | ||
|
||
|
@@ -328,26 +323,6 @@ func (ts *CastorTupleStreamer) writeDataToPipe(terminateCh chan struct{}, doneCh | |
} | ||
} | ||
|
||
// tupleListToByteArray converts a given list of tuple to a byte array | ||
func (ts *CastorTupleStreamer) tupleListToByteArray(tl *castor.TupleList) ([]byte, error) { | ||
var result []byte | ||
for _, tuple := range tl.Tuples { | ||
for _, share := range tuple.Shares { | ||
decodeString, err := base64.StdEncoding.DecodeString(share.Value) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
result = append(result, decodeString...) | ||
decodeString, err = base64.StdEncoding.DecodeString(share.Mac) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
result = append(result, decodeString...) | ||
} | ||
} | ||
return result, nil | ||
} | ||
|
||
// generateHeader returns the file header for the given protocol and spdz runtime configuration | ||
func generateHeader(sp castor.SPDZProtocol, conf *SPDZEngineTypedConfig) ([]byte, error) { | ||
switch sp { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update Copyright header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update Copyright header