From 26d7dd31246c289dd8db2c6910e1ce85d1209edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Rojas?= Date: Sat, 22 Apr 2017 14:47:30 +0300 Subject: [PATCH] Cache public keys for the duration of the agent This saves a lot of time when connecting to multiple hosts simultaneously (e.g., during a deploy) as every time we are asked to sign a challenge, all public keys are iterated to find the correct one. This can become especially slow when using the Bridge transport and/or many identities are defined. --- trezor_agent/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trezor_agent/__main__.py b/trezor_agent/__main__.py index eedcd61..263fd91 100644 --- a/trezor_agent/__main__.py +++ b/trezor_agent/__main__.py @@ -147,8 +147,9 @@ class JustInTimeConnection(object): """Create a JIT connection object.""" self.conn_factory = conn_factory self.identities = identities + self.public_keys = util.memoize(self._public_keys) # a simple cache - def public_keys(self): + def _public_keys(self): """Return a list of SSH public keys (in textual format).""" conn = self.conn_factory() return [conn.get_public_key(i) for i in self.identities]