Skip to content

Commit fccf08e

Browse files
authored
Merge pull request #1617 from matrix-org/jryans/crypto-store-logging
Add logging to crypto store transactions
2 parents 2cdc68f + f43fe36 commit fccf08e

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/crypto/OlmDevice.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
1818

19-
import {logger} from '../logger';
19+
import {getPrefixedLogger, logger} from '../logger';
2020
import {IndexedDBCryptoStore} from './store/indexeddb-crypto-store';
2121
import * as algorithms from './algorithms';
2222

@@ -545,6 +545,7 @@ OlmDevice.prototype.createOutboundSession = async function(
545545
}
546546
});
547547
},
548+
getPrefixedLogger("[createOutboundSession]"),
548549
);
549550
return newSessionId;
550551
};
@@ -605,6 +606,7 @@ OlmDevice.prototype.createInboundSession = async function(
605606
}
606607
});
607608
},
609+
getPrefixedLogger("[createInboundSession]"),
608610
);
609611

610612
return result;
@@ -638,6 +640,7 @@ OlmDevice.prototype.getSessionIdsForDevice = async function(theirDeviceIdentityK
638640
},
639641
);
640642
},
643+
getPrefixedLogger("[getSessionIdsForDevice]"),
641644
);
642645

643646
return sessionIds;
@@ -727,6 +730,7 @@ OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey,
727730
}
728731
});
729732
},
733+
getPrefixedLogger("[getSessionInfoForDevice]"),
730734
);
731735

732736
return info;
@@ -761,6 +765,7 @@ OlmDevice.prototype.encryptMessage = async function(
761765
this._saveSession(theirDeviceIdentityKey, sessionInfo, txn);
762766
});
763767
},
768+
getPrefixedLogger("[encryptMessage]"),
764769
);
765770
return res;
766771
};
@@ -794,6 +799,7 @@ OlmDevice.prototype.decryptMessage = async function(
794799
this._saveSession(theirDeviceIdentityKey, sessionInfo, txn);
795800
});
796801
},
802+
getPrefixedLogger("[decryptMessage]"),
797803
);
798804
return payloadString;
799805
};
@@ -825,6 +831,7 @@ OlmDevice.prototype.matchesSession = async function(
825831
matches = sessionInfo.session.matches_inbound(ciphertext);
826832
});
827833
},
834+
getPrefixedLogger("[matchesSession]"),
828835
);
829836
return matches;
830837
};
@@ -1095,6 +1102,7 @@ OlmDevice.prototype.addInboundGroupSession = async function(
10951102
},
10961103
);
10971104
},
1105+
getPrefixedLogger("[addInboundGroupSession]"),
10981106
);
10991107
};
11001108

@@ -1265,6 +1273,7 @@ OlmDevice.prototype.decryptGroupMessage = async function(
12651273
},
12661274
);
12671275
},
1276+
getPrefixedLogger("[decryptGroupMessage]"),
12681277
);
12691278

12701279
if (error) {
@@ -1310,6 +1319,7 @@ OlmDevice.prototype.hasInboundSessionKeys = async function(roomId, senderKey, se
13101319
},
13111320
);
13121321
},
1322+
getPrefixedLogger("[hasInboundSessionKeys]"),
13131323
);
13141324

13151325
return result;
@@ -1369,6 +1379,7 @@ OlmDevice.prototype.getInboundGroupSessionKey = async function(
13691379
},
13701380
);
13711381
},
1382+
getPrefixedLogger("[getInboundGroupSessionKey]"),
13721383
);
13731384

13741385
return result;

src/crypto/store/indexeddb-crypto-store-backend.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class Backend {
3434
*/
3535
constructor(db) {
3636
this._db = db;
37+
this._nextTxnId = 0;
3738

3839
// make sure we close the db on `onversionchange` - otherwise
3940
// attempts to delete the database will block (and subsequent
@@ -757,10 +758,21 @@ export class Backend {
757758
}));
758759
}
759760

760-
doTxn(mode, stores, func) {
761+
doTxn(mode, stores, func, log = logger) {
762+
const txnId = this._nextTxnId++;
763+
const startTime = Date.now();
764+
const description = `${mode} crypto store transaction ${txnId} in ${stores}`;
765+
log.debug(`Starting ${description}`);
761766
const txn = this._db.transaction(stores, mode);
762767
const promise = promiseifyTxn(txn);
763768
const result = func(txn);
769+
promise.then(() => {
770+
const elapsedTime = Date.now() - startTime;
771+
log.debug(`Finished ${description}, took ${elapsedTime} ms`);
772+
}, () => {
773+
const elapsedTime = Date.now() - startTime;
774+
log.error(`Failed ${description}, took ${elapsedTime} ms`);
775+
});
764776
return promise.then(() => {
765777
return result;
766778
});

src/crypto/store/indexeddb-crypto-store.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,16 @@ export class IndexedDBCryptoStore {
596596
* @param {function(*)} func Function called with the
597597
* transaction object: an opaque object that should be passed
598598
* to store functions.
599+
* @param {object} [log] A possibly customised log
599600
* @return {Promise} Promise that resolves with the result of the `func`
600601
* when the transaction is complete. If the backend is
601602
* async (ie. the indexeddb backend) any of the callback
602603
* functions throwing an exception will cause this promise to
603604
* reject with that exception. On synchronous backends, the
604605
* exception will propagate to the caller of the getFoo method.
605606
*/
606-
doTxn(mode, stores, func) {
607-
return this._backend.doTxn(mode, stores, func);
607+
doTxn(mode, stores, func, log) {
608+
return this._backend.doTxn(mode, stores, func, log);
608609
}
609610
}
610611

0 commit comments

Comments
 (0)