NIMSDK-AOS  10.5.0
ServerAddresses.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk;
2 
3 import android.util.Pair;
4 import androidx.annotation.Nullable;
5 import com.netease.nimlib.push.net.lbs.IPVersion;
6 import com.netease.nimlib.push.packet.asymmetric.AsymmetricType;
7 import com.netease.nimlib.push.packet.symmetry.SymmetryType;
8 import com.netease.nimlib.util.CollectionUtil;
9 import java.io.Serializable;
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.HashSet;
13 import java.util.List;
14 import java.util.Set;
15 import org.json.JSONException;
16 import org.json.JSONObject;
17 
21 public class ServerAddresses implements Serializable {
22  public static final String KEY_MODULE = "KEY_MODULE";
23  public static final String KEY_PUBLIC_KEY_VERSION = "KEY_PUBLIC_KEY_VERSION";
24  public static final String KEY_LBS = "KEY_LBS";
25  public static final String KEY_LBS_BACKUP = "KEY_LBS_BACKUP";
26  public static final String KEY_DEFAULT_LINK = "KEY_DEFAULT_LINK";
27  public static final String KEY_DEFAULT_LINK_BACKUP = "KEY_DEFAULT_LINK_BACKUP";
28  public static final String KEY_NOS_UPLOAD_LBS = "KEY_NOS_UPLOAD_LBS";
29  public static final String KEY_NOS_UPLOAD_DEFAULT_LINK = "KEY_NOS_UPLOAD_DEFAULT_LINK";
30  public static final String KEY_NOS_UPLOAD = "KEY_NOS_UPLOAD";
31  public static final String KEY_NOS_SUPPORT_HTTPS = "KEY_NOS_SUPPORT_HTTPS";
32  public static final String KEY_NOS_DOWNLOAD_URL_FORMAT = "KEY_NOS_DOWNLOAD_URL_FORMAT";
33  public static final String KEY_NOS_DOWNLOAD = "KEY_NOS_DOWNLOAD";
34  public static final String KEY_NOS_ACCESS = "KEY_NOS_ACCESS";
35  public static final String KEY_NT_SERVER_ADDRESS = "KEY_NT_SERVER_ADDRESS";
36  public static final String KEY_BD_SERVER_ADDRESS = "KEY_BD_SERVER_ADDRESS";
37  public static final String KEY_TEST = "KEY_TEST";
38  public static final String KEY_DEDICATED_CLUSTE_FLAG = "KEY_DEDICATED_CLUSTE_FLAG";
39  public static final String KEY_NEGO_KEY_NECA = "KEY_NEGO_KEY_NECA";
40  public static final String KEY_NEGO_KEY_ENCA_KEY_VERSION = "KEY_NEGO_KEY_ENCA_KEY_VERSION";
41  public static final String KEY_NEGO_KEY_ENCA_KEY_PARTA = "KEY_NEGO_KEY_ENCA_KEY_PARTA";
42  public static final String KEY_NEGO_KEY_ENCA_KEY_PARTB = "KEY_NEGO_KEY_ENCA_KEY_PARTB";
43  public static final String KEY_COMM_ENCA = "KEY_COMM_ENCA";
44  public static final String KEY_LINK_IPV6 = "KEY_LINK_IPV6";
45  public static final String KEY_IP_PROTOCOL_VERSION = "KEY_IP_PROTOCOL_VERSION";
46  public static final String KEY_PROBE_IPV4_URL = "KEY_PROBE_IPV4_URL";
47  public static final String KEY_PROBE_IPV6_URL = "KEY_PROBE_IPV6_URL";
48  public static final String KEY_HANDSHAKE_TYPE = "KEY_HANDSHAKE_TYPE";
49  public static final String KEY_NOS_CDN_ENABLE = "KEY_NOS_CDN_ENABLE";
50  public static final String KEY_NOS_DOWNLOAD_SET = "KEY_NOS_DOWNLOAD_SET";
51  public static final String KEY_COMPASS_DATA_ENDPOINT = "KEY_COMPASS_DATA_ENDPOINT";
52 
56  public String module;
57 
61  public int publicKeyVersion = 0;
62 
69  public String lbs;
70 
77  public List<String> lbsBackup;
78 
83  public String defaultLink;
84 
89  public List<String> defaultLinkBackup;
90 
95  public String nosUploadLbs;
96 
101  public String nosUploadDefaultLink;
102 
107  public String nosUpload;
108 
112  public boolean nosSupportHttps = true;
113 
118  public String nosDownloadUrlFormat;
119 
124  public String nosDownload;
125 
132  public String nosAccess;
133 
137  public String ntServerAddress;
138 
142  public String bdServerAddress;
143 
147  public boolean test = false;
148 
153 
157  public AsymmetricType negoKeyNeca = AsymmetricType.RSA;
158 
163 
167  public String negoKeyEncaKeyParta;
168 
172  public String negoKeyEncaKeyPartb;
173 
178  public SymmetryType commEnca = SymmetryType.RC4;
179 
183  public String linkIpv6;
184 
189  public IPVersion ipProtocolVersion = IPVersion.IPV4;
190 
194  public String probeIpv4Url;
195 
199  public String probeIpv6Url;
200 
205 
209  public boolean nosCdnEnable = true;
210 
215  public Set<String> nosDownloadSet;
216 
220  public String compassDataEndpoint;
221 
222 
223  public JSONObject toJson() {
224  JSONObject object = new JSONObject();
225  try {
226  object.putOpt(KEY_MODULE, module);
227  object.putOpt(KEY_PUBLIC_KEY_VERSION, publicKeyVersion);
228  object.putOpt(KEY_LBS, lbs);
229  object.putOpt(KEY_LBS_BACKUP, CollectionUtil.toString(lbsBackup, ";"));
230  object.putOpt(KEY_DEFAULT_LINK, defaultLink);
231  object.putOpt(KEY_DEFAULT_LINK_BACKUP, CollectionUtil.toString(defaultLinkBackup, ";"));
232  object.putOpt(KEY_NOS_UPLOAD_LBS, nosUploadLbs);
233  object.putOpt(KEY_NOS_UPLOAD_DEFAULT_LINK, nosUploadDefaultLink);
234  object.putOpt(KEY_NOS_UPLOAD, nosUpload);
235  object.putOpt(KEY_NOS_SUPPORT_HTTPS, nosSupportHttps);
236  object.putOpt(KEY_NOS_DOWNLOAD_URL_FORMAT, nosDownloadUrlFormat);
237  object.putOpt(KEY_NOS_DOWNLOAD, nosDownload);
238  object.putOpt(KEY_NOS_ACCESS, nosAccess);
239  object.putOpt(KEY_NT_SERVER_ADDRESS, ntServerAddress);
240  object.putOpt(KEY_BD_SERVER_ADDRESS, bdServerAddress);
241  object.putOpt(KEY_TEST, test);
242  object.putOpt(KEY_DEDICATED_CLUSTE_FLAG, dedicatedClusteFlag);
243  object.putOpt(KEY_NEGO_KEY_NECA, negoKeyNeca == null ? AsymmetricType.RSA.getValue(): negoKeyNeca.getValue());
244  object.putOpt(KEY_NEGO_KEY_ENCA_KEY_VERSION, negoKeyEncaKeyVersion);
245  object.putOpt(KEY_NEGO_KEY_ENCA_KEY_PARTA, negoKeyEncaKeyParta);
246  object.putOpt(KEY_NEGO_KEY_ENCA_KEY_PARTB, negoKeyEncaKeyPartb);
247  object.putOpt(KEY_COMM_ENCA, commEnca == null ? SymmetryType.RC4.getValue() : commEnca.getValue());
248  object.putOpt(KEY_LINK_IPV6, linkIpv6);
249  object.putOpt(KEY_IP_PROTOCOL_VERSION, ipProtocolVersion == null ? IPVersion.IPV4.getValue() :ipProtocolVersion.getValue());
250  object.putOpt(KEY_PROBE_IPV4_URL, probeIpv4Url);
251  object.putOpt(KEY_PROBE_IPV6_URL, probeIpv6Url);
252  object.putOpt(KEY_HANDSHAKE_TYPE, handshakeType == null ? NimHandshakeType.V1.getValue() : handshakeType.getValue());
253  object.putOpt(KEY_NOS_CDN_ENABLE, nosCdnEnable);
254  object.putOpt(KEY_NOS_DOWNLOAD_SET, CollectionUtil.toString(nosDownloadSet, ";"));
255  object.putOpt(KEY_COMPASS_DATA_ENDPOINT, compassDataEndpoint);
256  } catch (JSONException e) {
257  e.printStackTrace();
258  }
259  return object;
260  }
261 
262  public static ServerAddresses fromJson(@Nullable JSONObject object) {
263  if (object == null) {
264  return null;
265  }
266  ServerAddresses serverAddresses = new ServerAddresses();
267 
268  serverAddresses.module = object.optString(KEY_MODULE);
269  serverAddresses.publicKeyVersion = object.optInt(KEY_PUBLIC_KEY_VERSION);
270  serverAddresses.lbs = object.optString(KEY_LBS);
271  serverAddresses.lbsBackup = new ArrayList<>(Arrays.asList(object.optString(KEY_LBS_BACKUP).split(";")));
272  serverAddresses.defaultLink = object.optString(KEY_DEFAULT_LINK);
273  serverAddresses.defaultLinkBackup = new ArrayList<>(Arrays.asList(object.optString(KEY_DEFAULT_LINK_BACKUP).split(";")));
274  serverAddresses.nosUploadLbs = object.optString(KEY_NOS_UPLOAD_LBS);
275  serverAddresses.nosUploadDefaultLink = object.optString(KEY_NOS_UPLOAD_DEFAULT_LINK);
276  serverAddresses.nosUpload = object.optString(KEY_NOS_UPLOAD);
277  serverAddresses.nosSupportHttps = object.optBoolean(KEY_NOS_SUPPORT_HTTPS);
278  serverAddresses.nosDownloadUrlFormat = object.optString(KEY_NOS_DOWNLOAD_URL_FORMAT);
279  serverAddresses.nosDownload = object.optString(KEY_NOS_DOWNLOAD);
280  serverAddresses.nosAccess = object.optString(KEY_NOS_ACCESS);
281  serverAddresses.ntServerAddress = object.optString(KEY_NT_SERVER_ADDRESS);
282  serverAddresses.bdServerAddress = object.optString(KEY_BD_SERVER_ADDRESS);
283  serverAddresses.test = object.optBoolean(KEY_TEST);
284  serverAddresses.dedicatedClusteFlag = object.optInt(KEY_DEDICATED_CLUSTE_FLAG);
285  serverAddresses.negoKeyNeca = AsymmetricType.value(object.optInt(KEY_NEGO_KEY_NECA));
286  serverAddresses.negoKeyEncaKeyVersion = object.optInt(KEY_NEGO_KEY_ENCA_KEY_VERSION);
287  serverAddresses.negoKeyEncaKeyParta = object.optString(KEY_NEGO_KEY_ENCA_KEY_PARTA);
288  serverAddresses.negoKeyEncaKeyPartb = object.optString(KEY_NEGO_KEY_ENCA_KEY_PARTB);
289  serverAddresses.commEnca = SymmetryType.value(object.optInt(KEY_COMM_ENCA));
290  serverAddresses.linkIpv6 = object.optString(KEY_LINK_IPV6);
291  serverAddresses.ipProtocolVersion = IPVersion.value(object.optInt(KEY_IP_PROTOCOL_VERSION));
292  serverAddresses.probeIpv4Url = object.optString(KEY_PROBE_IPV4_URL);
293  serverAddresses.probeIpv6Url = object.optString(KEY_PROBE_IPV6_URL);
294  serverAddresses.handshakeType = NimHandshakeType.value(object.optInt(KEY_HANDSHAKE_TYPE));
295  serverAddresses.nosCdnEnable = object.optBoolean(KEY_NOS_CDN_ENABLE);
296  serverAddresses.nosDownloadSet = new HashSet<>(Arrays.asList(object.optString(KEY_NOS_DOWNLOAD_SET).split(";")));
297  serverAddresses.compassDataEndpoint = object.optString(KEY_COMPASS_DATA_ENDPOINT);
298  return serverAddresses;
299  }
300 
301 }
int negoKeyEncaKeyVersion
"交换密钥"协议加密算法密钥版本 version 自定义时则必填
String ntServerAddress
云信运行时异常统计服务器地址
NimHandshakeType handshakeType
握手协议选择字段
String nosDownloadUrlFormat
[4.6.0版本新增] NOS下载地址拼接模板,用于拼接最终得到的下载地址。 默认是 {bucket}.nosdn.127.net/{object},SDK 上传资源后生成的下载地址为 https://bucket.nosdn.127.net/object
String negoKeyEncaKeyPartb
"交换密钥"协议加密算法密钥 part B 自定义时则必填 BigNumHex string 不含0x RSA: EXP, SM2: Y
String lbs
IM LBS服务器地址,通过它获取IM link 地址信息 填http/https地址
int dedicatedClusteFlag
是否为专属集群{1(是), 0(否)}
String nosDownload
NOS下载地址的host,用于拼接最终获得的文件URL地址,也支持该host替换成下载加速域名/地址 nosAccess...
IPVersion ipProtocolVersion
IP协议版本{0(IPV4), 1(IPV6), 2(Auto, SDK测试后自行选择, 存在性能损耗)}。 默认: 0(IPV4) 非对称加密 ...
static ServerAddresses fromJson(@Nullable JSONObject object)
Set< String > nosDownloadSet
每个元素为使用过的NOS下载地址的特征以及桶名是否在host中组成的Pair对象 如new Pair("nim.nos.netease.com", true), new Pair("nos.netease.com/nim", false)等
AsymmetricType negoKeyNeca
"交换密钥"协议加密算法 {1(RSA),2(SM2)}, def:1(RSA) 非对称加密
String nosAccess
NOS下载加速域名/地址,用于替换NOS下载url中的 nosDownload。 提供两种方式: 1) [4.4.0+开始支持]模板方式:填写云信规定的两种模板:{bucket}.nosdn.127.net/{object} 或者 nosdn.127.net/{bucket}/{object},其中 {bucket} 和 {object} 作为标识符,必须填写。域名部分可以替换为您申请的加速域名。 2) [所有版本支持]非模板方式:填写用于加速的 http/https地址,例如:http://111.222.111.22:9090
String module
连接云信服务器加密数据通道的公钥参数1 rsaModulus
String nosUploadDefaultLink
NOS上传默认的link服务器地址,当NOS LBS不可用时先连接该地址 填http/https地址
boolean nosCdnEnable
是否优先使用Cdn域名进行NOS下载
String compassDataEndpoint
数据上报端点
String probeIpv6Url
探测ipv6地址类型使用的url, IPProtVersion == 2或3 时生效
String probeIpv4Url
探测ipv4地址类型使用的url, IPProtVersion == 2或3 时生效
SymmetryType commEnca
通信加密算法 {1(RC4), 2(AES128), 4(SM4)} 默认: 1(RC4) 对称加密
String negoKeyEncaKeyParta
"交换密钥"协议加密算法密钥 part A 自定义时则必填 BigNumHex string 不含0x RSA: module, SM2: X
String nosUpload
NOS上传服务器主机地址(仅nosSupportHttps=true时有效,用作https上传时的域名校验及http header host字段...
List< String > defaultLinkBackup
IM 默认的link服务器地址不可用时,连接这些地址 填"IP/Host:PORT"
static final String KEY_NEGO_KEY_ENCA_KEY_VERSION
String nosUploadLbs
NOS上传LBS服务器地址 填http/https地址
云信私有化服务器配置项
String bdServerAddress
云信数据统计服务器地址
String linkIpv6
ipv6的缺省连接地址
int publicKeyVersion
连接云信服务器加密数据通道的公钥的版本号(默认0)
String defaultLink
IM 默认的link服务器地址,当IM LBS不可用时先连接该地址 填"IP/Host:PORT"
List< String > lbsBackup
备用IM LBS服务器地址,通过它获取IM link 地址信息 填http/https地址
boolean nosSupportHttps
NOS上传是否需要支持https。SDK 3.2版本后默认支持https,同时需要配置 nosUpload!