Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bounty] Add CDN for the file service #2160

Closed
5 of 15 tasks
yisiliu opened this issue Dec 31, 2020 · 27 comments
Closed
5 of 15 tasks

[Bounty] Add CDN for the file service #2160

yisiliu opened this issue Dec 31, 2020 · 27 comments

Comments

@yisiliu
Copy link
Member

yisiliu commented Dec 31, 2020

Catalogue

  • Platform
    • Gitcoin
    • Hackerlink
    • Mask
  • Experience
    • Beginner
    • Intermediate
    • Advanced
  • Category
    • Mask Core Feature
    • Mask Plugin
    • Security/Cryptography Feature
    • Documentation
    • Design
    • Other
      • /List it here/
  • Time Commitment
    • 2 weeks
  • Bounty Size
    • 500 DAI

Part 1: Problem Description

Right now we are using Arweave as the "backend" of the file service, where users are able to upload files onto or download from. However, the endpoint is not stable as it might be influenced by a few factors. We would like to add a CDN to help improve this experience for our users all over the world.

In the future, we are planning to add more "backends"(#2069) and would appreciate the CDN as well.

Part 2: Resources

https://github.com/DimensionDev/Maskbook/tree/master/packages/maskbook/src/plugins/FileService

Part 3: Contact and Support

@yisiliu and @septs

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 500.0 DAI (500.0 USD @ $1.0/DAI) attached to it.

@sherlock-shi-x
Copy link
Contributor

🙋‍♂️🙋‍♂️🙋‍♂️

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 265 years, 10 months from now.
Please review their action plans below:

1) haihongs has been approved to start work.

  • Test arweave api endpoint
  • Communicate with Mask
  • Add CDN service for Mask
  • Test in different area
  • Whooooa

Learn more on the Gitcoin Issue Details page.

@yisiliu
Copy link
Member Author

yisiliu commented Dec 31, 2020

@haihongS please sync any update with us here, thanks

@sherlock-shi-x
Copy link
Contributor

sherlock-shi-x commented Dec 31, 2020

Ok, let's start it.

The usual flow:

https://arweave.net/j8BNG1iTI0kebUQM9UlR9abW56fRmBZLnV3gsUOfo44

redirects to ->

https://r7ae2g2ysmrushtniqgpkskr6wtnnz5h2gmbms45lxqlcq47uoha.arweave.net/j8BNG1iTI0kebUQM9UlR9abW56fRmBZLnV3gsUOfo44

CDN cache

We can offer an acceleration link:
https://coldcdn.com/api/cdn/bronil/j8BNG1iTI0kebUQM9UlR9abW56fRmBZLnV3gsUOfo44

When we check the content in HTML, found the real file link in Arweave which needs to be changed in Mask.

@yisiliu
Copy link
Member Author

yisiliu commented Dec 31, 2020

We'd like some speed tests from different areas. What's your thoughts? @septs

@sherlock-shi-x
Copy link
Contributor

Can we get much more information about the user location in using Mask & Arweave

@yisiliu
Copy link
Member Author

yisiliu commented Dec 31, 2020

We do have some stats in Mask but you should probably test it all over the world to test out the robustness of your service

@sherlock-shi-x
Copy link
Contributor

We do have some stats in Mask but you should probably test it all over the world to test out the robustness of your service

Yeah, so can we start with an alternative link which gives users an option to reach files through cache service, just like live streaming has multiple lines.

e.g. users based in China Mainland and North America can try the alternative link, and we will check the status of service and do some tunings.

After several periods, we will know the performance and robustness of service, then comes the real CDN.

@yisiliu

@yisiliu
Copy link
Member Author

yisiliu commented Dec 31, 2020

Yeah, so can we start with an alternative link which gives users an option to reach files through cache service, just like live streaming has multiple lines.

I guess the ideal solution would require you to modify our code so that it'll test out all the options and choose the best available.

@sherlock-shi-x
Copy link
Contributor

sure, let me check the code

@gitcoinbot
Copy link

@haihongS Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@sherlock-shi-x
Copy link
Contributor

yeah, wip right now

@sherlock-shi-x
Copy link
Contributor

export const signing = 'https://service.maskbook.com/arweave-remote-signing'

Does Mask maintain the signing system in private and keep SK?

@yisiliu
Copy link
Member Author

yisiliu commented Jan 5, 2021

@septs

@septs
Copy link
Contributor

septs commented Jan 5, 2021

export const signing = 'https://service.maskbook.com/arweave-remote-signing'

Does Mask maintain the signing system in private and keep SK?

as arweave does not provide remote signing method,
but this repo include some non public limit settings, not can fully open source.
(if you idea access this codebase, need to get @yisiliu approve)

it's core logic like:

  const [data, parsed] = await readRequest(ctx.req.read());
  const signed = await instance.crypto.sign(keyfile, data);
  const id = await instance.crypto.hash(signed);
  ctx.body = {
    signature: bufferTob64Url(signed),
    id: bufferTob64Url(id),
  };

wrote here response body to transaction.setSignature, signed by remote

