Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
This is one more intermediate commit of the p2p networking feature.
Browse files Browse the repository at this point in the history
There is a problem right now with the run_test.pl script. For some
reason the eosd instance launched by perl is now failing to initalize
the shared memory, although running the exact same command line from
the shell works fine.
  • Loading branch information
pmesnier committed Jul 27, 2017
1 parent 842e12f commit 9b76ee8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 35 deletions.
55 changes: 42 additions & 13 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ip/host_name.hpp>
#include <boost/thread.hpp>

namespace eos {
using std::vector;
Expand Down Expand Up @@ -205,6 +206,20 @@ namespace eos {
}; // class connection


static boost::thread_specific_ptr<transaction_id_type> last_recd_txn;
static net_plugin_impl *my_impl;

class last_recd_txn_guard {
public:
last_recd_txn_guard (transaction_id_type id) {
transaction_id_type *ptid = new transaction_id_type(id);
last_recd_txn.reset (ptid);
}
~last_recd_txn_guard () {
last_recd_txn.reset (0);
}
};

class net_plugin_impl {
public:
unique_ptr<tcp::acceptor> acceptor;
Expand Down Expand Up @@ -578,6 +593,8 @@ namespace eos {
dlog ("got a SignedTransacton");
chain_controller &cc = chain_plug->chain();
if (!cc.is_known_transaction(msg.id())) {
last_recd_txn_guard tls_guard(msg.id());

chain_plug->accept_transaction (msg);
forward (c, msg);
}
Expand Down Expand Up @@ -664,10 +681,32 @@ namespace eos {
c.reset ();
}

void send_all_txn (const SignedTransaction&txn) {
dlog ("got signaled about a pending transaction");
if (last_recd_txn.get() && *last_recd_txn.get() == txn.id()) {
dlog ("skipping our received transacton");
return;
}

if (true) { //txn.get_size() <= just_send_it_max) {
send_all (txn);
return;
}

uint32_t psize = (pending_notify.size()+1) * sizeof (txn.id());
if (psize >= my_impl->just_send_it_max) {
notice_message nm = {vector<block_id_type>(), pending_notify};
send_all (nm);
pending_notify.clear();
}
pending_notify.push_back(txn.id());
}

static void pending_txn (const SignedTransaction& txn) {
// dlog ("got signaled of txn!");
my_impl->send_all_txn (txn);
}


}; // class net_plugin_impl

net_plugin_impl* handshake_initializer::info;
Expand Down Expand Up @@ -714,6 +753,7 @@ namespace eos {
net_plugin::net_plugin()
:my( new net_plugin_impl ) {
handshake_initializer::info = my.get();
my_impl = my.get();
}

net_plugin::~net_plugin() {
Expand Down Expand Up @@ -818,18 +858,7 @@ namespace eos {
} FC_CAPTURE_AND_RETHROW() }

void net_plugin::broadcast_transaction (const SignedTransaction &txn) {
if (true) { //txn.get_size() <= my->just_send_it_max) {
my->send_all (txn);
return;
}

uint32_t psize = (my->pending_notify.size()+1) * sizeof (txn.id());
if (psize >= my->just_send_it_max) {
notice_message nm = {vector<block_id_type>(), my->pending_notify};
my->send_all (nm);
my->pending_notify.clear();
}
my->pending_notify.push_back(txn.id());
my->pending_txn (txn);
}

void net_plugin::broadcast_block (const chain::signed_block &sb) {
Expand Down
52 changes: 30 additions & 22 deletions tests/p2p_tests/init/run_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,28 @@
my $genesis = "$eos_home/genesis.json";
my $http_port_base = 8888;
my $p2p_port_base = 9876;
my $data_dir_base = "tdn";
my $http_port_base = 8888;
my $hostname = "localhost";
my $data_dir_base = "ttdn";
my $hostname = "127.0.0.1";
my $first_pause = 45;
my $launch_pause = 5;
my $run_duration = 60;
my $topo = "ring";
my $override_gts = "now";
my $override_gts; # = "now";

if (!GetOptions("nodes=i" => \$nodes,
"first-pause=i" => \$first_pause,
"launch-pause=i" => \$launch_pause,
"duration=i" => \$run_duration,
"topo=s" => \$topo,
"pnodes=i" => \$pnodes)) {
print "usage: $ARGV[0] [--nodes=<n>] [--first-pause=<n>] [--launch-pause=<n>] [--duration=<n>] [--pnodes]\n";
print "usage: $ARGV[0] [--nodes=<n>] [--pnodes=<n>] [--topo=<ring|star>] [--first-pause=<n>] [--launch-pause=<n>] [--duration=<n>]\n";
print "where:\n";
print "--nodes=n (default = 1) sets the number of eosd instances to launch\n";
print "--pnodes=n (default = 1) sets the number nodes that will also be producers\n";
print "--topo=s (default = ring) sets the network topology to eithar a ring shape or a star shape\n";
print "--first-pause=n (default = 45) sets the seconds delay after starting the first instance\n";
print "--launch-pause=n (default = 5) sets the seconds delay after starting subsequent nodes\n";
print "--duration=n (default = 60) sets the seconds delay after starting the last node before shutting down the test\n";
print "--pnodes=n (default = 1) sets the number nodes that will also be producers\n";
print "\nproducer count currently fixed at $prods\n";
exit
}
Expand Down Expand Up @@ -73,7 +74,7 @@
opendir(DIR, ".") or die $!;
while (my $d = readdir(DIR)) {
if ($d =~ $data_dir_base) {
rmtree ($d);
rmtree ($d) or die $!;
}
}
closedir(DIR);
Expand All @@ -82,14 +83,16 @@ sub write_config {
my $i = shift;
my $producer = shift;
mkdir ($data_dir[$i]);
mkdir ($data_dir[$i]."/blocks");
mkdir ($data_dir[$i]."/blockchain");

open (my $cfg, '>', "$data_dir[$i]/config.ini") ;
print $cfg "genesis-json = \"$genesis\"\n";
print $cfg "block-log-dir = \"blocks\"\n";
print $cfg "block-log-dir = blocks\n";
print $cfg "readonly = 0\n";
print $cfg "shared-file-dir = \"blockchain\"\n";
print $cfg "shared-file-dir = blockchain\n";
print $cfg "shared-file-size = 64\n";
print $cfg "http-server-endpoint = 0.0.0.0:$http_port[$i]\n";
print $cfg "http-server-endpoint = 127.0.0.1:$http_port[$i]\n";
print $cfg "listen-endpoint = 0.0.0.0:$p2p_port[$i]\n";
print $cfg "public-endpoint = $hostname:$p2p_port[$i]\n";
foreach my $peer (@peers) {
Expand All @@ -102,6 +105,7 @@ sub write_config {
print $cfg "private-key = [\"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\",\"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3\"]\n";

print $cfg "plugin = eos::producer_plugin\n";
print $cfg "plugin = eos::chain_api_plugin\n";

my $prod_ndx = ord('a') + $producer;
my $num_prod = $pcount[$producer];
Expand Down Expand Up @@ -140,22 +144,26 @@ ()
}

sub launch_nodes () {
my $GTS = $override_gts;
if ($override_gts =~ "now" ) {
chomp ($GTS = `date -u "+%Y-%m-%dT%H:%M:%S"`);
my @s = split (':',$GTS);
$s[2] = substr ((100 + (int ($s[2]/3) * 3)),1);
$GTS = join (':', @s);
print "using genesis time stamp $GTS\n";
}
my $gtsarg;
$gtsarg = "--genesis-timestamp=$GTS" if ($override_gts);
if (defined $override_gts) {
my $GTS = $override_gts;
print "$override_gts\n";

if ($override_gts =~ "now" ) {
chomp ($GTS = `date -u "+%Y-%m-%dT%H:%M:%S"`);
my @s = split (':',$GTS);
$s[2] = substr ((100 + (int ($s[2]/3) * 3)),1);
$GTS = join (':', @s);
print "using genesis time stamp $GTS\n";
}
$gtsarg = " --genesis-timestamp=$GTS";
}

for (my $i = 0; $i < $nodes; $i++) {
my @cmdline = ($eosd,
$gtsarg,
"--data-dir=$data_dir[$i]");

" --data-dir=$data_dir[$i]");
print "starting $eosd $gtsarg --data-dir=$data_dir[$i]\n";
$pid[$i] = fork;
if ($pid[$i] > 0) {
my $pause = $i == 0 ? $first_pause : $launch_pause;
Expand Down Expand Up @@ -210,7 +218,7 @@ ()
elsif ( $topo =~ "star" ) { make_star_topology () or die; }
else { print "$topo is not a known topology" and die; }
}

exit; #sleep(1);
launch_nodes ();

kill_nodes () if ($run_duration > 0);

0 comments on commit 9b76ee8

Please sign in to comment.