diff --git a/package-lock.json b/package-lock.json index 9f894cce..d5cbbf35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cadt", - "version": "1.7.9", + "version": "1.7.9b1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cadt", - "version": "1.7.9", + "version": "1.7.9b1", "dependencies": { "@babel/eslint-parser": "^7.23.10", "async-mutex": "^0.4.1", diff --git a/package.json b/package.json index 3c30d897..bcdde061 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cadt", - "version": "1.7.9", + "version": "1.7.9b1", "_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2", "private": true, "bin": "build/server.js", diff --git a/src/controllers/organization.controller.js b/src/controllers/organization.controller.js index e90c247f..14bc433c 100644 --- a/src/controllers/organization.controller.js +++ b/src/controllers/organization.controller.js @@ -403,6 +403,8 @@ export const addMetadata = async (req, res) => { export const addMirror = async (req, res) => { try { + console.info(`ZGB: We are in the organization.controller.js file now`); + await assertIfReadOnlyMode(); await assertWalletIsSynced(); await assertHomeOrgExists(); diff --git a/src/datalayer/persistance.js b/src/datalayer/persistance.js index badc4d21..52da2fb4 100644 --- a/src/datalayer/persistance.js +++ b/src/datalayer/persistance.js @@ -113,8 +113,15 @@ const clearPendingRoots = async (storeId) => { }; const addMirror = async (storeId, url, forceAddMirror = false) => { + logger.info( + `ZGB: in persistance.js, forceAddMirror is ${forceAddMirror}, url is ${url}, storeId is ${storeId}`, + ); + await wallet.waitForAllTransactionsToConfirm(); const homeOrg = await Organization.getHomeOrg(); + logger.info( + `ZGB: homeorg is ${homeOrg}, forceAddMirror is ${forceAddMirror}, url is ${url}, storeId is ${storeId}`, + ); logger.info( `Checking mirrors for storeID is ${storeId} with mirror URL ${url}`, diff --git a/src/models/organizations/organizations.model.js b/src/models/organizations/organizations.model.js index ead372cb..90c5b4ff 100644 --- a/src/models/organizations/organizations.model.js +++ b/src/models/organizations/organizations.model.js @@ -222,8 +222,11 @@ class Organization extends Model { return registryVersionId; } - static async addMirror(storeId, url) { - await datalayer.addMirror(storeId, url); + static async addMirror(storeId, url, force = false) { + logger.info( + `ZGB: in organizations.model.js, storeId is ${storeId}, force is ${force}, url is ${url}`, + ); + await datalayer.addMirror(storeId, url, force); } static async importHomeOrg(orgUid) { diff --git a/src/tasks/mirror-check.js b/src/tasks/mirror-check.js index f115f35d..ad5be9ca 100644 --- a/src/tasks/mirror-check.js +++ b/src/tasks/mirror-check.js @@ -19,10 +19,12 @@ const task = new Task('mirror-check', async () => { await assertDataLayerAvailable(); await assertWalletIsSynced(); + logger.info(`ZGB: In the loop to do the mirror-check - no logic run yet`); // Default AUTO_MIRROR_EXTERNAL_STORES to true if it is null or undefined const shouldMirror = CONFIG?.AUTO_MIRROR_EXTERNAL_STORES ?? true; if (!CONFIG.USE_SIMULATOR && shouldMirror) { + logger.info(`ZGB: Conditions met for mirror-check - trying now`); runMirrorCheck(); } } catch (error) { @@ -43,24 +45,21 @@ const job = new SimpleIntervalJob( ); const runMirrorCheck = async () => { - const homeOrg = await Organization.getHomeOrg(); - - if (homeOrg) { - const organizations = await Organization.getOrgsMap(); - const orgs = Object.keys(organizations); - for (const org of orgs) { - const orgData = organizations[org]; - const mirrorUrl = await getMirrorUrl(); - - if (mirrorUrl) { - // There is logic within the addMirror function to check if the mirror already exists - await Organization.addMirror(orgData.orgUid, mirrorUrl); - await Organization.addMirror(orgData.registryId, mirrorUrl); - } else { - logger.error( - 'DATALAYER_FILE_SERVER_URL not set, skipping mirror announcement', - ); - } + const organizations = await Organization.getOrgsMap(); + const orgs = Object.keys(organizations); + logger.info(`ZGB: orgs available: ${orgs}`); + for (const org of orgs) { + const orgData = organizations[org]; + const mirrorUrl = await getMirrorUrl(); + logger.info(`ZGB: Working on mirror for ${org} with URL ${mirrorUrl}`); + if (mirrorUrl) { + // There is logic within the addMirror function to check if the mirror already exists + await Organization.addMirror(orgData.orgUid, mirrorUrl, true); + await Organization.addMirror(orgData.registryId, mirrorUrl, true); + } else { + logger.error( + 'DATALAYER_FILE_SERVER_URL not set, skipping mirror announcement', + ); } } }; diff --git a/src/utils/datalayer-utils.js b/src/utils/datalayer-utils.js index c9f39af3..f83553af 100644 --- a/src/utils/datalayer-utils.js +++ b/src/utils/datalayer-utils.js @@ -114,7 +114,7 @@ export const optimizeAndSortKvDiff = (kvDiff) => { export const getMirrorUrl = async () => { try { const { DATALAYER_FILE_SERVER_URL } = getConfig().APP; - logger.debug(`Resolved Mirror Url: ${DATALAYER_FILE_SERVER_URL}`); + logger.info(`Resolved Mirror Url: ${DATALAYER_FILE_SERVER_URL}`); return DATALAYER_FILE_SERVER_URL; } catch (error) { logger.error('Error getting DATALAYER_FILE_SERVER_URL: ${error}'); diff --git a/src/utils/ip-tools.js b/src/utils/ip-tools.js deleted file mode 100644 index 036cf4b8..00000000 --- a/src/utils/ip-tools.js +++ /dev/null @@ -1,101 +0,0 @@ -import _ from 'lodash'; -import superagent from 'superagent'; - -const defaults = { - timeout: 5000, - onlyHttps: false, -}; - -const dnsServers = [ - { - v4: { - servers: [ - '208.67.222.222', - '208.67.220.220', - '208.67.222.220', - '208.67.220.222', - ], - name: 'myip.opendns.com', - type: 'A', - }, - v6: { - servers: ['2620:0:ccc::2', '2620:0:ccd::2'], - name: 'myip.opendns.com', - type: 'AAAA', - }, - }, - { - v4: { - servers: [ - '216.239.32.10', - '216.239.34.10', - '216.239.36.10', - '216.239.38.10', - ], - name: 'o-o.myaddr.l.google.com', - type: 'TXT', - transform: (ip) => ip.replace(/"/g, ''), - }, - v6: { - servers: [ - '2001:4860:4802:32::a', - '2001:4860:4802:34::a', - '2001:4860:4802:36::a', - '2001:4860:4802:38::a', - ], - name: 'o-o.myaddr.l.google.com', - type: 'TXT', - transform: (ip) => ip.replace(/"/g, ''), - }, - }, -]; - -const type = { - v4: { - dnsServers: dnsServers.map(({ v4: { servers, ...question } }) => ({ - servers, - question, - })), - httpsUrls: ['https://icanhazip.com/', 'https://api.ipify.org/'], - }, - v6: { - dnsServers: dnsServers.map(({ v6: { servers, ...question } }) => ({ - servers, - question, - })), - httpsUrls: ['https://icanhazip.com/', 'https://api6.ipify.org/'], - }, -}; - -const queryHttps = (version, options) => { - let cancel; - - const promise = (async () => { - const urls = [...type[version].httpsUrls, ...(options.fallbackUrls ?? [])]; - - for (const url of urls) { - const response = await superagent.get(url); - const ip = (response.text || '').trim(); - if (!_.isEmpty(ip)) { - return ip; - } - } - - throw new Error('IP Not found'); - })(); - - promise.cancel = function () { - return cancel.apply(this); - }; - - return promise; -}; - -export function publicIpv4(options) { - options = { - ...defaults, - ...options, - }; - - return queryHttps('v4', options); -}