make explicit file size RPCs unauthenticated
This commit is contained in:
@@ -99,7 +99,9 @@ types of messages:
|
||||
delete ctx.pending[txid];
|
||||
return;
|
||||
}
|
||||
console.error("received message [%s] for txid[%s] with no callback", msg, txid);
|
||||
if (parsed.length !== 2) {
|
||||
console.error("received message [%s] for txid[%s] with no callback", msg, txid);
|
||||
}
|
||||
};
|
||||
|
||||
var create = function (network, edPrivateKey, edPublicKey, cb) {
|
||||
@@ -217,5 +219,104 @@ types of messages:
|
||||
});
|
||||
};
|
||||
|
||||
return { create: create };
|
||||
var onAnonMsg = function (ctx, msg) {
|
||||
var parsed = parse(msg);
|
||||
|
||||
if (!parsed) {
|
||||
return void console.error(new Error('could not parse message: %s', msg));
|
||||
}
|
||||
|
||||
// RPC messages are always arrays.
|
||||
if (!Array.isArray(parsed)) { return; }
|
||||
var txid = parsed[0];
|
||||
|
||||
// txid must be a string, or this message is not meant for us
|
||||
if (typeof(txid) !== 'string') { return; }
|
||||
|
||||
var pending = ctx.pending[txid];
|
||||
|
||||
if (!(parsed && parsed.slice)) {
|
||||
// RPC responses are arrays. this message isn't meant for us.
|
||||
return;
|
||||
}
|
||||
if (/FULL_HISTORY/.test(parsed[0])) { return; }
|
||||
var response = parsed.slice(2);
|
||||
|
||||
if (typeof(pending) === 'function') {
|
||||
if (parsed[1] === 'ERROR') {
|
||||
pending(parsed[2]);
|
||||
delete ctx.pending[txid];
|
||||
return;
|
||||
}
|
||||
pending(void 0, response);
|
||||
|
||||
// if successful, delete the callback...
|
||||
delete ctx.pending[txid];
|
||||
return;
|
||||
}
|
||||
// HACK: filter out ugly messages we don't care about
|
||||
if (typeof(msg) !== 'string') {
|
||||
console.error("received message [%s] for txid[%s] with no callback", msg, txid);
|
||||
}
|
||||
};
|
||||
|
||||
var createAnonymous = function (network, cb) {
|
||||
var ctx = {
|
||||
network: network,
|
||||
timeouts: {}, // timeouts
|
||||
pending: {}, // callbacks
|
||||
cookie: null,
|
||||
connected: true,
|
||||
};
|
||||
|
||||
var send = ctx.send = function (type, msg, cb) {
|
||||
if (!ctx.connected) {
|
||||
return void window.setTimeout(function () {
|
||||
cb('DISCONNECTED');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// construct an unsigned message...
|
||||
var data = [type, msg];
|
||||
|
||||
// [sig, edPublicKey, cookie, type, msg]
|
||||
return sendMsg(ctx, data, cb);
|
||||
};
|
||||
|
||||
ctx.resend = function (txid) {
|
||||
var pending = ctx.pending[txid];
|
||||
if (pending.called) {
|
||||
console.error("[%s] called too many times", txid);
|
||||
return true;
|
||||
}
|
||||
pending.called++;
|
||||
|
||||
try {
|
||||
return ctx.network.sendto(ctx.network.historyKeeper,
|
||||
JSON.stringify([txid, pending.data]));
|
||||
} catch (e) {
|
||||
console.log("failed to resend");
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
network.on('message', function (msg) {
|
||||
onAnonMsg(ctx, msg);
|
||||
});
|
||||
|
||||
network.on('disconnect', function () {
|
||||
ctx.connected = false;
|
||||
});
|
||||
|
||||
network.on('reconnect', function () {
|
||||
ctx.connected = true;
|
||||
});
|
||||
|
||||
cb(void 0, {
|
||||
send: send
|
||||
});
|
||||
};
|
||||
|
||||
return { create: create, createAnonymous: createAnonymous };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user