2018-06-11 10:48:42 +00:00
|
|
|
package benchmarks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2018-11-14 07:03:58 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2018-06-11 10:48:42 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
2018-09-25 07:05:38 +00:00
|
|
|
whisper "github.com/status-im/whisper/whisperv6"
|
2018-06-11 10:48:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
topic = whisper.TopicType{0xfa, 0xfb, 0xfc, 0xfd}
|
|
|
|
)
|
|
|
|
|
|
|
|
func createNode() (*node.Node, error) {
|
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return node.New(&node.Config{
|
|
|
|
DataDir: "",
|
|
|
|
P2P: p2p.Config{
|
|
|
|
PrivateKey: key,
|
|
|
|
DiscoveryV5: false,
|
|
|
|
NoDiscovery: true,
|
|
|
|
MaxPeers: 1,
|
|
|
|
NAT: nat.Any(),
|
|
|
|
},
|
2019-02-01 17:02:52 +00:00
|
|
|
NoUSB: true,
|
2018-06-11 10:48:42 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-14 07:03:58 +00:00
|
|
|
func addPeerWithConfirmation(server *p2p.Server, node *enode.Node) error {
|
2018-06-11 10:48:42 +00:00
|
|
|
ch := make(chan *p2p.PeerEvent, server.MaxPeers)
|
|
|
|
subscription := server.SubscribeEvents(ch)
|
|
|
|
defer subscription.Unsubscribe()
|
|
|
|
|
|
|
|
server.AddPeer(node)
|
|
|
|
|
|
|
|
ev := <-ch
|
2018-11-14 07:03:58 +00:00
|
|
|
if ev.Type != p2p.PeerEventTypeAdd || ev.Peer == node.ID() {
|
2018-06-11 10:48:42 +00:00
|
|
|
return fmt.Errorf("got unexpected event: %+v", ev)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func createWhisperService() *whisper.Whisper {
|
|
|
|
whisperServiceConfig := &whisper.Config{
|
|
|
|
MaxMessageSize: whisper.DefaultMaxMessageSize,
|
|
|
|
MinimumAcceptedPOW: 0.005,
|
|
|
|
}
|
|
|
|
return whisper.New(whisperServiceConfig)
|
|
|
|
}
|