Skip to content

Commit

Permalink
Cleanup handshake naming in agent
Browse files Browse the repository at this point in the history
  • Loading branch information
kthomas committed Jan 9, 2024
1 parent 10799db commit 8413a3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 8 additions & 5 deletions agent-api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ import (
"github.com/nats-io/nats.go"
)

// NexExecutionProviderELF Executable Linkable Format execution provider
// Agent handshake subject
const NexAgentSubjectHandshake = "agentint.handshake"

// Executable Linkable Format execution provider
const NexExecutionProviderELF = "elf"

// NexExecutionProviderV8 V8 execution provider
// V8 execution provider
const NexExecutionProviderV8 = "v8"

// NexExecutionProviderOCI OCI execution provider
// OCI execution provider
const NexExecutionProviderOCI = "oci"

// NexExecutionProviderWasm Wasm execution provider
// Wasm execution provider
const NexExecutionProviderWasm = "wasm"

// WorkloadCacheBucket is an internal, non-public bucket for sharing files between host and agent
// Name of the internal, non-public bucket for sharing files between host and agent
const WorkloadCacheBucket = "NEXCACHE"

// DefaultRunloopSleepTimeoutMillis default number of milliseconds to sleep during execution runloops
Expand Down
10 changes: 5 additions & 5 deletions nex-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/nats-io/nats.go"
)

const NexAgentSubjectAdvertise = "agentint.handshake"
const defaultAgentHandshakeTimeoutMillis = 250
const workloadExecutionSleepTimeoutMillis = 1000

// Agent facilitates communication between the nex agent running in the firecracker VM
Expand Down Expand Up @@ -75,7 +75,7 @@ func NewAgent() (*Agent, error) {
// Start the agent
// NOTE: agent process will request vm shutdown if this fails
func (a *Agent) Start() error {
err := a.Advertise()
err := a.RequestHandshake()
if err != nil {
a.LogError(fmt.Sprintf("Failed to handshake with node: %s", err))
return err
Expand All @@ -95,17 +95,17 @@ func (a *Agent) Start() error {
return nil
}

// Publish an initial message to the host indicating the agent is "all the way" up
// Request a handshake with the host indicating the agent is "all the way" up
// NOTE: the agent process will request a VM shutdown if this fails
func (a *Agent) Advertise() error {
func (a *Agent) RequestHandshake() error {
msg := agentapi.HandshakeRequest{
MachineId: a.md.VmId,
StartTime: a.started,
Message: a.md.Message,
}
raw, _ := json.Marshal(msg)

_, err := a.nc.Request(NexAgentSubjectAdvertise, raw, 100*time.Millisecond)
_, err := a.nc.Request(agentapi.NexAgentSubjectHandshake, raw, time.Millisecond*defaultAgentHandshakeTimeoutMillis)
if err != nil {
a.LogError(fmt.Sprintf("Agent failed to request initial sync message: %s", err))
return err
Expand Down

0 comments on commit 8413a3a

Please sign in to comment.