|
20 | 20 | import static org.tron.common.overlay.message.ReasonCode.DUPLICATE_PEER; |
21 | 21 | import static org.tron.common.overlay.message.ReasonCode.TOO_MANY_PEERS; |
22 | 22 |
|
23 | | -import java.io.IOException; |
24 | 23 | import java.net.InetAddress; |
25 | 24 | import java.net.InetSocketAddress; |
26 | | -import java.util.*; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Collection; |
| 27 | +import java.util.Collections; |
| 28 | +import java.util.Comparator; |
| 29 | +import java.util.Date; |
| 30 | +import java.util.HashSet; |
| 31 | +import java.util.List; |
| 32 | +import java.util.Map; |
| 33 | +import java.util.Set; |
27 | 34 | import java.util.concurrent.ConcurrentHashMap; |
28 | 35 | import java.util.concurrent.CopyOnWriteArrayList; |
29 | 36 | import java.util.concurrent.Executors; |
30 | 37 | import java.util.concurrent.ScheduledExecutorService; |
31 | 38 | import java.util.concurrent.TimeUnit; |
32 | | - |
33 | | -import io.netty.channel.ChannelHandlerContext; |
34 | | -import io.netty.handler.timeout.ReadTimeoutException; |
35 | 39 | import org.apache.commons.collections4.map.LRUMap; |
36 | 40 | import org.slf4j.Logger; |
37 | 41 | import org.slf4j.LoggerFactory; |
38 | 42 | import org.springframework.beans.factory.annotation.Autowired; |
39 | 43 | import org.springframework.stereotype.Component; |
40 | 44 | import org.tron.common.overlay.client.PeerClient; |
41 | | -import org.tron.common.overlay.message.DisconnectMessage; |
42 | 45 | import org.tron.common.overlay.message.ReasonCode; |
43 | 46 | import org.tron.core.config.args.Args; |
44 | 47 | import org.tron.core.db.ByteArrayWrapper; |
@@ -143,6 +146,13 @@ public void notifyDisconnect(Channel channel) { |
143 | 146 | syncPool.onDisconnect(channel); |
144 | 147 | activePeers.values().remove(channel); |
145 | 148 | newPeers.remove(channel); |
| 149 | + if (channel == null || channel.getChannelHandlerContext() == null |
| 150 | + || channel.getChannelHandlerContext().channel() == null) { |
| 151 | + return; |
| 152 | + } |
| 153 | + InetSocketAddress socketAddress = (InetSocketAddress) channel.getChannelHandlerContext() |
| 154 | + .channel().remoteAddress(); |
| 155 | + recentlyDisconnected.put(socketAddress.getAddress(), new Date()); |
146 | 156 | } |
147 | 157 |
|
148 | 158 | public boolean isRecentlyDisconnected(InetAddress peerAddr) { |
|
0 commit comments