Skip to content

Commit

Permalink
perf: using ECDSA to generate node id
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiaxun authored and liujiaxun2018 committed Jul 2, 2019
1 parent 036c061 commit 75d527b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
20 changes: 10 additions & 10 deletions core/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"crypto/rand"
"encoding/base64"
"errors"
"net/http"
"io/ioutil"
"fmt"
"io/ioutil"
"net/http"

"go.uber.org/fx"

Expand Down Expand Up @@ -119,7 +119,7 @@ func (cfg *BuildCfg) options(ctx context.Context) (fx.Option, *cfg.Config) {

address, err := externalIP()
if err == nil {
if ! contains(conf.Addresses.Announce, address) {
if !contains(conf.Addresses.Announce, address) {
conf.Addresses.Announce = append(conf.Addresses.Announce, address)
cfg.Repo.SetConfig(conf)
}
Expand All @@ -134,12 +134,12 @@ func (cfg *BuildCfg) options(ctx context.Context) (fx.Option, *cfg.Config) {
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
for _, a := range s {
if a == e {
return true
}
}
return false
}

func externalIP() (string, error) {
Expand All @@ -164,7 +164,7 @@ func externalIP() (string, error) {

func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
c := cfg.Config{}
priv, pub, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, rand.Reader)
priv, pub, err := ci.GenerateKeyPairWithReader(ci.ECDSA, 1024, rand.Reader)
if err != nil {
return nil, err
}
Expand Down
48 changes: 37 additions & 11 deletions patches/go-ipfs-config-v0.0.3-init.go.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
--- [email protected]/init.go 2019-06-10 11:17:01.000000000 -0700
+++ /tmp/go-ipfs-config/init.go 2019-06-10 15:52:58.000000000 -0700
@@ -49,8 +49,8 @@
--- /Users/tron/work/go/pkg/mod/github.com/ipfs/[email protected]/init.go 2019-06-27 12:07:43.000000000 +0800
+++ init.go 2019-06-27 12:17:17.000000000 +0800
@@ -6,6 +6,7 @@
"fmt"
"io"
"time"
+ "os"

// setup the node mount points.
Mounts: Mounts{
- IPFS: "/ipfs",
- IPNS: "/ipns",
+ IPFS: "/btfs",
+ IPNS: "/btns",
},
ci "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
@@ -156,10 +157,24 @@
return ident, errors.New("bitsize less than 1024 is considered unsafe")
}

- fmt.Fprintf(out, "generating %v-bit RSA keypair...", nbits)
- sk, pk, err := ci.GenerateKeyPair(ci.RSA, nbits)
- if err != nil {
- return ident, err
+ var (
+ sk ci.PrivKey
+ pk ci.PubKey
+ err error
+ )
+
+ if os.Getenv("RSA_FLG") == "TRUE" {
+ fmt.Fprintf(out, "generating %v-bit RSA keypair...", nbits)
+ sk, pk, err = ci.GenerateKeyPair(ci.ECDSA, nbits)
+ if err != nil {
+ return ident, err
+ }
+ } else {
+ fmt.Fprintf(out, "generating %v-bit ECDSA keypair...", nbits)
+ sk, pk, err = ci.GenerateKeyPair(ci.ECDSA, nbits)
+ if err != nil {
+ return ident, err
+ }
}
fmt.Fprintf(out, "done\n")

Ipns: Ipns{
7 changes: 7 additions & 0 deletions patching.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ patchdir=$GOPATH/pkg/mod/github.com/ipfs/[email protected]
chmod -R 777 $patchdir
if ! patch -R -s -f --dry-run $patchdir/record.go < ./patches/go-ipns-v.0.0.1-record.go.patch 1>/dev/null; then
patch $patchdir/record.go < ./patches/go-ipns-v.0.0.1-record.go.patch;
fi

# patching $GOPATH/pkg/mod/github.com/ipfs/[email protected]
patchdir=$GOPATH/pkg/mod/github.com/ipfs/[email protected]
chmod -R 777 $patchdir
if ! patch -R -s -f --dry-run $patchdir/init.go < ./patches/go-ipfs-config-v0.0.3-init.go.patch 1>/dev/null; then
patch $patchdir/init.go < ./patches/go-ipfs-config-v0.0.3-init.go.patch;
fi

0 comments on commit 75d527b

Please sign in to comment.