File tree Expand file tree Collapse file tree
main/java/org/tron/core/net
test/java/org/tron/core/net/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -293,6 +293,14 @@ public static boolean needToLog(Message msg) {
293293 return true ;
294294 }
295295
296+ public synchronized boolean checkAndPutAdvInvRequest (Item key , Long value ) {
297+ if (advInvRequest .containsKey (key )) {
298+ return false ;
299+ }
300+ advInvRequest .put (key , value );
301+ return true ;
302+ }
303+
296304 @ Override
297305 public boolean equals (Object o ) {
298306 if (!(o instanceof PeerConnection )) {
Original file line number Diff line number Diff line change @@ -281,8 +281,9 @@ private void consumerInvToFetch() {
281281 && invSender .getSize (peer ) < MAX_TRX_FETCH_PER_PEER )
282282 .sorted (Comparator .comparingInt (peer -> invSender .getSize (peer )))
283283 .findFirst ().ifPresent (peer -> {
284- invSender .add (item , peer );
285- peer .getAdvInvRequest ().put (item , now );
284+ if (peer .checkAndPutAdvInvRequest (item , now )) {
285+ invSender .add (item , peer );
286+ }
286287 invToFetch .remove (item );
287288 });
288289 });
Original file line number Diff line number Diff line change @@ -117,8 +117,8 @@ private void fetchBlockProcess(FetchBlockInfo fetchBlock) {
117117
118118 if (optionalPeerConnection .isPresent ()) {
119119 optionalPeerConnection .ifPresent (firstPeer -> {
120- if (shouldFetchBlock (firstPeer , fetchBlock )) {
121- firstPeer .getAdvInvRequest (). put ( item , System .currentTimeMillis ());
120+ if (shouldFetchBlock (firstPeer , fetchBlock )
121+ && firstPeer .checkAndPutAdvInvRequest ( item , System .currentTimeMillis ())) {
122122 firstPeer .sendMessage (new FetchInvDataMessage (Collections .singletonList (item .getHash ()),
123123 item .getType ()));
124124 this .fetchBlockInfo = null ;
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ private void testBroadcast() {
8585
8686 try {
8787 peer = context .getBean (PeerConnection .class );
88+ Assert .assertFalse (peer .isDisconnect ());
8889 p2pEventHandler = context .getBean (P2pEventHandlerImpl .class );
8990
9091 List <PeerConnection > peers = Lists .newArrayList ();
@@ -96,6 +97,9 @@ private void testBroadcast() {
9697 service .broadcast (msg );
9798 Item item = new Item (blockCapsule .getBlockId (), InventoryType .BLOCK );
9899 Assert .assertNotNull (service .getMessage (item ));
100+ peer .checkAndPutAdvInvRequest (item , System .currentTimeMillis ());
101+ boolean res = peer .checkAndPutAdvInvRequest (item , System .currentTimeMillis ());
102+ Assert .assertFalse (res );
99103 } catch (NullPointerException e ) {
100104 System .out .println (e );
101105 }
You can’t perform that action at this time.
0 commit comments