Skip to content

Commit

Permalink
Update PathSegment string representation. (#1894)
Browse files Browse the repository at this point in the history
- If a *seg.PathSegment is nil, just return "<nil">.
- Use a shorter version of seg id in the string output (using 12B, same
  as python). This improves log readability a lot.

Also:
- Change segs.FilterSegs to return how many segments were filtered out.
  It's useful for debugging if nothing else.
  • Loading branch information
kormat authored Sep 24, 2018
1 parent 1dde278 commit aefd33d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion go/lib/ctrl/seg/seg.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,14 @@ func (ps *PathSegment) ProtoId() proto.ProtoIdType {
}

func (ps *PathSegment) String() string {
if ps == nil {
return "<nil>"
}
desc := []string{}
if id, err := ps.ID(); err != nil {
desc = append(desc, fmt.Sprintf("ID error: %s", err))
} else {
desc = append(desc, id.String())
desc = append(desc, id.String()[:12])
}
info, _ := ps.InfoF()
desc = append(desc, util.TimeToString(info.Timestamp()))
Expand Down
6 changes: 4 additions & 2 deletions go/lib/ctrl/seg/segs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ import (
type Segments []*PathSegment

// FilterSegs filters the given segs and only keeps the segments for which keep returns true.
// Modifies segs in-place.
func (segs *Segments) FilterSegs(keep func(*PathSegment) bool) {
// Modifies segs in-place. Returns the number of segments filtered out.
func (segs *Segments) FilterSegs(keep func(*PathSegment) bool) int {
full := len(*segs)
filtered := (*segs)[:0]
for _, s := range *segs {
if keep(s) {
filtered = append(filtered, s)
}
}
*segs = filtered
return full - len(*segs)
}

// FirstIAs returns the slice of FirstIAs in the given segments. Each FirstIA appears just once.
Expand Down

0 comments on commit aefd33d

Please sign in to comment.