mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
p2p, pot, swarm/pss, swarm/storage, swarm: De-linting, versionfilter
This commit is contained in:
parent
3791497eeb
commit
833f2f9323
9 changed files with 191 additions and 208 deletions
|
|
@ -55,7 +55,7 @@ func TestSocketPipe(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(msg, out) != 0 {
|
if !bytes.Equal(msg, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", msg, out)
|
t.Fatalf("expected %#v, got %#v", msg, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ func TestSocketPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(out, []byte(`ping`)) == 0 {
|
if bytes.Equal(out, []byte(`ping`)) {
|
||||||
msg := []byte(`pong`)
|
msg := []byte(`pong`)
|
||||||
_, err := c2.Write(msg)
|
_, err := c2.Write(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -114,7 +114,7 @@ func TestSocketPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(out, expected) != 0 {
|
if !bytes.Equal(out, expected) {
|
||||||
t.Fatalf("expected %#v, got %#v", expected, out)
|
t.Fatalf("expected %#v, got %#v", expected, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +160,7 @@ func TestTcpPipe(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(msg, out) != 0 {
|
if !bytes.Equal(msg, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", msg, out)
|
t.Fatalf("expected %#v, got %#v", msg, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -203,7 +203,7 @@ func TestTcpPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", out, expected)
|
t.Fatalf("expected %#v, got %#v", out, expected)
|
||||||
} else {
|
} else {
|
||||||
msg := []byte(fmt.Sprintf("pong %02d", i))
|
msg := []byte(fmt.Sprintf("pong %02d", i))
|
||||||
|
|
@ -223,7 +223,7 @@ func TestTcpPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", out, expected)
|
t.Fatalf("expected %#v, got %#v", out, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +271,7 @@ func TestNetPipe(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(msg, out) != 0 {
|
if !bytes.Equal(msg, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", msg, out)
|
t.Fatalf("expected %#v, got %#v", msg, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -323,7 +323,7 @@ func TestNetPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", expected, out)
|
t.Fatalf("expected %#v, got %#v", expected, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -341,7 +341,7 @@ func TestNetPipeBidirections(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(expected, out) != 0 {
|
if !bytes.Equal(expected, out) {
|
||||||
t.Fatalf("expected %#v, got %#v", expected, out)
|
t.Fatalf("expected %#v, got %#v", expected, out)
|
||||||
} else {
|
} else {
|
||||||
msg := []byte(fmt.Sprintf(pongTemplate, i))
|
msg := []byte(fmt.Sprintf(pongTemplate, i))
|
||||||
|
|
|
||||||
|
|
@ -271,10 +271,7 @@ func testPotEachNeighbour(n *Pot, pof Pof, val Val, expCount int, fs ...func(Val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
if count == expCount {
|
return count == expCount
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
if err == nil && count < expCount {
|
if err == nil && count < expCount {
|
||||||
return fmt.Errorf("not enough neighbours returned, expected %v, got %v", expCount, count)
|
return fmt.Errorf("not enough neighbours returned, expected %v, got %v", expCount, count)
|
||||||
|
|
@ -558,10 +555,7 @@ func benchmarkEachNeighbourSync(t *testing.B, max, count int, d time.Duration) {
|
||||||
n.EachNeighbour(val, pof, func(v Val, po int) bool {
|
n.EachNeighbour(val, pof, func(v Val, po int) bool {
|
||||||
time.Sleep(d)
|
time.Sleep(d)
|
||||||
m++
|
m++
|
||||||
if m == count {
|
return m == count
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
t.StopTimer()
|
t.StopTimer()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//-build go1.7
|
// +build go1.8
|
||||||
|
|
||||||
package pss
|
package pss
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//-build go1.7
|
// +build go1.8
|
||||||
|
|
||||||
package pss
|
package pss
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,9 +215,7 @@ func (self *Pss) APIs() []rpc.API {
|
||||||
Public: true,
|
Public: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, auxapi := range self.auxAPIs {
|
apis = append(apis, self.auxAPIs...)
|
||||||
apis = append(apis, auxapi)
|
|
||||||
}
|
|
||||||
return apis
|
return apis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -388,7 +386,7 @@ func (self *Pss) SetPeerPublicKey(pubkey *ecdsa.PublicKey, topic Topic, address
|
||||||
address: address,
|
address: address,
|
||||||
}
|
}
|
||||||
self.pubKeyPoolMu.Lock()
|
self.pubKeyPoolMu.Lock()
|
||||||
if _, ok := self.pubKeyPool[pubkeyid]; ok == false {
|
if _, ok := self.pubKeyPool[pubkeyid]; !ok {
|
||||||
self.pubKeyPool[pubkeyid] = make(map[Topic]*pssPeer)
|
self.pubKeyPool[pubkeyid] = make(map[Topic]*pssPeer)
|
||||||
}
|
}
|
||||||
self.pubKeyPool[pubkeyid][topic] = psp
|
self.pubKeyPool[pubkeyid][topic] = psp
|
||||||
|
|
@ -537,7 +535,7 @@ func (self *Pss) cleanKeys() (count int) {
|
||||||
match = true
|
match = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match == false {
|
if !match {
|
||||||
expiredtopics = append(expiredtopics, topic)
|
expiredtopics = append(expiredtopics, topic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//-build go17
|
// +build go1.8
|
||||||
package pss
|
package pss
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -19,11 +19,13 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/swarm/network"
|
"github.com/ethereum/go-ethereum/swarm/network"
|
||||||
|
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// send symmetrically encrypted message between two directly connected peers
|
// send symmetrically encrypted message between two directly connected peers
|
||||||
|
|
@ -361,7 +363,7 @@ func testNetwork(t *testing.T) {
|
||||||
select {
|
select {
|
||||||
case recvmsg := <-msgC:
|
case recvmsg := <-msgC:
|
||||||
idx, _ := binary.Uvarint(recvmsg.Msg)
|
idx, _ := binary.Uvarint(recvmsg.Msg)
|
||||||
if recvmsgs[idx] == false {
|
if !recvmsgs[idx] {
|
||||||
log.Debug("msg recv", "idx", idx, "id", id)
|
log.Debug("msg recv", "idx", idx, "id", id)
|
||||||
recvmsgs[idx] = true
|
recvmsgs[idx] = true
|
||||||
trigger <- id
|
trigger <- id
|
||||||
|
|
@ -544,3 +546,169 @@ func benchmarkAsymKeySend(b *testing.B) {
|
||||||
ps.SendAsym(common.ToHex(crypto.FromECDSAPub(&privkey.PublicKey)), topic, msg)
|
ps.SendAsym(common.ToHex(crypto.FromECDSAPub(&privkey.PublicKey)), topic, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkSymkeyBruteforceChangeaddr(b *testing.B) {
|
||||||
|
for i := 100; i < 100000; i = i * 10 {
|
||||||
|
for j := 32; j < 10000; j = j * 8 {
|
||||||
|
b.Run(fmt.Sprintf("%d/%d", i, j), benchmarkSymkeyBruteforceChangeaddr)
|
||||||
|
}
|
||||||
|
//b.Run(fmt.Sprintf("%d", i), benchmarkSymkeyBruteforceChangeaddr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// decrypt performance using symkey cache, worst case
|
||||||
|
// (decrypt key always last in cache)
|
||||||
|
func benchmarkSymkeyBruteforceChangeaddr(b *testing.B) {
|
||||||
|
keycountstring := strings.Split(b.Name(), "/")
|
||||||
|
cachesize := int64(0)
|
||||||
|
var ps *Pss
|
||||||
|
if len(keycountstring) < 2 {
|
||||||
|
b.Fatalf("benchmark called without count param")
|
||||||
|
}
|
||||||
|
keycount, err := strconv.ParseInt(keycountstring[1], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("benchmark called with invalid count param '%s': %v", keycountstring[1], err)
|
||||||
|
}
|
||||||
|
if len(keycountstring) == 3 {
|
||||||
|
cachesize, err = strconv.ParseInt(keycountstring[2], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("benchmark called with invalid cachesize '%s': %v", keycountstring[2], err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pssmsgs := make([]*PssMsg, 0, keycount)
|
||||||
|
var keyid string
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
|
defer cancel()
|
||||||
|
keys, err := wapi.NewKeyPair(ctx)
|
||||||
|
privkey, err := w.GetPrivateKey(keys)
|
||||||
|
if cachesize > 0 {
|
||||||
|
ps = newTestPss(privkey, nil, &PssParams{SymKeyCacheCapacity: int(cachesize)})
|
||||||
|
} else {
|
||||||
|
ps = newTestPss(privkey, nil, nil)
|
||||||
|
}
|
||||||
|
topic := BytesToTopic([]byte("foo"))
|
||||||
|
for i := 0; i < int(keycount); i++ {
|
||||||
|
to := make(PssAddress, 32)
|
||||||
|
copy(to[:], network.RandomAddr().Over())
|
||||||
|
keyid, err = ps.generateSymmetricKey(topic, &to, true)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("cant generate symkey #%d: %v", i, err)
|
||||||
|
}
|
||||||
|
symkey, err := ps.w.GetSymKey(keyid)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not retrieve symkey %s: %v", keyid, err)
|
||||||
|
}
|
||||||
|
wparams := &whisper.MessageParams{
|
||||||
|
TTL: defaultWhisperTTL,
|
||||||
|
KeySym: symkey,
|
||||||
|
Topic: whisper.TopicType(topic),
|
||||||
|
WorkTime: defaultWhisperWorkTime,
|
||||||
|
PoW: defaultWhisperPoW,
|
||||||
|
Payload: []byte("xyzzy"),
|
||||||
|
Padding: []byte("1234567890abcdef"),
|
||||||
|
}
|
||||||
|
woutmsg, err := whisper.NewSentMessage(wparams)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not create whisper message: %v", err)
|
||||||
|
}
|
||||||
|
env, err := woutmsg.Wrap(wparams)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not generate whisper envelope: %v", err)
|
||||||
|
}
|
||||||
|
ps.Register(&topic, func(msg []byte, p *p2p.Peer, asymmetric bool, keyid string) error {
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
pssmsgs = append(pssmsgs, &PssMsg{
|
||||||
|
To: to,
|
||||||
|
Payload: env,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
if !ps.process(pssmsgs[len(pssmsgs)-(i%len(pssmsgs))-1]) {
|
||||||
|
b.Fatalf("pss processing failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSymkeyBruteforceSameaddr(b *testing.B) {
|
||||||
|
for i := 100; i < 100000; i = i * 10 {
|
||||||
|
for j := 32; j < 10000; j = j * 8 {
|
||||||
|
b.Run(fmt.Sprintf("%d/%d", i, j), benchmarkSymkeyBruteforceSameaddr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// decrypt performance using symkey cache, best case
|
||||||
|
// (decrypt key always first in cache)
|
||||||
|
func benchmarkSymkeyBruteforceSameaddr(b *testing.B) {
|
||||||
|
var keyid string
|
||||||
|
var ps *Pss
|
||||||
|
cachesize := int64(0)
|
||||||
|
keycountstring := strings.Split(b.Name(), "/")
|
||||||
|
if len(keycountstring) < 2 {
|
||||||
|
b.Fatalf("benchmark called without count param")
|
||||||
|
}
|
||||||
|
keycount, err := strconv.ParseInt(keycountstring[1], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("benchmark called with invalid count param '%s': %v", keycountstring[1], err)
|
||||||
|
}
|
||||||
|
if len(keycountstring) == 3 {
|
||||||
|
cachesize, err = strconv.ParseInt(keycountstring[2], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("benchmark called with invalid cachesize '%s': %v", keycountstring[2], err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addr := make([]PssAddress, keycount)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
|
defer cancel()
|
||||||
|
keys, err := wapi.NewKeyPair(ctx)
|
||||||
|
privkey, err := w.GetPrivateKey(keys)
|
||||||
|
if cachesize > 0 {
|
||||||
|
ps = newTestPss(privkey, nil, &PssParams{SymKeyCacheCapacity: int(cachesize)})
|
||||||
|
} else {
|
||||||
|
ps = newTestPss(privkey, nil, nil)
|
||||||
|
}
|
||||||
|
topic := BytesToTopic([]byte("foo"))
|
||||||
|
for i := 0; i < int(keycount); i++ {
|
||||||
|
copy(addr[i], network.RandomAddr().Over())
|
||||||
|
keyid, err = ps.generateSymmetricKey(topic, &addr[i], true)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("cant generate symkey #%d: %v", i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
symkey, err := ps.w.GetSymKey(keyid)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not retrieve symkey %s: %v", keyid, err)
|
||||||
|
}
|
||||||
|
wparams := &whisper.MessageParams{
|
||||||
|
TTL: defaultWhisperTTL,
|
||||||
|
KeySym: symkey,
|
||||||
|
Topic: whisper.TopicType(topic),
|
||||||
|
WorkTime: defaultWhisperWorkTime,
|
||||||
|
PoW: defaultWhisperPoW,
|
||||||
|
Payload: []byte("xyzzy"),
|
||||||
|
Padding: []byte("1234567890abcdef"),
|
||||||
|
}
|
||||||
|
woutmsg, err := whisper.NewSentMessage(wparams)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not create whisper message: %v", err)
|
||||||
|
}
|
||||||
|
env, err := woutmsg.Wrap(wparams)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("could not generate whisper envelope: %v", err)
|
||||||
|
}
|
||||||
|
ps.Register(&topic, func(msg []byte, p *p2p.Peer, asymmetric bool, keyid string) error {
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
pssmsg := &PssMsg{
|
||||||
|
To: addr[len(addr)-1][:],
|
||||||
|
Payload: env,
|
||||||
|
}
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
if !ps.process(pssmsg) {
|
||||||
|
b.Fatalf("pss processing failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -392,172 +392,6 @@ func TestMismatch(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSymkeyBruteforceChangeaddr(b *testing.B) {
|
|
||||||
for i := 100; i < 100000; i = i * 10 {
|
|
||||||
for j := 32; j < 10000; j = j * 8 {
|
|
||||||
b.Run(fmt.Sprintf("%d/%d", i, j), benchmarkSymkeyBruteforceChangeaddr)
|
|
||||||
}
|
|
||||||
//b.Run(fmt.Sprintf("%d", i), benchmarkSymkeyBruteforceChangeaddr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// decrypt performance using symkey cache, worst case
|
|
||||||
// (decrypt key always last in cache)
|
|
||||||
func benchmarkSymkeyBruteforceChangeaddr(b *testing.B) {
|
|
||||||
keycountstring := strings.Split(b.Name(), "/")
|
|
||||||
cachesize := int64(0)
|
|
||||||
var ps *Pss
|
|
||||||
if len(keycountstring) < 2 {
|
|
||||||
b.Fatalf("benchmark called without count param")
|
|
||||||
}
|
|
||||||
keycount, err := strconv.ParseInt(keycountstring[1], 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("benchmark called with invalid count param '%s': %v", keycountstring[1], err)
|
|
||||||
}
|
|
||||||
if len(keycountstring) == 3 {
|
|
||||||
cachesize, err = strconv.ParseInt(keycountstring[2], 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("benchmark called with invalid cachesize '%s': %v", keycountstring[2], err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pssmsgs := make([]*PssMsg, 0, keycount)
|
|
||||||
var keyid string
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
|
||||||
defer cancel()
|
|
||||||
keys, err := wapi.NewKeyPair(ctx)
|
|
||||||
privkey, err := w.GetPrivateKey(keys)
|
|
||||||
if cachesize > 0 {
|
|
||||||
ps = newTestPss(privkey, nil, &PssParams{SymKeyCacheCapacity: int(cachesize)})
|
|
||||||
} else {
|
|
||||||
ps = newTestPss(privkey, nil, nil)
|
|
||||||
}
|
|
||||||
topic := BytesToTopic([]byte("foo"))
|
|
||||||
for i := 0; i < int(keycount); i++ {
|
|
||||||
to := make(PssAddress, 32)
|
|
||||||
copy(to[:], network.RandomAddr().Over())
|
|
||||||
keyid, err = ps.generateSymmetricKey(topic, &to, true)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("cant generate symkey #%d: %v", i, err)
|
|
||||||
}
|
|
||||||
symkey, err := ps.w.GetSymKey(keyid)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not retrieve symkey %s: %v", keyid, err)
|
|
||||||
}
|
|
||||||
wparams := &whisper.MessageParams{
|
|
||||||
TTL: defaultWhisperTTL,
|
|
||||||
KeySym: symkey,
|
|
||||||
Topic: whisper.TopicType(topic),
|
|
||||||
WorkTime: defaultWhisperWorkTime,
|
|
||||||
PoW: defaultWhisperPoW,
|
|
||||||
Payload: []byte("xyzzy"),
|
|
||||||
Padding: []byte("1234567890abcdef"),
|
|
||||||
}
|
|
||||||
woutmsg, err := whisper.NewSentMessage(wparams)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not create whisper message: %v", err)
|
|
||||||
}
|
|
||||||
env, err := woutmsg.Wrap(wparams)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not generate whisper envelope: %v", err)
|
|
||||||
}
|
|
||||||
ps.Register(&topic, func(msg []byte, p *p2p.Peer, asymmetric bool, keyid string) error {
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
pssmsgs = append(pssmsgs, &PssMsg{
|
|
||||||
To: to,
|
|
||||||
Payload: env,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
if !ps.process(pssmsgs[len(pssmsgs)-(i%len(pssmsgs))-1]) {
|
|
||||||
b.Fatalf("pss processing failed: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkSymkeyBruteforceSameaddr(b *testing.B) {
|
|
||||||
for i := 100; i < 100000; i = i * 10 {
|
|
||||||
for j := 32; j < 10000; j = j * 8 {
|
|
||||||
b.Run(fmt.Sprintf("%d/%d", i, j), benchmarkSymkeyBruteforceSameaddr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// decrypt performance using symkey cache, best case
|
|
||||||
// (decrypt key always first in cache)
|
|
||||||
func benchmarkSymkeyBruteforceSameaddr(b *testing.B) {
|
|
||||||
var keyid string
|
|
||||||
var ps *Pss
|
|
||||||
cachesize := int64(0)
|
|
||||||
keycountstring := strings.Split(b.Name(), "/")
|
|
||||||
if len(keycountstring) < 2 {
|
|
||||||
b.Fatalf("benchmark called without count param")
|
|
||||||
}
|
|
||||||
keycount, err := strconv.ParseInt(keycountstring[1], 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("benchmark called with invalid count param '%s': %v", keycountstring[1], err)
|
|
||||||
}
|
|
||||||
if len(keycountstring) == 3 {
|
|
||||||
cachesize, err = strconv.ParseInt(keycountstring[2], 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("benchmark called with invalid cachesize '%s': %v", keycountstring[2], err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addr := make([]PssAddress, keycount)
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
|
||||||
defer cancel()
|
|
||||||
keys, err := wapi.NewKeyPair(ctx)
|
|
||||||
privkey, err := w.GetPrivateKey(keys)
|
|
||||||
if cachesize > 0 {
|
|
||||||
ps = newTestPss(privkey, nil, &PssParams{SymKeyCacheCapacity: int(cachesize)})
|
|
||||||
} else {
|
|
||||||
ps = newTestPss(privkey, nil, nil)
|
|
||||||
}
|
|
||||||
topic := BytesToTopic([]byte("foo"))
|
|
||||||
for i := 0; i < int(keycount); i++ {
|
|
||||||
copy(addr[i], network.RandomAddr().Over())
|
|
||||||
keyid, err = ps.generateSymmetricKey(topic, &addr[i], true)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("cant generate symkey #%d: %v", i, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
symkey, err := ps.w.GetSymKey(keyid)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not retrieve symkey %s: %v", keyid, err)
|
|
||||||
}
|
|
||||||
wparams := &whisper.MessageParams{
|
|
||||||
TTL: defaultWhisperTTL,
|
|
||||||
KeySym: symkey,
|
|
||||||
Topic: whisper.TopicType(topic),
|
|
||||||
WorkTime: defaultWhisperWorkTime,
|
|
||||||
PoW: defaultWhisperPoW,
|
|
||||||
Payload: []byte("xyzzy"),
|
|
||||||
Padding: []byte("1234567890abcdef"),
|
|
||||||
}
|
|
||||||
woutmsg, err := whisper.NewSentMessage(wparams)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not create whisper message: %v", err)
|
|
||||||
}
|
|
||||||
env, err := woutmsg.Wrap(wparams)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("could not generate whisper envelope: %v", err)
|
|
||||||
}
|
|
||||||
ps.Register(&topic, func(msg []byte, p *p2p.Peer, asymmetric bool, keyid string) error {
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
pssmsg := &PssMsg{
|
|
||||||
To: addr[len(addr)-1][:],
|
|
||||||
Payload: env,
|
|
||||||
}
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
if !ps.process(pssmsg) {
|
|
||||||
b.Fatalf("pss processing failed: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup simulated network and connect nodes in circle
|
// setup simulated network and connect nodes in circle
|
||||||
func setupNetwork(numnodes int) (clients []*rpc.Client, err error) {
|
func setupNetwork(numnodes int) (clients []*rpc.Client, err error) {
|
||||||
nodes := make([]*simulations.Node, numnodes)
|
nodes := make([]*simulations.Node, numnodes)
|
||||||
|
|
|
||||||
|
|
@ -637,10 +637,7 @@ func (self *ResourceHandler) verifyContent(chunkdata []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ResourceHandler) hasUpdate(name string, period uint32) bool {
|
func (self *ResourceHandler) hasUpdate(name string, period uint32) bool {
|
||||||
if self.resources[name].lastPeriod == period {
|
return self.resources[name].lastPeriod == period
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type resourceChunkStore struct {
|
type resourceChunkStore struct {
|
||||||
|
|
|
||||||
|
|
@ -254,14 +254,10 @@ func (self *Swarm) Stop() error {
|
||||||
// implements the node.Service interface
|
// implements the node.Service interface
|
||||||
func (self *Swarm) Protocols() (protos []p2p.Protocol) {
|
func (self *Swarm) Protocols() (protos []p2p.Protocol) {
|
||||||
|
|
||||||
for _, p := range self.bzz.Protocols() {
|
protos = append(protos, self.bzz.Protocols()...)
|
||||||
protos = append(protos, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.ps != nil {
|
if self.ps != nil {
|
||||||
for _, p := range self.ps.Protocols() {
|
protos = append(protos, self.ps.Protocols())
|
||||||
protos = append(protos, p)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -322,14 +318,10 @@ func (self *Swarm) APIs() []rpc.API {
|
||||||
// {Namespace, Version, api.NewAdmin(self), false},
|
// {Namespace, Version, api.NewAdmin(self), false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, api := range self.bzz.APIs() {
|
apis = append(apis, self.bzz.APIs())
|
||||||
apis = append(apis, api)
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.ps != nil {
|
if self.ps != nil {
|
||||||
for _, api := range self.ps.APIs() {
|
apis = append(apis, self.ps.APIs())
|
||||||
apis = append(apis, api)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return apis
|
return apis
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue