def accept(self) -> bool:
     self.update_state(CallState.EXCHANGING_KEYS)
     if not self.call:
         self.call_failed()
         raise RuntimeError('call is not set')
     self.get_dhc()
     self.b = randint(2, self.dhc.p-1)
     self.g_b = pow(self.dhc.g, self.b, self.dhc.p)
     self.g_a_hash = self.call.g_a_hash
     try:
         self.call = self.client.send(functions.phone.AcceptCall(
             peer=types.InputPhoneCall(id=self.call_id, access_hash=self.call_access_hash),
             g_b=i2b(self.g_b),
             protocol=self.get_protocol()
         )).phone_call
     except errors.Error as e:
         if e.ID == 'CALL_ALREADY_ACCEPTED':
             self.stop()
             return True
         elif e.ID == 'CALL_ALREADY_DECLINED':
             self.call_discarded()
             return False
         raise e
     if isinstance(self.call, types.PhoneCallDiscarded):
         print('Call is already discarded')
         self.call_discarded()
         return False
     return True
示例#2
0
 def accept(self) -> bool:
     self.update_state(CallState.EXCHANGING_KEYS)
     if not self.call:
         self.call_failed()
         raise RuntimeError('call is not set')
     self.b = randint(2, self.dhc.p-1)
     self.g_b = pow(self.dhc.g, self.b, self.dhc.p)
     self.check_g(self.g_b, self.dhc.p)
     self.g_a_hash = self.call.g_a_hash
     try:
         self.call = self.client.send(functions.phone.AcceptCall(
             peer=types.InputPhoneCall(self.call_id, self.call.access_hash),
             g_b=i2b(self.g_b),
             protocol=self.get_protocol()
         )).phone_call
     except errors.CallAlreadyAccepted:
         self.stop()
         return True
     except errors.CallAlreadyDeclined:
         self.call_discarded()
         return False
     if isinstance(self.call, types.PhoneCallDiscarded):
         print('Call is already discarded')
         self.call_discarded()
         return False
     return True
示例#3
0
 def call_accepted(self) -> None:
     self.update_state(CallState.EXCHANGING_KEYS)
     self.g_b = b2i(self.call.g_b)
     self.check_g(self.g_b, self.dhc.p)
     self.auth_key = pow(self.g_b, self.a, self.dhc.p)
     self.key_fingerprint = calc_fingerprint(self.auth_key_bytes)
     self.call = self.client.send(
         functions.phone.ConfirmCall(
             key_fingerprint=self.key_fingerprint,
             peer=types.InputPhoneCall(self.call.id, self.call.access_hash),
             g_a=i2b(self.g_a),
             protocol=self.get_protocol(),
         )).phone_call
     self._initiate_encrypted_call()
示例#4
0
 def discard_call(self, reason=None):
     # TODO: rating
     if not reason:
         reason = types.PhoneCallDiscardReasonDisconnect()
     try:
         self.client.send(
             functions.phone.DiscardCall(
                 peer=types.InputPhoneCall(
                     id=self.call_id, access_hash=self.call_access_hash),
                 duration=self.ctrl.call_duration,
                 connection_id=self.ctrl.get_preferred_relay_id(),
                 reason=reason))
     except (errors.CallAlreadyDeclined, errors.CallAlreadyAccepted):
         pass
     self.call_ended()
示例#5
0
 def discard_call(self, reason=None):
     # TODO: rating
     if not reason:
         reason = types.PhoneCallDiscardReasonDisconnect()
     try:
         self.client.send(
             functions.phone.DiscardCall(
                 peer=types.InputPhoneCall(
                     id=self.call_id, access_hash=self.call_access_hash),
                 duration=self.ctrl.call_duration,
                 connection_id=self.ctrl.get_preferred_relay_id(),
                 reason=reason))
     except errors.Error as e:
         if e.ID not in ('CALL_ALREADY_DECLINED', 'CALL_ALREADY_ACCEPTED'):
             raise e
     self.call_ended()