File tree Expand file tree Collapse file tree 4 files changed +17
-4
lines changed
main/java/org/tron/core/net
test/java/org/tron/core/net/services Expand file tree Collapse file tree 4 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,14 @@ public static boolean needToLog(Message msg) {
293
293
return true ;
294
294
}
295
295
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
+
296
304
@ Override
297
305
public boolean equals (Object o ) {
298
306
if (!(o instanceof PeerConnection )) {
Original file line number Diff line number Diff line change @@ -281,8 +281,9 @@ private void consumerInvToFetch() {
281
281
&& invSender .getSize (peer ) < MAX_TRX_FETCH_PER_PEER )
282
282
.sorted (Comparator .comparingInt (peer -> invSender .getSize (peer )))
283
283
.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
+ }
286
287
invToFetch .remove (item );
287
288
});
288
289
});
Original file line number Diff line number Diff line change @@ -117,8 +117,8 @@ private void fetchBlockProcess(FetchBlockInfo fetchBlock) {
117
117
118
118
if (optionalPeerConnection .isPresent ()) {
119
119
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 ())) {
122
122
firstPeer .sendMessage (new FetchInvDataMessage (Collections .singletonList (item .getHash ()),
123
123
item .getType ()));
124
124
this .fetchBlockInfo = null ;
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ private void testBroadcast() {
85
85
86
86
try {
87
87
peer = context .getBean (PeerConnection .class );
88
+ Assert .assertFalse (peer .isDisconnect ());
88
89
p2pEventHandler = context .getBean (P2pEventHandlerImpl .class );
89
90
90
91
List <PeerConnection > peers = Lists .newArrayList ();
@@ -96,6 +97,9 @@ private void testBroadcast() {
96
97
service .broadcast (msg );
97
98
Item item = new Item (blockCapsule .getBlockId (), InventoryType .BLOCK );
98
99
Assert .assertNotNull (service .getMessage (item ));
100
+ peer .checkAndPutAdvInvRequest (item , System .currentTimeMillis ());
101
+ boolean res = peer .checkAndPutAdvInvRequest (item , System .currentTimeMillis ());
102
+ Assert .assertFalse (res );
99
103
} catch (NullPointerException e ) {
100
104
System .out .println (e );
101
105
}
You can’t perform that action at this time.
0 commit comments