You need to enable JavaScript to run this app.
导航

DnsTaskInfo 类

最近更新时间2023.10.08 19:55:26

首次发布时间2023.03.22 20:50:06

定义

public class DnsTaskInfo {
    private final long mDuration;
    private final TaskInfoSource mType;
    private final int mNetError;

    private SubHttpDnsType mSubHttpDnsType = SubHttpDnsType.PRIVATE_PROTOCOL;
    private final List<DohSubTaskInfo> mDohSubTaskInfos = new ArrayList<>();

    public enum SubHttpDnsType {
        PRIVATE_PROTOCOL,
        DOH
    }

    public static class DohSubTaskInfo {
        public enum DohSubTaskType {
            IPV4,
            IPV6
        }

        public DohSubTaskType mDohSubTaskType;
        public int mNetError;
        public long mDuration;
    }

    public enum TaskInfoSource {
        HTTPDNS(0),
        LOCALDNS(1);

        TaskInfoSource(int value) {
            mValue = value;
        }

        final int mValue;
    }

    // for localdns
    public DnsTaskInfo(long duration, TaskInfoSource type, int netError) {
        mDuration = duration;
        mType = type;
        mNetError = netError;
        if (HttpDns.getService().useDoh()) {
            mSubHttpDnsType = SubHttpDnsType.DOH;
        } else {
            mSubHttpDnsType = SubHttpDnsType.PRIVATE_PROTOCOL;
        }
    }

    // for httpdns
    public DnsTaskInfo(long duration, TaskInfoSource type, int netError, List<DohSubTaskInfo> dohSubTaskInfos) {
        mDuration = duration;
        mType = type;
        mNetError = netError;
        if (dohSubTaskInfos != null) {
            mDohSubTaskInfos.addAll(dohSubTaskInfos);
        }
        if (HttpDns.getService().useDoh()) {
            mSubHttpDnsType = SubHttpDnsType.DOH;
        } else {
            mSubHttpDnsType = SubHttpDnsType.PRIVATE_PROTOCOL;
        }
    }

    public int getNetError() {
        return mNetError;
    }

    public long getDuration() {
        return mDuration;
    }

    public int getType() {
        return mType.mValue;
    }

    public SubHttpDnsType getSubHttpDnsType() {
        return mSubHttpDnsType;
    }

    public List<DohSubTaskInfo> getDohSubTaskInfos() {
        return mDohSubTaskInfos;
    }

    public JSONObject toJson() {
        JSONObject taskInfoJson = new JSONObject();
        try {
            taskInfoJson.put("type", mType.mValue);
            taskInfoJson.put("duration", getDuration());
            taskInfoJson.put("error", getNetError());
            if (mType == TaskInfoSource.HTTPDNS) {
                taskInfoJson.put("httpdns_subtype", mSubHttpDnsType.ordinal());
                if (mSubHttpDnsType == SubHttpDnsType.DOH) {
                    JSONArray dohSubTasksJson = new JSONArray();
                    for (DohSubTaskInfo dohSubTaskInfo : mDohSubTaskInfos) {
                        JSONObject subTaskJson = new JSONObject();
                        subTaskJson.put("type", dohSubTaskInfo.mDohSubTaskType.ordinal());
                        subTaskJson.put("duration", dohSubTaskInfo.mDuration);
                        subTaskJson.put("error", dohSubTaskInfo.mNetError);
                        dohSubTasksJson.put(subTaskJson);
                    }
                    taskInfoJson.put("doh_task_infos", dohSubTasksJson);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return taskInfoJson;
    }
}


作用

SDK 解析任务的过程信息。

属性

属性描述
mDurationSDK 完成解析任务所需要的时长。单位为毫秒。
mType解析任务的类型。参见 TaskInfoSource 枚举
mNetError错误码。
mSubHttpDnsType使用 HTTPDNS 服务端解析时,SDK 使用的请求类型。
  • PRIVATE_PROTOCOL(0):HTTPDNS 请求。
  • DOH(1):DoH 请求。
mDohSubTaskInfos参见 DohSubTaskInfo 类

构造函数

包含 2 个构造函数,分别返回 Local DNS 服务器和 HTTPDNS 服务端的解析结果。

// 返回 Local DNS 服务器的解析结果
public DnsTaskInfo(long duration, TaskInfoSource type, int netError)

// 返回 HTTPDNS 服务端的解析结果
public DnsTaskInfo(long duration, TaskInfoSource type, int netError, List<DohSubTaskInfo> dohSubTaskInfos)

成员

TaskInfoSource 枚举

解析任务的类型。

枚举描述
HTTPDNS0:使用 HTTPDNS 服务端解析。
LOCALDNS1:使用 Local DNS 解析。

DohSubTaskInfo 类

基于 DoH 协议的解析任务的信息,包含以下成员:

属性

属性描述
mDurationSDK 完成解析任务所需要的时长。单位为毫秒。
mDohSubTaskType解析任务获取的 IP 地址类型。参见 DohSubTaskType 枚举
mNetError错误码。

DohSubTaskType 枚举

解析任务获取的 IP 地址类型。

枚举描述
IPV4IPv4 地址。
IPV6IPv6 地址。