Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gRPC): defining network and peers info response's properly #898

Merged
merged 19 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions network/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@ type Network interface {
NumConnectedPeers() int
ReachabilityStatus() string
HostAddrs() []string
Name() string
b00f marked this conversation as resolved.
Show resolved Hide resolved
DHTSize() int32
kehiy marked this conversation as resolved.
Show resolved Hide resolved
Protocols() []string
kehiy marked this conversation as resolved.
Show resolved Hide resolved
}
12 changes: 12 additions & 0 deletions network/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,15 @@ func (mock *MockNetwork) ReachabilityStatus() string {
func (mock *MockNetwork) HostAddrs() []string {
return []string{"localhost"}
}

func (mock *MockNetwork) Name() string {
return "pactus"
}

func (mock *MockNetwork) DHTSize() int32 {
return 0
}

func (mock *MockNetwork) Protocols() []string {
return []string{"gossip"}
}
16 changes: 16 additions & 0 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,19 @@

return addrs
}

func (n *network) Name() string {
return n.config.NetworkName

Check warning on line 403 in network/network.go

View check run for this annotation

Codecov / codecov/patch

network/network.go#L403

Added line #L403 was not covered by tests
}

func (n *network) DHTSize() int32 {
size, err := n.dht.kademlia.NetworkSize()
if err != nil {
return 0

Check warning on line 409 in network/network.go

View check run for this annotation

Codecov / codecov/patch

network/network.go#L407-L409

Added lines #L407 - L409 were not covered by tests
}
return size

Check warning on line 411 in network/network.go

View check run for this annotation

Codecov / codecov/patch

network/network.go#L411

Added line #L411 was not covered by tests
}

func (n *network) Protocols() []string {
return []string{string(n.stream.protocolID), string(n.notifee.streamProtocolID)}

Check warning on line 415 in network/network.go

View check run for this annotation

Codecov / codecov/patch

network/network.go#L415

Added line #L415 was not covered by tests
}
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const (
minor uint = 19
patch uint = 0
meta string = "beta"
protocolVersion uint = 1
ProtocolVersion uint = 1
kehiy marked this conversation as resolved.
Show resolved Hide resolved
)

func Agent() string {
return fmt.Sprintf("node=%s/node-version=v%s/protocol-version=%d/os=%s/arch=%s",
ExecutorName(), Version(), protocolVersion, runtime.GOOS, runtime.GOARCH)
ExecutorName(), Version(), ProtocolVersion, runtime.GOOS, runtime.GOARCH)
}

func Version() string {
Expand Down
7 changes: 5 additions & 2 deletions www/grpc/buf/grpc-gateway.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ http:
get: "/v1/transactions/amount/{amount}/payloadType/{payloadType}"

# Network APIs
- selector: pactus.Network.GetNetworkInfo
get: "/v1/network/info"
- selector: pactus.Network.GetPeersInfo
get: "/v1/network/peers"

- selector: pactus.Network.GetNodeInfo
get: "/v1/network/node"

- selector: pactus.Network.GetNetworkInfo
get: "/v1/network/info"

# Wallet APIs
- selector: pactus.Wallet.CreateWallet
get: "/v1/wallets/create/name/{name}/mnemonic/{mnemonic}/language/{language}"
Expand Down
216 changes: 177 additions & 39 deletions www/grpc/gen/dart/network.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,42 @@ 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.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)
..m<$core.int, $fixnum.Int64>(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'sentBytes', entryClassName: 'GetNetworkInfoResponse.SentBytesEntry', keyFieldType: $pb.PbFieldType.O3, valueFieldType: $pb.PbFieldType.O6, packageName: const $pb.PackageName('pactus'))
..m<$core.int, $fixnum.Int64>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'receivedBytes', entryClassName: 'GetNetworkInfoResponse.ReceivedBytesEntry', keyFieldType: $pb.PbFieldType.O3, valueFieldType: $pb.PbFieldType.O6, packageName: const $pb.PackageName('pactus'))
..a<$core.int>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'protocolVersion', $pb.PbFieldType.O3)
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'connectedPeers', $pb.PbFieldType.O3)
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'networkName')
..a<$core.int>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'networkDhtSize', $pb.PbFieldType.O3)
..pPS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'protocols')
..pPS(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'localAddress')
..hasRequiredFields = false
;

