Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sekulicd committed Nov 5, 2024
1 parent aaacbfd commit d9c9536
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 62 deletions.
6 changes: 6 additions & 0 deletions simulation/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.PHONY: run push-to-ecr build-client

#### Local simulation ####
## run-single: Run bundled simulation where client and server are in the same process
run-single:
@echo "Running singe process simulation..."
go run ./local/single-process/main.go

#### Remote simulation ####

# Default values for optional variables
Expand Down
2 changes: 1 addition & 1 deletion simulation/local/process-per-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (

var (
clients = make(map[string]*ClientConnection)
clientsMu sync.Mutex // Protects the clients map
clientsMu sync.Mutex
upgrader = websocket.Upgrader{}
)

Expand Down
2 changes: 1 addition & 1 deletion simulation/local/single-process/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
)

func main() {
simFile := flag.String("simulation", "simulation2.yaml", "Path to the simulation YAML file")
simFile := flag.String("simulation", "simulation.yaml", "Path to the simulation YAML file")
flag.Parse()

simulation, err := loadAndValidateSimulation(*simFile)
Expand Down
16 changes: 8 additions & 8 deletions simulation/remote/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
}

// Listen for commands from orchestrator
client.listenForCommands()
client.listenForCommands(orchestratorUrl)
}

// setupArkClient initializes the ArkClient for the client.
Expand Down Expand Up @@ -137,7 +137,7 @@ func (c *Client) sendAddress() error {
}

// listenForCommands listens for commands from the orchestrator.
func (c *Client) listenForCommands() {
func (c *Client) listenForCommands(orchestratorUrl string) {
defer c.Conn.Close()
for {
select {
Expand All @@ -152,13 +152,13 @@ func (c *Client) listenForCommands() {
return
}
// Handle the command
c.handleCommand(command)
c.handleCommand(orchestratorUrl, command)
}
}
}

// handleCommand processes a command received from the orchestrator.
func (c *Client) handleCommand(command Command) {
func (c *Client) handleCommand(orchestratorUrl string, command Command) {
switch command.Type {
case "Onboard":
amount, ok := command.Data["amount"].(float64)
Expand All @@ -181,7 +181,7 @@ func (c *Client) handleCommand(command Command) {
c.sendError("Invalid recipient in SendAsync command")
return
}
err := c.sendAsync(amount, toClientID)
err := c.sendAsync(amount, orchestratorUrl, toClientID)
if err != nil {
c.sendError(fmt.Sprintf("SendAsync failed: %v", err))
}
Expand Down Expand Up @@ -248,11 +248,11 @@ func (c *Client) onboard(amount float64) error {
}

// sendAsync sends funds asynchronously to another client.
func (c *Client) sendAsync(amount float64, toClientID string) error {
func (c *Client) sendAsync(amount float64, orchestratorUrl, toClientID string) error {
ctx := context.Background()

// Request recipient address from orchestrator
recipientAddress, err := c.requestRecipientAddress(toClientID)
recipientAddress, err := c.requestRecipientAddress(orchestratorUrl, toClientID)
if err != nil {
return err
}
Expand Down Expand Up @@ -321,7 +321,7 @@ func (c *Client) sendLog(message string) {
}

// requestRecipientAddress requests the recipient's address from the orchestrator.
func (c *Client) requestRecipientAddress(toClientID string) (string, error) {
func (c *Client) requestRecipientAddress(orchestratorUrl, toClientID string) (string, error) {
resp, err := http.Get(fmt.Sprintf("http://localhost:9000/address?client_id=%s", toClientID))
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion simulation/remote/infra/cloudformation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Resources:
nigiri start

echo "Running make push-to-ecr..."
make push-to-ecr AWS_ACCOUNT_ID=\$AWS_ACCOUNT_ID AWS_REGION=\$AWS_REGION
cd simulation & make push-to-ecr AWS_ACCOUNT_ID=\$AWS_ACCOUNT_ID AWS_REGION=\$AWS_REGION

EOF

Expand Down
Loading

0 comments on commit d9c9536

Please sign in to comment.