From: <com...@us...> - 2008-04-15 19:42:17
|
Revision: 4166 http://phex.svn.sourceforge.net/phex/?rev=4166&view=rev Author: complication Date: 2008-04-15 12:41:30 -0700 (Tue, 15 Apr 2008) Log Message: ----------- i2phex: Merged changes from trunk rev. 4154 Modified Paths: -------------- phex/branches/i2phex/src/main/java/phex/host/CatchedHostCache.java phex/branches/i2phex/src/main/java/phex/host/CaughtHostsContainer.java phex/branches/i2phex/src/main/java/phex/host/DefaultHostFetchingStrategy.java phex/branches/i2phex/src/main/java/phex/host/HostManager.java phex/branches/i2phex/src/main/java/phex/msg/PongFactory.java phex/branches/i2phex/src/main/java/phex/query/DynamicQueryEngine.java phex/branches/i2phex/src/main/java/phex/servent/Servent.java phex/branches/i2phex/src/main/java/phex/utils/InternalFileHandler.java Modified: phex/branches/i2phex/src/main/java/phex/host/CatchedHostCache.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/host/CatchedHostCache.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/host/CatchedHostCache.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -85,7 +85,7 @@ } } assert addressHostMapping.size() == sortedHosts.size() : - "CatchedHostCache out of sync."; + "CatchedHostCache out of sync. s: " + sortedHosts.toString() + " - m: " + addressHostMapping.toString(); } /** @@ -101,7 +101,7 @@ sortedHosts.remove( value ); } assert addressHostMapping.size() == sortedHosts.size() : - "CatchedHostCache out of sync."; + "CatchedHostCache out of sync. s: " + sortedHosts.toString() + " - m: " + addressHostMapping.toString(); } /** Modified: phex/branches/i2phex/src/main/java/phex/host/CaughtHostsContainer.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/host/CaughtHostsContainer.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/host/CaughtHostsContainer.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -96,13 +96,12 @@ private boolean hasChangedSinceLastSave; - private final HostFetchingStrategy hostFetchingStrategy; + private HostFetchingStrategy hostFetchingStrategy; private final Servent servent; public CaughtHostsContainer( Servent servent ) { this.servent = servent; - this.hostFetchingStrategy = servent.getHostFetchingStrategy(); int[] capacities = new int[3]; capacities[ HIGH_PRIORITY ] = (int)Math.round( NetworkPrefs.MaxHostInHostCache.get().doubleValue() @@ -130,6 +129,14 @@ } /** + * @param hostFetchingStrategy the hostFetchingStrategy to set + */ + public void setHostFetchingStrategy(HostFetchingStrategy hostFetchingStrategy) + { + this.hostFetchingStrategy = hostFetchingStrategy; + } + + /** * Clears and reloads caught hosts */ private void initializeCaughtHostsContainer() @@ -379,7 +386,7 @@ { int minCount = (int)Math.ceil( NetworkPrefs.MaxHostInHostCache.get().doubleValue()/100.0 ); - if ( caughtHosts.getSize() < minCount ) + if ( caughtHosts.getSize() < minCount && hostFetchingStrategy != null ) { hostFetchingStrategy.fetchNewHosts( FetchingReason.EnsureMinHosts ); } Modified: phex/branches/i2phex/src/main/java/phex/host/DefaultHostFetchingStrategy.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/host/DefaultHostFetchingStrategy.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/host/DefaultHostFetchingStrategy.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -33,6 +33,10 @@ public DefaultHostFetchingStrategy( Servent servent, UdpHostCacheContainer udpHostCacheContainer ) { + if ( udpHostCacheContainer == null ) + { + throw new IllegalArgumentException( "UHC is null" ); + } this.gWebCacheMgr = new GWebCacheManager( servent ); this.udpHostCacheContainer = udpHostCacheContainer; } @@ -47,7 +51,7 @@ { NLogger.info( DefaultHostFetchingStrategy.class, "Fetch new Hosts: " + reason.toString() ); - + // Query udpHostCache for new hosts udpHostCacheContainer.invokeQueryCachesRequest(); Modified: phex/branches/i2phex/src/main/java/phex/host/HostManager.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/host/HostManager.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/host/HostManager.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -49,12 +49,19 @@ private final UdpHostCacheContainer udpHostCacheContainer; private final FavoritesContainer favoritesContainer; - public HostManager( Servent servent ) + public HostManager( Servent servent, boolean useUdpHostCache ) { this.servent = servent; networkHostsContainer = new NetworkHostsContainer( servent ); caughtHostsContainer = new CaughtHostsContainer( servent ); - udpHostCacheContainer = new UdpHostCacheContainer( servent ); + if ( useUdpHostCache ) + { + udpHostCacheContainer = new UdpHostCacheContainer( servent ); + } + else + { + udpHostCacheContainer = null; + } favoritesContainer = new FavoritesContainer( servent ); } @@ -63,6 +70,8 @@ protected void doStart() throws Exception { networkHostsContainer.start(); + caughtHostsContainer.setHostFetchingStrategy( + servent.getHostFetchingStrategy() ); PingWorker pingWorker = new PingWorker( servent ); pingWorker.start(); Environment.getInstance().scheduleTimerTask( @@ -73,7 +82,10 @@ @Override public void doStop() { - udpHostCacheContainer.saveCachesToFile(); + if ( udpHostCacheContainer != null ) + { + udpHostCacheContainer.saveCachesToFile(); + } caughtHostsContainer.saveHostsContainer(); favoritesContainer.saveFavoriteHosts(); } @@ -88,6 +100,11 @@ return caughtHostsContainer; } + /** + * Returns the {@link UdpHostCacheContainer} of this HostManager. + * Value might be null in case no UDP host cache is used. + * @return the host cache container or null. + */ public UdpHostCacheContainer getUhcContainer() { return udpHostCacheContainer; @@ -196,66 +213,17 @@ */ public boolean catchHosts( PongMsg pongMsg ) { - boolean isNew = caughtHostsContainer.catchHosts( pongMsg ); - udpHostCacheContainer.catchHosts( pongMsg ); + boolean isNew = caughtHostsContainer.catchHosts( pongMsg ); + if ( udpHostCacheContainer != null ) + { + udpHostCacheContainer.catchHosts( pongMsg ); + } return isNew; } - public void doAutoConnectCheck() - { - if ( !servent.getOnlineStatus().isNetworkOnline() ) - { - return; - } - - int hostCount; - int requiredHostCount; - - if ( servent.isAbleToBecomeUltrapeer() ) - { - // as a ultrapeer I'm primary searching for Ultrapeers only... - // to make sure I'm well connected... - hostCount = networkHostsContainer.getUltrapeerConnectionCount(); - requiredHostCount = ConnectionPrefs.Up2UpConnections.get().intValue(); - } - // we don't support legacy peers anymore ( since 3.0 ) therefore we only - // handle leaf mode here - else - { - // as a leaf I'm primary searching for Ultrapeers only... - hostCount = networkHostsContainer.getUltrapeerConnectionCount(); - requiredHostCount = ConnectionPrefs.Leaf2UpConnections.get().intValue(); - } - - // count the number of missing connection tries this is the required count - // minus the available count. The result is multiplied by four to raise the - // connection try count. - int missingCount = ( requiredHostCount - hostCount ) * 4; - - // find out the number of hosts where a connection is currently tried... - int allHostCount = networkHostsContainer.getNetworkHostCount( ); - int errorHostCount = networkHostsContainer.getNetworkHostCount( - HostStatus.ERROR); - // make sure the value is not negative. - int totalCount = networkHostsContainer.getTotalConnectionCount(); - int currentTryCount = Math.max( 0, allHostCount - totalCount - errorHostCount); - - // we will never try more then a reasonable parallel tries.. - int upperLimit = Math.min( MAX_PARALLEL_CONNECTION_TRIES, - NetworkPrefs.MaxConcurrentConnectAttempts.get().intValue() ) - currentTryCount; - - int outConnectCount = Math.min( missingCount-currentTryCount, - upperLimit ); - if ( outConnectCount > 0 ) - { - NLogger.debug( HostManager.class, - "Auto-connect to " + outConnectCount + " new hosts."); - OutgoingConnectionDispatcher.dispatchConnectToNextHosts( - outConnectCount, caughtHostsContainer, networkHostsContainer ); - } - } + private class HostCheckTimer extends TimerTask { @@ -277,5 +245,59 @@ NLogger.error( HostManager.class, th, th ); } } + + public void doAutoConnectCheck() + { + if ( !servent.getOnlineStatus().isNetworkOnline() ) + { + return; + } + + int hostCount; + int requiredHostCount; + + if ( servent.isAbleToBecomeUltrapeer() ) + { + // as a ultrapeer I'm primary searching for Ultrapeers only... + // to make sure I'm well connected... + hostCount = networkHostsContainer.getUltrapeerConnectionCount(); + requiredHostCount = ConnectionPrefs.Up2UpConnections.get().intValue(); + } + // we don't support legacy peers anymore ( since 3.0 ) therefore we only + // handle leaf mode here + else + { + // as a leaf I'm primary searching for Ultrapeers only... + hostCount = networkHostsContainer.getUltrapeerConnectionCount(); + requiredHostCount = ConnectionPrefs.Leaf2UpConnections.get().intValue(); + } + + // count the number of missing connection tries this is the required count + // minus the available count. The result is multiplied by four to raise the + // connection try count. + int missingCount = ( requiredHostCount - hostCount ) * 4; + + // find out the number of hosts where a connection is currently tried... + int allHostCount = networkHostsContainer.getNetworkHostCount( ); + int errorHostCount = networkHostsContainer.getNetworkHostCount( + HostStatus.ERROR); + // make sure the value is not negative. + int totalCount = networkHostsContainer.getTotalConnectionCount(); + int currentTryCount = Math.max( 0, allHostCount - totalCount - errorHostCount); + + // we will never try more then a reasonable parallel tries.. + int upperLimit = Math.min( MAX_PARALLEL_CONNECTION_TRIES, + NetworkPrefs.MaxConcurrentConnectAttempts.get().intValue() ) - currentTryCount; + + int outConnectCount = Math.min( missingCount-currentTryCount, + upperLimit ); + if ( outConnectCount > 0 ) + { + NLogger.debug( HostManager.class, + "Auto-connect to " + outConnectCount + " new hosts."); + OutgoingConnectionDispatcher.dispatchConnectToNextHosts( + outConnectCount, caughtHostsContainer, networkHostsContainer ); + } + } } } \ No newline at end of file Modified: phex/branches/i2phex/src/main/java/phex/msg/PongFactory.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/msg/PongFactory.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/msg/PongFactory.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -283,13 +283,17 @@ NLogger.debug( PongMsg.class, "UDP HOST CACHE extension added to outgoing pongs"); } - // if we want Packed Host Caches the data should be added in compressed form - String packedCacheString = uhcContainer.createPackedHostCaches(); - if( packedCacheString.length() > 0 ) + // providing a uhcContainer is optional + if ( uhcContainer != null ) { - byte[] data = IOUtil.deflate( packedCacheString.getBytes() ); - ggepBlock.addExtension( GGEPBlock.UDP_HOST_CACHE_PHC, data ); - NLogger.debug( PongMsg.class, " PACKED HOST CACHE extension added to outgoing pongs "); + // if we want Packed Host Caches the data should be added in compressed form + String packedCacheString = uhcContainer.createPackedHostCaches(); + if( packedCacheString.length() > 0 ) + { + byte[] data = IOUtil.deflate( packedCacheString.getBytes() ); + ggepBlock.addExtension( GGEPBlock.UDP_HOST_CACHE_PHC, data ); + NLogger.debug( PongMsg.class, " PACKED HOST CACHE extension added to outgoing pongs "); + } } } */ Modified: phex/branches/i2phex/src/main/java/phex/query/DynamicQueryEngine.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/query/DynamicQueryEngine.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/query/DynamicQueryEngine.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -542,7 +542,7 @@ return maxTTL; } - int hosts = (int)(16.0 * calculateEstimatedHorizon(degree, i) ); + int hosts = (int)(16.0 * calculateEstimatedHorizon(degree, i) ); if( hosts >= hostsPerConnection ) { return i; Modified: phex/branches/i2phex/src/main/java/phex/servent/Servent.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/servent/Servent.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/servent/Servent.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -151,11 +151,8 @@ uploadService = new UploadManager( this ); - // Initialize hostFetchingStrategy before hostService, - // since CaughtHostsContainer is created by HostManager. - hostFetchingStrategy = new I2PHostFetchingStrategy( this ); + hostService = new HostManager( this, true ); - hostService = new HostManager( this ); dependentLifeCycles.add( hostService ); messageService = new MessageService( this ); @@ -164,6 +161,8 @@ queryService = new QueryManager( this ); dependentLifeCycles.add( queryService ); + hostFetchingStrategy = new I2PHostFetchingStrategy( this ); + onlineObserver = new OnlineObserver( this, hostFetchingStrategy ); // I2PMOD: create an I2PServer instead. Modified: phex/branches/i2phex/src/main/java/phex/utils/InternalFileHandler.java =================================================================== --- phex/branches/i2phex/src/main/java/phex/utils/InternalFileHandler.java 2008-04-14 18:43:11 UTC (rev 4165) +++ phex/branches/i2phex/src/main/java/phex/utils/InternalFileHandler.java 2008-04-15 19:41:30 UTC (rev 4166) @@ -65,26 +65,28 @@ URI uri = new URI( magnet, true ); // dont add already downloading or shared urns. - // If we've got a relativeDownloadDir, download to there. - //if ( relativeDownloadDir.isEmpty() ) - //{ + // If we didn't get a relativeDownloadDir, + // Download to the default folder. + if ( relativeDownloadDir.length() == 0 ) + { downloadUri( uri ); - //} - //else - //{ + } + // Else download to the relativeDOwnloadDir inside the default folder. + else + { downloadUri( uri, relativeDownloadDir ); - //} + } } -/* String uuri = parser.getUpdateURI(); - if ( uuri != null) - { - URI uri = new URI( uuri, true ); - sheduledReadout(uri, 60000); +/* String uuri = parser.getUpdateURI(); + if ( uuri != null) + { + URI uri = new URI( uuri, true ); + sheduledReadout(uri, 60000); } + + */ - */ - } catch (IOException exp) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |