Skip to content

Commit

Permalink
fix: updating gRPC and HTTP modules
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Jun 27, 2023
1 parent 067bdef commit 8da78dc
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 984 deletions.
23 changes: 23 additions & 0 deletions sync/peerset/peer_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ type PeerSet struct {
sessionTimeout time.Duration
totalSentBytes int
totalReceivedBytes int
startedAt time.Time
}

func NewPeerSet(sessionTimeout time.Duration) *PeerSet {
return &PeerSet{
peers: make(map[peer.ID]*Peer),
sessions: make(map[int]*Session),
sessionTimeout: sessionTimeout,
startedAt: time.Now(),
}
}

Expand Down Expand Up @@ -325,3 +327,24 @@ func (ps *PeerSet) IncreaseSendFailedCounter(pid peer.ID) {
p := ps.mustGetPeer(pid)
p.SendFailed++
}

func (ps *PeerSet) TotalSentBytes() int {
ps.lk.RLock()
defer ps.lk.RUnlock()

return ps.totalSentBytes
}

func (ps *PeerSet) TotalReceivedBytes() int {
ps.lk.RLock()
defer ps.lk.RUnlock()

return ps.totalReceivedBytes
}

func (ps *PeerSet) StartedAt() time.Time {
ps.lk.RLock()
defer ps.lk.RUnlock()

Check warning on line 347 in sync/peerset/peer_set.go

View check run for this annotation

Codecov / codecov/patch

sync/peerset/peer_set.go#L346-L347

Added lines #L346 - L347 were not covered by tests

return ps.startedAt

Check warning on line 349 in sync/peerset/peer_set.go

View check run for this annotation

Codecov / codecov/patch

sync/peerset/peer_set.go#L349

Added line #L349 was not covered by tests
}
3 changes: 3 additions & 0 deletions sync/peerset/peer_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestPeerSet(t *testing.T) {
peerSet.IncreaseInvalidBundlesCounter(pid1)
peerSet.IncreaseReceivedBundlesCounter(pid1)
peerSet.IncreaseReceivedBytesCounter(pid1, 100)
peerSet.IncreaseTotalSentBytesCounter(200)
peerSet.IncreaseSendFailedCounter(pid1)
peerSet.IncreaseSendSuccessCounter(pid1)

Expand All @@ -79,6 +80,8 @@ func TestPeerSet(t *testing.T) {
assert.Equal(t, peer1.ReceivedBytes, 100)
assert.Equal(t, peer1.SendFailed, 1)
assert.Equal(t, peer1.SendSuccess, 1)
assert.Equal(t, peerSet.TotalReceivedBytes(), 100)
assert.Equal(t, peerSet.TotalSentBytes(), 200)
})

t.Run("Testing UpdateStatus", func(t *testing.T) {
Expand Down
88 changes: 19 additions & 69 deletions www/grpc/gen/dart/network.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,30 @@ class GetNetworkInfoRequest extends $pb.GeneratedMessage {

class GetNetworkInfoResponse extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'GetNetworkInfoResponse', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..a<$core.List<$core.int>>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'selfId', $pb.PbFieldType.OY)
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'totalSentBytes', $pb.PbFieldType.O3)
..a<$core.int>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'totalReceivedBytes', $pb.PbFieldType.O3)
..a<$core.int>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'totalSentBytes', $pb.PbFieldType.O3)
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'totalReceivedBytes', $pb.PbFieldType.O3)
..aInt64(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'startedAt')
..pc<PeerInfo>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'peers', $pb.PbFieldType.PM, subBuilder: PeerInfo.create)
..hasRequiredFields = false
;

