def __init__(self, connectionPool, timeout=10): """ We have access to the connection pool so we can store connections there after they've been successfully made. """ MsgPackProtocol.__init__(self, timeout) self.connectionPool = connectionPool self.log = Logger(system=self) self.storage = self.connectionPool.storage self.peersKeyId = None
def connectionLost(self, reason): keyId = self.getPeersKeyId() self.log.warning("Connection to %s lost: %s" % (keyId, str(reason))) self.connectionPool.forgetConnection(keyId) MsgPackProtocol.connectionLost(self, reason)
def dataReceived(self, data): self.connectionPool.saveConnection(self, self.getPeersKeyId()) self.log.debug("received data from %s: %s" % (self.getPeersKeyId(), data)) MsgPackProtocol.dataReceived(self, data)