diff --git a/bin/bot.js b/bin/bot.js index 0fac179..b20966e 100644 --- a/bin/bot.js +++ b/bin/bot.js @@ -18,6 +18,7 @@ const { CDN_HOSTNAME = 'calibration.filbeam.io', DELAY = 1_000, FROM_DATA_SET_ID = 0, + AUTH_TOKEN, } = process.env const fetchRequest = new ethers.FetchRequest(RPC_URL) @@ -57,6 +58,7 @@ await Promise.all([ botLocation: FLY_REGION, CDN_HOSTNAME, FROM_DATA_SET_ID: BigInt(FROM_DATA_SET_ID), + AUTH_TOKEN, }) console.log('\n') await setTimeout(Number(DELAY)) @@ -71,6 +73,7 @@ await Promise.all([ botLocation: FLY_REGION, CDN_HOSTNAME, FROM_DATA_SET_ID: BigInt(FROM_DATA_SET_ID), + AUTH_TOKEN, }) console.log('\n') await setTimeout(Number(30_000)) // block time diff --git a/index.js b/index.js index a9456a7..1a07839 100644 --- a/index.js +++ b/index.js @@ -135,6 +135,7 @@ export const serviceProviderRegistryAbi = [ * @param {BigInt} args.pieceId * @param {boolean} [args.retryOn404=true] Default is `true` * @param {number} [args.retryDelayMs=10_000] Default is `10_000` + * @param {string} [args.AUTH_TOKEN] * @returns {Promise} */ async function testRetrieval({ @@ -149,13 +150,19 @@ async function testRetrieval({ pieceId, retryOn404 = true, retryDelayMs = 10_000, + AUTH_TOKEN, }) { const url = `https://${clientAddress}.${CDN_HOSTNAME}/${pieceCid}` console.log('Fetching', url) let res try { - res = await fetch(url) + const headers = new Headers() + if (AUTH_TOKEN) { + headers.set('authorization', `Bearer ${AUTH_TOKEN}`) + } + + res = await fetch(url, { headers }) } catch (err) { console.error( 'ALERT Cannot retrieve data set %s piece %sfrom %s via %s: %s', @@ -188,6 +195,7 @@ async function testRetrieval({ pieceCid, dataSetId, pieceId, + AUTH_TOKEN, retryOn404: false, }) } @@ -305,6 +313,7 @@ async function maybeGetResolvedDataSetRetrievalUrl({ * @param {string} [args.botLocation] Fly region where the bot is running * @param {string} args.CDN_HOSTNAME * @param {BigInt} args.FROM_DATA_SET_ID + * @param {string} [args.AUTH_TOKEN] */ export async function sampleRetrieval({ @@ -314,6 +323,7 @@ export async function sampleRetrieval({ botLocation = '', CDN_HOSTNAME, FROM_DATA_SET_ID, + AUTH_TOKEN, }) { const { pieceCid, dataSetId, pieceId, clientAddress } = await pickRandomFileWithCDN({ @@ -333,6 +343,7 @@ export async function sampleRetrieval({ pieceCid, dataSetId, pieceId, + AUTH_TOKEN, }) } @@ -474,6 +485,7 @@ async function pickRandomFileWithCDN({ * @param {string} [args.botLocation] Fly region where the bot is running * @param {string} args.CDN_HOSTNAME * @param {BigInt} args.FROM_DATA_SET_ID + * @param {string} [args.AUTH_TOKEN] */ export async function testLatestRetrievablePiece({ diff --git a/package-lock.json b/package-lock.json index 0a28a6d..19e175d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@filcdn/bot", + "name": "@filbeam/bot", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@filcdn/bot", + "name": "@filbeam/bot", "version": "0.0.0", "license": "MIT", "dependencies": {