-
Notifications
You must be signed in to change notification settings - Fork 0
Return comp, algo, data hash on compu run and algo and data upload #48
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
Open
darkodraskovic
wants to merge
1
commit into
main
Choose a base branch
from
hash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ package agent | |
|
|
||
| import ( | ||
| "context" | ||
| "crypto/sha256" | ||
| "encoding/hex" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
@@ -44,7 +46,9 @@ type agentService struct { | |
| } | ||
|
|
||
| const socketPath = "unix_socket" | ||
| const pyRuntime = "python3" | ||
|
|
||
| // const pyRuntime = "python3" | ||
| const pyRuntime = "/home/darko/anaconda3/bin/python" | ||
|
Contributor
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. Hard-coded? |
||
|
|
||
| var _ Service = (*agentService)(nil) | ||
|
|
||
|
|
@@ -54,14 +58,19 @@ func New() Service { | |
| } | ||
|
|
||
| func (as *agentService) Run(ctx context.Context, cmp Computation) (string, error) { | ||
| cmpJSON, err := json.Marshal(cmp) | ||
| cmpSlice, err := json.Marshal(cmp) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| as.computation = cmp | ||
|
|
||
| return string(cmpJSON), nil // return the JSON string as the function's string return value | ||
| // Calculate the SHA-256 hash of the algorithm | ||
| hash := sha256.Sum256(cmpSlice) | ||
| cmpHash := hex.EncodeToString(hash[:]) | ||
|
|
||
| // Return the algorithm hash or an error | ||
| return cmpHash, nil | ||
| } | ||
|
|
||
| func (as *agentService) Algo(ctx context.Context, algorithm []byte) (string, error) { | ||
|
|
@@ -70,12 +79,12 @@ func (as *agentService) Algo(ctx context.Context, algorithm []byte) (string, err | |
|
|
||
| as.algorithms = append(as.algorithms, algorithm) | ||
|
|
||
| // Perform some processing on the algorithm byte array | ||
| // For example, generate a unique ID for the algorithm | ||
| algorithmID := "algo123" | ||
| // Calculate the SHA-256 hash of the algorithm | ||
| hash := sha256.Sum256(algorithm) | ||
| algorithmHash := hex.EncodeToString(hash[:]) | ||
|
|
||
| // Return the algorithm ID or an error | ||
| return algorithmID, nil | ||
| // Return the algorithm hash or an error | ||
| return algorithmHash, nil | ||
| } | ||
|
|
||
| func (as *agentService) Data(ctx context.Context, dataset []byte) (string, error) { | ||
|
|
@@ -84,12 +93,12 @@ func (as *agentService) Data(ctx context.Context, dataset []byte) (string, error | |
|
|
||
| as.datasets = append(as.datasets, dataset) | ||
|
|
||
| // Perform some processing on the dataset string | ||
| // For example, generate a unique ID for the dataset | ||
| datasetID := "dataset456" | ||
| // Calculate the SHA-256 hash of the dataset | ||
| hash := sha256.Sum256(dataset) | ||
| datasetHash := hex.EncodeToString(hash[:]) | ||
|
|
||
| // Return the dataset ID or an error | ||
| return datasetID, nil | ||
| // Return the dataset hash or an error | ||
| return datasetHash, nil | ||
| } | ||
|
|
||
| func (as *agentService) Result(ctx context.Context) ([]byte, error) { | ||
|
|
@@ -147,9 +156,9 @@ func run(algoContent []byte, dataContent []byte) ([]byte, error) { | |
| return nil, fmt.Errorf("error starting Python script: %v", err) | ||
| } | ||
|
|
||
| var receivedData []byte | ||
| var result []byte | ||
| select { | ||
| case receivedData = <-dataChannel: | ||
| case result = <-dataChannel: | ||
| case err = <-errorChannel: | ||
| return nil, fmt.Errorf("error receiving data: %v", err) | ||
| } | ||
|
|
@@ -158,5 +167,5 @@ func run(algoContent []byte, dataContent []byte) ([]byte, error) { | |
| return nil, fmt.Errorf("python script execution error: %v", err) | ||
| } | ||
|
|
||
| return receivedData, nil | ||
| return result, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Dead code?