浏览代码

Merge pull request #7481 from jitsi/aaronkvanmeerten/token-util-cache-in-object

FEAT: jwt pubkey cache inside object
master
Aaron van Meerten 5 年前
父节点
当前提交
21767fa7cf
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 11 次插入4 次删除
  1. 11
    4
      resources/prosody-plugins/token/util.lib.lua

+ 11
- 4
resources/prosody-plugins/token/util.lib.lua 查看文件

19
 
19
 
20
 -- TODO: Figure out a less arbitrary default cache size.
20
 -- TODO: Figure out a less arbitrary default cache size.
21
 local cacheSize = module:get_option_number("jwt_pubkey_cache_size", 128);
21
 local cacheSize = module:get_option_number("jwt_pubkey_cache_size", 128);
22
-local cache = require"util.cache".new(cacheSize);
23
 
22
 
24
 local Util = {}
23
 local Util = {}
25
 Util.__index = Util
24
 Util.__index = Util
38
     self.asapKeyServer = module:get_option_string("asap_key_server");
37
     self.asapKeyServer = module:get_option_string("asap_key_server");
39
     self.allowEmptyToken = module:get_option_boolean("allow_empty_token");
38
     self.allowEmptyToken = module:get_option_boolean("allow_empty_token");
40
 
39
 
40
+    self.cache = require"util.cache".new(cacheSize);
41
+
41
     --[[
42
     --[[
42
         Multidomain can be supported in some deployments. In these deployments
43
         Multidomain can be supported in some deployments. In these deployments
43
         there is a virtual conference muc, which address contains the subdomain
44
         there is a virtual conference muc, which address contains the subdomain
108
 -- @param keyId the key ID to request
109
 -- @param keyId the key ID to request
109
 -- @return the public key (the content of requested resource) or nil
110
 -- @return the public key (the content of requested resource) or nil
110
 function Util:get_public_key(keyId)
111
 function Util:get_public_key(keyId)
111
-    local content = cache:get(keyId);
112
+    local content = self.cache:get(keyId);
112
     if content == nil then
113
     if content == nil then
113
         -- If the key is not found in the cache.
114
         -- If the key is not found in the cache.
114
         module:log("debug", "Cache miss for key: "..keyId);
115
         module:log("debug", "Cache miss for key: "..keyId);
117
         local function cb(content_, code_, response_, request_)
118
         local function cb(content_, code_, response_, request_)
118
             content, code = content_, code_;
119
             content, code = content_, code_;
119
             if code == 200 or code == 204 then
120
             if code == 200 or code == 204 then
120
-                cache:set(keyId, content);
121
+                self.cache:set(keyId, content);
122
+            else
123
+                module:log("warn", "Error on public key request: Code %s, Content %s",
124
+                code_, content_);
121
             end
125
             end
122
             done();
126
             done();
123
         end
127
         end
138
             -- TODO: This check is racey. Not likely to be a problem, but we should
142
             -- TODO: This check is racey. Not likely to be a problem, but we should
139
             --       still stick a mutex on content / code at some point.
143
             --       still stick a mutex on content / code at some point.
140
             if code == nil then
144
             if code == nil then
141
-                http.destroy_request(request);
145
+                -- no longer present in prosody 0.11, so check before calling
146
+                if http.destroy_request ~= nil then
147
+                    http.destroy_request(request);
148
+                end
142
                 done();
149
                 done();
143
             end
150
             end
144
         end
151
         end

正在加载...
取消
保存