Separate the agent from the olm version

This commit is contained in:
Owen
2026-10-22 15:09:05 -04:00
parent 256143adea
commit 71625bf11d
4 changed files with 51 additions and 13 deletions
+2 -1
View File
@@ -238,7 +238,8 @@ func runOlmMainWithArgs(ctx context.Context, cancel context.CancelFunc, signalCt
SocketPath: config.SocketPath,
Version: config.Version,
Agent: "Olm CLI",
OnExit: cancel, // Pass cancel function directly to trigger shutdown
OlmVersion: config.Version, // the standalone binary is olm itself
OnExit: cancel, // Pass cancel function directly to trigger shutdown
OnTerminated: cancel,
PprofAddr: ":4444", // TODO: REMOVE OR MAKE CONFIGURABLE
// Re-invoke this binary in watchdog mode to clean up DNS if we die.
+15 -11
View File
@@ -288,6 +288,8 @@ func Init(ctx context.Context, config OlmConfig) (*Olm, error) {
apiServer.SetVersion(config.Version)
apiServer.SetAgent(config.Agent)
config.OlmVersion = resolveOlmVersion(config)
newOlm := &Olm{
logFile: logFile,
olmCtx: ctx,
@@ -727,16 +729,17 @@ func (o *Olm) StartTunnel(config TunnelConfig) {
publicKey := o.privateKey.PublicKey()
logger.Debug("Sending registration message to server with public key: %s, relay: %v, pingResults: %+v", publicKey, !config.Holepunch, pingResults)
o.stopRegister, o.updateRegister = o.websocket.SendMessageInterval("olm/wg/register", map[string]any{
"publicKey": publicKey.String(),
"relay": !config.Holepunch,
"olmVersion": o.olmConfig.Version,
"olmAgent": o.olmConfig.Agent,
"orgId": config.OrgID,
"userToken": userToken,
"fingerprint": o.fingerprint,
"postures": o.postures,
"pingResults": pingResults,
"chainId": generateChainId(), // use a random chainId for registration updates - it won't be used for cancellation since registration is a one-time message but for tracking the session
"publicKey": publicKey.String(),
"relay": !config.Holepunch,
"olmVersion": o.olmConfig.OlmVersion,
"olmAgent": o.olmConfig.Agent,
"agentVersion": o.olmConfig.Version,
"orgId": config.OrgID,
"userToken": userToken,
"fingerprint": o.fingerprint,
"postures": o.postures,
"pingResults": pingResults,
"chainId": generateChainId(), // use a random chainId for registration updates - it won't be used for cancellation since registration is a one-time message but for tracking the session
}, 2*time.Second, 20) // after 18 tries on the server side we send the error so dont change this without changing that
})
@@ -786,8 +789,9 @@ func (o *Olm) StartTunnel(config TunnelConfig) {
if err := o.websocket.SendMessage("olm/wg/register", map[string]any{
"publicKey": publicKey.String(),
"relay": !config.Holepunch,
"olmVersion": o.olmConfig.Version,
"olmVersion": o.olmConfig.OlmVersion,
"olmAgent": o.olmConfig.Agent,
"agentVersion": o.olmConfig.Version,
"orgId": config.OrgID,
"userToken": userToken,
"fingerprint": o.fingerprint,
+4 -1
View File
@@ -82,8 +82,11 @@ type OlmConfig struct {
EnableAPI bool
HTTPAddr string
SocketPath string
Version string
Version string // version of the agent (the app embedding olm)
Agent string
// OlmVersion is the version of the github.com/fosrl/olm module itself.
// Optional: when empty it is read from the binary's build info.
OlmVersion string
WakeUpDebounce time.Duration
+30
View File
@@ -0,0 +1,30 @@
package olm
import (
"runtime/debug"
"strings"
)
// olmModulePath is the module path of this package, used to find its version
// in the build info of a binary that embeds olm (the CLI, Pangolin Windows, ...).
const olmModulePath = "github.com/fosrl/olm"
// resolveOlmVersion returns the version of the olm module this binary was
// built with, as opposed to config.Version which is the embedding agent's
// version. It prefers config.OlmVersion, then the module version from the
// binary's build info, and returns "" if neither is available.
func resolveOlmVersion(config OlmConfig) string {
if config.OlmVersion != "" {
return config.OlmVersion
}
if bi, ok := debug.ReadBuildInfo(); ok {
for _, dep := range bi.Deps {
if dep.Path == olmModulePath {
return strings.TrimPrefix(dep.Version, "v")
}
}
}
return ""
}