|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.messages.Message
com.limegroup.gnutella.messages.QueryReply
A query reply. Contains information about the responding host in addition to an array of responses. These responses are not parsed until the getResponses method is called. For efficiency reasons, bad query reply packets may not be discovered until the getResponses methods are called.
This class has partial support for BearShare-style query reply trailers. You can extract the vendor code, push flag, and busy flag. These methods may throw BadPacketException if the metadata cannot be extracted. Note that BadPacketException does not mean that other data (namely responses) cannot be read; MissingDataException might have been a better name. This class also encapsulates xml metadata. See the description of the QHD below for more details.
Nested Class Summary | |
static class |
QueryReply.IPPortCombo
Another utility class the encapsulates some complexity. |
static class |
QueryReply.PushProxyContainer
A simple utility class for doling out PushProxy information. |
Field Summary | |
static int |
COMMON_PAYLOAD_LEN
2 bytes for public area, 2 bytes for xml length. |
static boolean |
debugOn
|
static int |
XML_MAX_SIZE
|
Fields inherited from class com.limegroup.gnutella.messages.Message |
F_PING, F_PING_REPLY, F_PUSH, F_QUERY, F_QUERY_REPLY, F_ROUTE_TABLE_UPDATE, F_VENDOR_MESSAGE, F_VENDOR_MESSAGE_STABLE, N_MULTICAST, N_TCP, N_UDP, N_UNKNOWN, RECORD_STATS, SOFT_MAX |
Constructor Summary | |
QueryReply(byte[] guid,
byte ttl,
byte hops,
byte[] payload)
Creates a new query reply with data read from the network. |
|
QueryReply(byte[] guid,
byte ttl,
int port,
byte[] ip,
long speed,
Response[] responses,
byte[] clientGUID,
boolean isMulticastReply)
Creates a new query reply. |
|
QueryReply(byte[] guid,
byte ttl,
int port,
byte[] ip,
long speed,
Response[] responses,
byte[] clientGUID,
boolean needsPush,
boolean isBusy,
boolean finishedUpload,
boolean measuredSpeed,
boolean supportsChat,
boolean isMulticastReply)
Creates a new QueryReply with a BearShare 2.2.0-style QHD. |
|
QueryReply(byte[] guid,
byte ttl,
int port,
byte[] ip,
long speed,
Response[] responses,
byte[] clientGUID,
byte[] xmlBytes,
boolean needsPush,
boolean isBusy,
boolean finishedUpload,
boolean measuredSpeed,
boolean supportsChat,
boolean isMulticastReply)
Creates a new QueryReply with a BearShare 2.2.0-style QHD. |
|
QueryReply(byte[] guid,
byte ttl,
int port,
byte[] ip,
long speed,
Response[] responses,
byte[] clientGUID,
byte[] xmlBytes,
boolean needsPush,
boolean isBusy,
boolean finishedUpload,
boolean measuredSpeed,
boolean supportsChat,
boolean isMulticastReply,
java.util.Set proxies)
Creates a new QueryReply with a BearShare 2.2.0-style QHD. |
|
QueryReply(byte[] guid,
QueryReply reply)
Copy constructor. |
Method Summary | |
int |
calculateQualityOfService(boolean iFirewalled)
This method calculates the quality of service for a given host. |
static void |
debug(java.lang.Exception e)
|
static void |
debug(java.lang.String out)
|
byte[] |
getClientGUID()
Returns the 16 byte client ID (i.e., the "footer") of the responding host. |
boolean |
getHadSuccessfulUpload()
Returns true if this has successfully uploaded a complete file (bit set). |
HostData |
getHostData()
Returns the HostData object describing information about this QueryReply. |
java.lang.String |
getIP()
Returns the IP address of the responding host in standard dotted-decimal format, e.g., "192.168.0.1" |
byte[] |
getIPBytes()
Accessor the IP address in byte array form. |
boolean |
getIsBusy()
Returns true if this has no more download slots. |
boolean |
getIsMeasuredSpeed()
Returns true if the speed in this QueryReply was measured (bit set). |
boolean |
getNeedsPush()
Returns true if this's push flag is set, i.e., a push download is needed. |
int |
getPort()
|
java.util.Set |
getPushProxies()
|
short |
getResultCount()
Return the number of results N in this query. |
java.util.Iterator |
getResults()
Returns an iterator that will yield the results, each as an instance of the Response class. |
java.util.List |
getResultsAsList()
Returns a List that will yield the results, each as an instance of the Response class. |
long |
getSpeed()
|
boolean |
getSupportsBrowseHost()
Returns true iff the client supports browse host feature. |
boolean |
getSupportsChat()
Returns true iff the client supports chat. |
java.lang.String |
getVendor()
Returns the name of this' vendor, all capitalized. |
byte[] |
getXMLBytes()
Return the associated xml metadata string if the queryreply contained one. |
static boolean |
isFirewalledQuality(int quality)
Utility method for determining whether or not the given "quality" score for a QueryReply denotes that the host is firewalled or not. |
boolean |
isReplyToMulticastQuery()
Returns true iff the reply was sent in response to a multicast query. |
void |
recordDrop()
Records the dropping of this message in statistics. |
void |
setGUID(GUID guid)
Sets the guid for this message. |
Message |
stripExtendedPayload()
Returns this, because it's always safe to send big replies. |
java.lang.String |
toString()
|
void |
writePayload(java.io.OutputStream out)
|
Methods inherited from class com.limegroup.gnutella.messages.Message |
compareTo, getCreationTime, getFunc, getGUID, getHops, getLength, getNetwork, getPriority, getTotalLength, getTTL, hop, isMulticast, isTCP, isUDP, isUnknownNetwork, makeGuid, read, read, read, read, read, readNullTerminatedBytes, repOk, setHops, setPriority, setTTL, updateLength, write, writeGemExtension, writeGemExtension, writeGemExtensions |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int XML_MAX_SIZE
public static final int COMMON_PAYLOAD_LEN
public static final boolean debugOn
Constructor Detail |
public QueryReply(byte[] guid, byte ttl, int port, byte[] ip, long speed, Response[] responses, byte[] clientGUID, boolean isMulticastReply)
public QueryReply(byte[] guid, byte ttl, int port, byte[] ip, long speed, Response[] responses, byte[] clientGUID, boolean needsPush, boolean isBusy, boolean finishedUpload, boolean measuredSpeed, boolean supportsChat, boolean isMulticastReply)
needsPush
- true iff this is firewalled and the downloader should
attempt a push without trying a normal download.isBusy
- true iff this server is busy, i.e., has no more upload slots.finishedUpload
- true iff this server has successfully finished an
uploadmeasuredSpeed
- true iff speed is measured, not as reported by the
usersupportsChat
- true iff the host currently allows chatting.public QueryReply(byte[] guid, byte ttl, int port, byte[] ip, long speed, Response[] responses, byte[] clientGUID, byte[] xmlBytes, boolean needsPush, boolean isBusy, boolean finishedUpload, boolean measuredSpeed, boolean supportsChat, boolean isMulticastReply) throws java.lang.IllegalArgumentException
needsPush
- true iff this is firewalled and the downloader should
attempt a push without trying a normal download.isBusy
- true iff this server is busy, i.e., has no more upload slots.finishedUpload
- true iff this server has successfully finished an
uploadmeasuredSpeed
- true iff speed is measured, not as reported by the
userxmlBytes
- The (non-null) byte[] containing aggregated
and indexed information regarding file metadata. In terms of byte-size,
this should not be bigger than 65535 bytes. Anything larger will result
in an Exception being throw. This String is assumed to consist of
compressed data.supportsChat
- true iff the host currently allows chatting.
java.lang.IllegalArgumentException
- Thrown if
xmlBytes.length > XML_MAX_SIZEpublic QueryReply(byte[] guid, byte ttl, int port, byte[] ip, long speed, Response[] responses, byte[] clientGUID, byte[] xmlBytes, boolean needsPush, boolean isBusy, boolean finishedUpload, boolean measuredSpeed, boolean supportsChat, boolean isMulticastReply, java.util.Set proxies) throws java.lang.IllegalArgumentException
needsPush
- true iff this is firewalled and the downloader should
attempt a push without trying a normal download.isBusy
- true iff this server is busy, i.e., has no more upload slots.finishedUpload
- true iff this server has successfully finished an
uploadmeasuredSpeed
- true iff speed is measured, not as reported by the
userxmlBytes
- The (non-null) byte[] containing aggregated
and indexed information regarding file metadata. In terms of byte-size,
this should not be bigger than 65535 bytes. Anything larger will result
in an Exception being throw. This String is assumed to consist of
compressed data.supportsChat
- true iff the host currently allows chatting.proxies
- an array of PushProxy interfaces. will be included in
the replies GGEP extension.
java.lang.IllegalArgumentException
- Thrown if
xmlBytes.length > XML_MAX_SIZEpublic QueryReply(byte[] guid, byte ttl, byte hops, byte[] payload) throws BadPacketException
public QueryReply(byte[] guid, QueryReply reply)
Note: The payload is not really copied, but the reference in the newly constructed query reply, points to the one in the passed reply. But since the payload cannot be mutated, it shouldn't make difference if different query replies maintain reference to same payload
guid
- The new GUID for the replyreply
- The query reply from where to copy the fields into the
new constructed query replyMethod Detail |
public void setGUID(GUID guid)
setGUID
in class Message
guid
- The guid to be setpublic void writePayload(java.io.OutputStream out) throws java.io.IOException
writePayload
in class Message
java.io.IOException
public byte[] getXMLBytes()
public short getResultCount()
public int getPort()
public java.lang.String getIP()
public byte[] getIPBytes()
public long getSpeed()
public java.util.Iterator getResults() throws BadPacketException
BadPacketException
public java.util.List getResultsAsList() throws BadPacketException
BadPacketException
public java.lang.String getVendor() throws BadPacketException
BadPacketException
public boolean getNeedsPush() throws BadPacketException
BadPacketException
public boolean getIsBusy() throws BadPacketException
BadPacketException
public boolean getHadSuccessfulUpload() throws BadPacketException
BadPacketException
public boolean getIsMeasuredSpeed() throws BadPacketException
BadPacketException
public boolean getSupportsChat() throws BadPacketException
BadPacketException
public boolean getSupportsBrowseHost() throws BadPacketException
Throws
- BadPacketException if
the flag couldn't be extracted, either because it is missing or
corrupted. Typically this exception is treated the same way as returning
false.
BadPacketException
public boolean isReplyToMulticastQuery() throws BadPacketException
Throws
- BadPacketException if
the flag couldn't be extracted, either because it is missing or
corrupted. Typically this exception is treated the same way as returning
false.
BadPacketException
public java.util.Set getPushProxies()
public HostData getHostData() throws BadPacketException
BadPacketException
public byte[] getClientGUID()
public Message stripExtendedPayload()
stripExtendedPayload
in class Message
public java.lang.String toString()
toString
in class Message
public int calculateQualityOfService(boolean iFirewalled)
iFirewalled
- switch to indicate if the client is firewalled or
not. See RouterService.acceptingIncomingConnection or Acceptor for
details.
public static boolean isFirewalledQuality(int quality)
quality
- the quality, or score, in question
public void recordDrop()
Message
recordDrop
in class Message
public static void debug(java.lang.String out)
public static void debug(java.lang.Exception e)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |