|
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; |
23 | 24 | import java.net.InetAddress; |
24 | 25 | import java.util.*; |
25 | 26 | import java.util.concurrent.ConcurrentHashMap; |
26 | 27 | import java.util.concurrent.CopyOnWriteArrayList; |
27 | 28 | import java.util.concurrent.Executors; |
28 | 29 | import java.util.concurrent.ScheduledExecutorService; |
29 | 30 | import java.util.concurrent.TimeUnit; |
| 31 | + |
| 32 | +import io.netty.channel.ChannelHandlerContext; |
| 33 | +import io.netty.handler.timeout.ReadTimeoutException; |
30 | 34 | import org.apache.commons.collections4.map.LRUMap; |
31 | 35 | import org.slf4j.Logger; |
32 | 36 | import org.slf4j.LoggerFactory; |
33 | 37 | import org.springframework.beans.factory.annotation.Autowired; |
34 | 38 | import org.springframework.stereotype.Component; |
| 39 | +import org.tron.common.overlay.message.DisconnectMessage; |
35 | 40 | import org.tron.common.overlay.message.ReasonCode; |
36 | 41 | import org.tron.core.config.args.Args; |
37 | 42 | import org.tron.core.db.ByteArrayWrapper; |
@@ -153,6 +158,17 @@ public Collection<Channel> getActivePeers() { |
153 | 158 | return new ArrayList<>(activePeers.values()); |
154 | 159 | } |
155 | 160 |
|
| 161 | + public void processException(ChannelHandlerContext ctx, Throwable throwable){ |
| 162 | + if (throwable instanceof ReadTimeoutException){ |
| 163 | + logger.error("Read timeout, {}", ctx.channel().remoteAddress()); |
| 164 | + }else if (throwable.getMessage().contains("Connection reset by peer")){ |
| 165 | + logger.error("Connection reset by peer, {}", ctx.channel().remoteAddress()); |
| 166 | + }else { |
| 167 | + logger.error("exception caught, {}", ctx.channel().remoteAddress(), throwable); |
| 168 | + } |
| 169 | + ctx.close(); |
| 170 | + } |
| 171 | + |
156 | 172 | public void close() { |
157 | 173 | try { |
158 | 174 | mainWorker.shutdownNow(); |
|
0 commit comments