diff --git a/openapi/SwarmCommon.yaml b/openapi/SwarmCommon.yaml index 15ac347d5fe..0824187278b 100644 --- a/openapi/SwarmCommon.yaml +++ b/openapi/SwarmCommon.yaml @@ -1,6 +1,6 @@ openapi: 3.0.3 info: - version: 3.2.1 + version: 3.2.2 title: Common Data Types description: | \*****bzzz***** @@ -861,6 +861,8 @@ components: type: boolean BatchCommitment: type: integer + isReachable: + type: boolean StatusResponse: type: object diff --git a/pkg/api/status.go b/pkg/api/status.go index 813feec9c95..4f302e37c82 100644 --- a/pkg/api/status.go +++ b/pkg/api/status.go @@ -27,6 +27,7 @@ type statusSnapshotResponse struct { NeighborhoodSize uint64 `json:"neighborhoodSize"` RequestFailed bool `json:"requestFailed,omitempty"` BatchCommitment uint64 `json:"batchCommitment"` + IsReachable bool `json:"isReachable"` } type statusResponse struct { @@ -77,6 +78,7 @@ func (s *Service) statusGetHandler(w http.ResponseWriter, _ *http.Request) { ConnectedPeers: ss.ConnectedPeers, NeighborhoodSize: ss.NeighborhoodSize, BatchCommitment: ss.BatchCommitment, + IsReachable: ss.IsReachable, }) } @@ -121,6 +123,7 @@ func (s *Service) statusGetPeersHandler(w http.ResponseWriter, r *http.Request) snapshot.ConnectedPeers = ss.ConnectedPeers snapshot.NeighborhoodSize = ss.NeighborhoodSize snapshot.BatchCommitment = ss.BatchCommitment + snapshot.IsReachable = ss.IsReachable } mu.Lock() @@ -133,7 +136,7 @@ func (s *Service) statusGetPeersHandler(w http.ResponseWriter, r *http.Request) err := s.topologyDriver.EachConnectedPeer( peerFunc, - topology.Filter{Reachable: true}, + topology.Filter{}, ) if err != nil { logger.Debug("status snapshot", "error", err) diff --git a/pkg/api/status_test.go b/pkg/api/status_test.go index e37c186167d..805643406c9 100644 --- a/pkg/api/status_test.go +++ b/pkg/api/status_test.go @@ -33,6 +33,7 @@ func TestGetStatus(t *testing.T) { ConnectedPeers: 0, NeighborhoodSize: 0, BatchCommitment: 1, + IsReachable: true, } ssMock := &statusSnapshotMock{ @@ -99,6 +100,9 @@ func (m *topologyPeersIterNoopMock) EachConnectedPeer(_ topology.EachPeerFunc, _ func (m *topologyPeersIterNoopMock) EachConnectedPeerRev(_ topology.EachPeerFunc, _ topology.Filter) error { return nil } +func (m *topologyPeersIterNoopMock) IsReachable() bool { + return true +} // statusSnapshotMock satisfies the following interfaces: // - depthmonitor.ReserveReporter diff --git a/pkg/status/internal/pb/status.pb.go b/pkg/status/internal/pb/status.pb.go index 86b63bb5316..315c8cc8aeb 100644 --- a/pkg/status/internal/pb/status.pb.go +++ b/pkg/status/internal/pb/status.pb.go @@ -71,6 +71,7 @@ type Snapshot struct { NeighborhoodSize uint64 `protobuf:"varint,5,opt,name=NeighborhoodSize,proto3" json:"NeighborhoodSize,omitempty"` BeeMode string `protobuf:"bytes,6,opt,name=BeeMode,proto3" json:"BeeMode,omitempty"` BatchCommitment uint64 `protobuf:"varint,7,opt,name=BatchCommitment,proto3" json:"BatchCommitment,omitempty"` + IsReachable bool `protobuf:"varint,8,opt,name=IsReachable,proto3" json:"IsReachable,omitempty"` } func (m *Snapshot) Reset() { *m = Snapshot{} } @@ -155,6 +156,13 @@ func (m *Snapshot) GetBatchCommitment() uint64 { return 0 } +func (m *Snapshot) GetIsReachable() bool { + if m != nil { + return m.IsReachable + } + return false +} + func init() { proto.RegisterType((*Get)(nil), "status.Get") proto.RegisterType((*Snapshot)(nil), "status.Snapshot") @@ -163,24 +171,25 @@ func init() { func init() { proto.RegisterFile("status.proto", fileDescriptor_dfe4fce6682daf5b) } var fileDescriptor_dfe4fce6682daf5b = []byte{ - // 259 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0xd0, 0xc1, 0x4a, 0xc3, 0x40, - 0x10, 0x06, 0xe0, 0x6c, 0xda, 0xa6, 0xba, 0xb6, 0x2a, 0x7b, 0xda, 0x83, 0x2c, 0x21, 0x88, 0x04, - 0x0f, 0x5e, 0x7c, 0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93, 0xab, 0xcf, 0x41, 0xb1, 0xdd, - 0xa0, 0xd8, 0xf7, 0xa0, 0xd8, 0xc7, 0xa8, 0xbc, 0xdd, 0xa8, 0xbc, 0xaf, 0x51, 0x79, 0xcf, 0x7e, - 0x9b, 0x65, 0x81, 0x2b, 0xf1, 0xfe, 0x27, 0x00, 0x00, 0xff, 0xff, 0x21, 0xd4, 0xe4, 0x38, 0x54, - 0x01, 0x00, 0x00, + // 279 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0xd0, 0xc1, 0x4a, 0xf3, 0x40, + 0x10, 0x07, 0xf0, 0x6e, 0xda, 0xa6, 0xf9, 0xf6, 0x6b, 0x55, 0xf6, 0xb4, 0x07, 0x59, 0x96, 0x20, + 0xb2, 0x78, 0xf0, 0xe2, 0x1b, 0xa4, 0x07, 0xf1, 0xa0, 0x94, 0xcd, 0xcd, 0xdb, 0x26, 0x19, 0x9a, + 0x40, 0x92, 0x0d, 0xd9, 0x89, 0xa0, 0x4f, 0xe1, 0xa3, 0xf8, 0x18, 0x1e, 0x7b, 0xf4, 0x28, 0xc9, + 0x8b, 0x88, 0x11, 0xa1, 0xad, 0xc7, 0xff, 0x8f, 0x61, 0x66, 0xf8, 0xd3, 0xa5, 0x43, 0x83, 0x9d, + 0xbb, 0x6e, 0x5a, 0x8b, 0x96, 0xf9, 0x3f, 0x29, 0x9c, 0xd3, 0xe9, 0x2d, 0x60, 0xf8, 0xe6, 0xd1, + 0x20, 0xae, 0x4d, 0xe3, 0x72, 0x8b, 0x4c, 0xd2, 0xff, 0x1a, 0x1c, 0xb4, 0x4f, 0x10, 0x17, 0x2f, + 0xc0, 0x89, 0x24, 0x6a, 0xa6, 0xf7, 0x89, 0x85, 0x74, 0xb9, 0xe9, 0xca, 0xd2, 0x3d, 0xd7, 0xa9, + 0x36, 0x08, 0xdc, 0x93, 0x44, 0x11, 0x7d, 0x60, 0xec, 0x82, 0xae, 0x62, 0xb4, 0xad, 0xd9, 0x82, + 0x36, 0x59, 0xd1, 0x39, 0x3e, 0x95, 0x44, 0xad, 0xf4, 0x21, 0xb2, 0x4b, 0x7a, 0xb2, 0xb6, 0x75, + 0x0d, 0x29, 0x42, 0xb6, 0x01, 0x68, 0x1d, 0x9f, 0x8d, 0xe7, 0x8e, 0x94, 0x5d, 0xd1, 0xb3, 0x07, + 0x28, 0xb6, 0x79, 0x62, 0xdb, 0xdc, 0xda, 0x6c, 0x7c, 0x6c, 0x3e, 0x4e, 0xfe, 0x71, 0xc6, 0xe9, + 0x22, 0x02, 0xb8, 0xb7, 0x19, 0x70, 0x5f, 0x12, 0xf5, 0x4f, 0xff, 0x46, 0xa6, 0xe8, 0x69, 0x64, + 0x30, 0xcd, 0xd7, 0xb6, 0xaa, 0x0a, 0xac, 0xa0, 0x46, 0xbe, 0x18, 0x97, 0x1c, 0xf3, 0x77, 0x07, + 0x77, 0x4e, 0x83, 0x49, 0x73, 0x93, 0x94, 0xc0, 0x03, 0x49, 0x54, 0xa0, 0xf7, 0x29, 0x3a, 0x7f, + 0xef, 0x05, 0xd9, 0xf5, 0x82, 0x7c, 0xf6, 0x82, 0xbc, 0x0e, 0x62, 0xb2, 0x1b, 0xc4, 0xe4, 0x63, + 0x10, 0x93, 0x47, 0xaf, 0x49, 0x12, 0x7f, 0xac, 0xf9, 0xe6, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x64, + 0x9a, 0xeb, 0xde, 0x76, 0x01, 0x00, 0x00, } func (m *Get) Marshal() (dAtA []byte, err error) { @@ -226,6 +235,16 @@ func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.IsReachable { + i-- + if m.IsReachable { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x40 + } if m.BatchCommitment != 0 { i = encodeVarintStatus(dAtA, i, uint64(m.BatchCommitment)) i-- @@ -315,6 +334,9 @@ func (m *Snapshot) Size() (n int) { if m.BatchCommitment != 0 { n += 1 + sovStatus(uint64(m.BatchCommitment)) } + if m.IsReachable { + n += 2 + } return n } @@ -359,10 +381,7 @@ func (m *Get) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthStatus - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthStatus } if (iNdEx + skippy) > l { @@ -544,16 +563,33 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { break } } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsReachable", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStatus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsReachable = bool(v != 0) default: iNdEx = preIndex skippy, err := skipStatus(dAtA[iNdEx:]) if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthStatus - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthStatus } if (iNdEx + skippy) > l { diff --git a/pkg/status/internal/pb/status.proto b/pkg/status/internal/pb/status.proto index b72c094726e..f4cecd47088 100644 --- a/pkg/status/internal/pb/status.proto +++ b/pkg/status/internal/pb/status.proto @@ -22,4 +22,5 @@ message Snapshot { uint64 NeighborhoodSize = 5; string BeeMode = 6; uint64 BatchCommitment = 7; + bool IsReachable = 8; } diff --git a/pkg/status/status.go b/pkg/status/status.go index 0dc478930b3..beab920b987 100644 --- a/pkg/status/status.go +++ b/pkg/status/status.go @@ -32,11 +32,16 @@ const ( // Snapshot is the current snapshot of the system. type Snapshot pb.Snapshot +type topologyDriver interface { + topology.PeerIterator + IsReachable() bool +} + // Service is the status service. type Service struct { - logger log.Logger - streamer p2p.Streamer - topologyIter topology.PeerIterator + logger log.Logger + streamer p2p.Streamer + topologyDriver topologyDriver beeMode string reserve depthmonitor.ReserveReporter @@ -52,7 +57,7 @@ func (s *Service) LocalSnapshot() (*Snapshot, error) { connectedPeers uint64 neighborhoodSize uint64 ) - err := s.topologyIter.EachConnectedPeer( + err := s.topologyDriver.EachConnectedPeer( func(_ swarm.Address, po uint8) (bool, bool, error) { connectedPeers++ if po >= storageRadius { @@ -60,7 +65,7 @@ func (s *Service) LocalSnapshot() (*Snapshot, error) { } return false, false, nil }, - topology.Filter{Reachable: true}, + topology.Filter{}, ) if err != nil { return nil, fmt.Errorf("iterate connected peers: %w", err) @@ -68,7 +73,7 @@ func (s *Service) LocalSnapshot() (*Snapshot, error) { commitment, err := s.commitment.Commitment() if err != nil { - return nil, fmt.Errorf("batchstore commitemnt: %w", err) + return nil, fmt.Errorf("batchstore commitment: %w", err) } return &Snapshot{ @@ -79,6 +84,7 @@ func (s *Service) LocalSnapshot() (*Snapshot, error) { ConnectedPeers: connectedPeers, NeighborhoodSize: neighborhoodSize, BatchCommitment: commitment, + IsReachable: s.topologyDriver.IsReachable(), }, nil } @@ -105,6 +111,7 @@ func (s *Service) PeerSnapshot(ctx context.Context, peer swarm.Address) (*Snapsh } return nil, fmt.Errorf("read message failed: %w", err) } + return (*Snapshot)(ss), nil } @@ -142,7 +149,7 @@ func (s *Service) handler(ctx context.Context, _ p2p.Peer, stream p2p.Stream) er connectedPeers uint64 neighborhoodSize uint64 ) - err := s.topologyIter.EachConnectedPeer( + err := s.topologyDriver.EachConnectedPeer( func(_ swarm.Address, po uint8) (bool, bool, error) { connectedPeers++ if po >= storageRadius { @@ -150,7 +157,7 @@ func (s *Service) handler(ctx context.Context, _ p2p.Peer, stream p2p.Stream) er } return false, false, nil }, - topology.Filter{Reachable: true}, + topology.Filter{}, ) if err != nil { s.logger.Error(err, "iteration of connected peers failed") @@ -170,6 +177,7 @@ func (s *Service) handler(ctx context.Context, _ p2p.Peer, stream p2p.Stream) er ConnectedPeers: connectedPeers, NeighborhoodSize: neighborhoodSize, BatchCommitment: commitment, + IsReachable: s.topologyDriver.IsReachable(), }); err != nil { loggerV2.Debug("write message failed", "error", err) return fmt.Errorf("write message: %w", err) @@ -182,7 +190,7 @@ func (s *Service) handler(ctx context.Context, _ p2p.Peer, stream p2p.Stream) er func NewService( logger log.Logger, streamer p2p.Streamer, - topologyIter topology.PeerIterator, + topology topologyDriver, beeMode string, reserve depthmonitor.ReserveReporter, sync depthmonitor.SyncReporter, @@ -190,13 +198,13 @@ func NewService( commitment postage.CommitmentGetter, ) *Service { return &Service{ - logger: logger.WithName(loggerName).Register(), - streamer: streamer, - topologyIter: topologyIter, - beeMode: beeMode, - reserve: reserve, - sync: sync, - radius: radius, - commitment: commitment, + logger: logger.WithName(loggerName).Register(), + streamer: streamer, + topologyDriver: topology, + beeMode: beeMode, + reserve: reserve, + sync: sync, + radius: radius, + commitment: commitment, } } diff --git a/pkg/status/status_test.go b/pkg/status/status_test.go index 56b5afb22ed..b662842bc9a 100644 --- a/pkg/status/status_test.go +++ b/pkg/status/status_test.go @@ -29,6 +29,7 @@ func TestStatus(t *testing.T) { PullsyncRate: 64, StorageRadius: 8, BatchCommitment: 1024, + IsReachable: true, } sssMock := &statusSnapshotMock{want} @@ -100,6 +101,10 @@ func (m *topologyPeersIterNoopMock) EachConnectedPeerRev(_ topology.EachPeerFunc return nil } +func (m *topologyPeersIterNoopMock) IsReachable() bool { + return true +} + // statusSnapshotMock satisfies the following interfaces: // - depthmonitor.ReserveReporter // - depthmonitor.SyncReporter diff --git a/pkg/topology/kademlia/kademlia.go b/pkg/topology/kademlia/kademlia.go index 84882d94b1c..edd6c6db2ca 100644 --- a/pkg/topology/kademlia/kademlia.go +++ b/pkg/topology/kademlia/kademlia.go @@ -1369,7 +1369,6 @@ func (k *Kad) UpdateReachability(status p2p.ReachabilityStatus) { // p2p.ReachabilityStatusUnknown are ignored. func (k *Kad) UpdatePeerHealth(peer swarm.Address, health bool) { k.collector.Record(peer, im.PeerHealth(health)) - // k.logger.Debug("health of peer updated", "peer_address", peer, "health", health) } // SubscribeTopologyChange returns the channel that signals when the connected peers