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:
|
case <-lmsgC:
|
||||||
log.Debug("lnode ok")
|
log.Debug("lnode ok")
|
||||||
case cerr := <-lctx.Done():
|
case cerr := <-lctx.Done():
|
||||||
log.Debug("testmsgtimeout")
|
|
||||||
_ = cerr
|
_ = cerr
|
||||||
return
|
return
|
||||||
//t.Fatalf("test message timed out: %v", cerr)
|
//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 pssmsg.isRaw() {
|
||||||
if p.topicHandlerCaps[psstopic]&handlerCapRaw == 0 {
|
if p.topicHandlerCaps[psstopic]&handlerCapRaw == 0 {
|
||||||
log.Debug("No handler for raw message", "topic", psstopic)
|
log.Debug("No handler for raw message", "topic", psstopic)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
isRaw = true
|
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
|
// - no prox handler on message and partial address matches
|
||||||
// - prox handler on message and we are in prox regardless of partial address match
|
// - 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
|
// store this result so we don't calculate again on every handler
|
||||||
var isProx bool
|
isProx := p.topicHandlerCaps[psstopic]&handlerCapProx != 0
|
||||||
var isRecipient bool
|
isRecipient := p.isSelfPossibleRecipient(pssmsg, isProx)
|
||||||
if p.isSelfPossibleRecipient(pssmsg, false) && p.topicHandlerCaps[psstopic]&handlerCapProx == 0 {
|
|
||||||
isRecipient = true
|
|
||||||
} else if p.isSelfPossibleRecipient(pssmsg, true) {
|
|
||||||
isRecipient = true
|
|
||||||
isProx = true
|
|
||||||
}
|
|
||||||
if !isRecipient {
|
if !isRecipient {
|
||||||
log.Trace("pss was for someone else :'( ... forwarding", "pss", common.ToHex(p.BaseAddr()), "prox", isProx)
|
log.Trace("pss was for someone else :'( ... forwarding", "pss", common.ToHex(p.BaseAddr()), "prox", isProx)
|
||||||
return p.enqueue(pssmsg)
|
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) {
|
func TestProxShortCircuit(t *testing.T) {
|
||||||
|
|
||||||
// sender node address
|
// sender node address
|
||||||
|
|
@ -370,6 +371,8 @@ func TestProxShortCircuit(t *testing.T) {
|
||||||
})
|
})
|
||||||
defer hndlrProxDereg()
|
defer hndlrProxDereg()
|
||||||
|
|
||||||
|
// send message too far away for sender to be in prox
|
||||||
|
// reception of this message should time out
|
||||||
errC := make(chan error)
|
errC := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
err := ps.SendRaw(distantMessageAddress, topic, []byte("foo"))
|
err := ps.SendRaw(distantMessageAddress, topic, []byte("foo"))
|
||||||
|
|
@ -388,6 +391,8 @@ func TestProxShortCircuit(t *testing.T) {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send message that should be within sender prox
|
||||||
|
// this message should be delivered
|
||||||
go func() {
|
go func() {
|
||||||
err := ps.SendRaw(proxMessageAddress, topic, []byte("bar"))
|
err := ps.SendRaw(proxMessageAddress, topic, []byte("bar"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -405,8 +410,9 @@ func TestProxShortCircuit(t *testing.T) {
|
||||||
t.Fatal("raw timeout")
|
t.Fatal("raw timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
localAddrPss := PssAddress(localAddr)
|
// try the same prox message with sym and asym send
|
||||||
symKeyId, err := ps.GenerateSymmetricKey(topic, &localAddrPss, true)
|
proxAddrPss := PssAddress(proxMessageAddress)
|
||||||
|
symKeyId, err := ps.GenerateSymmetricKey(topic, &proxAddrPss, true)
|
||||||
go func() {
|
go func() {
|
||||||
err := ps.SendSym(symKeyId, topic, []byte("baz"))
|
err := ps.SendSym(symKeyId, topic, []byte("baz"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -423,7 +429,7 @@ func TestProxShortCircuit(t *testing.T) {
|
||||||
t.Fatal("sym timeout")
|
t.Fatal("sym timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ps.SetPeerPublicKey(&privKey.PublicKey, topic, &localAddrPss)
|
err = ps.SetPeerPublicKey(&privKey.PublicKey, topic, &proxAddrPss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -456,7 +462,8 @@ func TestAddressMatchProx(t *testing.T) {
|
||||||
// set up kademlia
|
// set up kademlia
|
||||||
kadparams := network.NewKadParams()
|
kadparams := network.NewKadParams()
|
||||||
kad := network.NewKademlia(localAddr, kadparams)
|
kad := network.NewKademlia(localAddr, kadparams)
|
||||||
peerCount := kad.MinBinSize + 2
|
nnPeerCount := kad.MinBinSize
|
||||||
|
peerCount := nnPeerCount + 2
|
||||||
|
|
||||||
// set up pss
|
// set up pss
|
||||||
privKey, err := crypto.GenerateKey()
|
privKey, err := crypto.GenerateKey()
|
||||||
|
|
@ -497,8 +504,8 @@ func TestAddressMatchProx(t *testing.T) {
|
||||||
log.Trace("kadconn", "po", po, "peer", p, "prox", prox)
|
log.Trace("kadconn", "po", po, "peer", p, "prox", prox)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
if proxes != kad.MinBinSize {
|
if proxes != nnPeerCount {
|
||||||
t.Fatalf("expected %d proxpeers, have %d", kad.MinBinSize, proxes)
|
t.Fatalf("expected %d proxpeers, have %d", nnPeerCount, proxes)
|
||||||
} else if conns != peerCount {
|
} else if conns != peerCount {
|
||||||
t.Fatalf("expected %d peers total, have %d", peerCount, proxes)
|
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
|
// remote address distances from localAddr to try and the expected outcomes if we use prox handler
|
||||||
remoteDistances := []int{
|
remoteDistances := []int{
|
||||||
255,
|
255,
|
||||||
kad.MinBinSize + 1,
|
nnPeerCount + 1,
|
||||||
kad.MinBinSize,
|
nnPeerCount,
|
||||||
kad.MinBinSize - 1,
|
nnPeerCount - 1,
|
||||||
0,
|
0,
|
||||||
}
|
}
|
||||||
expects := []bool{
|
expects := []bool{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue