Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@Component
public class ChannelManager {

private final Map<ByteArrayWrapper, Channel> activePeers = new ConcurrentHashMap<>();
private final Map<ByteArrayWrapper, Channel> activeChannels = new ConcurrentHashMap<>();
@Autowired
private PeerServer peerServer;
@Autowired
Expand Down Expand Up @@ -121,7 +121,7 @@ public void processDisconnect(Channel channel, ReasonCode reason) {

public void notifyDisconnect(Channel channel) {
syncPool.onDisconnect(channel);
activePeers.values().remove(channel);
activeChannels.values().remove(channel);
if (channel != null) {
if (channel.getNodeStatistics() != null) {
channel.getNodeStatistics().notifyDisconnect();
Expand All @@ -146,7 +146,7 @@ public synchronized boolean processPeer(Channel peer) {
return false;
}

if (!peer.isActive() && activePeers.size() >= maxActivePeers) {
if (!peer.isActive() && activeChannels.size() >= maxActivePeers) {
peer.disconnect(TOO_MANY_PEERS);
return false;
}
Expand All @@ -157,7 +157,7 @@ public synchronized boolean processPeer(Channel peer) {
}
}

Channel channel = activePeers.get(peer.getNodeIdWrapper());
Channel channel = activeChannels.get(peer.getNodeIdWrapper());
if (channel != null) {
if (channel.getStartTime() > peer.getStartTime()) {
logger.info("Disconnect connection established later, {}", channel.getNode());
Expand All @@ -167,14 +167,14 @@ public synchronized boolean processPeer(Channel peer) {
return false;
}
}
activePeers.put(peer.getNodeIdWrapper(), peer);
logger.info("Add active peer {}, total active peers: {}", peer, activePeers.size());
activeChannels.put(peer.getNodeIdWrapper(), peer);
logger.info("Add active peer {}, total active peers: {}", peer, activeChannels.size());
return true;
}

public int getConnectionNum(InetAddress inetAddress) {
int cnt = 0;
for (Channel channel : activePeers.values()) {
for (Channel channel : activeChannels.values()) {
if (channel.getInetAddress().equals(inetAddress)) {
cnt++;
}
Expand All @@ -183,7 +183,7 @@ public int getConnectionNum(InetAddress inetAddress) {
}

public Collection<Channel> getActivePeers() {
return activePeers.values();
return activeChannels.values();
}

public Cache<InetAddress, ReasonCode> getRecentlyDisconnected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ private synchronized void handleSyncBlock() {

isProcessed[0] = false;

synchronized (tronNetDelegate.getBlockLock()) {
blockWaitToProcess.forEach((msg, peerConnection) -> {
blockWaitToProcess.forEach((msg, peerConnection) -> {
synchronized (tronNetDelegate.getBlockLock()) {
if (peerConnection.isDisconnect()) {
blockWaitToProcess.remove(msg);
invalid(msg.getBlockId());
Expand All @@ -254,8 +254,8 @@ private synchronized void handleSyncBlock() {
isProcessed[0] = true;
processSyncBlock(msg.getBlockCapsule());
}
});
}
}
});
}
}

Expand Down