Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _handlePush ({ connection, stream }) {
const [data] = await pipe(
stream,
lp.decode(),
take(1),
toBuffer,
collect
)
let message
try {
message = Message.decode(data)
} catch (err) {
return log.error('received invalid message', err)
}
// Update the listen addresses
const peerInfo = new PeerInfo(connection.remotePeer)
try {
async _processMessages (idB58Str, conn, peer) {
const onRpcFunc = this._onRpc
try {
await pipe(
conn,
lp.decode(),
async function (source) {
for await (const data of source) {
const rpc = Buffer.isBuffer(data) ? data : data.slice()
onRpcFunc(idB58Str, message.rpc.RPC.decode(rpc))
}
}
)
} catch (err) {
this._onPeerDisconnected(peer, err)
}
}
async identify (connection) {
const { stream } = await connection.newStream(MULTICODEC_IDENTIFY)
const [data] = await pipe(
stream,
lp.decode(),
take(1),
toBuffer,
collect
)
if (!data) {
throw errCode(new Error('No data could be retrieved'), codes.ERR_CONNECTION_ENDED)
}
let message
try {
message = Message.decode(data)
} catch (err) {
throw errCode(err, codes.ERR_INVALID_MESSAGE)
}