From 0491e15fceec504d9c6962bde501ac6144c97c23 Mon Sep 17 00:00:00 2001 From: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:41:43 +0200 Subject: [PATCH] Fix PeerExchange rpc decode in order not to take response's status_code mandatory - for support old protocol implementation --- waku/waku_peer_exchange/protocol.nim | 4 +++- waku/waku_peer_exchange/rpc_codec.nim | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/waku/waku_peer_exchange/protocol.nim b/waku/waku_peer_exchange/protocol.nim index 0d00cfb0f1..e70afe16c7 100644 --- a/waku/waku_peer_exchange/protocol.nim +++ b/waku/waku_peer_exchange/protocol.nim @@ -217,7 +217,9 @@ proc populateEnrCache(wpx: WakuPeerExchange) = proc updatePxEnrCache(wpx: WakuPeerExchange) {.async.} = # try more aggressively to fill the cache at startup - while wpx.enrCache.len < MaxPeersCacheSize: + var attempts = 10 + while wpx.enrCache.len < MaxPeersCacheSize and attempts > 0: + attempts -= 1 wpx.populateEnrCache() await sleepAsync(5.seconds) diff --git a/waku/waku_peer_exchange/rpc_codec.nim b/waku/waku_peer_exchange/rpc_codec.nim index c0288ae39b..b698ffe9f5 100644 --- a/waku/waku_peer_exchange/rpc_codec.nim +++ b/waku/waku_peer_exchange/rpc_codec.nim @@ -71,7 +71,11 @@ proc decode*(T: type PeerExchangeResponse, buffer: seq[byte]): ProtobufResult[T] if ?pb.getField(10, status_code): rpc.status_code = PeerExchangeResponseStatusCode.parse(status_code) else: - return err(ProtobufError.missingRequiredField("status_code")) + # older peers may not support status_code field yet + if rpc.peerInfos.len() > 0: + rpc.status_code = PeerExchangeResponseStatusCode.SUCCESS + else: + rpc.status_code = PeerExchangeResponseStatusCode.SERVICE_UNAVAILABLE var status_desc: string if ?pb.getField(11, status_desc):