P2p: algorithmic optimisation in P2p_pool
.
This commit is contained in:
parent
15b61d6b84
commit
5f378c8ba0
@ -303,21 +303,24 @@ let gc_points ({ config = { max_known_points } ; known_points } as pool) =
|
|||||||
match max_known_points with
|
match max_known_points with
|
||||||
| None -> ()
|
| None -> ()
|
||||||
| Some (_, target) ->
|
| Some (_, target) ->
|
||||||
let now = Time.now () in (* TODO: maybe time of discovery? *)
|
let current_size = P2p_point.Table.length known_points in
|
||||||
let table = Gc_point_set.create target in
|
if current_size > target then
|
||||||
P2p_point.Table.iter (fun p point_info ->
|
let to_remove_target = current_size - target in
|
||||||
if P2p_point_state.is_disconnected point_info then
|
let now = Time.now () in (* TODO: maybe time of discovery? *)
|
||||||
let time =
|
let table = Gc_point_set.create to_remove_target in
|
||||||
match P2p_point_state.Info.last_miss point_info with
|
P2p_point.Table.iter (fun p point_info ->
|
||||||
| None -> now
|
if P2p_point_state.is_disconnected point_info then
|
||||||
| Some t -> t in
|
let time =
|
||||||
Gc_point_set.insert (time, p) table
|
match P2p_point_state.Info.last_miss point_info with
|
||||||
) known_points ;
|
| None -> now
|
||||||
let to_remove = Gc_point_set.get table in
|
| Some t -> t in
|
||||||
ListLabels.iter to_remove ~f:begin fun (_, p) ->
|
Gc_point_set.insert (time, p) table
|
||||||
P2p_point.Table.remove known_points p
|
) known_points ;
|
||||||
end ;
|
let to_remove = Gc_point_set.get table in
|
||||||
log pool Gc_points
|
ListLabels.iter to_remove ~f:begin fun (_, p) ->
|
||||||
|
P2p_point.Table.remove known_points p
|
||||||
|
end ;
|
||||||
|
log pool Gc_points
|
||||||
|
|
||||||
let register_point pool ?trusted _source_peer_id (addr, port as point) =
|
let register_point pool ?trusted _source_peer_id (addr, port as point) =
|
||||||
match P2p_point.Table.find_opt pool.known_points point with
|
match P2p_point.Table.find_opt pool.known_points point with
|
||||||
@ -358,18 +361,21 @@ let gc_peer_ids ({ peer_meta_config = { score } ;
|
|||||||
match max_known_peer_ids with
|
match max_known_peer_ids with
|
||||||
| None -> ()
|
| None -> ()
|
||||||
| Some (_, target) ->
|
| Some (_, target) ->
|
||||||
let table = Gc_peer_set.create target in
|
let current_size = P2p_peer.Table.length known_peer_ids in
|
||||||
P2p_peer.Table.iter (fun peer_id peer_info ->
|
if current_size > target then
|
||||||
let created = P2p_peer_state.Info.created peer_info in
|
let to_remove_target = current_size - target in
|
||||||
let score = score @@ P2p_peer_state.Info.peer_metadata peer_info in
|
let table = Gc_peer_set.create to_remove_target in
|
||||||
if P2p_peer_state.is_disconnected peer_info then
|
P2p_peer.Table.iter (fun peer_id peer_info ->
|
||||||
Gc_peer_set.insert (score, created, peer_id) table)
|
let created = P2p_peer_state.Info.created peer_info in
|
||||||
known_peer_ids ;
|
let score = score @@ P2p_peer_state.Info.peer_metadata peer_info in
|
||||||
let to_remove = Gc_peer_set.get table in
|
if P2p_peer_state.is_disconnected peer_info then
|
||||||
ListLabels.iter to_remove ~f:begin fun (_, _, peer_id) ->
|
Gc_peer_set.insert (score, created, peer_id) table
|
||||||
P2p_peer.Table.remove known_peer_ids peer_id
|
) known_peer_ids ;
|
||||||
end ;
|
let to_remove = Gc_peer_set.get table in
|
||||||
log pool Gc_peer_ids
|
ListLabels.iter to_remove ~f:begin fun (_, _, peer_id) ->
|
||||||
|
P2p_peer.Table.remove known_peer_ids peer_id
|
||||||
|
end ;
|
||||||
|
log pool Gc_peer_ids
|
||||||
|
|
||||||
let register_peer pool peer_id =
|
let register_peer pool peer_id =
|
||||||
match P2p_peer.Table.find_opt pool.known_peer_ids peer_id with
|
match P2p_peer.Table.find_opt pool.known_peer_ids peer_id with
|
||||||
|
Loading…
Reference in New Issue
Block a user