pandora: decrease all info logs to debug

This commit is contained in:
Lucas Abel
2023-08-02 17:34:48 +00:00
parent 6ea669531a
commit 3ab2cd5e71
2 changed files with 46 additions and 46 deletions

View File

@@ -112,7 +112,7 @@ class HostService(HostServicer):
async def FactoryReset( async def FactoryReset(
self, request: empty_pb2.Empty, context: grpc.ServicerContext self, request: empty_pb2.Empty, context: grpc.ServicerContext
) -> empty_pb2.Empty: ) -> empty_pb2.Empty:
self.log.info('FactoryReset') self.log.debug('FactoryReset')
# delete all bonds # delete all bonds
if self.device.keystore is not None: if self.device.keystore is not None:
@@ -126,7 +126,7 @@ class HostService(HostServicer):
async def Reset( async def Reset(
self, request: empty_pb2.Empty, context: grpc.ServicerContext self, request: empty_pb2.Empty, context: grpc.ServicerContext
) -> empty_pb2.Empty: ) -> empty_pb2.Empty:
self.log.info('Reset') self.log.debug('Reset')
# clear service. # clear service.
self.waited_connections.clear() self.waited_connections.clear()
@@ -139,7 +139,7 @@ class HostService(HostServicer):
async def ReadLocalAddress( async def ReadLocalAddress(
self, request: empty_pb2.Empty, context: grpc.ServicerContext self, request: empty_pb2.Empty, context: grpc.ServicerContext
) -> ReadLocalAddressResponse: ) -> ReadLocalAddressResponse:
self.log.info('ReadLocalAddress') self.log.debug('ReadLocalAddress')
return ReadLocalAddressResponse( return ReadLocalAddressResponse(
address=bytes(reversed(bytes(self.device.public_address))) address=bytes(reversed(bytes(self.device.public_address)))
) )
@@ -152,7 +152,7 @@ class HostService(HostServicer):
address = Address( address = Address(
bytes(reversed(request.address)), address_type=Address.PUBLIC_DEVICE_ADDRESS bytes(reversed(request.address)), address_type=Address.PUBLIC_DEVICE_ADDRESS
) )
self.log.info(f"Connect to {address}") self.log.debug(f"Connect to {address}")
try: try:
connection = await self.device.connect( connection = await self.device.connect(
@@ -167,7 +167,7 @@ class HostService(HostServicer):
return ConnectResponse(connection_already_exists=empty_pb2.Empty()) return ConnectResponse(connection_already_exists=empty_pb2.Empty())
raise e raise e
self.log.info(f"Connect to {address} done (handle={connection.handle})") self.log.debug(f"Connect to {address} done (handle={connection.handle})")
cookie = any_pb2.Any(value=connection.handle.to_bytes(4, 'big')) cookie = any_pb2.Any(value=connection.handle.to_bytes(4, 'big'))
return ConnectResponse(connection=Connection(cookie=cookie)) return ConnectResponse(connection=Connection(cookie=cookie))
@@ -186,7 +186,7 @@ class HostService(HostServicer):
if address in (Address.NIL, Address.ANY): if address in (Address.NIL, Address.ANY):
raise ValueError('Invalid address') raise ValueError('Invalid address')
self.log.info(f"WaitConnection from {address}...") self.log.debug(f"WaitConnection from {address}...")
connection = self.device.find_connection_by_bd_addr( connection = self.device.find_connection_by_bd_addr(
address, transport=BT_BR_EDR_TRANSPORT address, transport=BT_BR_EDR_TRANSPORT
@@ -201,7 +201,7 @@ class HostService(HostServicer):
# save connection has waited and respond. # save connection has waited and respond.
self.waited_connections.add(id(connection)) self.waited_connections.add(id(connection))
self.log.info( self.log.debug(
f"WaitConnection from {address} done (handle={connection.handle})" f"WaitConnection from {address} done (handle={connection.handle})"
) )
@@ -216,7 +216,7 @@ class HostService(HostServicer):
if address in (Address.NIL, Address.ANY): if address in (Address.NIL, Address.ANY):
raise ValueError('Invalid address') raise ValueError('Invalid address')
self.log.info(f"ConnectLE to {address}...") self.log.debug(f"ConnectLE to {address}...")
try: try:
connection = await self.device.connect( connection = await self.device.connect(
@@ -233,7 +233,7 @@ class HostService(HostServicer):
return ConnectLEResponse(connection_already_exists=empty_pb2.Empty()) return ConnectLEResponse(connection_already_exists=empty_pb2.Empty())
raise e raise e
self.log.info(f"ConnectLE to {address} done (handle={connection.handle})") self.log.debug(f"ConnectLE to {address} done (handle={connection.handle})")
cookie = any_pb2.Any(value=connection.handle.to_bytes(4, 'big')) cookie = any_pb2.Any(value=connection.handle.to_bytes(4, 'big'))
return ConnectLEResponse(connection=Connection(cookie=cookie)) return ConnectLEResponse(connection=Connection(cookie=cookie))
@@ -243,12 +243,12 @@ class HostService(HostServicer):
self, request: DisconnectRequest, context: grpc.ServicerContext self, request: DisconnectRequest, context: grpc.ServicerContext
) -> empty_pb2.Empty: ) -> empty_pb2.Empty:
connection_handle = int.from_bytes(request.connection.cookie.value, 'big') connection_handle = int.from_bytes(request.connection.cookie.value, 'big')
self.log.info(f"Disconnect: {connection_handle}") self.log.debug(f"Disconnect: {connection_handle}")
self.log.info("Disconnecting...") self.log.debug("Disconnecting...")
if connection := self.device.lookup_connection(connection_handle): if connection := self.device.lookup_connection(connection_handle):
await connection.disconnect(HCI_REMOTE_USER_TERMINATED_CONNECTION_ERROR) await connection.disconnect(HCI_REMOTE_USER_TERMINATED_CONNECTION_ERROR)
self.log.info("Disconnected") self.log.debug("Disconnected")
return empty_pb2.Empty() return empty_pb2.Empty()
@@ -257,7 +257,7 @@ class HostService(HostServicer):
self, request: WaitDisconnectionRequest, context: grpc.ServicerContext self, request: WaitDisconnectionRequest, context: grpc.ServicerContext
) -> empty_pb2.Empty: ) -> empty_pb2.Empty:
connection_handle = int.from_bytes(request.connection.cookie.value, 'big') connection_handle = int.from_bytes(request.connection.cookie.value, 'big')
self.log.info(f"WaitDisconnection: {connection_handle}") self.log.debug(f"WaitDisconnection: {connection_handle}")
if connection := self.device.lookup_connection(connection_handle): if connection := self.device.lookup_connection(connection_handle):
disconnection_future: asyncio.Future[ disconnection_future: asyncio.Future[
@@ -270,7 +270,7 @@ class HostService(HostServicer):
connection.on('disconnection', on_disconnection) connection.on('disconnection', on_disconnection)
try: try:
await disconnection_future await disconnection_future
self.log.info("Disconnected") self.log.debug("Disconnected")
finally: finally:
connection.remove_listener('disconnection', on_disconnection) # type: ignore connection.remove_listener('disconnection', on_disconnection) # type: ignore
@@ -378,7 +378,7 @@ class HostService(HostServicer):
try: try:
while True: while True:
if not self.device.is_advertising: if not self.device.is_advertising:
self.log.info('Advertise') self.log.debug('Advertise')
await self.device.start_advertising( await self.device.start_advertising(
target=target, target=target,
advertising_type=advertising_type, advertising_type=advertising_type,
@@ -393,10 +393,10 @@ class HostService(HostServicer):
bumble.device.Connection bumble.device.Connection
] = asyncio.get_running_loop().create_future() ] = asyncio.get_running_loop().create_future()
self.log.info('Wait for LE connection...') self.log.debug('Wait for LE connection...')
connection = await pending_connection connection = await pending_connection
self.log.info( self.log.debug(
f"Advertise: Connected to {connection.peer_address} (handle={connection.handle})" f"Advertise: Connected to {connection.peer_address} (handle={connection.handle})"
) )
@@ -410,7 +410,7 @@ class HostService(HostServicer):
self.device.remove_listener('connection', on_connection) # type: ignore self.device.remove_listener('connection', on_connection) # type: ignore
try: try:
self.log.info('Stop advertising') self.log.debug('Stop advertising')
await self.device.abort_on('flush', self.device.stop_advertising()) await self.device.abort_on('flush', self.device.stop_advertising())
except: except:
pass pass
@@ -423,7 +423,7 @@ class HostService(HostServicer):
if request.phys: if request.phys:
raise NotImplementedError("TODO: add support for `request.phys`") raise NotImplementedError("TODO: add support for `request.phys`")
self.log.info('Scan') self.log.debug('Scan')
scan_queue: asyncio.Queue[Advertisement] = asyncio.Queue() scan_queue: asyncio.Queue[Advertisement] = asyncio.Queue()
handler = self.device.on('advertisement', scan_queue.put_nowait) handler = self.device.on('advertisement', scan_queue.put_nowait)
@@ -470,7 +470,7 @@ class HostService(HostServicer):
finally: finally:
self.device.remove_listener('advertisement', handler) # type: ignore self.device.remove_listener('advertisement', handler) # type: ignore
try: try:
self.log.info('Stop scanning') self.log.debug('Stop scanning')
await self.device.abort_on('flush', self.device.stop_scanning()) await self.device.abort_on('flush', self.device.stop_scanning())
except: except:
pass pass
@@ -479,7 +479,7 @@ class HostService(HostServicer):
async def Inquiry( async def Inquiry(
self, request: empty_pb2.Empty, context: grpc.ServicerContext self, request: empty_pb2.Empty, context: grpc.ServicerContext
) -> AsyncGenerator[InquiryResponse, None]: ) -> AsyncGenerator[InquiryResponse, None]:
self.log.info('Inquiry') self.log.debug('Inquiry')
inquiry_queue: asyncio.Queue[ inquiry_queue: asyncio.Queue[
Optional[Tuple[Address, int, AdvertisingData, int]] Optional[Tuple[Address, int, AdvertisingData, int]]
@@ -510,7 +510,7 @@ class HostService(HostServicer):
self.device.remove_listener('inquiry_complete', complete_handler) # type: ignore self.device.remove_listener('inquiry_complete', complete_handler) # type: ignore
self.device.remove_listener('inquiry_result', result_handler) # type: ignore self.device.remove_listener('inquiry_result', result_handler) # type: ignore
try: try:
self.log.info('Stop inquiry') self.log.debug('Stop inquiry')
await self.device.abort_on('flush', self.device.stop_discovery()) await self.device.abort_on('flush', self.device.stop_discovery())
except: except:
pass pass
@@ -519,7 +519,7 @@ class HostService(HostServicer):
async def SetDiscoverabilityMode( async def SetDiscoverabilityMode(
self, request: SetDiscoverabilityModeRequest, context: grpc.ServicerContext self, request: SetDiscoverabilityModeRequest, context: grpc.ServicerContext
) -> empty_pb2.Empty: ) -> empty_pb2.Empty:
self.log.info("SetDiscoverabilityMode") self.log.debug("SetDiscoverabilityMode")
await self.device.set_discoverable(request.mode != NOT_DISCOVERABLE) await self.device.set_discoverable(request.mode != NOT_DISCOVERABLE)
return empty_pb2.Empty() return empty_pb2.Empty()
@@ -527,7 +527,7 @@ class HostService(HostServicer):
async def SetConnectabilityMode( async def SetConnectabilityMode(
self, request: SetConnectabilityModeRequest, context: grpc.ServicerContext self, request: SetConnectabilityModeRequest, context: grpc.ServicerContext
) -> empty_pb2.Empty: ) -> empty_pb2.Empty:
self.log.info("SetConnectabilityMode") self.log.debug("SetConnectabilityMode")
await self.device.set_connectable(request.mode != NOT_CONNECTABLE) await self.device.set_connectable(request.mode != NOT_CONNECTABLE)
return empty_pb2.Empty() return empty_pb2.Empty()

View File

@@ -99,7 +99,7 @@ class PairingDelegate(BasePairingDelegate):
return ev return ev
async def confirm(self, auto: bool = False) -> bool: async def confirm(self, auto: bool = False) -> bool:
self.log.info( self.log.debug(
f"Pairing event: `just_works` (io_capability: {self.io_capability})" f"Pairing event: `just_works` (io_capability: {self.io_capability})"
) )
@@ -114,7 +114,7 @@ class PairingDelegate(BasePairingDelegate):
return answer.confirm return answer.confirm
async def compare_numbers(self, number: int, digits: int = 6) -> bool: async def compare_numbers(self, number: int, digits: int = 6) -> bool:
self.log.info( self.log.debug(
f"Pairing event: `numeric_comparison` (io_capability: {self.io_capability})" f"Pairing event: `numeric_comparison` (io_capability: {self.io_capability})"
) )
@@ -129,7 +129,7 @@ class PairingDelegate(BasePairingDelegate):
return answer.confirm return answer.confirm
async def get_number(self) -> Optional[int]: async def get_number(self) -> Optional[int]:
self.log.info( self.log.debug(
f"Pairing event: `passkey_entry_request` (io_capability: {self.io_capability})" f"Pairing event: `passkey_entry_request` (io_capability: {self.io_capability})"
) )
@@ -146,7 +146,7 @@ class PairingDelegate(BasePairingDelegate):
return answer.passkey return answer.passkey
async def get_string(self, max_length: int) -> Optional[str]: async def get_string(self, max_length: int) -> Optional[str]:
self.log.info( self.log.debug(
f"Pairing event: `pin_code_request` (io_capability: {self.io_capability})" f"Pairing event: `pin_code_request` (io_capability: {self.io_capability})"
) )
@@ -177,7 +177,7 @@ class PairingDelegate(BasePairingDelegate):
): ):
return return
self.log.info( self.log.debug(
f"Pairing event: `passkey_entry_notification` (io_capability: {self.io_capability})" f"Pairing event: `passkey_entry_notification` (io_capability: {self.io_capability})"
) )
@@ -247,7 +247,7 @@ class SecurityService(SecurityServicer):
async def OnPairing( async def OnPairing(
self, request: AsyncIterator[PairingEventAnswer], context: grpc.ServicerContext self, request: AsyncIterator[PairingEventAnswer], context: grpc.ServicerContext
) -> AsyncGenerator[PairingEvent, None]: ) -> AsyncGenerator[PairingEvent, None]:
self.log.info('OnPairing') self.log.debug('OnPairing')
if self.event_queue is not None: if self.event_queue is not None:
raise RuntimeError('already streaming pairing events') raise RuntimeError('already streaming pairing events')
@@ -273,7 +273,7 @@ class SecurityService(SecurityServicer):
self, request: SecureRequest, context: grpc.ServicerContext self, request: SecureRequest, context: grpc.ServicerContext
) -> SecureResponse: ) -> SecureResponse:
connection_handle = int.from_bytes(request.connection.cookie.value, 'big') connection_handle = int.from_bytes(request.connection.cookie.value, 'big')
self.log.info(f"Secure: {connection_handle}") self.log.debug(f"Secure: {connection_handle}")
connection = self.device.lookup_connection(connection_handle) connection = self.device.lookup_connection(connection_handle)
assert connection assert connection
@@ -291,7 +291,7 @@ class SecurityService(SecurityServicer):
# trigger pairing if needed # trigger pairing if needed
if self.need_pairing(connection, level): if self.need_pairing(connection, level):
try: try:
self.log.info('Pair...') self.log.debug('Pair...')
if ( if (
connection.transport == BT_LE_TRANSPORT connection.transport == BT_LE_TRANSPORT
@@ -309,7 +309,7 @@ class SecurityService(SecurityServicer):
else: else:
await connection.pair() await connection.pair()
self.log.info('Paired') self.log.debug('Paired')
except asyncio.CancelledError: except asyncio.CancelledError:
self.log.warning("Connection died during encryption") self.log.warning("Connection died during encryption")
return SecureResponse(connection_died=empty_pb2.Empty()) return SecureResponse(connection_died=empty_pb2.Empty())
@@ -320,9 +320,9 @@ class SecurityService(SecurityServicer):
# trigger authentication if needed # trigger authentication if needed
if self.need_authentication(connection, level): if self.need_authentication(connection, level):
try: try:
self.log.info('Authenticate...') self.log.debug('Authenticate...')
await connection.authenticate() await connection.authenticate()
self.log.info('Authenticated') self.log.debug('Authenticated')
except asyncio.CancelledError: except asyncio.CancelledError:
self.log.warning("Connection died during authentication") self.log.warning("Connection died during authentication")
return SecureResponse(connection_died=empty_pb2.Empty()) return SecureResponse(connection_died=empty_pb2.Empty())
@@ -333,9 +333,9 @@ class SecurityService(SecurityServicer):
# trigger encryption if needed # trigger encryption if needed
if self.need_encryption(connection, level): if self.need_encryption(connection, level):
try: try:
self.log.info('Encrypt...') self.log.debug('Encrypt...')
await connection.encrypt() await connection.encrypt()
self.log.info('Encrypted') self.log.debug('Encrypted')
except asyncio.CancelledError: except asyncio.CancelledError:
self.log.warning("Connection died during encryption") self.log.warning("Connection died during encryption")
return SecureResponse(connection_died=empty_pb2.Empty()) return SecureResponse(connection_died=empty_pb2.Empty())
@@ -353,7 +353,7 @@ class SecurityService(SecurityServicer):
self, request: WaitSecurityRequest, context: grpc.ServicerContext self, request: WaitSecurityRequest, context: grpc.ServicerContext
) -> WaitSecurityResponse: ) -> WaitSecurityResponse:
connection_handle = int.from_bytes(request.connection.cookie.value, 'big') connection_handle = int.from_bytes(request.connection.cookie.value, 'big')
self.log.info(f"WaitSecurity: {connection_handle}") self.log.debug(f"WaitSecurity: {connection_handle}")
connection = self.device.lookup_connection(connection_handle) connection = self.device.lookup_connection(connection_handle)
assert connection assert connection
@@ -390,7 +390,7 @@ class SecurityService(SecurityServicer):
def set_failure(name: str) -> Callable[..., None]: def set_failure(name: str) -> Callable[..., None]:
def wrapper(*args: Any) -> None: def wrapper(*args: Any) -> None:
self.log.info(f'Wait for security: error `{name}`: {args}') self.log.debug(f'Wait for security: error `{name}`: {args}')
wait_for_security.set_result(name) wait_for_security.set_result(name)
return wrapper return wrapper
@@ -398,13 +398,13 @@ class SecurityService(SecurityServicer):
def try_set_success(*_: Any) -> None: def try_set_success(*_: Any) -> None:
assert connection assert connection
if self.reached_security_level(connection, level): if self.reached_security_level(connection, level):
self.log.info('Wait for security: done') self.log.debug('Wait for security: done')
wait_for_security.set_result('success') wait_for_security.set_result('success')
def on_encryption_change(*_: Any) -> None: def on_encryption_change(*_: Any) -> None:
assert connection assert connection
if self.reached_security_level(connection, level): if self.reached_security_level(connection, level):
self.log.info('Wait for security: done') self.log.debug('Wait for security: done')
wait_for_security.set_result('success') wait_for_security.set_result('success')
elif ( elif (
connection.transport == BT_BR_EDR_TRANSPORT connection.transport == BT_BR_EDR_TRANSPORT
@@ -432,7 +432,7 @@ class SecurityService(SecurityServicer):
if self.reached_security_level(connection, level): if self.reached_security_level(connection, level):
return WaitSecurityResponse(success=empty_pb2.Empty()) return WaitSecurityResponse(success=empty_pb2.Empty())
self.log.info('Wait for security...') self.log.debug('Wait for security...')
kwargs = {} kwargs = {}
kwargs[await wait_for_security] = empty_pb2.Empty() kwargs[await wait_for_security] = empty_pb2.Empty()
@@ -442,12 +442,12 @@ class SecurityService(SecurityServicer):
# wait for `authenticate` to finish if any # wait for `authenticate` to finish if any
if authenticate_task is not None: if authenticate_task is not None:
self.log.info('Wait for authentication...') self.log.debug('Wait for authentication...')
try: try:
await authenticate_task # type: ignore await authenticate_task # type: ignore
except: except:
pass pass
self.log.info('Authenticated') self.log.debug('Authenticated')
return WaitSecurityResponse(**kwargs) return WaitSecurityResponse(**kwargs)
@@ -503,7 +503,7 @@ class SecurityStorageService(SecurityStorageServicer):
self, request: IsBondedRequest, context: grpc.ServicerContext self, request: IsBondedRequest, context: grpc.ServicerContext
) -> wrappers_pb2.BoolValue: ) -> wrappers_pb2.BoolValue:
address = utils.address_from_request(request, request.WhichOneof("address")) address = utils.address_from_request(request, request.WhichOneof("address"))
self.log.info(f"IsBonded: {address}") self.log.debug(f"IsBonded: {address}")
if self.device.keystore is not None: if self.device.keystore is not None:
is_bonded = await self.device.keystore.get(str(address)) is not None is_bonded = await self.device.keystore.get(str(address)) is not None
@@ -517,7 +517,7 @@ class SecurityStorageService(SecurityStorageServicer):
self, request: DeleteBondRequest, context: grpc.ServicerContext self, request: DeleteBondRequest, context: grpc.ServicerContext
) -> empty_pb2.Empty: ) -> empty_pb2.Empty:
address = utils.address_from_request(request, request.WhichOneof("address")) address = utils.address_from_request(request, request.WhichOneof("address"))
self.log.info(f"DeleteBond: {address}") self.log.debug(f"DeleteBond: {address}")
if self.device.keystore is not None: if self.device.keystore is not None:
with suppress(KeyError): with suppress(KeyError):