Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coap

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coap - npm Package Compare versions

Comparing version 0.18.0 to 0.19.0

12

lib/parameters.js

@@ -58,2 +58,14 @@ /*

p.exchangeLifetime = p.maxTransmitSpan + p.maxRTT
// LRU prune timer period.
// In order to reduce unnecessary heap usage on low-traffic servers the
// LRU cache is periodically pruned to remove old, expired packets. This
// is a fairly low-intensity task, but the period can be altered here
// or the timer disabled by setting the value to zero.
// By default the value is set to 0.5 x exchangeLifetime (~120s)
if (values && (typeof(values.pruneTimerPeriod)==="number")) {
p.pruneTimerPeriod = values.pruneTimerPeriod
} else {
p.pruneTimerPeriod = (0.5 * p.exchangeLifetime)
}
}

@@ -60,0 +72,0 @@ p.refreshTiming()

23

lib/server.js

@@ -88,4 +88,4 @@ /*

max: options.cacheSize || (32768 * 1024)
, length: function(n) { return n.length }
, maxAge: parameters.exchangeLifetime
, length: function(n) { return n.buffer.byteLength }
, maxAge: (parameters.exchangeLifetime * 1000)
, dispose: function(key, value) {

@@ -241,2 +241,12 @@ if (value.sender)

if (parameters.pruneTimerPeriod) {
// Start LRU pruning timer
this._lru.pruneTimer = setInterval(function () {
that._lru.prune()
}, parameters.pruneTimerPeriod*1000)
if (this._lru.pruneTimer.unref) {
this._lru.pruneTimer.unref()
}
}
return this

@@ -250,2 +260,6 @@ }

if (this._lru.pruneTimer) {
clearInterval(this._lru.pruneTimer)
}
if (this._sock) {

@@ -329,4 +343,5 @@ this._sock.close()

lru.set(toKey(rsinfo.address, rsinfo.port,
packet, packet.ack || !packet.confirmable), buf)
var key = toKey(rsinfo.address, rsinfo.port,
packet, packet.ack || !packet.confirmable)
lru.set(key, buf)
buf.sender = sender

@@ -333,0 +348,0 @@

18

package.json
{
"name": "coap",
"version": "0.18.0",
"version": "0.19.0",
"description": "A CoAP library for node modelled after 'http'",

@@ -31,17 +31,17 @@ "main": "index.js",

"devDependencies": {
"pre-commit": "0.0.9",
"chai": "~3.4.1",
"mocha": "~2.3.4",
"timekeeper": "~0.0.5",
"pre-commit": "1.1.3",
"chai": "^3.4.1",
"mocha": "^3.2.0",
"timekeeper": "^1.0.0",
"sinon": "~1.7.3"
},
"dependencies": {
"bl": "~1.0.0",
"bl": "^1.0.0",
"capitalize": "^1.0.0",
"coap-packet": "~0.1.12",
"coap-packet": "^0.1.12",
"debug": "^2.2.0",
"fastseries": "^1.7.0",
"lru-cache": "~4.0.0",
"readable-stream": "~2.0.5"
"lru-cache": "^4.0.0",
"readable-stream": "^2.2.2"
}
}

@@ -164,3 +164,3 @@ /*

server.on('request', function(req) {
server.once('request', function(req) {
expect(req.options[0].name).to.eql(option)

@@ -182,3 +182,3 @@ expect(req.options[0].value).to.eql(format)

server.on('request', function(req) {
server.once('request', function(req) {
expect(req.options[0].name).to.eql(option)

@@ -200,3 +200,3 @@ expect(req.options[0].value).to.eql(format)

server.on('request', function(req) {
server.once('request', function(req) {
expect(req.headers[option]).to.eql(format)

@@ -212,3 +212,3 @@ done()

server.on('request', function(req) {
server.once('request', function(req) {
expect(req.headers[option]).to.eql(format)

@@ -226,3 +226,3 @@ done()

server.on('request', function(req, res) {
server.once('request', function(req, res) {
res.setOption('Content-Format', format)

@@ -246,3 +246,3 @@ res.end()

server.on('request', function(req) {
server.once('request', function(req) {
expect(req.options[0].name).to.equal('Content-Format')

@@ -260,3 +260,3 @@ expect(req.options[0].value).to.equal('application/json')

server.on('request', function(req) {
server.once('request', function(req) {
expect(req.options[0].name).to.equal('Max-Age')

@@ -276,3 +276,3 @@ expect(req.options[0].value).to.equal(26763)

server.on('request', function(req, res) {
server.once('request', function(req, res) {
res.writeHead(200, {'Content-Format': 'application/json'})

@@ -279,0 +279,0 @@ res.write(JSON.stringify({}))

@@ -82,7 +82,8 @@ /*

var req = request('coap://aaa.eee:' + 1234)
req.end(new Buffer('hello world'))
req.on('error', function () {
req.once('error', function () {
done()
})
req.end(new Buffer('hello world'))
})

@@ -718,3 +719,3 @@

fastForward(100, 45 * 1000)
fastForward(20, 45 * 1000)
})

@@ -835,3 +836,3 @@

fastForward(100, 45 * 1000)
fastForward(20, 45 * 1000)
})

@@ -838,0 +839,0 @@

@@ -468,18 +468,23 @@ /*

it('should calculate the response twice after the interval', function(done) {
var now = Date.now()
send(generate(packet))
var first = true
var delay = (params.exchangeLifetime * 1000)+1
server.once('request', function(req, res) {
res.end('42')
server.on('request', function(req, res) {
var now = Date.now()
clock.restore()
tk.travel(now + params.exchangeLifetime * 1000)
if (first) {
res.end('42')
first = false
setTimeout(function() {
send(generate(packet))
}, delay)
server.on('request', function(req, res) {
fastForward(100, delay)
} else {
res.end('24')
done()
})
}
})
send(generate(packet))
})
send(generate(packet))
})

@@ -1098,1 +1103,61 @@

})
describe('server LRU', function() {
var server
, port
, clientPort
, client
, clock
var packet = {
confirmable: true
, messageId: 4242
, token: new Buffer(5)
}
beforeEach(function (done) {
clock = sinon.useFakeTimers()
port = nextPort()
server = coap.createServer()
server.listen(port, done)
})
beforeEach(function (done) {
clientPort = nextPort()
client = dgram.createSocket('udp4')
client.bind(clientPort, done)
})
afterEach(function () {
clock.restore()
client.close()
server.close()
tk.reset()
})
function send(message) {
client.send(message, 0, message.length, port, '127.0.0.1')
}
it('should remove old packets after < exchangeLifetime x 1.5', function (done) {
var messages = 0
send(generate(packet))
server.on('request', function (req, res) {
var now = Date.now()
res.end()
expect(server._lru.itemCount, 1)
clock.tick(params.exchangeLifetime * 500)
expect(server._lru.itemCount, 1)
clock.tick(params.exchangeLifetime * 1000)
expect(server._lru.itemCount, 0)
done()
})
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc