Algorithms » History » Version 19
Greg Burri, 08/07/2009 01:38 PM
1 | 1 | Greg Burri | h1. Algorithms |
---|---|---|---|
2 | |||
3 | h2. Searching |
||
4 | 2 | Greg Burri | |
5 | 3 | Greg Burri | For a functional description see here : [[Functional definition#The-search-window]] |
6 | 15 | Greg Burri | |
7 | 1 | Greg Burri | !aybabtu_search.png! |
8 | 18 | Greg Burri | _This schema depicts how the results are sorted from one peer. Each peer result are then merged._ |
9 | 4 | Greg Burri | |
10 | 5 | Greg Burri | h2. Peer ID |
11 | |||
12 | 7 | Greg Burri | Each peer owns a peer id which is unique and generated during the first start. This ID is used to identify a peer, it's better than the previous usage of peer IP, considering this situation : |
13 | 5 | Greg Burri | |
14 | * _A_ put in queue a file entry _f_ from _B_, _B_ doesn't know the hashes of this file entry. |
||
15 | * _B_ change his IP address. |
||
16 | * _A_ want to download _f_, it can ask _B_ for the hashes even _B_'s IP changed. |
||
17 | |||
18 | 8 | Greg Burri | h2. Core threads |
19 | |||
20 | 9 | Greg Burri | There are three kind of threads in the core in addition to the main thread : |
21 | * [[Protocol_core-core#Downloading-thread|Downloading thread]] : @DownloadManager::ChunkDownloader@ |
||
22 | 8 | Greg Burri | * Uploading thread : @UploadManager::Uploader@ |
23 | 11 | Greg Burri | * [[Algorithms#Updating-the-file-cache|Updating file cache thread]] : @FileManager::FileUpdater@ |
24 | 5 | Greg Burri | |
25 | 19 | Greg Burri | h2. Updating the file cache (Obsolete, must be rewritten after the seventh prototype ended) |
26 | 10 | Greg Burri | |
27 | Here is the algorithm for the thread (@FileManager::FileUpdater@) which will periodically update the file cache and persist it. |
||
28 | |||
29 | <pre> |
||
30 | D : The set of shared directories |
||
31 | T : Time during the hashes are computed (for example 30s) |
||
32 | F : A set of file initialy empty |
||
33 | |||
34 | 13 | Greg Burri | - Add a watcher to the shared directories |
35 | |||
36 | // First synchronize (at start) |
||
37 | For each d in D (recursively) : |
||
38 | 14 | Greg Burri | - Synchronize physical folders and files with d content |
39 | 13 | Greg Burri | - Add in F the files which doesn't have computed hashes |
40 | |||
41 | Loop : |
||
42 | 10 | Greg Burri | t : Time.now |
43 | 1 | Greg Burri | For each f in F : |
44 | 13 | Greg Burri | - Compute the unknown hash of files f |
45 | 1 | Greg Burri | - Remove f from F |
46 | 10 | Greg Burri | If (Time.now - t) > T : break |
47 | - Wait T - (Time.now - t) |
||
48 | 13 | Greg Burri | - Wait for changes for a period of P |
49 | - When a modification occurs synchronise the file/folder |
||
50 | - Add each new file in F |
||
51 | 12 | Greg Burri | - Persist the entire cache in a file (only every ~30min) |
52 | 10 | Greg Burri | </pre> |
53 | |||
54 | 5 | Greg Burri | |
55 | 4 | Greg Burri | h2. Downloading |
56 | |||
57 | See here : [[Protocol_core-core#Downloading-threads]] |