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

Commit

Permalink
Merge pull request #727 from holochain/726-hcadmin-output-id
Browse files Browse the repository at this point in the history
adds ID to output of hcdev status <app>, closes #726
  • Loading branch information
zippy committed May 24, 2018
2 parents 8770ec5 + f9ebc39 commit 203f772
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
19 changes: 16 additions & 3 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 @@ -277,9 +278,21 @@ func setupApp() (app *cli.App) {
if err != nil {
return err
}
dna := h.Nucleus().DNA()
fmt.Printf("Status of %s\n", dna.Name)
fmt.Printf(" ---More status info here, not yet implemented---\n")
// dna := h.Nucleus().DNA()
fmt.Printf("Status of %s\n", h.Name())
fmt.Printf("DNA Hash: %v\n", h.DNAHash())
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
30 changes: 30 additions & 0 deletions cmd/hcadmin/hcadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@ func TestJoinFromSourceDir(t *testing.T) {
})
}

func TestStatus(t *testing.T) {
d := holo.SetupTestDir()
defer os.RemoveAll(d)
app := setupApp()
os.Args = []string{"hcadmin", "-path", d, "init", "test-identity"}
err := app.Run(os.Args)
if err != nil {
panic(err)
}
hcdev := filepath.Join(os.Getenv("GOPATH"), "/bin/hcdev")
err = cmd.OsExecSilent(hcdev, "-path", d, "init", "-test", "testAppSrc")
if err != nil {
panic(err)
}
app = setupApp()
_, err = runAppWithStdoutCapture(app, []string{"hcadmin", "-verbose", "-path", d, "join", filepath.Join(d, "testAppSrc"), "testApp"})
if err != nil {
panic(err)
}

app = setupApp()
Convey("status should show detailed info about an app", t, func() {
out, err := runAppWithStdoutCapture(app, []string{"hcadmin", "-path", d, "status", "testApp"})
So(err, ShouldBeNil)
So(out, ShouldContainSubstring, "Status of test")
So(out, ShouldContainSubstring, "DNA Hash: Qm")
So(out, ShouldContainSubstring, "ID Hash: Qm")
})
}

func TestJoinFromPackage(t *testing.T) {
d := holo.SetupTestDir()
// defer os.RemoveAll(d)
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 203f772

Please sign in to comment.