mirror of
https://github.com/fosrl/olm.git
synced 2026-03-03 01:06:49 +00:00
feat(api): add fingerprint + posture fields to client state
Former-commit-id: 566084683a
This commit is contained in:
committed by
Owen Schwartz
parent
1ecb97306f
commit
69952ee5c5
67
olm/olm.go
67
olm/olm.go
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fosrl/newt/bind"
|
||||
@@ -51,6 +52,11 @@ type Olm struct {
|
||||
olmConfig OlmConfig
|
||||
tunnelConfig TunnelConfig
|
||||
|
||||
// Metadata to send alongside pings
|
||||
fingerprint map[string]any
|
||||
postures map[string]any
|
||||
metaMu sync.Mutex
|
||||
|
||||
stopRegister func()
|
||||
stopPeerSend func()
|
||||
updateRegister func(newData any)
|
||||
@@ -229,6 +235,20 @@ func (o *Olm) registerAPICallbacks() {
|
||||
logger.Info("Received switch organization request via HTTP: orgID=%s", req.OrgID)
|
||||
return o.SwitchOrg(req.OrgID)
|
||||
},
|
||||
// onMetadataChange
|
||||
func(req api.MetadataChangeRequest) error {
|
||||
logger.Info("Received change metadata request via API")
|
||||
|
||||
if req.Fingerprint != nil {
|
||||
o.SetFingerprint(req.Fingerprint)
|
||||
}
|
||||
|
||||
if req.Postures != nil {
|
||||
o.SetPostures(req.Postures)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
// onDisconnect
|
||||
func() error {
|
||||
logger.Info("Processing disconnect request via API")
|
||||
@@ -404,6 +424,19 @@ func (o *Olm) StartTunnel(config TunnelConfig) {
|
||||
}
|
||||
})
|
||||
|
||||
fingerprint := config.InitialFingerprint
|
||||
if fingerprint == nil {
|
||||
fingerprint = make(map[string]any)
|
||||
}
|
||||
|
||||
postures := config.InitialPostures
|
||||
if postures == nil {
|
||||
postures = make(map[string]any)
|
||||
}
|
||||
|
||||
o.SetFingerprint(fingerprint)
|
||||
o.SetPostures(postures)
|
||||
|
||||
// Connect to the WebSocket server
|
||||
if err := olmClient.Connect(); err != nil {
|
||||
logger.Error("Failed to connect to server: %v", err)
|
||||
@@ -577,28 +610,16 @@ func (o *Olm) SwitchOrg(orgID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Olm) AddDevice(fd uint32) error {
|
||||
if o.middleDev == nil {
|
||||
return fmt.Errorf("middle device is not initialized")
|
||||
}
|
||||
func (o *Olm) SetFingerprint(data map[string]any) {
|
||||
o.metaMu.Lock()
|
||||
defer o.metaMu.Unlock()
|
||||
|
||||
if o.tunnelConfig.MTU == 0 {
|
||||
return fmt.Errorf("tunnel MTU is not set")
|
||||
}
|
||||
|
||||
tdev, err := olmDevice.CreateTUNFromFD(fd, o.tunnelConfig.MTU)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create TUN device from fd: %v", err)
|
||||
}
|
||||
|
||||
// Update interface name if available
|
||||
if realInterfaceName, err2 := tdev.Name(); err2 == nil {
|
||||
o.tunnelConfig.InterfaceName = realInterfaceName
|
||||
}
|
||||
|
||||
// Replace the existing TUN device in the middle device with the new one
|
||||
o.middleDev.AddDevice(tdev)
|
||||
|
||||
logger.Info("Added device from file descriptor %d", fd)
|
||||
return nil
|
||||
o.fingerprint = data
|
||||
}
|
||||
|
||||
func (o *Olm) SetPostures(data map[string]any) {
|
||||
o.metaMu.Lock()
|
||||
defer o.metaMu.Unlock()
|
||||
|
||||
o.postures = data
|
||||
}
|
||||
|
||||
@@ -67,5 +67,8 @@ type TunnelConfig struct {
|
||||
OverrideDNS bool
|
||||
TunnelDNS bool
|
||||
|
||||
InitialFingerprint map[string]any
|
||||
InitialPostures map[string]any
|
||||
|
||||
DisableRelay bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user