void testReachable(String aPeer) throws AsyncFileTransferException { RoutingTableEntry theEntryForPeer; try { theEntryForPeer = getRoutingTable().getEntryForPeer(aPeer); if (!theEntryForPeer.isReachable()) throw new AsyncFileTransferException( "The peer became you want to send a file to is unreachable"); } catch (Exception e) { throw new AsyncFileTransferException( "Not able to retrieve routing table entry for peer '" + aPeer + "'"); } }
public void setUp() throws Exception { super.setUp(); // p1 <--> p2 <--> p3 peer 1 cannot reach peer 3 myProtocolContainer1 = getProtocolContainer(-1, false, "1"); myServer1 = getP2PServer(myProtocolContainer1, RoutingProtocol.START_PORT); RoutingProtocol theRoutingProtocol1 = (RoutingProtocol) myProtocolContainer1.getProtocol(RoutingProtocol.ID); myTransferProtocl1 = ((AsyncTransferProtocol) myProtocolContainer1.getProtocol(AsyncTransferProtocol.ID)); myProtocolContainer2 = getProtocolContainer(-1, false, "2"); myServer2 = getP2PServer(myProtocolContainer2, RoutingProtocol.START_PORT + 1); RoutingProtocol theRoutingProtocol2 = (RoutingProtocol) myProtocolContainer2.getProtocol(RoutingProtocol.ID); myTransferProtocol2 = ((AsyncTransferProtocol) myProtocolContainer2.getProtocol(AsyncTransferProtocol.ID)); assertTrue(myServer1.start()); assertTrue(myServer2.start()); theRoutingProtocol1.scanLocalSystem(); theRoutingProtocol2.scanLocalSystem(); Thread.sleep(SLEEP_AFTER_SCAN); for (int i = 0; i < 5; i++) { theRoutingProtocol1.exchangeRoutingTable(); theRoutingProtocol2.exchangeRoutingTable(); } RoutingTable theRoutingTable1 = ((RoutingProtocol) myProtocolContainer1.getProtocol(RoutingProtocol.ID)).getRoutingTable(); RoutingTable theRoutingTable2 = ((RoutingProtocol) myProtocolContainer2.getProtocol(RoutingProtocol.ID)).getRoutingTable(); RoutingTableEntry thePeer2 = theRoutingTable1.getEntryForPeer(theRoutingTable2.getLocalPeerId()); assertNotNull(thePeer2.getPeer()); assertTrue(thePeer2.isReachable()); }