Skip to content

Commit

Permalink
customize coap timing settings
Browse files Browse the repository at this point in the history
  • Loading branch information
neophob committed Mar 18, 2016
1 parent ee044f8 commit bb343ea
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 34 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ first ten come from different ports.
* <a href="#agent"><code>coap.<b>Agent</b></code></a>
* <a href="#globalAgent"><code>coap.<b>globalAgent</b></code></a>
* <a href="#globalAgentIPv6"><code>coap.<b>globalAgentIPv6</b></code></a>
* <a href="#updateTiming"><code>coap.<b>updateTiming</b></code></a>
* <a href="#defaultTiming"><code>coap.<b>defaultTiming</b></code></a>

-------------------------------------------------------
<a name="request"></a>
Expand Down Expand Up @@ -217,7 +219,7 @@ The constructor can be given an optional options object, containing one of the f
* `proxy`: indicates that the server should behave like a proxy for incoming requests containing the `Proxy-Uri` header.
An example of how the proxy feature works, refer to the example in the `/examples` folder. Defaults to `false`.
* `multicastAddress`: Optional. Use this in order to force server to listen on multicast address
* `multicastInterface`: Optional. Use this in order to force server to listen on multicast interface. This is only applicable
* `multicastInterface`: Optional. Use this in order to force server to listen on multicast interface. This is only applicable
if `multicastAddress` is set. If absent, server will try to listen `multicastAddress` on all available interfaces
* `piggybackReplyMs`: set the number of milliseconds to wait for a
biggyback response. Default 50.
Expand All @@ -226,7 +228,7 @@ The constructor can be given an optional options object, containing one of the f

`function (request, response) { }`

Emitted each time there is a request.
Emitted each time there is a request.
`request` is an instance of <a
href='#incoming'><code>IncomingMessage</code></a> and `response` is
an instance of <a
Expand Down Expand Up @@ -418,7 +420,7 @@ Information about the socket used for the communication (address and port).
<a name="observewrite"></a>
### ObserveWriteStream

An `ObserveWriteStream` object is
An `ObserveWriteStream` object is
emitted by the `coap.createServer` `'response'` event as a response
object.
It may be used to set response status, headers and stream changing data
Expand Down Expand Up @@ -503,6 +505,30 @@ The default [`Agent`](#agent) for IPv4.

The default [`Agent`](#agent) for IPv6.

-------------------------------------------------------
<a name="updateTiming"></a>
### coap.updateTiming

You can update the CoAP timing settings, take a look at the examples:

```js
var coapTiming = {
ackTimeout:0.25,
ackRandomFactor: 1.0,
maxRetransmit: 3,
probingRate: 1,
maxLatency: 2,
piggybackReplyMs: 10
};
coap.updateTiming(coapTiming);
```

-------------------------------------------------------
<a name="defaultTiming"></a>
### coap.defaultTiming

Reset the CoAP timings to the default values

<a name="contributing"></a>
## Contributing

Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ module.exports.registerFormat = optionsConv.registerFormat
module.exports.ignoreOption = optionsConv.ignoreOption

module.exports.parameters = parameters
module.exports.updateTiming = parameters.refreshTiming
module.exports.defaultTiming = parameters.defaultTiming
71 changes: 40 additions & 31 deletions lib/parameters.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
/*
* Copyright (c) 2013-2015 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.
*/
* Copyright (c) 2013-2015 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.
*/

// CoAP parameters
var p = {
ackTimeout: 2 // seconds
ackTimeout: 2 // seconds
, ackRandomFactor: 1.5
, maxRetransmit: 4
, nstart: 1
, defaultLeisure: 5
, probingRate: 1 // byte/seconds

// MAX_LATENCY is the maximum time a datagram is expected to take
// from the start of its transmission to the completion of its
// reception.
, maxLatency: 100 // seconds

, piggybackReplyMs: 50
// default coap port
, coapPort: 5683
// default max packet size
, maxPacketSize: 1280
}
var defaultTiming = JSON.parse(JSON.stringify(p))

// MAX_TRANSMIT_SPAN is the maximum time from the first transmission
// of a Confirmable message to its last retransmission.
p.maxTransmitSpan = p.ackTimeout * ((Math.pow(2, p.maxRetransmit)) - 1) * p.ackRandomFactor
p.refreshTiming = function(values) {
for (var key in values){
if (p[key]) {
p[key] = values[key]
}
}

// MAX_TRANSMIT_WAIT is the maximum time from the first transmission
// of a Confirmable message to the time when the sender gives up on
// receiving an acknowledgement or reset.
p.maxTransmitWait = p.ackTimeout * (Math.pow(2, p.maxRetransmit + 1) - 1) * p.ackRandomFactor
// MAX_TRANSMIT_SPAN is the maximum time from the first transmission
// of a Confirmable message to its last retransmission.
p.maxTransmitSpan = p.ackTimeout * ((Math.pow(2, p.maxRetransmit)) - 1) * p.ackRandomFactor

// MAX_TRANSMIT_WAIT is the maximum time from the first transmission
// of a Confirmable message to the time when the sender gives up on
// receiving an acknowledgement or reset.
p.maxTransmitWait = p.ackTimeout * (Math.pow(2, p.maxRetransmit + 1) - 1) * p.ackRandomFactor

// PROCESSING_DELAY is the time a node takes to turn around a
// Confirmable message into an acknowledgement.
p.processingDelay = p.ackTimeout
// PROCESSING_DELAY is the time a node takes to turn around a
// Confirmable message into an acknowledgement.
p.processingDelay = p.ackTimeout

// MAX_RTT is the maximum round-trip time
p.maxRTT = 2 * p.maxLatency + p.processingDelay
// MAX_RTT is the maximum round-trip time
p.maxRTT = 2 * p.maxLatency + p.processingDelay

// EXCHANGE_LIFETIME is the time from starting to send a Confirmable
// message to the time when an acknowledgement is no longer expected,
// i.e. message layer information about the message exchange can be
// purged
p.exchangeLifetime = p.maxTransmitSpan + p.maxRTT
// EXCHANGE_LIFETIME is the time from starting to send a Confirmable
// message to the time when an acknowledgement is no longer expected,
// i.e. message layer information about the message exchange can be
// purged
p.exchangeLifetime = p.maxTransmitSpan + p.maxRTT
}
p.refreshTiming()

// default port for CoAP
p.coapPort = 5683

// default max packet size
p.maxPacketSize = 1280
p.defaultTiming = function() {
p.refreshTiming(defaultTiming)
}

module.exports = p

0 comments on commit bb343ea

Please sign in to comment.