Skip to content

Commit

Permalink
Get connected remote node version by using nodectl
Browse files Browse the repository at this point in the history
1. Add an --nodeversion(-v) option for `nodectl info` subcommand
2. Add a RPC interface `getversion`
Now we can use command nodectl info --nodeversion(-v) to
show connected remote node version

Signed-off-by: Ziyan Zhou <[email protected]>
  • Loading branch information
zhouziyan authored and dreamfly281 committed May 25, 2017
1 parent 84ae2d8 commit 33e8a63
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ GOFMT=gofmt
GC=go build
VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
Minversion := $(shell date)
BUILD_PAR = -ldflags "-X main.Version=$(VERSION)" #-race
BUILD_NODE_PAR = -ldflags "-X DNA/common/config.Version=$(VERSION)" #-race
BUILD_NODECTL_PAR = -ldflags "-X DNA/cli.Version=$(VERSION)"

all:
$(GC) $(BUILD_PAR) -o node main.go
$(GC) $(BUILD_PAR) nodectl.go
$(GC) $(BUILD_NODE_PAR) -o node main.go
$(GC) $(BUILD_NODECTL_PAR) nodectl.go

format:
$(GOFMT) -w main.go
Expand Down
4 changes: 3 additions & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/urfave/cli"
)

var Version string

func init() {
var path string = "./Log/"
log.CreatePrintLog(path)
Expand All @@ -28,7 +30,7 @@ func init() {

app := cli.NewApp()
app.Name = "nodectl"
app.Version = "1.0.1"
app.Version = Version
app.HelpName = "nodectl"
app.Usage = "command line tool for DNA blockchain"
app.UsageText = "nodectl [global options] command [command options] [args]"
Expand Down
15 changes: 15 additions & 0 deletions cli/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func infoAction(c *cli.Context) (err error) {
connections := c.Bool("connections")
neighbor := c.Bool("neighbor")
state := c.Bool("state")
version := c.Bool("nodeversion")

var resp []byte
var output [][]byte
Expand Down Expand Up @@ -97,6 +98,16 @@ func infoAction(c *cli.Context) (err error) {
}
output = append(output, resp)
}

if version {
resp, err = httpjsonrpc.Call(Address(), "getversion", 0, []interface{}{})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return err
}
output = append(output, resp)

}
for _, v := range output {
FormatOutput(v)
}
Expand Down Expand Up @@ -144,6 +155,10 @@ func NewCommand() *cli.Command {
Name: "state, s",
Usage: "current node state",
},
cli.BoolFlag{
Name: "nodeversion, v",
Usage: "version of connected remote node",
},
},
Action: infoAction,
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
Expand Down
4 changes: 3 additions & 1 deletion common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const (
DefaultConfigFilename = "./config.json"
)

var Version string

type Configuration struct {
Magic int64 `json:"Magic"`
Version int `json:"Version"`
Version int `json:"Version"`
SeedList []string `json:"SeedList"`
HttpJsonPort int `json:"HttpJsonPort"`
HttpLocalPort int `json:"HttpLocalPort"`
Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const (
DefaultMultiCoreNum = 4
)

var Version string

func init() {
var path string = "./Log/"
log.CreatePrintLog(path)
Expand Down Expand Up @@ -67,7 +65,7 @@ func InitBlockChain() ledger.Blockchain {
}

func main() {
fmt.Printf("Node version: %s\n", Version)
fmt.Printf("Node version: %s\n", config.Version)
fmt.Println("//**************************************************************************")
fmt.Println("//*** 0. Client open ***")
fmt.Println("//**************************************************************************")
Expand Down
1 change: 1 addition & 0 deletions net/httpjsonrpc/RPCserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func StartRPCServer() {
HandleFunc("getrawtransaction", getRawTransaction)
HandleFunc("sendrawtransaction", sendRawTransaction)
HandleFunc("submitblock", submitBlock)
HandleFunc("getversion", getVersion)

err := http.ListenAndServe(":"+strconv.Itoa(Parameters.HttpJsonPort), nil)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions net/httpjsonrpc/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package httpjsonrpc
import (
"DNA/client"
. "DNA/common"
"DNA/common/config"
"DNA/common/log"
"DNA/core/ledger"
tx "DNA/core/transaction"
Expand Down Expand Up @@ -485,3 +486,7 @@ func setDebugInfo(params []interface{}) map[string]interface{} {
}
return DnaRpcSuccess
}

func getVersion(params []interface{}) map[string]interface{} {
return DnaRpc(config.Version)
}

0 comments on commit 33e8a63

Please sign in to comment.