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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? searchreplymessage.java

?? P2P協(xié)議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.util.Vector;
import java.util.Enumeration;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import com.kenmccrary.jtella.util.Log;

/**
 *  Search Reply message(QUERY HIT), response to a search request
 *
 *
 */
public class SearchReplyMessage extends Message
{
  private Vector fileRecords = new Vector();

  // These are used to send the message
  private SearchMessage searchMessage;
  private short port;
  private String ipAddress;
  private int speed;
  private String vendorCode;

  /**
   *  Construct a SearchReply message
   *
   *
   */
  SearchReplyMessage()
  {
    super(Message.QUERYREPLY);
  }

  /**
   *  Construct a search reply message from data read
   *  read from network
   *
   *  @param rawMessage binary data from a connection
   *  @param originatingConnection Connection creating this message
   */
  SearchReplyMessage(short[] rawMessage, Connection originatingConnection)
  {
    super(rawMessage, originatingConnection);
  }

  /**
   *  Used to respond to a query message
   *
   *  @param searchMessage the search thats being responded to
   *  @param port the point used for download
   *  @param ipAddress of the servant
   *  @param speed download speed in kilobytes/sec
   *  */
  public SearchReplyMessage(SearchMessage searchMessage,
                            short port,
                            String ipAddress,
                            int speed)
  {
    this(searchMessage, port, ipAddress, speed, null);
  }

  /**
   *  Used to respond to a query message
   *
   *  @param searchMessage the search thats being responded to
   *  @param port the point used for download
   *  @param ipAddress of the servant
   *  @param speed download speed in kilobytes/sec
   *  @param vendorCode option 4 byte value identifying the servant vendor
   *  */
  public SearchReplyMessage(SearchMessage searchMessage,
                            short port,
                            String ipAddress,
                            int speed,
                            String vendorCode)
  {
    super(Message.QUERYREPLY);
    setGUID(searchMessage.getGUID());
    this.searchMessage = searchMessage;
    this.port = port;
    this.ipAddress = ipAddress;
    this.speed = speed;
    this.vendorCode = vendorCode;
  }

  /**
   *  Contructs the payload for the search reply message
   *
   */
  void buildPayload()
  {

    try
    {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      DataOutputStream dataStream = new DataOutputStream(byteStream);

      // hit count
      dataStream.writeByte(fileRecords.size());

      // port, little endian
      int portByte1 = 0x00FF & port;
      int portByte2 = (0xFF00 & port) >> 8;
      dataStream.write(portByte1);
      dataStream.write(portByte2);

      // IP Address
      int beginIndex = 0;
      int endIndex = ipAddress.indexOf('.');

      int ip1 = Integer.parseInt(ipAddress.substring(beginIndex, endIndex));

      beginIndex = endIndex + 1;
      endIndex = ipAddress.indexOf('.', beginIndex);

      int ip2 = Integer.parseInt(ipAddress.substring(beginIndex, endIndex));

      beginIndex = endIndex + 1;
      endIndex = ipAddress.indexOf('.', beginIndex);

      int ip3 = Integer.parseInt(ipAddress.substring(beginIndex, endIndex));

      beginIndex = endIndex + 1;

      int ip4 = Integer.parseInt(ipAddress.substring(beginIndex, ipAddress.length()));

      dataStream.writeByte(ip1);
      dataStream.writeByte(ip2);
      dataStream.writeByte(ip3);
      dataStream.writeByte(ip4);

      // download speed, little endian
      int speedByte1 = 0x000000FF & speed;
      int speedByte2 = (0x0000FF00 & speed) >> 8;
      int speedByte3 = (0x00FF0000 & speed) >> 16;
      int speedByte4 = (0xFF000000 & speed) >> 24;
      dataStream.writeByte(speedByte1);
      dataStream.writeByte(speedByte2);
      dataStream.writeByte(speedByte3);
      dataStream.writeByte(speedByte4);

      // result set
      for (int i = 0; i < fileRecords.size(); i++)
      {
        FileRecord fileRecord = (FileRecord)fileRecords.elementAt(i);
        byte[] fileRecordData = fileRecord.getBytes();

        dataStream.write(fileRecordData);
      }

      // bearshare trailer
      if ( null != vendorCode )
      {
        byte[] byteData = vendorCode.getBytes();

        // write the 4 byte vendor code
        for (int i = 0; i < 4; i++)
        {
          dataStream.writeByte(byteData[i]);
        }

        // open data size
        // todo support Quality of Server statistics here
        dataStream.writeByte(0); // no further datafs

      }
      
      // client identifier
      short[] clientID = Utilities.getClientIdentifier();

      for (int i = 0; i < clientID.length; i++)
      {
        dataStream.writeByte(clientID[i]);
      }

      addPayload(byteStream.toByteArray());
      dataStream.close();
    }
    catch(IOException io)
    {
      Log.getLog().log(io);
    }


  }

