Comparing version 0.7.0 to 0.7.1
16
index.js
@@ -9,10 +9,10 @@ /* | ||
const optionsConv = require('./lib/option_converter') | ||
, Server = require('./lib/server') | ||
, Agent = require('./lib/agent') | ||
, parameters = require('./lib/parameters') | ||
, net = require('net') | ||
, URL = require('url') | ||
, globalAgent = new Agent({ type: 'udp4' }) | ||
, globalAgentV6 = new Agent({ type: 'udp6' }) | ||
var optionsConv = require('./lib/option_converter') | ||
, Server = require('./lib/server') | ||
, Agent = require('./lib/agent') | ||
, parameters = require('./lib/parameters') | ||
, net = require('net') | ||
, URL = require('url') | ||
, globalAgent = new Agent({ type: 'udp4' }) | ||
, globalAgentV6 = new Agent({ type: 'udp6' }) | ||
@@ -19,0 +19,0 @@ module.exports.request = function(url) { |
@@ -9,20 +9,20 @@ /* | ||
const bl = require('bl') | ||
, util = require('util') | ||
, events = require('events') | ||
, dgram = require('dgram') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, URL = require('url') | ||
, IncomingMessage = require('./incoming_message') | ||
, OutgoingMessage = require('./outgoing_message') | ||
, ObserveStream = require('./observe_read_stream') | ||
, parameters = require('./parameters') | ||
, optionsConv = require('./option_converter') | ||
, RetrySend = require('./retry_send') | ||
, parseBlock2 = require('./helpers').parseBlock2 | ||
, createBlock2 = require('./helpers').createBlock2 | ||
, getOption = require('./helpers').getOption | ||
, maxToken = Math.pow(2, 32) | ||
, maxMessageId = Math.pow(2, 16) | ||
var bl = require('bl') | ||
, util = require('util') | ||
, events = require('events') | ||
, dgram = require('dgram') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, URL = require('url') | ||
, IncomingMessage = require('./incoming_message') | ||
, OutgoingMessage = require('./outgoing_message') | ||
, ObserveStream = require('./observe_read_stream') | ||
, parameters = require('./parameters') | ||
, optionsConv = require('./option_converter') | ||
, RetrySend = require('./retry_send') | ||
, parseBlock2 = require('./helpers').parseBlock2 | ||
, createBlock2 = require('./helpers').createBlock2 | ||
, getOption = require('./helpers').getOption | ||
, maxToken = Math.pow(2, 32) | ||
, maxMessageId = Math.pow(2, 16) | ||
@@ -29,0 +29,0 @@ function Agent(opts) { |
@@ -9,10 +9,10 @@ /* | ||
const toBinary = require('./option_converter').toBinary | ||
, fromBinary = require('./option_converter').fromBinary | ||
, codes = { | ||
'0.01': 'GET' | ||
, '0.02': 'POST' | ||
, '0.03': 'PUT' | ||
, '0.04': 'DELETE' | ||
} | ||
var toBinary = require('./option_converter').toBinary | ||
, fromBinary = require('./option_converter').fromBinary | ||
, codes = { | ||
'0.01': 'GET' | ||
, '0.02': 'POST' | ||
, '0.03': 'PUT' | ||
, '0.04': 'DELETE' | ||
} | ||
@@ -19,0 +19,0 @@ module.exports.genAck = function(request) { |
@@ -9,5 +9,5 @@ /* | ||
const Readable = require('stream').Readable | ||
, util = require('util') | ||
, pktToMsg = require('./helpers').packetToMessage | ||
var Readable = require('stream').Readable | ||
, util = require('util') | ||
, pktToMsg = require('./helpers').packetToMessage | ||
@@ -14,0 +14,0 @@ function IncomingMessage(packet) { |
@@ -9,5 +9,5 @@ /* | ||
const Readable = require('stream').Readable | ||
, util = require('util') | ||
, pktToMsg = require('./helpers').packetToMessage | ||
var Readable = require('stream').Readable | ||
, util = require('util') | ||
, pktToMsg = require('./helpers').packetToMessage | ||
@@ -14,0 +14,0 @@ function ObserveReadStream(packet) { |
@@ -9,6 +9,6 @@ /* | ||
const Writable = require('stream').Writable | ||
, util = require('util') | ||
, helpers = require('./helpers') | ||
, toCode = helpers.toCode | ||
var Writable = require('stream').Writable | ||
, util = require('util') | ||
, helpers = require('./helpers') | ||
, toCode = helpers.toCode | ||
@@ -15,0 +15,0 @@ function ObserveWriteStream(request, send) { |
@@ -9,6 +9,6 @@ /* | ||
const BufferList = require('bl') | ||
, util = require('util') | ||
, helpers = require('./helpers') | ||
, toCode = helpers.toCode | ||
var BufferList = require('bl') | ||
, util = require('util') | ||
, helpers = require('./helpers') | ||
, toCode = helpers.toCode | ||
@@ -15,0 +15,0 @@ function OutgoingMessage(request, send) { |
@@ -9,5 +9,5 @@ /* | ||
const parameters = require('./parameters') | ||
, util = require('util') | ||
, EventEmitter = require('events').EventEmitter | ||
var parameters = require('./parameters') | ||
, util = require('util') | ||
, EventEmitter = require('events').EventEmitter | ||
@@ -14,0 +14,0 @@ function RetrySend(sock, port, host) { |
@@ -9,16 +9,17 @@ /* | ||
const dgram = require('dgram') | ||
, util = require('util') | ||
, events = require('events') | ||
, LRU = require('lru-cache') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, IncomingMessage = require('./incoming_message') | ||
, OutgoingMessage = require('./outgoing_message') | ||
, ObserveStream = require('./observe_write_stream') | ||
, parameters = require('./parameters') | ||
, RetrySend = require('./retry_send') | ||
, parseBlock2 = require('./helpers').parseBlock2 | ||
, createBlock2 = require('./helpers').createBlock2 | ||
, getOption = require('./helpers').getOption | ||
var dgram = require('dgram') | ||
, net = require('net') | ||
, util = require('util') | ||
, events = require('events') | ||
, LRU = require('lru-cache') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, IncomingMessage = require('./incoming_message') | ||
, OutgoingMessage = require('./outgoing_message') | ||
, ObserveStream = require('./observe_write_stream') | ||
, parameters = require('./parameters') | ||
, RetrySend = require('./retry_send') | ||
, parseBlock2 = require('./helpers').parseBlock2 | ||
, createBlock2 = require('./helpers').createBlock2 | ||
, getOption = require('./helpers').getOption | ||
@@ -38,17 +39,4 @@ function CoAPServer(options, listener) { | ||
if (!options.type) | ||
options.type = 'udp4' | ||
this._options = options | ||
var that = this | ||
this._sock = dgram.createSocket(options.type, function(msg, rsinfo) { | ||
var packet | ||
try { | ||
packet = parse(msg) | ||
} catch(err) { | ||
return that._sendError(new Buffer('Unable to parse packet'), rsinfo) | ||
} | ||
that._handle(packet, rsinfo) | ||
}) | ||
// We use an LRU cache for the responses to avoid | ||
@@ -85,2 +73,6 @@ // DDOS problems. | ||
CoAPServer.prototype.listen = function(port, address, done) { | ||
if (port == undefined) { | ||
port = parameters.coapPort | ||
} | ||
if (typeof port === 'function') { | ||
@@ -96,3 +88,27 @@ done = port | ||
this._sock.bind(port, address || null, done) | ||
if (this._sock && done) | ||
done(new Error('Already listening')) | ||
else if (this._sock) | ||
throw new Error('Already listening') | ||
if (address && net.isIPv6(address)) | ||
this._options.type = 'udp6' | ||
if (!this._options.type) | ||
this._options.type = 'udp4' | ||
var that = this | ||
this._sock = dgram.createSocket(this._options.type, function(msg, rsinfo) { | ||
var packet | ||
try { | ||
packet = parse(msg) | ||
} catch(err) { | ||
return that._sendError(new Buffer('Unable to parse packet'), rsinfo) | ||
} | ||
that._handle(packet, rsinfo) | ||
}) | ||
this._sock.bind(port, address || null, done || null) | ||
this._port = port | ||
@@ -99,0 +115,0 @@ this._address = address |
{ | ||
"name": "coap", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "A CoAP library for node modelled after 'http'", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,4 +6,5 @@ node-coap | ||
Status](https://travis-ci.org/mcollina/node-coap.png)](https://travis-ci.org/mcollina/node-coap) | ||
[![gitter](https://badges.gitter.im/mcollina/node-coap.png)](https://gitter.im/mcollina/node-coap) | ||
__node-coap__ is an _highly experimental_ client and server library for CoAP modelled after the `http` module. | ||
__node-coap__ is a client and server library for CoAP modelled after the `http` module. | ||
@@ -40,3 +41,3 @@ * <a href="#intro">Introduction</a> | ||
If you need a command line interface for CoAP, check out | ||
[coap-cli](http://github.com/mcollna/coap-cli). | ||
[coap-cli](http://github.com/mcollina/coap-cli). | ||
@@ -43,0 +44,0 @@ **node-coap** is an **OPEN Open Source Project**, see the <a href="#contributing">Contributing</a> section to find out what this means. |
@@ -0,9 +1,16 @@ | ||
/* | ||
* Copyright (c) 2013-2014 node-coap contributors. | ||
* | ||
* node-coap is licensed under an MIT +no-false-attribs license. | ||
* All rights not explicitly granted in the MIT license are reserved. | ||
* See the included LICENSE file for more details. | ||
*/ | ||
const coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
, bl = require('bl') | ||
, sinon = require('sinon') | ||
, request = coap.request | ||
var coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
, bl = require('bl') | ||
, sinon = require('sinon') | ||
, request = coap.request | ||
@@ -10,0 +17,0 @@ describe('Agent', function() { |
@@ -0,3 +1,10 @@ | ||
/* | ||
* Copyright (c) 2013-2014 node-coap contributors. | ||
* | ||
* node-coap is licensed under an MIT +no-false-attribs license. | ||
* All rights not explicitly granted in the MIT license are reserved. | ||
* See the included LICENSE file for more details. | ||
*/ | ||
const coap = require('../') | ||
var coap = require('../') | ||
@@ -4,0 +11,0 @@ describe('blockwise2', function() { |
@@ -0,1 +1,8 @@ | ||
/* | ||
* Copyright (c) 2013-2014 node-coap contributors. | ||
* | ||
* node-coap is licensed under an MIT +no-false-attribs license. | ||
* All rights not explicitly granted in the MIT license are reserved. | ||
* See the included LICENSE file for more details. | ||
*/ | ||
@@ -2,0 +9,0 @@ global.expect = require("chai").expect |
@@ -0,3 +1,10 @@ | ||
/* | ||
* Copyright (c) 2013-2014 node-coap contributors. | ||
* | ||
* node-coap is licensed under an MIT +no-false-attribs license. | ||
* All rights not explicitly granted in the MIT license are reserved. | ||
* See the included LICENSE file for more details. | ||
*/ | ||
const coap = require('../') | ||
var coap = require('../') | ||
@@ -4,0 +11,0 @@ describe('end-to-end', function() { |
@@ -1,5 +0,5 @@ | ||
const coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
var coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
@@ -17,7 +17,2 @@ describe('IPv6', function() { | ||
port = nextPort() | ||
server = coap.createServer({ type: 'udp6' }) | ||
server.listen(port, done) | ||
}) | ||
beforeEach(function(done) { | ||
clientPort = nextPort() | ||
@@ -37,8 +32,21 @@ client = dgram.createSocket('udp6') | ||
it('should receive a CoAP message', function(done) { | ||
send(generate()) | ||
server.on('request', function(req, res) { | ||
done() | ||
it('should receive a CoAP message specifying the type', function(done) { | ||
server = coap.createServer({ type: 'udp6' }, done) | ||
server.listen(port, function() { | ||
send(generate()) | ||
server.on('request', function(req, res) { | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('should automatically discover the type based on the host', function(done) { | ||
server = coap.createServer() | ||
server.listen(port, '::1', function() { | ||
send(generate()) | ||
server.on('request', function(req, res) { | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -45,0 +53,0 @@ |
@@ -1,9 +0,17 @@ | ||
const coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
, bl = require('bl') | ||
, sinon = require('sinon') | ||
, request = coap.request | ||
/* | ||
* Copyright (c) 2013-2014 node-coap contributors. | ||
* | ||
* node-coap is licensed under an MIT +no-false-attribs license. | ||
* All rights not explicitly granted in the MIT license are reserved. | ||
* See the included LICENSE file for more details. | ||
*/ | ||
var coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
, bl = require('bl') | ||
, sinon = require('sinon') | ||
, request = coap.request | ||
describe('request', function() { | ||
@@ -10,0 +18,0 @@ var server |
@@ -0,11 +1,18 @@ | ||
/* | ||
* Copyright (c) 2013-2014 node-coap contributors. | ||
* | ||
* node-coap is licensed under an MIT +no-false-attribs license. | ||
* All rights not explicitly granted in the MIT license are reserved. | ||
* See the included LICENSE file for more details. | ||
*/ | ||
const coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
, bl = require('bl') | ||
, request = coap.request | ||
, tk = require('timekeeper') | ||
, sinon = require('sinon') | ||
, params = require('../lib/parameters') | ||
var coap = require('../') | ||
, parse = require('coap-packet').parse | ||
, generate = require('coap-packet').generate | ||
, dgram = require('dgram') | ||
, bl = require('bl') | ||
, request = coap.request | ||
, tk = require('timekeeper') | ||
, sinon = require('sinon') | ||
, params = require('../lib/parameters') | ||
@@ -56,2 +63,13 @@ describe('server', function() { | ||
it('should listen when listen() has no argument ', function(done) { | ||
port = 5683 | ||
server.close() // refresh | ||
server = coap.createServer() | ||
server.on('request', function(req, res) { | ||
done() | ||
}) | ||
server.listen() | ||
send(generate()) | ||
}) | ||
it('should listen by default to 5683', function(done) { | ||
@@ -58,0 +76,0 @@ server.close() // we need to change port |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
121630
3331
462
8