亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gnutellaconnection.java

?? P2P協議GUNTELLA的java源代碼
?? JAVA
字號:
/*
 * Copyright (C) 2000-2001  Ken McCrary
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Email: jkmccrary@yahoo.com
 */
package com.kenmccrary.jtella;

import java.net.Socket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.DataOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Vector;
import java.util.List;
import java.util.ListIterator;
import java.util.LinkedList;
import java.util.Collections;

import com.kenmccrary.jtella.util.Log;
import com.kenmccrary.jtella.util.LoggingThreadGroup;

/**
 *  The GNUTellaConnection represents a connection to the GNUTella 
 *  <STRONG>network</STRONG>. The connection consists of one or more
 *  socket connections to servant nodes on the network.<p>
 *
 *  The following is an example initiating a GNUTellaConnection.
 *
 * <PRE>
 *     GNUTellaConnection c = new GNUTellaConnection("gnutellahosts.com", 6346);
 *     c.start();
 * </PRE>
 */
public class GNUTellaConnection
{
  private static String greeting = "GNUTELLA CONNECT/0.4\n\n";
  private static String SERVER_READY = "GNUTELLA OK";

  private boolean shutdownFlag;
  private static ConnectionData connectionData;
  private HostCache hostCache;
  private ConnectionList connectionList;
  private Router router;
  private IncomingConnectionManager incomingConnectionManager;
  private OutgoingConnectionManager outgoingConnectionManager;
  private HostFeed hostFeed;
  private SearchMonitorSession searchMonitorSession;
  private KeepAliveThread keepAliveThread;

  /**
   *  Constructs an empty connection, the application must add a host cache or
   *  servant to generate activity
   */
  public GNUTellaConnection() throws UnknownHostException,
                                     IOException 
  {
     this(null);
  } 

  /**
   *  Construct the connection using default connection data and the supplied
   *  information regarding the host cache on the network
   *
   *  @param host can be a machine name or IP address
   *  @param port port to use
   *
   **/
  public GNUTellaConnection(String host,
                            int port) throws UnknownHostException,
                                            IOException 
  {
     this(null, host, port);
  } 
  
  /**
   *  Construct the connection specifying connection data. The connection will
   *  not have access to a host cache unless specified later.
   *
   *  @param connData connection data
   **/
  public GNUTellaConnection(ConnectionData connData) throws UnknownHostException,
                                                            IOException 
  {
    Log.getLog().logInformation("Network connection initializing");
    Log.getLog().logInformation(System.getProperties().toString());

    if ( null != connData )
    {    
      connectionData = connData;
    }    
    else        
    {    
      connectionData = new ConnectionData();  
    }  
        
    // the cache of known gnutella hosts
    hostCache = new HostCache();
    
    // the connection list contains the connections to GNUTella
    connectionList = new ConnectionList();
    
    // the router routes messages received on the connections
    router = new Router(connectionList, hostCache);
    
    // the host feed is a connection to a GNUTella cache
    hostFeed = new HostFeed(hostCache, router, connectionData);
    
    // Maintains appropriate incoming connections
    incomingConnectionManager = new IncomingConnectionManager(router,
                                                              connectionList, 
                                                              connectionData,
                                                              hostCache);
    
    outgoingConnectionManager = new OutgoingConnectionManager(router,
                                                              hostCache,
                                                              connectionList,
                                                              connectionData);
                                                              
    keepAliveThread = new KeepAliveThread(connectionList);
  } 

     
  /**
   *  Construct the connection, providing <code>ConnectionData</code>
   *  to initialize the connection and the address of a host cache servant
   *
   *  @oaran connectionData configuration data for the connection
   *  @param host can be a machine name or IP address
   *  @param port port to use
   */
  public GNUTellaConnection(ConnectionData connData, 
                            String host, 
                            int port) throws UnknownHostException,
                                             IOException
  {
    this(connData);
    hostFeed.addHost(host, port);
  }
  
  /** 
   *  Starts the connection
   *
   *
   */
  public void start()
  {
    try
    {
      // run the components
      router.start();
      hostFeed.start();
      incomingConnectionManager.start();
      outgoingConnectionManager.start();
      keepAliveThread.start();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
	
	/**
	 *  Stop the connection, after execution the <code>GNUTellaConnection</code>
	 *  is unusable. A new connection must be created if needed. If a 
	 *  temporary disconnect from NodeConnections is desired, the connection count
	 *  requests can be set to 0
	 *
	 */
	public void stop()
	{
    keepAliveThread.shutdown();
		incomingConnectionManager.shutdown();
		outgoingConnectionManager.shutdown();
		connectionList.reduceActiveIncomingConnections(0);
		connectionList.reduceActiveOutgoingConnections(0);
		connectionList.stopOutgoingConnectionAttempts();
		hostFeed.shutdown();
		router.shutdown();
	}
  
  /**
   *  Get the current <code>HostCache</code>. Using the <code>HostCache</code>
   *  an application can query the known hosts, and add and remove hosts
   *
   *  @return host cache
   */
  public HostCache getHostCache()
  {
    return hostCache;  
  }    

  /**
   *  Query if we are online with the network, with at least one active
   *  node connection
   *
   *  @return true if online, false otherwise
   */
  public boolean isOnline()
  {
    if ( null == connectionList )
    {    
      return false;
    }  
      
    return !connectionList.getActiveIncomingConnections().isEmpty() ||
           !connectionList.getActiveOutgoingConnections().isEmpty();
  }
  
  /**
   *  Get the <code>ConnectionData</code> settings
   *
   *  @return connection data
   */
  public ConnectionData getConnectionData()
  {
    return connectionData;  
  }

  /** 
   *  Creates a session to conduct network searches
   *
   *  @param query search query
   *  @param maxResults maximum result set size
   *  @param minSpeed minimum speed for responding servants
   *  @param receiver receiver for search responses
   *  @return session
   */
  public SearchSession createSearchSession(String query, 
                                           int maxResults, 
                                           int minSpeed,
                                           MessageReceiver receiver)
  {
    return new SearchSession(query, maxResults, minSpeed, this, router, receiver);
  }

  /**
   *  Get a search monitor session to monitor query requests
   *  flowing through this network connection. 
	 *
   *  @param searchReceiver message receiver
   */
  public SearchMonitorSession getSearchMonitorSession(MessageReceiver searchReceiver)
  {
		return new SearchMonitorSession(router, searchReceiver);
  }

  /**
   *  Creates a file serving session. <code>FileServerSession</code> can respond
   *  with a query hit
   *
   *  @param receiver message receiver
   */
  public FileServerSession createFileServerSession(MessageReceiver receiver)
  {
    return new FileServerSession(router, receiver);
  }

  // todo the two methods below should possibly be merged
  // consider if the ConnectionList should be publicly available
  
  /**
   *  Gets the current list of connections to GNUTella
   *
   *  @return list of connections
   */
  public LinkedList getConnectionList()
  {
    return connectionList.getList();  
  }    
  
  
  /**
   * Get the connection list
   */
  ConnectionList getConnections()
  {
    return connectionList;
  }
  
  /**
   *  Attempts an outgoing connection on the specified host
   *
   *  @param ipAddress host IP
   *  @param port port number
   */
  public void addConnection(String ipAddress, int port)
  {
    outgoingConnectionManager.addImmediateConnection(ipAddress, port);
  }
  
  /**
   * Informs the system of a host cache servant on the network
   *
   *  @param ipAddress host IP
   *  @param port port number
   */
  public void addHostCacheServant(String ipAddress, int port)
  {
    hostFeed.addHost(ipAddress, port);
  }
  
  /**
   *  Removes host cache servant information
   *
   *  @param ipAddress host IP
   *  @param port port number
   */
  public void removeHostCacheServant(String ipAddress, int port)
  {
    hostFeed.removeHost(ipAddress, port);
  }
  
  /**
   *  Get the servant identifier the <code>GnutellaConnection</code> 
   *  is using. The servant identifier is used in connection with Push
   *  message processing
   *
   *  @return servant identifier
   */
  public short[] getServantIdentifier()
  {
    return Utilities.getClientIdentifier();
  }
  
  /**
   *  Sends a message to all connections
   *
   *  @param m message to broadcast
   *  @param receiver message receiver
   */
  void broadcast(Message m, MessageReceiver receiver)
  {
    List connections = connectionList.getActiveConnections();
    
    Log.getLog().logDebug("Broadcasting message, type: " +
                           m.getType() +
                           ", to " +
                           connections.size() +
                           " connections");
    
    ListIterator i = connections.listIterator();
        
    while ( i.hasNext() )
    {    
      NodeConnection connection = (NodeConnection)i.next();

      try
      {
        connection.sendAndReceive(m, receiver);  
      }    
      catch (IOException io)
      {
        Log.getLog().log(io);  
      }    
    }    
  }    

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久久国产成人精品亚洲午夜| 亚洲成年人网站在线观看| 蜜桃精品视频在线| 欧美日韩国产欧美日美国产精品| 亚洲精品精品亚洲| 91国内精品野花午夜精品| 日韩亚洲欧美在线| 久久精品国产秦先生| 日韩欧美国产三级电影视频| 国内精品国产成人国产三级粉色 | 久久国内精品自在自线400部| 欧美疯狂做受xxxx富婆| 性久久久久久久久久久久| 91精品久久久久久久99蜜桃| 亚洲综合在线免费观看| 欧美日韩一区二区三区不卡| 日韩影院在线观看| 欧美成人午夜电影| 秋霞av亚洲一区二区三| 久久久另类综合| 99在线精品观看| 亚洲第一综合色| 欧美丰满美乳xxx高潮www| 另类小说欧美激情| 精品理论电影在线| 一本久道久久综合中文字幕| 亚洲成a人片在线不卡一二三区| 88在线观看91蜜桃国自产| 免费在线一区观看| 国产女主播视频一区二区| eeuss鲁片一区二区三区| 午夜精品福利在线| 久久久99精品免费观看不卡| eeuss鲁一区二区三区| 一区二区三区欧美亚洲| 日韩午夜精品视频| 国产99久久久精品| 亚洲一区二区三区三| 精品国产青草久久久久福利| 青青草97国产精品免费观看无弹窗版 | 日韩av一区二| 日本一区免费视频| 欧美另类z0zxhd电影| 国产精品18久久久久久久久久久久 | 亚洲国产另类精品专区| 久久人人97超碰com| 精品国产露脸精彩对白| 色综合天天综合在线视频| 日韩欧美亚洲一区二区| 激情综合色丁香一区二区| 精品国产电影一区二区| kk眼镜猥琐国模调教系列一区二区| 91丝袜美腿高跟国产极品老师 | 欧美色视频在线| 国产成人啪午夜精品网站男同| 亚洲一区二区3| 亚洲欧美国产三级| 中文字幕精品在线不卡| 26uuu成人网一区二区三区| 日韩一级成人av| 欧美一区二区视频在线观看2020| 一本一道波多野结衣一区二区| 国产成人免费视频网站高清观看视频 | 狠狠色丁香久久婷婷综合_中| 亚洲 欧美综合在线网络| 亚洲综合免费观看高清在线观看| 国产欧美日韩不卡免费| 精品国产第一区二区三区观看体验| 欧美一区二区三区在| 欧美一区二区三区免费| 日韩一区二区在线看片| 欧美片网站yy| 在线成人av网站| 欧美日韩国产在线观看| 欧美日韩精品欧美日韩精品一 | 亚洲亚洲精品在线观看| 综合久久久久综合| 亚洲免费看黄网站| 亚洲一区二区在线播放相泽 | 在线观看91精品国产麻豆| 欧美日韩一区国产| 69堂国产成人免费视频| 欧美性感一区二区三区| 欧美丰满少妇xxxxx高潮对白| 欧美日韩成人在线| 3d动漫精品啪啪1区2区免费 | 久久夜色精品国产噜噜av | 91精品国产高清一区二区三区| 欧美亚洲综合在线| 欧美一区二区二区| 国产色婷婷亚洲99精品小说| 国产日产亚洲精品系列| 国产精品三级av| 夜夜嗨av一区二区三区中文字幕| 亚洲国产精品欧美一二99| 日本亚洲免费观看| 国产精品一二三四| av高清不卡在线| 欧美日韩电影一区| 国产亚洲短视频| 最新久久zyz资源站| 亚洲一区在线视频观看| 激情国产一区二区 | 国内精品国产成人| 91免费看片在线观看| 91精品国产综合久久精品麻豆 | 不卡av免费在线观看| 在线欧美日韩国产| 日韩午夜电影av| 中文字幕一区二区三区乱码在线 | 美女一区二区三区| av网站免费线看精品| 欧美一级黄色大片| 国产精品大尺度| 日韩电影一区二区三区四区| 国产福利精品导航| 亚洲一区二区三区四区五区黄| 青青草国产精品亚洲专区无| 欧美自拍偷拍一区| 欧美精选一区二区| 国产三级精品三级| 石原莉奈在线亚洲二区| 国产乱码精品一区二区三区五月婷 | 欧美精品久久一区二区三区| 亚洲精品在线电影| 日韩福利电影在线| 国产精品久久久久久妇女6080| 欧美成人高清电影在线| 专区另类欧美日韩| 国产成人精品亚洲777人妖| 91国内精品野花午夜精品| 日韩精品一区二区三区视频在线观看| 成人欧美一区二区三区视频网页| 毛片av中文字幕一区二区| 91美女蜜桃在线| 国产女人水真多18毛片18精品视频 | 亚洲免费色视频| 国产91丝袜在线播放0| 日韩视频在线一区二区| 亚洲成人中文在线| 色偷偷成人一区二区三区91| 久久精品男人天堂av| 免费一区二区视频| 欧美系列在线观看| 国产精品久久久久四虎| 精品无码三级在线观看视频 | 91精品福利在线| 中文字幕成人av| 蜜臀av在线播放一区二区三区| 欧美在线免费播放| 成人欧美一区二区三区| 国产成人免费视频网站 | 欧美一区二区美女| 亚洲影院理伦片| 91年精品国产| 亚洲人快播电影网| www.一区二区| 中文字幕在线不卡一区二区三区| 国产乱码精品一区二区三| 日韩精品专区在线| 免费观看成人av| 日韩一区二区在线观看视频| 日本视频一区二区三区| 欧美一区二区精品| 青青草视频一区| 日韩欧美国产成人一区二区| 免费看欧美女人艹b| 欧美大片拔萝卜| 韩日av一区二区| 久久久久亚洲蜜桃| 国产99久久久国产精品潘金| 中文欧美字幕免费| 91在线国产福利| 亚洲一区二区五区| 欧美猛男gaygay网站| 视频一区二区中文字幕| 日韩欧美一区二区在线视频| 极品美女销魂一区二区三区免费 | 成人午夜伦理影院| 亚洲欧美aⅴ...| 欧美日免费三级在线| 日本亚洲天堂网| 久久蜜臀精品av| 成人精品国产一区二区4080| 亚洲同性gay激情无套| 91久久精品网| 日韩在线观看一区二区| 久久亚洲春色中文字幕久久久| 成人激情免费网站| 亚洲国产日韩a在线播放| 日韩欧美中文字幕制服| 高清国产一区二区| 亚洲综合久久av| 日韩午夜在线影院| 成人动漫在线一区| 天堂久久一区二区三区| 久久久不卡网国产精品一区| 99精品久久99久久久久| 日韩电影一区二区三区| 国产精品萝li|