# HG changeset patch # User oc # Date 1402373759 -32400 # Node ID c3761c89660702a81a2bf476f9d01f1d73dc44c2 # Parent 41f049cebcb5d01aadbfb20f9a131b5a27eb74d8 minor fix diff -r 41f049cebcb5 -r c3761c896607 src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Sun Jun 08 19:30:18 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Tue Jun 10 13:15:59 2014 +0900 @@ -42,7 +42,7 @@ private boolean cuiVersion; private long counter = 0; // packet serial number TreeVncProtocol treeProtocol; - public TReeVNCCommand treeVncCommand; + public TreeVncCommand treeVncCommand; public ServerSocket servSock; private boolean permitChangeScreen = true; private static final int INFLATE_BUFSIZE = 1024 * 100; @@ -58,7 +58,7 @@ public void setVncProxy(VncProxyService viewer) { this.viewer = viewer; - treeVncCommand = new TReeVNCCommand(viewer,this,treeProtocol); + treeVncCommand = new TreeVncCommand(viewer,this,treeProtocol); } abstract public boolean isRoot() ; diff -r 41f049cebcb5 -r c3761c896607 src/main/java/jp/ac/u_ryukyu/treevnc/TReeVNCCommand.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TReeVNCCommand.java Sun Jun 08 19:30:18 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -package jp.ac.u_ryukyu.treevnc; - -import java.io.IOException; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; - -import com.glavsoft.exceptions.TransportException; -import com.glavsoft.rfb.protocol.ProtocolContext; -import com.glavsoft.transport.Reader; -import com.glavsoft.transport.Writer; - -import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; -import jp.ac.u_ryukyu.treevnc.server.VncProxyService; - -public class TReeVNCCommand { - public VncProxyService viewer; - MyRfbProto rfb; - private TreeVncProtocol treeProtocol; - - public TReeVNCCommand(VncProxyService viewer,MyRfbProto rfb, TreeVncProtocol treeProtocol) { - this.viewer = viewer; - this.rfb = rfb; - this.treeProtocol = treeProtocol; - } - - /** - * handle TreeVNC Command - * @param b 12byte header ( command 4byte, length 4byte, port 4byte, option String ) - * @param is - * @param os - * @throws TransportException - * @throws IOException - */ - void treeVncCommand(byte[] b, Reader is, Writer os) throws TransportException, IOException { - ByteBuffer buf = ByteBuffer.wrap(b); - int command = buf.get()&0xff; // make it unsigned - buf.position(buf.position()+3); - int length = buf.getInt(); - int port = buf.getInt(); - String hostname = null; - if (length>12) { - byte namebuf[] = new byte[length-12]; - try { - is.readBytes(namebuf); - } catch (TransportException e) { - return; - } - hostname = new String(namebuf); - } - switch (command) { - case ProtocolContext.FIND_ROOT_REPLY : - handleFindRootReply(port,hostname); - break; - case ProtocolContext.CONNECT_TO_AS_LEADER : - handleConnectTo( port,hostname,true); - break; - case ProtocolContext.CONNECT_TO : - handleConnectTo( port,hostname,false); - break; - case ProtocolContext.FIND_ROOT : - // this is a multicast message, cannot happen - break; - case ProtocolContext.WHERE_TO_CONNECT : - handleWhereToConnect(port,hostname); - break; - case ProtocolContext.LOST_PARENT : - handleLostParent(port,hostname); - break; - case ProtocolContext.NOT_FOUND_PARENT : - handleNotFoundParent(port,hostname); - break; - default: - System.out.println("unknown treeVNC command" + command); - } - } - - - /** - * new clients ask root to where to connect - * tell him his parent - * @param port - * @param hostname - */ - void handleWhereToConnect(int port, String hostname) { - viewer.replyCreateTree(hostname,port); - } - - /** - * set new parent address - * @param port - * @param hostname - * @param leader - * @throws IOException - * @throws SocketException - * @throws UnknownHostException - */ - void handleConnectTo(int port, String hostname, boolean leader) throws UnknownHostException, SocketException, IOException { - if (rfb.isRoot()) { - return; // we don't have parent - } - treeProtocol.connectToParenet(port, hostname,leader); - } - - /** - * Accept FIND_ROOT_REPLY - * add replying TreeVNC root to RootSelection Panel - * @param port - * @param hostname - */ - void handleFindRootReply(int port, String hostname) { - viewer.addHostToSelectionPanel(port, hostname); - } - - /** - * client node lost parent connection, send reconnection message. - * if root is not here, clients die themselves. - * @param port - * @param hostname - */ - private void handleLostParent(int port, String hostname) { - viewer.fixLostParent(hostname,port); - } - - /** - * Some parent is missing. Reorganize tree - * @param port - * @param hostname - */ - private void handleNotFoundParent(int port, String hostname) { - treeProtocol.notfoundParent(hostname, port); - } - -} \ No newline at end of file diff -r 41f049cebcb5 -r c3761c896607 src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java Tue Jun 10 13:15:59 2014 +0900 @@ -0,0 +1,134 @@ +package jp.ac.u_ryukyu.treevnc; + +import java.io.IOException; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; + +import com.glavsoft.exceptions.TransportException; +import com.glavsoft.rfb.protocol.ProtocolContext; +import com.glavsoft.transport.Reader; +import com.glavsoft.transport.Writer; + +import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; +import jp.ac.u_ryukyu.treevnc.server.VncProxyService; + +public class TreeVncCommand { + public VncProxyService viewer; + MyRfbProto rfb; + private TreeVncProtocol treeProtocol; + + public TreeVncCommand(VncProxyService viewer,MyRfbProto rfb, TreeVncProtocol treeProtocol) { + this.viewer = viewer; + this.rfb = rfb; + this.treeProtocol = treeProtocol; + } + + /** + * handle TreeVNC Command + * @param b 12byte header ( command 4byte, length 4byte, port 4byte, option String ) + * @param is + * @param os + * @throws TransportException + * @throws IOException + */ + void treeVncCommand(byte[] b, Reader is, Writer os) throws TransportException, IOException { + ByteBuffer buf = ByteBuffer.wrap(b); + int command = buf.get()&0xff; // make it unsigned + buf.position(buf.position()+3); + int length = buf.getInt(); + int port = buf.getInt(); + String hostname = null; + if (length>12) { + byte namebuf[] = new byte[length-12]; + try { + is.readBytes(namebuf); + } catch (TransportException e) { + return; + } + hostname = new String(namebuf); + } + switch (command) { + case ProtocolContext.FIND_ROOT_REPLY : + handleFindRootReply(port,hostname); + break; + case ProtocolContext.CONNECT_TO_AS_LEADER : + handleConnectTo( port,hostname,true); + break; + case ProtocolContext.CONNECT_TO : + handleConnectTo( port,hostname,false); + break; + case ProtocolContext.FIND_ROOT : + // this is a multicast message, cannot happen + break; + case ProtocolContext.WHERE_TO_CONNECT : + handleWhereToConnect(port,hostname); + break; + case ProtocolContext.LOST_PARENT : + handleLostParent(port,hostname); + break; + case ProtocolContext.NOT_FOUND_PARENT : + handleNotFoundParent(port,hostname); + break; + default: + System.out.println("unknown treeVNC command" + command); + } + } + + + /** + * new clients ask root to where to connect + * tell him his parent + * @param port + * @param hostname + */ + void handleWhereToConnect(int port, String hostname) { + viewer.replyCreateTree(hostname,port); + } + + /** + * set new parent address + * @param port + * @param hostname + * @param leader + * @throws IOException + * @throws SocketException + * @throws UnknownHostException + */ + void handleConnectTo(int port, String hostname, boolean leader) throws UnknownHostException, SocketException, IOException { + if (rfb.isRoot()) { + return; // we don't have parent + } + treeProtocol.connectToParenet(port, hostname,leader); + } + + /** + * Accept FIND_ROOT_REPLY + * add replying TreeVNC root to RootSelection Panel + * @param port + * @param hostname + */ + void handleFindRootReply(int port, String hostname) { + viewer.addHostToSelectionPanel(port, hostname); + } + + /** + * client node lost parent connection, send reconnection message. + * if root is not here, clients die themselves. + * @param port + * @param hostname + */ + private void handleLostParent(int port, String hostname) { + viewer.fixLostParent(hostname,port); + } + + /** + * Some parent is missing. Reorganize tree + * @param port + * @param hostname + */ + private void handleNotFoundParent(int port, String hostname) { + treeProtocol.notfoundParent(hostname, port); + } + +} \ No newline at end of file diff -r 41f049cebcb5 -r c3761c896607 src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptClient.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptClient.java Sun Jun 08 19:30:18 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptClient.java Tue Jun 10 13:15:59 2014 +0900 @@ -15,11 +15,10 @@ // private final int intv_time = 100; avoid too frequent reconnection private MyRfbProto rfb; - public AcceptClient(MyRfbProto rfb) { - this.rfb = rfb; - TreeVNCNode me = new TreeVNCNode( rfb.getMyAddress(), rfb.getAcceptPort()); - me.setTreeNum(0); - nodeList.add(me); + public AcceptClient(String hostName, int vncport) { + TreeVNCNode me = new TreeVNCNode(hostName, vncport); + me.setTreeNum(0); + nodeList.add(me); } // @@ -35,6 +34,7 @@ // } // } + /** * a parent is lost, remove from the list and move last one into here * @param nodeNum diff -r 41f049cebcb5 -r c3761c896607 src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Sun Jun 08 19:30:18 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Tue Jun 10 13:15:59 2014 +0900 @@ -7,6 +7,7 @@ import java.util.logging.Logger; import jp.ac.u_ryukyu.treevnc.AcceptThread; +import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; import jp.ac.u_ryukyu.treevnc.client.TreeVncRootSelectionPanel; import com.glavsoft.core.SettingsChangedEvent; @@ -76,7 +77,7 @@ private void initProxy1(String hostName) { myRfb = new MyRfbProtoProxy(); myRfb.setVncProxy(this); - clients = new AcceptClient(myRfb); + clients = new AcceptClient(hostName, vncport); isApplet = false; setIsTreeVNC(true); setConnectionParam(hostName,vncport);