Skip to content

Commit

Permalink
clean ws_server
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed May 31, 2022
1 parent e9cb7d1 commit 0155ea8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
7 changes: 1 addition & 6 deletions kong/clustering/control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local _MT = { __index = _M, }


local semaphore = require("ngx.semaphore")
local ws_server = require("resty.websocket.server")
local cjson = require("cjson.safe")
local declarative = require("kong.db.declarative")
local utils = require("kong.tools.utils")
Expand Down Expand Up @@ -44,10 +43,6 @@ local ngx_ERR = ngx.ERR
local ngx_OK = ngx.OK
local ngx_ERROR = ngx.ERROR
local ngx_CLOSE = ngx.HTTP_CLOSE
local WS_OPTS = {
timeout = constants.CLUSTERING_TIMEOUT,
max_payload_len = kong.configuration.cluster_max_payload,
}
local PING_INTERVAL = constants.CLUSTERING_PING_INTERVAL
local PING_WAIT = PING_INTERVAL * 1.5
local CLUSTERING_SYNC_STATUS = constants.CLUSTERING_SYNC_STATUS
Expand Down Expand Up @@ -300,7 +295,7 @@ function _M:handle_cp_websocket()
ngx_exit(400)
end

local wb, err = ws_server:new(WS_OPTS)
local wb, err = clustering_utils.connect_dp()
if not wb then
ngx_log(ngx_ERR, _log_prefix, "failed to perform server side websocket handshake: ", err, log_suffix)
return ngx_exit(ngx_CLOSE)
Expand Down
6 changes: 6 additions & 0 deletions kong/clustering/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local ssl = require("ngx.ssl")
local ocsp = require("ngx.ocsp")
local http = require("resty.http")
local ws_client = require("resty.websocket.client")
local ws_server = require("resty.websocket.server")

local type = type
local tonumber = tonumber
Expand Down Expand Up @@ -390,4 +391,9 @@ function _M.connect_cp(endpoint, conf, cert, cert_key, protocols)
end


function _M.connect_dp()
return ws_server:new(WS_OPTS)
end


return _M
8 changes: 1 addition & 7 deletions kong/clustering/wrpc_control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local _MT = { __index = _M, }


local semaphore = require("ngx.semaphore")
local ws_server = require("resty.websocket.server")
local cjson = require("cjson.safe")
local declarative = require("kong.db.declarative")
local constants = require("kong.constants")
Expand Down Expand Up @@ -35,11 +34,6 @@ local ngx_NOTICE = ngx.NOTICE
local ngx_WARN = ngx.WARN
local ngx_ERR = ngx.ERR
local ngx_CLOSE = ngx.HTTP_CLOSE
local MAX_PAYLOAD = constants.CLUSTERING_MAX_PAYLOAD
local WS_OPTS = {
timeout = constants.CLUSTERING_TIMEOUT,
max_payload_len = MAX_PAYLOAD,
}
local CLUSTERING_SYNC_STATUS = constants.CLUSTERING_SYNC_STATUS
local _log_prefix = "[wrpc-clustering] "

Expand Down Expand Up @@ -216,7 +210,7 @@ function _M:handle_cp_websocket()
local wb
do
local err
wb, err = ws_server:new(WS_OPTS)
wb, err = clustering_utils.connect_dp()
if not wb then
ngx_log(ngx_ERR, _log_prefix, "failed to perform server side websocket handshake: ", err, log_suffix)
return ngx_exit(ngx_CLOSE)
Expand Down

0 comments on commit 0155ea8

Please sign in to comment.