netmap returns a fully populated NetworkMap from the last state seen from a call to updateStateFromResponse, filling in omitted information from prior MapResponse values.
()
| 1226 | // a call to updateStateFromResponse, filling in omitted |
| 1227 | // information from prior MapResponse values. |
| 1228 | func (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 | } |