Simplified API. Correct Router initialization. Debug printing.

This commit is contained in:
Milos Gajdos
2019-06-10 19:50:54 +01:00
parent da18ea4ab5
commit 5899134b66
5 changed files with 72 additions and 85 deletions

View File

@@ -137,28 +137,31 @@ func (t *table) String() string {
// create nice table printing structure
table := tablewriter.NewWriter(sb)
table.SetHeader([]string{"Dest", "Hop", "Src", "Metric"})
table.SetHeader([]string{"Service", "Gateway", "Network", "Metric"})
for _, route := range t.m {
strRoute := []string{
route.Options().DestAddr,
route.Options().Hop.Address(),
fmt.Sprintf("%d", route.Options().SrcAddr),
route.Options().Network,
fmt.Sprintf("%d", route.Options().Metric),
}
table.Append(strRoute)
}
// render table into sb
table.Render()
return sb.String()
}
func (t *table) hash(r Route) uint64 {
srcAddr := r.Options().SrcAddr
destAddr := r.Options().DestAddr
routerAddr := r.Options().Hop.Address()
network := r.Options().Network
t.h.Reset()
t.h.Write([]byte(srcAddr + destAddr + routerAddr))
t.h.Write([]byte(destAddr + routerAddr + network))
return t.h.Sum64()
}