mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/swarm, p2p, swarm: Enable ENR in binary/execadapter
This commit is contained in:
parent
8d04154691
commit
55bddb51ab
7 changed files with 60 additions and 39 deletions
|
|
@ -135,9 +135,9 @@ func initSwarmNode(config *bzzapi.Config, stack *node.Node, ctx *cli.Context, no
|
|||
return err
|
||||
}
|
||||
//configuration phase completed here
|
||||
log.Debug("Starting Swarm with the following parameters:")
|
||||
log.Info("Starting Swarm with the following parameters:")
|
||||
//after having created the config, print it to screen
|
||||
log.Debug(printConfig(config))
|
||||
log.Info(printConfig(config))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/swarm"
|
||||
"github.com/ethereum/go-ethereum/swarm/api"
|
||||
"github.com/ethereum/go-ethereum/swarm/log"
|
||||
)
|
||||
|
||||
func TestConfigDump(t *testing.T) {
|
||||
|
|
@ -161,6 +162,16 @@ func TestConfigFileOverrides(t *testing.T) {
|
|||
defaultConf.HiveParams.KeepAliveInterval = 6000000000
|
||||
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second
|
||||
//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
|
||||
out, err := tomlSettings.Marshal(&defaultConf)
|
||||
if err != nil {
|
||||
|
|
@ -178,14 +189,6 @@ func TestConfigFileOverrides(t *testing.T) {
|
|||
}
|
||||
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{
|
||||
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(),
|
||||
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
|
||||
|
|
@ -372,6 +375,19 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
|
|||
defaultConf.HiveParams.KeepAliveInterval = 6000000000
|
||||
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second
|
||||
//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
|
||||
out, err := tomlSettings.Marshal(&defaultConf)
|
||||
if err != nil {
|
||||
|
|
@ -391,16 +407,6 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
|
|||
}
|
||||
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{
|
||||
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "77",
|
||||
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort,
|
||||
|
|
@ -411,6 +417,7 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
|
|||
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
|
||||
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
|
||||
}
|
||||
log.Warn("exec with flags", "f", flags)
|
||||
node.Cmd = runSwarm(t, flags...)
|
||||
node.Cmd.InputLine(testPassphrase)
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -222,7 +222,12 @@ type testNode struct {
|
|||
const testPassphrase = "swarm-test-passphrase"
|
||||
|
||||
func getTestAccount(t *testing.T, dir string) (conf *node.Config, account accounts.Account) {
|
||||
// create key
|
||||
conf, account, _ = getTestAccountWithPrivateKey(t, dir)
|
||||
return
|
||||
}
|
||||
|
||||
func getTestAccountWithPrivateKey(t *testing.T, dir string) (conf *node.Config, account accounts.Account, pk *ecdsa.PrivateKey) {
|
||||
// create kej
|
||||
conf = &node.Config{
|
||||
DataDir: dir,
|
||||
IPCPath: "bzzd.ipc",
|
||||
|
|
@ -232,17 +237,19 @@ func getTestAccount(t *testing.T, dir string) (conf *node.Config, account accoun
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
account, err = n.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore).NewAccount(testPassphrase)
|
||||
ks := n.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||
account, err = ks.NewAccount(testPassphrase)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pk = decryptStoreAccount(ks, account.Address.String(), []string{testPassphrase})
|
||||
|
||||
// use a unique IPCPath when running tests on Windows
|
||||
if runtime.GOOS == "windows" {
|
||||
conf.IPCPath = fmt.Sprintf("bzzd-%s.ipc", account.Address.String())
|
||||
}
|
||||
|
||||
return conf, account
|
||||
return conf, account, pk
|
||||
}
|
||||
|
||||
func existingTestNode(t *testing.T, dir string, bzzaccount string) *testNode {
|
||||
|
|
|
|||
|
|
@ -118,6 +118,9 @@ func (e *ExecAdapter) NewNode(config *NodeConfig) (Node, error) {
|
|||
// listen on a localhost port, which we set when we
|
||||
// initialise NodeConfig (usually a random port)
|
||||
conf.Stack.P2P.ListenAddr = fmt.Sprintf(":%d", config.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node := &ExecNode{
|
||||
ID: config.ID,
|
||||
|
|
|
|||
|
|
@ -267,14 +267,15 @@ func RegisterServices(services Services) {
|
|||
}
|
||||
}
|
||||
|
||||
// adds the host part to the configuration's ENR, signs it
|
||||
// creates and the corresponding enode object to the configuration
|
||||
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)
|
||||
enrTcpPort := enr.TCP(tcpport)
|
||||
enrTcpPort := enr.TCP(0)
|
||||
n.Record.Set(&enrTcpPort)
|
||||
enrUdpPort := enr.UDP(tcpport)
|
||||
enrUdpPort := enr.UDP(0)
|
||||
n.Record.Set(&enrUdpPort)
|
||||
|
||||
err := enode.SignV4(&n.Record, n.PrivateKey)
|
||||
|
|
|
|||
|
|
@ -47,17 +47,18 @@ type Config struct {
|
|||
*storage.FileStoreParams
|
||||
*storage.LocalStoreParams
|
||||
*network.HiveParams
|
||||
Swap *swap.LocalProfile
|
||||
Pss *pss.PssParams
|
||||
Contract common.Address
|
||||
EnsRoot common.Address
|
||||
EnsAPIs []string
|
||||
Path string
|
||||
ListenAddr string
|
||||
Port string
|
||||
PublicKey string
|
||||
BzzKey string
|
||||
Enode *enode.Node `toml:"-"`
|
||||
Swap *swap.LocalProfile
|
||||
Pss *pss.PssParams
|
||||
Contract common.Address
|
||||
EnsRoot common.Address
|
||||
EnsAPIs []string
|
||||
Path string
|
||||
ListenAddr string
|
||||
Port string
|
||||
PublicKey string
|
||||
BzzKey string
|
||||
//NodeID string
|
||||
Enode *enode.Node `toml:",omit"`
|
||||
NetworkID uint64
|
||||
SwapEnabled bool
|
||||
SyncEnabled bool
|
||||
|
|
@ -86,6 +87,7 @@ func NewConfig() (c *Config) {
|
|||
ListenAddr: DefaultHTTPListenAddr,
|
||||
Port: DefaultHTTPPort,
|
||||
Path: node.DefaultDataDir(),
|
||||
Enode: &enode.Node{},
|
||||
EnsAPIs: nil,
|
||||
EnsRoot: ens.TestNetAddress,
|
||||
NetworkID: network.DefaultNetworkID,
|
||||
|
|
|
|||
|
|
@ -171,6 +171,7 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
|||
}
|
||||
|
||||
nodeID := config.Enode.ID()
|
||||
bzzconfig.UnderlayAddr = []byte(nodeID.String())
|
||||
|
||||
syncing := stream.SyncingAutoSubscribe
|
||||
if !config.SyncEnabled || config.LightNodeEnabled {
|
||||
|
|
|
|||
Loading…
Reference in a new issue