mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/pss: Simplify caps check, test cleanup
This commit is contained in:
parent
6f93440540
commit
122d351c62
3 changed files with 19 additions and 18 deletions
|
|
@ -129,7 +129,6 @@ func testProtocol(t *testing.T) {
|
|||
case <-lmsgC:
|
||||
log.Debug("lnode ok")
|
||||
case cerr := <-lctx.Done():
|
||||
log.Debug("testmsgtimeout")
|
||||
_ = cerr
|
||||
return
|
||||
//t.Fatalf("test message timed out: %v", cerr)
|
||||
|
|
|
|||
|
|
@ -381,6 +381,7 @@ func (p *Pss) handlePssMsg(ctx context.Context, msg interface{}) error {
|
|||
if pssmsg.isRaw() {
|
||||
if p.topicHandlerCaps[psstopic]&handlerCapRaw == 0 {
|
||||
log.Debug("No handler for raw message", "topic", psstopic)
|
||||
return nil
|
||||
}
|
||||
isRaw = true
|
||||
}
|
||||
|
|
@ -389,14 +390,8 @@ func (p *Pss) handlePssMsg(ctx context.Context, msg interface{}) error {
|
|||
// - no prox handler on message and partial address matches
|
||||
// - prox handler on message and we are in prox regardless of partial address match
|
||||
// store this result so we don't calculate again on every handler
|
||||
var isProx bool
|
||||
var isRecipient bool
|
||||
if p.isSelfPossibleRecipient(pssmsg, false) && p.topicHandlerCaps[psstopic]&handlerCapProx == 0 {
|
||||
isRecipient = true
|
||||
} else if p.isSelfPossibleRecipient(pssmsg, true) {
|
||||
isRecipient = true
|
||||
isProx = true
|
||||
}
|
||||
isProx := p.topicHandlerCaps[psstopic]&handlerCapProx != 0
|
||||
isRecipient := p.isSelfPossibleRecipient(pssmsg, isProx)
|
||||
if !isRecipient {
|
||||
log.Trace("pss was for someone else :'( ... forwarding", "pss", common.ToHex(p.BaseAddr()), "prox", isProx)
|
||||
return p.enqueue(pssmsg)
|
||||
|
|
|
|||
|
|
@ -315,6 +315,7 @@ func TestAddressMatch(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
// test that message is handled by sender if a prox handler exists and sender is in prox of message
|
||||
func TestProxShortCircuit(t *testing.T) {
|
||||
|
||||
// sender node address
|
||||
|
|
@ -370,6 +371,8 @@ func TestProxShortCircuit(t *testing.T) {
|
|||
})
|
||||
defer hndlrProxDereg()
|
||||
|
||||
// send message too far away for sender to be in prox
|
||||
// reception of this message should time out
|
||||
errC := make(chan error)
|
||||
go func() {
|
||||
err := ps.SendRaw(distantMessageAddress, topic, []byte("foo"))
|
||||
|
|
@ -388,6 +391,8 @@ func TestProxShortCircuit(t *testing.T) {
|
|||
case <-ctx.Done():
|
||||
}
|
||||
|
||||
// send message that should be within sender prox
|
||||
// this message should be delivered
|
||||
go func() {
|
||||
err := ps.SendRaw(proxMessageAddress, topic, []byte("bar"))
|
||||
if err != nil {
|
||||
|
|
@ -405,8 +410,9 @@ func TestProxShortCircuit(t *testing.T) {
|
|||
t.Fatal("raw timeout")
|
||||
}
|
||||
|
||||
localAddrPss := PssAddress(localAddr)
|
||||
symKeyId, err := ps.GenerateSymmetricKey(topic, &localAddrPss, true)
|
||||
// try the same prox message with sym and asym send
|
||||
proxAddrPss := PssAddress(proxMessageAddress)
|
||||
symKeyId, err := ps.GenerateSymmetricKey(topic, &proxAddrPss, true)
|
||||
go func() {
|
||||
err := ps.SendSym(symKeyId, topic, []byte("baz"))
|
||||
if err != nil {
|
||||
|
|
@ -423,7 +429,7 @@ func TestProxShortCircuit(t *testing.T) {
|
|||
t.Fatal("sym timeout")
|
||||
}
|
||||
|
||||
err = ps.SetPeerPublicKey(&privKey.PublicKey, topic, &localAddrPss)
|
||||
err = ps.SetPeerPublicKey(&privKey.PublicKey, topic, &proxAddrPss)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -456,7 +462,8 @@ func TestAddressMatchProx(t *testing.T) {
|
|||
// set up kademlia
|
||||
kadparams := network.NewKadParams()
|
||||
kad := network.NewKademlia(localAddr, kadparams)
|
||||
peerCount := kad.MinBinSize + 2
|
||||
nnPeerCount := kad.MinBinSize
|
||||
peerCount := nnPeerCount + 2
|
||||
|
||||
// set up pss
|
||||
privKey, err := crypto.GenerateKey()
|
||||
|
|
@ -497,8 +504,8 @@ func TestAddressMatchProx(t *testing.T) {
|
|||
log.Trace("kadconn", "po", po, "peer", p, "prox", prox)
|
||||
return true
|
||||
})
|
||||
if proxes != kad.MinBinSize {
|
||||
t.Fatalf("expected %d proxpeers, have %d", kad.MinBinSize, proxes)
|
||||
if proxes != nnPeerCount {
|
||||
t.Fatalf("expected %d proxpeers, have %d", nnPeerCount, proxes)
|
||||
} else if conns != peerCount {
|
||||
t.Fatalf("expected %d peers total, have %d", peerCount, proxes)
|
||||
}
|
||||
|
|
@ -506,9 +513,9 @@ func TestAddressMatchProx(t *testing.T) {
|
|||
// remote address distances from localAddr to try and the expected outcomes if we use prox handler
|
||||
remoteDistances := []int{
|
||||
255,
|
||||
kad.MinBinSize + 1,
|
||||
kad.MinBinSize,
|
||||
kad.MinBinSize - 1,
|
||||
nnPeerCount + 1,
|
||||
nnPeerCount,
|
||||
nnPeerCount - 1,
|
||||
0,
|
||||
}
|
||||
expects := []bool{
|
||||
|
|
|
|||
Loading…
Reference in a new issue