Skip to content

Commit

Permalink
networkStatus resend handling performed by firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Feb 8, 2024
1 parent fd78fac commit 0e9c654
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 57 deletions.
4 changes: 2 additions & 2 deletions lib/Af.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class Af extends EventEmitter {
if(ex.status == 178) { // ZApsTableFull
wf.cancel()
areqCancelable._cancels.delete(wf)
await Q.delay((Math.random() + 0.5) * 16000)
await Q.delay((Math.random() + 0.5) * 32000)

// in case the src rtg changed
const srcRtg = dstEp.getSrcRtg()
Expand Down Expand Up @@ -372,7 +372,7 @@ class Af extends EventEmitter {
if(ex.status == 178) { // ZApsTableFull
wf.cancel()
areqCancelable._cancels.delete(wf)
await Q.delay((Math.random() + 0.5) * 16000)
await Q.delay((Math.random() + 0.5) * 32000)
continue
}
throw ex
Expand Down
55 changes: 0 additions & 55 deletions lib/AfController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ const EventEmitter = require('eventemitter2')
const Q = require('@halleyassist/q-lite')
const debug = require('debug')("zstack-af:controller")

/**
NO_ROUTE_AVAIL 0
"INDIRECT_TRANS_EXPIRY": 6,
"VALIDATE_ROUTE": 10,
"SOURCE_ROUTE_FAILURE": 11,
NWKSTAT_MANY_TO_ONE_ROUTE_FAILURE 0x0c
*/
const DefaultCodesOfInterest = [0, 6, 0x10, 0x11, 0x0c, 0xb2]

class AfController extends EventEmitter {
constructor(){
super()
Expand Down Expand Up @@ -40,35 +31,6 @@ class AfController extends EventEmitter {
}
/* eslint-enable no-unused-vars */

registerResend(dstAddr, interestedCodes = DefaultCodesOfInterest){
const afResendEvt = 'ZDO:networkStatus:' + dstAddr.toString(16)
let sendTime = Date.now()
const deferred = Q.defer()
let done = false

const handleResend = data=>{
if(done) return
if(interestedCodes.includes(data.code) && (Date.now() - sendTime) > 6500){
debug(`possible indirect expiration for 0x${dstAddr.toString(16)}, resending (status: 0x${data.code.toString(16)})`)
done = true
deferred.resolve(data.code)
} else {
this.removeListener(...eventArgs)
this.once(...eventArgs)
}
}

const eventArgs = [afResendEvt, handleResend] // declaration gets hoisted, handleResend can reference it

this.once(...eventArgs);

const cleanup = ()=>{
this.removeListener(...eventArgs)
deferred.resolve(null)
}

return {cleanup, promise: deferred.promise}
}
async indirectSend(sendFn, cfg){
const shouldIndirect = this.shouldSendIndrect(cfg.dstAddr)
let retries = cfg.retries || 4
Expand All @@ -82,7 +44,6 @@ class AfController extends EventEmitter {
for(let i = 1; i<=retries; i++){
let resend
try {
let attemptStart = Date.now()
// Return immediately without retry if we can (racey)

// Perform send
Expand All @@ -97,10 +58,6 @@ class AfController extends EventEmitter {
if(cfg.signalTimeout){
promises.push(cfg.signalTimeout.promise)
}
if(shouldIndirect){
resend = this.registerResend(cfg.dstAddr)
promises.push(resend.promise.then(a=>a||'resend'))
}
const result = await Q.cancelledRace(promises)

// Handle results for any of the promises that might have returned
Expand All @@ -109,18 +66,6 @@ class AfController extends EventEmitter {
await Q.cancelledRace([Q.delay(5000), workPromise]) // Wait at-least 5 seconds after a module error
canSrcRtg = false
}
else if(typeof result === 'number') {
// network status code
if(result != 6 && i != retries) {
const waitTime = 3500 - (Date.now() - attemptStart)
if(waitTime > 0) await Q.cancelledRace([Q.delay(waitTime), workPromise])

// After a MTO failure we can still srcrtg, the coordinator will send a RReq
// NO_ROUTE_AVAIL occurs when the device has no free space for new routes
if(result != 0x0c) canSrcRtg = false
}
// if is 6 (INDIRECT_TRANS_EXPIRY) we continue
}
else if(result !== undefined) {
// should be the same as result
return await workPromise
Expand Down

0 comments on commit 0e9c654

Please sign in to comment.