Home | Trees | Index | Help |
---|
Package twisted :: Package protocols :: Module gnutella :: Class GnutellaTalker |
|
BaseProtocol
--+ |Protocol
--+ |LineReceiver
--+ | GnutellaTalker
GnutellaRouter
,
GnutellaPinger
,
GnutellaPonger
This just speaks the Gnutella protocol and translates it into Python methods for higher-level services to program with. You probably want a higher-level class like GnutellaRouter or GnutellaServent.
If you really want to use this class itself, then the way to use it is to subclass it and override the methods named {ping,pong,push,query,queryHit}Received().
One constraint that it imposes which is not specified in the Gnutella 0.4 spec is that payload lengths must be less than or equal to 640 KB. If the payload length is greater than that, GnutellaTalker closes the connection.Method Summary | |
---|---|
__init__(self)
| |
(Deprecated) (inherited from Protocol )
| |
Called when the connection is shut down. (inherited from Protocol )
| |
Called when a connection is made. | |
Protocol.dataReceived. (inherited from LineReceiver )
| |
A Gnutella descriptor has arrived. | |
A ping message has arrived. | |
handlePong(self,
descriptorId,
ttl,
hops,
payload)
| |
handlePush(self,
descriptorId,
ttl,
hops,
payload)
| |
handleQuery(self,
descriptorId,
ttl,
hops,
payload)
| |
handleQueryHit(self,
descriptorId,
ttl,
hops,
payload)
| |
Called when the maximum line length has been reached. (inherited from LineReceiver )
| |
Precondition: We must be expecting a GNUTELLA CONNECT handshake move.: (self.initiator and (self.handshake == "initiatorsaidhello")) or ((not self.initiator) and (self.handshake == "start")): "self.initiator: %s, self.handshake: %s, line: %s" % (str(self.initiator), str(self.handshake), str(line),) | |
Override this to handle ping messages. | |
Override this to handle pong messages. | |
Override this to handle push messages. | |
Override this to handle query hit messages. | |
Override this to handle query messages. | |
Override this for when raw data is received. | |
Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),) Precondition: payload must not be larger than MAXUINT32 bytes.: len(payload) <= MAXUINT32: "len(payload): %s" | |
Sends a line to the other end of the connection. (inherited from LineReceiver )
| |
Precondition: ttl must be > 0 and <= MAXUINT8.: (ttl > 0) and (ttl <= MAXUINT8): "ttl: %s" % str(ttl) | |
Precondition: ttl must be > 0 and <= MAXUINT8.: (ttl > 0) and (ttl <= MAXUINT8): "ttl: %s" % str(ttl) Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),) Precondition: host must be a well-formed IPv4 address.: is_ipv4(host): "host: %s" % str(host) Precondition: port must be > 0 and <= MAXUINT16.: (port > 0) and (port <= MAXUINT16): "port: %s" % str(port) Precondition: numberOfFilesShared must be >= 0 and <= MAXUINT32.: (numberOfFilesShared >= 0) and (numberOfFilesShared <= MAXUINT32): "numberOfFilesShared: %s" % str(numberOfFilesShared) Precondition: kbShared must be >- 0 and <= MAXUINT32: (kbShared >= 0) and (kbShared <= MAXUINT32): "kbShared: %s" % str(kbShared) | |
setInitiator(self)
| |
Sets the line-mode of this receiver. (inherited from LineReceiver )
| |
Sets the raw mode of this receiver. (inherited from LineReceiver )
|
Method Details |
---|
connectionMade(self)Called when a connection is made. This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.
|
descriptorReceived(self, descriptor)A Gnutella descriptor has arrived. Precondition: descriptor must be a string of the right length to hold a payload of the encoded length.: len(descriptor) == (struct.unpack(PAYLOADENCODING, descriptor[PAYLOADLENGTHOFFSET:HEADERLENGTH])[0] + HEADERLENGTH): "self: %s, descriptor: %s" % (str(self), repr(descriptor),) |
handlePing(self, descriptorId, ttl, hops, payload)A ping message has arrived. |
lineReceived(self, line)Precondition: We must be expecting a GNUTELLA CONNECT handshake move.: (self.initiator and (self.handshake == "initiatorsaidhello")) or ((not self.initiator) and (self.handshake == "start")): "self.initiator: %s, self.handshake: %s, line: %s" % (str(self.initiator), str(self.handshake), str(line),) |
pingReceived(self, descriptorId, ttl, hops)Override this to handle ping messages. Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),) |
pongReceived(self, descriptorId, ttl, hops, ipAddress, port, numberOfFilesShared, kbShared)Override this to handle pong messages. Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),)
|
pushReceived(descriptorId, ttl, hops, ipAddress, port, serventIdentifier, fileIndex)Override this to handle push messages. Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),)
|
queryHitReceived(self, descriptorId, ttl, hops, ipAddress, port, resultSet, serventIdentifier, speed)Override this to handle query hit messages. Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),)
|
queryReceived(self, descriptorId, ttl, hops, searchCriteria, minimumSpeed)Override this to handle query messages. Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),)
|
rawDataReceived(self, data)Override this for when raw data is received.
|
sendDescriptor(self, descriptorId, payloadDescriptor, ttl, payload)Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),) Precondition: payload must not be larger than MAXUINT32 bytes.: len(payload) <= MAXUINT32: "len(payload): %s" |
sendPing(self, ttl)Precondition: ttl must be > 0 and <= MAXUINT8.: (ttl > 0) and (ttl <= MAXUINT8): "ttl: %s" % str(ttl) |
sendPong(self, ttl, descriptorId, host, port, numberOfFilesShared, kbShared)Precondition: ttl must be > 0 and <= MAXUINT8.: (ttl > 0) and (ttl <= MAXUINT8): "ttl: %s" % str(ttl) Precondition: descriptorId must be a string of length DESCRIPTORLENGTH.: (type(descriptorId) is types.StringType) and (len(descriptorId) == DESCRIPTORLENGTH): "descriptorId: %s :: %s" % (repr(descriptorId), str(type(descriptorId)),) Precondition: host must be a well-formed IPv4 address.: is_ipv4(host): "host: %s" % str(host) Precondition: port must be > 0 and <= MAXUINT16.: (port > 0) and (port <= MAXUINT16): "port: %s" % str(port) Precondition: numberOfFilesShared must be >= 0 and <= MAXUINT32.: (numberOfFilesShared >= 0) and (numberOfFilesShared <= MAXUINT32): "numberOfFilesShared: %s" % str(numberOfFilesShared) Precondition: kbShared must be >- 0 and <= MAXUINT32: (kbShared >= 0) and (kbShared <= MAXUINT32): "kbShared: %s" % str(kbShared) |
Home | Trees | Index | Help |
---|
Generated by Epydoc 1.1 on Thu May 8 13:16:37 2003 | http://epydoc.sf.net |