Skip to content

Commit

Permalink
swarm/pss: Add missing timer selects
Browse files Browse the repository at this point in the history
  • Loading branch information
nolash committed May 4, 2018
1 parent 0e3656f commit 2c634e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
44 changes: 22 additions & 22 deletions swarm/pss/pss.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,33 +326,33 @@ func (self *Pss) getHandlers(topic Topic) map[*Handler]bool {
func (self *Pss) handlePssMsg(msg interface{}) error {
pssmsg, ok := msg.(*PssMsg)

if ok {
if int64(pssmsg.Expire) < time.Now().Unix() {
log.Trace(fmt.Sprintf("pss filtered expired message FROM %x TO %x", self.Overlay.BaseAddr(), common.ToHex(pssmsg.To)))
return nil
}
if self.checkFwdCache(pssmsg) {
log.Trace(fmt.Sprintf("pss relay block-cache match (process): FROM %x TO %x", self.Overlay.BaseAddr(), common.ToHex(pssmsg.To)))
return nil
}
self.addFwdCache(pssmsg)
if !ok {
return fmt.Errorf("invalid message type. Expected *PssMsg, got %T ", msg)
}
if int64(pssmsg.Expire) < time.Now().Unix() {
log.Trace(fmt.Sprintf("pss filtered expired message FROM %x TO %x", self.Overlay.BaseAddr(), common.ToHex(pssmsg.To)))
return nil
}
if self.checkFwdCache(pssmsg) {
log.Trace(fmt.Sprintf("pss relay block-cache match (process): FROM %x TO %x", self.Overlay.BaseAddr(), common.ToHex(pssmsg.To)))
return nil
}
self.addFwdCache(pssmsg)

if !self.isSelfPossibleRecipient(pssmsg) {
log.Trace("pss was for someone else :'( ... forwarding", "pss", common.ToHex(self.BaseAddr()))
return self.enqueue(pssmsg)
}
if !self.isSelfPossibleRecipient(pssmsg) {
log.Trace("pss was for someone else :'( ... forwarding", "pss", common.ToHex(self.BaseAddr()))
return self.enqueue(pssmsg)
}

log.Trace("pss for us, yay! ... let's process!", "pss", common.ToHex(self.BaseAddr()))
if err := self.process(pssmsg); err != nil {
qerr := self.enqueue(pssmsg)
if qerr != nil {
return fmt.Errorf("process fail: processerr %v, queueerr: %v", err, qerr)
}
log.Trace("pss for us, yay! ... let's process!", "pss", common.ToHex(self.BaseAddr()))
if err := self.process(pssmsg); err != nil {
qerr := self.enqueue(pssmsg)
if qerr != nil {
return fmt.Errorf("process fail: processerr %v, queueerr: %v", err, qerr)
}
return nil
}
return nil

return fmt.Errorf("invalid message type. Expected *PssMsg, got %T ", msg)
}

// Entry point to processing a message for which the current node can be the intended recipient.
Expand Down
4 changes: 3 additions & 1 deletion swarm/pss/pss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@ func TestHandlerConditions(t *testing.T) {
var outmsg *PssMsg
select {
case outmsg = <-ps.outbox:
case <-tmr.C:
default:
}
if outmsg != nil {
t.Fatalf("expected outbox empty after full address on msg, but had message %v", msg)
t.Fatalf("expected outbox empty after full address on msg, but had message %s", msg)
}

// message should pass and queue due to partial length
Expand Down Expand Up @@ -361,6 +362,7 @@ func TestHandlerConditions(t *testing.T) {
outmsg = nil
select {
case outmsg = <-ps.outbox:
case <-tmr.C:
default:
}
if outmsg != nil {
Expand Down

0 comments on commit 2c634e5

Please sign in to comment.