public AckListMessage(DatagramPacket dp) { this.dp = dp; dpData = dp.getData(); ver = ByteShortConvert.toShort(dpData, 0); sType = ByteShortConvert.toShort(dpData, 2); connectId = ByteIntConvert.toInt(dpData, 4); clientId = ByteIntConvert.toInt(dpData, 8); lastRead = ByteIntConvert.toInt(dpData, 4 + 8); int sum = ByteShortConvert.toShort(dpData, 8 + 8); ackList = new List <int>(); int t = 0; for (int i = 0; i < sum; i++) { t = 10 + 4 * i; int sequence = ByteIntConvert.toInt(dpData, t + 8); ackList.Add(sequence); } ////#MLog.println("LLLLLLLLLLLLLL "+dp.getLength()+" "+ackList.size()); t = 10 + 4 * sum - 4; r1 = ByteIntConvert.toInt(dpData, t + 4 + 8); s1 = ByteIntConvert.toInt(dpData, t + 8 + 8); r2 = ByteIntConvert.toInt(dpData, t + 12 + 8); s2 = ByteIntConvert.toInt(dpData, t + 16 + 8); r3 = ByteIntConvert.toInt(dpData, t + 20 + 8); s3 = ByteIntConvert.toInt(dpData, t + 24 + 8); ////#MLog.println("aaaaaaaaa"+r3+"kkkkkkk "+s3); }
public CloseMessage_Conn(DatagramPacket dp) { this.dp = dp; dpData = dp.getData(); ver = ByteShortConvert.toShort(dpData, 0); sType = ByteShortConvert.toShort(dpData, 2); connectId = ByteIntConvert.toInt(dpData, 4); clientId = ByteIntConvert.toInt(dpData, 8); }
public PingMessage2(int connectId, int clientId, int pingId) { ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence dp = new DatagramPacket(dpData, dpData.Length); }
public PingMessage(int connectId, int clientId, int pingId, int downloadSpeed, int uploadSpeed) { ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(pingId, dpData, 12); //add: sequence ByteShortConvert.toByteArray((short)(downloadSpeed / 1024), dpData, 16); ByteShortConvert.toByteArray((short)(uploadSpeed / 1024), dpData, 18); dp = new DatagramPacket(dpData, dpData.Length); }
public CloseMessage_Conn(int connectId, int clientId) { byte[] dpData = new byte[12]; this.clientId = clientId; this.connectId = connectId; ByteShortConvert.toByteArray(ver, dpData, 0); ByteShortConvert.toByteArray(sType, dpData, 2); ByteIntConvert.toByteArray(connectId, dpData, 4); ByteIntConvert.toByteArray(clientId, dpData, 8); dp = new DatagramPacket(dpData, dpData.Length); }
public PingMessage(DatagramPacket dp) { this.dp = dp; dpData = dp.getData(); ver = ByteShortConvert.toShort(dpData, 0); sType = ByteShortConvert.toShort(dpData, 2); connectId = ByteIntConvert.toInt(dpData, 4); clientId = ByteIntConvert.toInt(dpData, 8); pingId = ByteIntConvert.toInt(dpData, 12); downloadSpeed = ByteShortConvert.toShort(dpData, 16); uploadSpeed = ByteShortConvert.toShort(dpData, 18); }
public CloseMessage_Stream(int connectId, int clientId, int closeOffset) { byte[] dpData = new byte[16]; this.clientId = clientId; this.connectId = connectId; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(closeOffset, dpData, 12); //add: sequence dp = new DatagramPacket(dpData, dpData.Length); }
public DataMessage(DatagramPacket dp) { this.dp = dp; dpData = dp.getData(); ver = ByteShortConvert.toShort(dpData, 0); sType = ByteShortConvert.toShort(dpData, 2); connectId = ByteIntConvert.toInt(dpData, 4); clientId = ByteIntConvert.toInt(dpData, 8); sequence = ByteIntConvert.toInt(dpData, 12); length = ByteShortConvert.toShort(dpData, 16); timeId = ByteIntConvert.toInt(dpData, 18); data = new byte[length]; Array.Copy(dpData, 22, data, 0, length); }
public void create(int timeId) { this.timeId = timeId; dpData = new byte[this.length + 16 + 8]; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(this.sequence, dpData, 12); //add: sequence ByteShortConvert.toByteArray((short)this.length, dpData, 16); //add:length ByteIntConvert.toByteArray(this.timeId, dpData, 18); //add: sequence Array.Copy(this.data, 0, dpData, 22, this.length); dp = new DatagramPacket(dpData, dpData.Length); dp.setAddress(dstAddress); dp.setPort(dstPort); }
public void onReceivePacket(DatagramPacket dp) { byte[] dpData = dp.getData(); int sType = 0; sType = MessageCheck.checkSType(dp); int remote_clientId = ByteIntConvert.toInt(dpData, 8); if (sType == MessageType.sType_PingMessage) { PingMessage pm = new PingMessage(dp); sendPingMessage2(pm.getPingId(), dp.getAddress(), dp.getPort()); currentSpeed = pm.getDownloadSpeed() * 1024; } else if (sType == MessageType.sType_PingMessage2) { PingMessage2 pm = new PingMessage2(dp); lastReceivePingTime = DateTime.Now.Millisecond; long t = pingTable[pm.getPingId()]; if (t != null) { pingDelay = (int)(DateTime.Now.Millisecond - t); String protocal = ""; if (route.isUseTcpTun()) { protocal = "tcp"; } else { protocal = "udp"; } //MLog.println(" receive_ping222: "+pm.getPingId()+" "+new Date()); //MLog.println("delay_"+protocal+" "+pingDelay+"ms "+dp.getAddress().getHostAddress()+":"+dp.getPort()); } } }
public AckListMessage(long connId, List <int> ackList, int lastRead, //ArrayList ackList Dictionary <int, SendRecord> sendRecordTable, int timeId, int connectId, int clientId) { this.clientId = clientId; this.connectId = connectId; this.ackList = ackList; this.lastRead = lastRead; int len1 = 4 + 4 + 10 + 4 * ackList.Count; dpData = new byte[len1 + 24 + 9]; sType = MessageType.sType_AckListMessage; ByteShortConvert.toByteArray(ver, dpData, 0); //add: ver ByteShortConvert.toByteArray(sType, dpData, 2); //add: service type ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence ByteIntConvert.toByteArray(lastRead, dpData, 4 + 8); //dpData[8]=(byte) ackList.size(); ByteShortConvert.toByteArray((short)ackList.Count, dpData, 8 + 8); //add: service type for (int i = 0; i < ackList.Count; i++) { int sequence = (int)ackList[i]; ByteIntConvert.toByteArray(sequence, dpData, 10 + 4 * i + 8); //add: sequence ////#MLog.println("发送确认 "+sequence); } int u1 = timeId - 2; ByteIntConvert.toByteArray(u1, dpData, len1 + 8); SendRecord r1 = sendRecordTable[u1]; int s1 = 0; if (r1 != null) { s1 = r1.getSendSize(); } ByteIntConvert.toByteArray(s1, dpData, len1 + 4 + 8); int u2 = timeId - 1; ByteIntConvert.toByteArray(u2, dpData, len1 + 8 + 8); SendRecord r2 = sendRecordTable[u2]; int s2 = 0; if (r2 != null) { s2 = r2.getSendSize(); } ByteIntConvert.toByteArray(s2, dpData, len1 + 12 + 8); int u3 = timeId; ByteIntConvert.toByteArray(u3, dpData, len1 + 16 + 8); SendRecord r3 = sendRecordTable[u3]; int s3 = 0; if (r3 != null) { s3 = r3.getSendSize(); } ByteIntConvert.toByteArray(s3, dpData, len1 + 20 + 8); dp = new DatagramPacket(dpData, dpData.Length); }