NewFakeUserspaceEngine returns a new userspace engine for testing. The opts may contain the following types: - int or uint16: to set the ListenPort.
(logf logger.Logf, opts ...any)
| 286 | // |
| 287 | // - int or uint16: to set the ListenPort. |
| 288 | func NewFakeUserspaceEngine(logf logger.Logf, opts ...any) (Engine, error) { |
| 289 | conf := Config{ |
| 290 | RespondToPing: true, |
| 291 | } |
| 292 | for _, o := range opts { |
| 293 | switch v := o.(type) { |
| 294 | case uint16: |
| 295 | conf.ListenPort = v |
| 296 | case int: |
| 297 | if v < 0 || v > math.MaxUint16 { |
| 298 | return nil, fmt.Errorf("invalid ListenPort: %d", v) |
| 299 | } |
| 300 | conf.ListenPort = uint16(v) |
| 301 | case func(any): |
| 302 | conf.SetSubsystem = v |
| 303 | case *controlknobs.Knobs: |
| 304 | conf.ControlKnobs = v |
| 305 | case *health.Tracker: |
| 306 | conf.HealthTracker = v |
| 307 | case *usermetric.Registry: |
| 308 | conf.Metrics = v |
| 309 | case *eventbus.Bus: |
| 310 | conf.EventBus = v |
| 311 | default: |
| 312 | return nil, fmt.Errorf("unknown option type %T", v) |
| 313 | } |
| 314 | } |
| 315 | logf("Starting userspace WireGuard engine (with fake TUN device)") |
| 316 | return NewUserspaceEngine(logf, conf) |
| 317 | } |
| 318 | |
| 319 | // NewUserspaceEngine creates the named tun device and returns a |
| 320 | // Tailscale Engine running on it. |
searching dependent graphs…