Unverified Commit 9d770c10 authored by michaellee8's avatar michaellee8 Committed by GitHub

[flutter_tools] fix pm serve ipv6 linklocal addr issue (#55664)

parent 9d106bde
...@@ -58,7 +58,7 @@ class FuchsiaAmberCtl { ...@@ -58,7 +58,7 @@ class FuchsiaAmberCtl {
/// Teaches the amber instance running on [device] about the Fuchsia package /// Teaches the amber instance running on [device] about the Fuchsia package
/// server accessible via [configUrl]. /// server accessible via [configUrl].
Future<bool> addSrc(FuchsiaDevice device, FuchsiaPackageServer server) async { Future<bool> addSrc(FuchsiaDevice device, FuchsiaPackageServer server) async {
final String configUrl = '${server.url}/config.json'; final String configUrl = '${server.interfaceStrippedUrl}/config.json';
final RunResult result = final RunResult result =
await device.shell('amber_ctl add_src -x -f $configUrl'); await device.shell('amber_ctl add_src -x -f $configUrl');
return result.exitCode == 0; return result.exitCode == 0;
...@@ -68,7 +68,7 @@ class FuchsiaAmberCtl { ...@@ -68,7 +68,7 @@ class FuchsiaAmberCtl {
/// Fuchsia package server that it was accessing via [serverUrl]. /// Fuchsia package server that it was accessing via [serverUrl].
Future<bool> rmSrc(FuchsiaDevice device, FuchsiaPackageServer server) async { Future<bool> rmSrc(FuchsiaDevice device, FuchsiaPackageServer server) async {
final RunResult result = final RunResult result =
await device.shell('amber_ctl rm_src -n ${server.url}'); await device.shell('amber_ctl rm_src -n ${server.interfaceStrippedUrl}');
return result.exitCode == 0; return result.exitCode == 0;
} }
...@@ -84,7 +84,7 @@ class FuchsiaAmberCtl { ...@@ -84,7 +84,7 @@ class FuchsiaAmberCtl {
/// pkg_resolver repo config, and teaches the pkg_resolver instance running /// pkg_resolver repo config, and teaches the pkg_resolver instance running
/// on [device] about the [FuchsiaPackageServer]. /// on [device] about the [FuchsiaPackageServer].
Future<bool> addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async { Future<bool> addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async {
final String configUrl = '${server.url}/config.json'; final String configUrl = '${server.interfaceStrippedUrl}/config.json';
final RunResult result = final RunResult result =
await device.shell('amber_ctl add_repo_cfg -n ${server.name} -f $configUrl'); await device.shell('amber_ctl add_repo_cfg -n ${server.name} -f $configUrl');
return result.exitCode == 0; return result.exitCode == 0;
......
...@@ -111,7 +111,7 @@ class FuchsiaPM { ...@@ -111,7 +111,7 @@ class FuchsiaPM {
throwToolExit('Fuchsia pm tool not found'); throwToolExit('Fuchsia pm tool not found');
} }
if (isIPv6Address(host.split('%').first)) { if (isIPv6Address(host.split('%').first)) {
host = '[${host.replaceAll('%', '%25')}]'; host = '[$host]';
} }
final List<String> command = <String>[ final List<String> command = <String>[
globals.fuchsiaArtifacts.pm.path, globals.fuchsiaArtifacts.pm.path,
...@@ -181,12 +181,6 @@ class FuchsiaPM { ...@@ -181,12 +181,6 @@ class FuchsiaPM {
/// } /// }
class FuchsiaPackageServer { class FuchsiaPackageServer {
factory FuchsiaPackageServer(String repo, String name, String host, int port) { factory FuchsiaPackageServer(String repo, String name, String host, int port) {
// TODO(jonahwilliams): ensure we only receive valid ipv4 or ipv6 InternetAddresses.
// Temporary work around to receiving ipv6 addresses with trailing information:
// fe80::ec4:7aff:fecc:ea8f%eno2
if (host.contains('%')) {
host = host.split('%').first;
}
return FuchsiaPackageServer._(repo, name, host, port); return FuchsiaPackageServer._(repo, name, host, port);
} }
...@@ -204,6 +198,14 @@ class FuchsiaPackageServer { ...@@ -204,6 +198,14 @@ class FuchsiaPackageServer {
/// The URL that can be used by the device to access this package server. /// The URL that can be used by the device to access this package server.
String get url => Uri(scheme: 'http', host: _host, port: _port).toString(); String get url => Uri(scheme: 'http', host: _host, port: _port).toString();
/// The URL that is stripped of interface name if it is an ipv6 address,
/// which should be supplied to amber_ctl to configure access to host
String get interfaceStrippedUrl => Uri(
scheme: 'http',
host: (isIPv6Address(_host.split('%').first)) ? '[${_host.split('%').first}]' : _host,
port: _port,
).toString();
// The name used to reference the server by fuchsia-pkg:// urls. // The name used to reference the server by fuchsia-pkg:// urls.
final String name; final String name;
......
...@@ -65,7 +65,7 @@ void main() { ...@@ -65,7 +65,7 @@ void main() {
'-repo', '-repo',
'<repo>', '<repo>',
'-l', '-l',
'[fe80::ec4:7aff:fecc:ea8f%25eno2]:43819', '[fe80::ec4:7aff:fecc:ea8f%eno2]:43819',
])).called(1); ])).called(1);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FuchsiaArtifacts: () => mockFuchsiaArtifacts, FuchsiaArtifacts: () => mockFuchsiaArtifacts,
...@@ -78,6 +78,11 @@ void main() { ...@@ -78,6 +78,11 @@ void main() {
expect( expect(
FuchsiaPackageServer('a', 'b', host, port).url, FuchsiaPackageServer('a', 'b', host, port).url,
'http://[fe80::ec4:7aff:fecc:ea8f%25eno2]:23',
);
expect(
FuchsiaPackageServer('a', 'b', host, port).interfaceStrippedUrl,
'http://[fe80::ec4:7aff:fecc:ea8f]:23', 'http://[fe80::ec4:7aff:fecc:ea8f]:23',
); );
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment