diff --git a/config.default.json b/config.default.json index 4c9da227779f30df2dc11bc02885cf8baaf7e409..3161b48f6ff436ba5113347f95791fef5bc0cf8d 100644 --- a/config.default.json +++ b/config.default.json @@ -13,7 +13,7 @@ }, "autopeering": { "entryNodes": [ - "MRCJTGX9x+PPiT3um1DQSHXvALaUg/tCH/oQr6mliGo=@35.246.104.243:14626" + "4JXbv7u61TPfDkN63KK2UxDquuKsewZBMnBujTvXnmHK@35.246.104.243:14626" ], "port": 14626 }, diff --git a/go.mod b/go.mod index 8485376324ad4c40826bad1928e1249caa0cc371..b2a9251a20bc586c8779f6b712cd138121d90fe5 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/gobuffalo/packr/v2 v2.7.1 github.com/golang/protobuf v1.3.5 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/hive.go v0.0.0-20200525142347-543f24c486b8 + github.com/iotaledger/hive.go v0.0.0-20200608165853-97365812038c github.com/iotaledger/iota.go v1.0.0-beta.14 github.com/labstack/echo v3.3.10+incompatible github.com/labstack/gommon v0.3.0 diff --git a/go.sum b/go.sum index 77da261f6c05159eaec85f7f2946dcbcc0e3e97a..3a33c2d492e56a8a6bf00b53714f27bcf3d54c18 100644 --- a/go.sum +++ b/go.sum @@ -139,8 +139,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/iotaledger/hive.go v0.0.0-20200525142347-543f24c486b8 h1:QRVEyknRx6lCrHtk6BbBLcs16nQ8Ozbe4OSxV8XYAr8= -github.com/iotaledger/hive.go v0.0.0-20200525142347-543f24c486b8/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU= +github.com/iotaledger/hive.go v0.0.0-20200608165853-97365812038c h1:092HC7xRUSHpoXoAz2oTNWzfHDMMu3tEZsg2RF131hA= +github.com/iotaledger/hive.go v0.0.0-20200608165853-97365812038c/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index d9f60b6d878178c95941fb14421f7acef4399c15..3fc0bea3887907f6a566b5e5f6f81b7a7a55292b 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -1,7 +1,6 @@ package autopeering import ( - "encoding/base64" "errors" "fmt" "hash/fnv" @@ -21,6 +20,7 @@ import ( "github.com/iotaledger/hive.go/crypto/ed25519" "github.com/iotaledger/hive.go/identity" "github.com/iotaledger/hive.go/logger" + "github.com/mr-tron/base58" ) // autopeering constants @@ -181,7 +181,7 @@ func parseEntryNodes() (result []*peer.Peer, err error) { if len(parts) != 2 { return nil, fmt.Errorf("%w: master node parts must be 2, is %d", ErrParsingMasterNode, len(parts)) } - pubKey, err := base64.StdEncoding.DecodeString(parts[0]) + pubKey, err := base58.Decode(parts[0]) if err != nil { return nil, fmt.Errorf("%w: invalid public key: %s", ErrParsingMasterNode, err) } diff --git a/plugins/autopeering/local/local.go b/plugins/autopeering/local/local.go index 040dcc0fbaef5e393b3b603611ca097c09249cdf..b2a211c8a7d005f63e82cd3cc0393ab311577a07 100644 --- a/plugins/autopeering/local/local.go +++ b/plugins/autopeering/local/local.go @@ -1,8 +1,8 @@ package local import ( - "crypto/ed25519" "encoding/base64" + "fmt" "net" "strings" "sync" @@ -12,7 +12,9 @@ import ( "github.com/iotaledger/goshimmer/plugins/database" "github.com/iotaledger/hive.go/autopeering/peer" "github.com/iotaledger/hive.go/autopeering/peer/service" + "github.com/iotaledger/hive.go/crypto/ed25519" "github.com/iotaledger/hive.go/logger" + "github.com/mr-tron/base58" ) var ( @@ -49,7 +51,17 @@ func configureLocal() *peer.Local { // set the private key from the seed provided in the config var seed [][]byte if str := config.Node.GetString(CfgSeed); str != "" { - bytes, err := base64.StdEncoding.DecodeString(str) + var bytes []byte + var err error + + if strings.HasPrefix(str, "base58:") { + bytes, err = base58.Decode(str[7:]) + } else if strings.HasPrefix(str, "base64:") { + bytes, err = base64.StdEncoding.DecodeString(str[7:]) + } else { + err = fmt.Errorf("neither base58 nor base64 prefix provided") + } + if err != nil { log.Fatalf("Invalid %s: %s", CfgSeed, err) } @@ -65,7 +77,7 @@ func configureLocal() *peer.Local { // the private key seed of the current local can be returned the following way: // key, _ := peerDB.LocalPrivateKey() - // fmt.Println(base64.StdEncoding.EncodeToString(ed25519.PrivateKey(key).Seed())) + // fmt.Printf("Seed: base58:%s\n", key.Seed().String()) local, err := peer.NewLocal(peeringIP, services, peerDB, seed...) if err != nil { diff --git a/plugins/autopeering/local/parameters.go b/plugins/autopeering/local/parameters.go index b04ae156c9bf40e5a1de1d9db024b0655a166f22..6fa316d72d93528d134f3d72d9e9e2f7c897727c 100644 --- a/plugins/autopeering/local/parameters.go +++ b/plugins/autopeering/local/parameters.go @@ -19,5 +19,5 @@ func init() { flag.String(CfgBind, "0.0.0.0", "bind address for global services such as autopeering and gossip") flag.String(CfgExternal, "auto", "external IP address under which the node is reachable; or 'auto' to determine it automatically") flag.Int(CfgPort, 14626, "UDP port for incoming peering requests") - flag.BytesBase64(CfgSeed, nil, "private key seed used to derive the node identity; optional Base64 encoded 256-bit string") + flag.String(CfgSeed, "", "private key seed used to derive the node identity; optional base58 or base64 encoded 256-bit string. Prefix with 'base58:' or 'base64', respectively") } diff --git a/plugins/remotelog/plugin.go b/plugins/remotelog/plugin.go index fadc136e1a0f1f4ee86861822da1b4e39adcccf2..32a507786ca41e984517e8f103e64030e86b0045 100644 --- a/plugins/remotelog/plugin.go +++ b/plugins/remotelog/plugin.go @@ -5,7 +5,6 @@ package remotelog import ( - "encoding/hex" "encoding/json" "fmt" "net" @@ -78,7 +77,7 @@ func configure(plugin *node.Plugin) { conn = c if local.GetInstance() != nil { - myID = hex.EncodeToString(local.GetInstance().ID().Bytes()) + myID = local.GetInstance().ID().String() } getGitInfo() diff --git a/plugins/webapi/autopeering/plugin.go b/plugins/webapi/autopeering/plugin.go index d8647fbdc601d0a5bd169450a67997be8e82debd..0267831b63819f1495c4ae4a373cf816ac3486f2 100644 --- a/plugins/webapi/autopeering/plugin.go +++ b/plugins/webapi/autopeering/plugin.go @@ -1,7 +1,6 @@ package autopeering import ( - "encoding/base64" "net" "net/http" "strconv" @@ -27,41 +26,36 @@ func configure(plugin *node.Plugin) { // getNeighbors returns the chosen and accepted neighbors of the node func getNeighbors(c echo.Context) error { - chosen := []Neighbor{} - accepted := []Neighbor{} - knownPeers := []Neighbor{} + var chosen []Neighbor + var accepted []Neighbor + var knownPeers []Neighbor if c.QueryParam("known") == "1" { - for _, peer := range autopeering.Discovery().GetVerifiedPeers() { - n := Neighbor{ - ID: peer.ID().String(), - PublicKey: base64.StdEncoding.EncodeToString(peer.PublicKey().Bytes()), - } - n.Services = getServices(peer) - knownPeers = append(knownPeers, n) + for _, p := range autopeering.Discovery().GetVerifiedPeers() { + knownPeers = append(knownPeers, createNeighborFromPeer(p)) } } - for _, peer := range autopeering.Selection().GetOutgoingNeighbors() { - n := Neighbor{ - ID: peer.ID().String(), - PublicKey: base64.StdEncoding.EncodeToString(peer.PublicKey().Bytes()), - } - n.Services = getServices(peer) - chosen = append(chosen, n) + for _, p := range autopeering.Selection().GetOutgoingNeighbors() { + chosen = append(chosen, createNeighborFromPeer(p)) } - for _, peer := range autopeering.Selection().GetIncomingNeighbors() { - n := Neighbor{ - ID: peer.ID().String(), - PublicKey: base64.StdEncoding.EncodeToString(peer.PublicKey().Bytes()), - } - n.Services = getServices(peer) - accepted = append(accepted, n) + for _, p := range autopeering.Selection().GetIncomingNeighbors() { + accepted = append(accepted, createNeighborFromPeer(p)) } return c.JSON(http.StatusOK, Response{KnownPeers: knownPeers, Chosen: chosen, Accepted: accepted}) } +func createNeighborFromPeer(p *peer.Peer) Neighbor { + n := Neighbor{ + ID: p.ID().String(), + PublicKey: p.PublicKey().String(), + } + n.Services = getServices(p) + + return n +} + // Response contains information of the autopeering. type Response struct { KnownPeers []Neighbor `json:"known,omitempty"` diff --git a/plugins/webapi/info/plugin.go b/plugins/webapi/info/plugin.go index b6bf4eb3901b6d98e64a39d1d3599e0fbc5f9c2d..5dfc6f159b17a0d8d5923c58e10bdda422f16849 100644 --- a/plugins/webapi/info/plugin.go +++ b/plugins/webapi/info/plugin.go @@ -86,7 +86,7 @@ type Response struct { Version string `json:"version,omitempty"` // whether the node is synchronized Synced bool `json:"synced"` - // identity ID of the node encoded in hex and truncated to its first 8 bytes + // identity ID of the node encoded in base58 and truncated to its first 8 bytes IdentityID string `json:"identityID,omitempty"` // public key of the node encoded in base58 PublicKey string `json:"publickey,omitempty"` diff --git a/tools/docker-network/docker-compose.yml b/tools/docker-network/docker-compose.yml index 510364e38fdc19d142c25302361e9e5691ea7414..f275ec22a897811f426f531e9036d079c09869d6 100644 --- a/tools/docker-network/docker-compose.yml +++ b/tools/docker-network/docker-compose.yml @@ -8,7 +8,7 @@ services: command: > --config-dir=/tmp --database.directory=/tmp/mainnetdb - --autopeering.seed=uuDCzsjyLNQ17/7fWKPNMYmr4IWuaVRf7qKqRL0v/6c= + --autopeering.seed=base58:8kPPCqaJFAt8BJtx6qw5PN8bKEM2XKXor6PxkmHf6bcr --autopeering.entryNodes= --analysis.server.bindAddress=0.0.0.0:1888 --analysis.dashboard.bindAddress=0.0.0.0:9000 diff --git a/tools/integration-tests/tester/framework/docker.go b/tools/integration-tests/tester/framework/docker.go index 37ab6594cc22894046caa268535e7b520dc4dede..a5c2cb2493fc6732b013f8d608caf8d8003e2926 100644 --- a/tools/integration-tests/tester/framework/docker.go +++ b/tools/integration-tests/tester/framework/docker.go @@ -63,7 +63,7 @@ func (d *DockerContainer) CreateGoShimmerEntryNode(name string, seed string) err "--logger.level=debug", fmt.Sprintf("--node.disablePlugins=%s", disabledPluginsEntryNode), "--autopeering.entryNodes=", - fmt.Sprintf("--autopeering.seed=%s", seed), + fmt.Sprintf("--autopeering.seed=base58:%s", seed), }, } @@ -90,7 +90,7 @@ func (d *DockerContainer) CreateGoShimmerPeer(config GoShimmerConfig) error { }()), fmt.Sprintf("--bootstrap.initialIssuance.timePeriodSec=%d", config.BootstrapInitialIssuanceTimePeriodSec), "--webapi.bindAddress=0.0.0.0:8080", - fmt.Sprintf("--autopeering.seed=%s", config.Seed), + fmt.Sprintf("--autopeering.seed=base58:%s", config.Seed), fmt.Sprintf("--autopeering.entryNodes=%s@%s:14626", config.EntryNodePublicKey, config.EntryNodeHost), fmt.Sprintf("--drng.instanceId=%d", config.DRNGInstance), fmt.Sprintf("--drng.threshold=%d", config.DRNGThreshold), diff --git a/tools/integration-tests/tester/framework/drngnetwork.go b/tools/integration-tests/tester/framework/drngnetwork.go index 4169c37ecee4897c9a105c8962a9f53aa0d89aca..9df42cdb73c4b856cc828e13095c72fc1b20a318 100644 --- a/tools/integration-tests/tester/framework/drngnetwork.go +++ b/tools/integration-tests/tester/framework/drngnetwork.go @@ -7,7 +7,7 @@ import ( "time" "github.com/docker/docker/client" - hive_ed25519 "github.com/iotaledger/hive.go/crypto/ed25519" + "github.com/iotaledger/hive.go/crypto/ed25519" "github.com/iotaledger/hive.go/identity" ) @@ -31,7 +31,7 @@ func newDRNGNetwork(dockerClient *client.Client, name string, tester *DockerCont } // CreatePeer creates a new peer/GoShimmer node in the network and returns it. -func (n *DRNGNetwork) CreatePeer(c GoShimmerConfig, publicKey hive_ed25519.PublicKey) (*Peer, error) { +func (n *DRNGNetwork) CreatePeer(c GoShimmerConfig, publicKey ed25519.PublicKey) (*Peer, error) { name := n.network.namePrefix(fmt.Sprintf("%s%d", containerNameReplica, len(n.network.peers))) config := c diff --git a/tools/integration-tests/tester/framework/framework.go b/tools/integration-tests/tester/framework/framework.go index 55f822869e8d6a3311b851363813695275a131ff..449c2dc6d07993d3bc722f342c21731e0c6252f0 100644 --- a/tools/integration-tests/tester/framework/framework.go +++ b/tools/integration-tests/tester/framework/framework.go @@ -4,8 +4,6 @@ package framework import ( - "crypto/ed25519" - "encoding/base64" "encoding/hex" "fmt" "strings" @@ -14,7 +12,7 @@ import ( "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/client" - hive_ed25519 "github.com/iotaledger/hive.go/crypto/ed25519" + "github.com/iotaledger/hive.go/crypto/ed25519" ) var ( @@ -210,12 +208,12 @@ func (f *Framework) CreateDRNGNetwork(name string, members, peers, minimumNeighb } // create GoShimmer identities - pubKeys := make([]hive_ed25519.PublicKey, peers) - privKeys := make([]hive_ed25519.PrivateKey, peers) + pubKeys := make([]ed25519.PublicKey, peers) + privKeys := make([]ed25519.PrivateKey, peers) var drngCommittee string for i := 0; i < peers; i++ { - pubKeys[i], privKeys[i], err = hive_ed25519.GenerateKey() + pubKeys[i], privKeys[i], err = ed25519.GenerateKey() if err != nil { return nil, err } @@ -238,7 +236,7 @@ func (f *Framework) CreateDRNGNetwork(name string, members, peers, minimumNeighb // create peers/GoShimmer nodes for i := 0; i < peers; i++ { config.Bootstrap = i == 0 - config.Seed = base64.StdEncoding.EncodeToString(ed25519.PrivateKey(privKeys[i].Bytes()).Seed()) + config.Seed = privKeys[i].Seed().String() if _, err = drng.CreatePeer(config, pubKeys[i]); err != nil { return nil, err } diff --git a/tools/integration-tests/tester/framework/network.go b/tools/integration-tests/tester/framework/network.go index f8efc9798779ab2f811c4aeb540c0fe88bb3534b..c115fcb5a364e57a59183f05ae6b2cedc170c817 100644 --- a/tools/integration-tests/tester/framework/network.go +++ b/tools/integration-tests/tester/framework/network.go @@ -2,8 +2,6 @@ package framework import ( "context" - "crypto/ed25519" - "encoding/base64" "fmt" "log" "math/rand" @@ -11,7 +9,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/client" - hive_ed25519 "github.com/iotaledger/hive.go/crypto/ed25519" + "github.com/iotaledger/hive.go/crypto/ed25519" "github.com/iotaledger/hive.go/identity" ) @@ -57,13 +55,13 @@ func newNetwork(dockerClient *client.Client, name string, tester *DockerContaine // createEntryNode creates the network's entry node. func (n *Network) createEntryNode() error { // create identity - publicKey, privateKey, err := hive_ed25519.GenerateKey() + publicKey, privateKey, err := ed25519.GenerateKey() if err != nil { return err } n.entryNodeIdentity = identity.New(publicKey) - seed := base64.StdEncoding.EncodeToString(ed25519.PrivateKey(privateKey.Bytes()).Seed()) + seed := privateKey.Seed().String() // create entry node container n.entryNode = NewDockerContainer(n.dockerClient) @@ -89,11 +87,11 @@ func (n *Network) CreatePeer(c GoShimmerConfig) (*Peer, error) { name := n.namePrefix(fmt.Sprintf("%s%d", containerNameReplica, len(n.peers))) // create identity - publicKey, privateKey, err := hive_ed25519.GenerateKey() + publicKey, privateKey, err := ed25519.GenerateKey() if err != nil { return nil, err } - seed := base64.StdEncoding.EncodeToString(ed25519.PrivateKey(privateKey.Bytes()).Seed()) + seed := privateKey.Seed().String() config := c config.Name = name @@ -260,9 +258,9 @@ func (n *Network) namePrefix(suffix string) string { return fmt.Sprintf("%s-%s", n.name, suffix) } -// entryNodePublicKey returns the entry node's public key encoded as base64 +// entryNodePublicKey returns the entry node's public key encoded as base58 func (n *Network) entryNodePublicKey() string { - return base64.StdEncoding.EncodeToString(n.entryNodeIdentity.PublicKey().Bytes()) + return n.entryNodeIdentity.PublicKey().String() } // Peers returns all available peers in the network. diff --git a/tools/integration-tests/tester/go.mod b/tools/integration-tests/tester/go.mod index a9a1a0e32432ad6acc597375b0a0786f61032841..f7331d4533c1f264623dabe875266f2de77de786 100644 --- a/tools/integration-tests/tester/go.mod +++ b/tools/integration-tests/tester/go.mod @@ -10,7 +10,7 @@ require ( github.com/docker/go-units v0.4.0 // indirect github.com/drand/drand v0.8.1 github.com/iotaledger/goshimmer v0.1.3 - github.com/iotaledger/hive.go v0.0.0-20200525142347-543f24c486b8 + github.com/iotaledger/hive.go v0.0.0-20200608165853-97365812038c github.com/opencontainers/go-digest v1.0.0-rc1 // indirect github.com/stretchr/testify v1.5.1 ) diff --git a/tools/integration-tests/tester/go.sum b/tools/integration-tests/tester/go.sum index 2214754956637a299b0be8e15f83ff6b82fd2520..aadb3c43a10a2dd3942d3b8016d3310bed1af26b 100644 --- a/tools/integration-tests/tester/go.sum +++ b/tools/integration-tests/tester/go.sum @@ -138,8 +138,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/iotaledger/hive.go v0.0.0-20200525142347-543f24c486b8 h1:QRVEyknRx6lCrHtk6BbBLcs16nQ8Ozbe4OSxV8XYAr8= -github.com/iotaledger/hive.go v0.0.0-20200525142347-543f24c486b8/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU= +github.com/iotaledger/hive.go v0.0.0-20200608165853-97365812038c h1:092HC7xRUSHpoXoAz2oTNWzfHDMMu3tEZsg2RF131hA= +github.com/iotaledger/hive.go v0.0.0-20200608165853-97365812038c/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=