Testing docker sia IP
This commit is contained in:
parent
50c1239a68
commit
f94cf74dd1
|
@ -1,4 +1,3 @@
|
||||||
const crypto = require("crypto");
|
|
||||||
const got = require("got");
|
const got = require("got");
|
||||||
const { isEqual } = require("lodash");
|
const { isEqual } = require("lodash");
|
||||||
const {
|
const {
|
||||||
|
@ -7,7 +6,8 @@ const {
|
||||||
getAuthCookie,
|
getAuthCookie,
|
||||||
isPortalModuleEnabled,
|
isPortalModuleEnabled,
|
||||||
uploadFunc,
|
uploadFunc,
|
||||||
sectorSize,
|
siaDockerContainerIP,
|
||||||
|
defaultSiaPort,
|
||||||
} = require("../utils");
|
} = require("../utils");
|
||||||
const { SkynetClient, stringToUint8ArrayUtf8, genKeyPairAndSeed } = require("skynet-js");
|
const { SkynetClient, stringToUint8ArrayUtf8, genKeyPairAndSeed } = require("skynet-js");
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ async function skydConfigCheck(done) {
|
||||||
const data = { up: false };
|
const data = { up: false };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await got(`http://10.10.10.10:9980/renter`, { headers: { "User-Agent": "Sia-Agent" } }).json();
|
const response = await got(`http://${siaDockerContainerIP}:${defaultSiaPort}/renter`, {
|
||||||
|
headers: { "User-Agent": "Sia-Agent" },
|
||||||
|
}).json();
|
||||||
|
|
||||||
// make sure initial funding is set to 10SC
|
// make sure initial funding is set to 10SC
|
||||||
if (response.settings.allowance.paymentcontractinitialfunding !== "10000000000000000000000000") {
|
if (response.settings.allowance.paymentcontractinitialfunding !== "10000000000000000000000000") {
|
||||||
|
@ -48,13 +50,6 @@ async function uploadCheck(done) {
|
||||||
return uploadFunc(done, payload, "upload_file");
|
return uploadFunc(done, payload, "upload_file");
|
||||||
}
|
}
|
||||||
|
|
||||||
// uploadLargeFileCheck returns the result of uploading a large file
|
|
||||||
async function uploadLargeFileCheck(done) {
|
|
||||||
const payload = Buffer.from(crypto.randomBytes(sectorSize));
|
|
||||||
|
|
||||||
return uploadFunc(done, payload, "upload_large_file", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// websiteCheck checks whether the main website is working
|
// websiteCheck checks whether the main website is working
|
||||||
async function websiteCheck(done) {
|
async function websiteCheck(done) {
|
||||||
return done(await genericAccessCheck("website", `https://${process.env.PORTAL_DOMAIN}`));
|
return done(await genericAccessCheck("website", `https://${process.env.PORTAL_DOMAIN}`));
|
||||||
|
@ -211,7 +206,6 @@ async function genericAccessCheck(name, url) {
|
||||||
const checks = [
|
const checks = [
|
||||||
skydConfigCheck,
|
skydConfigCheck,
|
||||||
uploadCheck,
|
uploadCheck,
|
||||||
uploadLargeFileCheck,
|
|
||||||
websiteCheck,
|
websiteCheck,
|
||||||
downloadCheck,
|
downloadCheck,
|
||||||
skylinkSubdomainCheck,
|
skylinkSubdomainCheck,
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
|
const crypto = require("crypto");
|
||||||
const got = require("got");
|
const got = require("got");
|
||||||
const hasha = require("hasha");
|
const hasha = require("hasha");
|
||||||
const { detailedDiff } = require("deep-object-diff");
|
const { detailedDiff } = require("deep-object-diff");
|
||||||
const { isEqual } = require("lodash");
|
const { isEqual } = require("lodash");
|
||||||
const { calculateElapsedTime, ensureValidJSON, getResponseContent, getAuthCookie, uploadFunc } = require("../utils");
|
const {
|
||||||
|
calculateElapsedTime,
|
||||||
|
ensureValidJSON,
|
||||||
|
getResponseContent,
|
||||||
|
getAuthCookie,
|
||||||
|
sectorSize,
|
||||||
|
uploadFunc,
|
||||||
|
} = require("../utils");
|
||||||
const { parseSkylink } = require("skynet-js");
|
const { parseSkylink } = require("skynet-js");
|
||||||
|
|
||||||
// audioExampleCheck returns the result of trying to download the skylink
|
// audioExampleCheck returns the result of trying to download the skylink
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const FormData = require("form-data");
|
const FormData = require("form-data");
|
||||||
|
const got = require("got");
|
||||||
const ipCheckService = "whatismyip.akamai.com";
|
const ipCheckService = "whatismyip.akamai.com";
|
||||||
const ipRegex = new RegExp(
|
const ipRegex = new RegExp(
|
||||||
`^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$`
|
`^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$`
|
||||||
|
@ -21,6 +22,9 @@ const defaultFanoutRedundancy = 3;
|
||||||
// siaDockerContainerIP is the local IP of the sia docker container
|
// siaDockerContainerIP is the local IP of the sia docker container
|
||||||
const siaDockerContainerIP = "10.10.10.10";
|
const siaDockerContainerIP = "10.10.10.10";
|
||||||
|
|
||||||
|
// defaultSiaPort is the default port the sia runs on.
|
||||||
|
const defaultSiaPort = "9980";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the time between start and now in milliseconds
|
* Get the time between start and now in milliseconds
|
||||||
*/
|
*/
|
||||||
|
@ -159,8 +163,8 @@ async function sleep(seconds) {
|
||||||
// skylinkHealthCheck checks if the skylink has reached full redundancy
|
// skylinkHealthCheck checks if the skylink has reached full redundancy
|
||||||
async function skylinkHealthCheck(skylink, numRetries = 30, authCookie, isLarge = false) {
|
async function skylinkHealthCheck(skylink, numRetries = 30, authCookie, isLarge = false) {
|
||||||
// Get the health of the skylink
|
// Get the health of the skylink
|
||||||
const response = await got(`http://${siaDockerContainerIP}/skynet/health/skylink/${skylink}`, {
|
const response = await got(`http://${siaDockerContainerIP}:${defaultSiaPort}/skynet/health/skylink/${skylink}`, {
|
||||||
headers: { "user-agent": "Sia-Agent", cookie: authCookie },
|
headers: { "User-Agent": "Sia-Agent", cookie: authCookie },
|
||||||
});
|
});
|
||||||
const healthData = getResponseContent(response);
|
const healthData = getResponseContent(response);
|
||||||
|
|
||||||
|
@ -168,7 +172,9 @@ async function skylinkHealthCheck(skylink, numRetries = 30, authCookie, isLarge
|
||||||
if (healthData.basesectorredundancy !== defaultBaseSectorRedundancy && numRetries > 0) {
|
if (healthData.basesectorredundancy !== defaultBaseSectorRedundancy && numRetries > 0) {
|
||||||
// Semi-smart sleep before retrying. Sleep longer if the redundancy is
|
// Semi-smart sleep before retrying. Sleep longer if the redundancy is
|
||||||
// lower.
|
// lower.
|
||||||
await sleep(10 - healthData.basesectorredundancy);
|
let sleepTime = defaultBaseSectorRedundancy - healthData.basesectorredundancy;
|
||||||
|
console.log(`sleeping ${sleepTime}s for basesectorredundancy ${healthData.basesectorredundancy}`);
|
||||||
|
await sleep(sleepTime);
|
||||||
return skylinkHealthCheck(skylink, numRetries - 1, authCookie, isLarge);
|
return skylinkHealthCheck(skylink, numRetries - 1, authCookie, isLarge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +182,9 @@ async function skylinkHealthCheck(skylink, numRetries = 30, authCookie, isLarge
|
||||||
if (isLarge && healthData.fanoutredundancy != defaultFanoutRedundancy && numRetries > 0) {
|
if (isLarge && healthData.fanoutredundancy != defaultFanoutRedundancy && numRetries > 0) {
|
||||||
// Semi-smart sleep before retrying. Sleep longer if the redundancy is
|
// Semi-smart sleep before retrying. Sleep longer if the redundancy is
|
||||||
// lower.
|
// lower.
|
||||||
await sleep((defaultFanoutRedundancy - healthData.fanoutredundancy) * 10);
|
let sleepTime = (defaultFanoutRedundancy - healthData.fanoutredundancy) * 10;
|
||||||
|
console.log(`sleeping ${sleepTime}s for fanout redundancy ${healthData.fanoutredundancy}`);
|
||||||
|
await sleep(sleepTime);
|
||||||
return skylinkHealthCheck(skylink, numRetries - 1, authCookie, isLarge);
|
return skylinkHealthCheck(skylink, numRetries - 1, authCookie, isLarge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +213,7 @@ async function uploadFunc(done, payload, name, isLarge = false) {
|
||||||
|
|
||||||
form.append("file", payload, { filename: `${name}.txt`, contentType: "text/plain" });
|
form.append("file", payload, { filename: `${name}.txt`, contentType: "text/plain" });
|
||||||
|
|
||||||
|
let skylink;
|
||||||
try {
|
try {
|
||||||
// Upload file
|
// Upload file
|
||||||
const response = await got.post(`https://${process.env.PORTAL_DOMAIN}/skynet/skyfile`, {
|
const response = await got.post(`https://${process.env.PORTAL_DOMAIN}/skynet/skyfile`, {
|
||||||
|
@ -214,7 +223,7 @@ async function uploadFunc(done, payload, name, isLarge = false) {
|
||||||
|
|
||||||
// Check file health
|
// Check file health
|
||||||
const responseContent = getResponseContent(response);
|
const responseContent = getResponseContent(response);
|
||||||
const skylink = responseContent.skylink;
|
skylink = responseContent.skylink;
|
||||||
await skylinkHealthCheck(skylink, 60, authCookie, isLarge);
|
await skylinkHealthCheck(skylink, 60, authCookie, isLarge);
|
||||||
|
|
||||||
// Update data response
|
// Update data response
|
||||||
|
@ -243,5 +252,7 @@ module.exports = {
|
||||||
ipCheckService,
|
ipCheckService,
|
||||||
ipRegex,
|
ipRegex,
|
||||||
sectorSize,
|
sectorSize,
|
||||||
|
siaDockerContainerIP,
|
||||||
|
defaultSiaPort,
|
||||||
uploadFunc,
|
uploadFunc,
|
||||||
};
|
};
|
||||||
|
|
Reference in New Issue