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

Commit

Permalink
added list of gossipers to status
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed May 24, 2018
1 parent b6abfc1 commit 74a2380
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/hcadmin/hcadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

holo "github.com/holochain/holochain-proto"
"github.com/holochain/holochain-proto/cmd"
. "github.com/holochain/holochain-proto/hash"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -252,6 +253,15 @@ func setupApp() (app *cli.App) {
fmt.Printf("ID Hash: %s\n", h.NodeIDStr())
idx, _ := h.DHT().GetIdx()
fmt.Printf("Current Put Index: %d\n", idx)
fmt.Printf("Gossipers:\n")
gossipers, err := h.DHT().GetGossipers()
if err != nil {
return err
}
for _, g := range gossipers {
h := HashFromPeerID(g.ID)
fmt.Printf(" %v idx: %d\n", h.String(), g.PutIdx)
}
} else {
return errors.New("status: expected 0 or 1 argument")
}
Expand Down
33 changes: 32 additions & 1 deletion gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,39 @@ func (dht *DHT) GetGossiper(id peer.ID) (idx int, err error) {
return
}

type GossiperData struct {
ID peer.ID
PutIdx int
}

func (dht *DHT) GetGossipers() (gossipers []GossiperData, err error) {
var glist []peer.ID
glist, err = dht._getGossipers()
if err != nil {
return
}
for _, id := range glist {
var idx int
idx, err = dht.GetGossiper(id)
if err != nil {
return
}
gossipers = append(gossipers, GossiperData{ID: id, PutIdx: idx})
}
return
}

func (dht *DHT) getGossipers() (glist []peer.ID, err error) {
glist, err = dht.getGossipers()
if err != nil {
return
}
ns := dht.config.RedundancyFactor
glist = dht.h.node.filterInactviePeers(glist, ns)
return
}

func (dht *DHT) _getGossipers() (glist []peer.ID, err error) {
glist = make([]peer.ID, 0)
db := dht.ht.(*BuntHT).db
err = db.View(func(tx *buntdb.Tx) error {
Expand Down Expand Up @@ -160,7 +192,6 @@ func (dht *DHT) getGossipers() (glist []peer.ID, err error) {
glist[i] = PeerIDFromHash(hlist[i])
}
}
glist = dht.h.node.filterInactviePeers(glist, ns)
return
}

Expand Down

0 comments on commit 74a2380

Please sign in to comment.