Skip to content

Commit

Permalink
Cleanup management API
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Mar 21, 2024
1 parent 9695e14 commit 4e58636
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 261 deletions.
82 changes: 11 additions & 71 deletions api/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,24 @@ type (
MultiAddresses []iotago.PrefixedStringUint8 `serix:",lenPrefix=uint8"`
// The alias to identify the peer.
Alias string `serix:",lenPrefix=uint8,omitempty"`
// The relation (static, autopeered) of the peer.
// The relation (manual, autopeered) of the peer.
Relation string `serix:",lenPrefix=uint8"`
// Whether the peer is connected.
Connected bool `serix:""`
// The gossip related information about this peer.
Gossip *GossipInfo `serix:",optional,omitempty"`
}

PeersResponse struct {
Peers []*PeerInfo `serix:",lenPrefix=uint8"`
}

// GossipInfo represents information about an ongoing gossip protocol.
GossipInfo struct {
// The last received heartbeat by the given node.
Heartbeat *GossipHeartbeat `serix:",omitempty"`
// The metrics about sent and received protocol messages.
Metrics *PeerGossipMetrics `serix:",omitempty"`
}

// GossipHeartbeat represents a gossip heartbeat message.
// Peers send each other this gossip protocol message when their
// state is updated, such as when:
// - a new slot was received
// - the solid slot changed
// - the node performed pruning of data
GossipHeartbeat struct {
// The solid slot of the node.
SolidSlot iotago.SlotIndex `serix:""`
// The oldest known slot by the node.
PrunedSlot iotago.SlotIndex `serix:""`
// The latest known slot by the node.
LatestSlot iotago.SlotIndex `serix:""`
// The amount of currently connected peers.
ConnectedPeers uint32 `serix:""`
// The amount of currently connected peers who also
// are synchronized with the network.
SyncedPeers uint32 `serix:""`
// The gossip metrics for this peer.
GossipMetrics *PeerGossipMetrics `serix:""`
}

// PeerGossipMetrics defines the peer gossip metrics.
PeerGossipMetrics struct {
// The total amount of received new blocks.
NewBlocks uint32 `serix:""`
// The total amount of received known blocks.
KnownBlocks uint32 `serix:""`
// The total amount of received blocks.
ReceivedBlocks uint32 `serix:""`
// The total amount of received block requests.
ReceivedBlockRequests uint32 `serix:""`
// The total amount of received slot requests.
ReceivedSlotRequests uint32 `serix:""`
// The total amount of received heartbeats.
ReceivedHeartbeats uint32 `serix:""`
// The total amount of sent blocks.
SentBlocks uint32 `serix:""`
// The total amount of sent block request.
SentBlockRequests uint32 `serix:""`
// The total amount of sent slot request.
SentSlotRequests uint32 `serix:""`
// The total amount of sent heartbeats.
SentHeartbeats uint32 `serix:""`
// The total amount of packets which couldn't be sent.
DroppedPackets uint32 `serix:""`
// The total amount of received packets.
PacketsReceived uint32 `serix:""`
// The total amount of sent packets.
PacketsSent uint32 `serix:""`
}

PeersResponse struct {
Peers []*PeerInfo `serix:",lenPrefix=uint8"`
}

// PruneDatabaseRequest defines the request of a prune database REST API call.
Expand All @@ -102,18 +56,4 @@ type (
// The current oldest epoch in the database.
Epoch iotago.EpochIndex `serix:""`
}

// CreateSnapshotsRequest defines the request of a create snapshots REST API call.
CreateSnapshotsRequest struct {
// The slot of the snapshot.
Slot iotago.SlotIndex `serix:""`
}

