Skip to content

Instantly share code, notes, and snippets.

@snyh
Created January 20, 2016 16:11
Show Gist options
  • Save snyh/3321c93c3ea310fc643f to your computer and use it in GitHub Desktop.
Save snyh/3321c93c3ea310fc643f to your computer and use it in GitHub Desktop.
1 Why we don't use server side choosing mirror?
═══════════════════════════════════════════════
The IP address family can't reflect the connection status between
mirror server and the user, especially in China.
We belive Only the user side can make the best choose.
2 How deepin solve the problem?
═══════════════════════════════
2.1 Make Sure that anytime the selected mirror is 100% freshness, even the mirror server is broken.
─────────────────────────────────────────────────
How deepin make the magic? The idea if very simple and workable.
Let apt detect every download file from mirror server and official
server at the same time. Using the mirror server one if available,
otherwise using the official server one.
It even can work well when the mirror is partially fresh, e.g. syncing
from official server.
2.2 Why this can workable?
─────────────
• The cost of detection is very little if it make in user side. We can
just using HTTP HEAD method do this for deb file and with by-hash
feature for Packages files.
• The Release file is always from official server and it's very
little. This can make sure the Packages files is 100% fresh and then
make sure all deb is 100% fresh.
2.3 How this be implement?
─────────────
• Patching the [apt] for hooking choosing URI in
pkgAcquire::Worker::QueueItem
• The final URI will be find by third-part program (currently is
lastore-smartmirrors)
• The third-part program just simply send a HEAD request both to
mirror and official server.
[apt]
https://github.com/linuxdeepin/lastore-daemon/blob/master/smartmirror.patch
@Artoria2e5
Copy link

OH.. so by-hash encodes the hash in the filename. I see.

@Artoria2e5
Copy link

Line 1, Why not choose mirrors on the server side?
Line 7, .. make the best choice
Line 10, How does
Line 11,
Line 11, Make sure the selected download source is always 100% up-to-date with the main (upstream Deepin) repo
Line 16, How does again, if -> is
Line 18, detect -> check/probe if the file is available .. If so, use the mirror
Line 26, How can this work?
Line 29, if we do it, detection -> probing
Line 30.., We can just use the HTTP HEAD method to probe for the corresponding file's existence on the mirror. With the by-hash feature in apt which encodes the deb hash in the filename enabled, we can be sure about which file we are pointing to. [note1]
Line 33, little -> small (in size)
Line 37, implemented
Line 44, the third-party external program <https://github.com/linuxdeepin/lastore-daemon/tree/master/src/lastore-smartmirror >

Notes
-----

1. We only use `HEAD` on our main server since some mirrors may not support this RFC 2616 method. Duh.
2. The probe actually works like this:
  1. make sure this uri comes from deepin's repo, is something in dist or pool, and starts with http --
    nothing will be tried for other sources.
  2. try the requests by spawning two go-funcs, and use the mirror if it comes as the first successful one.
    Successful is defined as `(statusCode // 100 in [1, 2] || statusCode // 100 == 3 && "Location" in headerDict)`.

Generated by a brain too bored on a Physics class (not enough laptop battery power to run KSP).
accidentally deleted.

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