GetNetworkInfoResponse._() : super();
factory GetNetworkInfoResponse({
$core.List<$core.int>? selfId,
$core.int? totalSentBytes,
$core.int? totalReceivedBytes,
$fixnum.Int64? startedAt,
$core.Iterable<PeerInfo>? peers,
}) {
final _result = create();
if (selfId != null) {
_result.selfId = selfId;
}
if (totalSentBytes != null) {
_result.totalSentBytes = totalSentBytes;
}
if (totalReceivedBytes != null) {
_result.totalReceivedBytes = totalReceivedBytes;
}
if (startedAt != null) {
_result.startedAt = startedAt;
}
if (peers != null) {
_result.peers.addAll(peers);
}
Expand Down Expand Up @@ -93,31 +93,31 @@ class GetNetworkInfoResponse extends $pb.GeneratedMessage {
static GetNetworkInfoResponse? _defaultInstance;

@$pb.TagNumber(1)
$core.List<$core.int> get selfId => $_getN(0);
$core.int get totalSentBytes => $_getIZ(0);
@$pb.TagNumber(1)
set selfId($core.List<$core.int> v) { $_setBytes(0, v); }
set totalSentBytes($core.int v) { $_setSignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasSelfId() => $_has(0);
$core.bool hasTotalSentBytes() => $_has(0);
@$pb.TagNumber(1)
void clearSelfId() => clearField(1);
void clearTotalSentBytes() => clearField(1);

@$pb.TagNumber(2)
$core.int get totalSentBytes => $_getIZ(1);
$core.int get totalReceivedBytes => $_getIZ(1);
@$pb.TagNumber(2)
set totalSentBytes($core.int v) { $_setSignedInt32(1, v); }
set totalReceivedBytes($core.int v) { $_setSignedInt32(1, v); }
@$pb.TagNumber(2)
$core.bool hasTotalSentBytes() => $_has(1);
$core.bool hasTotalReceivedBytes() => $_has(1);
@$pb.TagNumber(2)
void clearTotalSentBytes() => clearField(2);
void clearTotalReceivedBytes() => clearField(2);

@$pb.TagNumber(3)
$core.int get totalReceivedBytes => $_getIZ(2);
$fixnum.Int64 get startedAt => $_getI64(2);
@$pb.TagNumber(3)
set totalReceivedBytes($core.int v) { $_setSignedInt32(2, v); }
set startedAt($fixnum.Int64 v) { $_setInt64(2, v); }
@$pb.TagNumber(3)
$core.bool hasTotalReceivedBytes() => $_has(2);
$core.bool hasStartedAt() => $_has(2);
@$pb.TagNumber(3)
void clearTotalReceivedBytes() => clearField(3);
void clearStartedAt() => clearField(3);

@$pb.TagNumber(4)
$core.List<PeerInfo> get peers => $_getList(3);
Expand Down Expand Up @@ -157,10 +157,6 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'moniker')
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'agent')
..a<$core.List<$core.int>>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'peerId', $pb.PbFieldType.OY)
..pPS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'consensusKeys')
..a<$core.int>(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'flags', $pb.PbFieldType.O3)
..a<$core.int>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'height', $pb.PbFieldType.OU3)
..aInt64(7, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'startedAt')
..hasRequiredFields = false
;

Expand All @@ -169,10 +165,6 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
$core.String? moniker,
$core.String? agent,
$core.List<$core.int>? peerId,
$core.Iterable<$core.String>? consensusKeys,
$core.int? flags,
$core.int? height,
$fixnum.Int64? startedAt,
}) {
final _result = create();
if (moniker != null) {
Expand All @@ -184,18 +176,6 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
if (peerId != null) {
_result.peerId = peerId;
}
if (consensusKeys != null) {
_result.consensusKeys.addAll(consensusKeys);
}
if (flags != null) {
_result.flags = flags;
}
if (height != null) {
_result.height = height;
}
if (startedAt != null) {
_result.startedAt = startedAt;
}
return _result;
}
factory GetNodeInfoResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
Expand Down Expand Up @@ -245,36 +225,6 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
$core.bool hasPeerId() => $_has(2);
@$pb.TagNumber(3)
void clearPeerId() => clearField(3);

@$pb.TagNumber(4)
$core.List<$core.String> get consensusKeys => $_getList(3);

@$pb.TagNumber(5)
$core.int get flags => $_getIZ(4);
@$pb.TagNumber(5)
set flags($core.int v) { $_setSignedInt32(4, v); }
@$pb.TagNumber(5)
$core.bool hasFlags() => $_has(4);
@$pb.TagNumber(5)
void clearFlags() => clearField(5);

@$pb.TagNumber(6)
$core.int get height => $_getIZ(5);
@$pb.TagNumber(6)
set height($core.int v) { $_setUnsignedInt32(5, v); }
@$pb.TagNumber(6)
$core.bool hasHeight() => $_has(5);
@$pb.TagNumber(6)
void clearHeight() => clearField(6);

@$pb.TagNumber(7)
$fixnum.Int64 get startedAt => $_getI64(6);
@$pb.TagNumber(7)
set startedAt($fixnum.Int64 v) { $_setInt64(6, v); }
@$pb.TagNumber(7)
$core.bool hasStartedAt() => $_has(6);
@$pb.TagNumber(7)
void clearStartedAt() => clearField(7);
}

