Package viff :: Module runtime :: Class ShareExchanger
[hide private]
[frames] | no frames]

Class ShareExchanger

source code


Send and receive shares.

All players are connected by pair-wise connections and this Twisted protocol is one such connection. It is used to send and receive shares from one other player.

Instance Methods [hide private]
 
__init__(self) source code
 
connectionMade(self)
Called when a connection is made.
source code
 
connectionLost(self, reason)
Called when the connection is shut down.
source code
 
stringReceived(self, string)
Called when a share is received.
source code
 
sendData(self, program_counter, data_type, data)
Send data to the peer.
source code
 
sendShare(self, program_counter, share)
Send a share.
source code
 
loseConnection(self)
Disconnect this protocol instance.
source code

Inherited from twisted.protocols.basic.Int16StringReceiver: dataReceived, sendString

Inherited from twisted.internet.protocol.BaseProtocol: __providedBy__, makeConnection

Inherited from twisted.protocols.basic._PauseableMixin: pauseProducing, resumeProducing, stopProducing

Class Variables [hide private]

Inherited from twisted.protocols.basic.Int16StringReceiver: recvd

Inherited from twisted.internet.protocol.Protocol: __implemented__, __provides__

Inherited from twisted.internet.protocol.BaseProtocol: connected, transport

Inherited from twisted.protocols.basic._PauseableMixin: paused

Instance Variables [hide private]
  incoming_data
Data expected to be received in the future.
  sent_packets
Statistics
Method Details [hide private]

connectionMade(self)

source code 

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)

connectionLost(self, reason)

source code 

Called when the connection is shut down.

Clear any circular references here, and any external references to this Protocol. The connection has been closed.

Overrides: twisted.internet.protocol.Protocol.connectionLost
(inherited documentation)

stringReceived(self, string)

source code 

Called when a share is received.

The string received is unpacked into the program counter, and a data part. The data is passed the appropriate Deferred in self.incoming_data.

Overrides: twisted.protocols.basic.Int16StringReceiver.stringReceived

sendData(self, program_counter, data_type, data)

source code 

Send data to the peer.

The program_counter is a tuple of unsigned integers, the data_type is an unsigned byte and data is a string.

The data is encoded as follows:

+---------+-----------+-----------+--------+--------------+
| pc_size | data_size | data_type |   pc   |     data     |
+---------+-----------+-----------+--------+--------------+
  2 bytes   2 bytes      1 byte     varies      varies

The program counter takes up 4 * pc_size bytes, the data takes up data_size bytes.

sendShare(self, program_counter, share)

source code 

Send a share.

The program counter and the share are converted to bytes and sent to the peer.