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

coap

Package Overview
Dependencies
Maintainers
1
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.8.0 to 0.9.0

examples/req_with_payload.js

11

lib/agent.js

@@ -53,2 +53,3 @@ /*

, message
, outSocket

@@ -63,3 +64,5 @@ try {

}
that._handle(msg, rsinfo)
outSocket = that._sock.address();
that._handle(msg, rsinfo, outSocket)
})

@@ -108,3 +111,3 @@

Agent.prototype._handle = function handle(msg, rsinfo) {
Agent.prototype._handle = function handle(msg, rsinfo, outSocket) {
var packet = parse(msg)

@@ -225,3 +228,3 @@ , buf

if (req.url.observe && packet.code !== '4.04') {
response = new ObserveStream(packet, rsinfo)
response = new ObserveStream(packet, rsinfo, outSocket)
response.on('close', function() {

@@ -232,3 +235,3 @@ delete that._tkToReq[packet.token.readUInt32BE(0)]

} else {
response = new IncomingMessage(packet, rsinfo)
response = new IncomingMessage(packet, rsinfo, outSocket)
}

@@ -235,0 +238,0 @@

@@ -9,7 +9,7 @@ /*

var Readable = require('stream').Readable
var Readable = require('readable-stream').Readable
, util = require('util')
, pktToMsg = require('./helpers').packetToMessage
function IncomingMessage(packet) {
function IncomingMessage(packet, rsinfo, outSocket) {
Readable.call(this)

@@ -19,2 +19,5 @@

this.rsinfo = rsinfo
this.outSocket = outSocket
this._packet = packet

@@ -21,0 +24,0 @@ this._payloadIndex = 0

@@ -9,9 +9,12 @@ /*

var Readable = require('stream').Readable
var Readable = require('readable-stream').Readable
, util = require('util')
, pktToMsg = require('./helpers').packetToMessage
function ObserveReadStream(packet) {
function ObserveReadStream(packet, rsinfo, outSocket) {
Readable.call(this, { objectMode: true })
this.rsinfo = rsinfo
this.outSocket = outSocket
this._lastId = 0

@@ -18,0 +21,0 @@ this.append(packet)

@@ -9,3 +9,3 @@ /*

var Writable = require('stream').Writable
var Writable = require('readable-stream').Writable
, util = require('util')

@@ -67,2 +67,17 @@ , helpers = require('./helpers')

ObserveWriteStream.prototype.reset = function reset() {
var packet = this._packet
packet.code = '0.00'
packet.payload = ''
packet.reset = true;
packet.ack = false
packet.token = new Buffer(0);
this._send(this, packet)
this._packet.confirmable = this._request.confirmable
delete this._packet.messageId
delete this._packet.payload
}
module.exports = ObserveWriteStream

@@ -79,2 +79,25 @@ /*

OutgoingMessage.prototype.reset = function() {
BufferList.prototype.end.call(this)
var packet = this._packet
, message
, that = this
packet.code = '0.00'
packet.payload = ''
packet.reset = true;
packet.ack = false
this._send(this, packet)
// easy clean up after generating the packet
delete this._packet.payload
if (this._ackTimer)
clearTimeout(this._ackTimer)
return this
}
module.exports = OutgoingMessage
{
"name": "coap",
"version": "0.8.0",
"version": "0.9.0",
"description": "A CoAP library for node modelled after 'http'",

@@ -39,4 +39,5 @@ "main": "index.js",

"coap-packet": "~0.1.12",
"lru-cache": "~2.5.0"
"lru-cache": "~2.5.0",
"readable-stream": "~1.0.33"
}
}

@@ -157,3 +157,3 @@ node-coap

`coap.request()` returns an instance of <a
href='#incoming'><code>IncomingMessage</code></a>.
href='#incoming'><code>OutgoingMessage</code></a>.
If you need

@@ -264,4 +264,3 @@ to add a payload, just `pipe` into it.

message.setOption("555", [new Buffer('abcde',
new Buffer('ghi')]);
message.setOption("555", [new Buffer('abcde'),new Buffer('ghi')]);

@@ -282,2 +281,5 @@ `setOption` is also aliased as `setHeader` for HTTP API

#### message.reset()
Returns a Reset COAP Message to the sender. The RST message will appear as an empty message with code `0.00` and the
reset flag set to `true` to the caller. This action ends the interaction with the caller.
-------------------------------------------------------

@@ -344,2 +346,7 @@ <a name="incoming"></a>

#### message.outSocket
Information about the socket used for the communication (address and port).
-------------------------------------------------------

@@ -365,2 +372,11 @@ <a name="observeread"></a>

#### message.rsinfo
The sender informations, as emitted by the socket.
See [the `dgram` docs](http://nodejs.org/api/dgram.html#dgram_event_message) for details
#### message.outSocket
Information about the socket used for the communication (address and port).
-------------------------------------------------------

@@ -388,2 +404,6 @@ <a name="observewrite"></a>

#### reset()
Returns a Reset COAP Message to the sender. The RST message will appear as an empty message with code `0.00` and the
reset flag set to `true` to the caller. This action ends the interaction with the caller.
-------------------------------------------------------

@@ -467,2 +487,3 @@ <a name="registerOption"></a>

<tr><th align="left">Nguyen Quoc Dinh</th><td><a href="https://github.com/nqd">GitHub/nqd</a></td><td><a href="https://twitter.com/nqdinh">Twitter/@nqdinh</a></td></tr>
<tr><th align="left">Daniel Moran Jimenez</th><td><a href="https://github.com/dmoranj">GitHub/nqd</a></td><td><a href="https://twitter.com/erzeneca">Twitter/@erzeneca</a></td></tr>
</tbody></table>

@@ -469,0 +490,0 @@

@@ -11,3 +11,3 @@ /*

var portCounter = 11043
var portCounter = 9042
global.nextPort = function() {

@@ -14,0 +14,0 @@ return ++portCounter

@@ -555,2 +555,28 @@ /*

it('should include original and destination socket information in the response', function(done) {
var req = request({
port: port
})
server.on('message', function(msg, rsinfo) {
var packet = parse(msg)
, toSend = generate({
messageId: packet.messageId
, token: packet.token
, options: []
})
server.send(toSend, 0, toSend.length, rsinfo.port, rsinfo.address)
})
req.on('response', function(res) {
expect(res).to.have.property('rsinfo')
expect(res).to.have.property('outSocket')
expect(res.outSocket).to.have.property('address')
expect(res.outSocket).to.have.property('port')
done()
})
req.end()
})
describe('non-confirmable retries', function() {

@@ -838,2 +864,18 @@ var clock

it('should send origin and destination socket data along with the response', function(done) {
var req = doObserve()
req.on('response', function(res) {
res.once('data', function(data) {
expect(res).to.have.property('rsinfo')
expect(res).to.have.property('outSocket')
expect(res.outSocket).to.have.property('address')
expect(res.outSocket).to.have.property('port')
res.close()
done()
})
})
})
it('should emit any more data after close', function(done) {

@@ -840,0 +882,0 @@

@@ -218,2 +218,18 @@ /*

it('should include a reset() function in the response', function(done) {
var buf = new Buffer(25)
send(generate({ payload: buf }))
client.on('message', function(msg, rinfo) {
var result = parse(msg)
expect(result.code).to.eql('0.00')
expect(result.reset).to.eql(true)
expect(result.ack).to.eql(false)
expect(result.payload.length).to.eql(0)
done()
});
server.on('request', function(req, res) {
res.reset()
})
})
var formatsString = {

@@ -765,2 +781,21 @@ 'text/plain': new Buffer([0])

it('should send a \'RST\' to the client if the msg.reset() method is invoked', function(done) {
var now = Date.now()
doObserve()
server.on('request', function(req, res) {
res.reset()
})
client.on('message', function(msg) {
var result = parse(msg)
expect(result.code).to.eql('0.00')
expect(result.reset).to.eql(true)
expect(result.ack).to.eql(false)
expect(result.payload.length).to.eql(0)
done();
})
})
it('should correctly generate two-byte long sequence numbers', function(done) {

@@ -767,0 +802,0 @@ var now = Date.now()

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