onion_messages: fix code indentation
This commit is contained in:
committed by
Sander van Grieken
parent
7109c22317
commit
a157108e75
@@ -1516,10 +1516,11 @@ class Commands(Logger):
|
|||||||
blinded_path = create_blinded_path(session_key, path=path, final_recipient_data={}, dummy_hops=dummy_hops)
|
blinded_path = create_blinded_path(session_key, path=path, final_recipient_data={}, dummy_hops=dummy_hops)
|
||||||
|
|
||||||
with io.BytesIO() as blinded_path_fd:
|
with io.BytesIO() as blinded_path_fd:
|
||||||
OnionWireSerializer._write_complex_field(fd=blinded_path_fd,
|
OnionWireSerializer._write_complex_field(
|
||||||
field_type='blinded_path',
|
fd=blinded_path_fd,
|
||||||
count=1,
|
field_type='blinded_path',
|
||||||
value=blinded_path)
|
count=1,
|
||||||
|
value=blinded_path)
|
||||||
encoded_blinded_path = blinded_path_fd.getvalue()
|
encoded_blinded_path = blinded_path_fd.getvalue()
|
||||||
|
|
||||||
return encoded_blinded_path.hex()
|
return encoded_blinded_path.hex()
|
||||||
|
|||||||
@@ -420,23 +420,26 @@ class LNSerializer:
|
|||||||
subtype_field_type = row[3]
|
subtype_field_type = row[3]
|
||||||
subtype_field_count_str = row[4]
|
subtype_field_count_str = row[4]
|
||||||
|
|
||||||
subtype_field_count = _resolve_field_count(subtype_field_count_str,
|
subtype_field_count = _resolve_field_count(
|
||||||
vars_dict=record,
|
subtype_field_count_str,
|
||||||
allow_any=True)
|
vars_dict=record,
|
||||||
|
allow_any=True)
|
||||||
|
|
||||||
if subtype_field_name not in record:
|
if subtype_field_name not in record:
|
||||||
raise Exception(f'complex field type {field_type} missing element {subtype_field_name}')
|
raise Exception(f'complex field type {field_type} missing element {subtype_field_name}')
|
||||||
|
|
||||||
if subtype_field_type in self.subtypes:
|
if subtype_field_type in self.subtypes:
|
||||||
self._write_complex_field(fd=fd,
|
self._write_complex_field(
|
||||||
field_type=subtype_field_type,
|
fd=fd,
|
||||||
count=subtype_field_count,
|
field_type=subtype_field_type,
|
||||||
value=record[subtype_field_name])
|
count=subtype_field_count,
|
||||||
|
value=record[subtype_field_name])
|
||||||
else:
|
else:
|
||||||
_write_field(fd=fd,
|
_write_field(
|
||||||
field_type=subtype_field_type,
|
fd=fd,
|
||||||
count=subtype_field_count,
|
field_type=subtype_field_type,
|
||||||
value=record[subtype_field_name])
|
count=subtype_field_count,
|
||||||
|
value=record[subtype_field_name])
|
||||||
|
|
||||||
def _read_complex_field(self, *, fd: io.BytesIO, field_type: str, count: Union[int, str])\
|
def _read_complex_field(self, *, fd: io.BytesIO, field_type: str, count: Union[int, str])\
|
||||||
-> Union[bytes, List[Dict[str, Any]], Dict[str, Any]]:
|
-> Union[bytes, List[Dict[str, Any]], Dict[str, Any]]:
|
||||||
@@ -460,18 +463,21 @@ class LNSerializer:
|
|||||||
subtype_field_type = row[3]
|
subtype_field_type = row[3]
|
||||||
subtype_field_count_str = row[4]
|
subtype_field_count_str = row[4]
|
||||||
|
|
||||||
subtype_field_count = _resolve_field_count(subtype_field_count_str,
|
subtype_field_count = _resolve_field_count(
|
||||||
vars_dict=parsed,
|
subtype_field_count_str,
|
||||||
allow_any=True)
|
vars_dict=parsed,
|
||||||
|
allow_any=True)
|
||||||
|
|
||||||
if subtype_field_type in self.subtypes:
|
if subtype_field_type in self.subtypes:
|
||||||
parsed[subtype_field_name] = self._read_complex_field(fd=fd,
|
parsed[subtype_field_name] = self._read_complex_field(
|
||||||
field_type=subtype_field_type,
|
fd=fd,
|
||||||
count=subtype_field_count)
|
field_type=subtype_field_type,
|
||||||
|
count=subtype_field_count)
|
||||||
else:
|
else:
|
||||||
parsed[subtype_field_name] = _read_field(fd=fd,
|
parsed[subtype_field_name] = _read_field(
|
||||||
field_type=subtype_field_type,
|
fd=fd,
|
||||||
count=subtype_field_count)
|
field_type=subtype_field_type,
|
||||||
|
count=subtype_field_count)
|
||||||
parsedlist.append(parsed)
|
parsedlist.append(parsed)
|
||||||
|
|
||||||
return parsedlist if count == '...' or count > 1 else parsedlist[0]
|
return parsedlist if count == '...' or count > 1 else parsedlist[0]
|
||||||
@@ -498,15 +504,17 @@ class LNSerializer:
|
|||||||
allow_any=True)
|
allow_any=True)
|
||||||
field_value = kwargs[tlv_record_name][field_name]
|
field_value = kwargs[tlv_record_name][field_name]
|
||||||
if field_type in self.subtypes:
|
if field_type in self.subtypes:
|
||||||
self._write_complex_field(fd=tlv_record_fd,
|
self._write_complex_field(
|
||||||
field_type=field_type,
|
fd=tlv_record_fd,
|
||||||
count=field_count,
|
field_type=field_type,
|
||||||
value=field_value)
|
count=field_count,
|
||||||
|
value=field_value)
|
||||||
else:
|
else:
|
||||||
_write_field(fd=tlv_record_fd,
|
_write_field(
|
||||||
field_type=field_type,
|
fd=tlv_record_fd,
|
||||||
count=field_count,
|
field_type=field_type,
|
||||||
value=field_value)
|
count=field_count,
|
||||||
|
value=field_value)
|
||||||
else:
|
else:
|
||||||
raise Exception(f"unexpected row in scheme: {row!r}")
|
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())
|
_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_name = row[3]
|
||||||
field_type = row[4]
|
field_type = row[4]
|
||||||
field_count_str = row[5]
|
field_count_str = row[5]
|
||||||
field_count = _resolve_field_count(field_count_str,
|
field_count = _resolve_field_count(
|
||||||
vars_dict=parsed[tlv_record_name],
|
field_count_str,
|
||||||
allow_any=True)
|
vars_dict=parsed[tlv_record_name],
|
||||||
|
allow_any=True)
|
||||||
#print(f">> count={field_count}. parsed={parsed}")
|
#print(f">> count={field_count}. parsed={parsed}")
|
||||||
if field_type in self.subtypes:
|
if field_type in self.subtypes:
|
||||||
parsed[tlv_record_name][field_name] = self._read_complex_field(fd=tlv_record_fd,
|
parsed[tlv_record_name][field_name] = self._read_complex_field(
|
||||||
field_type=field_type,
|
fd=tlv_record_fd,
|
||||||
count=field_count)
|
field_type=field_type,
|
||||||
|
count=field_count)
|
||||||
else:
|
else:
|
||||||
parsed[tlv_record_name][field_name] = _read_field(fd=tlv_record_fd,
|
parsed[tlv_record_name][field_name] = _read_field(
|
||||||
field_type=field_type,
|
fd=tlv_record_fd,
|
||||||
count=field_count)
|
field_type=field_type,
|
||||||
|
count=field_count)
|
||||||
else:
|
else:
|
||||||
raise Exception(f"unexpected row in scheme: {row!r}")
|
raise Exception(f"unexpected row in scheme: {row!r}")
|
||||||
if _num_remaining_bytes_to_read(tlv_record_fd) > 0:
|
if _num_remaining_bytes_to_read(tlv_record_fd) > 0:
|
||||||
|
|||||||
@@ -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, add next_blinding_override
|
||||||
final_hop_pre_ip = OnionHopsDataSingle(
|
final_hop_pre_ip = OnionHopsDataSingle(
|
||||||
tlv_stream_name='onionmsg_tlv',
|
tlv_stream_name='onionmsg_tlv',
|
||||||
blind_fields={'next_node_id': {'node_id': introduction_point},
|
blind_fields={
|
||||||
'next_blinding_override': {'blinding': blinded_path['blinding']},
|
'next_node_id': {'node_id': introduction_point},
|
||||||
}
|
'next_blinding_override': {'blinding': blinded_path['blinding']},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
hops_data.append(final_hop_pre_ip)
|
hops_data.append(final_hop_pre_ip)
|
||||||
|
|
||||||
# encrypt encrypted_data_tlv here
|
# encrypt encrypted_data_tlv here
|
||||||
for i in range(len(hops_data)):
|
for i in range(len(hops_data)):
|
||||||
encrypted_recipient_data = encrypt_onionmsg_data_tlv(shared_secret=hop_shared_secrets[i],
|
encrypted_recipient_data = encrypt_onionmsg_data_tlv(
|
||||||
**hops_data[i].blind_fields)
|
shared_secret=hop_shared_secrets[i],
|
||||||
|
**hops_data[i].blind_fields)
|
||||||
hops_data[i].payload['encrypted_recipient_data'] = {
|
hops_data[i].payload['encrypted_recipient_data'] = {
|
||||||
'encrypted_recipient_data': 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.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))
|
self.forwardqueue.put_nowait((now() + FORWARD_RETRY_DELAY, expires, onion_packet, blinding, node_id))
|
||||||
|
|
||||||
def submit_forward(self, *,
|
def submit_forward(
|
||||||
onion_packet: OnionPacket,
|
self, *,
|
||||||
blinding: bytes,
|
onion_packet: OnionPacket,
|
||||||
node_id: bytes):
|
blinding: bytes,
|
||||||
|
node_id: bytes):
|
||||||
if self.forwardqueue.qsize() >= FORWARD_MAX_QUEUE:
|
if self.forwardqueue.qsize() >= FORWARD_MAX_QUEUE:
|
||||||
self.logger.debug('forward queue full, dropping packet')
|
self.logger.debug('forward queue full, dropping packet')
|
||||||
return
|
return
|
||||||
@@ -534,10 +536,11 @@ class OnionMessageManager(Logger):
|
|||||||
requestreply['ev'].set()
|
requestreply['ev'].set()
|
||||||
del self.pending[key]
|
del self.pending[key]
|
||||||
|
|
||||||
def submit_requestreply(self, *,
|
def submit_requestreply(
|
||||||
payload: dict,
|
self, *,
|
||||||
node_id_or_blinded_path: bytes,
|
payload: dict,
|
||||||
key: bytes = None) -> 'Task':
|
node_id_or_blinded_path: bytes,
|
||||||
|
key: bytes = None) -> 'Task':
|
||||||
"""Add onion message to queue for sending. Queued onion message payloads
|
"""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
|
are supplied with a path_id and a reply_path to determine which request
|
||||||
corresponds with arriving replies.
|
corresponds with arriving replies.
|
||||||
|
|||||||
Reference in New Issue
Block a user