Skip to content

Commit

Permalink
Added a GetNodeID API call to the admin api
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Mar 12, 2020
1 parent c827c91 commit 2f1f4dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ava-labs/gecko/api"
"github.com/ava-labs/gecko/chains"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow/engine/common"
"github.com/ava-labs/gecko/utils/logging"

Expand All @@ -18,6 +19,7 @@ import (

// Admin is the API service for node admin management
type Admin struct {
nodeID ids.ShortID
networkID uint32
log logging.Logger
networking Networking
Expand All @@ -27,12 +29,13 @@ type Admin struct {
}

// NewService returns a new admin API service
func NewService(networkID uint32, log logging.Logger, chainManager chains.Manager, peers Peerable, httpServer *api.Server) *common.HTTPHandler {
func NewService(nodeID ids.ShortID, networkID uint32, log logging.Logger, chainManager chains.Manager, peers Peerable, httpServer *api.Server) *common.HTTPHandler {
newServer := rpc.NewServer()
codec := cjson.NewCodec()
newServer.RegisterCodec(codec, "application/json")
newServer.RegisterCodec(codec, "application/json;charset=UTF-8")
newServer.RegisterService(&Admin{
nodeID: nodeID,
networkID: networkID,
log: log,
chainManager: chainManager,
Expand All @@ -44,6 +47,22 @@ func NewService(networkID uint32, log logging.Logger, chainManager chains.Manage
return &common.HTTPHandler{Handler: newServer}
}

// GetNodeIDArgs are the arguments for calling GetNodeID
type GetNodeIDArgs struct{}

// GetNodeIDReply are the results from calling GetNodeID
type GetNodeIDReply struct {
NodeID ids.ShortID `json:"nodeID"`
}

// GetNodeID returns the node ID of this node
func (service *Admin) GetNodeID(r *http.Request, args *GetNodeIDArgs, reply *GetNodeIDReply) error {
service.log.Debug("Admin: GetNodeID called")

reply.NodeID = service.nodeID
return nil
}

// GetNetworkIDArgs are the arguments for calling GetNetworkID
type GetNetworkIDArgs struct{}

Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (n *Node) initMetricsAPI() {
func (n *Node) initAdminAPI() {
if n.Config.AdminAPIEnabled {
n.Log.Info("initializing Admin API")
service := admin.NewService(n.Config.NetworkID, n.Log, n.chainManager, n.ValidatorAPI.Connections(), &n.APIServer)
service := admin.NewService(n.ID, n.Config.NetworkID, n.Log, n.chainManager, n.ValidatorAPI.Connections(), &n.APIServer)
n.APIServer.AddRoute(service, &sync.RWMutex{}, "admin", "", n.HTTPLog)
}
}
Expand Down

0 comments on commit 2f1f4dd

Please sign in to comment.