MCPcopy Create free account
hub / github.com/tailscale/tailcat / Start

Method Start

tailcat.go:356–491  ·  view source on GitHub ↗

Start connects to the DERP relay and begins accepting clients, first picking defaults for any unset configuration fields: a new ephemeral key, log.Printf for logging, and the nearest region of the default DERP map.

()

Source from the content-addressed store, hash-verified

354// ephemeral key, log.Printf for logging, and the nearest region of
355// the default DERP map.
356func (s *Server) Start() error {
357 if s.lb != nil {
358 return errors.New("tailcat: Server.Start called twice")
359 }
360 logf := s.Logf
361 if logf == nil {
362 logf = log.Printf
363 }
364 priv := s.Key
365 if priv.IsZero() {
366 priv = key.NewNode()
367 }
368 reg := s.Region
369 if reg == nil {
370 ci := &ConnInfo{RegionID: cmp.Or(s.RegionID, -1)}
371 opts := []any{ExpandForServer}
372 if s.DERPMapURL != "" {
373 opts = append(opts, DERPMapURL(s.DERPMapURL))
374 }
375 if s.DERPMapCache != nil {
376 opts = append(opts, s.DERPMapCache)
377 }
378 if err := ci.Expand(context.Background(), opts...); err != nil {
379 return err
380 }
381 reg = ci.Region[0]
382 }
383 if reg.RegionID == 0 {
384 return fmt.Errorf("missing RegionID in %v", logger.AsJSON(reg))
385 }
386
387 lb := newLocoBackend(priv)
388 lb.logf = logf
389 lb.dm = &tailcfg.DERPMap{}
390 mak.Set(&lb.dm.Regions, reg.RegionID, reg)
391 for _, k := range s.AllowedClients {
392 mak.Set(&lb.allowedClients, k, true)
393 }
394
395 sys := &lb.sys
396 bus := eventbus.New()
397 sys.Set(bus)
398 sys.Set(health.NewTracker(bus))
399
400 netMon, err := netmon.New(bus, func(format string, args ...any) {
401 logf(format, args...)
402 })
403 if err != nil {
404 lb.Close() // closes the subsystems started so far
405 return fmt.Errorf("netmon.New: %w", err)
406 }
407 sys.Set(netMon)
408
409 dialer := &tsdial.Dialer{Logf: logf} // mutated below (before used)
410 sys.Set(dialer)
411
412 var store ipn.StateStore = new(mem.Store)
413 sys.Set(store)

Callers 15

setupSSHEnvFunction · 0.95
TestTailcatFunction · 0.95
TestHalfCloseFunction · 0.95
serverFunction · 0.95
TestBrowserSendsFunction · 0.95
TestBrowserSendsTextUIFunction · 0.95
tailcatListenFunction · 0.95
StartMethod · 0.45
initLockedMethod · 0.45
ensureStartedMethod · 0.45
runWithPTYFunction · 0.45

Calls 15

ExpandMethod · 0.95
buildFilterMethod · 0.95
DERPMapURLTypeAlias · 0.85
newLocoBackendFunction · 0.85
IsMeowPacketFunction · 0.85
IsMeowedPacketFunction · 0.85
ParseMeowPingFunction · 0.85
EncodeMeowedFunction · 0.85
createEngineFunction · 0.85
newNetstackFunction · 0.85
onMeowMethod · 0.80
AddrMethod · 0.80

Tested by 8

setupSSHEnvFunction · 0.76
TestTailcatFunction · 0.76
TestHalfCloseFunction · 0.76
TestBrowserSendsFunction · 0.76
TestBrowserSendsTextUIFunction · 0.76
TestPipeModeFunction · 0.36
TestSOCKSClientKeyFunction · 0.36