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

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

?? message.java

?? P2P協(xié)議GUNTELLA的java源代碼
?? JAVA
字號(hào):
/*
 * 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.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import com.kenmccrary.jtella.util.Log;

/**
 *  Abstract base class for GNUTella messages
 *
 */
abstract class Message
{
  public final static int SIZE = 23;

  final static short PING =  (short)0x00;
  final static short PONG =  (short)0x01;
  final static short PUSH =  (short)0x40;
  final static short QUERY = (short)0x80;
  final static short QUERYREPLY = (short)0x81;

  final static int SIZE_PING_PAYLOAD = 0;
  final static int SIZE_PONG_PAYLOAD = 14;
  final static int SIZE_PUSH_PAYLOAD = 26;
  final static int SIZE_QUERY_PAYLOAD = 257;
  final static int SIZE_QUERYREPLY_PAYLOAD = 65536;

  protected Connection originatingConnection;
  protected GUID guid;
  protected short type;
  protected byte ttl;
  protected byte hops;
  protected short[] payload;
  protected int payloadSize; 
  
  /**
   *  Constructs a new message
   *
   *
   *  @param type function type
   */
   Message(int type)
   {
     this(new GUID(), type);
   }
   
   
   /**
    *  Construct a message with a specific guid
    *
    *  @param guid
    *  @type message type
    */
   Message(GUID guid, int type)
   {
     this.guid = guid;
     this.type = (short)type;
     ttl = 7;
     hops = 0;
   }

  /**
   *  Query the type of message
   *
   *  @return type
   */
  int getType()
  {
    return type;  
  }

   /**
    *  Constructs a message from data read from network
    *
    *  @param rawMessage bytes
    */
   Message(short[] rawMessage, Connection originatingConnection)
   {
     this.originatingConnection = originatingConnection;
     StringBuffer buffer = new StringBuffer();

     for (int i = 0; i < rawMessage.length; i++) 
     {
       buffer.append("[" +
                     Integer.toHexString(rawMessage[i]) +
                     "]");

     }

     Log.getLog().logDebug("Raw Message Bytes: " +
                           buffer.toString());

     // Copy the GUID
     short[] guidData = new short[16];
     System.arraycopy(rawMessage, 0, guidData, 0, guidData.length);
     guid = new GUID(guidData);

     // Copy the function identifier
     type = rawMessage[16];

     // Copy the TTL 
     ttl = (byte)rawMessage[17];

     // Copy the hop count
     hops = (byte)rawMessage[18];

     // Copy the payoad size (little endian)
     int byte1 = rawMessage[19];
     int byte2 = rawMessage[20];
     int byte3 = rawMessage[21];
     int byte4 = rawMessage[22];

     payloadSize += byte1;
     payloadSize += (byte2 << 8);
     payloadSize += (byte3 << 16);
     payloadSize += (byte4 << 24);

   }


   /**
    *  Query the GUID 
    *
    *  @return 16 byte array
    */
   
   GUID getGUID()
   {
     return guid;
   }

   /**
    *  Apply a guid to the message
    *
    *  @param guid new guid
    */
   void setGUID(GUID guid)
   {
     this.guid = guid;
   }

   /**
    *  Get the Time to live for the message
    *
    */
  int getTTL()
  {
    return ttl;   
  }

  /**
   *  Set the ttl value for the message
   *
   */
  void setTTL(byte ttl)
  {
    this.ttl = ttl;
  }

  /**
   *  Get the hop count for this message
   *
   */
  int getHops()
  {
    return hops;
  }

  /**
   *  Set the hop count for this message, seven is the recommended maximum
   *
   */
  void setHops(byte hops)
  {
    this.hops = hops;
  }
   

   /**
    *  Add a payload to the message
    *
    *  @param payload payload for the message
    */
   void addPayload(short[] payload)
   {
     this.payload = payload;
     payloadSize = payload.length;
   }

   /**
    *  Add a payload to the message
    *
    *  @param payload payload for the message
    */
   void addPayload(byte[] payload)
   {
     short[] shortPayload = new short[payload.length];

     for (int i = 0; i < payload.length; i++) 
     {
       shortPayload[i] = payload[i];
     }

     addPayload(shortPayload);
   }

   /**
    *  Query the payload size for this message
    *
    */
   int getPayloadLength()
   {
     return payloadSize;
   }
   
   /**
    *  Retrieve the message payload
    *
    *  @return payload
    */
   short[] getPayload()
   {
     return payload;
   }

   /**
    *  Produces a byte[] suitable for 
    *  GNUTELLA network
    *
    */
   byte[] getByteArray()
   {
     // TODO handle expection avoid null pointer
     ByteArrayOutputStream byteStream = null;

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

       // Write the guid
       short[] guidData = guid.getData();
       for (int i = 0; i < guidData.length; i++) 
       {
         payloadStream.writeByte((byte)guidData[i]);
       }

       // Write the function (payload descriptor)
       payloadStream.writeByte(type);

       // Write the time to live
       payloadStream.writeByte(ttl);

       // Write the hop count
       payloadStream.writeByte(0);

      // Write the Payload size in little-endian
      int payloadSize1 = 0x000000FF & payloadSize;
      int payloadSize2 = (0x0000FF00 & payloadSize) >> 8;
      int payloadSize3 = (0x00FF0000 & payloadSize) >> 16;
      int payloadSize4 = (0xFF000000 & payloadSize) >> 24;
       
      payloadStream.writeByte(payloadSize1);
      payloadStream.writeByte(payloadSize2);
      payloadStream.writeByte(payloadSize3);
      payloadStream.writeByte(payloadSize4);

       // Write the payload
       if ( null != payload ) 
       {
         // Message may not have a payload (ex. Ping)
         for (int i = 0; i < payload.length; i++) 
         {
           byte payloadByte = (byte)payload[i];
           payloadStream.writeByte(payloadByte);
         }
       }
       

       // all done
       payloadStream.close();

     }
     catch (IOException io)
     {
       Log.getLog().log(io);
     }