GetNetworkInfoResponse._() : super();
factory GetNetworkInfoResponse({
$core.int? totalSentBytes,
$core.int? totalReceivedBytes,
$fixnum.Int64? startedAt,
$core.Iterable<PeerInfo>? peers,
$core.Map<$core.int, $fixnum.Int64>? sentBytes,
$core.Map<$core.int, $fixnum.Int64>? receivedBytes,
$core.int? protocolVersion,
$core.int? connectedPeers,
$core.String? networkName,
$core.int? networkDhtSize,
$core.Iterable<$core.String>? protocols,
$core.Iterable<$core.String>? localAddress,
}) {
final _result = create();
if (totalSentBytes != null) {
_result.totalSentBytes = totalSentBytes;
if (protocolVersion != null) {
_result.protocolVersion = protocolVersion;
}
if (totalReceivedBytes != null) {
_result.totalReceivedBytes = totalReceivedBytes;
if (connectedPeers != null) {
_result.connectedPeers = connectedPeers;
}
if (startedAt != null) {
_result.startedAt = startedAt;
if (networkName != null) {
_result.networkName = networkName;
}
if (peers != null) {
_result.peers.addAll(peers);
if (networkDhtSize != null) {
_result.networkDhtSize = networkDhtSize;
}
if (sentBytes != null) {
_result.sentBytes.addAll(sentBytes);
if (protocols != null) {
_result.protocols.addAll(protocols);
}
if (receivedBytes != null) {
_result.receivedBytes.addAll(receivedBytes);
if (localAddress != null) {
_result.localAddress.addAll(localAddress);
}
return _result;
}
Expand All @@ -103,40 +103,46 @@ class GetNetworkInfoResponse extends $pb.GeneratedMessage {
static GetNetworkInfoResponse? _defaultInstance;

@$pb.TagNumber(1)
$core.int get totalSentBytes => $_getIZ(0);
$core.int get protocolVersion => $_getIZ(0);
@$pb.TagNumber(1)
set totalSentBytes($core.int v) { $_setSignedInt32(0, v); }
set protocolVersion($core.int v) { $_setSignedInt32(0, v); }
@$pb.TagNumber(1)
$core.bool hasTotalSentBytes() => $_has(0);
$core.bool hasProtocolVersion() => $_has(0);
@$pb.TagNumber(1)
void clearTotalSentBytes() => clearField(1);
void clearProtocolVersion() => clearField(1);

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

@$pb.TagNumber(3)
$fixnum.Int64 get startedAt => $_getI64(2);
$core.String get networkName => $_getSZ(2);
@$pb.TagNumber(3)
set startedAt($fixnum.Int64 v) { $_setInt64(2, v); }
set networkName($core.String v) { $_setString(2, v); }
@$pb.TagNumber(3)
$core.bool hasStartedAt() => $_has(2);
$core.bool hasNetworkName() => $_has(2);
@$pb.TagNumber(3)
void clearStartedAt() => clearField(3);
void clearNetworkName() => clearField(3);

@$pb.TagNumber(4)
$core.List<PeerInfo> get peers => $_getList(3);
$core.int get networkDhtSize => $_getIZ(3);
@$pb.TagNumber(4)
set networkDhtSize($core.int v) { $_setSignedInt32(3, v); }
@$pb.TagNumber(4)
$core.bool hasNetworkDhtSize() => $_has(3);
@$pb.TagNumber(4)
void clearNetworkDhtSize() => clearField(4);

@$pb.TagNumber(5)
$core.Map<$core.int, $fixnum.Int64> get sentBytes => $_getMap(4);
$core.List<$core.String> get protocols => $_getList(4);

@$pb.TagNumber(6)
$core.Map<$core.int, $fixnum.Int64> get receivedBytes => $_getMap(5);
$core.List<$core.String> get localAddress => $_getList(5);
}

class GetNodeInfoRequest extends $pb.GeneratedMessage {
Expand Down Expand Up @@ -265,6 +271,134 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
$core.List<$core.String> get addrs => $_getList(4);
}

class GetPeersInfoRequest extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'GetPeersInfoRequest', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..hasRequiredFields = false
;

GetPeersInfoRequest._() : super();
factory GetPeersInfoRequest() => create();
factory GetPeersInfoRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory GetPeersInfoRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
GetPeersInfoRequest clone() => GetPeersInfoRequest()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
GetPeersInfoRequest copyWith(void Function(GetPeersInfoRequest) updates) => super.copyWith((message) => updates(message as GetPeersInfoRequest)) as GetPeersInfoRequest; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static GetPeersInfoRequest create() => GetPeersInfoRequest._();
GetPeersInfoRequest createEmptyInstance() => create();
static $pb.PbList<GetPeersInfoRequest> createRepeated() => $pb.PbList<GetPeersInfoRequest>();
@$core.pragma('dart2js:noInline')
static GetPeersInfoRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<GetPeersInfoRequest>(create);
static GetPeersInfoRequest? _defaultInstance;
}

class GetPeersInfoResponse extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'GetPeersInfoResponse', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..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)
..m<$core.int, $fixnum.Int64>(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'sentBytes', entryClassName: 'GetPeersInfoResponse.SentBytesEntry', keyFieldType: $pb.PbFieldType.O3, valueFieldType: $pb.PbFieldType.O6, packageName: const $pb.PackageName('pactus'))
..m<$core.int, $fixnum.Int64>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'receivedBytes', entryClassName: 'GetPeersInfoResponse.ReceivedBytesEntry', keyFieldType: $pb.PbFieldType.O3, valueFieldType: $pb.PbFieldType.O6, packageName: const $pb.PackageName('pactus'))
..hasRequiredFields = false
;

GetPeersInfoResponse._() : super();
factory GetPeersInfoResponse({
$core.int? totalSentBytes,
$core.int? totalReceivedBytes,
$fixnum.Int64? startedAt,
$core.Iterable<PeerInfo>? peers,
$core.Map<$core.int, $fixnum.Int64>? sentBytes,
$core.Map<$core.int, $fixnum.Int64>? receivedBytes,
}) {
final _result = create();
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);
}
if (sentBytes != null) {
_result.sentBytes.addAll(sentBytes);
}
if (receivedBytes != null) {
_result.receivedBytes.addAll(receivedBytes);
}
return _result;
}
factory GetPeersInfoResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory GetPeersInfoResponse.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
GetPeersInfoResponse clone() => GetPeersInfoResponse()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
GetPeersInfoResponse copyWith(void Function(GetPeersInfoResponse) updates) => super.copyWith((message) => updates(message as GetPeersInfoResponse)) as GetPeersInfoResponse; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static GetPeersInfoResponse create() => GetPeersInfoResponse._();
GetPeersInfoResponse createEmptyInstance() => create();
static $pb.PbList<GetPeersInfoResponse> createRepeated() => $pb.PbList<GetPeersInfoResponse>();
@$core.pragma('dart2js:noInline')
static GetPeersInfoResponse getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<GetPeersInfoResponse>(create);
static GetPeersInfoResponse? _defaultInstance;

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

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

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

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

@$pb.TagNumber(5)
$core.Map<$core.int, $fixnum.Int64> get sentBytes => $_getMap(4);

@$pb.TagNumber(6)
$core.Map<$core.int, $fixnum.Int64> get receivedBytes => $_getMap(5);
}

class PeerInfo extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'PeerInfo', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..a<$core.int>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'status', $pb.PbFieldType.O3)
Expand Down Expand Up @@ -552,5 +686,9 @@ class NetworkApi {
var emptyResponse = GetNodeInfoResponse();
return _client.invoke<GetNodeInfoResponse>(ctx, 'Network', 'GetNodeInfo', request, emptyResponse);
}
$async.Future<GetPeersInfoResponse> getPeersInfo($pb.ClientContext? ctx, GetPeersInfoRequest request) {
var emptyResponse = GetPeersInfoResponse();
return _client.invoke<GetPeersInfoResponse>(ctx, 'Network', 'GetPeersInfo', request, emptyResponse);
}
}

Loading
Loading