Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
delete bad keys when encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
joecaswell committed Jun 28, 2022
1 parent 78c8b48 commit 192abf9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/peerbook/libp2p_peerbook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ iterator_move_filtered(KeyFun, Iterator, Action) ->
-spec random(peerbook(), [libp2p_crypto:pubkey_bin()], fun((libp2p_peer:peer()) -> boolean()), non_neg_integer()) -> {libp2p_crypto:pubkey_bin(), libp2p_peer:peer()} | false.
random(Peerbook=#peerbook{tid=TID, store=Store, stale_time=StaleTime}, Exclude, Pred, Tries) ->
{ok, Iterator} = rocksdb:iterator(Store, []),
KeyFilterFun = fun(K) -> <<_:(33*8)>> = K end,
%% Alternately, we might delete keys we don't like:
%KeyFilterFun = fun(<<_:(33*8)>>) -> true;
% (K) when is_binary(K) ->
% delete_peer(rev(K), Peerbook),
% false;
% (K) ->
% rocksdb:delete(Store, K, []),
% false
% end,
KeyFilterFun = fun(<<_:(33*8)>>) -> true;
(K) when is_binary(K) ->
delete_peer(rev(K), Peerbook),
false;
(K) ->
rocksdb:delete(Store, K, []),
false
end,
%% Alternately, we might filter without deleting bad keys:
% KeyFilterFun = fun(K) -> <<_:(33*8)>> = K end,
case iterator_move_filtered(KeyFilterFun, Iterator, first) of
{ok, FirstAddr = <<Start:(33*8)/integer-unsigned-big>>, FirstPeer} ->
{ok, <<End:(33*8)/integer-unsigned-big>>, _} = iterator_move_filtered(KeyFilterFun, Iterator, last),
Expand Down

0 comments on commit 192abf9

Please sign in to comment.