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

src: fix json payload from inspector #7232

Merged
merged 1 commit into from
Jun 9, 2016
Merged
Changes from all commits
Commits
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
22 changes: 13 additions & 9 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ namespace node {
namespace {

const char DEVTOOLS_PATH[] = "/node";
const char DEVTOOLS_HASH[] = "521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef";

void PrintDebuggerReadyMessage(int port) {
fprintf(stderr, "Debugger listening on port %d.\n"
"To start debugging, open the following URL in Chrome:\n"
" chrome-devtools://devtools/remote/serve_file/"
"@521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef/inspector.html?"
"experiments=true&v8only=true&ws=localhost:%d/node\n", port, port);
"@%s/inspector.html?"
"experiments=true&v8only=true&ws=localhost:%d/node\n",
port, DEVTOOLS_HASH, port);
}

bool AcceptsConnection(inspector_socket_t* socket, const char* path) {
Expand Down Expand Up @@ -89,18 +91,19 @@ void SendVersionResponse(inspector_socket_t* socket) {
SendHttpResponse(socket, buffer, len);
}

void SendTargentsListResponse(inspector_socket_t* socket) {
void SendTargentsListResponse(inspector_socket_t* socket, int port) {
const char LIST_RESPONSE_TEMPLATE[] =
"[ {"
" \"description\": \"node.js instance\","
" \"devtoolsFrontendUrl\": "
"\"https://chrome-devtools-frontend.appspot.com/serve_file/"
"@4604d24a75168768584760ba56d175507941852f/inspector.html\","
"@%s/inspector.html?experiments=true&v8only=true"
"&ws=localhost:%d%s\","
" \"faviconUrl\": \"https://nodejs.org/static/favicon.ico\","
" \"id\": \"%d\","
" \"title\": \"%s\","
" \"type\": \"node\","
" \"webSocketDebuggerUrl\": \"ws://%s\""
" \"webSocketDebuggerUrl\": \"ws://localhost:%d%s\""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% that this should be localhost... it should potentially be the ip associated with the addr incase there is remote debugging going on. Open to modifying this but wanted to check first

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

Indeed, it would be nice to get rid of the hard coded localhost and use the
value from addr()

I'm not sure if it's binding to 0.0.0.0 or the local IP (enables remoting
over the network?)

On Wed, Jun 8, 2016 at 1:16 PM Myles Borins notifications@github.com
wrote:

In src/inspector_agent.cc
#7232 (comment):

   "  \"faviconUrl\": \"https://nodejs.org/static/favicon.ico\","
   "  \"id\": \"%d\","
   "  \"title\": \"%s\","
   "  \"type\": \"node\","
  •  "  \"webSocketDebuggerUrl\": \"ws://%s\""
    
  •  "  \"webSocketDebuggerUrl\": \"ws://localhost:%d%s\""
    

I'm not 100% that this should be localhost... it should potentially be the
ip associated with the addr incase there is remote debugging going on. Open
to modifying this but wanted to check first


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/nodejs/node/pull/7232/files/aca56db0c4691b6080290792ec8318c04dcb6347#r66331013,
or mute the thread
https://github.com/notifications/unsubscribe/AAKl9ySsaar49QaCCK7P28BUgi8ZlXSJks5qJyMlgaJpZM4IxWgR
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave it as a localhost for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@auchenberg I'll dig into this some more and maybe make a different PR that builds on this one.

"} ]";
char buffer[sizeof(LIST_RESPONSE_TEMPLATE) + 4096];
char title[2048]; // uv_get_process_title trims the title if too long
Expand All @@ -114,12 +117,13 @@ void SendTargentsListResponse(inspector_socket_t* socket) {
c++;
}
size_t len = snprintf(buffer, sizeof(buffer), LIST_RESPONSE_TEMPLATE,
getpid(), title, DEVTOOLS_PATH);
DEVTOOLS_HASH, port, DEVTOOLS_PATH, getpid(),
title, port, DEVTOOLS_PATH);
ASSERT_LT(len, sizeof(buffer));
SendHttpResponse(socket, buffer, len);
}

bool RespondToGet(inspector_socket_t* socket, const char* path) {
bool RespondToGet(inspector_socket_t* socket, const char* path, int port) {
const char PATH[] = "/json";
const char PATH_LIST[] = "/json/list";
const char PATH_VERSION[] = "/json/version";
Expand All @@ -128,7 +132,7 @@ bool RespondToGet(inspector_socket_t* socket, const char* path) {
SendVersionResponse(socket);
} else if (!strncmp(PATH_LIST, path, sizeof(PATH_LIST)) ||
!strncmp(PATH, path, sizeof(PATH))) {
SendTargentsListResponse(socket);
SendTargentsListResponse(socket, port);
} else if (!strncmp(path, PATH_ACTIVATE, sizeof(PATH_ACTIVATE) - 1) &&
atoi(path + (sizeof(PATH_ACTIVATE) - 1)) == getpid()) {
const char TARGET_ACTIVATED[] = "Target activated";
Expand Down Expand Up @@ -348,7 +352,7 @@ bool Agent::OnInspectorHandshakeIO(inspector_socket_t* socket,
Agent* agent = static_cast<Agent*>(socket->data);
switch (state) {
case kInspectorHandshakeHttpGet:
return RespondToGet(socket, path);
return RespondToGet(socket, path, agent->port_);
case kInspectorHandshakeUpgrading:
return AcceptsConnection(socket, path);
case kInspectorHandshakeUpgraded:
Expand Down