@ -23,6 +23,7 @@ import (
"os"
"runtime"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils"
@ -38,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/swarm"
bzzapi "github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/swarm/network"
"gopkg.in/urfave/cli.v1"
)
@ -61,17 +63,22 @@ var (
Name : "bzzport" ,
Usage : "Swarm local http api port" ,
}
SwarmNetworkIdFlag = cli . IntFlag {
Name : "bzznetworkid" ,
Usage : "Network identifier (integer, default 322=swarm testnet)" ,
Value : network . NetworkId ,
}
SwarmConfigPathFlag = cli . StringFlag {
Name : "bzzconfig" ,
Usage : "Swarm config file path (datadir/bzz)" ,
}
SwarmSwapDisabled = cli . BoolFlag {
Name : "bzzno swap" ,
Usage : "Swarm SWAP dis abled (default false)" ,
SwarmSwapEn abled = cli . BoolFlag {
Name : "swap" ,
Usage : "Swarm SWAP en abled (default false)" ,
}
SwarmSyncDis abled = cli . BoolFlag {
Name : "bzzno sync" ,
Usage : "Swarm Syncing disabled (default fals e)" ,
SwarmSyncEn abled = cli . BoolT Flag {
Name : "sync" ,
Usage : "Swarm Syncing enabled (default tru e)" ,
}
EthAPI = cli . StringFlag {
Name : "ethapi" ,
@ -86,6 +93,7 @@ func init() {
// Override flag defaults so bzzd can run alongside geth.
utils . ListenPortFlag . Value = 30399
utils . IPCPathFlag . Value = utils . DirectoryString { Value : "bzzd.ipc" }
utils . IPCApiFlag . Value = "admin, bzz, chequebook, debug, rpc, web3"
// Set up the cli app.
app . Commands = nil
@ -96,21 +104,24 @@ func init() {
utils . BootnodesFlag ,
utils . KeyStoreDirFlag ,
utils . ListenPortFlag ,
utils . NoDiscoverFlag ,
utils . DiscoveryV5Flag ,
utils . NetrestrictFlag ,
utils . MaxPeersFlag ,
utils . NATFlag ,
utils . NodeKeyFileFlag ,
utils . NodeKeyHexFlag ,
utils . MaxPeersFlag ,
utils . NATFlag ,
utils . IPCDisabledFlag ,
utils . IPCApiFlag ,
utils . IPCPathFlag ,
// bzzd-specific flags
EthAPI ,
SwarmConfigPathFlag ,
SwarmSwapDis abled ,
SwarmSyncDis abled ,
SwarmSwapEn abled ,
SwarmSyncEn abled ,
SwarmPortFlag ,
SwarmAccountFlag ,
SwarmNetworkIdFlag ,
ChequebookAddrFlag ,
}
app . Flags = append ( app . Flags , debug . Flags ... )
@ -138,7 +149,8 @@ func bzzd(ctx *cli.Context) error {
// Add bootnodes as initial peers.
if ctx . GlobalIsSet ( utils . BootnodesFlag . Name ) {
injectBootnodes ( stack . Server ( ) , ctx . GlobalStringSlice ( utils . BootnodesFlag . Name ) )
bootnodes := strings . Split ( ctx . GlobalString ( utils . BootnodesFlag . Name ) , "," )
injectBootnodes ( stack . Server ( ) , bootnodes )
} else {
injectBootnodes ( stack . Server ( ) , defaultBootnodes )
}
@ -155,7 +167,7 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
if bzzdir == "" {
bzzdir = stack . InstanceDir ( )
}
bzzconfig , err := bzzapi . NewConfig ( bzzdir , chbookaddr , prvkey )
bzzconfig , err := bzzapi . NewConfig ( bzzdir , chbookaddr , prvkey , ctx . GlobalUint64 ( SwarmNetworkIdFlag . Name ) )
if err != nil {
utils . Fatalf ( "unable to configure swarm: %v" , err )
}
@ -163,16 +175,18 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
if len ( bzzport ) > 0 {
bzzconfig . Port = bzzport
}
swapEnabled := ! ctx . GlobalBool ( SwarmSwapDis abled . Name )
syncEnabled := ! ctx . GlobalBool ( SwarmSyncDis abled . Name )
swapEnabled := ctx . GlobalBool ( SwarmSwapEn abled . Name )
syncEnabled := ctx . GlobalBoolT ( SwarmSyncEn abled . Name )
ethapi := ctx . GlobalString ( EthAPI . Name )
if ethapi == "" {
utils . Fatalf ( "Option %q must not be empty" , EthAPI . Name )
}
boot := func ( ctx * node . ServiceContext ) ( node . Service , error ) {
client , err := ethclient . Dial ( ethapi )
var client * ethclient . Client
if ethapi == "" {
err = fmt . Errorf ( "use ethapi flag to connect to a an eth client and talk to the blockchain" )
} else {
client , err = ethclient . Dial ( ethapi )
}
if err != nil {
utils . Fatalf ( "Can't connect: %v" , err )
}
@ -241,6 +255,7 @@ func injectBootnodes(srv *p2p.Server, nodes []string) {
n , err := discover . ParseNode ( url )
if err != nil {
glog . Errorf ( "invalid bootnode %q" , err )
continue
}
srv . AddPeer ( n )
}