Package twisted :: Package protocols :: Module gnutella :: Class GnutellaTalker |
[show private | hide private]
[frames | no frames]

## Class GnutellaTalker

    BaseProtocol --+
                   |
            Protocol --+
                       |
            LineReceiver --+
                           |
                          GnutellaTalker

Known Subclasses:
  `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)`
| ``connectionFailed`(self)` (Deprecated) (inherited from `Protocol`)
| ``connectionLost`(self, reason)` Called when the connection is shut down. (inherited from `Protocol`)
| ``connectionMade`(self)` Called when a connection is made.
| ``dataReceived`(self, data)` Protocol.dataReceived. (inherited from `LineReceiver`)
| ``descriptorReceived`(self, descriptor)` A Gnutella descriptor has arrived.
| ``handlePing`(self, descriptorId, ttl, hops, payload)` 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)`
| ``lineLengthExceeded`(self, line)` Called when the maximum line length has been reached. (inherited from `LineReceiver`)
| ``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.
| ``pongReceived`(self, descriptorId, ttl, hops, ipAddress, port, numberOfFilesShared, kbShared)` Override this to handle pong messages.
| ``pushReceived`(descriptorId, ttl, hops, ipAddress, port, serventIdentifier, fileIndex)` Override this to handle push messages.
| ``queryHitReceived`(self, descriptorId, ttl, hops, ipAddress, port, resultSet, serventIdentifier, speed)` Override this to handle query hit messages.
| ``queryReceived`(self, descriptorId, ttl, hops, searchCriteria, minimumSpeed)` Override this to handle query messages.
| ``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"
| ``sendLine`(self, line)` Sends a line to the other end of the connection. (inherited from `LineReceiver`)
| ``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)
| `setInitiator(self)`
| ``setLineMode`(self, extra)` Sets the line-mode of this receiver. (inherited from `LineReceiver`)
| ``setRawMode`(self)` 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. Overrides: `twisted.internet.protocol.BaseProtocol.connectionMade` (inherited documentation)

### 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)),) Parameters: `ipAddress` - a string representing an IPv4 address like this "140.184.83.37"; This is the representation that the Python Standard Library's socket.connect() expects. `port` - an integer port number `numberOfFilesShared` - a long `kbShared` - a long

### 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)),) Parameters: `ipAddress` - a string representing an IPv4 address like this "140.184.83.37"; This is the representation that the Python Standard Library's socket.connect() expects. `port` - an integer port number `serventIdentifier` - string of length 16 `fileIndex` - a long

### 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)),) Parameters: `ipAddress` - a string representing an IPv4 address like this "140.184.83.37"; This is the representation that the Python Standard Library's socket.connect() expects. `port` - an integer port number `resultSet` - a list of tuples of (fileIndex, fileSize, fileName,) where fileIndex is a long, fileSize (in bytes) is a long, and fileName is a string `serventIdentifier` - string of length 16 `speed` - integer KB/s claimed by the responding host

### 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)),) Parameters: `searchCriteria` - a string `minimumSpeed` - integer KB/s -- you are not supposed to respond to this query if you can't serve at least this fast

### rawDataReceived(self, data) Override this for when raw data is received. Overrides: `twisted.protocols.basic.LineReceiver.rawDataReceived` (inherited documentation)

### 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)

Generated by Epydoc 1.1 on Thu May 8 13:16:37 2003 | http://epydoc.sf.net