-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
It makes less sense to code the complex logic here as the storage server doesn't care much about which is the latest one; simply pulling down all registry tarballs and whatever packages they contain would be good enough.
StorageMirrorServer.jl/src/utils/server_utils.jl
Lines 54 to 89 in 3bfd65e
| function query_latest_hash(registry::RegistryMeta, upstreams::AbstractVector{<:AbstractString}) | |
| # collect current registry hashes from servers | |
| uuid = registry.uuid | |
| hash_info = Dict{String, Vector{String}}() # Dict(hashA => [serverA, serverB], ...) | |
| servers = String[] # [serverA, serverB] | |
| for server in upstreams | |
| hash = query_latest_hash(registry, server) | |
| isnothing(hash) && continue | |
| push!(get!(hash_info, hash, String[]), server) | |
| push!(servers, server) | |
| end | |
| # for each hash check what other servers know about it | |
| if isempty(hash_info) | |
| # if none of the upstreams contains the registry we want to mirror | |
| @warn "failed to find available registry" registry=registry.name upstreams=upstreams | |
| return nothing | |
| end | |
| # a hash might be known to many upstreams | |
| for (hash, hash_servers) in hash_info | |
| for server in servers | |
| server in hash_servers && continue | |
| url_exists("$server/registry/$uuid/$hash") || continue | |
| push!(hash_servers, server) | |
| end | |
| end | |
| # Ideally, there is an upstream server that knows all hashes, and we set hash in that server | |
| # as the latest hash. | |
| # In practice, we set the first non-malicious hash known to fewest servers as the latest hash. | |
| hashes = sort!(collect(keys(hash_info))) | |
| sort!(hashes, by = hash -> length(hash_info[hash])) | |
| hashes[findfirst(x->verify_registry_hash(registry.source_url, x), hashes)] | |
| end |
Metadata
Metadata
Assignees
Labels
No labels