add src files decompiled via jad
[rsa2client.git] / src / mcsClient / DatagramReader.java
1 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.kpdus.com/jad.html
3 // Decompiler options: packimports(3) fieldsfirst nonlb space 
4
5 package mcsClient;
6
7 import java.io.IOException;
8 import java.net.*;
9 import java.util.LinkedList;
10 import java.util.logging.Level;
11 import java.util.logging.Logger;
12 import javax.swing.JFrame;
13 import javax.swing.JOptionPane;
14
15 // Referenced classes of package mcsClient:
16 //            BitMap, SecureDatagramSocket, McsTcpConnection, LiveVideoPanel, 
17 //            McsToolBar
18
19 public final class DatagramReader
20     implements Runnable {
21
22     public boolean videoLostSync;
23     private DatagramSocket dgSocket;
24     private McsTcpConnection mcsTcpConnection;
25     private LiveVideoPanel liveVideoPanel;
26     private LinkedList datagramList;
27     private static final boolean USE_MULTICAST = false;
28     public static final int DEFAULT_DIALIN_BITRATE;
29     public static final int DEFAULT_NET_BITRATE;
30     private long serverTime;
31     private long serverBaseTime;
32     private long clientTime;
33     private long clientBaseTime;
34     private boolean gotBaseTime;
35     private long skew;
36     private long upperSkew;
37     private long lowerSkew;
38     private long initialBitRate;
39     private long skewTime;
40     private boolean gotBeginningOfFrame;
41     private boolean gotInitialBitRate;
42     private boolean detectedPPP;
43     private int frameNumber;
44     private int maxSequenceNumber;
45     private int lastFrameNumber;
46     private long totalFrameSize;
47     private BitMap bitmap;
48     private boolean initialized;
49     private static int nakMessage[] = new int[4];
50     private McsToolBar sliderListener;
51     private int nakCount;
52     private static Logger logger = Logger.getAnonymousLogger();
53
54     public DatagramReader(McsTcpConnection mcstcpconnection, LiveVideoPanel livevideopanel, LinkedList linkedlist, String s, int i, boolean flag) {
55         videoLostSync = false;
56         serverBaseTime = 0L;
57         clientTime = 0L;
58         clientBaseTime = 0L;
59         gotBaseTime = false;
60         skew = 0L;
61         upperSkew = 150L;
62         lowerSkew = -10L;
63         initialBitRate = 0L;
64         skewTime = 225L;
65         gotBeginningOfFrame = false;
66         gotInitialBitRate = false;
67         detectedPPP = false;
68         maxSequenceNumber = 0;
69         lastFrameNumber = 0;
70         totalFrameSize = 0L;
71         bitmap = new BitMap();
72         initialized = true;
73         sliderListener = null;
74         nakCount = 0;
75         mcsTcpConnection = mcstcpconnection;
76         liveVideoPanel = livevideopanel;
77         datagramList = linkedlist;
78         logger.setLevel(Level.WARNING);
79         String s1 = System.getProperty("mcs.debug");
80         if (s1 != null && s1.equalsIgnoreCase("true"))
81             logger.setLevel(Level.ALL);
82         nakMessage[0] = nakMessage.length * 4;
83         nakMessage[1] = 5;
84         if (mcstcpconnection.getDetectedPPP() || flag) {
85             detectedPPP = true;
86             upperSkew = 150L;
87             lowerSkew = -30L;
88             skewTime = 2000L;
89         }
90         if (mcstcpconnection.videoEncrypted())
91             dgSocket = new SecureDatagramSocket(mcstcpconnection.cipher1, mcstcpconnection.cipher2, mcstcpconnection.getLocalPort());
92         else
93             dgSocket = new DatagramSocket(mcstcpconnection.getLocalPort());
94         dgSocket.setReceiveBufferSize(0x1f400);
95         dgSocket.setSoTimeout(500);
96         if (flag)
97             return;
98         try {
99             byte abyte0[] = new byte[10];
100             DatagramPacket datagrampacket = new DatagramPacket(abyte0, abyte0.length, InetAddress.getByName(s), i);
101             for (int j = 0; j < 6; j++) {
102                 dgSocket.send(datagrampacket);
103                 try {
104                     Thread.currentThread();
105                     Thread.sleep(60L);
106                 }
107                 catch (InterruptedException interruptedexception) { }
108             }
109
110             try {
111                 Thread.currentThread();
112                 Thread.sleep(200L);
113             }
114             catch (InterruptedException interruptedexception1) { }
115         }
116         catch (Exception exception) {
117             logger.severe(exception.toString());
118             initialized = false;
119             JOptionPane.showMessageDialog(new JFrame(), "Failed to connect.  Try again.", "Remote Console Datagram Reader Initialization Error", 0);
120         }
121         return;
122     }
123
124     private void cleanupThread() {
125         if (dgSocket != null) {
126             dgSocket.disconnect();
127             dgSocket.close();
128         }
129         dgSocket = null;
130         mcsTcpConnection = null;
131         liveVideoPanel = null;
132         datagramList = null;
133         initialized = false;
134     }
135
136     private void process() {
137         int l;
138         Thread thread;
139         l = 0;
140         boolean flag = false;
141         boolean flag1 = false;
142         boolean flag2 = false;
143         if (!initialized)
144             return;
145         thread = Thread.currentThread();
146           goto _L1
147 _L22:
148         if (nakCount >= 25) {
149             logger.info("25 NAK messages sent");
150             nakCount = 0;
151         }
152         DatagramPacket datagrampacket;
153         byte abyte1[] = new byte[1500];
154         datagrampacket = new DatagramPacket(abyte1, abyte1.length);
155         dgSocket.receive(datagrampacket);
156           goto _L2
157         SocketTimeoutException sockettimeoutexception;
158         sockettimeoutexception;
159           goto _L1
160         IOException ioexception3;
161         ioexception3;
162         logger.warning("Datagram Reader - error reading datagram " + ioexception3);
163         return;
164 _L2:
165         byte abyte0[];
166         int j;
167         abyte0 = datagrampacket.getData();
168         j = datagrampacket.getOffset();
169         if (datagrampacket.getLength() >= 24) goto _L3; else goto _L1
170 _L3:
171         if (abyte0[j + 7] != 6) goto _L5; else goto _L4
172 _L4:
173         videoLostSync = true;
174         gotBaseTime = false;
175         logger.info("DatagramReader: video lost sync");
176           goto _L1
177 _L5:
178         videoLostSync = false;
179         frameNumber = (abyte0[j + 8] & 0xff) << 8 | abyte0[j + 9] & 0xff;
180         if (gotBeginningOfFrame) goto _L7; else goto _L6
181 _L6:
182         if ((abyte0[j + 7] & 0xbf) != 0) goto _L8; else goto _L1
183 _L8:
184         gotBeginningOfFrame = true;
185         lastFrameNumber = frameNumber - 1;
186         l = 128;
187         bitmap.clear();
188         bitmap.setBit(0);
189 _L7:
190         int i;
191         i = (abyte0[j + 10] & 0xff) << 8 | abyte0[j + 11] & 0xff;
192         int i1 = (abyte0[j + 2] & 0xff) << 8 | abyte0[j + 3] & 0xff;
193         totalFrameSize += i1;
194         serverTime = ((long)abyte0[j + 20] & 255L) << 24 | ((long)abyte0[j + 21] & 255L) << 16 | ((long)abyte0[j + 22] & 255L) << 8 | (long)abyte0[j + 23] & 255L;
195         clientTime = System.currentTimeMillis();
196         if (gotBaseTime) goto _L10; else goto _L9
197 _L9:
198         gotBaseTime = true;
199         serverBaseTime = serverTime;
200         clientBaseTime = clientTime;
201         totalFrameSize = 0L;
202           goto _L11
203 _L10:
204         long l1;
205         skew = clientTime - clientBaseTime - (serverTime - serverBaseTime);
206         l1 = (totalFrameSize * 8L * 1000L) / ((clientTime - clientBaseTime) + 50L);
207         if (l1 > 0x13880L)
208             liveVideoPanel.doPartialScreenUpdates = false;
209         else
210             liveVideoPanel.doPartialScreenUpdates = true;
211         if (skew >= lowerSkew) goto _L13; else goto _L12
212 _L12:
213         gotBaseTime = false;
214           goto _L11
215 _L13:
216         if (skew <= upperSkew || clientTime - clientBaseTime <= skewTime) goto _L11; else goto _L14
217 _L14:
218         int ai[];
219         if (!gotInitialBitRate) {
220             initialBitRate = l1;
221             gotInitialBitRate = true;
222             if (detectedPPP) {
223                 if (initialBitRate < (long)DEFAULT_DIALIN_BITRATE)
224                     initialBitRate = DEFAULT_DIALIN_BITRATE;
225             } else
226             if (initialBitRate < (long)DEFAULT_NET_BITRATE)
227                 initialBitRate = DEFAULT_NET_BITRATE;
228             if (sliderListener != null)
229                 sliderListener.setSliderInitialBitRate(initialBitRate);
230         } else {
231             if (l1 < (initialBitRate * 60L) / 100L)
232                 l1 = (initialBitRate * 60L) / 100L;
233             if (detectedPPP && l1 > initialBitRate)
234                 l1 = initialBitRate;
235         }
236         gotBaseTime = false;
237         l1 *= 75L;
238         l1 /= 100L;
239         ai = new int[3];
240         ai[0] = ai.length * 4;
241         ai[1] = 10;
242         ai[2] = (int)l1;
243         thread;
244         if (Thread.interrupted())
245             return;
246         try {
247             mcsTcpConnection.sendMessage(ai, false);
248         }
249         catch (IOException ioexception4) {
250             logger.severe("Socket exception - DatagramReader exiting");
251             return;
252         }
253 _L11:
254         if (frameNumber == lastFrameNumber)
255             break MISSING_BLOCK_LABEL_1033;
256         if (frameNumber == lastFrameNumber + 1) goto _L16; else goto _L15
257 _L15:
258         nakMessage[2] = 0;
259         nakMessage[3] = frameNumber;
260         try {
261             mcsTcpConnection.sendMessage(nakMessage, false);
262         }
263         catch (IOException ioexception) {
264             logger.severe("Socket exception - DatagramReader exiting");
265             return;
266         }
267         nakCount++;
268           goto _L17
269 _L16:
270         if ((l & 0x80) != 0) goto _L19; else goto _L18
271 _L18:
272         nakMessage[2] = 0;
273         nakMessage[3] = 0;
274         thread;
275         if (Thread.interrupted())
276             return;
277         try {
278             mcsTcpConnection.sendMessage(nakMessage, false);
279         }
280         catch (IOException ioexception1) {
281             logger.severe("Socket exception - DatagramReader exiting");
282             return;
283         }
284         nakCount++;
285           goto _L17
286 _L20:
287         int k;
288         nakMessage[2] = k;
289         nakMessage[3] = frameNumber;
290         thread;
291         if (Thread.interrupted())
292             return;
293         try {
294             mcsTcpConnection.sendMessage(nakMessage, false);
295         }
296         catch (IOException ioexception2) {
297             logger.severe("Socket exception - DatagramReader exiting");
298             return;
299         }
300         nakCount++;
301         break; /* Loop/switch isn't completed */
302 _L19:
303         if ((k = bitmap.findZeroBit()) <= maxSequenceNumber) goto _L20; else goto _L17
304 _L17:
305         lastFrameNumber = frameNumber;
306         bitmap.clear();
307         l = 0;
308         maxSequenceNumber = 0;
309         bitmap.setBit(i);
310         maxSequenceNumber = i <= maxSequenceNumber ? maxSequenceNumber : i;
311         l |= abyte0[j + 7];
312         abyte0[j + 7] &= 0x3f;
313         int j1;
314         if ((j1 = datagramList.size()) < 10 || liveVideoPanel.imagesAutomaticallyPaused)
315             break MISSING_BLOCK_LABEL_1147;
316         thread;
317         if (Thread.interrupted())
318             return;
319         if (liveVideoPanel.pauseVideo() != 1) {
320             logger.severe("Socket exception - DatagramReader exiting");
321             return;
322         }
323         liveVideoPanel.imagesAutomaticallyPaused = true;
324         long l2 = ((long)abyte0[j] & 255L) << 24 | ((long)abyte0[j + 1] & 255L) << 16 | ((long)abyte0[j + 2] & 255L) << 8 | (long)abyte0[j + 3] & 255L;
325         long l3 = ((long)abyte0[j + 12] & 255L) << 24 | ((long)abyte0[j + 13] & 255L) << 16 | ((long)abyte0[j + 14] & 255L) << 8 | (long)abyte0[j + 15] & 255L;
326         long l4 = ((long)abyte0[j + 16] & 255L) << 24 | ((long)abyte0[j + 17] & 255L) << 16 | ((long)abyte0[j + 18] & 255L) << 8 | (long)abyte0[j + 19] & 255L;
327         if (i >= 0 && i <= 896 && l3 >= 0L && l3 <= 0xc0000L && l4 >= 0L && l3 <= 0xc0000L) {
328             if (l2 != 31L)
329                 synchronized (datagramList) {
330                     datagramList.addFirst(datagrampacket);
331                     datagramList.notify();
332                 }
333         } else {
334             logger.warning("Bad packet discarded.  seq num: " + i + " vid ram offset: " + l3 + " vid ram count: " + l4);
335         }
336           goto _L1
337         ArrayIndexOutOfBoundsException arrayindexoutofboundsexception;
338         arrayindexoutofboundsexception;
339         logger.warning(arrayindexoutofboundsexception.toString());
340 _L1:
341         thread;
342         if (Thread.interrupted())
343             return;
344         if (true) goto _L22; else goto _L21
345 _L21:
346     }
347
348     public void run() {
349         process();
350         cleanupThread();
351     }
352
353     protected void finalize() throws Throwable {
354         cleanupThread();
355     }
356
357     public boolean initialized() {
358         return initialized;
359     }
360
361     public void addSliderListener(McsToolBar mcstoolbar) {
362         sliderListener = mcstoolbar;
363     }
364
365     public void setInitialBitRate(long l) {
366         initialBitRate = l;
367         gotInitialBitRate = true;
368         int ai[] = new int[3];
369         ai[0] = ai.length * 4;
370         ai[1] = 10;
371         ai[2] = (int)l;
372         try {
373             mcsTcpConnection.sendMessage(ai, true);
374         }
375         catch (IOException ioexception) {
376             logger.severe("Socket exception - setInitialBitRate");
377             return;
378         }
379     }
380
381     static  {
382         DEFAULT_DIALIN_BITRATE = McsToolBar.BITRATES[2];
383         DEFAULT_NET_BITRATE = McsToolBar.BITRATES[7];
384     }
385 }