Skip to content

Commit

Permalink
crc moved to separate module; fix bug in association establishment an…
Browse files Browse the repository at this point in the history
…d error in docs
  • Loading branch information
latysheff committed Jan 16, 2018
1 parent c4cd9f0 commit 628d2a0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 165 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.idea
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Application should globally provide raw-socket module as a transport.

`sctp.raw(require('raw-socket'))`

By the way, this doesn't prevent sctp to be used in mixed mode with UDP/DTLS,
This doesn't prevent sctp to be used in mixed mode with UDP/DTLS (see below),
but allows to remove direct dependency on binary module.

### Prerequisites for building [raw-socket] module
Expand Down Expand Up @@ -154,11 +154,13 @@ Set socket options related to write operations. Argument 'options' is an object
### sctp.raw(module)
* module Should be [raw-socket] module and nothing else.

`sctp.raw(require('raw-socket'))`

### sctp.setLogger(logger)
* logger Global logger for transport.

Example:
`sctp.transport(require('raw-socket'), console)`
`sctp.setLogger(console)`

### sctp.defaults(options)

Expand Down Expand Up @@ -233,7 +235,6 @@ socket.on('data', function (buffer) {

## Credits
* Inspiration and some ideas are taken from [smpp] module
* CRC algorithm ported from https://pycrc.org/

[raw-socket]: https://www.npmjs.com/package/raw-socket
[Net]: https://nodejs.org/api/net.html
Expand Down
4 changes: 2 additions & 2 deletions lib/association.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ class Association extends EventEmitter {
})

this.on('cookie_ack', () => {
this._up()
this.log('debug', '< CHUNK cookie_ack')
this.log('debug', '< CHUNK cookie_ack', this.state)
if (this.state === 'COOKIE-ECHOED') {
this._up()
this.emit('COMMUNICATION UP')
}
})
Expand Down
154 changes: 0 additions & 154 deletions lib/crc.js

This file was deleted.

6 changes: 3 additions & 3 deletions lib/packet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const crc32c = require('./crc').crc32c
const crc32c = require('polycrc').crc32c

class Packet {
constructor(headers, chunks) {
Expand All @@ -20,7 +20,7 @@ class Packet {
this.verification_tag = buffer.readUInt32BE(4)
this.checksum = buffer.readUInt32LE(8)
buffer.writeUInt32LE(0x00000000, 8)
if (this.checksum !== crc32c.calculate(buffer)) return
if (this.checksum !== crc32c(buffer)) return
let offset = 12
this.chunks = []
while (offset + 4 <= buffer.length) {
Expand Down Expand Up @@ -49,7 +49,7 @@ class Packet {
headers.writeUInt32BE(this.verification_tag, 4)
headers.writeUInt32LE(0x00000000, 8)
let buffer = Buffer.concat([headers, ...this.chunks])
this.checksum = crc32c.calculate(buffer, 0)
this.checksum = crc32c(buffer, 0)
buffer.writeUInt32LE(this.checksum, 8)
return buffer
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sctp",
"version": "0.0.6",
"version": "0.0.7",
"author": {
"name": "Vladimir Latyshev",
"email": "[email protected]"
Expand All @@ -10,7 +10,8 @@
},
"dependencies": {
"ip": "^1.1.5",
"lodash": "^4.17.4"
"lodash": "^4.17.4",
"polycrc": "^0.1.0"
},
"description": "SCTP network protocol (RFC4960) in plain Javascript",
"keywords": [
Expand Down

0 comments on commit 628d2a0

Please sign in to comment.