· 6 years ago · Apr 21, 2020, 10:28 AM
1public void startPhotonServer(String password,String ethRPCEndPoint) {
2 try {
3 if (PhotonApplication.photonStatus && PhotonApplication.api == null ){
4 return;
5 }
6 final String tempAddress = WalletInfoUtils.getInstance().getSelectAddress();
7 ThreadPoolUtils.getInstance().getCachedThreadPool().execute(() -> {
8 try {
9 if (PhotonApplication.api != null && PhotonApplication.photonStatus) {
10 if(PhotonApplication.mPhotonSubscribe !=null){
11 PhotonApplication.mPhotonSubscribe.unsubscribe();
12 }
13 PhotonApplication.api.stop();
14 PhotonApplication.api = null;
15 PhotonApplication.photonStatus = false;
16 PhotonApplication.photonStatusStatus = false;
17 }
18 String clientIP = PhotonNetUtil.getInstance().getCurWifiIp();
19 if (TextUtils.isEmpty(clientIP)){
20 clientIP = "0.0.0.0";
21 }
22 String fileName = "photon_log" + "(" + tempAddress + ")" + ".txt";
23 SDCardCtrl.checkPathExist();
24 File logFile = new File(SDCardCtrl.getPhotonErrorLogPath(), fileName);
25 if (!logFile.exists()) {
26 logFile.createNewFile();
27 }
28 PhotonApplication.mPhotonStatusVo = new PhotonStatusVo();
29 PhotonApplication.mPhotonStatusVo.setEthStatus(PhotonStatusType.Default);
30 PhotonApplication.mPhotonStatusVo.setXmppStatus(PhotonStatusType.Default);
31 Bundle bundle = new Bundle();
32 Utils.intentAction(PhotonApplication.mContext, PhotonUrl.ACTION_RAIDEN_CONNECTION_STATE, bundle);
33 PhotonApplication.photonStatus = true;
34 /**
35 * 参数: parameter
36 * address string– 光子节点所使用的账户地址 Account address used by the photon node
37 * keystorePath string – 账户私钥保存路径 Account private key save path
38 * ethRPCEndPoint string – 公链节点host,http协议 Public chain node host, http protocol
39 * dataDir string – Photon db路径 测试环境和正式环境数据不一致,所以路径也不一样,
40 * passwordfile string – 账户密码文件路径 Account password file path
41 * apiAddr string – http api 监听端口 Http api listening port
42 * listenAddr string – udp 监听端口 Udp listening port
43 * ogFile string – 日志文件路径 Log file path
44 * registryAddress string – TokenNetworkRegistry合约地址 Contract address
45 * otherArgs mobile.Strings – 其他参数,参考photon -h Other parameters
46 * */
47 Strings otherArg= Mobile.newStrings(1);
48 String arg = "--xmpp";
49// String arg = "--xmpp" : "--matrix";
50 otherArg.set(0,arg);
51 String dataDir = PhotonApplication.mContext.getFilesDir().getAbsolutePath() + SDCardCtrl.PHOTON_DATA;
52 PhotonApplication.api = Mobile.startUp(//start up photon
53 tempAddress,
54 PhotonApplication.mContext.getFilesDir().getAbsolutePath() + SDCardCtrl.WALLET_PATH,
55 TextUtils.isEmpty(ethRPCEndPoint) ? PhotonUrl.PHOTON_URL_WS : ethRPCEndPoint,
56 dataDir,
57 password,
58 "127.0.0.1:5001",
59 clientIP + ":40001",
60 logFile.getAbsolutePath(),
61 ContractUtils.CONTACT_PHOTON_ADDRESS,
62 otherArg);
63 PhotonApplication.mPhotonSubscribe = PhotonApplication.api.subscribe(new NotifyHandler() {
64
65 @Override
66 public void onError(long l, String s) {
67 PhotonApplication.photonStatus = false;
68 onStartPhotonError(true);
69 }
70
71 @Override
72 public void onNotify(long l, String s) {
73 onPhotonNotify(l,s);
74 }
75
76 @Override
77 public void onReceivedTransfer(String s) {
78 updateChannelBalance(s);
79 }
80
81 @Override
82 public void onStatusChange(String s) {
83 updateStatusChanged(s);
84 }
85 });
86 } catch (Exception e) {
87 startUpError(e);
88 }
89 });
90 } catch (Exception e) {
91 startUpError(e);
92 }
93 }