Skip to content

Commit

Permalink
pygossmap: rename GossipStoreHeader to GossipStoreMsgHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock committed Mar 24, 2023
1 parent aa0dcc5 commit 710a15c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions contrib/pyln-client/pyln/client/gossmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _parse_features(featurebytes):
return result


class GossipStoreHeader(object):
class GossipStoreMsgHeader(object):
def __init__(self, buf: bytes, off: int):
self.flags, self.length, self.crc, self.timestamp = struct.unpack('>HHII', buf)
self.off = off
Expand All @@ -97,14 +97,14 @@ def __init__(self, buf: bytes, off: int):
class GossmapHalfchannel(object):
"""One direction of a GossmapChannel."""
def __init__(self, channel: 'GossmapChannel', direction: int,
fields: Dict[str, Any], hdr: GossipStoreHeader):
fields: Dict[str, Any], hdr: GossipStoreMsgHeader):
assert direction in [0, 1], "direction can only be 0 or 1"
self.channel = channel
self.direction = direction
self.source = channel.node1 if direction == 0 else channel.node2
self.destination = channel.node2 if direction == 0 else channel.node1
self.fields: Dict[str, Any] = fields
self.hdr: GossipStoreHeader = hdr
self.hdr: GossipStoreMsgHeader = hdr

self.timestamp: int = fields['timestamp']
self.cltv_expiry_delta: int = fields['cltv_expiry_delta']
Expand Down Expand Up @@ -185,9 +185,9 @@ def __init__(self,
node1: 'GossmapNode',
node2: 'GossmapNode',
is_private: bool,
hdr: GossipStoreHeader):
hdr: GossipStoreMsgHeader):
self.fields: Dict[str, Any] = fields
self.hdr: GossipStoreHeader = hdr
self.hdr: GossipStoreMsgHeader = hdr

self.is_private = is_private
self.scid = ShortChannelId.from_str(scid) if isinstance(scid, str) else scid
Expand All @@ -200,7 +200,7 @@ def __init__(self,
def _update_channel(self,
direction: int,
fields: Dict[str, Any],
hdr: GossipStoreHeader):
hdr: GossipStoreMsgHeader):

half = GossmapHalfchannel(self, direction, fields, hdr)
self.half_channels[direction] = half
Expand Down Expand Up @@ -246,7 +246,7 @@ def __init__(self, node_id: Union[GossmapNodeId, bytes, str]):
if isinstance(node_id, bytes) or isinstance(node_id, str):
node_id = GossmapNodeId(node_id)
self.fields: Optional[Dict[str, Any]] = None
self.hdr: GossipStoreHeader = None
self.hdr: GossipStoreMsgHeader = None
self.channels: List[GossmapChannel] = []
self.node_id = node_id
self.announced = False
Expand Down Expand Up @@ -388,7 +388,7 @@ def _new_channel(self,
node1: GossmapNode,
node2: GossmapNode,
is_private: bool,
hdr: GossipStoreHeader):
hdr: GossipStoreMsgHeader):
c = GossmapChannel(fields, scid, node1, node2, is_private, hdr)
self._last_scid = scid
self.channels[scid] = c
Expand All @@ -406,7 +406,7 @@ def _del_channel(self, scid: ShortChannelId):
if len(c.node2.channels) == 0:
del self.nodes[c.node2.node_id]

def _add_channel(self, rec: bytes, is_private: bool, hdr: GossipStoreHeader):
def _add_channel(self, rec: bytes, is_private: bool, hdr: GossipStoreMsgHeader):
fields = channel_announcement.read(io.BytesIO(rec[2:]), {})
# Add nodes one the fly
node1_id = GossmapNodeId(fields['node_id_1'])
Expand Down Expand Up @@ -533,7 +533,7 @@ def get_neighbors(self,
inner = shell
return result

def _update_channel(self, rec: bytes, hdr: GossipStoreHeader):
def _update_channel(self, rec: bytes, hdr: GossipStoreMsgHeader):
fields = channel_update.read(io.BytesIO(rec[2:]), {})
direction = fields['channel_flags'] & 1
scid = ShortChannelId.from_int(fields['short_channel_id'])
Expand All @@ -543,7 +543,7 @@ def _update_channel(self, rec: bytes, hdr: GossipStoreHeader):
else:
self.orphan_channel_updates.add(scid)

def _add_node_announcement(self, rec: bytes, hdr: GossipStoreHeader):
def _add_node_announcement(self, rec: bytes, hdr: GossipStoreMsgHeader):
fields = node_announcement.read(io.BytesIO(rec[2:]), {})
node_id = GossmapNodeId(fields['node_id'])
if node_id not in self.nodes:
Expand Down Expand Up @@ -583,7 +583,7 @@ def _read_record(self) -> Optional[bytes]:
off = self.bytes_read + 1
if not self._pull_bytes(12):
return None, None
hdr = GossipStoreHeader(self.store_buf[:12], off)
hdr = GossipStoreMsgHeader(self.store_buf[:12], off)
if not self._pull_bytes(12 + hdr.length):
return None, hdr
rec = self.store_buf[12:]
Expand Down

0 comments on commit 710a15c

Please sign in to comment.