Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/goal/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
errorNodeCreationIPFailure = "Parsing passed IP %v failed: need a valid IPv4 or IPv6 address with a specified port number"
errorNodeNotDetected = "Algorand node does not appear to be running: %s"
errorNodeStatus = "Cannot contact Algorand node: %s"
errorNodePeers = "Cannot retrieve node peers: %s"
errorNodeFailedToStart = "Algorand node failed to start: %s"
errorNodeRunning = "Node must be stopped before writing APIToken"
errorNodeFailGenToken = "Cannot generate API token: %s"
Expand Down
26 changes: 26 additions & 0 deletions cmd/goal/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func init() {
nodeCmd.AddCommand(waitCmd)
nodeCmd.AddCommand(createCmd)
nodeCmd.AddCommand(catchupCmd)
nodeCmd.AddCommand(peersCmd)
// Once the server-side implementation of the shutdown command is ready, we should enable this one.
//nodeCmd.AddCommand(shutdownCmd)
nodeCmd.AddCommand(p2pID)
Expand Down Expand Up @@ -415,6 +416,31 @@ var generateTokenCmd = &cobra.Command{
},
}

var peersCmd = &cobra.Command{
Use: "peers",
Short: "Get peers",
Long: `Show the Algorand node's current peers`,
Args: validateNoPosArgsFn,
Run: func(cmd *cobra.Command, _ []string) {
datadir.OnDataDirs(getPeers)
},
}

func getPeers(dataDir string) {

client := ensureAlgodClient(dataDir)
response, err := client.GetPeers()
if err != nil {
reportErrorf(errorNodePeers, err)
}

fmt.Printf("CONN TYPE\tNETWORK\tADDRESS\n")
for _, peer := range response.Peers {
fmt.Printf("%s\t%s\t%s\n", peer.ConnectionType, peer.NetworkType, peer.NetworkAddress)
}

}

var statusCmd = &cobra.Command{
Use: "status",
Short: "Get the current node status",
Expand Down
75 changes: 74 additions & 1 deletion daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,24 @@
}
]
},
"/v2/node/peers": {
"get": {
"description": "Get information about connected peers.",
"tags": ["private"],
"produces": ["application/json"],
"schemes": ["http"],
"operationId": "GetPeers",
"responses": {
"200": {
"$ref": "#/responses/GetPeersResponse"
}
}
}
},
"/v2/shutdown": {
"post": {
"description": "Special management endpoint to shutdown the node. Optionally provide a timeout parameter to indicate that the node should begin shutting down after a number of seconds.",
"deprecated": true,
"description": "Special management endpoint to shutdown the node. Optionally provide a timeout parameter to indicate that the node should begin shutting down after a number of seconds. This endpoint is deprecated, use `POST /v2/node/shutdown` instead",
"tags": ["private", "nonparticipating"],
"operationId": "ShutdownNode",
"parameters": [
Expand All @@ -1043,6 +1058,28 @@
}
}
},
"/v2/node/shutdown": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for implementing. Technically this is API change. I guess the best way of action is:

  1. to mark it deprecated (deprecated: true)
  2. continue calling the shutdown method under it is old/current path along with the new one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Implemented in 229f033

Thank you for taking the time to review this.

