Skip to content

Commit

Permalink
max packet size defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen Quoc Dinh committed Jun 15, 2014
1 parent 4a7afb6 commit d727d43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ p.exchangeLifetime = p.maxTransmitSpan + p.maxRTT
// default port for CoAP
p.coapPort = 5683

// default max packet size
p.maxPacketSize = 1280

module.exports = p
7 changes: 5 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,18 @@ function OutMessage() {
}
util.inherits(OutMessage, OutgoingMessage)

var maxBlock2 = 1024 //16, 32, 64, must <= 2**(6+4)
// maxBlock2 is in formular 2**(i+4), and must <= 2**(6+4)
var maxBlock2 = Math.pow(2, Math.floor(Math.log(parameters.maxPacketSize)/Math.log(2)))
if (maxBlock2 > Math.pow(2, (6+4)))
maxBlock2 = Math.pow(2, (6+4))

OutMessage.prototype.end= function(payload) {
var that = this
var requestedBlockOption = _parseBlock2(that._request.options)

// if payload is suitable for ONE message, shoot it out
if (!payload ||
((!requestedBlockOption) && (payload.length < maxBlock2)))
((!requestedBlockOption) && (payload.length < parameters.maxPacketSize)))
return OutgoingMessage.prototype.end.call(this, payload)

// for the first request, block2 option may be missed
Expand Down

0 comments on commit d727d43

Please sign in to comment.