container: remove unnecessary network settings
This commit is contained in:
parent
2c403967a6
commit
e0eb79520e
|
@ -19,18 +19,13 @@ package container
|
|||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/phayes/freeport"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
|
||||
"github.com/getamis/istanbul-tools/genesis"
|
||||
)
|
||||
|
@ -51,7 +46,6 @@ func NewBlockchain(numOfValidators int, options ...Option) (bc *blockchain) {
|
|||
log.Fatalf("Cannot connect to Docker daemon, err: %v", err)
|
||||
}
|
||||
|
||||
bc.setupNetwork()
|
||||
keys, addrs := generateKeys(numOfValidators)
|
||||
bc.setupGenesis(addrs)
|
||||
bc.setupValidators(keys, options...)
|
||||
|
@ -62,24 +56,16 @@ func NewBlockchain(numOfValidators int, options ...Option) (bc *blockchain) {
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
type blockchain struct {
|
||||
dockerClient *client.Client
|
||||
dockerNetworkID string
|
||||
netClass string
|
||||
genesisFile string
|
||||
validators []Ethereum
|
||||
dockerClient *client.Client
|
||||
genesisFile string
|
||||
validators []Ethereum
|
||||
}
|
||||
|
||||
func (bc *blockchain) Start() error {
|
||||
for i, v := range bc.validators {
|
||||
for _, v := range bc.validators {
|
||||
if err := v.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := bc.dockerClient.NetworkConnect(context.Background(), bc.dockerNetworkID, v.ContainerID(), &network.EndpointSettings{
|
||||
IPAddress: fmt.Sprintf(bc.netClass+".%d", i+1),
|
||||
}); err != nil {
|
||||
log.Printf("Failed to connect to network '%s', %v", bc.dockerNetworkID, err)
|
||||
}
|
||||
}
|
||||
|
||||
return bc.connectAll()
|
||||
|
@ -97,8 +83,6 @@ func (bc *blockchain) Stop() error {
|
|||
|
||||
func (bc *blockchain) Finalize() {
|
||||
os.RemoveAll(filepath.Dir(bc.genesisFile))
|
||||
|
||||
bc.dockerClient.NetworkRemove(context.Background(), bc.dockerNetworkID)
|
||||
}
|
||||
|
||||
func (bc *blockchain) Validators() []Ethereum {
|
||||
|
@ -107,26 +91,6 @@ func (bc *blockchain) Validators() []Ethereum {
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
func (bc *blockchain) setupNetwork() {
|
||||
name := "net" + uuid.NewV4().String()
|
||||
bc.netClass = fmt.Sprintf("172.16.%d", rand.Uint32()%255)
|
||||
resp, err := bc.dockerClient.NetworkCreate(context.Background(), name, types.NetworkCreate{
|
||||
IPAM: &network.IPAM{
|
||||
Config: []network.IPAMConfig{
|
||||
network.IPAMConfig{
|
||||
Subnet: bc.netClass + ".0/24",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Failed to setup blockchain network,", err)
|
||||
}
|
||||
|
||||
bc.dockerNetworkID = resp.ID
|
||||
}
|
||||
|
||||
func (bc *blockchain) setupGenesis(addrs []common.Address) {
|
||||
setupDir, err := generateRandomDir()
|
||||
if err != nil {
|
||||
|
|
|
@ -102,7 +102,6 @@ type ethereum struct {
|
|||
wsPort string
|
||||
hostName string
|
||||
containerID string
|
||||
ipAddress string
|
||||
node *discover.Node
|
||||
|
||||
imageRepository string
|
||||
|
@ -265,7 +264,6 @@ func (eth *ethereum) Start() error {
|
|||
return err
|
||||
}
|
||||
|
||||
eth.ipAddress = containerJSON.NetworkSettings.IPAddress
|
||||
if eth.key != nil {
|
||||
eth.node = discover.NewNode(
|
||||
discover.PubkeyID(ð.key.PublicKey),
|
||||
|
|
|
@ -20,10 +20,8 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
@ -36,10 +34,6 @@ const (
|
|||
nodekeyFileName = "nodekey"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
||||
func generateRandomDir() (string, error) {
|
||||
err := os.MkdirAll(filepath.Join(defaultLocalDir), 0700)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue