changeset 152:fb1a62154851

merge 151
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sat, 10 Sep 2011 04:16:19 +0900
parents db5f735fd2b4 (current diff) ea60596e05ef (diff)
children 881e5b87ee42
files src/myVncProxy/AcceptClient.java src/myVncProxy/MyRfbProto.java
diffstat 2 files changed, 33 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncProxy/AcceptClient.java	Sat Sep 10 04:13:50 2011 +0900
+++ b/src/myVncProxy/AcceptClient.java	Sat Sep 10 04:16:19 2011 +0900
@@ -11,6 +11,7 @@
 	boolean runflag = false;
 	private String name;
 	boolean addrRegistor = true;
+	int passCheck = 0;
 
 	public AcceptClient(String _name) {
 		name = _name;
@@ -52,15 +53,15 @@
 							counter--;
 							runflag = true;
 
-							sendleaderflag = decisionLeader(
-									Integer.parseInt(port), treebranch);
-
-							Child report = new Child();
+							sendleaderflag = decisionLeader(Integer.parseInt(port), treebranch);
 
-							report.reportLastNode(ls.getLast(), newparent,
-									port, String.valueOf(parentnum),
-									sendleaderflag, counter);
-
+							//waitreplyに向けて命令を送る。
+							Child report = new Child();
+							
+							passCheck = 1;
+							report.reportLastNode(ls.getLast(), newparent,port, 
+									String.valueOf(parentnum),sendleaderflag, counter);
+							
 							listupdate(port);
 
 							int g = 0;
@@ -89,14 +90,11 @@
 							os.close();
 
 						} else if ("2".equals(line)) {
-							parentnum = (Integer.parseInt(port) - 1)
-									/ treebranch;
+							parentnum = (Integer.parseInt(port) - 1) / treebranch;
 							String newparent = ls.get(parentnum);
-
-							outputStream(os, newparent,
-									String.valueOf(parentnum),
-									String.valueOf(counter), leaderflag);
-
+							leaderflag = decisionLeader(Integer.parseInt(port),treebranch);
+							listupdate(port,newparent);
+							outputStream(os, newparent,String.valueOf(parentnum),port,leaderflag);
 							os.close();
 							is.close();
 						} else if ("3".equals(line)) {
@@ -106,13 +104,16 @@
 							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((Integer.parseInt(checkRepetition) -1)/treebranch
-										== Integer.parseInt(port))
+
+								//checkRepetition = "go";
+								if(ls.size()-1+passCheck == Integer.parseInt(checkRepetition)) {
 									checkRepetition = "skip";
+
+								}
+								passCheck = 0;
 							}
 							os.println(checkRepetition);
 
@@ -136,17 +137,12 @@
 							}
 
 							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の親ノードに接続する人に接続する人を教える
@@ -177,6 +173,12 @@
 		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) {
@@ -204,12 +206,12 @@
 	}
 
 	String decisionLeader(int counter, int treebranch) {
-		if ((counter - 1) % treebranch == 1) { // children in most young treenum
-												// have leaderflag 1 other 0
+		if(counter == 1) 
+			return "1";
+		if ((counter - 1) % treebranch == 1)// children in most young treenum
 			return "0";
-		} else {
+		else
 			return "1";
-		}
 	}
 
 }
--- a/src/myVncProxy/MyRfbProto.java	Sat Sep 10 04:13:50 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Sat Sep 10 04:16:19 2011 +0900
@@ -599,6 +599,7 @@
 	 * 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); 
@@ -649,6 +650,7 @@
 		// 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 {