add reissuing mechanism of records if addrs dont change as done in #815

This commit is contained in:
lla-dane
2025-08-14 11:26:14 +05:30
parent 56526b4870
commit d4c387f923
4 changed files with 70 additions and 84 deletions

View File

@ -50,14 +50,13 @@ from libp2p.network.stream.exceptions import (
StreamEOF,
StreamReset,
)
from libp2p.peer.envelope import consume_envelope
from libp2p.peer.id import (
ID,
)
from libp2p.peer.peerdata import (
PeerDataError,
)
from libp2p.peer.peerstore import create_signed_peer_record
from libp2p.pubsub.utils import env_to_send_in_RPC, maybe_consume_signed_record
from libp2p.tools.async_service import (
Service,
)
@ -250,12 +249,8 @@ class Pubsub(Service, IPubsub):
[rpc_pb2.RPC.SubOpts(subscribe=True, topicid=topic_id)]
)
# Add the sender's signedRecord in the RPC message
envelope = create_signed_peer_record(
self.host.get_id(),
self.host.get_addrs(),
self.host.get_private_key(),
)
packet.senderRecord = envelope.marshal_envelope()
envelope_bytes, bool = env_to_send_in_RPC(self.host)
packet.senderRecord = envelope_bytes
return packet
@ -275,24 +270,7 @@ class Pubsub(Service, IPubsub):
rpc_incoming.ParseFromString(incoming)
# Process the sender's signed-record if sent
if rpc_incoming.HasField("senderRecord"):
try:
# Convert the signed-peer-record(Envelope) from
# protobuf bytes
envelope, _ = consume_envelope(
rpc_incoming.senderRecord, "libp2p-peer-record"
)
# Use the default TTL of 2 hours (7200 seconds)
if self.host.get_peerstore().consume_peer_record(
envelope, 7200
):
logger.error(
"Updating the Certified-Addr-Book was unsuccessful"
)
except Exception as e:
logger.error(
"Error updating the certified addr book for peer: %s", e
)
_ = maybe_consume_signed_record(rpc_incoming, self.host)
if rpc_incoming.publish:
# deal with RPC.publish
@ -604,13 +582,8 @@ class Pubsub(Service, IPubsub):
)
# Add the senderRecord of the peer in the RPC msg
envelope = create_signed_peer_record(
self.host.get_id(),
self.host.get_addrs(),
self.host.get_private_key(),
)
packet.senderRecord = envelope.marshal_envelope()
envelope_bytes, bool = env_to_send_in_RPC(self.host)
packet.senderRecord = envelope_bytes
# Send out subscribe message to all peers
await self.message_all_peers(packet.SerializeToString())
@ -644,12 +617,8 @@ class Pubsub(Service, IPubsub):
[rpc_pb2.RPC.SubOpts(subscribe=False, topicid=topic_id)]
)
# Add the senderRecord of the peer in the RPC msg
envelope = create_signed_peer_record(
self.host.get_id(),
self.host.get_addrs(),
self.host.get_private_key(),
)
packet.senderRecord = envelope.marshal_envelope()
envelope_bytes, bool = env_to_send_in_RPC(self.host)
packet.senderRecord = envelope_bytes
# Send out unsubscribe message to all peers
await self.message_all_peers(packet.SerializeToString())