mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
swarm/network, p2p/testing: WIP first test of pss poc
Fails as hive insists on starting discovery even though we don't want it
This commit is contained in:
parent
d4a08fdf7e
commit
9cad74910f
6 changed files with 116 additions and 25 deletions
|
|
@ -2,12 +2,12 @@ package testing
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/p2p/adapters"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/p2p/adapters"
|
||||
)
|
||||
|
||||
type ProtocolSession struct {
|
||||
|
|
@ -57,9 +57,8 @@ type Disconnect struct {
|
|||
Error error // disconnect reason
|
||||
}
|
||||
|
||||
|
||||
func NewProtocolSession(na adapters.NodeAdapter, ids []*adapters.NodeId) *ProtocolSession {
|
||||
ps := &ProtocolSession {
|
||||
ps := &ProtocolSession{
|
||||
TestNodeAdapter: na.(TestNodeAdapter),
|
||||
Ids: ids,
|
||||
}
|
||||
|
|
@ -133,7 +132,6 @@ func (self *ProtocolSession) expect(exp Expect) error {
|
|||
// fatal upon encountering first exchange error
|
||||
}
|
||||
|
||||
|
||||
// TestExchange tests a series of exchanges againsts the session
|
||||
func (self *ProtocolSession) TestExchanges(exchanges ...Exchange) error {
|
||||
// launch all triggers of this exchanges
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package testing
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/p2p/adapters"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/p2p/adapters"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||
)
|
||||
|
||||
type ProtocolTester struct {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func TestDiscovery(t *testing.T) {
|
|||
p2ptest.Expect{
|
||||
Code: 3,
|
||||
Msg: &SubPeersMsg{ProxLimit: 0, MinProxBinSize: 8},
|
||||
Peer: s.ExchangeSession.Ids[0],
|
||||
Peer: s.ProtocolTester.Ids[0],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -60,13 +60,13 @@ func newBzzBaseTester(t *testing.T, n int, addr *peerAddr, ct *protocols.CodeMap
|
|||
|
||||
return &bzzTester{
|
||||
addr: addr,
|
||||
ExchangeSession: s,
|
||||
ProtocolTester: s,
|
||||
cs: cs,
|
||||
}
|
||||
}
|
||||
|
||||
type bzzTester struct {
|
||||
*p2ptest.ExchangeSession
|
||||
*p2ptest.ProtocolTester
|
||||
addr *peerAddr
|
||||
cs map[string]chan bool
|
||||
}
|
||||
|
|
|
|||
26
swarm/network/pss.go
Normal file
26
swarm/network/pss.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
)
|
||||
|
||||
type pssPeer struct {
|
||||
Peer
|
||||
}
|
||||
|
||||
type PssMsg struct {
|
||||
Recipient pssPeer
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
func (pm *PssMsg) String() string {
|
||||
return fmt.Sprintf("PssMsg: Recipient: %v", pm.Recipient)
|
||||
}
|
||||
|
||||
func PssMsgHandler(msg interface{}) error {
|
||||
glog.V(logger.Detail).Infof("Pss Handled!")
|
||||
return nil
|
||||
}
|
||||
67
swarm/network/pss_test.go
Normal file
67
swarm/network/pss_test.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/p2p/adapters"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||
p2ptest "github.com/ethereum/go-ethereum/p2p/testing"
|
||||
)
|
||||
|
||||
type pssTester struct {
|
||||
*p2ptest.ProtocolTester
|
||||
}
|
||||
|
||||
func TestPssTwoToSelf(t *testing.T) {
|
||||
addr := RandomAddr()
|
||||
pt := newPssTester(t, addr, 2)
|
||||
hs_pivot := correctBzzHandshake(addr)
|
||||
for _, id := range pt.Ids {
|
||||
hs_sim := correctBzzHandshake(NewPeerAddrFromNodeId(id))
|
||||
glog.V(logger.Detail).Infof("Will handshake %v with %v", hs_pivot, hs_sim)
|
||||
<-pt.GetPeer(id).Connc
|
||||
pt.TestExchanges(bzzHandshakeExchange(hs_pivot, hs_sim, id)...)
|
||||
}
|
||||
}
|
||||
|
||||
func newPssTester(t *testing.T, addr *peerAddr, n int) *pssTester {
|
||||
return newPssBaseTester(t, addr, n)
|
||||
}
|
||||
|
||||
func newPssBaseTester(t *testing.T, addr *peerAddr, n int) *pssTester {
|
||||
ct := BzzCodeMap()
|
||||
ct.Register(&PssMsg{})
|
||||
|
||||
simPipe := adapters.NewSimPipe
|
||||
kp := NewKadParams()
|
||||
to := NewKademlia(addr.OverlayAddr(), kp)
|
||||
pp := NewHive(NewHiveParams(), to)
|
||||
net := simulations.NewNetwork(&simulations.NetworkConfig{})
|
||||
naf := func(conf *simulations.NodeConfig) adapters.NodeAdapter {
|
||||
na := adapters.NewSimNode(conf.Id, net, simPipe)
|
||||
return na
|
||||
}
|
||||
net.SetNaf(naf)
|
||||
|
||||
srv := func(p Peer) error {
|
||||
p.Register(&PssMsg{}, PssMsgHandler)
|
||||
pp.Add(p)
|
||||
p.DisconnectHook(func(err error) {
|
||||
pp.Remove(p)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
protocall := func(na adapters.NodeAdapter) adapters.ProtoCall {
|
||||
protocol := Bzz(addr.OverlayAddr(), na, ct, srv, nil, nil)
|
||||
return protocol.Run
|
||||
}
|
||||
|
||||
s := p2ptest.NewProtocolTester(t, NodeId(addr), n, protocall)
|
||||
|
||||
return &pssTester{
|
||||
ProtocolTester: s,
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue