MCPcopy Index your code
hub / github.com/tailscale/tailscale / ConciseDiffFrom

Method ConciseDiffFrom

types/netmap/netmap.go:430–475  ·  view source on GitHub ↗
(a *NetworkMap)

Source from the content-addressed store, hash-verified

428}
429
430func (b *NetworkMap) ConciseDiffFrom(a *NetworkMap) string {
431 var diff strings.Builder
432
433 // See if header (non-peers, "bare") part of the network map changed.
434 // If so, print its diff lines first.
435 if !a.equalConciseHeader(b) {
436 diff.WriteByte('-')
437 a.printConciseHeader(&diff)
438 diff.WriteByte('+')
439 b.printConciseHeader(&diff)
440 }
441
442 aps, bps := a.Peers, b.Peers
443 for len(aps) > 0 && len(bps) > 0 {
444 pa, pb := aps[0], bps[0]
445 switch {
446 case pa.ID() == pb.ID():
447 if !nodeConciseEqual(pa, pb) {
448 diff.WriteByte('-')
449 printPeerConcise(&diff, pa)
450 diff.WriteByte('+')
451 printPeerConcise(&diff, pb)
452 }
453 aps, bps = aps[1:], bps[1:]
454 case pa.ID() > pb.ID():
455 // New peer in b.
456 diff.WriteByte('+')
457 printPeerConcise(&diff, pb)
458 bps = bps[1:]
459 case pb.ID() > pa.ID():
460 // Deleted peer in b.
461 diff.WriteByte('-')
462 printPeerConcise(&diff, pa)
463 aps = aps[1:]
464 }
465 }
466 for _, pa := range aps {
467 diff.WriteByte('-')
468 printPeerConcise(&diff, pa)
469 }
470 for _, pb := range bps {
471 diff.WriteByte('+')
472 printPeerConcise(&diff, pb)
473 }
474 return diff.String()
475}
476
477func (nm *NetworkMap) JSON() string {
478 b, err := json.MarshalIndent(*nm, "", " ")

Callers 2

TestConciseDiffFromFunction · 0.80

Calls 6

printConciseHeaderMethod · 0.95
nodeConciseEqualFunction · 0.85
printPeerConciseFunction · 0.85
equalConciseHeaderMethod · 0.80
StringMethod · 0.65
IDMethod · 0.45

Tested by 1

TestConciseDiffFromFunction · 0.64