mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
swarm/pss, pot: Remove redundant conversion, go1.7 compat
This commit is contained in:
parent
63a44a80d6
commit
068b0b6e6c
3 changed files with 80 additions and 79 deletions
|
|
@ -105,7 +105,7 @@ func posProximity(one, other Address, pos int) (ret int, eq bool) {
|
||||||
if one[i] == other[i] {
|
if one[i] == other[i] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
oxo := uint8(one[i] ^ other[i])
|
oxo := one[i] ^ other[i]
|
||||||
start := 0
|
start := 0
|
||||||
if i == pos/8 {
|
if i == pos/8 {
|
||||||
start = pos % 8
|
start = pos % 8
|
||||||
|
|
|
||||||
|
|
@ -463,3 +463,82 @@ outer:
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// symmetric send performance with varying message sizes
|
||||||
|
func BenchmarkSymkeySend(b *testing.B) {
|
||||||
|
b.Run(fmt.Sprintf("%d", 256), benchmarkSymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024), benchmarkSymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024*1024), benchmarkSymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024*1024*10), benchmarkSymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024*1024*100), benchmarkSymKeySend)
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkSymKeySend(b *testing.B) {
|
||||||
|
msgsizestring := strings.Split(b.Name(), "/")
|
||||||
|
if len(msgsizestring) != 2 {
|
||||||
|
b.Fatalf("benchmark called without msgsize param")
|
||||||
|
}
|
||||||
|
msgsize, err := strconv.ParseInt(msgsizestring[1], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("benchmark called with invalid msgsize param '%s': %v", msgsizestring[1], err)
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
|
defer cancel()
|
||||||
|
keys, err := wapi.NewKeyPair(ctx)
|
||||||
|
privkey, err := w.GetPrivateKey(keys)
|
||||||
|
ps := newTestPss(privkey, nil, nil)
|
||||||
|
msg := make([]byte, msgsize)
|
||||||
|
rand.Read(msg)
|
||||||
|
topic := BytesToTopic([]byte("foo"))
|
||||||
|
to := make(PssAddress, 32)
|
||||||
|
copy(to[:], network.RandomAddr().Over())
|
||||||
|
symkeyid, err := ps.generateSymmetricKey(topic, &to, true)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not generate symkey: %v", err)
|
||||||
|
}
|
||||||
|
symkey, err := ps.w.GetSymKey(symkeyid)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not retrieve symkey: %v", err)
|
||||||
|
}
|
||||||
|
ps.SetSymmetricKey(symkey, topic, &to, false)
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ps.SendSym(symkeyid, topic, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// asymmetric send performance with varying message sizes
|
||||||
|
func BenchmarkAsymkeySend(b *testing.B) {
|
||||||
|
b.Run(fmt.Sprintf("%d", 256), benchmarkAsymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024), benchmarkAsymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024*1024), benchmarkAsymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024*1024*10), benchmarkAsymKeySend)
|
||||||
|
b.Run(fmt.Sprintf("%d", 1024*1024*100), benchmarkAsymKeySend)
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkAsymKeySend(b *testing.B) {
|
||||||
|
msgsizestring := strings.Split(b.Name(), "/")
|
||||||
|
if len(msgsizestring) != 2 {
|
||||||
|
b.Fatalf("benchmark called without msgsize param")
|
||||||
|
}
|
||||||
|
msgsize, err := strconv.ParseInt(msgsizestring[1], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("benchmark called with invalid msgsize param '%s': %v", msgsizestring[1], err)
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
|
defer cancel()
|
||||||
|
keys, err := wapi.NewKeyPair(ctx)
|
||||||
|
privkey, err := w.GetPrivateKey(keys)
|
||||||
|
ps := newTestPss(privkey, nil, nil)
|
||||||
|
msg := make([]byte, msgsize)
|
||||||
|
rand.Read(msg)
|
||||||
|
topic := BytesToTopic([]byte("foo"))
|
||||||
|
to := make(PssAddress, 32)
|
||||||
|
copy(to[:], network.RandomAddr().Over())
|
||||||
|
ps.SetPeerPublicKey(&privkey.PublicKey, topic, &to)
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ps.SendAsym(common.ToHex(crypto.FromECDSAPub(&privkey.PublicKey)), topic, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -392,84 +392,6 @@ func TestMismatch(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// symmetric send performance with varying message sizes
|
|
||||||
func BenchmarkSymkeySend(b *testing.B) {
|
|
||||||
b.Run(fmt.Sprintf("%d", 256), benchmarkSymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024), benchmarkSymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024*1024), benchmarkSymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024*1024*10), benchmarkSymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024*1024*100), benchmarkSymKeySend)
|
|
||||||
}
|
|
||||||
|
|
||||||
func benchmarkSymKeySend(b *testing.B) {
|
|
||||||
msgsizestring := strings.Split(b.Name(), "/")
|
|
||||||
if len(msgsizestring) != 2 {
|
|
||||||
b.Fatalf("benchmark called without msgsize param")
|
|
||||||
}
|
|
||||||
msgsize, err := strconv.ParseInt(msgsizestring[1], 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("benchmark called with invalid msgsize param '%s': %v", msgsizestring[1], err)
|
|
||||||
}
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
|
||||||
defer cancel()
|
|
||||||
keys, err := wapi.NewKeyPair(ctx)
|
|
||||||
privkey, err := w.GetPrivateKey(keys)
|
|
||||||
ps := newTestPss(privkey, nil, nil)
|
|
||||||
msg := make([]byte, msgsize)
|
|
||||||
rand.Read(msg)
|
|
||||||
topic := BytesToTopic([]byte("foo"))
|
|
||||||
to := make(PssAddress, 32)
|
|
||||||
copy(to[:], network.RandomAddr().Over())
|
|
||||||
symkeyid, err := ps.generateSymmetricKey(topic, &to, true)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not generate symkey: %v", err)
|
|
||||||
}
|
|
||||||
symkey, err := ps.w.GetSymKey(symkeyid)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not retrieve symkey: %v", err)
|
|
||||||
}
|
|
||||||
ps.SetSymmetricKey(symkey, topic, &to, false)
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
ps.SendSym(symkeyid, topic, msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// asymmetric send performance with varying message sizes
|
|
||||||
func BenchmarkAsymkeySend(b *testing.B) {
|
|
||||||
b.Run(fmt.Sprintf("%d", 256), benchmarkAsymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024), benchmarkAsymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024*1024), benchmarkAsymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024*1024*10), benchmarkAsymKeySend)
|
|
||||||
b.Run(fmt.Sprintf("%d", 1024*1024*100), benchmarkAsymKeySend)
|
|
||||||
}
|
|
||||||
|
|
||||||
func benchmarkAsymKeySend(b *testing.B) {
|
|
||||||
msgsizestring := strings.Split(b.Name(), "/")
|
|
||||||
if len(msgsizestring) != 2 {
|
|
||||||
b.Fatalf("benchmark called without msgsize param")
|
|
||||||
}
|
|
||||||
msgsize, err := strconv.ParseInt(msgsizestring[1], 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("benchmark called with invalid msgsize param '%s': %v", msgsizestring[1], err)
|
|
||||||
}
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
|
||||||
defer cancel()
|
|
||||||
keys, err := wapi.NewKeyPair(ctx)
|
|
||||||
privkey, err := w.GetPrivateKey(keys)
|
|
||||||
ps := newTestPss(privkey, nil, nil)
|
|
||||||
msg := make([]byte, msgsize)
|
|
||||||
rand.Read(msg)
|
|
||||||
topic := BytesToTopic([]byte("foo"))
|
|
||||||
to := make(PssAddress, 32)
|
|
||||||
copy(to[:], network.RandomAddr().Over())
|
|
||||||
ps.SetPeerPublicKey(&privkey.PublicKey, topic, &to)
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
ps.SendAsym(common.ToHex(crypto.FromECDSAPub(&privkey.PublicKey)), topic, msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func BenchmarkSymkeyBruteforceChangeaddr(b *testing.B) {
|
func BenchmarkSymkeyBruteforceChangeaddr(b *testing.B) {
|
||||||
for i := 100; i < 100000; i = i * 10 {
|
for i := 100; i < 100000; i = i * 10 {
|
||||||
for j := 32; j < 10000; j = j * 8 {
|
for j := 32; j < 10000; j = j * 8 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue