discord-jadx/app/src/main/java/c/m/a/g/d/e.java
2021-07-13 22:23:20 +02:00

139 lines
4.3 KiB
Java

package c.m.a.g.d;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Arrays;
/* compiled from: SntpClient */
public class e {
public final c.m.a.b a;
public final c b;
/* renamed from: c reason: collision with root package name */
public final a f1465c;
/* compiled from: SntpClient */
public static class a extends IOException {
public a(String str) {
super(str);
}
}
/* compiled from: SntpClient */
public static final class b {
public final long a;
public final long b;
/* renamed from: c reason: collision with root package name */
public final long f1466c;
public final c.m.a.b d;
public b(long j, long j2, long j3, c.m.a.b bVar) {
this.a = j;
this.b = j2;
this.f1466c = j3;
this.d = bVar;
}
public long a() {
return this.a + this.f1466c + (this.d.b() - this.b);
}
}
public e(c.m.a.b bVar, c cVar, a aVar) {
this.a = bVar;
this.b = cVar;
this.f1465c = aVar;
}
public static void a(byte b2, byte b3, int i, long j) throws a {
if (b2 == 3) {
throw new a("unsynchronized server");
} else if (b3 != 4 && b3 != 5) {
throw new a(c.d.b.a.a.k("untrusted mode: ", b3));
} else if (i == 0 || i > 15) {
throw new a(c.d.b.a.a.k("untrusted stratum: ", i));
} else if (j == 0) {
throw new a("zero transmitTime");
}
}
public static long b(byte[] bArr, int i) {
byte b2 = bArr[i];
byte b3 = bArr[i + 1];
byte b4 = bArr[i + 2];
byte b5 = bArr[i + 3];
int i2 = b2 & 128;
byte b6 = b2;
if (i2 == 128) {
b6 = (b2 & Byte.MAX_VALUE) + 128;
}
int i3 = b3 & 128;
byte b7 = b3;
if (i3 == 128) {
b7 = (b3 & Byte.MAX_VALUE) + 128;
}
int i4 = b4 & 128;
byte b8 = b4;
if (i4 == 128) {
b8 = (b4 & Byte.MAX_VALUE) + 128;
}
int i5 = b5 & 128;
byte b9 = b5;
if (i5 == 128) {
b9 = (b5 & Byte.MAX_VALUE) + 128;
}
return ((b6 == 1 ? 1 : 0) << 24) + ((b7 == 1 ? 1 : 0) << 16) + ((b8 == 1 ? 1 : 0) << 8) + (b9 == 1 ? 1 : 0);
}
public static long c(byte[] bArr, int i) {
long b2 = b(bArr, i);
return ((b(bArr, i + 4) * 1000) / 4294967296L) + ((b2 - 2208988800L) * 1000);
}
public b d(String str, Long l) throws IOException {
DatagramSocket datagramSocket = null;
try {
InetAddress a2 = this.b.a(str);
datagramSocket = this.f1465c.c();
datagramSocket.setSoTimeout(l.intValue());
byte[] bArr = new byte[48];
DatagramPacket b2 = this.f1465c.b(bArr, a2, 123);
bArr[0] = 27;
long a3 = this.a.a();
long b3 = this.a.b();
long j = a3 / 1000;
Long.signum(j);
long j2 = a3 - (j * 1000);
long j3 = j + 2208988800L;
bArr[40] = (byte) ((int) (j3 >> 24));
bArr[41] = (byte) ((int) (j3 >> 16));
bArr[42] = (byte) ((int) (j3 >> 8));
bArr[43] = (byte) ((int) (j3 >> 0));
long j4 = (j2 * 4294967296L) / 1000;
bArr[44] = (byte) ((int) (j4 >> 24));
bArr[45] = (byte) ((int) (j4 >> 16));
bArr[46] = (byte) ((int) (j4 >> 8));
bArr[47] = (byte) ((int) (Math.random() * 255.0d));
datagramSocket.send(b2);
byte[] copyOf = Arrays.copyOf(bArr, 48);
datagramSocket.receive(this.f1465c.a(copyOf));
long b4 = this.a.b();
long j5 = (b4 - b3) + a3;
long c2 = c(copyOf, 24);
long c3 = c(copyOf, 32);
long c4 = c(copyOf, 40);
a((byte) ((copyOf[0] >> 6) & 3), (byte) (copyOf[0] & 7), copyOf[1] & 255, c4);
b bVar = new b(j5, b4, ((c4 - j5) + (c3 - c2)) / 2, this.a);
datagramSocket.close();
return bVar;
} catch (Throwable th) {
if (datagramSocket != null) {
datagramSocket.close();
}
throw th;
}
}
}