  /**
   *  Query the umber of files found for the search
   *
   */
  public int getFileCount()
  {
    return payload[0];
  }


  /**
   *  Query the port for this search reply
   *
   *  @return port
   */
  public int getPort()
  {
    int port = 0;
    int byte1 = 0;
    int byte2 = 0;
    byte1 |= payload[1];
    byte2 |= payload[2];

    // the port is in little endian format
    port |= byte1;
    port |= (byte2 << 8);

    return port;
  }


  /**
   *  Query the IP address for this pong message
   *  result is an IP address in the form of
   *  "206.26.48.100".
   *
   *  @return IP address
   */
  public String getIPAddress()
  {
    StringBuffer ipBuffer = new StringBuffer();

    ipBuffer.append(Integer.toString(payload[3])).
             append(".").
             append(Integer.toString(payload[4])).
             append(".").
             append(Integer.toString(payload[5])).
             append(".").
             append(Integer.toString(payload[6]));

    return ipBuffer.toString();
  }

  /**
   *  Returns the replying host's connection bandwidth
   *
   *  @return download speed, in kilobytes/sec
   */
  public int getDownloadSpeed()
  {
    int byte1 = payload[7];
    int byte2 = payload[8];
    int byte3 = payload[9];
    int byte4 = payload[10];

    return byte1 | (byte2 << 8 | byte3 << 16 | byte4 << 24);

  }

  /**
   *  Adds a file record. This is for originating a message
   *  for a query hit
   *
   *  @param fileRecord file information
   */
  public void addFileRecord(FileRecord fileRecord)
  {
    fileRecords.addElement(fileRecord);
  }

  /**
   *  Get information about the files found
   *
   */
  public FileRecord getFileRecord(int index)
  {
    if ( 0 == fileRecords.size() )
    {
      int payloadIndex = 11;

      for (int i = 0; i < getFileCount(); i ++ )
      {
        // TODO calculate size/index

        // Read the index
        int index1 = payload[payloadIndex++];
        int index2 = payload[payloadIndex++];
        int index3 = payload[payloadIndex++];
        int index4 = payload[payloadIndex++];

        int fileIndex = 0;
        fileIndex |= index1;
        fileIndex |= index2 << 8;
        fileIndex |= index3 << 16;
        fileIndex |= index4 << 24;

        // Read the size
        int size1 = payload[payloadIndex++];
        int size2 = payload[payloadIndex++];
        int size3 = payload[payloadIndex++];
        int size4 = payload[payloadIndex++];

        int fileSize = 0;
        fileSize |= size1;
        fileSize |= size2 << 8;
        fileSize |= size3 << 16;
        fileSize |= size4 << 24;

        // Read the file terminated by double null
        // temp
        int nullCount = 0;
        Vector stringData = new Vector();
        while ( 2 != nullCount )
        {

          byte b = (byte)payload[payloadIndex++];
          
          if  ( 0 == nullCount )
          {  
            // The file name is terminated by null which is sometimes followed
            // by another null but in some cases (mp3) extra data is between
            // the null characters
            stringData.addElement(new Byte(b));
          }
          
          if ( 0 == b )
          {
            nullCount++;
          }
        }

        byte[] stringBytes = new byte[stringData.size()];

        for(int z = 0; z < stringBytes.length; z++)
        {
          stringBytes[z] = ((Byte)stringData.get(z)).byteValue();
        }

        fileRecords.addElement(new FileRecord(fileIndex,
                                              fileSize,
                                              new String(stringBytes)));

      }
    }

    return (FileRecord)fileRecords.elementAt(index);
  }


