MCPcopy
hub / github.com/tailscale/tailscale / netmap

Method netmap

control/controlclient/map.go:1228–1285  ·  view source on GitHub ↗

netmap returns a fully populated NetworkMap from the last state seen from a call to updateStateFromResponse, filling in omitted information from prior MapResponse values.

()

Source from the content-addressed store, hash-verified

1226// a call to updateStateFromResponse, filling in omitted
1227// information from prior MapResponse values.
1228func (ms *mapSession) netmap() *netmap.NetworkMap {
1229 peerViews := ms.sortedPeers()
1230
1231 var msgs map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage
1232 if len(ms.lastDisplayMessages) != 0 {
1233 msgs = ms.lastDisplayMessages
1234 } else if len(ms.lastHealth) > 0 {
1235 // Convert all ms.lastHealth to the new [netmap.NetworkMap.DisplayMessages]
1236 for _, h := range ms.lastHealth {
1237 id := "health-" + strhash(h) // Unique ID in case there is more than one health message
1238 mak.Set(&msgs, tailcfg.DisplayMessageID(id), tailcfg.DisplayMessage{
1239 Title: "Coordination server reports an issue",
1240 Severity: tailcfg.SeverityMedium,
1241 Text: "The coordination server is reporting a health issue: " + h,
1242 })
1243 }
1244 }
1245
1246 nm := &netmap.NetworkMap{
1247 NodeKey: ms.publicNodeKey,
1248 MachineKey: ms.machinePubKey,
1249 Peers: peerViews,
1250 UserProfiles: make(map[tailcfg.UserID]tailcfg.UserProfileView),
1251 Domain: ms.lastDomain,
1252 DomainAuditLogID: ms.lastDomainAuditLogID,
1253 DNS: *ms.lastDNSConfig,
1254 PacketFilter: ms.lastParsedPacketFilter,
1255 PacketFilterRules: ms.lastPacketFilterRules,
1256 SSHPolicy: ms.lastSSHPolicy,
1257 CollectServices: ms.collectServices,
1258 DERPMap: ms.lastDERPMap,
1259 DisplayMessages: msgs,
1260 TKAEnabled: ms.lastTKAInfo != nil && !ms.lastTKAInfo.Disabled,
1261 }
1262
1263 if ms.lastTKAInfo != nil && ms.lastTKAInfo.Head != "" {
1264 if err := nm.TKAHead.UnmarshalText([]byte(ms.lastTKAInfo.Head)); err != nil {
1265 ms.logf("error unmarshalling TKAHead: %v", err)
1266 nm.TKAEnabled = false
1267 }
1268 }
1269
1270 if node := ms.lastNode; node.Valid() {
1271 nm.SelfNode = node
1272 nm.AllCaps = ms.lastCapSet
1273 }
1274
1275 ms.addUserProfile(nm, nm.User())
1276 for _, peer := range peerViews {
1277 ms.addUserProfile(nm, peer.Sharer())
1278 ms.addUserProfile(nm, peer.User())
1279 }
1280 if DevKnob.ForceProxyDNS() {
1281 nm.DNS.Proxied = true
1282 }
1283
1284 return nm
1285}

Callers 4

netmapForResponseMethod · 0.95
TestNetmapForResponseFunction · 0.80

Calls 11

sortedPeersMethod · 0.95
addUserProfileMethod · 0.95
UserMethod · 0.95
SetFunction · 0.92
DisplayMessageIDTypeAlias · 0.92
strhashFunction · 0.85
SharerMethod · 0.80
ValidMethod · 0.65
UserMethod · 0.65
UnmarshalTextMethod · 0.45
logfMethod · 0.45

Tested by 2

netmapForResponseMethod · 0.76
TestNetmapForResponseFunction · 0.64