コード例 #1
0
ファイル: server.py プロジェクト: squareinc/lbry
    def handle_handshake(self, request_dict):
        """
        Upon connecting, the client sends a version handshake:
        {
            'version': int,
        }

        The server replies with the same version if it is supported
        {
            'version': int,
        }
        """

        if VERSION not in request_dict:
            raise ReflectorRequestError("Client should send version")

        if int(request_dict[VERSION]) not in [REFLECTOR_V1, REFLECTOR_V2]:
            raise ReflectorClientVersionError("Unknown version: %i" %
                                              int(request_dict[VERSION]))

        self.peer_version = int(request_dict[VERSION])
        log.debug('Handling handshake for client version %i',
                  self.peer_version)
        self.received_handshake = True
        return self.send_handshake_response()
コード例 #2
0
ファイル: client.py プロジェクト: vyaspranjal33/lbry
 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
             disconnect = False
             if response_dict['received_sd_blob']:
                 self.reflected_blobs.append(
                     self.next_blob_to_send.blob_hash)
                 log.info("Sent reflector descriptor %s",
                          self.next_blob_to_send)
             else:
                 log.warning("Reflector failed to receive descriptor %s",
                             self.next_blob_to_send)
                 disconnect = True
             d = self.set_not_uploading()
             if disconnect:
                 d.addCallback(lambda _: self.transport.loseConnection())
             return d
コード例 #3
0
ファイル: server.py プロジェクト: squareinc/lbry
 def handle_request(self, request_dict):
     if self.need_handshake():
         return self.handle_handshake(request_dict)
     if self.is_descriptor_request(request_dict):
         return self.handle_descriptor_request(request_dict)
     if self.is_blob_request(request_dict):
         return self.handle_blob_request(request_dict)
     raise ReflectorRequestError("Invalid request")