Handle timeouts in guard testing; address some review comments

pull/1000/head
Maxim Shishmarev 5 years ago
parent b786df8045
commit f2ef69f00d

@ -116,9 +116,9 @@ const sendOnionRequest = async (req_idx, nodePath, targetNode, plaintext) => {
const url = `https://${nodePath[0].ip}:${nodePath[0].port}/onion_req`; const url = `https://${nodePath[0].ip}:${nodePath[0].port}/onion_req`;
// we only proxy to snodes... // we only proxy to snodes...
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const response = await nodeFetch(url, fetchOptions); const response = await nodeFetch(url, fetchOptions);
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1';
return await processOnionResponse(req_idx, response, ctx_1.symmetricKey, true); return await processOnionResponse(req_idx, response, ctx_1.symmetricKey, true);
} }

@ -34,7 +34,7 @@ class LokiSnodeAPI {
async test_guard_node(snode) { async test_guard_node(snode) {
log.info("Testing a candidate guard node ", snode); log.info("[maxim] Testing a candidate guard node ", snode);
// Send a post request and make sure it is OK // Send a post request and make sure it is OK
const endpoint = "/storage_rpc/v1"; const endpoint = "/storage_rpc/v1";
@ -57,15 +57,26 @@ class LokiSnodeAPI {
method: 'POST', method: 'POST',
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
timeout: 1000 // 1s, we want a small timeout for testing timeout: 10000 // 10s, we want a smaller timeout for testing
}; };
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const response = await nodeFetch(url, fetchOptions);
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1; let response;
try {
response = await nodeFetch(url, fetchOptions);
} catch (e) {
if (e.type === 'request-timeout') {
log.warn(`[maxim] test timeout for node,`, snode);
}
return false;
} finally {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1';
}
if (!response.ok) { if (!response.ok) {
log.log(`Node ${snode} failed the guard test`); log.info(`Node failed the guard test:`, snode);
} }
return response.ok; return response.ok;
@ -166,6 +177,8 @@ class LokiSnodeAPI {
const all_nodes = await this.getRandomSnodePool(); const all_nodes = await this.getRandomSnodePool();
log.info("[maxim] all nodes: ", all_nodes.length);
if (this.guardNodes.length == 0) { if (this.guardNodes.length == 0) {
// Not cached, load from DB // Not cached, load from DB
@ -242,7 +255,8 @@ class LokiSnodeAPI {
const trySeedNode = async (consecutiveErrors = 0) => { const trySeedNode = async (consecutiveErrors = 0) => {
// Removed limit until there is a way to get snode info // Removed limit until there is a way to get snode info
// for individual nodes (needed for guard nodes) // for individual nodes (needed for guard nodes); this way
// we get all active nodes
const params = { const params = {
active_only: true, active_only: true,
fields: { fields: {

Loading…
Cancel
Save