// The purpose of this function is to return a list of blocks (~180KB) to // download. To avoid a prematurely stop of the downloading, all blocks that // are requested from the same source must be located within the same // chunk (=> part ~9MB). // // The selection of the chunk to download is one of the CRITICAL parts of the // edonkey network. The selection algorithm must insure the best spreading // of files. // // The selection is based on 4 criteria: // 1. Frequency of the chunk (availability), very rare chunks must be downloaded // as quickly as possible to become a new available source. // 2. Parts used for preview (first + last chunk), preview or check a // file (e.g. movie, mp3) // 3. Request state (downloading in process), try to ask each source for another // chunk. Spread the requests between all sources. // 4. Completion (shortest-to-complete), partially retrieved chunks should be // completed before starting to download other one. // // The frequency criterion defines three zones: very rare (<10%), rare (<50%) // and common (>30%). Inside each zone, the criteria have a specific weight, used // to calculate the priority of chunks. The chunk(s) with the highest // priority (highest=0, lowest=0xffff) is/are selected first. // // very rare (preview) rare common // 0% <---- +0 pt ----> 10% <----- +10000 pt -----> 50% <---- +20000 pt ----> 100% // 1. <------- frequency: +25*frequency pt -----------> // 2. <- preview: +1 pt --><-------------- preview: set to 10000 pt -------------> // 3. <------ request: download in progress +20000 pt ------> // 4a. <- completion: 0% +100, 25% +75 .. 100% +0 pt --><-- !req => completion ---> // 4b. <--- req => !completion --> // // Unrolled, the priority scale is: // // 0..xxxx unrequested and requested very rare chunks // 10000..1xxxx unrequested rare chunks + unrequested preview chunks // 20000..2xxxx unrequested common chunks (priority to the most complete) // 30000..3xxxx requested rare chunks + requested preview chunks // 40000..4xxxx requested common chunks (priority to the least complete) // // This algorithm usually selects first the rarest chunk(s). However, partially // complete chunk(s) that is/are close to completion may overtake the priority // (priority inversion). // For the common chuncks, the algorithm tries to spread the dowload between // the sources //