Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions agent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package agent

import (
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -44,7 +46,9 @@ type agentService struct {
}

const socketPath = "unix_socket"
const pyRuntime = "python3"

// const pyRuntime = "python3"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code?

const pyRuntime = "/home/darko/anaconda3/bin/python"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded?


var _ Service = (*agentService)(nil)

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
cli.SetSDK(sdk)

rootCmd := &cobra.Command{
Use: "agent-cli [command]",
Use: "cocos-cli [command]",
Short: "CLI application for Computation Service API",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("CLI application for Computation Service API\n\n")
Expand Down
2 changes: 1 addition & 1 deletion test/manual/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Do this both on the host machine and in the VM.
```sh
apt update
apt install python3-pip
pip3 install pandas sklearn scikit-learn
pip3 install pandas scikit-learn
```

### Agent-CLI interaction
Expand Down