Skip to content

Commit 2b6666c

Browse files
author
Kelven Yang
committed
Remove the dependency on VNC port for session management inside Console Proxy. This is to adapt Xen secure console support
1 parent 6c9fd60 commit 2b6666c

6 files changed

Lines changed: 44 additions & 27 deletions

File tree

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxy.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ public static ConsoleProxyClient getAjaxVncViewer(ConsoleProxyClientParam param,
397397
s_logger.info("Added viewer object " + viewer);
398398
reportLoadChange = true;
399399
} else if (!viewer.isFrontEndAlive()) {
400-
s_logger.info("The rfb thread died, reinitializing the viewer " +
401-
viewer);
400+
s_logger.info("The rfb thread died, reinitializing the viewer " + viewer);
402401
viewer.initClient(param);
403402
} else if (!param.getClientHostPassword().equals(viewer.getClientHostPassword())) {
404403
s_logger.warn("Bad sid detected(VNC port may be reused). sid in session: "

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClientBase.java‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ public abstract class ConsoleProxyClientBase implements ConsoleProxyClient, Cons
4343
protected Object tileDirtyEvent = new Object();
4444
protected TileTracker tracker;
4545
protected AjaxFIFOImageCache ajaxImageCache = new AjaxFIFOImageCache(2);
46-
46+
47+
/*
4748
protected String host;
4849
protected int port;
4950
protected String passwordParam;
5051
protected String tag = "";
51-
protected String ticket = "";
52+
protected String ticket = "";
53+
*/
54+
protected ConsoleProxyClientParam clientParam;
55+
5256
protected long createTime = System.currentTimeMillis();
5357
protected long lastFrontEndActivityTime = System.currentTimeMillis();
5458

@@ -105,22 +109,24 @@ public long getClientLastFrontEndActivityTime() {
105109

106110
@Override
107111
public String getClientHostAddress() {
108-
return host;
112+
return clientParam.getClientHostAddress();
109113
}
110114

111115
@Override
112116
public int getClientHostPort() {
113-
return port;
117+
return clientParam.getClientHostPort();
114118
}
115119

116120
@Override
117121
public String getClientHostPassword() {
118-
return passwordParam;
122+
return clientParam.getClientHostPassword();
119123
}
120124

121125
@Override
122-
public String getClientTag() {
123-
return tag;
126+
public String getClientTag() {
127+
if(clientParam.getClientTag() != null)
128+
return clientParam.getClientTag();
129+
return "";
124130
}
125131

126132
@Override
@@ -188,9 +194,10 @@ private String prepareAjaxImage(List<TileInfo> tiles, boolean init) {
188194

189195
int key = ajaxImageCache.putImage(imgBits);
190196
StringBuffer sb = new StringBuffer("/ajaximg?host=");
191-
sb.append(host).append("&port=").append(port).append("&sid=").append(passwordParam);
192-
sb.append("&key=").append(key).append("&ts=").append(System.currentTimeMillis());
193-
return sb.toString();
197+
sb.append(getClientHostAddress()).append("&port=").append(getClientHostPort()).append("&sid=").append(getClientHostPassword());
198+
sb.append("&key=").append(key).append("&tag=").append(this.getClientTag());
199+
sb.append("&ts=").append(System.currentTimeMillis());
200+
return sb.toString();
194201
}
195202

196203
private String prepareAjaxSession(boolean init) {
@@ -202,8 +209,8 @@ private String prepareAjaxSession(boolean init) {
202209

203210
StringBuffer sb = new StringBuffer();
204211

205-
sb.append("/ajax?host=").append(host).append("&port=").append(port);
206-
sb.append("&sid=").append(passwordParam).append("&sess=").append(ajaxSessionId);
212+
sb.append("/ajax?host=").append(getClientHostAddress()).append("&port=").append(getClientHostPort());
213+
sb.append("&sid=").append(getClientHostPassword()).append("&tag=").append(getClientTag()).append("&sess=").append(ajaxSessionId);
207214
return sb.toString();
208215
}
209216

@@ -440,5 +447,13 @@ public void updateFrontEndActivityTime() {
440447
lastFrontEndActivityTime = System.currentTimeMillis();
441448
}
442449

443-
protected abstract FrameBufferCanvas getFrameBufferCavas();
450+
protected abstract FrameBufferCanvas getFrameBufferCavas();
451+
452+
public ConsoleProxyClientParam getClientParam() {
453+
return clientParam;
454+
}
455+
456+
public void setClientParam(ConsoleProxyClientParam clientParam) {
457+
this.clientParam = clientParam;
458+
}
444459
}

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClientParam.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public void setClientTunnelSession(String clientTunnelSession) {
8989
}
9090

9191
public String getClientMapKey() {
92+
if(clientTag != null && !clientTag.isEmpty())
93+
return clientTag;
94+
9295
return clientHostAddress + ":" + clientHostPort;
9396
}
9497
}

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public void run() {
6464
while (true) {
6565
cleanupLogging();
6666
bReportLoad = false;
67-
68-
s_logger.info("connMap=" + connMap);
67+
68+
if(s_logger.isDebugEnabled())
69+
s_logger.debug("connMap=" + connMap);
6970
Enumeration<String> e = connMap.keys();
7071
while (e.hasMoreElements()) {
7172
String key;
@@ -98,7 +99,7 @@ public void run() {
9899
s_logger.debug("Report load change : " + loadInfo);
99100
}
100101

101-
try { Thread.sleep(1000); } catch (InterruptedException ex) {}
102+
try { Thread.sleep(5000); } catch (InterruptedException ex) {}
102103
}
103104
}
104105
}

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
130130
param.setClientHostPassword(sid);
131131
param.setClientTag(tag);
132132
param.setTicket(ticket);
133+
param.setClientTunnelUrl(console_url);
134+
param.setClientTunnelSession(console_host_session);
135+
133136
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
134137

135138
if (!viewer.isHostConnected()) {

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ public boolean isFrontEndAlive() {
5454
}
5555

5656
@Override
57-
public void initClient(ConsoleProxyClientParam param) {
58-
this.host = param.getClientHostAddress();
59-
this.port = param.getClientHostPort();
60-
this.passwordParam = param.getClientHostPassword();
61-
this.tag = param.getClientTag();
62-
this.ticket = param.getTicket();
57+
public void initClient(ConsoleProxyClientParam param) {
58+
setClientParam(param);
6359

6460
final String tunnelUrl = param.getClientTunnelUrl();
6561
final String tunnelSession = param.getClientTunnelSession();
@@ -78,13 +74,13 @@ public void run() {
7874
uri.getHost(), uri.getPort(),
7975
uri.getPath() + "?" + uri.getQuery(),
8076
tunnelSession, "https".equalsIgnoreCase(uri.getScheme()),
81-
passwordParam);
77+
getClientHostPassword());
8278
} catch (URISyntaxException e) {
8379
s_logger.warn("Invalid tunnel URL " + tunnelUrl);
8480
}
8581
} else {
86-
s_logger.info("Connect to VNC server directly. host: " + host + ", port: " + port);
87-
client.connectTo(host, port, passwordParam);
82+
s_logger.info("Connect to VNC server directly. host: " + getClientHostAddress() + ", port: " + getClientHostPort());
83+
client.connectTo(getClientHostAddress(), getClientHostPort(), getClientHostPassword());
8884
}
8985
} catch (UnknownHostException e) {
9086
s_logger.error("Unexpected exception: ", e);

0 commit comments

Comments
 (0)