NagyZoltanPeter dcf09dd365 feat: lightpush v3 (#3279)
* Separate new lightpush protocol
New RPC defined
Rename al occurence of old lightpush to legacy lightpush, fix rest tests of lightpush
New lightpush protocol added back
Setup new lightpush protocol, mounting and rest api for it

	modified:   apps/chat2/chat2.nim
	modified:   tests/node/test_wakunode_lightpush.nim
	modified:   tests/node/test_wakunode_sharding.nim
	modified:   tests/test_peer_manager.nim
	modified:   tests/test_wakunode_lightpush.nim
	renamed:    tests/waku_lightpush/lightpush_utils.nim -> tests/waku_lightpush_legacy/lightpush_utils.nim
	renamed:    tests/waku_lightpush/test_all.nim -> tests/waku_lightpush_legacy/test_all.nim
	renamed:    tests/waku_lightpush/test_client.nim -> tests/waku_lightpush_legacy/test_client.nim
	renamed:    tests/waku_lightpush/test_ratelimit.nim -> tests/waku_lightpush_legacy/test_ratelimit.nim
	modified:   tests/wakunode_rest/test_all.nim
	renamed:    tests/wakunode_rest/test_rest_lightpush.nim -> tests/wakunode_rest/test_rest_lightpush_legacy.nim
	modified:   waku/factory/node_factory.nim
	modified:   waku/node/waku_node.nim
	modified:   waku/waku_api/rest/admin/handlers.nim
	modified:   waku/waku_api/rest/builder.nim
	new file:   waku/waku_api/rest/legacy_lightpush/client.nim
	new file:   waku/waku_api/rest/legacy_lightpush/handlers.nim
	new file:   waku/waku_api/rest/legacy_lightpush/types.nim
	modified:   waku/waku_api/rest/lightpush/client.nim
	modified:   waku/waku_api/rest/lightpush/handlers.nim
	modified:   waku/waku_api/rest/lightpush/types.nim
	modified:   waku/waku_core/codecs.nim
	modified:   waku/waku_lightpush.nim
	modified:   waku/waku_lightpush/callbacks.nim
	modified:   waku/waku_lightpush/client.nim
	modified:   waku/waku_lightpush/common.nim
	modified:   waku/waku_lightpush/protocol.nim
	modified:   waku/waku_lightpush/rpc.nim
	modified:   waku/waku_lightpush/rpc_codec.nim
	modified:   waku/waku_lightpush/self_req_handler.nim
	new file:   waku/waku_lightpush_legacy.nim
	renamed:    waku/waku_lightpush/README.md -> waku/waku_lightpush_legacy/README.md
	new file:   waku/waku_lightpush_legacy/callbacks.nim
	new file:   waku/waku_lightpush_legacy/client.nim
	new file:   waku/waku_lightpush_legacy/common.nim
	new file:   waku/waku_lightpush_legacy/protocol.nim
	new file:   waku/waku_lightpush_legacy/protocol_metrics.nim
	new file:   waku/waku_lightpush_legacy/rpc.nim
	new file:   waku/waku_lightpush_legacy/rpc_codec.nim
	new file:   waku/waku_lightpush_legacy/self_req_handler.nim

Adapt to non-invasive libp2p observers

cherry pick latest lightpush (v1) changes into legacy lightpush code after rebase to latest master

Fix vendor dependencies from origin/master after failed rebase of them

Adjust examples, test to new lightpush - keep using of legacy

Fixup error code mappings

Fix REST admin interface with distinct legacy and new lightpush

Fix lightpush v2 tests

* Utilize new publishEx interface of pubsub libp2p

* Adapt to latest libp2p pubslih design changes. publish returns an outcome as Result error.

* Fix review findings

* Fix tests, re-added lost one

* Fix rebase

* Apply suggestions from code review

Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>

* Addressing review comments

* Fix incentivization tests

* Fix build failed on libwaku

* Change new lightpush endpoint version to 3 instead of 2. Noticed that old and new lightpush metrics can cause trouble in monitoring dashboards so decided to give new name as v3 for the new lightpush metrics and change legacy ones back - temporarly till old lightpush will be decommissioned

* Fixing flaky test with rate limit timing

* Fixing logscope of lightpush and legacy lightpush

---------

Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
2025-03-05 12:07:56 +01:00

180 lines
5.1 KiB
Nim

{.used.}
import
stew/results,
testutils/unittests,
libp2p/multiaddress,
libp2p/peerid,
libp2p/errors,
confutils/toml/std/net
import waku/[waku_core, waku_enr], ../testlib/wakucore
suite "Waku Core - Peers":
test "Peer info parses correctly":
## Given
let address =
"/ip4/127.0.0.1/tcp/65002/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## When
let remotePeerInfoRes = parsePeerInfo(address)
require remotePeerInfoRes.isOk()
let remotePeerInfo = remotePeerInfoRes.value
## Then
check:
$(remotePeerInfo.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
$(remotePeerInfo.addrs[0][0].tryGet()) == "/ip4/127.0.0.1"
$(remotePeerInfo.addrs[0][1].tryGet()) == "/tcp/65002"
test "DNS multiaddrs parsing - dns peer":
## Given
let address =
"/dns/localhost/tcp/65012/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## When
let dnsPeerRes = parsePeerInfo(address)
require dnsPeerRes.isOk()
let dnsPeer = dnsPeerRes.value
## Then
check:
$(dnsPeer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
$(dnsPeer.addrs[0][0].tryGet()) == "/dns/localhost"
$(dnsPeer.addrs[0][1].tryGet()) == "/tcp/65012"
test "DNS multiaddrs parsing - dnsaddr peer":
## Given
let address =
"/dnsaddr/localhost/tcp/65022/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## When
let dnsAddrPeerRes = parsePeerInfo(address)
require dnsAddrPeerRes.isOk()
let dnsAddrPeer = dnsAddrPeerRes.value
## Then
check:
$(dnsAddrPeer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
$(dnsAddrPeer.addrs[0][0].tryGet()) == "/dnsaddr/localhost"
$(dnsAddrPeer.addrs[0][1].tryGet()) == "/tcp/65022"
test "DNS multiaddrs parsing - dns4 peer":
## Given
let address =
"/dns4/localhost/tcp/65032/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## When
let dns4PeerRes = parsePeerInfo(address)
require dns4PeerRes.isOk()
let dns4Peer = dns4PeerRes.value
# Then
check:
$(dns4Peer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
$(dns4Peer.addrs[0][0].tryGet()) == "/dns4/localhost"
$(dns4Peer.addrs[0][1].tryGet()) == "/tcp/65032"
test "DNS multiaddrs parsing - dns6 peer":
## Given
let address =
"/dns6/localhost/tcp/65042/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## When
let dns6PeerRes = parsePeerInfo(address)
require dns6PeerRes.isOk()
let dns6Peer = dns6PeerRes.value
## Then
check:
$(dns6Peer.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
$(dns6Peer.addrs[0][0].tryGet()) == "/dns6/localhost"
$(dns6Peer.addrs[0][1].tryGet()) == "/tcp/65042"
test "Multiaddr parsing should fail with invalid address":
## Given
let address = "/p2p/$UCH GIBBER!SH"
## Then
check:
parsePeerInfo(address).isErr()
test "Multiaddr parsing should fail with leading whitespace":
## Given
let address =
" /ip4/127.0.0.1/tcp/65062/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## Then
check:
parsePeerInfo(address).isErr()
test "Multiaddr parsing should fail with trailing whitespace":
## Given
let address =
"/ip4/127.0.0.1/tcp/65072/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc "
## Then
check:
parsePeerInfo(address).isErr()
test "Multiaddress parsing should fail with invalid IP address":
## Given
let address =
"/ip4/127.0.0.0.1/tcp/65082/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## Then
check:
parsePeerInfo(address).isErr()
test "Multiaddress parsing should fail with no peer ID":
## Given
let address = "/ip4/127.0.0.1/tcp/65092"
# Then
check:
parsePeerInfo(address).isErr()
test "Multiaddress parsing should fail with unsupported transport":
## Given
let address =
"/ip4/127.0.0.1/udp/65102/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
## Then
check:
parsePeerInfo(address).isErr()
test "ENRs capabilities are filled when creating RemotePeerInfo":
let
enrSeqNum = 1u64
enrPrivKey = generatesecp256k1key()
## When
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
builder.withIpAddressAndPorts(
ipAddr = some(parseIpAddress("127.0.0.1")),
tcpPort = some(Port(0)),
udpPort = some(Port(0)),
)
builder.withWakuCapabilities(Capabilities.Relay, Capabilities.Store)
let recordRes = builder.build()
## Then
assert recordRes.isOk(), $recordRes.error
let record = recordRes.tryGet()
let remotePeerInfoRes = record.toRemotePeerInfo()
assert remotePeerInfoRes.isOk(),
"failed creating RemotePeerInfo: " & $remotePeerInfoRes.error()
let remotePeerInfo = remotePeerInfoRes.get()
check:
remotePeerInfo.protocols.len == 2
remotePeerInfo.protocols.contains(WakuRelayCodec)
remotePeerInfo.protocols.contains(WakuStoreCodec)