class PeerInfo extends $pb.GeneratedMessage {
Expand Down
14 changes: 5 additions & 9 deletions www/grpc/gen/dart/network.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ final $typed_data.Uint8List getNetworkInfoRequestDescriptor = $convert.base64Dec
const GetNetworkInfoResponse$json = const {
'1': 'GetNetworkInfoResponse',
'2': const [
const {'1': 'self_id', '3': 1, '4': 1, '5': 12, '10': 'selfId'},
const {'1': 'total_sent_bytes', '3': 2, '4': 1, '5': 5, '10': 'totalSentBytes'},
const {'1': 'total_received_bytes', '3': 3, '4': 1, '5': 5, '10': 'totalReceivedBytes'},
const {'1': 'total_sent_bytes', '3': 1, '4': 1, '5': 5, '10': 'totalSentBytes'},
const {'1': 'total_received_bytes', '3': 2, '4': 1, '5': 5, '10': 'totalReceivedBytes'},
const {'1': 'started_at', '3': 3, '4': 1, '5': 3, '10': 'startedAt'},
const {'1': 'peers', '3': 4, '4': 3, '5': 11, '6': '.pactus.PeerInfo', '10': 'peers'},
],
};

/// Descriptor for `GetNetworkInfoResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getNetworkInfoResponseDescriptor = $convert.base64Decode('ChZHZXROZXR3b3JrSW5mb1Jlc3BvbnNlEhcKB3NlbGZfaWQYASABKAxSBnNlbGZJZBIoChB0b3RhbF9zZW50X2J5dGVzGAIgASgFUg50b3RhbFNlbnRCeXRlcxIwChR0b3RhbF9yZWNlaXZlZF9ieXRlcxgDIAEoBVISdG90YWxSZWNlaXZlZEJ5dGVzEiYKBXBlZXJzGAQgAygLMhAucGFjdHVzLlBlZXJJbmZvUgVwZWVycw==');
final $typed_data.Uint8List getNetworkInfoResponseDescriptor = $convert.base64Decode('ChZHZXROZXR3b3JrSW5mb1Jlc3BvbnNlEigKEHRvdGFsX3NlbnRfYnl0ZXMYASABKAVSDnRvdGFsU2VudEJ5dGVzEjAKFHRvdGFsX3JlY2VpdmVkX2J5dGVzGAIgASgFUhJ0b3RhbFJlY2VpdmVkQnl0ZXMSHQoKc3RhcnRlZF9hdBgDIAEoA1IJc3RhcnRlZEF0EiYKBXBlZXJzGAQgAygLMhAucGFjdHVzLlBlZXJJbmZvUgVwZWVycw==');
@$core.Deprecated('Use getNodeInfoRequestDescriptor instead')
const GetNodeInfoRequest$json = const {
'1': 'GetNodeInfoRequest',
Expand All @@ -42,15 +42,11 @@ const GetNodeInfoResponse$json = const {
const {'1': 'moniker', '3': 1, '4': 1, '5': 9, '10': 'moniker'},
const {'1': 'agent', '3': 2, '4': 1, '5': 9, '10': 'agent'},
const {'1': 'peer_id', '3': 3, '4': 1, '5': 12, '10': 'peerId'},
const {'1': 'consensus_keys', '3': 4, '4': 3, '5': 9, '10': 'consensusKeys'},
const {'1': 'flags', '3': 5, '4': 1, '5': 5, '10': 'flags'},
const {'1': 'height', '3': 6, '4': 1, '5': 13, '10': 'height'},
const {'1': 'started_at', '3': 7, '4': 1, '5': 3, '10': 'startedAt'},
],
};

/// Descriptor for `GetNodeInfoResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAxSBnBlZXJJZBIlCg5jb25zZW5zdXNfa2V5cxgEIAMoCVINY29uc2Vuc3VzS2V5cxIUCgVmbGFncxgFIAEoBVIFZmxhZ3MSFgoGaGVpZ2h0GAYgASgNUgZoZWlnaHQSHQoKc3RhcnRlZF9hdBgHIAEoA1IJc3RhcnRlZEF0');
final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAxSBnBlZXJJZA==');
@$core.Deprecated('Use peerInfoDescriptor instead')
const PeerInfo$json = const {
'1': 'PeerInfo',
Expand Down

0 comments on commit 8da78dc

Please sign in to comment.