// CreateSnapshotResponse defines the response of a create snapshot REST API call.
CreateSnapshotResponse struct {
// The slot of the snapshot.
Slot iotago.SlotIndex `serix:""`
// The file path of the snapshot file.
FilePath string `serix:",lenPrefix=uint8"`
}
)
179 changes: 18 additions & 161 deletions api/management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,9 @@ func Test_ManagementAPIDeSerialize(t *testing.T) {
Alias: "alias",
Relation: "relation",
Connected: true,
Gossip: &api.GossipInfo{
Heartbeat: &api.GossipHeartbeat{
SolidSlot: 1,
PrunedSlot: 2,
LatestSlot: 3,
ConnectedPeers: 4,
SyncedPeers: 5,
},
Metrics: &api.PeerGossipMetrics{
NewBlocks: 1,
KnownBlocks: 2,
ReceivedBlocks: 3,
ReceivedBlockRequests: 4,
ReceivedSlotRequests: 5,
ReceivedHeartbeats: 6,
SentBlocks: 7,
SentBlockRequests: 8,
SentSlotRequests: 9,
SentHeartbeats: 10,
DroppedPackets: 11,
},
GossipMetrics: &api.PeerGossipMetrics{
PacketsReceived: 1,
PacketsSent: 2,
},
},
Target: &api.PeerInfo{},
Expand All @@ -61,27 +43,9 @@ func Test_ManagementAPIDeSerialize(t *testing.T) {
Alias: "alias",
Relation: "relation",
Connected: true,
Gossip: &api.GossipInfo{
Heartbeat: &api.GossipHeartbeat{
SolidSlot: 1,
PrunedSlot: 2,
LatestSlot: 3,
ConnectedPeers: 4,
SyncedPeers: 5,
},
Metrics: &api.PeerGossipMetrics{
NewBlocks: 1,
KnownBlocks: 2,
ReceivedBlocks: 3,
ReceivedBlockRequests: 4,
ReceivedSlotRequests: 5,
ReceivedHeartbeats: 6,
SentBlocks: 7,
SentBlockRequests: 8,
SentSlotRequests: 9,
SentHeartbeats: 10,
DroppedPackets: 11,
},
GossipMetrics: &api.PeerGossipMetrics{
PacketsReceived: 1,
PacketsSent: 2,
},
},
},
Expand All @@ -104,21 +68,6 @@ func Test_ManagementAPIDeSerialize(t *testing.T) {
},
Target: &api.PruneDatabaseResponse{},
},
{
Name: "ok - CreateSnapshotsRequest",
Source: &api.CreateSnapshotsRequest{
Slot: 1,
},
Target: &api.CreateSnapshotsRequest{},
},
{
Name: "ok - CreateSnapshotResponse",
Source: &api.CreateSnapshotResponse{
Slot: 1,
FilePath: "filePath",
},
Target: &api.CreateSnapshotResponse{},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -147,27 +96,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) {
Alias: "alias",
Relation: "relation",
Connected: true,
Gossip: &api.GossipInfo{
Heartbeat: &api.GossipHeartbeat{
SolidSlot: 1,
PrunedSlot: 2,
LatestSlot: 3,
ConnectedPeers: 4,
SyncedPeers: 5,
},
Metrics: &api.PeerGossipMetrics{
NewBlocks: 1,
KnownBlocks: 2,
ReceivedBlocks: 3,
ReceivedBlockRequests: 4,
ReceivedSlotRequests: 5,
ReceivedHeartbeats: 6,
SentBlocks: 7,
SentBlockRequests: 8,
SentSlotRequests: 9,
SentHeartbeats: 10,
DroppedPackets: 11,
},
GossipMetrics: &api.PeerGossipMetrics{
PacketsReceived: 1,
PacketsSent: 2,
},
},
Target: `{
Expand All @@ -178,27 +109,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) {
"alias": "alias",
"relation": "relation",
"connected": true,
"gossip": {
"heartbeat": {
"solidSlot": 1,
"prunedSlot": 2,
"latestSlot": 3,
"connectedPeers": 4,
"syncedPeers": 5
},
"metrics": {
"newBlocks": 1,
"knownBlocks": 2,
"receivedBlocks": 3,
"receivedBlockRequests": 4,
"receivedSlotRequests": 5,
"receivedHeartbeats": 6,
"sentBlocks": 7,
"sentBlockRequests": 8,
"sentSlotRequests": 9,
"sentHeartbeats": 10,
"droppedPackets": 11
}
"gossipMetrics": {
"packetsReceived": 1,
"packetsSent": 2
}
}`,
},
Expand All @@ -212,27 +125,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) {
Alias: "alias",
Relation: "relation",
Connected: true,
Gossip: &api.GossipInfo{
Heartbeat: &api.GossipHeartbeat{
SolidSlot: 1,
PrunedSlot: 2,
LatestSlot: 3,
ConnectedPeers: 4,
SyncedPeers: 5,
},
Metrics: &api.PeerGossipMetrics{
NewBlocks: 1,
KnownBlocks: 2,
ReceivedBlocks: 3,
ReceivedBlockRequests: 4,
ReceivedSlotRequests: 5,
ReceivedHeartbeats: 6,
SentBlocks: 7,
SentBlockRequests: 8,
SentSlotRequests: 9,
SentHeartbeats: 10,
DroppedPackets: 11,
},
GossipMetrics: &api.PeerGossipMetrics{
PacketsReceived: 1,
PacketsSent: 2,
},
},
},
Expand All @@ -247,27 +142,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) {
"alias": "alias",
"relation": "relation",
"connected": true,
"gossip": {
"heartbeat": {
"solidSlot": 1,
"prunedSlot": 2,
"latestSlot": 3,
"connectedPeers": 4,
"syncedPeers": 5
},
"metrics": {
"newBlocks": 1,
"knownBlocks": 2,
"receivedBlocks": 3,
"receivedBlockRequests": 4,
"receivedSlotRequests": 5,
"receivedHeartbeats": 6,
"sentBlocks": 7,
"sentBlockRequests": 8,
"sentSlotRequests": 9,
"sentHeartbeats": 10,
"droppedPackets": 11
}
"gossipMetrics": {
"packetsReceived": 1,
"packetsSent": 2
}
}
]
Expand All @@ -293,26 +170,6 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) {
},
Target: `{
"epoch": 1
}`,
},
{
Name: "ok - CreateSnapshotsRequest",
Source: &api.CreateSnapshotsRequest{
Slot: 1,
},
Target: `{
"slot": 1
}`,
},
{
Name: "ok - CreateSnapshotResponse",
Source: &api.CreateSnapshotResponse{
Slot: 1,
FilePath: "filePath",
},
Target: `{
"slot": 1,
"filePath": "filePath"
}`,
},
}
Expand Down
Loading

0 comments on commit 4e58636

Please sign in to comment.