File tree Expand file tree Collapse file tree 4 files changed +13
-9
lines changed
main/java/org/tron/core/net
test/java/org/tron/core/net Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 66
77public class P2pRateLimiter {
88 private final Cache <Byte , RateLimiter > rateLimiters = CacheBuilder .newBuilder ()
9- .maximumSize (256 ).build ();
9+ .maximumSize (32 ).build ();
1010
11- public void register (Byte type , double rate ) {
12- rateLimiters .put (type , RateLimiter .create (rate ));
11+ public void register (Byte type , double rate ) {
12+ RateLimiter rateLimiter = RateLimiter .create (Double .POSITIVE_INFINITY );
13+ rateLimiter .setRate (rate );
14+ rateLimiters .put (type , rateLimiter );
1315 }
1416
15- public void acquire (Byte type ) {
17+ public void acquire (Byte type ) {
1618 RateLimiter rateLimiter = rateLimiters .getIfPresent (type );
1719 if (rateLimiter == null ) {
1820 return ;
1921 }
2022 rateLimiter .acquire ();
2123 }
2224
23- public boolean tryAcquire (Byte type ) {
25+ public boolean tryAcquire (Byte type ) {
2426 RateLimiter rateLimiter = rateLimiters .getIfPresent (type );
2527 if (rateLimiter == null ) {
2628 return true ;
Original file line number Diff line number Diff line change @@ -173,7 +173,7 @@ public void setChannel(Channel channel) {
173173 this .nodeStatistics = TronStatsManager .getNodeStatistics (channel .getInetAddress ());
174174 lastInteractiveTime = System .currentTimeMillis ();
175175 p2pRateLimiter .register (SYNC_BLOCK_CHAIN .asByte (), 2 );
176- p2pRateLimiter .register (FETCH_INV_DATA .asByte (), 1 );
176+ p2pRateLimiter .register (FETCH_INV_DATA .asByte (), 2 );
177177 p2pRateLimiter .register (P2P_DISCONNECT .asByte (), 1 );
178178 }
179179
Original file line number Diff line number Diff line change @@ -12,8 +12,10 @@ public void test() {
1212 P2pRateLimiter limiter = new P2pRateLimiter ();
1313 limiter .register (SYNC_BLOCK_CHAIN .asByte (), 2 );
1414 limiter .acquire (SYNC_BLOCK_CHAIN .asByte ());
15- limiter .tryAcquire (SYNC_BLOCK_CHAIN .asByte ());
1615 boolean ret = limiter .tryAcquire (SYNC_BLOCK_CHAIN .asByte ());
16+ Assert .assertTrue (ret );
17+ limiter .tryAcquire (SYNC_BLOCK_CHAIN .asByte ());
18+ ret = limiter .tryAcquire (SYNC_BLOCK_CHAIN .asByte ());
1719 Assert .assertFalse (ret );
1820 ret = limiter .tryAcquire (FETCH_INV_DATA .asByte ());
1921 Assert .assertTrue (ret );
Original file line number Diff line number Diff line change 11package org .tron .core .net .messagehandler ;
22
3+ import static org .tron .core .net .message .MessageTypes .FETCH_INV_DATA ;
4+
35import com .google .common .cache .Cache ;
46import com .google .common .cache .CacheBuilder ;
57import java .lang .reflect .Field ;
2224import org .tron .core .net .service .adv .AdvService ;
2325import org .tron .protos .Protocol ;
2426
25- import static org .tron .core .net .message .MessageTypes .FETCH_INV_DATA ;
26-
2727public class FetchInvDataMsgHandlerTest {
2828
2929 @ Test
You can’t perform that action at this time.
0 commit comments