← back to Exo
Fix IPv4 serialisation for topology
176d077c877c8a9f6a2740f6603861b85b364aa9 · 2025-07-28 13:07:10 +0100 · Seth Howes
Files touched
M shared/topology.pyM shared/types/multiaddr.pyM shared/types/topology.py
Diff
commit 176d077c877c8a9f6a2740f6603861b85b364aa9
Author: Seth Howes <71157822+sethhowes@users.noreply.github.com>
Date: Mon Jul 28 13:07:10 2025 +0100
Fix IPv4 serialisation for topology
---
shared/topology.py | 10 ----------
shared/types/multiaddr.py | 7 ++++++-
shared/types/topology.py | 4 ++--
3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/shared/topology.py b/shared/topology.py
index cdbc6622..0f75a214 100644
--- a/shared/topology.py
+++ b/shared/topology.py
@@ -11,8 +11,6 @@ from shared.types.topology import Connection, Node, TopologyProto
class TopologySnapshot(BaseModel):
- """Immutable serialisable representation of a :class:`Topology`."""
-
nodes: list[Node]
connections: list[Connection]
master_node_id: NodeId | None = None
@@ -29,8 +27,6 @@ class Topology(TopologyProto):
self.master_node_id: NodeId | None = None
def to_snapshot(self) -> TopologySnapshot:
- """Return an immutable snapshot suitable for JSON serialisation."""
-
return TopologySnapshot(
nodes=list(self.list_nodes()),
connections=list(self.list_connections()),
@@ -39,12 +35,6 @@ class Topology(TopologyProto):
@classmethod
def from_snapshot(cls, snapshot: TopologySnapshot) -> "Topology":
- """Reconstruct a :class:`Topology` from *snapshot*.
-
- The reconstructed topology is equivalent (w.r.t. nodes, connections
- and ``master_node_id``) to the original one that produced *snapshot*.
- """
-
topology = cls()
topology.master_node_id = snapshot.master_node_id
diff --git a/shared/types/multiaddr.py b/shared/types/multiaddr.py
index 53c0a22f..db16c933 100644
--- a/shared/types/multiaddr.py
+++ b/shared/types/multiaddr.py
@@ -2,7 +2,7 @@ import re
from ipaddress import IPv4Address
from typing import ClassVar
-from pydantic import BaseModel, computed_field, field_validator
+from pydantic import BaseModel, computed_field, field_serializer, field_validator
class Multiaddr(BaseModel):
@@ -31,6 +31,11 @@ class Multiaddr(BaseModel):
if not match:
raise ValueError(f"Invalid multiaddr format: {self.address}. Expected format like /ip4/127.0.0.1/tcp/4001")
return IPv4Address(match.group(1))
+
+ @field_serializer("ipv4_address")
+ def serialize_ipv4_address(self, value: IPv4Address) -> str:
+ return str(value)
+
@computed_field
@property
diff --git a/shared/types/topology.py b/shared/types/topology.py
index 2a5609fd..029db17f 100644
--- a/shared/types/topology.py
+++ b/shared/types/topology.py
@@ -33,8 +33,8 @@ class Connection(BaseModel):
return (
self.local_node_id == other.local_node_id
and self.send_back_node_id == other.send_back_node_id
- and self.local_multiaddr == other.local_multiaddr
- and self.send_back_multiaddr == other.send_back_multiaddr
+ and self.local_multiaddr.address == other.local_multiaddr.address
+ and self.send_back_multiaddr.address == other.send_back_multiaddr.address
)
← c3c8ddbc fix forwarder supervisor tests
·
back to Exo
·
some finishing touches to get this working e2e 20241e32 →