Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 34c4844

Browse files
authored
fix: comply with message framing spec (#123)
fix: catch async pipe errors
1 parent 5649f44 commit 34c4844

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/handshake/finish.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const lp = require('it-length-prefixed')
1010
const Wrap = require('it-pb-rpc')
1111
const { int32BEEncode, int32BEDecode } = lp
1212

13+
// Maximum length of the data section of the message
14+
// 8MB, https://github.com/libp2p/specs/blob/94ad1bd/secio/README.md#message-framing
15+
const MAX_DATA_LENGTH = 0x800000
16+
1317
const etm = require('../etm')
1418
const crypto = require('./crypto')
1519

@@ -28,10 +32,12 @@ module.exports = async function finish (state, wrapped) {
2832
etm.createBoxStream(proto.local.cipher, proto.local.mac),
2933
lp.encode({ lengthEncoder: int32BEEncode }),
3034
network, // and gets piped INTO and FROM the network
31-
lp.decode({ lengthDecoder: int32BEDecode }),
35+
lp.decode({ lengthDecoder: int32BEDecode, maxDataLength: MAX_DATA_LENGTH }),
3236
etm.createUnboxStream(proto.remote.cipher, proto.remote.mac),
3337
secure // and gets piped TO the user
34-
)
38+
).catch(err => {
39+
log.error('an error occurred in the crypto stream', err)
40+
})
3541

3642
// Exchange nonces over the encrypted stream for final verification
3743
const shake = Wrap(user)

0 commit comments

Comments
 (0)