Slightly improved the problem with stale objects in the requested objects list. But I don't know how to properly solve it, there may always be some left.
This commit is contained in:
		| @@ -183,7 +183,7 @@ public abstract class AbstractConnection { | ||||
|     } | ||||
|  | ||||
|     private void receiveMessage(Addr addr) { | ||||
|         LOG.debug("Received " + addr.getAddresses().size() + " addresses."); | ||||
|         LOG.trace("Received " + addr.getAddresses().size() + " addresses."); | ||||
|         ctx.getNodeRegistry().offerAddresses(addr.getAddresses()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -64,7 +64,7 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex | ||||
|     private Selector selector; | ||||
|     private ServerSocketChannel serverChannel; | ||||
|     private Map<ConnectionInfo, SelectionKey> connections = new ConcurrentHashMap<>(); | ||||
|     private volatile int requestedObjectsCount; | ||||
|     private final Set<InventoryVector> requestedObjects = Collections.newSetFromMap(new ConcurrentHashMap<InventoryVector, Boolean>(10_000)); | ||||
|  | ||||
|     private Thread starter; | ||||
|  | ||||
| @@ -147,7 +147,6 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex | ||||
|         } catch (IOException e) { | ||||
|             throw new ApplicationException(e); | ||||
|         } | ||||
|         final Set<InventoryVector> requestedObjects = new HashSet<>(); | ||||
|         thread("connection listener", new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
| @@ -287,7 +286,6 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex | ||||
|                                     connection.disconnect(); | ||||
|                                 } | ||||
|                             } | ||||
|                             requestedObjectsCount = requestedObjects.size(); | ||||
|                         } | ||||
|                         for (Map.Entry<ConnectionInfo, SelectionKey> e : connections.entrySet()) { | ||||
|                             if (e.getValue().isValid() && (e.getValue().interestOps() & OP_WRITE) == 0) { | ||||
| @@ -370,7 +368,10 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex | ||||
|  | ||||
|     @Override | ||||
|     public void request(Collection<InventoryVector> inventoryVectors) { | ||||
|         if (!isRunning()) return; | ||||
|         if (!isRunning()) { | ||||
|             requestedObjects.clear(); | ||||
|             return; | ||||
|         } | ||||
|         Iterator<InventoryVector> iterator = inventoryVectors.iterator(); | ||||
|         if (!iterator.hasNext()) { | ||||
|             return; | ||||
| @@ -408,6 +409,9 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex | ||||
|             } | ||||
|         } while (iterator.hasNext()); | ||||
|  | ||||
|         // remove objects nobody knows of | ||||
|         requestedObjects.removeAll(inventoryVectors); | ||||
|  | ||||
|         for (ConnectionInfo connection : distribution.keySet()) { | ||||
|             List<InventoryVector> ivs = distribution.get(connection); | ||||
|             if (!ivs.isEmpty()) { | ||||
| @@ -449,7 +453,7 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex | ||||
|         return new Property("network", null, | ||||
|             new Property("connectionManager", isRunning() ? "running" : "stopped"), | ||||
|             new Property("connections", null, streamProperties), | ||||
|             new Property("requestedObjects", requestedObjectsCount) | ||||
|             new Property("requestedObjects", requestedObjects.size()) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user