internal/agent/run/exposures.go
Ref: Size: 859 B History
package run
import "github.com/a73x/eitri/internal/agent/state"
// guestAddr answers a VM's current address from this agent's own records —
// exactly the answer the SSH tunnel dials, so a published port and a tunnelled
// one can never disagree about where a guest is. Empty means "no answer": the
// VM is not on this host, its record cannot be read, or its guest has not been
// given an address yet.
//
// It is asked per connection rather than once at bind, which is what makes an
// exposure created while its VM is still imaging simply start working when the
// guest comes up. Safe to call concurrently: a *state.Store is immutable after
// Open and Get only reads a record file that is written atomically.
func guestAddr(st *state.Store, vmID string) string {
rec, ok, err := st.Get(vmID)
if err != nil || !ok {
return ""
}
return rec.IP
}