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

Commit

Permalink
fix: comply with message framing spec (#123)
Browse files Browse the repository at this point in the history
fix: catch async pipe errors
  • Loading branch information
jacobheun authored Jul 8, 2020
1 parent 5649f44 commit 34c4844
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/handshake/finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const lp = require('it-length-prefixed')
const Wrap = require('it-pb-rpc')
const { int32BEEncode, int32BEDecode } = lp

// Maximum length of the data section of the message
// 8MB, https://github.com/libp2p/specs/blob/94ad1bd/secio/README.md#message-framing
const MAX_DATA_LENGTH = 0x800000

const etm = require('../etm')
const crypto = require('./crypto')

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

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

0 comments on commit 34c4844

Please sign in to comment.