Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
packetType: Packet.IlpPacketType.Prepare,
amount: '0',
frames: [new Packet.StreamMaxMoneyFrame(123, Long.MAX_UNSIGNED_VALUE, 456)]
},
buffer: 'AQwBAAEAAQESDwF7CQEAAAAAAAAAAAIByA==',
decode_only: true
})
// The send_max is set to `Long.MAX_UNSIGNED_VALUE + 1`.
fixtures.push({
name: 'frame:stream_money_blocked:send_max:too_big',
packet: {
sequence: '0',
packetType: Packet.IlpPacketType.Prepare,
amount: '0',
frames: [new Packet.StreamMoneyBlockedFrame(123, Long.MAX_UNSIGNED_VALUE, 456)]
},
buffer: 'AQwBAAEAAQETDwF7CQEAAAAAAAAAAAIByA==',
decode_only: true
})
console.log(JSON.stringify(fixtures, null, ' '))
this.log.debug('determined exchange rate to be %s with %d digits precision', exchangeRate, maxDigits)
this.exchangeRate = exchangeRate
return
}
// If we get here the first volley failed, try new volley using all unique packet amounts based on the max packets
testPacketAmounts = maxPacketAmounts
.filter((amount: any) => !amount.equals(Long.MAX_UNSIGNED_VALUE))
.reduce((acc: any, curr: any) => [...new Set([...acc, curr.toString()])], [])
// Check for any Txx Errors
if (packetErrors.some((error: any) => error.code[0] === 'T')) {
// Find the smallest packet amount we tried in case we ran into Txx errors
const smallestPacketAmount = packetErrors.reduce((min: Long, error: any) => {
return minLong(min, Long.fromNumber(error.sourceAmount, true))
}, Long.MAX_UNSIGNED_VALUE)
const reducedPacketAmount = smallestPacketAmount.subtract(smallestPacketAmount.divide(3))
this.log.debug('got Txx error(s), waiting %dms and reducing packet amount to %s before sending another test packet', retryDelay, reducedPacketAmount)
testPacketAmounts = [...testPacketAmounts, reducedPacketAmount]
await new Promise((resolve, reject) => setTimeout(resolve, retryDelay))
retryDelay *= RETRY_DELAY_INCREASE_FACTOR
}
this.log.debug('retry with packet amounts %j', testPacketAmounts)
}
throw new Error(`Unable to establish connection, no packets meeting the minimum exchange precision of ${this.minExchangeRatePrecision} digits made it through the path.`)
}
this.remoteMaxStreamId = frame.maxStreamId.toNumber()
break
case FrameType.ConnectionStreamIdBlocked:
this.log.trace('remote wants to open more streams but we are blocking them')
break
case FrameType.StreamClose:
this.handleStreamClose(frame)
break
case FrameType.StreamMaxMoney:
this.log.trace('peer told us that stream %s can receive up to: %s and has received: %s so far', frame.streamId, frame.receiveMax, frame.totalReceived)
stream = this.streams.get(frame.streamId.toNumber())
if (!stream) {
break
}
stream._remoteReceived = maxLong(stream._remoteReceived, frame.totalReceived)
if (stream._remoteReceiveMax.notEquals(Long.MAX_UNSIGNED_VALUE)) {
stream._remoteReceiveMax = maxLong(stream._remoteReceiveMax, frame.receiveMax)
} else {
stream._remoteReceiveMax = frame.receiveMax
}
if (stream._remoteReceiveMax.greaterThan(stream._remoteReceived)
&& stream._getAmountAvailableToSend().greaterThan(0)) {
/* tslint:disable-next-line:no-floating-promises */
this.startSendLoop()
}
break
case FrameType.StreamMoneyBlocked:
this.log.debug('peer told us that they want to send more money on stream %s but we are blocking them. they have sent: %s so far and want to send: %s', frame.streamId, frame.totalSent, frame.sendMax)
break
case FrameType.StreamData:
this.log.trace('got data for stream %s', frame.streamId)
it('should encode/decode uint 64', () => {
const values = [Long.MAX_UNSIGNED_VALUE.toString(), '0', '10', '518']
values.forEach((value) => {
const encoded = GdCom.putU64(value)
const decoded = GdCom.getU64(encoded)
expect(decoded.value).to.be.equal(value)
})
})
export function checkedAdd (a: Long, b: Long): {
sum: Long,
overflow: boolean
} {
const sum = a.add(b)
const overflow = sum.lessThan(a) || sum.lessThan(b)
return {
sum: overflow ? Long.MAX_UNSIGNED_VALUE : sum,
overflow
}
}
.filter((amount: any) => !amount.equals(Long.MAX_UNSIGNED_VALUE))
.reduce((acc: any, curr: any) => [...new Set([...acc, curr.toString()])], [])
export function checkedMultiply (a: Long, b: Long): {
product: Long,
overflow: boolean
} {
const product = a.multiply(b)
const overflow = product.lessThan(a) || product.lessThan(b)
return {
product: overflow ? Long.MAX_UNSIGNED_VALUE : product,
overflow
}
}
function saturatingReadVarUInt (reader: Reader): Long {
if (reader.peekVarOctetString().length > 8) {
reader.skipVarOctetString()
return Long.MAX_UNSIGNED_VALUE
} else {
return reader.readVarUIntLong()
}
}
constructor (opts: CongestionOptions) {
this._testMaximumPacketAmount = Long.MAX_UNSIGNED_VALUE
this._maximumPacketAmount = Long.MAX_UNSIGNED_VALUE
this._fixedPacketAmount = opts.maximumPacketAmount || Long.MAX_UNSIGNED_VALUE
}