2525import org .fisco .bcos .sdk .config .exceptions .ConfigException ;
2626import org .fisco .bcos .sdk .model .CryptoType ;
2727import org .fisco .bcos .sdk .model .Message ;
28+ import org .fisco .bcos .sdk .utils .SystemInformation ;
2829import org .slf4j .Logger ;
2930import org .slf4j .LoggerFactory ;
3031
@@ -152,30 +153,39 @@ private CheckCertExistenceResult checkCertExistence(boolean isSM) {
152153 public void start () throws NetworkException {
153154 boolean tryEcdsaConnect = false ;
154155 CheckCertExistenceResult result = null ;
156+ String ecdsaCryptoInfo = configOption .getCryptoMaterialConfig ().toString ();
155157 try {
156158 try {
157159 result = checkCertExistence (false );
158160 if (result .isCheckPassed ()) {
159161 logger .debug ("start connManager with ECDSA sslContext" );
160162 connManager .startConnect (configOption );
161163 connManager .startReconnectSchedule ();
162- tryEcdsaConnect = true ;
163164 return ;
164165 } else {
165166 logger .warn (
166- "Try to connect node with ECDSA sslContext failed, expected certPath: "
167- + configOption . getCryptoMaterialConfig (). toString ()
167+ "Try to connect node with ECDSA sslContext failed, the tried NON-SM certPath: "
168+ + ecdsaCryptoInfo
168169 + ", currentPath: "
169170 + new File ("" ).getAbsolutePath ());
170171 }
171172 } catch (NetworkException e ) {
172- tryEcdsaConnect = true ;
173173 configOption .reloadConfig (CryptoType .SM_TYPE );
174- result = checkCertExistence (true );
175- if (e .getErrorCode () == NetworkException .CONNECT_FAILED
176- || !result .isCheckPassed ()) {
177- throw e ;
174+ if (e .getErrorCode () == NetworkException .CONNECT_FAILED ) {
175+ String errorMessage = e .getMessage ();
176+ errorMessage +=
177+ "\n * If your blockchain is NON-SM, please provide the NON-SM certificates: "
178+ + ecdsaCryptoInfo
179+ + ".\n " ;
180+ errorMessage +=
181+ "\n * If your blockchain is SM, please provide the SM certificates: "
182+ + configOption .getCryptoMaterialConfig ().toString ()
183+ + "\n " ;
184+ throw new NetworkException (
185+ errorMessage + "\n " + SystemInformation .getSystemInformation ());
178186 }
187+ // means that all the ECDSA certificates exist
188+ tryEcdsaConnect = true ;
179189 connManager .stopNetty ();
180190 logger .debug (
181191 "start connManager with the ECDSA sslContext failed, try to use SM sslContext, error info: {}" ,
@@ -186,24 +196,49 @@ public void start() throws NetworkException {
186196 result = checkCertExistence (true );
187197 if (!result .isCheckPassed ()) {
188198 if (tryEcdsaConnect ) {
189- throw new NetworkException ("Certificate not exist:" + result .getErrorMessage ());
199+ String errorMessage =
200+ "\n * Try init the sslContext failed.\n \n * If your blockchain channel config is NON-SM, please provide the NON-SM certificates: "
201+ + ecdsaCryptoInfo
202+ + ".\n " ;
203+ errorMessage +=
204+ "\n * If your blockchain channel config is SM, please provide the missing certificates: "
205+ + result .getErrorMessage ()
206+ + "\n " ;
207+ throw new NetworkException (errorMessage );
190208 } else {
191- throw new NetworkException (
192- "Not providing all the certificates to connect to the node! Please provide the certificates to connect with the block-chain, expected certPath: ["
209+ String errorMessage =
210+ "\n # Not providing all the certificates to connect to the node! Please provide the certificates to connect with the block-chain.\n " ;
211+ errorMessage +=
212+ "\n * If your blockchain is NON-SM, please provide the NON-SM certificates: "
213+ + ecdsaCryptoInfo
214+ + ". \n " ;
215+ errorMessage +=
216+ "\n * If your blockchain is SM, please provide the SM certificates: "
193217 + configOption .getCryptoMaterialConfig ().toString ()
194- + "]" );
218+ + "\n " ;
219+ throw new NetworkException (errorMessage );
195220 }
196221 }
197- if ( tryEcdsaConnect ) {
222+ try {
198223 // create a new connectionManager to connect the node with the SM sslContext
199224 connManager = new ConnectionManager (configOption , handler );
225+ connManager .startConnect (configOption );
226+ connManager .startReconnectSchedule ();
227+ } catch (NetworkException e ) {
228+ String errorMessage = e .getMessage ();
229+ errorMessage +=
230+ "\n * If your blockchain channel config is NON-SM, please provide the NON-SM certificates: "
231+ + ecdsaCryptoInfo
232+ + ".\n " ;
233+ errorMessage +=
234+ "\n * If your blockchain channel config is SM, please provide the SM certificates: "
235+ + configOption .getCryptoMaterialConfig ().toString ()
236+ + "\n " ;
237+ throw new NetworkException (
238+ errorMessage + "\n " + SystemInformation .getSystemInformation ());
200239 }
201- connManager .startConnect (configOption );
202- connManager .startReconnectSchedule ();
203240 } catch (ConfigException e ) {
204- throw new NetworkException (
205- "start connManager with the SM algorithm failed, error info: " + e .getMessage (),
206- e );
241+ throw new NetworkException (e );
207242 }
208243 }
209244
0 commit comments