Ejemplo n.º 1
0
func getShortcut(tree prefix_tree.PrefixTree, s string, minLen int) string {
	s1, err := tree.Shortcut(s)
	if err != nil || s == s1 {
		return s
	}
	if len(s1) < minLen && minLen < len(s) {
		s1 = s[:minLen]
	}
	shortcut := fmt.Sprintf("%v...", s1)
	if len(shortcut) >= len(s) {
		shortcut = s
	}
	return shortcut
}
Ejemplo n.º 2
0
// Prints routing table in human readable table format
func printRTAsTable(r *rt.RoutingTable, humanForm bool) {
	// Minimum length of data part to which name can be shortened
	var minLen int
	var tmpl string
	var lightningIdTree, edgeIdTree prefix_tree.PrefixTree
	if humanForm {
		tmpl = "%-10v %-10v %-10v %-10v %-10v\n"
		minLen = 6
	} else {
		tmpl = "%-64v %-64v %-66v %-10v %-10v\n"
		minLen = 100
	}
	fmt.Printf(tmpl, "ID1", "ID2", "Outpoint", "Capacity", "Weight")
	channels := r.AllChannels()
	if humanForm {
		// Generate prefix tree for shortcuts
		lightningIdTree = prefix_tree.NewPrefixTree()
		for _, node := range r.Nodes() {
			lightningIdTree.Add(node.String())
		}
		edgeIdTree = prefix_tree.NewPrefixTree()
		for _, channel := range channels {
			edgeIdTree.Add(channel.EdgeID.String())
		}
	}
	for _, channel := range channels {
		var source, target, edgeId string
		sourceHex := channel.Id1.String()
		targetHex := channel.Id2.String()
		edgeIdRaw := channel.EdgeID.String()
		if humanForm {
			source = getShortcut(lightningIdTree, sourceHex, minLen)
			target = getShortcut(lightningIdTree, targetHex, minLen)
			edgeId = getShortcut(edgeIdTree, edgeIdRaw, minLen)
		} else {
			source = sourceHex
			target = targetHex
			edgeId = edgeIdRaw
		}
		fmt.Printf(tmpl, source, target, edgeId, channel.Info.Cpt, channel.Info.Wgt)
	}
}