From 4976fcc91a43b5c7047c51a03985887b694f0fbb Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 24 Jan 2019 12:02:18 +0100 Subject: swarm: bootnode-mode, new bootnodes and no p2p package discovery (#18498) (cherry picked from commit bbd120354a8d226b446591eeda9f9462cb9b690a) --- cmd/swarm/main.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'cmd/swarm/main.go') diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index ccbb24eec..722dc4ff5 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -154,7 +154,6 @@ func init() { utils.BootnodesFlag, utils.KeyStoreDirFlag, utils.ListenPortFlag, - utils.NoDiscoverFlag, utils.DiscoveryV5Flag, utils.NetrestrictFlag, utils.NodeKeyFileFlag, @@ -187,6 +186,8 @@ func init() { SwarmUploadDefaultPath, SwarmUpFromStdinFlag, SwarmUploadMimeType, + // bootnode mode + SwarmBootnodeModeFlag, // storage flags SwarmStorePath, SwarmStoreCapacity, @@ -227,12 +228,17 @@ func main() { func keys(ctx *cli.Context) error { privateKey := getPrivKey(ctx) - pub := hex.EncodeToString(crypto.FromECDSAPub(&privateKey.PublicKey)) + pubkey := crypto.FromECDSAPub(&privateKey.PublicKey) + pubkeyhex := hex.EncodeToString(pubkey) pubCompressed := hex.EncodeToString(crypto.CompressPubkey(&privateKey.PublicKey)) + bzzkey := crypto.Keccak256Hash(pubkey).Hex() + if !ctx.Bool(SwarmCompressedFlag.Name) { - fmt.Println(fmt.Sprintf("publicKey=%s", pub)) + fmt.Println(fmt.Sprintf("bzzkey=%s", bzzkey[2:])) + fmt.Println(fmt.Sprintf("publicKey=%s", pubkeyhex)) } fmt.Println(fmt.Sprintf("publicKeyCompressed=%s", pubCompressed)) + return nil } @@ -272,6 +278,10 @@ func bzzd(ctx *cli.Context) error { setSwarmBootstrapNodes(ctx, &cfg) //setup the ethereum node utils.SetNodeConfig(ctx, &cfg) + + //always disable discovery from p2p package - swarm discovery is done with the `hive` protocol + cfg.P2P.NoDiscovery = true + stack, err := node.New(&cfg) if err != nil { utils.Fatalf("can't create node: %v", err) @@ -294,6 +304,15 @@ func bzzd(ctx *cli.Context) error { stack.Stop() }() + // add swarm bootnodes, because swarm doesn't use p2p package's discovery discv5 + go func() { + s := stack.Server() + + for _, n := range cfg.P2P.BootstrapNodes { + s.AddPeer(n) + } + }() + stack.Wait() return nil } -- cgit v1.2.3 From e247dcc141a5d1c9129b987a5f164e9df29be951 Mon Sep 17 00:00:00 2001 From: gluk256 Date: Thu, 24 Jan 2019 15:35:10 +0400 Subject: swarm/version: commit version added (#18510) (cherry picked from commit ad13d2d407d2f614c39af92430fda0a926da2a8a) --- cmd/swarm/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cmd/swarm/main.go') diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 722dc4ff5..53888b615 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -66,9 +66,10 @@ OPTIONS: {{end}}{{end}} ` -var ( - gitCommit string // Git SHA1 commit hash of the release (set via linker flags) -) +// Git SHA1 commit hash of the release (set via linker flags) +// this variable will be assigned if corresponding parameter is passed with install, but not with test +// e.g.: go install -ldflags "-X main.gitCommit=ed1312d01b19e04ef578946226e5d8069d5dfd5a" ./cmd/swarm +var gitCommit string //declare a few constant error messages, useful for later error check comparisons in test var ( @@ -89,6 +90,7 @@ var defaultNodeConfig = node.DefaultConfig // This init function sets defaults so cmd/swarm can run alongside geth. func init() { + sv.GitCommit = gitCommit defaultNodeConfig.Name = clientIdentifier defaultNodeConfig.Version = sv.VersionWithCommit(gitCommit) defaultNodeConfig.P2P.ListenAddr = ":30399" -- cgit v1.2.3 From 1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12 Mon Sep 17 00:00:00 2001 From: holisticode Date: Thu, 7 Feb 2019 07:51:24 -0500 Subject: cmd/swarm: hashes command (#19008) (cherry picked from commit 7f55b0cbd8618a1b0de8d7e37d2b0143ebae4abf) --- cmd/swarm/main.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmd/swarm/main.go') diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 53888b615..8af5d8c32 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -142,6 +142,8 @@ func init() { dbCommand, // See config.go DumpConfigCommand, + // hashesCommand + hashesCommand, } // append a hidden help subcommand to all commands that have subcommands -- cgit v1.2.3 From d1ace4f344616fb6fa8643872c1f9cac89f8549e Mon Sep 17 00:00:00 2001 From: holisticode Date: Thu, 7 Feb 2019 09:49:19 -0500 Subject: swarm: Debug API and HasChunks() API endpoint (#18980) (cherry picked from commit 41597c2856d6ac7328baca1340c3e36ab0edd382) --- cmd/swarm/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/swarm/main.go') diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 8af5d8c32..1e96d1294 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -451,5 +451,5 @@ func setSwarmBootstrapNodes(ctx *cli.Context, cfg *node.Config) { } cfg.P2P.BootstrapNodes = append(cfg.P2P.BootstrapNodes, node) } - log.Debug("added default swarm bootnodes", "length", len(cfg.P2P.BootstrapNodes)) + } -- cgit v1.2.3 From 85217b08bde168c0fd41d7265afe401454bb0f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jano=C5=A1=20Gulja=C5=A1?= Date: Thu, 7 Feb 2019 15:46:58 +0100 Subject: cmd/swarm/global-store: global store cmd (#19014) (cherry picked from commit 33d0a0efa61fed2b16797fd12161519943943282) --- cmd/swarm/main.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'cmd/swarm/main.go') diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 1e96d1294..3053ea1b3 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -39,13 +39,16 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p/enode" + "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/swarm" bzzapi "github.com/ethereum/go-ethereum/swarm/api" swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics" + "github.com/ethereum/go-ethereum/swarm/storage/mock" + mockrpc "github.com/ethereum/go-ethereum/swarm/storage/mock/rpc" "github.com/ethereum/go-ethereum/swarm/tracing" sv "github.com/ethereum/go-ethereum/swarm/version" - "gopkg.in/urfave/cli.v1" + cli "gopkg.in/urfave/cli.v1" ) const clientIdentifier = "swarm" @@ -196,6 +199,7 @@ func init() { SwarmStorePath, SwarmStoreCapacity, SwarmStoreCacheCapacity, + SwarmGlobalStoreAPIFlag, } rpcFlags := []cli.Flag{ utils.WSEnabledFlag, @@ -324,8 +328,18 @@ func bzzd(ctx *cli.Context) error { func registerBzzService(bzzconfig *bzzapi.Config, stack *node.Node) { //define the swarm service boot function boot := func(_ *node.ServiceContext) (node.Service, error) { - // In production, mockStore must be always nil. - return swarm.NewSwarm(bzzconfig, nil) + var nodeStore *mock.NodeStore + if bzzconfig.GlobalStoreAPI != "" { + // connect to global store + client, err := rpc.Dial(bzzconfig.GlobalStoreAPI) + if err != nil { + return nil, fmt.Errorf("global store: %v", err) + } + globalStore := mockrpc.NewGlobalStore(client) + // create a node store for this swarm key on global store + nodeStore = globalStore.NewNodeStore(common.HexToAddress(bzzconfig.BzzKey)) + } + return swarm.NewSwarm(bzzconfig, nodeStore) } //register within the ethereum node if err := stack.Register(boot); err != nil { -- cgit v1.2.3