@@ -51,18 +51,23 @@ abstract class DartDevelopmentService {
51
51
/// development service will communicate with.
52
52
///
53
53
/// 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] .
55
56
///
56
57
/// [enableAuthCodes] controls whether or not an authentication code must
57
58
/// be provided by clients when communicating with this instance of
58
59
/// [DartDevelopmentService] . Authentication codes take the form of a base64
59
60
/// encoded string provided as the first element of the DDS path and is meant
60
61
/// to make it more difficult for unintended clients to connect to this
61
62
/// 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.
62
66
static Future <DartDevelopmentService > startDartDevelopmentService (
63
67
Uri remoteVmServiceUri, {
64
68
Uri serviceUri,
65
69
bool enableAuthCodes = true ,
70
+ bool ipv6 = false ,
66
71
}) async {
67
72
if (remoteVmServiceUri == null ) {
68
73
throw ArgumentError .notNull ('remoteVmServiceUri' );
@@ -72,15 +77,29 @@ abstract class DartDevelopmentService {
72
77
'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri .scheme }' ,
73
78
);
74
79
}
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
+ }
79
96
}
97
+
80
98
final service = _DartDevelopmentService (
81
99
remoteVmServiceUri,
82
100
serviceUri,
83
101
enableAuthCodes,
102
+ ipv6,
84
103
);
85
104
await service.startService ();
86
105
return service;
0 commit comments