Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

standalone libp2p-peerbook integration - BC core changes #413

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%% -*- erlang -*-
{cover_enabled, true}.
{cover_enabled, true}.
{cover_opts, [verbose]}.
{cover_export_enabled, true}.
{covertool, [{coverdata_files,
Expand All @@ -13,7 +12,7 @@
{deps, [
{lager, ".*", {git, "https://github.com/erlang-lager/lager.git", {branch, "master"}}},
{erl_base58, "0.0.1"},
{libp2p, ".*", {git, "https://github.com/helium/erlang-libp2p.git", {branch, "master"}}},
{libp2p, ".*", {git, "https://github.com/helium/erlang-libp2p.git", {branch, "andymck/use-peerbook-in-libp2p"}}},
{clique, ".*", {git, "https://github.com/helium/clique.git", {branch, "develop"}}},
{h3, ".*", {git, "https://github.com/helium/erlang-h3.git", {branch, "master"}}},
{erl_angry_purple_tiger, ".*", {git, "https://github.com/helium/erl_angry_purple_tiger.git", {branch, "master"}}},
Expand Down
6 changes: 5 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@
0},
{<<"libp2p">>,
{git,"https://github.com/helium/erlang-libp2p.git",
{ref,"2e81c79ceb16c74e3dbcc19e982b5192817e50b0"}},
{ref,"1703404f0f664a9345dbe1a39320c29f6d64a794"}},
0},
{<<"libp2p_crypto">>,{pkg,<<"libp2p_crypto">>,<<"1.0.1">>},1},
{<<"libp2p_peerbook">>,
{git,"https://github.com/helium/libp2p-peerbook",
{ref,"d198028c356521d40389f5c75e187c1cfc065a6b"}},
1},
{<<"multiaddr">>,{pkg,<<"multiaddr">>,<<"1.1.3">>},1},
{<<"nat">>,
{git,"https://github.com/benoitc/erlang-nat",
Expand Down
4 changes: 2 additions & 2 deletions src/blockchain_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ init(Args) ->
[
{key, proplists:get_value(key, Args)},
{base_dir, proplists:get_value(base_dir, Args, "data")},
{libp2p_peer_resolution, [{allow_rfc1918, application:get_env(blockchain, peerbook_allow_rfc1918, true)}]},
{libp2p_proxy,
[{limit, application:get_env(blockchain, relay_limit, 25)}]},
{libp2p_peerbook,
[{signed_metadata_fun, fun blockchain_worker:signed_metadata_fun/0},
{notify_time, application:get_env(blockchain, peerbook_update_interval, timer:minutes(5))},
{allow_rfc1918, application:get_env(blockchain, peerbook_allow_rfc1918, false)}
{notify_time, application:get_env(blockchain, peerbook_update_interval, timer:minutes(5))}
]},
{libp2p_group_gossip,
[
Expand Down
1 change: 1 addition & 0 deletions src/blockchain_swarm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

-define(SERVER, ?MODULE).
%% generated by libp2p
%% TODO - need better solution to hardcoding the name of a module in another lib
-define(SWARM_NAME, libp2p_swarm_sup_blockchain_swarm).

-record(state, {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/blockchain_cli_peer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ peer_refresh(["peer", "refresh", Addr], [], []) ->
Swarm = blockchain_swarm:swarm(),
Peerbook = libp2p_swarm:peerbook(Swarm),
TrimmedAddr = string:trim(Addr),
libp2p_peerbook:refresh(Peerbook, libp2p_crypto:p2p_to_pubkey_bin(TrimmedAddr)),
libp2p_peer_resolution:refresh(Peerbook, libp2p_crypto:p2p_to_pubkey_bin(TrimmedAddr)),
[clique_status:text("ok")].

%%
Expand Down
6 changes: 4 additions & 2 deletions test/blockchain_fastforward_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ all() ->
%%--------------------------------------------------------------------
init_per_testcase(TestCase, Config) ->
% Simulate other chain with fastforward handler only
{ok, SimSwarm} = libp2p_swarm:start(fastforward_SUITE_sim, [{libp2p_nat, [{enabled, false}]}]),
{ok, SimSwarm} = libp2p_swarm:start(fastforward_SUITE_sim, [{libp2p_nat, [{enabled, false}]},
{libp2p_peer_resolution, [{allow_rfc1918, application:get_env(blockchain, peerbook_allow_rfc1918, true)}]}]),
ok = libp2p_swarm:listen(SimSwarm, "/ip4/0.0.0.0/tcp/0"),
blockchain_ct_utils:init_base_dir_config(?MODULE, TestCase, [{swarm, SimSwarm}|Config]).

Expand Down Expand Up @@ -65,7 +66,7 @@ basic(Config) ->
Chain0 = blockchain_worker:blockchain(),
{ok, Genesis} = blockchain:genesis_block(Chain0),


% Simulate other chain with fastforward handler only
{ok, Chain} = blockchain:new(SimDir, Genesis, undefined),

% Add some blocks
Expand All @@ -86,6 +87,7 @@ basic(Config) ->
,?FASTFORWARD_PROTOCOL
,{libp2p_framed_stream, server, [blockchain_fastforward_handler, ?MODULE, Chain]}
),

% This is just to connect the 2 swarms
[ListenAddr|_] = libp2p_swarm:listen_addrs(blockchain_swarm:swarm()),
{ok, _} = libp2p_swarm:connect(SimSwarm, ListenAddr),
Expand Down
3 changes: 2 additions & 1 deletion test/blockchain_sync_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ all() ->
%% TEST CASE SETUP
%%--------------------------------------------------------------------
init_per_testcase(TestCase, Config) ->
{ok, SimSwarm} = libp2p_swarm:start(sync_SUITE_sim, [{libp2p_nat, [{enabled, false}]}]),
{ok, SimSwarm} = libp2p_swarm:start(sync_SUITE_sim, [{libp2p_nat, [{enabled, false}]},
{libp2p_peer_resolution, [{allow_rfc1918, application:get_env(blockchain, peerbook_allow_rfc1918, true)}]}]),
ok = libp2p_swarm:listen(SimSwarm, "/ip4/0.0.0.0/tcp/0"),
blockchain_ct_utils:init_base_dir_config(?MODULE, TestCase, [{swarm, SimSwarm}|Config]).

Expand Down