2016-08-04 05:03:14 +02:00
|
|
|
import json
|
|
|
|
import logging
|
2016-11-10 23:16:35 +01:00
|
|
|
|
2017-02-06 19:18:41 +01:00
|
|
|
from twisted.internet.error import ConnectionRefusedError
|
2016-08-08 04:33:40 +02:00
|
|
|
from twisted.protocols.basic import FileSender
|
2016-08-04 05:03:14 +02:00
|
|
|
from twisted.internet.protocol import Protocol, ClientFactory
|
2016-08-09 06:59:50 +02:00
|
|
|
from twisted.internet import defer, error
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2017-02-06 19:18:41 +01:00
|
|
|
from lbrynet.reflector.common import IncompleteResponse, ReflectorRequestError
|
|
|
|
from lbrynet.reflector.common import REFLECTOR_V1, REFLECTOR_V2
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2016-11-10 23:18:15 +01:00
|
|
|
log = logging.getLogger(__name__)
|
2016-08-04 05:03:14 +02:00
|
|
|
|
|
|
|
|
2016-09-27 20:18:16 +02:00
|
|
|
class EncryptedFileReflectorClient(Protocol):
|
2016-08-08 04:33:40 +02:00
|
|
|
# Protocol stuff
|
2016-08-04 05:03:14 +02:00
|
|
|
def connectionMade(self):
|
2017-02-06 19:18:41 +01:00
|
|
|
log.debug("Connected to reflector")
|
2016-08-04 05:03:14 +02:00
|
|
|
self.response_buff = ''
|
|
|
|
self.outgoing_buff = ''
|
|
|
|
self.blob_hashes_to_send = []
|
2017-02-08 22:18:34 +01:00
|
|
|
self.failed_blob_hashes = []
|
2016-08-04 05:03:14 +02:00
|
|
|
self.next_blob_to_send = None
|
2017-02-06 19:18:41 +01:00
|
|
|
self.read_handle = None
|
|
|
|
self.sent_stream_info = False
|
|
|
|
self.received_descriptor_response = False
|
|
|
|
self.received_server_version = False
|
|
|
|
self.server_version = None
|
|
|
|
self.stream_descriptor = None
|
|
|
|
self.descriptor_needed = None
|
|
|
|
self.needed_blobs = []
|
|
|
|
self.reflected_blobs = []
|
2016-08-08 04:33:40 +02:00
|
|
|
self.file_sender = None
|
2016-08-09 06:59:50 +02:00
|
|
|
self.producer = None
|
|
|
|
self.streaming = False
|
2017-02-10 16:56:22 +01:00
|
|
|
|
2018-03-19 18:36:53 +01:00
|
|
|
self.blob_manager = self.factory.blob_manager
|
|
|
|
self.protocol_version = self.factory.protocol_version
|
|
|
|
self.stream_hash = self.factory.stream_hash
|
2018-03-29 15:45:36 +02:00
|
|
|
self.sd_hash = self.factory.sd_hash
|
2017-02-10 16:56:22 +01:00
|
|
|
|
2018-03-19 18:36:53 +01:00
|
|
|
d = self.load_descriptor()
|
|
|
|
d.addCallback(lambda _: self.send_handshake())
|
|
|
|
d.addErrback(lambda err: log.warning("An error occurred immediately: %s", err.getTraceback()))
|
2017-02-10 16:56:22 +01:00
|
|
|
|
2016-08-04 05:03:14 +02:00
|
|
|
def dataReceived(self, data):
|
|
|
|
self.response_buff += data
|
|
|
|
try:
|
|
|
|
msg = self.parse_response(self.response_buff)
|
2016-11-10 23:18:15 +01:00
|
|
|
except IncompleteResponse:
|
2016-08-04 05:03:14 +02:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.response_buff = ''
|
|
|
|
d = self.handle_response(msg)
|
2016-08-09 06:59:50 +02:00
|
|
|
d.addCallback(lambda _: self.send_next_request())
|
|
|
|
d.addErrback(self.response_failure_handler)
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2018-05-08 19:51:02 +02:00
|
|
|
def store_result(self, result):
|
|
|
|
if not self.needed_blobs or len(self.reflected_blobs) == len(self.needed_blobs):
|
|
|
|
reflected = True
|
|
|
|
else:
|
|
|
|
reflected = False
|
|
|
|
|
|
|
|
d = self.blob_manager.storage.update_reflected_stream(self.sd_hash, self.transport.getPeer().host, reflected)
|
|
|
|
d.addCallback(lambda _: result)
|
|
|
|
return d
|
|
|
|
|
2016-08-04 05:03:14 +02:00
|
|
|
def connectionLost(self, reason):
|
2017-10-02 21:48:47 +02:00
|
|
|
# make sure blob file readers get closed
|
|
|
|
self.set_not_uploading()
|
|
|
|
|
2016-08-09 06:59:50 +02:00
|
|
|
if reason.check(error.ConnectionDone):
|
2017-02-08 22:18:34 +01:00
|
|
|
if not self.needed_blobs:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.info("Reflector has all blobs for %s", self.stream_descriptor)
|
2017-02-08 22:18:34 +01:00
|
|
|
elif not self.reflected_blobs:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.info("No more completed blobs for %s to reflect, %i are still needed",
|
|
|
|
self.stream_descriptor, len(self.needed_blobs))
|
2017-02-08 22:18:34 +01:00
|
|
|
else:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.info('Finished sending reflector %i blobs for %s',
|
|
|
|
len(self.reflected_blobs), self.stream_descriptor)
|
2018-05-08 19:51:02 +02:00
|
|
|
result = self.reflected_blobs
|
2017-02-10 16:56:22 +01:00
|
|
|
elif reason.check(error.ConnectionLost):
|
2017-12-06 21:08:13 +01:00
|
|
|
log.warning("Stopped reflecting %s after sending %i blobs",
|
2017-02-10 16:56:22 +01:00
|
|
|
self.stream_descriptor, len(self.reflected_blobs))
|
2018-05-08 19:51:02 +02:00
|
|
|
result = self.reflected_blobs
|
2016-08-09 06:59:50 +02:00
|
|
|
else:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.info('Reflector finished for %s: %s', self.stream_descriptor,
|
2017-02-10 16:56:22 +01:00
|
|
|
reason)
|
2018-05-08 19:51:02 +02:00
|
|
|
result = reason
|
|
|
|
self.factory.finished_deferred.addCallback(self.store_result)
|
|
|
|
self.factory.finished_deferred.callback(result)
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2016-08-08 04:33:40 +02:00
|
|
|
# IConsumer stuff
|
|
|
|
|
|
|
|
def registerProducer(self, producer, streaming):
|
2016-08-09 06:59:50 +02:00
|
|
|
self.producer = producer
|
|
|
|
self.streaming = streaming
|
|
|
|
if self.streaming is False:
|
|
|
|
from twisted.internet import reactor
|
|
|
|
reactor.callLater(0, self.producer.resumeProducing)
|
2016-08-08 04:33:40 +02:00
|
|
|
|
|
|
|
def unregisterProducer(self):
|
2016-08-09 06:59:50 +02:00
|
|
|
self.producer = None
|
2016-08-08 04:33:40 +02:00
|
|
|
|
|
|
|
def write(self, data):
|
|
|
|
self.transport.write(data)
|
2016-08-09 06:59:50 +02:00
|
|
|
if self.producer is not None and self.streaming is False:
|
|
|
|
from twisted.internet import reactor
|
|
|
|
reactor.callLater(0, self.producer.resumeProducing)
|
2016-08-08 04:33:40 +02:00
|
|
|
|
2017-02-06 19:18:41 +01:00
|
|
|
def get_validated_blobs(self, blobs_in_stream):
|
|
|
|
def get_blobs(blobs):
|
2018-02-12 20:05:27 +01:00
|
|
|
for crypt_blob in blobs:
|
|
|
|
if crypt_blob.blob_hash and crypt_blob.length:
|
|
|
|
yield self.blob_manager.get_blob(crypt_blob.blob_hash, crypt_blob.length)
|
2017-02-06 19:18:41 +01:00
|
|
|
|
|
|
|
dl = defer.DeferredList(list(get_blobs(blobs_in_stream)), consumeErrors=True)
|
2017-09-20 20:02:34 +02:00
|
|
|
dl.addCallback(lambda blobs: [blob for r, blob in blobs if r and blob.get_is_verified()])
|
2017-02-06 19:18:41 +01:00
|
|
|
return dl
|
|
|
|
|
|
|
|
def set_blobs_to_send(self, blobs_to_send):
|
|
|
|
for blob in blobs_to_send:
|
2017-10-02 18:50:47 +02:00
|
|
|
if blob.blob_hash not in self.blob_hashes_to_send:
|
|
|
|
self.blob_hashes_to_send.append(blob.blob_hash)
|
2017-02-06 19:18:41 +01:00
|
|
|
|
|
|
|
def get_blobs_to_send(self):
|
|
|
|
def _show_missing_blobs(filtered):
|
|
|
|
if filtered:
|
|
|
|
needs_desc = "" if not self.descriptor_needed else "descriptor and "
|
2017-12-06 21:08:13 +01:00
|
|
|
log.info("Reflector needs %s%i blobs for stream",
|
2017-02-06 19:18:41 +01:00
|
|
|
needs_desc,
|
2017-12-06 21:08:13 +01:00
|
|
|
len(filtered))
|
2017-02-06 19:18:41 +01:00
|
|
|
return filtered
|
|
|
|
|
2018-03-19 18:36:53 +01:00
|
|
|
d = self.factory.blob_manager.storage.get_blobs_for_stream(self.stream_hash)
|
2017-02-06 19:18:41 +01:00
|
|
|
d.addCallback(self.get_validated_blobs)
|
|
|
|
if not self.descriptor_needed:
|
|
|
|
d.addCallback(lambda filtered:
|
|
|
|
[blob for blob in filtered if blob.blob_hash in self.needed_blobs])
|
|
|
|
d.addCallback(_show_missing_blobs)
|
|
|
|
d.addCallback(self.set_blobs_to_send)
|
2017-02-10 16:56:22 +01:00
|
|
|
d.addCallback(lambda _: None if self.descriptor_needed else self.set_not_uploading())
|
2017-02-06 19:18:41 +01:00
|
|
|
return d
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2017-02-06 19:18:41 +01:00
|
|
|
def send_request(self, request_dict):
|
|
|
|
self.write(json.dumps(request_dict))
|
2016-08-04 05:11:29 +02:00
|
|
|
|
2017-02-06 19:18:41 +01:00
|
|
|
def send_handshake(self):
|
|
|
|
self.send_request({'version': self.protocol_version})
|
2016-08-04 05:11:29 +02:00
|
|
|
|
2018-03-29 15:45:36 +02:00
|
|
|
@defer.inlineCallbacks
|
2017-02-06 19:18:41 +01:00
|
|
|
def load_descriptor(self):
|
2018-03-29 15:45:36 +02:00
|
|
|
if self.sd_hash:
|
|
|
|
self.stream_descriptor = yield self.factory.blob_manager.get_blob(self.sd_hash)
|
|
|
|
else:
|
|
|
|
raise ValueError("no sd hash for stream %s" % self.stream_hash)
|
2016-08-04 05:03:14 +02:00
|
|
|
|
|
|
|
def parse_response(self, buff):
|
|
|
|
try:
|
|
|
|
return json.loads(buff)
|
|
|
|
except ValueError:
|
2016-11-10 23:18:15 +01:00
|
|
|
raise IncompleteResponse()
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2016-08-09 06:59:50 +02:00
|
|
|
def response_failure_handler(self, err):
|
|
|
|
log.warning("An error occurred handling the response: %s", err.getTraceback())
|
|
|
|
|
2016-08-04 05:03:14 +02:00
|
|
|
def handle_response(self, response_dict):
|
2017-02-06 19:18:41 +01:00
|
|
|
if not self.received_server_version:
|
2016-08-08 04:33:40 +02:00
|
|
|
return self.handle_handshake_response(response_dict)
|
2017-02-06 19:18:41 +01:00
|
|
|
elif not self.received_descriptor_response and self.server_version == REFLECTOR_V2:
|
|
|
|
return self.handle_descriptor_response(response_dict)
|
2016-08-04 05:03:14 +02:00
|
|
|
else:
|
2016-08-08 04:33:40 +02:00
|
|
|
return self.handle_normal_response(response_dict)
|
|
|
|
|
|
|
|
def set_not_uploading(self):
|
2016-08-09 06:59:50 +02:00
|
|
|
if self.next_blob_to_send is not None:
|
2017-02-07 20:27:05 +01:00
|
|
|
log.debug("Close %s", self.next_blob_to_send)
|
2017-09-27 23:00:51 +02:00
|
|
|
self.read_handle.close()
|
2016-08-08 04:33:40 +02:00
|
|
|
self.read_handle = None
|
2016-08-09 06:59:50 +02:00
|
|
|
self.next_blob_to_send = None
|
2017-02-10 16:56:22 +01:00
|
|
|
if self.file_sender is not None:
|
|
|
|
self.file_sender.stopProducing()
|
|
|
|
self.file_sender = None
|
2016-08-09 06:59:50 +02:00
|
|
|
return defer.succeed(None)
|
2016-08-08 04:33:40 +02:00
|
|
|
|
|
|
|
def start_transfer(self):
|
2016-11-30 21:20:45 +01:00
|
|
|
assert self.read_handle is not None, \
|
|
|
|
"self.read_handle was None when trying to start the transfer"
|
2016-08-08 04:33:40 +02:00
|
|
|
d = self.file_sender.beginFileTransfer(self.read_handle, self)
|
2017-09-27 23:02:17 +02:00
|
|
|
d.addCallback(lambda _: self.read_handle.close())
|
2016-08-08 04:33:40 +02:00
|
|
|
return d
|
2016-08-04 05:03:14 +02:00
|
|
|
|
|
|
|
def handle_handshake_response(self, response_dict):
|
2016-08-08 04:33:40 +02:00
|
|
|
if 'version' not in response_dict:
|
|
|
|
raise ValueError("Need protocol version number!")
|
2017-02-06 19:18:41 +01:00
|
|
|
self.server_version = int(response_dict['version'])
|
|
|
|
if self.server_version not in [REFLECTOR_V1, REFLECTOR_V2]:
|
|
|
|
raise ValueError("I can't handle protocol version {}!".format(self.server_version))
|
|
|
|
self.received_server_version = True
|
2016-08-09 06:59:50 +02:00
|
|
|
return defer.succeed(True)
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2017-02-06 19:18:41 +01:00
|
|
|
def handle_descriptor_response(self, response_dict):
|
|
|
|
if self.file_sender is None: # Expecting Server Info Response
|
|
|
|
if 'send_sd_blob' not in response_dict:
|
|
|
|
raise ReflectorRequestError("I don't know whether to send the sd blob or not!")
|
|
|
|
if response_dict['send_sd_blob'] is True:
|
|
|
|
self.file_sender = FileSender()
|
|
|
|
else:
|
|
|
|
self.received_descriptor_response = True
|
|
|
|
self.descriptor_needed = response_dict['send_sd_blob']
|
|
|
|
self.needed_blobs = response_dict.get('needed_blobs', [])
|
|
|
|
return self.get_blobs_to_send()
|
|
|
|
else: # Expecting Server Blob Response
|
|
|
|
if 'received_sd_blob' not in response_dict:
|
|
|
|
raise ValueError("I don't know if the sd blob made it to the intended destination!")
|
|
|
|
else:
|
|
|
|
self.received_descriptor_response = True
|
2018-03-22 21:53:16 +01:00
|
|
|
disconnect = False
|
2017-02-06 19:18:41 +01:00
|
|
|
if response_dict['received_sd_blob']:
|
|
|
|
self.reflected_blobs.append(self.next_blob_to_send.blob_hash)
|
2017-02-07 20:27:38 +01:00
|
|
|
log.info("Sent reflector descriptor %s", self.next_blob_to_send)
|
2017-02-06 19:18:41 +01:00
|
|
|
else:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.warning("Reflector failed to receive descriptor %s",
|
|
|
|
self.next_blob_to_send)
|
2018-03-22 21:53:16 +01:00
|
|
|
disconnect = True
|
|
|
|
d = self.set_not_uploading()
|
|
|
|
if disconnect:
|
|
|
|
d.addCallback(lambda _: self.transport.loseConnection())
|
|
|
|
return d
|
2017-02-06 19:18:41 +01:00
|
|
|
|
2016-08-04 05:03:14 +02:00
|
|
|
def handle_normal_response(self, response_dict):
|
2016-08-09 06:59:50 +02:00
|
|
|
if self.file_sender is None: # Expecting Server Info Response
|
2016-08-08 04:33:40 +02:00
|
|
|
if 'send_blob' not in response_dict:
|
|
|
|
raise ValueError("I don't know whether to send the blob or not!")
|
|
|
|
if response_dict['send_blob'] is True:
|
|
|
|
self.file_sender = FileSender()
|
2016-08-09 06:59:50 +02:00
|
|
|
return defer.succeed(True)
|
2016-08-08 04:33:40 +02:00
|
|
|
else:
|
2017-12-13 19:56:44 +01:00
|
|
|
log.info("Reflector already has %s", self.next_blob_to_send)
|
2016-08-08 04:33:40 +02:00
|
|
|
return self.set_not_uploading()
|
|
|
|
else: # Expecting Server Blob Response
|
|
|
|
if 'received_blob' not in response_dict:
|
|
|
|
raise ValueError("I don't know if the blob made it to the intended destination!")
|
|
|
|
else:
|
2017-02-06 19:18:41 +01:00
|
|
|
if response_dict['received_blob']:
|
|
|
|
self.reflected_blobs.append(self.next_blob_to_send.blob_hash)
|
2017-12-06 21:08:13 +01:00
|
|
|
log.debug("Sent reflector blob %s", self.next_blob_to_send)
|
2017-02-06 19:18:41 +01:00
|
|
|
else:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.warning("Reflector failed to receive blob %s", self.next_blob_to_send)
|
2016-08-08 04:33:40 +02:00
|
|
|
return self.set_not_uploading()
|
|
|
|
|
|
|
|
def open_blob_for_reading(self, blob):
|
2017-09-20 20:02:34 +02:00
|
|
|
if blob.get_is_verified():
|
2016-08-08 04:33:40 +02:00
|
|
|
read_handle = blob.open_for_reading()
|
|
|
|
if read_handle is not None:
|
2016-08-11 02:04:03 +02:00
|
|
|
log.debug('Getting ready to send %s', blob.blob_hash)
|
2016-08-08 04:33:40 +02:00
|
|
|
self.next_blob_to_send = blob
|
|
|
|
self.read_handle = read_handle
|
2017-02-06 19:18:41 +01:00
|
|
|
return defer.succeed(None)
|
|
|
|
return defer.fail(ValueError(
|
2017-01-25 19:03:48 +01:00
|
|
|
"Couldn't open that blob for some reason. blob_hash: {}".format(blob.blob_hash)))
|
2016-08-08 04:33:40 +02:00
|
|
|
|
|
|
|
def send_blob_info(self):
|
|
|
|
assert self.next_blob_to_send is not None, "need to have a next blob to send at this point"
|
2017-02-06 19:18:41 +01:00
|
|
|
r = {
|
2016-08-08 04:33:40 +02:00
|
|
|
'blob_hash': self.next_blob_to_send.blob_hash,
|
2016-08-09 06:59:50 +02:00
|
|
|
'blob_size': self.next_blob_to_send.length
|
2017-02-06 19:18:41 +01:00
|
|
|
}
|
|
|
|
self.send_request(r)
|
|
|
|
|
|
|
|
def send_descriptor_info(self):
|
|
|
|
assert self.stream_descriptor is not None, "need to have a sd blob to send at this point"
|
|
|
|
r = {
|
|
|
|
'sd_blob_hash': self.stream_descriptor.blob_hash,
|
|
|
|
'sd_blob_size': self.stream_descriptor.length
|
|
|
|
}
|
|
|
|
self.sent_stream_info = True
|
|
|
|
self.send_request(r)
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2017-01-25 19:03:48 +01:00
|
|
|
def skip_missing_blob(self, err, blob_hash):
|
|
|
|
err.trap(ValueError)
|
2017-02-08 22:18:34 +01:00
|
|
|
if blob_hash not in self.failed_blob_hashes:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.warning("Failed to reflect blob %s, reason: %s",
|
|
|
|
str(blob_hash)[:16], err.getTraceback())
|
2017-02-08 22:18:34 +01:00
|
|
|
self.blob_hashes_to_send.append(blob_hash)
|
|
|
|
self.failed_blob_hashes.append(blob_hash)
|
|
|
|
else:
|
2017-12-06 21:08:13 +01:00
|
|
|
log.warning("Failed second try reflecting blob %s, giving up, reason: %s",
|
|
|
|
str(blob_hash)[:16], err.getTraceback())
|
2017-01-25 19:03:48 +01:00
|
|
|
|
2016-08-04 05:03:14 +02:00
|
|
|
def send_next_request(self):
|
2016-08-08 04:33:40 +02:00
|
|
|
if self.file_sender is not None:
|
2016-08-04 05:03:14 +02:00
|
|
|
# send the blob
|
2016-08-08 04:33:40 +02:00
|
|
|
return self.start_transfer()
|
2017-02-06 19:18:41 +01:00
|
|
|
elif not self.sent_stream_info:
|
|
|
|
# open the sd blob to send
|
|
|
|
blob = self.stream_descriptor
|
|
|
|
d = self.open_blob_for_reading(blob)
|
2017-02-07 22:09:44 +01:00
|
|
|
d.addCallbacks(lambda _: self.send_descriptor_info(),
|
|
|
|
lambda err: self.skip_missing_blob(err, blob.blob_hash))
|
2017-02-06 19:18:41 +01:00
|
|
|
return d
|
2016-08-08 04:33:40 +02:00
|
|
|
elif self.blob_hashes_to_send:
|
|
|
|
# open the next blob to send
|
2017-10-02 18:50:47 +02:00
|
|
|
blob_hash = self.blob_hashes_to_send[0]
|
2016-08-08 04:33:40 +02:00
|
|
|
self.blob_hashes_to_send = self.blob_hashes_to_send[1:]
|
2017-10-02 18:50:47 +02:00
|
|
|
d = self.blob_manager.get_blob(blob_hash)
|
|
|
|
d.addCallback(self.open_blob_for_reading)
|
2017-01-25 19:10:38 +01:00
|
|
|
d.addCallbacks(lambda _: self.send_blob_info(),
|
2017-02-06 19:18:41 +01:00
|
|
|
lambda err: self.skip_missing_blob(err, blob.blob_hash))
|
2016-08-08 04:33:40 +02:00
|
|
|
return d
|
2017-02-06 19:18:41 +01:00
|
|
|
# close connection
|
|
|
|
self.transport.loseConnection()
|
2016-08-04 05:03:14 +02:00
|
|
|
|
|
|
|
|
2016-09-27 20:18:16 +02:00
|
|
|
class EncryptedFileReflectorClientFactory(ClientFactory):
|
|
|
|
protocol = EncryptedFileReflectorClient
|
2018-03-19 18:36:53 +01:00
|
|
|
protocol_version = REFLECTOR_V2
|
2016-08-04 05:03:14 +02:00
|
|
|
|
2018-03-29 15:45:36 +02:00
|
|
|
def __init__(self, blob_manager, stream_hash, sd_hash):
|
2018-03-19 18:36:53 +01:00
|
|
|
self.blob_manager = blob_manager
|
|
|
|
self.stream_hash = stream_hash
|
2018-03-29 15:45:36 +02:00
|
|
|
self.sd_hash = sd_hash
|
2016-08-04 05:03:14 +02:00
|
|
|
self.p = None
|
2016-08-09 06:59:50 +02:00
|
|
|
self.finished_deferred = defer.Deferred()
|
2016-08-04 05:03:14 +02:00
|
|
|
|
|
|
|
def buildProtocol(self, addr):
|
|
|
|
p = self.protocol()
|
|
|
|
p.factory = self
|
|
|
|
self.p = p
|
2016-08-11 02:04:03 +02:00
|
|
|
return p
|
|
|
|
|
2016-08-27 01:58:53 +02:00
|
|
|
def startFactory(self):
|
|
|
|
log.debug('Starting reflector factory')
|
|
|
|
ClientFactory.startFactory(self)
|
|
|
|
|
|
|
|
def startedConnecting(self, connector):
|
2017-02-06 19:18:41 +01:00
|
|
|
log.debug('Connecting to reflector')
|
2016-08-27 01:58:53 +02:00
|
|
|
|
|
|
|
def clientConnectionLost(self, connector, reason):
|
|
|
|
"""If we get disconnected, reconnect to server."""
|
|
|
|
|
|
|
|
def clientConnectionFailed(self, connector, reason):
|
2017-02-06 19:18:41 +01:00
|
|
|
if reason.check(ConnectionRefusedError):
|
|
|
|
log.warning("Could not connect to reflector server")
|
|
|
|
else:
|
|
|
|
log.error("Reflector connection failed: %s", reason)
|