Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Sorting according to presence. Presence is published in the last 30 m…
Browse files Browse the repository at this point in the history
…inutes.
  • Loading branch information
abourget committed May 27, 2018
1 parent 77ff321 commit 8627d8a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
19 changes: 17 additions & 2 deletions bios/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (net *Network) OrderedPeers(network *simple.WeightedDirectedGraph) (out []*
}

sort.Slice(out, func(i, j int) bool {
if out[i].Active() != out[j].Active() {
return out[i].Active()
}

if out[i].TotalWeight == out[j].TotalWeight {
return out[i].AccountName() < out[j].AccountName()
}
Expand Down Expand Up @@ -449,13 +453,24 @@ func (net *Network) PollGenesisTable(account eos.AccountName) (data string, err
func (net *Network) ListNetworks(verbose bool) {
net.Log.Println("Networks formed by published discovery files:")

columns := []string{
"Network | Seed Account | Weight | Last update | Active",
"------- | ------------ | ------ | ----------- | ------",
}

for idx, network := range net.allNetworks {
net.Log.Printf("%d.\n", idx+1)
columns = append(columns, fmt.Sprintf("%d | | | |", idx+1))
orderedPeers := net.OrderedPeers(network)
for _, peer := range orderedPeers {
net.Log.Printf(" - %s (total weight: %d), updated %s\n", peer.Discovery.SeedNetworkAccountName, peer.TotalWeight, humanize.Time(peer.UpdatedAt))
active := " "
if peer.Active() {
active = "X"
}
columns = append(columns, fmt.Sprintf(" | %s | %d | %s | %s", peer.Discovery.SeedNetworkAccountName, peer.TotalWeight, humanize.Time(peer.UpdatedAt), active))
//net.Log.Printf(" - %s (total weight: %d), updated %s\n", peer.Discovery.SeedNetworkAccountName, peer.TotalWeight, humanize.Time(peer.UpdatedAt))
}
}
net.Log.Println(columnize.SimpleFormat(columns))
}

func (net *Network) MyNetwork() *simple.WeightedDirectedGraph {
Expand Down
12 changes: 11 additions & 1 deletion bios/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (p *Peer) ID() int64 {
return int64(id)
}

// Active flags peers if they published in the last 30
// minutes.. otherwise they're ignored, as to not stop the boot.
func (p *Peer) Active() bool {
return p.UpdatedAt.After(time.Now().Add(-30 * time.Minute))
}

func (p *Peer) String() string {
if p == nil {
return "Account:nil"
Expand All @@ -46,7 +52,11 @@ func (p *Peer) String() string {
}

func (p *Peer) Columns() string {
return fmt.Sprintf("%s | %s | %d | %d | %d", p.Discovery.SeedNetworkAccountName, p.Discovery.TargetAccountName, p.TotalWeight, p.Discovery.GMTOffset, p.Discovery.SeedNetworkLaunchBlock)
active := ""
if p.Active() {
active = "A "
}
return fmt.Sprintf("%s | %s | %s%d | %d | %d", p.Discovery.SeedNetworkAccountName, p.Discovery.TargetAccountName, active, p.TotalWeight, p.Discovery.GMTOffset, p.Discovery.SeedNetworkLaunchBlock)
}

// PeerEdge is an internal structure that links two Discovery peers.
Expand Down

0 comments on commit 8627d8a

Please sign in to comment.