1 package com.netease.nimlib.sdk;
3 import android.util.Pair;
4 import androidx.annotation.Nullable;
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;
15 import org.json.JSONException;
16 import org.json.JSONObject;
21 @SuppressWarnings(
"java:S1104")
23 public static final String KEY_MODULE =
"KEY_MODULE";
24 public static final String KEY_PUBLIC_KEY_VERSION =
"KEY_PUBLIC_KEY_VERSION";
25 public static final String KEY_LBS =
"KEY_LBS";
26 public static final String KEY_LBS_BACKUP =
"KEY_LBS_BACKUP";
27 public static final String KEY_DEFAULT_LINK =
"KEY_DEFAULT_LINK";
28 public static final String KEY_DEFAULT_LINK_BACKUP =
"KEY_DEFAULT_LINK_BACKUP";
29 public static final String KEY_NOS_UPLOAD_LBS =
"KEY_NOS_UPLOAD_LBS";
30 public static final String KEY_NOS_UPLOAD_DEFAULT_LINK =
"KEY_NOS_UPLOAD_DEFAULT_LINK";
31 public static final String KEY_NOS_UPLOAD =
"KEY_NOS_UPLOAD";
32 public static final String KEY_NOS_SUPPORT_HTTPS =
"KEY_NOS_SUPPORT_HTTPS";
33 public static final String KEY_NOS_DOWNLOAD_URL_FORMAT =
"KEY_NOS_DOWNLOAD_URL_FORMAT";
34 public static final String KEY_NOS_DOWNLOAD =
"KEY_NOS_DOWNLOAD";
35 public static final String KEY_NOS_ACCESS =
"KEY_NOS_ACCESS";
36 public static final String KEY_NT_SERVER_ADDRESS =
"KEY_NT_SERVER_ADDRESS";
37 public static final String KEY_BD_SERVER_ADDRESS =
"KEY_BD_SERVER_ADDRESS";
38 public static final String KEY_TEST =
"KEY_TEST";
39 public static final String KEY_DEDICATED_CLUSTE_FLAG =
"KEY_DEDICATED_CLUSTE_FLAG";
40 public static final String KEY_NEGO_KEY_NECA =
"KEY_NEGO_KEY_NECA";
41 public static final String KEY_NEGO_KEY_ENCA_KEY_VERSION =
"KEY_NEGO_KEY_ENCA_KEY_VERSION";
42 public static final String KEY_NEGO_KEY_ENCA_KEY_PARTA =
"KEY_NEGO_KEY_ENCA_KEY_PARTA";
43 public static final String KEY_NEGO_KEY_ENCA_KEY_PARTB =
"KEY_NEGO_KEY_ENCA_KEY_PARTB";
44 public static final String KEY_COMM_ENCA =
"KEY_COMM_ENCA";
45 public static final String KEY_LINK_IPV6 =
"KEY_LINK_IPV6";
46 public static final String KEY_IP_PROTOCOL_VERSION =
"KEY_IP_PROTOCOL_VERSION";
47 public static final String KEY_PROBE_IPV4_URL =
"KEY_PROBE_IPV4_URL";
48 public static final String KEY_PROBE_IPV6_URL =
"KEY_PROBE_IPV6_URL";
49 public static final String KEY_HANDSHAKE_TYPE =
"KEY_HANDSHAKE_TYPE";
50 public static final String KEY_NOS_CDN_ENABLE =
"KEY_NOS_CDN_ENABLE";
51 public static final String KEY_NOS_DOWNLOAD_SET =
"KEY_NOS_DOWNLOAD_SET";
52 public static final String KEY_COMPASS_DATA_ENDPOINT =
"KEY_COMPASS_DATA_ENDPOINT";
62 public int publicKeyVersion = 0;
113 public boolean nosSupportHttps =
true;
148 public boolean test =
false;
158 public AsymmetricType negoKeyNeca = AsymmetricType.RSA;
179 public SymmetryType commEnca = SymmetryType.RC4;
190 public IPVersion ipProtocolVersion = IPVersion.IPV4;
210 public boolean nosCdnEnable =
true;
225 JSONObject
object =
new JSONObject();
227 object.putOpt(KEY_MODULE, module);
228 object.putOpt(KEY_PUBLIC_KEY_VERSION, publicKeyVersion);
229 object.putOpt(KEY_LBS, lbs);
230 object.putOpt(KEY_LBS_BACKUP, CollectionUtil.toString(lbsBackup,
";"));
231 object.putOpt(KEY_DEFAULT_LINK, defaultLink);
232 object.putOpt(KEY_DEFAULT_LINK_BACKUP, CollectionUtil.toString(defaultLinkBackup,
";"));
233 object.putOpt(KEY_NOS_UPLOAD_LBS, nosUploadLbs);
234 object.putOpt(KEY_NOS_UPLOAD_DEFAULT_LINK, nosUploadDefaultLink);
235 object.putOpt(KEY_NOS_UPLOAD, nosUpload);
236 object.putOpt(KEY_NOS_SUPPORT_HTTPS, nosSupportHttps);
237 object.putOpt(KEY_NOS_DOWNLOAD_URL_FORMAT, nosDownloadUrlFormat);
238 object.putOpt(KEY_NOS_DOWNLOAD, nosDownload);
239 object.putOpt(KEY_NOS_ACCESS, nosAccess);
240 object.putOpt(KEY_NT_SERVER_ADDRESS, ntServerAddress);
241 object.putOpt(KEY_BD_SERVER_ADDRESS, bdServerAddress);
242 object.putOpt(KEY_TEST, test);
243 object.putOpt(KEY_DEDICATED_CLUSTE_FLAG, dedicatedClusteFlag);
244 object.putOpt(KEY_NEGO_KEY_NECA, negoKeyNeca == null ? AsymmetricType.RSA.getValue(): negoKeyNeca.getValue());
245 object.putOpt(KEY_NEGO_KEY_ENCA_KEY_VERSION, negoKeyEncaKeyVersion);
246 object.putOpt(KEY_NEGO_KEY_ENCA_KEY_PARTA, negoKeyEncaKeyParta);
247 object.putOpt(KEY_NEGO_KEY_ENCA_KEY_PARTB, negoKeyEncaKeyPartb);
248 object.putOpt(KEY_COMM_ENCA, commEnca == null ? SymmetryType.RC4.getValue() : commEnca.getValue());
249 object.putOpt(KEY_LINK_IPV6, linkIpv6);
250 object.putOpt(KEY_IP_PROTOCOL_VERSION, ipProtocolVersion == null ? IPVersion.IPV4.getValue() :ipProtocolVersion.getValue());
251 object.putOpt(KEY_PROBE_IPV4_URL, probeIpv4Url);
252 object.putOpt(KEY_PROBE_IPV6_URL, probeIpv6Url);
254 object.putOpt(KEY_NOS_CDN_ENABLE, nosCdnEnable);
255 object.putOpt(KEY_NOS_DOWNLOAD_SET, CollectionUtil.toString(nosDownloadSet,
";"));
256 object.putOpt(KEY_COMPASS_DATA_ENDPOINT, compassDataEndpoint);
257 }
catch (JSONException e) {
264 if (
object == null) {
269 serverAddresses.
module =
object.optString(KEY_MODULE);
271 serverAddresses.
lbs =
object.optString(KEY_LBS);
272 serverAddresses.
lbsBackup =
new ArrayList<>(Arrays.asList(
object.optString(KEY_LBS_BACKUP).split(
";")));
273 serverAddresses.
defaultLink =
object.optString(KEY_DEFAULT_LINK);
274 serverAddresses.
defaultLinkBackup =
new ArrayList<>(Arrays.asList(
object.optString(KEY_DEFAULT_LINK_BACKUP).split(
";")));
275 serverAddresses.
nosUploadLbs =
object.optString(KEY_NOS_UPLOAD_LBS);
277 serverAddresses.
nosUpload =
object.optString(KEY_NOS_UPLOAD);
278 serverAddresses.
nosSupportHttps =
object.optBoolean(KEY_NOS_SUPPORT_HTTPS);
280 serverAddresses.
nosDownload =
object.optString(KEY_NOS_DOWNLOAD);
281 serverAddresses.
nosAccess =
object.optString(KEY_NOS_ACCESS);
282 serverAddresses.
ntServerAddress =
object.optString(KEY_NT_SERVER_ADDRESS);
283 serverAddresses.
bdServerAddress =
object.optString(KEY_BD_SERVER_ADDRESS);
284 serverAddresses.
test =
object.optBoolean(KEY_TEST);
286 serverAddresses.
negoKeyNeca = AsymmetricType.value(
object.optInt(KEY_NEGO_KEY_NECA));
290 serverAddresses.
commEnca = SymmetryType.value(
object.optInt(KEY_COMM_ENCA));
291 serverAddresses.
linkIpv6 =
object.optString(KEY_LINK_IPV6);
292 serverAddresses.
ipProtocolVersion = IPVersion.value(
object.optInt(KEY_IP_PROTOCOL_VERSION));
293 serverAddresses.
probeIpv4Url =
object.optString(KEY_PROBE_IPV4_URL);
294 serverAddresses.
probeIpv6Url =
object.optString(KEY_PROBE_IPV6_URL);
296 serverAddresses.
nosCdnEnable =
object.optBoolean(KEY_NOS_CDN_ENABLE);
297 serverAddresses.
nosDownloadSet =
new HashSet<>(Arrays.asList(
object.optString(KEY_NOS_DOWNLOAD_SET).split(
";")));
299 return serverAddresses;
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"
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!