changeset 158:1c0af90f7f59

modify AcceptClient, MyRfbProto
author e085711
date Wed, 12 Oct 2011 02:24:36 +0900
parents 881e5b87ee42
children 99747d2cb4cd
files src/myVncProxy/AcceptClient.java src/myVncProxy/MyRfbProto.java
diffstat 2 files changed, 29 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncProxy/AcceptClient.java	Wed Oct 12 02:19:51 2011 +0900
+++ b/src/myVncProxy/AcceptClient.java	Wed Oct 12 02:24:36 2011 +0900
@@ -11,7 +11,6 @@
 	boolean runflag = false;
 	private String name;
 	boolean addrRegistor = true;
-	int passCheck = 0;
 
 	public AcceptClient(String _name) {
 		name = _name;
@@ -53,15 +52,15 @@
 							counter--;
 							runflag = true;
 
-							sendleaderflag = decisionLeader(Integer.parseInt(port), treebranch);
+							sendleaderflag = decisionLeader(
+									Integer.parseInt(port), treebranch);
 
-							//waitreplyに向けて命令を送る。
 							Child report = new Child();
-							
-							passCheck = 1;
-							report.reportLastNode(ls.getLast(), newparent,port, 
-									String.valueOf(parentnum),sendleaderflag, counter);
-							
+
+							report.reportLastNode(ls.getLast(), newparent,
+									port, String.valueOf(parentnum),
+									sendleaderflag, counter);
+
 							listupdate(port);
 
 							int g = 0;
@@ -90,11 +89,14 @@
 							os.close();
 
 						} else if ("2".equals(line)) {
-							parentnum = (Integer.parseInt(port) - 1) / treebranch;
+							parentnum = (Integer.parseInt(port) - 1)
+									/ treebranch;
 							String newparent = ls.get(parentnum);
-							leaderflag = decisionLeader(Integer.parseInt(port),treebranch);
-							listupdate(port,newparent);
-							outputStream(os, newparent,String.valueOf(parentnum),port,leaderflag);
+
+							outputStream(os, newparent,
+									String.valueOf(parentnum),
+									String.valueOf(counter), leaderflag);
+
 							os.close();
 							is.close();
 						} else if ("3".equals(line)) {
@@ -104,16 +106,13 @@
 							os.println(ls.get(Integer.parseInt(port)));
 							os.println(port);
 
-							if (checkRepetition.equals(ls.getLast()))
+							if (checkRepetition.equals(ls.getLast())) {
 								checkRepetition = "stop";
 							} else {
-
-								//checkRepetition = "go";
-								if(ls.size()-1+passCheck == Integer.parseInt(checkRepetition)) {
+//								checkRepetition = "go";
+								if((Integer.parseInt(checkRepetition) -1)/treebranch
+										== Integer.parseInt(port))
 									checkRepetition = "skip";
-
-								}
-								passCheck = 0;
 							}
 							os.println(checkRepetition);
 
@@ -137,12 +136,17 @@
 							}
 
 							if (counter >= treebranch + 1) {
+
 								leaderflag = decisionLeader(counter, treebranch);
 								parentnum = (counter - 1) / treebranch;
+
 								request = ls.get(parentnum);
 								System.out.println(parentnum);
-								outputStream(os, request,String.valueOf(parentnum),
+
+								outputStream(os, request,
+										String.valueOf(parentnum),
 										String.valueOf(counter), leaderflag);
+
 								checkParameter(parentnum, counter, leaderflag);
 							} else {
 								// treeの親ノードに接続する人に接続する人を教える
@@ -173,12 +177,6 @@
 		ls.add(Integer.parseInt(port), ls.getLast());
 		ls.removeLast();
 	}
-	
-	void listupdate(String port,String myaddr) {
-		ls.remove(Integer.parseInt(port));
-		ls.add(Integer.parseInt(port), myaddr);
-		ls.removeLast();
-	}
 
 	void outputStream(PrintStream os, String request, String parentnum,
 			String treenum, String leaderflag) {
@@ -206,12 +204,12 @@
 	}
 
 	String decisionLeader(int counter, int treebranch) {
-		if(counter == 1) 
+		if ((counter - 1) % treebranch == 1) { // children in most young treenum
+												// have leaderflag 1 other 0
+			return "0";
+		} else {
 			return "1";
-		if ((counter - 1) % treebranch == 1)// children in most young treenum
-			return "0";
-		else
-			return "1";
+		}
 	}
 
 }
--- a/src/myVncProxy/MyRfbProto.java	Wed Oct 12 02:19:51 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Wed Oct 12 02:24:36 2011 +0900
@@ -615,7 +615,6 @@
 	 * ZRLEE compression is not context dependent, so no recompression is necessary.
 	 */
 	void readSendData(int dataLen) throws IOException, DataFormatException {
-		
 		LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>();
 		ByteBuffer header = ByteBuffer.allocate(16);
 		readFully(header.array(),0,16); 
@@ -676,7 +675,6 @@
 		// but it may generate too many large data. It is better to do it in each client.
 		// But we have do inflation for all input data, so we have to do it here.
 	}
-	
 
 	void newClient(AcceptThread acceptThread, final Socket newCli,
 			final OutputStream os, final InputStream is) throws IOException {