  /**
   *  Retrieve the client GUID for the replying servant
   *
   *  @return client GUID
   */
  public GUID getClientIdentifier()
  {
    int startIndex = payloadSize - 16; // GUID is last 16 bytes
    short[] guidData = new short[16];

    for (int i = 0; i < 16; i++)
    {
      guidData[i] = payload[startIndex++];
    }

    return new GUID(guidData);
  }

  /**
   *  Retrieve the vendor code for the responding servant
   *
   *  @return vendor code or NONE if the code is not present
   */
  public String getVendorCode()
  {
    String code = "NONE";

    if ( isBearShareTrailerPresent() )
    {
      int trailerIndex = getFileRecordBounds();

      byte[] codeData = new byte[4];
      for (int i = 0; i < 4; i++ )
      {
        codeData[i] = (byte)payload[trailerIndex++];
      }

      code = new String(codeData);
    }

    return code;
  }

  /**
   *  Produces a byte[] suitable for
   *  GNUTELLA network
   *
   */
  byte[] getByteArray()
  {
    // construct the payload prior to sending if the payload doesn't exist
    // the payload will not exist for a SearchReply generated by the JTella
    // application. If this is a message we are routing, the payload is read
    // from the stream
    if ( 0 == getPayloadLength() )
    {
      buildPayload();
    }
    
    return super.getByteArray();
  }

  /**
   *  Check if the bearshare trailer is present between file records
   *  and GUID
   *
   */
  private boolean isBearShareTrailerPresent()
  {
    return getFileRecordBounds() != (payloadSize - 16);
  }

  /**
   *  Method to determine the ending ending for file data. This can be used
   *  to determine if the message contains the BearShare trailer
   *
   *  @return ending index
   */
  private int getFileRecordBounds()
  {
    int boundsIndex = 11;

    for (int i = 0; i < getFileCount(); i++ )
    {
      boundsIndex += 4; // File Index
      boundsIndex += 4; // File Size

      // asci file name terminated by nulls which may not be continguous
      int nullCount = 0;
      while ( 2 != nullCount )
      {
        byte b = (byte)payload[boundsIndex++];
        if ( 0 == b )
        {
          nullCount++;
        }
      }
    }

    return boundsIndex;
  }

  /**
   *  Represents information about a single file served
   *
   */
  static public class FileRecord
  {
     int index;
     int size;
     String fileName;

     /**
      *  Constructs a record describing a shared file
      *
      *  @param index index of the file
      *  @param size size of the file in bytes
      *  @param filename file name
      */
     public FileRecord(int index, int size, String fileName)
     {
       this.index = index;
       this.size = size;
       this.fileName = fileName;
     }

     /**
      *  Get the index of the file
      *
      *  @return index
      */
     public int getIndex()
     {
       return index;
     }

     /**
      *  Get the size of the file
      *
      *  @return file size
      */
     public int getSize()
     {
       return size;
     }

     /**
      *  Get the file name
      *
      *  @return file name
      */
     public String getName()
     {
       return fileName;
     }