     return byteStream.toByteArray();
   }
   
   /**
    *  Checks validity of a payloads size
    *
    *  @param message to test
    *  @return true if valid, false otherwise
    */
   boolean validatePayloadSize()
   {
     boolean result = false;
 
     switch ( type ) 
     {
       case PING:
       {
         if ( SIZE_PING_PAYLOAD == payloadSize ) 
         {
           result = true;
         }
         break;
       }

       case PONG:
       {
         if ( SIZE_PONG_PAYLOAD == payloadSize ) 
         {
           result = true;
         }
         break;
       }

       case PUSH:
       {
         if ( SIZE_PUSH_PAYLOAD == payloadSize ) 
         {
           result = true;
         }
         break;
       }

       case QUERY:
       {
         if ( payloadSize < SIZE_QUERY_PAYLOAD ) 
         {
           result = true;
         }
         break;
       }

       case QUERYREPLY:
       {
         if ( payloadSize < SIZE_QUERYREPLY_PAYLOAD) 
         {
           result = true;
         }
         break;
       }
     }
 
     return result;
   }

   /**
    *  String representation of the message
    *
    */
   public String toString()
   {
     StringBuffer message = new StringBuffer();

     message.append("GUID: ");

     short[] guidData = getGUID().getData();
     for (int i = 0; i < guidData.length; i++) 
     {
       message.append( "[" +
                       Integer.toHexString( guidData[i]) +
                       "]");
     }

     message.append("\n");

     switch (type) 
     {
       case PING:
       {
         message.append("PING message\n");
         break;
       }

       case PONG:
       {
         message.append("PONG message\n");
         break;
       }

       case QUERY:
       {
         message.append("QUERY message\n");
         break;
       }

       case QUERYREPLY:
       {
         message.append("QUERY REPLY message\n");
         break;
       }

       case PUSH:
       {
         message.append("PUSH message\n");
         break;
       }

       default:
       {
         message.append("Unknown message");
         break;
       }
     }

     message.append("Payload length: " + payloadSize + "\n");
     message.append("Payload: \n");

     if (null != payload) 
     {
       for (int i = 0; i < payload.length; i++) 
       {
         message.append( "[" +
                         Integer.toHexString(payload[i]) + 
                         "]");
       }

       message.append("\n");
     }
     else
     {
       message.append("No payload");
     }


     return message.toString();
   }
   
  /**
   *  Returns a String containing the flattened message
   *
   *  @return message string
   */
  public String toRawString()
  {
    StringBuffer buffer = new StringBuffer();
    byte[] rawMessage = getByteArray();
    
    for (int i = 0; i < rawMessage.length; i++) 
    {
      buffer.append("[" +
                    Integer.toHexString(rawMessage[i]) +
                   "]");
   
    }
   
    return buffer.toString();
  } 

  
  /**
   *  Get the connection that was the source for this message
   *
   * 
   *  @return originating connection or null if this <code>Message</code> was
   *  not read from the network
   */
   public Connection getOriginatingConnection()
   {
     return originatingConnection; 
   }
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
风间由美一区二区三区在线观看 | aaa国产一区| 国产999精品久久| 91丨porny丨国产入口| 欧美日韩高清一区二区三区| 久久亚洲春色中文字幕久久久| 亚洲欧洲在线观看av| 日精品一区二区| 国产乱码一区二区三区| 91色在线porny| 日韩欧美视频在线| 国产精品久久久久久久久果冻传媒| 亚洲与欧洲av电影| 国内不卡的二区三区中文字幕 | 综合在线观看色| 首页欧美精品中文字幕| 国产成人免费高清| 欧美精品一卡二卡| 丁香婷婷综合五月| 91亚洲精华国产精华精华液| 日韩午夜激情电影| 亚洲欧洲日本在线| 久久精品国产久精国产爱| 99久久免费精品| 欧美成人乱码一区二区三区| 亚洲精品成人悠悠色影视| 黄色小说综合网站| 在线精品视频免费播放| 国产视频一区二区在线| 五月激情综合婷婷| 99re视频这里只有精品| 久久伊人中文字幕| 天堂资源在线中文精品| 99精品桃花视频在线观看| 欧美不卡一区二区三区| 午夜一区二区三区在线观看| av在线不卡观看免费观看| 2020日本不卡一区二区视频| 亚洲国产精品一区二区www在线 | 亚洲国产成人一区二区三区| 天天影视色香欲综合网老头| 色综合天天综合| 国产欧美精品一区aⅴ影院| 免费三级欧美电影| 欧美视频一二三区| 国产精品久久久久影院老司| 国产麻豆视频精品| 日韩欧美国产麻豆| 天天亚洲美女在线视频| 在线观看亚洲精品| 亚洲欧洲综合另类| www.成人网.com| 国产亚洲欧美色| 国产永久精品大片wwwapp | 国产专区欧美精品| 欧美一区二区免费视频| 日韩精品亚洲专区| 欧美日韩日日骚| 亚洲女女做受ⅹxx高潮| av一区二区三区四区| 亚洲国产精品成人久久综合一区| 国产一区欧美一区| 久久只精品国产| 国产原创一区二区三区| 2020国产精品自拍| 国产精品一区二区黑丝| 欧美精品一区二区在线播放| 国内成人精品2018免费看| 精品国精品自拍自在线| 久久97超碰色| 久久免费视频一区| 国产专区综合网| 久久精品视频在线免费观看| 国产精品白丝jk黑袜喷水| 成人性生交大合| 国产午夜亚洲精品理论片色戒| 国产剧情一区在线| 日本一区二区视频在线观看| 国产不卡在线视频| 国产精品素人一区二区| 国产成人无遮挡在线视频| 国产午夜精品在线观看| 不卡一卡二卡三乱码免费网站| 亚洲欧美一区二区视频| 色8久久人人97超碰香蕉987| 一区二区国产视频| 欧美日本在线播放| 美女在线观看视频一区二区| 精品美女被调教视频大全网站| 国产精品一二三区| 国产精品二三区| 欧美色老头old∨ideo| 日韩电影在线观看电影| 久久青草国产手机看片福利盒子| 成人永久aaa| 一区二区三区资源| 欧美一区二区三区在线| 韩国v欧美v日本v亚洲v| 欧美激情综合五月色丁香小说| 99re成人精品视频| 午夜不卡av免费| 欧美成人乱码一区二区三区| 成人手机电影网| 一区二区免费在线播放| 欧美一二三四在线| 国产suv精品一区二区三区| 亚洲天堂2016| 欧美一区二区三区在| 成人小视频在线| 亚洲444eee在线观看| 久久美女艺术照精彩视频福利播放 | 成人av在线一区二区三区| 亚洲福利视频三区| 亚洲精品在线一区二区| 91丨porny丨国产入口| 毛片基地黄久久久久久天堂| 国产精品乱码妇女bbbb| 欧美疯狂做受xxxx富婆| 粉嫩嫩av羞羞动漫久久久| 亚洲成人免费av| 久久精品人人做人人爽人人| 欧洲av在线精品| 国产精品亚洲专一区二区三区| 亚洲激情av在线| 亚洲精品一区二区三区精华液| 色噜噜狠狠色综合中国| 老司机免费视频一区二区三区| 亚洲欧美日韩综合aⅴ视频| 欧美www视频| 欧洲一区二区三区免费视频| 国产成人精品亚洲日本在线桃色 | 欧美高清视频一二三区| 成人妖精视频yjsp地址| 日产国产高清一区二区三区| 亚洲日本免费电影| 久久色中文字幕| 欧美精品xxxxbbbb| 97超碰欧美中文字幕| 国精产品一区一区三区mba桃花 | 欧美一级片在线看| 色婷婷久久久亚洲一区二区三区| 国产麻豆精品一区二区| 丝袜美腿亚洲一区| 亚洲日本va午夜在线影院| 精品国产一二三| 国产成人在线网站| 亚洲美女精品一区| 国产片一区二区三区| 日韩亚洲欧美一区| 色偷偷久久人人79超碰人人澡| 国产精品性做久久久久久| 奇米色777欧美一区二区| 一区二区在线观看不卡| 国产色综合一区| 精品三级在线观看| 在线91免费看| 欧美最猛黑人xxxxx猛交| 92精品国产成人观看免费| 国产91在线看| 国产最新精品免费| 捆绑调教美女网站视频一区| 视频一区二区中文字幕| 一区二区三区欧美| 亚洲精品五月天| 一区在线中文字幕| 国产偷v国产偷v亚洲高清| 久久综合久久综合久久| 精品久久国产97色综合| 欧美一区二区三区在线电影 | 老司机午夜精品99久久| 日韩中文字幕1| 亚洲6080在线| 同产精品九九九| 午夜激情综合网| 婷婷一区二区三区| 丝袜美腿亚洲色图| 日韩精品一级二级 | 欧美tk—视频vk| 日韩精品最新网址| 日韩免费电影一区| 欧美成人a∨高清免费观看| 日韩女优电影在线观看| 日韩午夜激情av| 久久这里只有精品6| 久久精品男人的天堂| 国产精品污污网站在线观看| 成人性色生活片免费看爆迷你毛片| 成人爱爱电影网址| 国产成人亚洲综合a∨猫咪| 国产在线国偷精品产拍免费yy| 国产一区二区不卡在线| 国产成人在线视频播放| 风流少妇一区二区| 成人精品高清在线| 97se狠狠狠综合亚洲狠狠| 色婷婷av一区二区三区之一色屋| 欧美午夜电影网| 日韩视频一区二区三区| 久久久久久久综合| 国产精品久久看|