# HG changeset patch # User Nobuyasu Oshiro # Date 1315595779 -32400 # Node ID fb1a62154851257fad6124de203e387b2deab93d # Parent db5f735fd2b4c223ce5f444a68aae0d6001897e8# Parent ea60596e05ef99f1dee0782367b5279edfa72939 merge 151 diff -r db5f735fd2b4 -r fb1a62154851 src/myVncProxy/AcceptClient.java --- 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"; - } } } diff -r db5f735fd2b4 -r fb1a62154851 src/myVncProxy/MyRfbProto.java --- 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 { + LinkedListbufs = new LinkedList(); 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 {