NIMSDK-AOS  9.16.3
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 
55  public String module;
56 
60  public int publicKeyVersion = 0;
61 
68  public String lbs;
69 
76  public List<String> lbsBackup;
77 
82  public String defaultLink;
83 
88  public List<String> defaultLinkBackup;
89 
94  public String nosUploadLbs;
95 
100  public String nosUploadDefaultLink;
101 
106  public String nosUpload;
107 
111  public boolean nosSupportHttps = true;
112 
117  public String nosDownloadUrlFormat;
118 
123  public String nosDownload;
124 
131  public String nosAccess;
132 
136  public String ntServerAddress;
137 
141  public String bdServerAddress;
142 
146  public boolean test = false;
147 
152 
156  public AsymmetricType negoKeyNeca = AsymmetricType.RSA;
157 
162 
166  public String negoKeyEncaKeyParta;
167 
171  public String negoKeyEncaKeyPartb;
172 
177  public SymmetryType commEnca = SymmetryType.RC4;
178 
182  public String linkIpv6;
183 
188  public IPVersion ipProtocolVersion = IPVersion.IPV4;
189 
193  public String probeIpv4Url;
194 
198  public String probeIpv6Url;
199 
204 
208  public boolean nosCdnEnable = true;
209 
214  public Set<String> nosDownloadSet;
215 
216 
217  public JSONObject toJson() {
218  JSONObject object = new JSONObject();
219  try {
220  object.putOpt(KEY_MODULE, module);
221  object.putOpt(KEY_PUBLIC_KEY_VERSION, publicKeyVersion);
222  object.putOpt(KEY_LBS, lbs);
223  object.putOpt(KEY_LBS_BACKUP, CollectionUtil.toString(lbsBackup, ";"));
224  object.putOpt(KEY_DEFAULT_LINK, defaultLink);
225  object.putOpt(KEY_DEFAULT_LINK_BACKUP, CollectionUtil.toString(defaultLinkBackup, ";"));
226  object.putOpt(KEY_NOS_UPLOAD_LBS, nosUploadLbs);
227  object.putOpt(KEY_NOS_UPLOAD_DEFAULT_LINK, nosUploadDefaultLink);
228  object.putOpt(KEY_NOS_UPLOAD, nosUpload);
229  object.putOpt(KEY_NOS_SUPPORT_HTTPS, nosSupportHttps);
230  object.putOpt(KEY_NOS_DOWNLOAD_URL_FORMAT, nosDownloadUrlFormat);
231  object.putOpt(KEY_NOS_DOWNLOAD, nosDownload);
232  object.putOpt(KEY_NOS_ACCESS, nosAccess);
233  object.putOpt(KEY_NT_SERVER_ADDRESS, ntServerAddress);
234  object.putOpt(KEY_BD_SERVER_ADDRESS, bdServerAddress);
235  object.putOpt(KEY_TEST, test);
236  object.putOpt(KEY_DEDICATED_CLUSTE_FLAG, dedicatedClusteFlag);
237  object.putOpt(KEY_NEGO_KEY_NECA, negoKeyNeca == null ? AsymmetricType.RSA.getValue(): negoKeyNeca.getValue());
238  object.putOpt(KEY_NEGO_KEY_ENCA_KEY_VERSION, negoKeyEncaKeyVersion);
239  object.putOpt(KEY_NEGO_KEY_ENCA_KEY_PARTA, negoKeyEncaKeyParta);
240  object.putOpt(KEY_NEGO_KEY_ENCA_KEY_PARTB, negoKeyEncaKeyPartb);
241  object.putOpt(KEY_COMM_ENCA, commEnca == null ? SymmetryType.RC4.getValue() : commEnca.getValue());
242  object.putOpt(KEY_LINK_IPV6, linkIpv6);
243  object.putOpt(KEY_IP_PROTOCOL_VERSION, ipProtocolVersion == null ? IPVersion.IPV4.getValue() :ipProtocolVersion.getValue());
244  object.putOpt(KEY_PROBE_IPV4_URL, probeIpv4Url);
245  object.putOpt(KEY_PROBE_IPV6_URL, probeIpv6Url);
246  object.putOpt(KEY_HANDSHAKE_TYPE, handshakeType == null ? NimHandshakeType.V1.getValue() : handshakeType.getValue());
247  object.putOpt(KEY_NOS_CDN_ENABLE, nosCdnEnable);
248  object.putOpt(KEY_NOS_DOWNLOAD_SET, CollectionUtil.toString(nosDownloadSet, ";"));
249  } catch (JSONException e) {
250  e.printStackTrace();
251  }
252  return object;
253  }
254 
255  public static ServerAddresses fromJson(@Nullable JSONObject object) {
256  if (object == null) {
257  return null;
258  }
259  ServerAddresses serverAddresses = new ServerAddresses();
260 
261  serverAddresses.module = object.optString(KEY_MODULE);
262  serverAddresses.publicKeyVersion = object.optInt(KEY_PUBLIC_KEY_VERSION);
263  serverAddresses.lbs = object.optString(KEY_LBS);
264  serverAddresses.lbsBackup = new ArrayList<>(Arrays.asList(object.optString(KEY_LBS_BACKUP).split(";")));
265  serverAddresses.defaultLink = object.optString(KEY_DEFAULT_LINK);
266  serverAddresses.defaultLinkBackup = new ArrayList<>(Arrays.asList(object.optString(KEY_DEFAULT_LINK_BACKUP).split(";")));
267  serverAddresses.nosUploadLbs = object.optString(KEY_NOS_UPLOAD_LBS);
268  serverAddresses.nosUploadDefaultLink = object.optString(KEY_NOS_UPLOAD_DEFAULT_LINK);
269  serverAddresses.nosUpload = object.optString(KEY_NOS_UPLOAD);
270  serverAddresses.nosSupportHttps = object.optBoolean(KEY_NOS_SUPPORT_HTTPS);
271  serverAddresses.nosDownloadUrlFormat = object.optString(KEY_NOS_DOWNLOAD_URL_FORMAT);
272  serverAddresses.nosDownload = object.optString(KEY_NOS_DOWNLOAD);
273  serverAddresses.nosAccess = object.optString(KEY_NOS_ACCESS);
274  serverAddresses.ntServerAddress = object.optString(KEY_NT_SERVER_ADDRESS);
275  serverAddresses.bdServerAddress = object.optString(KEY_BD_SERVER_ADDRESS);
276  serverAddresses.test = object.optBoolean(KEY_TEST);
277  serverAddresses.dedicatedClusteFlag = object.optInt(KEY_DEDICATED_CLUSTE_FLAG);
278  serverAddresses.negoKeyNeca = AsymmetricType.value(object.optInt(KEY_NEGO_KEY_NECA));
279  serverAddresses.negoKeyEncaKeyVersion = object.optInt(KEY_NEGO_KEY_ENCA_KEY_VERSION);
280  serverAddresses.negoKeyEncaKeyParta = object.optString(KEY_NEGO_KEY_ENCA_KEY_PARTA);
281  serverAddresses.negoKeyEncaKeyPartb = object.optString(KEY_NEGO_KEY_ENCA_KEY_PARTB);
282  serverAddresses.commEnca = SymmetryType.value(object.optInt(KEY_COMM_ENCA));
283  serverAddresses.linkIpv6 = object.optString(KEY_LINK_IPV6);
284  serverAddresses.ipProtocolVersion = IPVersion.value(object.optInt(KEY_IP_PROTOCOL_VERSION));
285  serverAddresses.probeIpv4Url = object.optString(KEY_PROBE_IPV4_URL);
286  serverAddresses.probeIpv6Url = object.optString(KEY_PROBE_IPV6_URL);
287  serverAddresses.handshakeType = NimHandshakeType.value(object.optInt(KEY_HANDSHAKE_TYPE));
288  serverAddresses.nosCdnEnable = object.optBoolean(KEY_NOS_CDN_ENABLE);
289  serverAddresses.nosDownloadSet = new HashSet<>(Arrays.asList(object.optString(KEY_NOS_DOWNLOAD_SET).split(";")));
290  return serverAddresses;
291  }
292 
293 }
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 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!