@@ -142,7 +142,7 @@ public Task BroadcastAnnounceAsync(BlockHeader blockHeader)
142142 Logger . LogInformation ( ex , $ "Could not broadcast announcement to { peer } " +
143143 $ "- status { peer . ConnectionStatus } .") ;
144144
145- await HandleNetworkException ( peer , ex ) ;
145+ await HandleNetworkExceptionAsync ( peer , ex ) ;
146146 }
147147 } ) ;
148148 }
@@ -171,7 +171,7 @@ public Task BroadcastTransactionAsync(Transaction transaction)
171171 Logger . LogWarning ( ex , $ "Could not broadcast transaction to { peer } " +
172172 $ "- status { peer . ConnectionStatus } .") ;
173173
174- await HandleNetworkException ( peer , ex ) ;
174+ await HandleNetworkExceptionAsync ( peer , ex ) ;
175175 }
176176 } ) ;
177177 }
@@ -201,7 +201,7 @@ public Task BroadcastLibAnnounceAsync(Hash libHash, long libHeight)
201201 {
202202 Logger . LogWarning ( ex , $ "Could not broadcast lib announcement to { peer } " +
203203 $ "- status { peer . ConnectionStatus } .") ;
204- await HandleNetworkException ( peer , ex ) ;
204+ await HandleNetworkExceptionAsync ( peer , ex ) ;
205205 }
206206 } ) ;
207207 }
@@ -256,7 +256,6 @@ public async Task<Response<List<BlockWithTransactions>>> GetBlocksAsync(Hash pre
256256
257257 if ( peer == null )
258258 throw new InvalidOperationException ( $ "Could not find peer { peerPubkey } .") ;
259-
260259 var response = await Request ( peer , p => p . GetBlocksAsync ( previousBlock , count ) ) ;
261260
262261 if ( response . Success && response . Payload != null
@@ -343,7 +342,7 @@ private void EnqueueBlock(IPeer peer, BlockWithTransactions blockWithTransaction
343342 if ( ex != null )
344343 {
345344 Logger . LogWarning ( ex , $ "Could not broadcast block to { peer } - status { peer . ConnectionStatus } .") ;
346- await HandleNetworkException ( peer , ex ) ;
345+ await HandleNetworkExceptionAsync ( peer , ex ) ;
347346 }
348347 } ) ;
349348 }
@@ -372,13 +371,33 @@ private async Task<Response<T>> Request<T>(IPeer peer, Func<IPeer, Task<T>> func
372371 if ( ex . ExceptionType == NetworkExceptionType . HandlerException )
373372 return new Response < T > ( default ) ;
374373
375- await HandleNetworkException ( peer , ex ) ;
374+ await HandleNetworkExceptionAsync ( peer , ex ) ;
376375 }
377376
378377 return new Response < T > ( ) ;
379378 }
380379
381- private async Task HandleNetworkException ( IPeer peer , NetworkException exception )
380+ public async Task < List < NodeInfo > > GetNodesAsync ( IPeer peer )
381+ {
382+ try
383+ {
384+ var nodeList = await peer . GetNodesAsync ( ) ;
385+
386+ if ( nodeList ? . Nodes == null )
387+ return new List < NodeInfo > ( ) ;
388+
389+ Logger . LogDebug ( "get nodes: {nodeList} from peer: {peer}." , nodeList , peer ) ;
390+ return nodeList . Nodes . ToList ( ) ;
391+ }
392+ catch ( Exception e )
393+ {
394+ if ( e is NetworkException exception ) await HandleNetworkExceptionAsync ( peer , exception ) ;
395+ Logger . LogWarning ( e , "get nodes failed. peer={peer}" , peer ) ;
396+ return new List < NodeInfo > ( ) ;
397+ }
398+ }
399+
400+ private async Task HandleNetworkExceptionAsync ( IPeer peer , NetworkException exception )
382401 {
383402 if ( exception . ExceptionType == NetworkExceptionType . Unrecoverable )
384403 {
@@ -398,8 +417,9 @@ private async Task RecoverPeerAsync(IPeer peer)
398417 return ;
399418
400419 var success = await peer . TryRecoverAsync ( ) ;
401-
402- if ( ! success )
420+ if ( success )
421+ await _networkServer . BuildStreamForPeerAsync ( peer ) ;
422+ else
403423 await _networkServer . TrySchedulePeerReconnectionAsync ( peer ) ;
404424 }
405425
0 commit comments