     /**
      *  Flatten the <code>FileRecord</code>
      *
      *  @return bytes
      */
     byte[] getBytes()
     {
       byte[] result = null;
       try
       {
         ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
         DataOutputStream dataStream = new DataOutputStream(byteStream);

         // write the index, little endian
         int index1 = 0x000000FF & index;
         int index2 = 0x0000FF00 & index;
         index2 = index2 >> 8;
         int index3 = 0x00FF0000 & index;
         index3 = index3 >> 16;
         int index4 = 0xFF000000 & index;
         index4 = index4 >> 24;

         dataStream.write(index1);
         dataStream.write(index2);
         dataStream.write(index3);
         dataStream.write(index4);

         int size1 = 0x000000FF & size;
         int size2 = 0x0000FF00 & size;
         size2 = size2 >> 8;
         int size3 = 0x00FF0000 & size;
         size3 = size3 >> 16;
         int size4 = 0xFF000000 & size;
         size4 = size4 >> 24;

         dataStream.write(size1);
         dataStream.write(size2);
         dataStream.write(size3);
         dataStream.write(size4);

         // write the file name, terminated by two nulls
         dataStream.write(fileName.getBytes());
         dataStream.writeByte(0);
         dataStream.writeByte(0);

         result = byteStream.toByteArray();
         dataStream.close();
       }
       catch(IOException io)
       {
         Log.getLog().log(io);
       }


       return result;
     }

  }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜精品久久久久久久久久久 | 91一区在线观看| 国产欧美视频一区二区三区| 国产99精品视频| 亚洲午夜精品网| 2017欧美狠狠色| 欧美自拍偷拍一区| 狠狠色丁香婷婷综合久久片| 国产精品福利影院| 日韩亚洲欧美高清| 色欧美片视频在线观看| 国产精品一区二区你懂的| 亚洲在线中文字幕| 国产精品久久久久久久久搜平片| 欧美久久久久久蜜桃| av一二三不卡影片| 国产 欧美在线| 久久成人综合网| 国产精品久久久久久一区二区三区| 欧美体内she精视频| 国产成人精品影视| 国产suv精品一区二区三区| 美女一区二区在线观看| 香蕉加勒比综合久久| 一区二区久久久久久| 亚洲精品你懂的| 亚洲精品成a人| 亚洲高清在线视频| 一区二区高清在线| 午夜欧美在线一二页| 爽好多水快深点欧美视频| 天天综合色天天| 另类小说综合欧美亚洲| 国产麻豆一精品一av一免费| 国产一区二区三区视频在线播放| 久久国产精品免费| thepron国产精品| 91精选在线观看| 久久久久国产免费免费| 欧美大片一区二区三区| 国产欧美一区二区三区网站| 欧美激情中文字幕一区二区| 亚洲精品日韩一| 美脚の诱脚舐め脚责91 | 欧美高清激情brazzers| 欧美成人一区二区| 国产精品福利av| 日本中文一区二区三区| 成人美女视频在线观看| 在线综合+亚洲+欧美中文字幕| 国产校园另类小说区| 亚洲va天堂va国产va久| 国产在线视视频有精品| 欧洲人成人精品| 国产精品亲子乱子伦xxxx裸| 免费成人在线影院| 在线观看视频一区| 亚洲品质自拍视频| 国精产品一区一区三区mba桃花 | 在线视频你懂得一区| 国产女同互慰高潮91漫画| 日日骚欧美日韩| 欧美日韩一区二区三区高清| 自拍视频在线观看一区二区| 国产成人自拍在线| 国产亚洲精品中文字幕| 美女任你摸久久| 日韩欧美国产综合在线一区二区三区| 亚洲男人的天堂在线aⅴ视频 | 在线视频一区二区三区| 一二三四区精品视频| 色狠狠综合天天综合综合| 亚洲人成网站在线| 91福利视频在线| 亚洲成av人影院| 欧美一区二区三区在线电影| 午夜视频在线观看一区| 日韩欧美一二三| 国产伦精一区二区三区| 国产欧美一区二区精品性| 国产成人免费视频网站高清观看视频 | 国产丝袜美腿一区二区三区| 国产自产视频一区二区三区| 亚洲国产激情av| 欧美图区在线视频| 激情文学综合插| 亚洲欧美日韩国产综合在线| 欧美乱熟臀69xxxxxx| 国内欧美视频一区二区| 一级精品视频在线观看宜春院| 制服丝袜日韩国产| 91丨九色丨蝌蚪富婆spa| 日韩成人免费在线| 一二三四区精品视频| 国产午夜亚洲精品不卡| 欧美精品自拍偷拍| 91最新地址在线播放| 国产专区欧美精品| 一区二区三区不卡视频 | 色一区在线观看| 久久99精品网久久| 亚洲尤物视频在线| 久久久久久久久久久99999| 色综合久久天天| 久久电影网站中文字幕| 亚洲在线视频一区| 国产精品三级久久久久三级| 欧美精品乱码久久久久久| 国产老妇另类xxxxx| 婷婷国产v国产偷v亚洲高清| 亚洲国产高清aⅴ视频| 欧美日韩的一区二区| 国产成人av一区| 蜜桃av噜噜一区| 日本亚洲免费观看| 亚洲风情在线资源站| 国产精品国产a级| 欧美tk丨vk视频| 日韩色视频在线观看| 欧美日韩电影一区| 欧美人与禽zozo性伦| 欧美综合一区二区三区| 色综合久久久久综合体| 欧美在线观看一区| 7878成人国产在线观看| 91精品国产综合久久香蕉的特点| 欧美喷潮久久久xxxxx| 91福利社在线观看| 欧美性做爰猛烈叫床潮| 欧美性视频一区二区三区| 欧美性色aⅴ视频一区日韩精品| 欧美日韩在线播放三区| 日韩免费看的电影| 国产午夜精品久久| 亚洲欧美一区二区三区久本道91 | 成人免费av在线| 欧美日韩日日骚| 亚洲精品一区在线观看| 国产精品久久久久久久第一福利| 一区二区三区在线观看欧美| 日本不卡一区二区三区高清视频| 蜜臀精品一区二区三区在线观看| 国产揄拍国内精品对白| 色婷婷亚洲综合| 精品国产伦一区二区三区观看方式 | 欧美大片在线观看一区| 综合av第一页| 久久精品国产99久久6| 欧美日韩在线观看一区二区| 日韩欧美一二三四区| 亚洲精品免费在线观看| av色综合久久天堂av综合| 欧美精品一区二区三区视频| 日本一区中文字幕| 欧美日韩一区高清| 亚洲国产精品综合小说图片区| 日本精品一区二区三区高清| 亚洲欧洲av一区二区三区久久| 风间由美性色一区二区三区| 久久久久久免费网| 夫妻av一区二区| 亚洲成人av一区| 91精品久久久久久蜜臀| 黄色资源网久久资源365| 国产欧美精品一区二区色综合 | 精品无码三级在线观看视频| 欧美成人女星排名| www.爱久久.com| 日韩和欧美的一区| 欧美高清在线一区| 欧美日韩五月天| 久久99久久久久| 亚洲欧美成aⅴ人在线观看| 91精品国产欧美一区二区18| 成人国产电影网| 蜜臀91精品一区二区三区| 国产精品美女一区二区在线观看| 欧美日韩你懂的| 国产精品91一区二区| 亚洲成av人片www| 中文字幕在线不卡视频| 日韩视频免费观看高清完整版在线观看| 国产一区二区中文字幕| 午夜精品福利一区二区蜜股av| 久久先锋影音av| 91精品国产麻豆国产自产在线 | 99久久精品久久久久久清纯| 喷水一区二区三区| 日韩1区2区3区| 日韩经典一区二区| 亚洲精品乱码久久久久久久久| 国产亚洲欧美激情| 国产清纯白嫩初高生在线观看91| 欧美乱熟臀69xxxxxx| 91成人在线免费观看| 欧美亚洲一区二区在线观看| 色欧美88888久久久久久影院| 色诱视频网站一区| 欧美色图片你懂的| 欧美片网站yy|