1
0

onion_messages: fix code indentation

This commit is contained in:
ThomasV
2025-01-22 16:43:33 +01:00
committed by Sander van Grieken
parent 7109c22317
commit a157108e75
3 changed files with 70 additions and 55 deletions

View File

@@ -1516,10 +1516,11 @@ class Commands(Logger):
blinded_path = create_blinded_path(session_key, path=path, final_recipient_data={}, dummy_hops=dummy_hops)
with io.BytesIO() as blinded_path_fd:
OnionWireSerializer._write_complex_field(fd=blinded_path_fd,
field_type='blinded_path',
count=1,
value=blinded_path)
OnionWireSerializer._write_complex_field(
fd=blinded_path_fd,
field_type='blinded_path',
count=1,
value=blinded_path)
encoded_blinded_path = blinded_path_fd.getvalue()
return encoded_blinded_path.hex()

View File

@@ -420,23 +420,26 @@ class LNSerializer:
subtype_field_type = row[3]
subtype_field_count_str = row[4]
subtype_field_count = _resolve_field_count(subtype_field_count_str,
vars_dict=record,
allow_any=True)
subtype_field_count = _resolve_field_count(
subtype_field_count_str,
vars_dict=record,
allow_any=True)
if subtype_field_name not in record:
raise Exception(f'complex field type {field_type} missing element {subtype_field_name}')
if subtype_field_type in self.subtypes:
self._write_complex_field(fd=fd,
field_type=subtype_field_type,
count=subtype_field_count,
value=record[subtype_field_name])
self._write_complex_field(
fd=fd,
field_type=subtype_field_type,
count=subtype_field_count,
value=record[subtype_field_name])
else:
_write_field(fd=fd,
field_type=subtype_field_type,
count=subtype_field_count,
value=record[subtype_field_name])
_write_field(
fd=fd,
field_type=subtype_field_type,
count=subtype_field_count,
value=record[subtype_field_name])
def _read_complex_field(self, *, fd: io.BytesIO, field_type: str, count: Union[int, str])\
-> Union[bytes, List[Dict[str, Any]], Dict[str, Any]]:
@@ -460,18 +463,21 @@ class LNSerializer:
subtype_field_type = row[3]
subtype_field_count_str = row[4]
subtype_field_count = _resolve_field_count(subtype_field_count_str,
vars_dict=parsed,
allow_any=True)
subtype_field_count = _resolve_field_count(
subtype_field_count_str,
vars_dict=parsed,
allow_any=True)
if subtype_field_type in self.subtypes:
parsed[subtype_field_name] = self._read_complex_field(fd=fd,
field_type=subtype_field_type,
count=subtype_field_count)
parsed[subtype_field_name] = self._read_complex_field(
fd=fd,
field_type=subtype_field_type,
count=subtype_field_count)
else:
parsed[subtype_field_name] = _read_field(fd=fd,
field_type=subtype_field_type,
count=subtype_field_count)
parsed[subtype_field_name] = _read_field(
fd=fd,
field_type=subtype_field_type,
count=subtype_field_count)
parsedlist.append(parsed)
return parsedlist if count == '...' or count > 1 else parsedlist[0]
@@ -498,15 +504,17 @@ class LNSerializer:
allow_any=True)
field_value = kwargs[tlv_record_name][field_name]
if field_type in self.subtypes:
self._write_complex_field(fd=tlv_record_fd,
field_type=field_type,
count=field_count,
value=field_value)
self._write_complex_field(
fd=tlv_record_fd,
field_type=field_type,
count=field_count,
value=field_value)
else:
_write_field(fd=tlv_record_fd,
field_type=field_type,
count=field_count,
value=field_value)
_write_field(
fd=tlv_record_fd,
field_type=field_type,
count=field_count,
value=field_value)
else:
raise Exception(f"unexpected row in scheme: {row!r}")
_write_tlv_record(fd=fd, tlv_type=tlv_record_type, tlv_val=tlv_record_fd.getvalue())
@@ -544,18 +552,21 @@ class LNSerializer:
field_name = row[3]
field_type = row[4]
field_count_str = row[5]
field_count = _resolve_field_count(field_count_str,
vars_dict=parsed[tlv_record_name],
allow_any=True)
field_count = _resolve_field_count(
field_count_str,
vars_dict=parsed[tlv_record_name],
allow_any=True)
#print(f">> count={field_count}. parsed={parsed}")
if field_type in self.subtypes:
parsed[tlv_record_name][field_name] = self._read_complex_field(fd=tlv_record_fd,
field_type=field_type,
count=field_count)
parsed[tlv_record_name][field_name] = self._read_complex_field(
fd=tlv_record_fd,
field_type=field_type,
count=field_count)
else:
parsed[tlv_record_name][field_name] = _read_field(fd=tlv_record_fd,
field_type=field_type,
count=field_count)
parsed[tlv_record_name][field_name] = _read_field(
fd=tlv_record_fd,
field_type=field_type,
count=field_count)
else:
raise Exception(f"unexpected row in scheme: {row!r}")
if _num_remaining_bytes_to_read(tlv_record_fd) > 0:

View File

@@ -264,17 +264,18 @@ def send_onion_message_to(lnwallet: 'LNWallet', node_id_or_blinded_path: bytes,
# final hop pre-ip, add next_blinding_override
final_hop_pre_ip = OnionHopsDataSingle(
tlv_stream_name='onionmsg_tlv',
blind_fields={'next_node_id': {'node_id': introduction_point},
'next_blinding_override': {'blinding': blinded_path['blinding']},
}
blind_fields={
'next_node_id': {'node_id': introduction_point},
'next_blinding_override': {'blinding': blinded_path['blinding']},
}
)
hops_data.append(final_hop_pre_ip)
# encrypt encrypted_data_tlv here
for i in range(len(hops_data)):
encrypted_recipient_data = encrypt_onionmsg_data_tlv(shared_secret=hop_shared_secrets[i],
**hops_data[i].blind_fields)
encrypted_recipient_data = encrypt_onionmsg_data_tlv(
shared_secret=hop_shared_secrets[i],
**hops_data[i].blind_fields)
hops_data[i].payload['encrypted_recipient_data'] = {
'encrypted_recipient_data': encrypted_recipient_data
}
@@ -457,10 +458,11 @@ class OnionMessageManager(Logger):
self.logger.debug(f'error while sending {node_id=} e={e!r}')
self.forwardqueue.put_nowait((now() + FORWARD_RETRY_DELAY, expires, onion_packet, blinding, node_id))
def submit_forward(self, *,
onion_packet: OnionPacket,
blinding: bytes,
node_id: bytes):
def submit_forward(
self, *,
onion_packet: OnionPacket,
blinding: bytes,
node_id: bytes):
if self.forwardqueue.qsize() >= FORWARD_MAX_QUEUE:
self.logger.debug('forward queue full, dropping packet')
return
@@ -534,10 +536,11 @@ class OnionMessageManager(Logger):
requestreply['ev'].set()
del self.pending[key]
def submit_requestreply(self, *,
payload: dict,
node_id_or_blinded_path: bytes,
key: bytes = None) -> 'Task':
def submit_requestreply(
self, *,
payload: dict,
node_id_or_blinded_path: bytes,
key: bytes = None) -> 'Task':
"""Add onion message to queue for sending. Queued onion message payloads
are supplied with a path_id and a reply_path to determine which request
corresponds with arriving replies.