Synchronisation API and related refactorings / improvements
-> lets you synchronize with the Bitmessage network without staying connected
This commit is contained in:
		| @@ -310,6 +310,8 @@ public class Connection implements Runnable { | ||||
|                 try { | ||||
|                     LOG.debug("Received object " + objectMessage.getInventoryVector()); | ||||
|                     security().checkProofOfWork(objectMessage, ctx.getNetworkNonceTrialsPerByte(), ctx.getNetworkExtraBytes()); | ||||
|                     if (ctx.getInventory().contains(objectMessage)) | ||||
|                         break; | ||||
|                     listener.receive(objectMessage); | ||||
|                     ctx.getInventory().storeObject(objectMessage); | ||||
|                     // offer object to some random nodes so it gets distributed throughout the network: | ||||
|   | ||||
| @@ -55,8 +55,9 @@ public class NetworkHandlerTest { | ||||
|                 .nodeRegistry(new TestNodeRegistry()) | ||||
|                 .networkHandler(new DefaultNetworkHandler()) | ||||
|                 .security(new BouncySecurity()) | ||||
|                 .listener(Mockito.mock(BitmessageContext.Listener.class)) | ||||
|                 .build(); | ||||
|         peer.startup(Mockito.mock(BitmessageContext.Listener.class)); | ||||
|         peer.startup(); | ||||
|  | ||||
|         nodeInventory = new TestInventory(); | ||||
|         networkHandler = new DefaultNetworkHandler(); | ||||
| @@ -68,13 +69,14 @@ public class NetworkHandlerTest { | ||||
|                 .nodeRegistry(new TestNodeRegistry(localhost)) | ||||
|                 .networkHandler(networkHandler) | ||||
|                 .security(new BouncySecurity()) | ||||
|                 .listener(Mockito.mock(BitmessageContext.Listener.class)) | ||||
|                 .build(); | ||||
|     } | ||||
|  | ||||
|     @Test(timeout = 20_000) | ||||
|     public void ensureNodesAreConnecting() { | ||||
|         try { | ||||
|             node.startup(Mockito.mock(BitmessageContext.Listener.class)); | ||||
|             node.startup(); | ||||
|             Property status; | ||||
|             do { | ||||
|                 Thread.yield(); | ||||
|   | ||||
| @@ -60,6 +60,11 @@ public class TestInventory implements Inventory { | ||||
|         inventory.put(object.getInventoryVector(), object); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean contains(ObjectMessage object) { | ||||
|         return inventory.containsKey(object.getInventoryVector()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void cleanup() { | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user