44 |
all (remaining) contributors become suspicious "number of contributors/2" |
all (remaining) contributors become suspicious "number of contributors/2" |
45 |
|
|
46 |
From that, we see than it's acceptable to sometimes mix reliable contributors |
From that, we see than it's acceptable to sometimes mix reliable contributors |
47 |
with others and still detect suspects (but the chunk may be unvalidated, |
with others and still detect suspects (but the chunk may be unvalidated, |
48 |
resulting in a poor use of reliable contributors). |
resulting in a poor use of reliable contributors). |
49 |
|
|
50 |
Neutrals can be mixed with suspicious, but should be accounted for when |
Neutrals can be mixed with suspicious, but should be accounted for when |
87 |
with several past contributors kinds, take the max of levels. |
with several past contributors kinds, take the max of levels. |
88 |
|
|
89 |
Legacy blocks (containing legacy data at the beginning of the session) |
Legacy blocks (containing legacy data at the beginning of the session) |
90 |
should be handled as if it was downloaded by another virtual neutral |
should be handled as if it was downloaded by another virtual neutral |
91 |
contributor. |
contributor. |
92 |
|
|
93 |
From several choices, prefer the one of lowest level. |
From several choices, prefer the one of lowest level. |
152 |
| Reliability_reliable -> "reliable" |
| Reliability_reliable -> "reliable" |
153 |
| Reliability_suspicious 0 -> "has sent corrupted data" |
| Reliability_suspicious 0 -> "has sent corrupted data" |
154 |
| Reliability_suspicious s -> Printf.sprintf "suspicious of level %d" s) |
| Reliability_suspicious s -> Printf.sprintf "suspicious of level %d" s) |
155 |
|
|
156 |
let bprint_reliability buf ip = |
let bprint_reliability buf ip = |
157 |
Printf.bprintf buf "%s is %s\n" (Ip.to_string ip) |
Printf.bprintf buf "%s is %s\n" (Ip.to_string ip) |
158 |
(match ip_reliability ip with |
(match ip_reliability ip with |
171 |
|
|
172 |
(* |
(* |
173 |
let valid_block_detected b = |
let valid_block_detected b = |
174 |
List.iter (fun ip -> |
List.iter (fun ip -> |
175 |
set_ip_reliability ip Reliability_reliable; |
set_ip_reliability ip Reliability_reliable; |
176 |
print_reliability ip |
print_reliability ip |
177 |
) b.block_contributors |
) b.block_contributors |
179 |
let corrupted_block_detected b = |
let corrupted_block_detected b = |
180 |
let r, n, s, l = block_reliability b in |
let r, n, s, l = block_reliability b in |
181 |
let n = if b.block_legacy then n + 1 else n in |
let n = if b.block_legacy then n + 1 else n in |
182 |
let r, contributors = if n + s > 0 then |
let r, contributors = if n + s > 0 then |
183 |
0, List.filter (fun ip -> ip_reliability ip <> Reliability_reliable) b.block_contributors |
0, List.filter (fun ip -> ip_reliability ip <> Reliability_reliable) b.block_contributors |
184 |
else r, b.block_contributors in |
else r, b.block_contributors in |
185 |
let max_neighbors = (r + n + s) / 2 in |
let max_neighbors = (r + n + s) / 2 in |
186 |
List.iter (fun ip -> |
List.iter (fun ip -> |
187 |
set_ip_reliability ip (Reliability_suspicious max_neighbors); |
set_ip_reliability ip (Reliability_suspicious max_neighbors); |
188 |
print_reliability ip; |
print_reliability ip; |
189 |
if max_neighbors = 0 then |
if max_neighbors = 0 then |
220 |
), ":\t\t\tdisplay the reliability of sources"; |
), ":\t\t\tdisplay the reliability of sources"; |
221 |
] |
] |
222 |
|
|
|
|
|
223 |
open Md4 |
open Md4 |
224 |
(* TODO: add timers to remove old entries *) |
(* TODO: add timers to remove old entries *) |
225 |
|
|
239 |
Hashtbl.add client_hashes ip hash; |
Hashtbl.add client_hashes ip hash; |
240 |
true |
true |
241 |
|
|
|
|
|
242 |
module Marshal = struct |
module Marshal = struct |
243 |
|
|
244 |
let to_string v _ = |
let to_string v _ = |
245 |
let v = Marshal.to_string v [] in |
let v = Marshal.to_string v [] in |
246 |
(* The header depends on Ocaml version. Remove it. *) |
(* The header depends on Ocaml version. Remove it. *) |
247 |
let v = String.sub v (Marshal.header_size) |
let v = String.sub v (Marshal.header_size) |
248 |
(String.length v - Marshal.header_size) in |
(String.length v - Marshal.header_size) in |
249 |
v |
v |
250 |
|
|
251 |
end |
end |