MCPcopy
hub / github.com/tailscale/tailscale / sendMapRequest

Method sendMapRequest

control/controlclient/direct.go:1062–1402  ·  view source on GitHub ↗

sendMapRequest makes a /map request to download the network map, calling cb with each new netmap. If isStreaming, it will poll forever and only returns if the context expires or the server returns an error/closes the connection and as such always returns a non-nil error. If nu is nil, OmitPeers wil

(ctx context.Context, isStreaming bool, nu NetmapUpdater)

Source from the content-addressed store, hash-verified

1060//
1061// If nu is nil, OmitPeers will be set to true.
1062func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu NetmapUpdater) error {
1063 if c.panicOnUse {
1064 panic("tainted client")
1065 }
1066 if isStreaming && nu == nil {
1067 panic("cb must be non-nil if isStreaming is true")
1068 }
1069
1070 metricMapRequests.Add(1)
1071 metricMapRequestsActive.Add(1)
1072 defer metricMapRequestsActive.Add(-1)
1073 if isStreaming {
1074 metricMapRequestsPoll.Add(1)
1075 } else {
1076 metricMapRequestsLite.Add(1)
1077 }
1078
1079 c.mu.Lock()
1080 persist := c.persist
1081 serverURL := c.serverURL
1082 serverNoiseKey := c.serverNoiseKey
1083 discoKey := c.discoPubKey
1084 hi := c.hostInfoLocked()
1085 backendLogID := hi.BackendLogID
1086 connectionHandleForTest := c.connectionHandleForTest
1087 tkaHead := c.tkaHead
1088 var epStrs []string
1089 var eps []netip.AddrPort
1090 var epTypes []tailcfg.EndpointType
1091 for _, ep := range c.endpoints {
1092 eps = append(eps, ep.Addr)
1093 epStrs = append(epStrs, ep.Addr.String())
1094 epTypes = append(epTypes, ep.Type)
1095 }
1096 c.mu.Unlock()
1097
1098 if serverNoiseKey.IsZero() {
1099 return errors.New("control server is too old; no noise key")
1100 }
1101
1102 machinePrivKey, err := c.getMachinePrivKey()
1103 if err != nil {
1104 return fmt.Errorf("getMachinePrivKey: %w", err)
1105 }
1106 if machinePrivKey.IsZero() {
1107 return errors.New("getMachinePrivKey returned zero key")
1108 }
1109
1110 if persist.PrivateNodeKey().IsZero() {
1111 return errors.New("privateNodeKey is zero")
1112 }
1113 if backendLogID == "" {
1114 return errors.New("hostinfo: BackendLogID missing")
1115 }
1116
1117 c.logf("[v1] PollNetMap: stream=%v ep=%v", isStreaming, epStrs)
1118
1119 vlogf := logger.Discard

Callers 3

PollNetMapMethod · 0.95
FetchNetMapForTestMethod · 0.95
SendUpdateMethod · 0.95

Calls 15

hostInfoLockedMethod · 0.95
getNoiseClientMethod · 0.95
StopMethod · 0.95
ResetMethod · 0.95
isUniquePingRequestMethod · 0.95
answerPingMethod · 0.95
DisabledEtcAptSourceFunction · 0.92
AddLBHeaderFunction · 0.92
encodeFunction · 0.85
newMapSessionFunction · 0.85
ignoreDialPlanFunction · 0.85

Tested by

no test coverage detected