"post": {
"description": "Special management endpoint to shutdown the node. Optionally provide a timeout parameter to indicate that the node should begin shutting down after a number of seconds.",
"tags": ["private", "nonparticipating"],
"operationId": "ShutdownNode2",
"parameters": [
{
"type": "integer",
"default": 0,
"name": "timeout",
"in": "query"
}
],
"responses": {
"200": {
"schema": {
"type": "object"
}
}
}
}
},
"/v2/status": {
"get": {
"tags": ["public", "nonparticipating"],
Expand Down Expand Up @@ -4095,6 +4132,27 @@
"description": "The type of hash function used to create the proof, must be one of: \n* sha512_256 \n* sha256"
}
}
},
"PeerStatus": {
"description": "The status of a connected peer in the P2P network",
"type": "object",
"required": ["network-address", "network-type", "connection-type"],
"properties": {
"network-address": {
"description": "Network address of the peer",
"type": "string"
},
"network-type": {
"description": "Network type",
"type": "string",
"enum": ["p2p", "ws"]
},
"connection-type": {
"description": "Connection type",
"type": "string",
"enum": ["inbound", "outbound"]
}
}
}
},
"parameters": {
Expand Down Expand Up @@ -4194,6 +4252,21 @@
}
},
"responses": {
"GetPeersResponse": {
"description": "Response containing the network peers of the node",
"schema": {
"type": "object",
"required": ["Peers"],
"properties": {
"Peers": {
"type": "array",
"items": {
"$ref": "#/definitions/PeerStatus"
}
}
}
}
},
"GetBlockTimeStampOffsetResponse": {
"description": "Response containing the timestamp offset in seconds",
"schema": {
Expand Down
118 changes: 117 additions & 1 deletion daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,27 @@
},
"description": "Response containing the timestamp offset in seconds"
},
"GetPeersResponse": {
"content": {
"application/json": {
"schema": {
"properties": {
"Peers": {
"items": {
"$ref": "#/components/schemas/PeerStatus"
},
"type": "array"
}
},
"required": [
"Peers"
],
"type": "object"
}
}
},
"description": "Response containing the network peers of the node"
},
"GetSyncRoundResponse": {
"content": {
"application/json": {
Expand Down Expand Up @@ -2227,6 +2248,37 @@
],
"type": "object"
},
"PeerStatus": {
"description": "The status of a connected peer in the P2P network",
"properties": {
"connection-type": {
"description": "Connection type",
"enum": [
"inbound",
"outbound"
],
"type": "string"
},
"network-address": {
"description": "Network address of the peer",
"type": "string"
},
"network-type": {
"description": "Network type",
"enum": [
"p2p",
"ws"
],
"type": "string"
}
},
"required": [
"connection-type",
"network-address",
"network-type"
],
"type": "object"
},
"PendingTransactionResponse": {
"description": "Details about a pending transaction. If the transaction was recently confirmed, includes confirmation details like the round and reward details.",
"properties": {
Expand Down Expand Up @@ -5773,6 +5825,69 @@
]
}
},
"/v2/node/peers": {
"get": {
"description": "Get information about connected peers.",
"operationId": "GetPeers",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {
"Peers": {
"items": {
"$ref": "#/components/schemas/PeerStatus"
},
"type": "array"
}
},
"required": [
"Peers"
],
"type": "object"
}
}
},
"description": "Response containing the network peers of the node"
}
},
"tags": [
"private"
]
}
},
"/v2/node/shutdown": {
"post": {
"description": "Special management endpoint to shutdown the node. Optionally provide a timeout parameter to indicate that the node should begin shutting down after a number of seconds.",
"operationId": "ShutdownNode2",
"parameters": [
{
"in": "query",
"name": "timeout",
"schema": {
"default": 0,
"type": "integer"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
},
"tags": [
"private",
"nonparticipating"
]
}
},
"/v2/participation": {
"get": {
"description": "Return a list of participation keys",
Expand Down Expand Up @@ -6288,7 +6403,8 @@
},
"/v2/shutdown": {
"post": {
"description": "Special management endpoint to shutdown the node. Optionally provide a timeout parameter to indicate that the node should begin shutting down after a number of seconds.",
"deprecated": true,
"description": "Special management endpoint to shutdown the node. Optionally provide a timeout parameter to indicate that the node should begin shutting down after a number of seconds. This endpoint is deprecated, use `POST /v2/node/shutdown` instead",
"operationId": "ShutdownNode",
"parameters": [
{
Expand Down
8 changes: 7 additions & 1 deletion daemon/algod/api/client/restClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ func (client RestClient) post(response interface{}, path string, params interfac
return client.submitForm(response, path, params, body, "POST", true /* encodeJSON */, true /* decodeJSON */, expectNoContent)
}

// GetPeers retrieves the node's peers.
func (client RestClient) GetPeers() (response model.GetPeersResponse, err error) {
err = client.get(&response, "/v2/node/peers", nil)
return
}

// Status retrieves the StatusResponse from the running node
// the StatusResponse includes data like the consensus version and current round
// Not supported
Expand Down Expand Up @@ -640,7 +646,7 @@ func (client RestClient) EncodedBlockCert(round basics.Round) (blockCert rpcs.En
// Shutdown requests the node to shut itself down
func (client RestClient) Shutdown() (err error) {
response := 1
err = client.post(&response, "/v2/shutdown", nil, nil, false)
err = client.post(&response, "/v2/node/shutdown", nil, nil, false)
return
}

Expand Down
5 changes: 5 additions & 0 deletions daemon/algod/api/server/common/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/network"
"github.com/algorand/go-algorand/node"
"github.com/algorand/go-algorand/protocol"
)
Expand Down Expand Up @@ -137,3 +138,7 @@ func (m *mockNode) Status() (s node.StatusReport, err error) {
func (m *mockNode) GenesisID() string { panic("not implemented") }

func (m *mockNode) GenesisHash() crypto.Digest { panic("not implemented") }

func (m *mockNode) GetPeers() (inboundPeers []network.Peer, outboundPeers []network.Peer, err error) {
panic("not implemented")
}
1 change: 1 addition & 0 deletions daemon/algod/api/server/v2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
errFailedRetrievingSyncRound = "failed retrieving sync round from ledger"
errFailedSettingSyncRound = "failed to set sync round on the ledger"
errFailedParsingFormatOption = "failed to parse the format option"
errFailedToGetPeers = "failed to get connected peers from node"
errFailedToParseAddress = "failed to parse the address"
errFailedToParseExclude = "failed to parse exclude"
errFailedToEncodeResponse = "failed to encode response"
Expand Down
Loading
Loading