导航菜单

页面标题

页面副标题

哔哩哔哩 v1.6.6 - no.java 源代码

正在查看: 哔哩哔哩 v1.6.6 应用的 no.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package bl;

import android.net.Uri;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import bl.nk;
import com.bilibili.lib.httpdns.LookupException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.android.log.BLog;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

public class no implements nh {
    private nk a;
    private b b = new b();

    @Override
    @NonNull
    public String a() {
        return "ali";
    }

    public no(nk nkVar) {
        this.a = nkVar;
    }

    @Override
    @NonNull
    public ni a(String str) throws LookupException {
        List<ni> a2 = a(str);
        if (a2 == null || a2.isEmpty()) {
            throw new LookupException("empty dns records for " + str);
        }
        return a2.get(0);
    }

    private List<ni> a(String... strArr) throws LookupException {
        HttpURLConnection httpURLConnection;
        IOException e;
        List<ni> list;
        nk.a aVar = new nk.a();
        long elapsedRealtime = SystemClock.elapsedRealtime();
        List<String> a2 = this.b.a();
        int i = 0;
        String str = a2.get(ks.a(0, a2.size()));
        InputStream inputStream = null;
        try {
            String uri = a(str, strArr).toString();
            BLog.d("AliDNSProvider", String.format(Locale.US, "send request for %s", uri));
            aVar.d = str;
            try {
                httpURLConnection = nl.a(uri);
                try {
                    try {
                        int responseCode = httpURLConnection.getResponseCode();
                        aVar.b = responseCode;
                        if (responseCode != 200) {
                            String str2 = "http status code " + responseCode;
                            aVar.a = new Exception(str2);
                            throw new LookupException(str2);
                        }
                        try {
                            this.b.a(str, true);
                            try {
                                str = httpURLConnection.getInputStream();
                            } catch (IOException e2) {
                                e = e2;
                            }
                            try {
                                try {
                                    List<ni> b2 = b(kz.a((InputStream) str, "UTF-8"));
                                    aVar.c = SystemClock.elapsedRealtime() - elapsedRealtime;
                                    if (b2 == null) {
                                        list = new ArrayList<>();
                                        int length = strArr.length;
                                        while (i < length) {
                                            String str3 = strArr[i];
                                            ni niVar = new ni();
                                            niVar.a = "ali";
                                            niVar.b = str3;
                                            list.add(niVar);
                                            i++;
                                        }
                                    } else {
                                        list = b2;
                                    }
                                    aVar.e = list;
                                    if (this.a != null) {
                                        this.a.a(aVar);
                                    }
                                    kz.a((InputStream) str);
                                    if (httpURLConnection != null) {
                                        httpURLConnection.disconnect();
                                    }
                                    return b2;
                                } catch (JSONException e3) {
                                    aVar.b = -3;
                                    aVar.a = e3;
                                    throw new LookupException(e3);
                                }
                            } catch (IOException e4) {
                                e = e4;
                                aVar.b = -2;
                                aVar.a = e;
                                throw new LookupException(e);
                            }
                        } catch (Throwable th) {
                            inputStream = str;
                            th = th;
                            aVar.c = SystemClock.elapsedRealtime() - elapsedRealtime;
                            ArrayList arrayList = new ArrayList();
                            int length2 = strArr.length;
                            while (i < length2) {
                                String str4 = strArr[i];
                                ni niVar2 = new ni();
                                niVar2.a = "ali";
                                niVar2.b = str4;
                                arrayList.add(niVar2);
                                i++;
                            }
                            aVar.e = arrayList;
                            if (this.a != null) {
                                this.a.a(aVar);
                            }
                            kz.a(inputStream);
                            if (httpURLConnection != null) {
                                httpURLConnection.disconnect();
                            }
                            throw th;
                        }
                    } catch (IOException e5) {
                        aVar.b = -1;
                        aVar.a = e5;
                        this.b.a(str, false);
                        throw new LookupException(e5);
                    }
                } catch (Throwable th2) {
                    th = th2;
                }
            } catch (IOException e6) {
                aVar.b = -1;
                aVar.a = e6;
                this.b.a(str, false);
                throw new LookupException(e6);
            }
        } catch (Throwable th3) {
            th = th3;
            httpURLConnection = null;
        }
    }

    private Uri a(String str, String[] strArr) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strArr.length; i++) {
            sb.append(strArr[i]);
            if (i != strArr.length - 1) {
                sb.append(",");
            }
        }
        return new Uri.Builder().scheme("http").authority(str).appendPath("191607").appendPath("resolve").appendQueryParameter(IjkMediaPlayer.OnNativeInvokeListener.ARG_DNS_HOST, sb.toString()).build();
    }

    private List<ni> b(String str) throws JSONException {
        JSONArray optJSONArray = new JSONObject(str).optJSONArray("dns");
        if (optJSONArray == null) {
            return null;
        }
        int length = optJSONArray.length();
        ArrayList arrayList = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            JSONObject optJSONObject = optJSONArray.optJSONObject(i);
            if (optJSONObject != null) {
                String optString = optJSONObject.optString(IjkMediaPlayer.OnNativeInvokeListener.ARG_DNS_HOST);
                JSONArray optJSONArray2 = optJSONObject.optJSONArray("ips");
                if (!TextUtils.isEmpty(optString) && optJSONArray2 != null && optJSONArray2.length() > 0) {
                    int length2 = optJSONArray2.length();
                    ni niVar = new ni();
                    niVar.a = "ali";
                    niVar.b = optString;
                    niVar.d = optJSONObject.optInt("ttl");
                    niVar.e = optJSONObject.optInt("origin_ttl");
                    niVar.c = new ArrayList(length2);
                    for (int i2 = 0; i2 < length2; i2++) {
                        niVar.c.add(optJSONArray2.optString(i2));
                    }
                    arrayList.add(niVar);
                }
            }
        }
        return arrayList;
    }

    static class b {
        static final String[] a = {"203.107.1.65", "203.107.1.34", "203.107.1.66", "203.107.1.33"};
        private static final Comparator<a> d = new Comparator<a>() {
            @Override
            public int compare(a aVar, a aVar2) {
                if (aVar.b > aVar2.b) {
                    return -1;
                }
                if (aVar.c > aVar2.c) {
                    return 1;
                }
                return aVar.c == aVar2.c ? 0 : -1;
            }
        };
        private boolean b = true;
        private LinkedList<a> c = new LinkedList<>();

        b() {
            for (String str : a) {
                this.c.add(new a(str));
            }
        }

        synchronized List<String> a() {
            ArrayList arrayList;
            int length = this.b ? a.length : a.length - 1;
            Collections.sort(this.c, d);
            arrayList = new ArrayList(length);
            for (int i = 0; i < length; i++) {
                arrayList.add(this.c.get(i).a);
            }
            if (this.b) {
                this.b = false;
            }
            return arrayList;
        }

        synchronized void a(String str, boolean z) {
            Iterator<a> it = this.c.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                a next = it.next();
                if (next.a.equals(str)) {
                    if (z) {
                        next.b++;
                    } else {
                        next.c++;
                    }
                }
            }
        }
    }

    static class a {
        String a;
        int b;
        int c;

        public a(String str) {
            this.a = str;
        }
    }
}