@@ -93,16 +93,15 @@ export interface ConnectionOpts {
9393 getExpiry ?: ( destination : string ) => Date ,
9494 /**
9595 * Callback for the consumer to perform accounting and choose to fulfill an incoming ILP Prepare,
96- * given the identifier of the connection, sequence of the packet, and amount received .
96+ * given the amount received, a unique identifier for the packet, and `connectionTag` .
9797 *
9898 * If the returned Promise is resolved, the ILP Prepare will be fulfilled; if it is rejected,
9999 * the ILP Prepare will be rejected. The ILP Fulfill will be immediately sent back after
100100 * the Promise is resolved.
101101 *
102- * Note: the `packetId` should be used for uniqueness, but a misbehaving sender can trigger duplicates.
103- * If receiving a duplicate packet ID, that packet should be ignored and rejected.
102+ * Note: a misbehaving sender can trigger duplicate packetIds, which should be ignored and rejected.
104103 */
105- shouldFulfill ?: ( packetAmount : Long , packetId : string , connectionTag ?: string ) => Promise < void > ,
104+ shouldFulfill ?: ( packetAmount : Long , packetId : Buffer , connectionTag ?: string ) => Promise < void > ,
106105}
107106
108107export interface BuildConnectionOpts extends ConnectionOpts {
@@ -197,14 +196,14 @@ export class Connection extends EventEmitter {
197196 protected _totalDelivered : Long
198197 protected _lastPacketExchangeRate : Rational
199198 protected getExpiry : ( destination : string ) => Date
200- protected shouldFulfill ?: ( packetAmount : Long , packetId : string , connectionTag ?: string ) => Promise < void >
199+ protected shouldFulfill ?: ( packetAmount : Long , packetId : Buffer , connectionTag ?: string ) => Promise < void >
201200
202201 constructor ( opts : NewConnectionOpts ) {
203202 super ( )
204203
205204 // Use the same connectionId for logging on both client & server
206205 const lastAddressSegment = opts . destinationAccount ? opts . destinationAccount . split ( '.' ) . slice ( - 1 ) [ 0 ] : undefined
207- this . connectionId = ( opts . connectionId || lastAddressSegment || uuid ( ) ) . slice ( 0 , 8 )
206+ this . connectionId = ( opts . connectionId || lastAddressSegment || uuid ( ) ) . replace ( / [ - _ ] / g , '' ) . slice ( 0 , 8 )
208207
209208 this . plugin = opts . plugin
210209 this . _sourceAccount = opts . sourceAccount
@@ -652,7 +651,7 @@ export class Connection extends EventEmitter {
652651 // Allow consumer to choose to fulfill each packet and/or perform other logic before fulfilling
653652 if ( this . shouldFulfill && incomingAmount . greaterThan ( 0 ) ) {
654653 const packetId = await cryptoHelper . generateIncomingPacketId ( this . sharedSecret , requestPacket . sequence )
655- await this . shouldFulfill ( incomingAmount , packetId . toString ( ) , this . connectionTag ) . catch ( async err => {
654+ await this . shouldFulfill ( incomingAmount , packetId , this . connectionTag ) . catch ( async err => {
656655 this . removeIncomingHold ( incomingAmount )
657656 this . log . debug ( 'application declined to fulfill packet %s:' , requestPacket . sequence , err )
658657 await throwFinalApplicationError ( )
0 commit comments