01d75a9d21
* go.mod: upgrade prysm and the indrect dependency prysm from v4.0.2 to v4.0.8, and run go mod tidy * ci: upgrade go version from 1.19 to 1.20 * go-version: upgrade from v1.19 to v1.20 there is some dependency on go v1.20, such as go-libp2p v0.27.8 and also run go mod tidy * dependency: upgrade docker version for security it is not a big issue, since docker is only used for test purpose. * rand: update the usage of math/rand after golang v1.20 2 APIs of math/rand module were deprecated since golang v1.20. that is: rand.Seed() and rand.Read(), refer: ettps://pkg.go.dev/math/rand "rand.Seed(seed int64)" has been replaced by: "r := rand.New(rand.NewSource(seed int64))", need to initialize it with an instance before use "rand.Read()" has been replaced by "crypto/rand.Read()" * readme: need golang v1.20+ to build bsc
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package trust
|
|
|
|
import (
|
|
"crypto/rand"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
)
|
|
|
|
// testPeer is a simulated peer to allow testing direct network calls.
|
|
type testPeer struct {
|
|
*Peer
|
|
|
|
net p2p.MsgReadWriter // Network layer reader/writer to simulate remote messaging
|
|
app *p2p.MsgPipeRW // Application layer reader/writer to simulate the local side
|
|
}
|
|
|
|
// newTestPeer creates a new peer registered at the given data backend.
|
|
func newTestPeer(name string, version uint, backend Backend) (*testPeer, <-chan error) {
|
|
// Create a message pipe to communicate through
|
|
app, net := p2p.MsgPipe()
|
|
|
|
// Start the peer on a new thread
|
|
var id enode.ID
|
|
rand.Read(id[:])
|
|
|
|
peer := NewPeer(version, p2p.NewPeer(id, name, nil), net)
|
|
errc := make(chan error, 1)
|
|
go func() {
|
|
errc <- backend.RunPeer(peer, func(peer *Peer) error {
|
|
return Handle(backend, peer)
|
|
})
|
|
}()
|
|
return &testPeer{app: app, net: net, Peer: peer}, errc
|
|
}
|
|
|
|
// close terminates the local side of the peer, notifying the remote protocol
|
|
// manager of termination.
|
|
func (p *testPeer) close() {
|
|
p.Peer.Close()
|
|
p.app.Close()
|
|
}
|