mirror of
https://github.com/fosrl/olm.git
synced 2026-03-02 00:36:44 +00:00
Include fingerprint and posture info in ping
Former-commit-id: f061596e5b
This commit is contained in:
@@ -315,6 +315,14 @@ func (o *Olm) StartTunnel(config TunnelConfig) {
|
|||||||
config.Endpoint,
|
config.Endpoint,
|
||||||
30, // 30 seconds
|
30, // 30 seconds
|
||||||
config.PingTimeoutDuration,
|
config.PingTimeoutDuration,
|
||||||
|
websocket.WithPingDataProvider(func() map[string]any {
|
||||||
|
o.metaMu.Lock()
|
||||||
|
defer o.metaMu.Unlock()
|
||||||
|
return map[string]any{
|
||||||
|
"fingerprint": o.fingerprint,
|
||||||
|
"postures": o.postures,
|
||||||
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Failed to create olm: %v", err)
|
logger.Error("Failed to create olm: %v", err)
|
||||||
|
|||||||
@@ -96,9 +96,10 @@ type Client struct {
|
|||||||
exitNodes []ExitNode // Cached exit nodes from token response
|
exitNodes []ExitNode // Cached exit nodes from token response
|
||||||
tokenMux sync.RWMutex // Protects token and exitNodes
|
tokenMux sync.RWMutex // Protects token and exitNodes
|
||||||
forceNewToken bool // Flag to force fetching a new token on next connection
|
forceNewToken bool // Flag to force fetching a new token on next connection
|
||||||
processingMessage bool // Flag to track if a message is currently being processed
|
processingMessage bool // Flag to track if a message is currently being processed
|
||||||
processingMux sync.RWMutex // Protects processingMessage
|
processingMux sync.RWMutex // Protects processingMessage
|
||||||
processingWg sync.WaitGroup // WaitGroup to wait for message processing to complete
|
processingWg sync.WaitGroup // WaitGroup to wait for message processing to complete
|
||||||
|
getPingData func() map[string]any // Callback to get additional ping data
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientOption func(*Client)
|
type ClientOption func(*Client)
|
||||||
@@ -134,6 +135,13 @@ func WithTLSConfig(config TLSConfig) ClientOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPingDataProvider sets a callback to provide additional data for ping messages
|
||||||
|
func WithPingDataProvider(fn func() map[string]any) ClientOption {
|
||||||
|
return func(c *Client) {
|
||||||
|
c.getPingData = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) OnConnect(callback func() error) {
|
func (c *Client) OnConnect(callback func() error) {
|
||||||
c.onConnect = callback
|
c.onConnect = callback
|
||||||
}
|
}
|
||||||
@@ -670,12 +678,19 @@ func (c *Client) pingMonitor() {
|
|||||||
configVersion := c.configVersion
|
configVersion := c.configVersion
|
||||||
c.configVersionMux.RUnlock()
|
c.configVersionMux.RUnlock()
|
||||||
|
|
||||||
|
pingData := map[string]any{
|
||||||
|
"timestamp": time.Now().Unix(),
|
||||||
|
"userToken": c.config.UserToken,
|
||||||
|
}
|
||||||
|
if c.getPingData != nil {
|
||||||
|
for k, v := range c.getPingData() {
|
||||||
|
pingData[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pingMsg := WSMessage{
|
pingMsg := WSMessage{
|
||||||
Type: "olm/ping",
|
Type: "olm/ping",
|
||||||
Data: map[string]any{
|
Data: pingData,
|
||||||
"timestamp": time.Now().Unix(),
|
|
||||||
"userToken": c.config.UserToken,
|
|
||||||
},
|
|
||||||
ConfigVersion: configVersion,
|
ConfigVersion: configVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user