mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
improve swarm/cmd/swarm: add enode, connect subcommands, improve startup (only one round needed)
This commit is contained in:
parent
4c19de895b
commit
e267b56c32
1 changed files with 63 additions and 16 deletions
|
|
@ -121,8 +121,10 @@ function init {
|
|||
killall geth
|
||||
reset all
|
||||
cluster $*
|
||||
stop all
|
||||
cluster $*
|
||||
enode all
|
||||
connect all
|
||||
# stop all
|
||||
# cluster $*
|
||||
}
|
||||
|
||||
function reset {
|
||||
|
|
@ -136,6 +138,61 @@ function reset {
|
|||
|
||||
}
|
||||
|
||||
function enode {
|
||||
dir=$root/$network_id
|
||||
id=$1
|
||||
shift
|
||||
if [ $id = "all" ]; then
|
||||
N=`ls -1 $dir/enodes/|wc -l`
|
||||
enodes=$dir/enodes.all
|
||||
rm -f $enodes
|
||||
# build a static nodes(-like) list of all enodes of the local cluster
|
||||
echo "[" >> $enodes
|
||||
for ((i=0;i<N;++i)); do
|
||||
id=`printf "%02d" $i`
|
||||
enode=$dir/enodes/$id.enode
|
||||
enode $id
|
||||
if [ -f "$enode" ] && [ ! -z "$enode" ]; then
|
||||
cat "$enode" >> $enodes
|
||||
echo "," >> $enodes
|
||||
fi
|
||||
done
|
||||
echo "\"\"]" >> $enodes
|
||||
cmd=$dir/connect.js
|
||||
for ((i=0;i<N;++i)); do
|
||||
id=`printf "%02d" $i`
|
||||
enode=$dir/enodes/$id.enode
|
||||
if [ -f "$enode" ] && [ ! -z "$enode" ]; then
|
||||
echo -n "admin.addPeer(" >> $cmd
|
||||
cat "$enode" >> $cmd
|
||||
echo ");" >> $cmd
|
||||
fi
|
||||
done
|
||||
else
|
||||
enode=$dir/enodes/$id.enode
|
||||
attach $id --exec "'console.log(admin.nodeInfo.enode)'" |head -2 |tail -1| perl -pe 's/^/"/;s/$/"/'|perl -pe 's/\s*$//' > $enode
|
||||
# cat $enode
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function connect {
|
||||
dir=$root/$network_id
|
||||
id=$1
|
||||
shift
|
||||
if [ $id = "all" ]; then
|
||||
for ((i=0;i<N;++i)); do
|
||||
id=`printf "%02d" $i`
|
||||
connect $id
|
||||
done
|
||||
else
|
||||
cmd="$GETH --preload $dir/connect.js --exec '\"admin.peers\"' attach ipc:$root/$network_id/data/$id/geth.ipc $dir/connect.js"
|
||||
# echo $cmd
|
||||
eval $cmd
|
||||
cat $dir/connect.js
|
||||
fi
|
||||
}
|
||||
|
||||
function cluster {
|
||||
N=$1
|
||||
shift
|
||||
|
|
@ -149,20 +206,6 @@ function cluster {
|
|||
mkdir -p $dir/pids
|
||||
mkdir -p $dir/log
|
||||
|
||||
enodes=$dir/enodes.all
|
||||
rm -f $enodes
|
||||
# build a static nodes(-like) list of all enodes of the local cluster
|
||||
echo "[" >> $enodes
|
||||
for ((i=0;i<N;++i)); do
|
||||
id=`printf "%02d" $i`
|
||||
enode=$dir/enodes/$id.enode
|
||||
if [ -f "$enode" ]; then
|
||||
cat "$enode" >> $enodes
|
||||
echo "," >> $enodes
|
||||
fi
|
||||
done
|
||||
echo "\"\"]" >> $enodes
|
||||
|
||||
for ((i=0;i<N;++i)); do
|
||||
id=`printf "%02d" $i`
|
||||
mkdir -p $dir/data/$id
|
||||
|
|
@ -282,6 +325,10 @@ function netstatconf {
|
|||
case $cmd in
|
||||
"info" )
|
||||
info $*;;
|
||||
"enode" )
|
||||
enode $*;;
|
||||
"connect" )
|
||||
connect $*;;
|
||||
"status" )
|
||||
status $*;;
|
||||
"clean" )
|
||||
|
|
|
|||
Loading…
Reference in a new issue