gt: 		return( new DDBaseContactImpl( this, dht.getLocalAddress()));	
context: /*
   * Created on 18-Feb-2005
   * Created by Paul Gardner
   * Copyright (C) 2004, 2005, 2006 Aelitis, All Rights Reserved.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   * 
   * AELITIS, SAS au capital de 46,603.30 euros
   * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
   *
   */
  
  package org.gudy.azureus2.pluginsimpl.local.ddb;
  
  import java.net.InetSocketAddress;
  import java.util.*;
  
  
  import org.gudy.azureus2.core3.util.AEMonitor;
  import org.gudy.azureus2.core3.util.Debug;
  import org.gudy.azureus2.core3.util.HashWrapper;
  import org.gudy.azureus2.core3.util.SHA1Simple;
  import org.gudy.azureus2.core3.util.SystemTime;
  import org.gudy.azureus2.plugins.PluginInterface;
  import org.gudy.azureus2.plugins.ddb.*;
  
  
  import com.aelitis.azureus.core.AzureusCore;
  import com.aelitis.azureus.core.dht.DHT;
  import com.aelitis.azureus.core.util.CopyOnWriteList;
  import com.aelitis.azureus.plugins.dht.DHTPlugin;
  import com.aelitis.azureus.plugins.dht.DHTPluginContact;
  import com.aelitis.azureus.plugins.dht.DHTPluginKeyStats;
  import com.aelitis.azureus.plugins.dht.DHTPluginListener;
  import com.aelitis.azureus.plugins.dht.DHTPluginOperationListener;
  import com.aelitis.azureus.plugins.dht.DHTPluginProgressListener;
  import com.aelitis.azureus.plugins.dht.DHTPluginTransferHandler;
  import com.aelitis.azureus.plugins.dht.DHTPluginValue;
  
  /**
   * @author parg
   *
   */
  
  public class 
  DDBaseImpl 
  	implements DistributedDatabase
  {
  	private static DDBaseImpl	singleton;
  	
  	protected static AEMonitor		class_mon	= new AEMonitor( "DDBaseImpl:class");
  
  	protected static Map			transfer_map = new HashMap();
  	
  	private static DDBaseTTTorrent	torrent_transfer;
  	
  	public static DDBaseImpl
  	getSingleton(
  		AzureusCore	azureus_core )
  	{
  		try{
  			class_mon.enter();
  	
  			if ( singleton == null ){
  				
  				singleton = new DDBaseImpl( azureus_core );
  			}
  		}finally{
  			
  			class_mon.exit();
  		}
  		
  		return( singleton );
  	}
  	
  	
  	private AzureusCore		azureus_core;
  	private DHTPlugin		dht_use_accessor;
  		
  	private CopyOnWriteList	listeners = new CopyOnWriteList();
  	
  	protected
  	DDBaseImpl(
  		final AzureusCore	_azureus_core )
  	{
  		azureus_core	= _azureus_core;
  		
  		torrent_transfer =  new DDBaseTTTorrent( this );
  		
  		grabDHT();
  	}
  	
  	public DDBaseTTTorrent
  	getTTTorrent()
  	{
  		return( torrent_transfer );
  	}
  	
  	protected DHTPlugin
  	grabDHT()
  	{
  		if ( dht_use_accessor != null ){
  			
  			return( dht_use_accessor );
  		}
  		
  		try{
  			class_mon.enter();
  			
  			if( dht_use_accessor == null ){
  						
  			PluginInterface dht_pi = 
  					azureus_core.getPluginManager().getPluginInterfaceByClass(
  								DHTPlugin.class );
  						
  				if ( dht_pi != null ){
  					
  					dht_use_accessor = (DHTPlugin)dht_pi.getPlugin();
  					
  					if ( dht_use_accessor.isEnabled()){
  						
  						dht_use_accessor.addListener(
  							new DHTPluginListener()
  							{
  								public void
  								localAddressChanged(
  									DHTPluginContact	local_contact )
  								{
  									List l = listeners.getList();
  									
  									dbEvent ev = new dbEvent( DistributedDatabaseEvent.ET_LOCAL_CONTACT_CHANGED );
  									
  									for (int i=0;i<l.size();i++){
  										
  										((DistributedDatabaseListener)l.get(i)).event( ev );
  									}
  								}
  							});
  						
  						try{
  							addTransferHandler(	torrent_transfer, torrent_transfer );
  		
  						}catch( Throwable e ){
  							
  							Debug.printStackTrace(e);
  						}
  					}
  				}
  			}
  		}finally{
  			
  			class_mon.exit();
  		}
  		
  		return( dht_use_accessor );
  	}
  	
  	public boolean
  	isAvailable()
  	{
  		DHTPlugin	dht = grabDHT();
  		
  		if ( dht == null ){
  			
  			return( false );
  		}
  		
  		return( dht.isEnabled());
  	}
  	
  	public boolean
  	isExtendedUseAllowed()
  	{
  		DHTPlugin	dht = grabDHT();
  		
  		if ( dht == null ){
  			
  			return( false );
  		}
  		
  		return( dht.isExtendedUseAllowed());	
  	}
  	
  	public DistributedDatabaseContact
  	getLocalContact()
  	{
  		DHTPlugin	dht = grabDHT();
  		
  		if ( dht == null ){
  			
  			return( null );
  		}
  		
  