export async function sign(transaction: Transaction) {
const response = await fetch(signing, {
method: 'POST',
// Temporary workaround for https://github.com/msgpack/msgpack-javascript/issues/145
body: Uint8Array.from(await makeRequest(transaction)),
})
transaction.setSignature(await response.json())
}

@septs
Copy link
Contributor

septs commented Jan 5, 2021

@haihongS plz send a email to septs@dimension.im request the codebase, thanks on @yisiliu approved

@sherlock-shi-x
Copy link
Contributor

@haihongS plz send a email to septs@dimension.im request the codebase, thanks on @yisiliu approved

Thx, and I can continue the idea without this part right now.


I read some codes and tried file service in twitter, here is my understanding of process:

User A clicks the FileService plugin in twitter and drops a file into it

-> mask builds an arweave transaction
-> signed by mask's signing system
-> broadcast to arweave network through endpoint:arweave.net
-> waiting for the confirmation of arweave network

-> display arweave link: https://arweave.net/MASK_FILE_HASH#KEY
-> arweave redirect: https://balabala.arweave.net/MASK_FILE_HASH#KEY
-> request real file download link: https://arweave.net/REAL_FILE_HASH

plz point out the mistakes above if it has @septs

@sherlock-shi-x
Copy link
Contributor

Besides, I noticed the lack of the whole encryption, which means, I can scan the history of transactions in mask's account and find the real file hash without the key.

Two sequent transactions, one for key check and the other represents the real file.

@septs
Copy link
Contributor

septs commented Jan 5, 2021

Besides, I noticed the lack of the whole encryption, which means, I can scan the history of transactions in mask's account and find the real file hash without the key.

key using hmac-sha256 verify user key correctness.

see https://github.com/DimensionDev/Maskbook-FileService-LandingPage/blob/1d87424b21ad3815e4987cd9c2e7bee2ec176112/src/components/Password.tsx#L77-L83

Two sequent transactions, one for key check and the other represents the real file.

  1. first transaction
    1. generate (un)encrypted file with metadata 1
    2. upload to arwavae
  2. two transaction
    1. inject metadata (include real file link, filename, etc) 2 into Landing page 3
    2. upload to arwavae

notes:

  1. https://github.com/DimensionDev/common-protocols/blob/master/specs/0-BSFOW.md
  2. export async function uploadLandingPage(metadata: LandingPageMetadata) {
    const encodedMetadata = JSON.stringify({
    name: metadata.name,
    size: metadata.size,
    link: `https://arweave.net/${metadata.txId}`,
    signed: await makeFileKeySigned(metadata.key),
    createdAt: new Date().toISOString(),
    })
    const response = await fetch(landing)
    const text = await response.text()
    const replaced = text.replace('__METADATA__', encodedMetadata)
    const data = encodeText(replaced)
    const transaction = await makePayload(data, 'text/html')
    await instance.transactions.post(transaction)
    return transaction.id
    }
  3. https://github.com/DimensionDev/Maskbook-FileService-LandingPage
    https://en.wikipedia.org/wiki/Landing_page

@sherlock-shi-x
Copy link
Contributor

sherlock-shi-x commented Jan 7, 2021

awesome codes, and now we need to talk about the solution for this issue.

purpose

  • offer a cdn for file service at this moment
  • accelerate other components for mask later

concern

the robustness of service

solution

keep the original arweave link, but give users an alternative link

I have noticed the two key point links in file service, one is landingTxID and the other is payloadTxID

so, I need to add alter link in Maskbook-FileService-LandingPage. Cuz every encoding in file service will fetch data from landing page, hot-update will be much easy.

Then, we can offer the entry atler landing-page link in twitter, which will help users who can't reach arweave endpoint.

@septs what's your idea?

@sherlock-shi-x
Copy link
Contributor

sherlock-shi-x commented Jan 13, 2021

@sherlock-shi-x
Copy link
Contributor

In chrome incognito mode, I tested two files.

one is from original arweave endpoint(8.7M):
https://arweave.net/9JgBCn8uaToqiTbugQ43yRuQioLbvbeTA5mSLEbnYt8#sample

another is the cached one(9.4M):
https://arweave.net/VzLiXPYJLyAmWoQbH05W5P5SOaqWesQCFg7a935iKYE#MrRBRMeAnB8EQBE4

The results is much ideal.

image

image


The strategy keeps the same as traditional cloud service provider. When the first request arrived, the system will redirect to origin source and schedule a job, which can cache file to the user's neighbourhood. As soon as the caching ready, new request will be distributed to cached nodes according to load-balance strategy.

@sherlock-shi-x
Copy link
Contributor

sherlock-shi-x commented Jan 13, 2021

Hope it will be convenient to users and save the cost of mask. ^...^

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 500.0 DAI (500.0 USD @ $1.0/DAI) has been submitted by:


@Tedko
Copy link
Member

Tedko commented Dec 10, 2021

consider done @yisiliu

@Tedko Tedko closed this as completed Dec 10, 2021
@Tedko
Copy link
Member

Tedko commented Dec 10, 2021

should close gitcoin bounty if this is consider done @yisiliu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants