Files
sdk/runtime/observatory/lib/service_io.dart
T
Ben Konyi 15b11b0183 [ VM / Service / Observatory ] The VM service now requires an authentication code by default.
Previously, a valid web socket connection would use the following URI:

`ws://127.0.0.1/ws`

Now, by default, the VM service requires a connection to be made with a
URI similar to the following:

`ws://127.0.0.1:8181/Ug_U0QVsqFs=/ws`

where `Ug_U0QVsqFs` is an authentication code generated and shared by the
service.

This behavior can be disabled with the `--disable-service-auth-codes`
flag.

Change-Id: I288aac58e3ba9d35dca8071f3f7e7a073896c271
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98433
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2019-04-09 22:57:29 +00:00

59 lines
1.6 KiB
Dart

// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library service_io;
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:logging/logging.dart';
import 'package:observatory/service_common.dart';
// Export the service library.
export 'package:observatory/service_common.dart';
class _IOWebSocket implements CommonWebSocket {
WebSocket _webSocket;
void connect(String address, void onOpen(), void onMessage(dynamic data),
void onError(), void onClose()) {
WebSocket.connect(address).then((WebSocket socket) {
_webSocket = socket;
_webSocket.listen(onMessage,
onError: (dynamic) => onError(),
onDone: onClose,
cancelOnError: true);
onOpen();
}).catchError((e, st) {
onError();
});
}
bool get isOpen =>
(_webSocket != null) && (_webSocket.readyState == WebSocket.open);
void send(dynamic data) {
_webSocket.add(data);
}
void close() {
if (_webSocket != null) {
_webSocket.close();
}
}
Future<ByteData> nonStringToByteData(dynamic data) {
assert(data is Uint8List);
Logger.root.info('Binary data size in bytes: ${data.lengthInBytes}');
return new Future.sync(() =>
new ByteData.view(data.buffer, data.offsetInBytes, data.lengthInBytes));
}
}
/// The [WebSocketVM] communicates with a Dart VM over WebSocket.
class WebSocketVM extends CommonWebSocketVM {
WebSocketVM(WebSocketVMTarget target) : super(target, new _IOWebSocket());
}