Skip to content
Snippets Groups Projects
Commit 8905f798 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fixes for websocket bugs

parent dbc38fec
No related branches found
No related tags found
No related merge requests found
......@@ -65,15 +65,15 @@ void ftl::net::Dispatcher::dispatch_call(Peer &s, const msgpack::object &msg) {
// assert(type == 0);
if (type == 1) {
DLOG(INFO) << "RPC return for " << id;
LOG(INFO) << "RPC return for " << id;
s._dispatchResponse(id, args);
} else if (type == 0) {
DLOG(INFO) << "RPC " << name << "() <- " << s.getURI();
LOG(INFO) << "RPC " << name << "() <- " << s.getURI();
auto func = _locateHandler(name);
if (func) {
DLOG(INFO) << "Found binding for " << name;
LOG(INFO) << "Found binding for " << name;
try {
auto result = (*func)(args); //->get();
s._sendResponse(id, result->get());
......
......@@ -489,9 +489,13 @@ bool Peer::_data() {
UNIQUE_LOCK(recv_mtx_,lk);
if (scheme_ == ftl::URI::SCHEME_WS && !ws_read_header_) {
if (scheme_ == ftl::URI::SCHEME_WS) {
LOG(INFO) << "Reading WS Header";
wsheader_type ws;
ws.header_size = 0;
if (ws_parse(recv_buf_, ws) < 0) {
LOG(ERROR) << "Bad WS header " << ws.header_size;
is_waiting_ = true;
return false;
}
ws_read_header_ = true;
......@@ -571,6 +575,7 @@ void Peer::cancelCall(int id) {
}
void Peer::_sendResponse(uint32_t id, const msgpack::object &res) {
LOG(INFO) << "Sending response: " << id;
Dispatcher::response_t res_obj = std::make_tuple(1,id,std::string(""),res);
UNIQUE_LOCK(send_mtx_,lk);
if (scheme_ == ftl::URI::SCHEME_WS) send_buf_.append_ref(nullptr,0);
......
......@@ -139,7 +139,7 @@ app.ws('/', (ws, req) => {
let p = new Peer(ws);
p.on("connect", (peer) => {
console.log("Node connected...");
console.log("Node connected...", peer.string_id);
peer_uris[peer.string_id] = [];
peer_by_id[peer.string_id] = peer;
......@@ -150,6 +150,7 @@ app.ws('/', (ws, req) => {
peer.name = obj.title;
peer.master = (obj.kind == "master");
console.log("Peer name = ", peer.name);
console.log("Details: ", details);
checkStreams(peer);
});
......@@ -175,6 +176,10 @@ app.ws('/', (ws, req) => {
checkStreams(p);
});
p.bind("node_details", () => {
return ['{"title": "FTL Web-Service", "id": "0", "kind": "master"}'];
});
p.bind("list_streams", () => {
return Object.keys(uri_data);
});
......@@ -189,10 +194,10 @@ app.ws('/', (ws, req) => {
}
});
p.proxy("source_calibration", (cb, uri) => {
p.proxy("source_details", (cb, uri) => {
let peer = uri_data[uri].peer;
if (peer) {
peer.rpc("source_calibration", cb, uri);
peer.rpc("source_details", cb, uri);
}
});
......
......@@ -90,11 +90,12 @@ Peer.prototype._dispatchNotification = function(name, args) {
Peer.prototype._dispatchCall = function(name, id, args) {
if (this.bindings.hasOwnProperty(name)) {
console.log("Call for:", name, id);
let res = this.bindings[name].apply(this, args);
try {
let res = this.bindings[name].apply(this, args);
this.sock.send(encode([1,id,name,res]));
} catch(e) {
console.error("Could to dispatch or return call");
this.close();
}
} else if (this.proxies.hasOwnProperty(name)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment