Skip to content

Commit 23f80fb

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ package:dds ] Add IPv6 support; 1.3.2 release
Change-Id: I62ca85c2340d8c91fd2f08c945bf981ac36adad3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161400 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent d275566 commit 23f80fb

File tree

5 files changed

+66
-17
lines changed

5 files changed

+66
-17
lines changed

pkg/dds/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# 1.3.2-dev
1+
# 1.3.2
22

3+
- Add IPv6 hosting support.
34
- Fix handling of requests that are outstanding when a client channel is closed.
45

56
# 1.3.1

pkg/dds/lib/dds.dart

+24-5
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,23 @@ abstract class DartDevelopmentService {
5151
/// development service will communicate with.
5252
///
5353
/// If provided, [serviceUri] will determine the address and port of the
54-
/// spawned Dart Development Service.
54+
/// spawned Dart Development Service. The format of [serviceUri] must be
55+
/// consistent with the protocol determined by [ipv6].
5556
///
5657
/// [enableAuthCodes] controls whether or not an authentication code must
5758
/// be provided by clients when communicating with this instance of
5859
/// [DartDevelopmentService]. Authentication codes take the form of a base64
5960
/// encoded string provided as the first element of the DDS path and is meant
6061
/// to make it more difficult for unintended clients to connect to this
6162
/// service. Authentication codes are enabled by default.
63+
///
64+
/// [ipv6] controls whether or not DDS is served via IPv6. IPv4 is enabled by
65+
/// default.
6266
static Future<DartDevelopmentService> startDartDevelopmentService(
6367
Uri remoteVmServiceUri, {
6468
Uri serviceUri,
6569
bool enableAuthCodes = true,
70+
bool ipv6 = false,
6671
}) async {
6772
if (remoteVmServiceUri == null) {
6873
throw ArgumentError.notNull('remoteVmServiceUri');
@@ -72,15 +77,29 @@ abstract class DartDevelopmentService {
7277
'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}',
7378
);
7479
}
75-
if (serviceUri != null && serviceUri.scheme != 'http') {
76-
throw ArgumentError(
77-
'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}',
78-
);
80+
if (serviceUri != null) {
81+
if (serviceUri.scheme != 'http') {
82+
throw ArgumentError(
83+
'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}',
84+
);
85+
}
86+
87+
// If provided an address to bind to, ensure it uses a protocol consistent
88+
// with that used to spawn DDS.
89+
final address = (await InternetAddress.lookup(serviceUri.host)).first;
90+
if ((ipv6 && address.type != InternetAddressType.IPv6) ||
91+
(!ipv6 && address.type != InternetAddressType.IPv4)) {
92+
throw ArgumentError(
93+
"serviceUri '$serviceUri' is not an IPv${ipv6 ? "6" : "4"} address.",
94+
);
95+
}
7996
}
97+
8098
final service = _DartDevelopmentService(
8199
remoteVmServiceUri,
82100
serviceUri,
83101
enableAuthCodes,
102+
ipv6,
84103
);
85104
await service.startService();
86105
return service;

pkg/dds/lib/src/dds_impl.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ part of dds;
66

77
class _DartDevelopmentService implements DartDevelopmentService {
88
_DartDevelopmentService(
9-
this._remoteVmServiceUri,
10-
this._uri,
11-
this._authCodesEnabled,
12-
) {
9+
this._remoteVmServiceUri, this._uri, this._authCodesEnabled, this._ipv6) {
1310
_clientManager = _ClientManager(this);
1411
_expressionEvaluator = _ExpressionEvaluator(this);
1512
_isolateManager = _IsolateManager(this);
@@ -38,8 +35,9 @@ class _DartDevelopmentService implements DartDevelopmentService {
3835

3936
Future<void> _startDDSServer() async {
4037
// No provided address, bind to an available port on localhost.
41-
// TODO(bkonyi): handle case where there's no IPv4 loopback.
42-
final host = uri?.host ?? InternetAddress.loopbackIPv4.host;
38+
final host = uri?.host ??
39+
(_ipv6 ? InternetAddress.loopbackIPv6 : InternetAddress.loopbackIPv4)
40+
.host;
4341
final port = uri?.port ?? 0;
4442

4543
// Start the DDS server.
@@ -226,6 +224,8 @@ class _DartDevelopmentService implements DartDevelopmentService {
226224
Uri get wsUri => _toWebSocket(_uri);
227225
Uri _uri;
228226

227+
final bool _ipv6;
228+
229229
bool get isRunning => _uri != null;
230230

231231
Future<void> get done => _done.future;

pkg/dds/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
A library used to spawn the Dart Developer Service, used to communicate with
44
a Dart VM Service instance.
55
6-
version: 1.3.2-dev
6+
version: 1.3.2
77

88
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/dds
99

pkg/dds/test/smoke_test.dart

+33-4
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,26 @@ void main() {
2727
process = null;
2828
});
2929

30-
void createSmokeTest(bool useAuthCodes) {
30+
void createSmokeTest(bool useAuthCodes, bool ipv6) {
31+
final protocol = ipv6 ? 'IPv6' : 'IPv4';
3132
test(
32-
'Smoke Test with ${useAuthCodes ? "" : "no "} authentication codes',
33+
'Smoke Test with ${useAuthCodes ? "" : "no"} authentication codes '
34+
'with $protocol',
3335
() async {
3436
dds = await DartDevelopmentService.startDartDevelopmentService(
3537
remoteVmServiceUri,
3638
enableAuthCodes: useAuthCodes,
39+
ipv6: ipv6,
3740
);
3841
expect(dds.isRunning, true);
3942

43+
try {
44+
Uri.parseIPv6Address(dds.uri.host);
45+
expect(ipv6, true);
46+
} on FormatException {
47+
expect(ipv6, false);
48+
}
49+
4050
// Ensure basic websocket requests are forwarded correctly to the VM service.
4151
final service = await vmServiceConnectUri(dds.wsUri.toString());
4252
final version = await service.getVersion();
@@ -69,8 +79,9 @@ void main() {
6979
);
7080
}
7181

72-
createSmokeTest(true);
73-
createSmokeTest(false);
82+
createSmokeTest(true, false);
83+
createSmokeTest(false, false);
84+
createSmokeTest(true, true);
7485

7586
test('startup fails when VM service has existing clients', () async {
7687
Uri httpToWebSocketUri(Uri httpUri) {
@@ -121,5 +132,23 @@ void main() {
121132
serviceUri: Uri.parse('dart-lang://localhost:2345'),
122133
),
123134
throwsA(TypeMatcher<ArgumentError>()));
135+
136+
// Protocol mismatch
137+
expect(
138+
() async => await DartDevelopmentService.startDartDevelopmentService(
139+
Uri.parse('http://localhost:1234'),
140+
serviceUri: Uri.parse('http://127.0.0.1:2345'),
141+
ipv6: true,
142+
),
143+
throwsA(TypeMatcher<ArgumentError>()));
144+
145+
// Protocol mismatch
146+
expect(
147+
() async => await DartDevelopmentService.startDartDevelopmentService(
148+
Uri.parse('http://localhost:1234'),
149+
serviceUri: Uri.parse('http://[::1]:2345'),
150+
ipv6: false,
151+
),
152+
throwsA(TypeMatcher<ArgumentError>()));
124153
});
125154
}

0 commit comments

Comments
 (0)