cmd/p2p/swarm: Remove comments + config.Enode nomarshal

This commit is contained in:
lash 2019-03-18 13:18:01 +01:00
parent bc2483eaff
commit 91d15ad5b3
7 changed files with 40 additions and 65 deletions

View file

@ -135,9 +135,9 @@ func initSwarmNode(config *bzzapi.Config, stack *node.Node, ctx *cli.Context) er
return err return err
} }
//configuration phase completed here //configuration phase completed here
log.Info("Starting Swarm with the following parameters:") log.Debug("Starting Swarm with the following parameters:")
//after having created the config, print it to screen //after having created the config, print it to screen
log.Info(printConfig(config)) log.Debug(printConfig(config))
return nil return nil
} }

View file

@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/swarm" "github.com/ethereum/go-ethereum/swarm"
"github.com/ethereum/go-ethereum/swarm/api" "github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/swarm/log"
) )
func TestConfigDump(t *testing.T) { func TestConfigDump(t *testing.T) {
@ -162,16 +161,6 @@ func TestConfigFileOverrides(t *testing.T) {
defaultConf.HiveParams.KeepAliveInterval = 6000000000 defaultConf.HiveParams.KeepAliveInterval = 6000000000
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second
//defaultConf.SyncParams.KeyBufferSize = 512 //defaultConf.SyncParams.KeyBufferSize = 512
dir, err := ioutil.TempDir("", "bzztest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
conf, account, pk := getTestAccountWithPrivateKey(t, dir)
node := &testNode{Dir: dir}
defaultConf.Init(pk)
//create a TOML string //create a TOML string
out, err := tomlSettings.Marshal(&defaultConf) out, err := tomlSettings.Marshal(&defaultConf)
if err != nil { if err != nil {
@ -189,6 +178,14 @@ func TestConfigFileOverrides(t *testing.T) {
} }
f.Sync() f.Sync()
dir, err := ioutil.TempDir("", "bzztest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
conf, account := getTestAccount(t, dir)
node := &testNode{Dir: dir}
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(), fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(),
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
@ -375,19 +372,6 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
defaultConf.HiveParams.KeepAliveInterval = 6000000000 defaultConf.HiveParams.KeepAliveInterval = 6000000000
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second
//defaultConf.SyncParams.KeyBufferSize = 512 //defaultConf.SyncParams.KeyBufferSize = 512
dir, err := ioutil.TempDir("", "bzztest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
conf, account, pk := getTestAccountWithPrivateKey(t, dir)
node := &testNode{Dir: dir}
expectNetworkId := uint64(77)
defaultConf.Init(pk)
//create a TOML file //create a TOML file
out, err := tomlSettings.Marshal(&defaultConf) out, err := tomlSettings.Marshal(&defaultConf)
if err != nil { if err != nil {
@ -407,6 +391,16 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
} }
f.Sync() f.Sync()
dir, err := ioutil.TempDir("", "bzztest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
conf, account := getTestAccount(t, dir)
node := &testNode{Dir: dir}
expectNetworkId := uint64(77)
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "77", fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "77",
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort, fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort,
@ -417,7 +411,6 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir, fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath, fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
} }
log.Warn("exec with flags", "f", flags)
node.Cmd = runSwarm(t, flags...) node.Cmd = runSwarm(t, flags...)
node.Cmd.InputLine(testPassphrase) node.Cmd.InputLine(testPassphrase)
defer func() { defer func() {

View file

@ -222,12 +222,7 @@ type testNode struct {
const testPassphrase = "swarm-test-passphrase" const testPassphrase = "swarm-test-passphrase"
func getTestAccount(t *testing.T, dir string) (conf *node.Config, account accounts.Account) { func getTestAccount(t *testing.T, dir string) (conf *node.Config, account accounts.Account) {
conf, account, _ = getTestAccountWithPrivateKey(t, dir) // create key
return
}
func getTestAccountWithPrivateKey(t *testing.T, dir string) (conf *node.Config, account accounts.Account, pk *ecdsa.PrivateKey) {
// create kej
conf = &node.Config{ conf = &node.Config{
DataDir: dir, DataDir: dir,
IPCPath: "bzzd.ipc", IPCPath: "bzzd.ipc",
@ -237,19 +232,17 @@ func getTestAccountWithPrivateKey(t *testing.T, dir string) (conf *node.Config,
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
ks := n.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) account, err = n.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore).NewAccount(testPassphrase)
account, err = ks.NewAccount(testPassphrase)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
pk = decryptStoreAccount(ks, account.Address.String(), []string{testPassphrase})
// use a unique IPCPath when running tests on Windows // use a unique IPCPath when running tests on Windows
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
conf.IPCPath = fmt.Sprintf("bzzd-%s.ipc", account.Address.String()) conf.IPCPath = fmt.Sprintf("bzzd-%s.ipc", account.Address.String())
} }
return conf, account, pk return conf, account
} }
func existingTestNode(t *testing.T, dir string, bzzaccount string) *testNode { func existingTestNode(t *testing.T, dir string, bzzaccount string) *testNode {

View file

@ -96,7 +96,6 @@ func (e *ExecAdapter) NewNode(config *NodeConfig) (Node, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Warn("set default enr", "e", config)
// generate the config // generate the config
conf := &execNodeConfig{ conf := &execNodeConfig{
Stack: node.DefaultConfig, Stack: node.DefaultConfig,
@ -415,6 +414,8 @@ func startExecNodeStack() (*node.Node, error) {
if err := json.Unmarshal([]byte(confEnv), &conf); err != nil { if err := json.Unmarshal([]byte(confEnv), &conf); err != nil {
return nil, fmt.Errorf("error decoding %s: %v", envNodeConfig, err) return nil, fmt.Errorf("error decoding %s: %v", envNodeConfig, err)
} }
// TODO verify that ListenAddr will contain the corrent tcp addr
// if we should start using exec adapters with other host than local
nodeTcpConn, err := net.ResolveTCPAddr("tcp", conf.Stack.P2P.ListenAddr) nodeTcpConn, err := net.ResolveTCPAddr("tcp", conf.Stack.P2P.ListenAddr)
if err != nil { if err != nil {
conf.Node.initDefaultEnode() conf.Node.initDefaultEnode()

View file

@ -272,14 +272,11 @@ func (n *NodeConfig) initDefaultEnode() error {
} }
func (n *NodeConfig) initEnode(ip net.IP, tcpport int, udpport int) error { func (n *NodeConfig) initEnode(ip net.IP, tcpport int, udpport int) error {
enrIp := enr.IP(ip)
// dialer in simulations based on ENR records
// doesn't work unless we explicitly set localhost record
enrIp := enr.IP(net.IPv4(127, 0, 0, 1))
n.Record.Set(&enrIp) n.Record.Set(&enrIp)
enrTcpPort := enr.TCP(0) enrTcpPort := enr.TCP(tcpport)
n.Record.Set(&enrTcpPort) n.Record.Set(&enrTcpPort)
enrUdpPort := enr.UDP(0) enrUdpPort := enr.UDP(tcpport)
n.Record.Set(&enrUdpPort) n.Record.Set(&enrUdpPort)
err := enode.SignV4(&n.Record, n.PrivateKey) err := enode.SignV4(&n.Record, n.PrivateKey)

View file

@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr" "github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/swarm/log"
"github.com/ethereum/go-ethereum/swarm/network" "github.com/ethereum/go-ethereum/swarm/network"
"github.com/ethereum/go-ethereum/swarm/pss" "github.com/ethereum/go-ethereum/swarm/pss"
"github.com/ethereum/go-ethereum/swarm/services/swap" "github.com/ethereum/go-ethereum/swarm/services/swap"
@ -59,8 +58,7 @@ type Config struct {
Port string Port string
PublicKey string PublicKey string
BzzKey string BzzKey string
//NodeID string Enode *enode.Node `toml:"-"`
Enode *enode.Node `toml:",omit"`
NetworkID uint64 NetworkID uint64
SwapEnabled bool SwapEnabled bool
SyncEnabled bool SyncEnabled bool
@ -89,7 +87,6 @@ func NewConfig() (c *Config) {
ListenAddr: DefaultHTTPListenAddr, ListenAddr: DefaultHTTPListenAddr,
Port: DefaultHTTPPort, Port: DefaultHTTPPort,
Path: node.DefaultDataDir(), Path: node.DefaultDataDir(),
Enode: &enode.Node{},
EnsAPIs: nil, EnsAPIs: nil,
EnsRoot: ens.TestNetAddress, EnsRoot: ens.TestNetAddress,
NetworkID: network.DefaultNetworkID, NetworkID: network.DefaultNetworkID,
@ -123,7 +120,7 @@ func (c *Config) Init(prvKey *ecdsa.PrivateKey) error {
c.PublicKey = pubkeyhex c.PublicKey = pubkeyhex
c.BzzKey = keyhex c.BzzKey = keyhex
//c.NodeID = enode.PubkeyToIDV4(&prvKey.PublicKey).String()
var record enr.Record var record enr.Record
record.Set(network.NewENRAddrEntry(bzzkeybytes)) record.Set(network.NewENRAddrEntry(bzzkeybytes))
record.Set(network.ENRLightNodeEntry(c.LightNodeEnabled)) record.Set(network.ENRLightNodeEntry(c.LightNodeEnabled))
@ -136,7 +133,6 @@ func (c *Config) Init(prvKey *ecdsa.PrivateKey) error {
if err != nil { if err != nil {
return fmt.Errorf("Enode create fail: %v", err) return fmt.Errorf("Enode create fail: %v", err)
} }
log.Warn("setting enode record", "node", c.Enode)
if c.SwapEnabled { if c.SwapEnabled {
c.Swap.Init(c.Contract, prvKey) c.Swap.Init(c.Contract, prvKey)

View file

@ -170,12 +170,7 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
self.accountingMetrics = protocols.SetupAccountingMetrics(10*time.Second, filepath.Join(config.Path, "metrics.db")) self.accountingMetrics = protocols.SetupAccountingMetrics(10*time.Second, filepath.Join(config.Path, "metrics.db"))
} }
// var nodeID enode.ID
// if err := nodeID.UnmarshalText([]byte(config.NodeID)); err != nil {
// return nil, err
// }
nodeID := config.Enode.ID() nodeID := config.Enode.ID()
bzzconfig.UnderlayAddr = []byte(nodeID.String())
syncing := stream.SyncingAutoSubscribe syncing := stream.SyncingAutoSubscribe
if !config.SyncEnabled || config.LightNodeEnabled { if !config.SyncEnabled || config.LightNodeEnabled {