diff --git a/doc/p2p.md b/doc/p2p.md index d2534b2..f52b474 100644 --- a/doc/p2p.md +++ b/doc/p2p.md @@ -56,7 +56,6 @@ proc newEthereumNode*(keys: KeyPair, ```nim node.addCapability(eth) - node.addCapability(shh) ``` Each supplied protocol identifier is a name of a protocol introduced diff --git a/eth/common/eth_types.nim b/eth/common/eth_types.nim index 7c22e06..39c6ffd 100644 --- a/eth/common/eth_types.nim +++ b/eth/common/eth_types.nim @@ -20,8 +20,6 @@ type BloomFilter* = array[256, byte] EthAddress* = array[20, byte] - WhisperIdentity* = array[60, byte] - DifficultyInt* = UInt256 GasInt* = int64 ## Type alias used for gas computation diff --git a/eth/p2p/whispernodes.nim b/eth/p2p/whispernodes.nim deleted file mode 100644 index b3c746f..0000000 --- a/eth/p2p/whispernodes.nim +++ /dev/null @@ -1,43 +0,0 @@ -const - # Whisper nodes taken from: - # curl -s https://fleets.status.im | jq '"\"" + .fleets["eth.prod"].whisper[] + "\","' -r - WhisperNodes* = [ - "enode://b957e51f41e4abab8382e1ea7229e88c6e18f34672694c6eae389eac22dab8655622bbd4a08192c321416b9becffaab11c8e2b7a5d0813b922aa128b82990dab@47.75.222.178:443", - "enode://66ba15600cda86009689354c3a77bdf1a97f4f4fb3ab50ffe34dbc904fac561040496828397be18d9744c75881ffc6ac53729ddbd2cdbdadc5f45c400e2622f7@178.128.141.87:443", - "enode://182ed5d658d1a1a4382c9e9f7c9e5d8d9fec9db4c71ae346b9e23e1a589116aeffb3342299bdd00e0ab98dbf804f7b2d8ae564ed18da9f45650b444aed79d509@34.68.132.118:443", - "enode://8bebe73ddf7cf09e77602c7d04c93a73f455b51f24ae0d572917a4792f1dec0bb4c562759b8830cc3615a658d38c1a4a38597a1d7ae3ba35111479fc42d65dec@47.75.85.212:443", - "enode://4ea35352702027984a13274f241a56a47854a7fd4b3ba674a596cff917d3c825506431cf149f9f2312a293bb7c2b1cca55db742027090916d01529fe0729643b@134.209.136.79:443", - "enode://fbeddac99d396b91d59f2c63a3cb5fc7e0f8a9f7ce6fe5f2eed5e787a0154161b7173a6a73124a4275ef338b8966dc70a611e9ae2192f0f2340395661fad81c0@34.67.230.193:443", - "enode://ac3948b2c0786ada7d17b80cf869cf59b1909ea3accd45944aae35bf864cc069126da8b82dfef4ddf23f1d6d6b44b1565c4cf81c8b98022253c6aea1a89d3ce2@47.75.88.12:443", - "enode://ce559a37a9c344d7109bd4907802dd690008381d51f658c43056ec36ac043338bd92f1ac6043e645b64953b06f27202d679756a9c7cf62fdefa01b2e6ac5098e@134.209.136.123:443", - "enode://c07aa0deea3b7056c5d45a85bca42f0d8d3b1404eeb9577610f386e0a4744a0e7b2845ae328efc4aa4b28075af838b59b5b3985bffddeec0090b3b7669abc1f3@35.226.92.155:443", - "enode://385579fc5b14e04d5b04af7eee835d426d3d40ccf11f99dbd95340405f37cf3bbbf830b3eb8f70924be0c2909790120682c9c3e791646e2d5413e7801545d353@47.244.221.249:443", - "enode://4e0a8db9b73403c9339a2077e911851750fc955db1fc1e09f81a4a56725946884dd5e4d11258eac961f9078a393c45bcab78dd0e3bc74e37ce773b3471d2e29c@134.209.136.101:443", - "enode://0624b4a90063923c5cc27d12624b6a49a86dfb3623fcb106801217fdbab95f7617b83fa2468b9ae3de593ff6c1cf556ccf9bc705bfae9cb4625999765127b423@35.222.158.246:443", - "enode://b77bffc29e2592f30180311dd81204ab845e5f78953b5ba0587c6631be9c0862963dea5eb64c90617cf0efd75308e22a42e30bc4eb3cd1bbddbd1da38ff6483e@47.75.10.177:443", - "enode://a8bddfa24e1e92a82609b390766faa56cf7a5eef85b22a2b51e79b333c8aaeec84f7b4267e432edd1cf45b63a3ad0fc7d6c3a16f046aa6bc07ebe50e80b63b8c@178.128.141.249:443", - "enode://a5fe9c82ad1ffb16ae60cb5d4ffe746b9de4c5fbf20911992b7dd651b1c08ba17dd2c0b27ee6b03162c52d92f219961cc3eb14286aca8a90b75cf425826c3bd8@104.154.230.58:443", - "enode://cf5f7a7e64e3b306d1bc16073fba45be3344cb6695b0b616ccc2da66ea35b9f35b3b231c6cf335fdfaba523519659a440752fc2e061d1e5bc4ef33864aac2f19@47.75.221.196:443", - "enode://887cbd92d95afc2c5f1e227356314a53d3d18855880ac0509e0c0870362aee03939d4074e6ad31365915af41d34320b5094bfcc12a67c381788cd7298d06c875@178.128.141.0:443", - "enode://282e009967f9f132a5c2dd366a76319f0d22d60d0c51f7e99795a1e40f213c2705a2c10e4cc6f3890319f59da1a535b8835ed9b9c4b57c3aad342bf312fd7379@35.223.240.17:443", - "enode://13d63a1f85ccdcbd2fb6861b9bd9d03f94bdba973608951f7c36e5df5114c91de2b8194d71288f24bfd17908c48468e89dd8f0fb8ccc2b2dedae84acdf65f62a@47.244.210.80:443", - "enode://2b01955d7e11e29dce07343b456e4e96c081760022d1652b1c4b641eaf320e3747871870fa682e9e9cfb85b819ce94ed2fee1ac458904d54fd0b97d33ba2c4a4@134.209.136.112:443", - "enode://b706a60572634760f18a27dd407b2b3582f7e065110dae10e3998498f1ae3f29ba04db198460d83ed6d2bfb254bb06b29aab3c91415d75d3b869cd0037f3853c@35.239.5.162:443", - "enode://32915c8841faaef21a6b75ab6ed7c2b6f0790eb177ad0f4ea6d731bacc19b938624d220d937ebd95e0f6596b7232bbb672905ee12601747a12ee71a15bfdf31c@47.75.59.11:443", - "enode://0d9d65fcd5592df33ed4507ce862b9c748b6dbd1ea3a1deb94e3750052760b4850aa527265bbaf357021d64d5cc53c02b410458e732fafc5b53f257944247760@178.128.141.42:443", - "enode://e87f1d8093d304c3a9d6f1165b85d6b374f1c0cc907d39c0879eb67f0a39d779be7a85cbd52920b6f53a94da43099c58837034afa6a7be4b099bfcd79ad13999@35.238.106.101:443", - ] - - # curl -s https://fleets.status.im | jq '"\"" + .fleets["eth.staging"].whisper[] + "\","' -r - WhisperNodesStaging* = [ - "enode://00395686f5954662a3796e170b9e87bbaf68a050d57e9987b78a2292502dae44aae2b8803280a017ec9af9be0b3121db9d6b3693ab3a0451a866bcbedd58fdac@47.52.226.137:443", - "enode://914c0b30f27bab30c1dfd31dad7652a46fda9370542aee1b062498b1345ee0913614b8b9e3e84622e84a7203c5858ae1d9819f63aece13ee668e4f6668063989@167.99.19.148:443", - "enode://2d897c6e846949f9dcf10279f00e9b8325c18fe7fa52d658520ad7be9607c83008b42b06aefd97cfe1fdab571f33a2a9383ff97c5909ed51f63300834913237e@35.192.0.86:443", - ] - - # curl -s https://fleets.status.im | jq '"\"" + .fleets["eth.test"].whisper[] + "\","' -r - WhisperNodesTest* = [ - "enode://ad38f94030a846cc7005b7a1f3b6b01bf4ef59d34e8d3d6f4d12df23d14ba8656702a435d34cf4df3b412c0c1923df5adcce8461321a0d8ffb9435b26e572c2a@47.52.255.194:443", - "enode://1d193635e015918fb85bbaf774863d12f65d70c6977506187ef04420d74ec06c9e8f0dcb57ea042f85df87433dab17a1260ed8dde1bdf9d6d5d2de4b7bf8e993@206.189.243.163:443", - "enode://f593a27731bc0f8eb088e2d39222c2d59dfb9bf0b3950d7a828d51e8ab9e08fffbd9916a82fd993c1a080c57c2bd70ed6c36f489a969de697aff93088dbee1a9@35.194.31.108:443", - ] diff --git a/tests/fuzzing/rlpx/thunk.nim b/tests/fuzzing/rlpx/thunk.nim index c050acd..508cb64 100644 --- a/tests/fuzzing/rlpx/thunk.nim +++ b/tests/fuzzing/rlpx/thunk.nim @@ -1,7 +1,7 @@ import - testutils/fuzzing, chronos, + testutils/fuzzing, chronos, ../../../eth/p2p, ../../../eth/p2p/rlpx, ../../../eth/p2p/private/p2p_types, - ../../../eth/p2p/rlpx_protocols/[whisper_protocol, eth_protocol], + ../../../eth/p2p/rlpx_protocols/eth_protocol, ../../p2p/p2p_test_helper var @@ -14,8 +14,8 @@ let rng = newRng() # to mock more to get rid of anything sockets, async, etc. # However, it can and has provided reasonably quick results anyhow. init: - node1 = setupTestNode(rng, eth, Whisper) - node2 = setupTestNode(rng, eth, Whisper) + node1 = setupTestNode(rng, eth) + node2 = setupTestNode(rng, eth) node2.startListening() peer = waitFor node1.rlpxConnect(newNode(node2.toENode())) diff --git a/tests/p2p/all_tests.nim b/tests/p2p/all_tests.nim index f73574e..f80189d 100644 --- a/tests/p2p/all_tests.nim +++ b/tests/p2p/all_tests.nim @@ -6,9 +6,5 @@ import ./test_ecies, ./test_enode, ./test_rlpx_thunk, - ./test_shh, - ./test_shh_config, - ./test_shh_connect, ./test_protocol_handlers, ./les/test_flow_control - \ No newline at end of file diff --git a/tests/p2p/shh_basic_client.nim b/tests/p2p/shh_basic_client.nim deleted file mode 100644 index 4a6fa0d..0000000 --- a/tests/p2p/shh_basic_client.nim +++ /dev/null @@ -1,154 +0,0 @@ -# -# Ethereum P2P -# (c) Copyright 2018 -# Status Research & Development GmbH -# -# Licensed under either of -# Apache License, version 2.0, (LICENSE-APACHEv2) -# MIT license (LICENSE-MIT) - -import - std/[sequtils, options, strutils, parseopt], - chronos, - ../../eth/[keys, rlp, p2p], eth/p2p/rlpx_protocols/[whisper_protocol], - ../../eth/p2p/[discovery, enode, peer_pool, bootnodes, whispernodes] - -const - DefaultListeningPort = 30303 - Usage = """Usage: - tssh_client [options] -Options: - -p --port Listening port - --post Post messages - --watch Install filters - --mainnet Connect to main network (default local private) - --local Only local loopback - --help Display this help and exit""" - - DockerBootnode = "enode://f41f87f084ed7df4a9fd0833e395f49c89764462d3c4bc16d061a3ae5e3e34b79eb47d61c2f62db95ff32ae8e20965e25a3c9d9b8dbccaa8e8d77ac6fc8efc06@172.17.0.2:30301" - -type - ShhConfig* = object - listeningPort*: int - post*: bool - watch*: bool - main*: bool - local*: bool - -proc processArguments*(): ShhConfig = - var opt = initOptParser() - var length = 0 - for kind, key, value in opt.getopt(): - case kind - of cmdArgument: - echo key - of cmdLongOption, cmdShortOption: - inc(length) - case key.toLowerAscii() - of "help", "h": quit(Usage, QuitSuccess) - of "port", "p": - result.listeningPort = value.parseInt - of "post": - result.post = true - of "watch": - result.watch = true - of "mainnet": - result.main = true - of "local": - result.local = true - else: quit(Usage) - of cmdEnd: - quit(Usage) - -let config = processArguments() - -var port: Port -var address: Address -var netId: uint - -# config -if config.listeningPort != 0: - port = Port(config.listeningPort) -else: - port = Port(DefaultListeningPort) -if config.local: - address = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("127.0.0.1")) -else: - address = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("0.0.0.0")) -if config.main: - netId = 1 -else: - netId = 15 - -let keypair = KeyPair.random()[] -var node = newEthereumNode(keypair, address, netId, nil, addAllCapabilities = false) -node.addCapability Whisper - -# lets prepare some prearranged keypairs -let encPrivateKey = PrivateKey.fromHex( - "5dc5381cae54ba3174dc0d46040fe11614d0cc94d41185922585198b4fcef9d3")[] -let encPublicKey = encPrivateKey.toPublicKey()[] -let signPrivateKey = PrivateKey.fromHex( - "365bda0757d22212b04fada4b9222f8c3da59b49398fa04cf612481cd893b0a3")[] -let signPublicKey = signPrivateKey.toPublicKey()[] -var symKey: SymKey -# To test with geth: all 0's key is invalid in geth console -symKey[31] = 1 -let topic = [byte 0x12, 0, 0, 0] - -if config.main: - var bootnodes: seq[ENode] = @[] - for nodeId in MainnetBootnodes: - bootnodes.add(ENode.fromString(nodeId).expect("static nodes")) - - asyncCheck node.connectToNetwork(bootnodes, true, true) - # main network has mostly non SHH nodes, so we connect directly to SHH nodes - for nodeId in WhisperNodes: - var whisperNode = newNode(ENode.fromString(nodeId).expect("static nodes")) - asyncCheck node.peerPool.connectToNode(whisperNode) -else: - let bootENode = ENode.fromString(DockerBootnode).expect("static node") - waitFor node.connectToNetwork(@[bootENode], true, true) - -if config.watch: - proc handler(msg: ReceivedMessage) = - echo msg.decoded.payload.repr - - # filter encrypted asym - discard node.subscribeFilter(initFilter(privateKey = some(encPrivateKey), - topics = @[topic]), - handler) - # filter encrypted asym + signed - discard node.subscribeFilter(initFilter(some(signPublicKey), - privateKey = some(encPrivateKey), - topics = @[topic]), - handler) - # filter encrypted sym - discard node.subscribeFilter(initFilter(symKey = some(symKey), - topics = @[topic]), - handler) - # filter encrypted sym + signed - discard node.subscribeFilter(initFilter(some(signPublicKey), - symKey = some(symKey), - topics = @[topic]), - handler) - -if config.post: - # encrypted asym - discard node.postMessage(some(encPublicKey), ttl = 5, topic = topic, - payload = repeat(byte 65, 10)) - poll() - # # encrypted asym + signed - discard node.postMessage(some(encPublicKey), src = some(signPrivateKey), - ttl = 5, topic = topic, payload = repeat(byte 66, 10)) - poll() - # # encrypted sym - discard node.postMessage(symKey = some(symKey), ttl = 5, topic = topic, - payload = repeat(byte 67, 10)) - poll() - # # encrypted sym + signed - discard node.postMessage(symKey = some(symKey), src = some(signPrivateKey), - ttl = 5, topic = topic, payload = repeat(byte 68, 10)) - -while true: - poll() diff --git a/tests/p2p/test_rlpx_thunk.json b/tests/p2p/test_rlpx_thunk.json index ce51de3..5c90ad6 100644 --- a/tests/p2p/test_rlpx_thunk.json +++ b/tests/p2p/test_rlpx_thunk.json @@ -7,7 +7,7 @@ "Message id that is not supported": { "payload": "08", "error": "UnsupportedMessageError", - "description": "This is a message id not used by devp2p, eth or whisper" + "description": "This is a message id not used by devp2p or eth" }, "Message id that is bigger than int32": { "payload": "888888888888888888", diff --git a/tests/p2p/test_rlpx_thunk.nim b/tests/p2p/test_rlpx_thunk.nim index 01f5bc7..4747e67 100644 --- a/tests/p2p/test_rlpx_thunk.nim +++ b/tests/p2p/test_rlpx_thunk.nim @@ -4,14 +4,14 @@ import std/[json, os], unittest2, chronos, stew/byteutils, - ../../eth/p2p, ../../eth/p2p/rlpx_protocols/[whisper_protocol, eth_protocol], + ../../eth/p2p, ../../eth/p2p/rlpx_protocols/eth_protocol, ./p2p_test_helper let rng = newRng() var - node1 = setupTestNode(rng, eth, Whisper) - node2 = setupTestNode(rng, eth, Whisper) + node1 = setupTestNode(rng, eth) + node2 = setupTestNode(rng, eth) node2.startListening() var peer = waitFor node1.rlpxConnect(newNode(node2.toENode())) diff --git a/tests/p2p/test_shh_connect.nim b/tests/p2p/test_shh_connect.nim deleted file mode 100644 index c4913dc..0000000 --- a/tests/p2p/test_shh_connect.nim +++ /dev/null @@ -1,329 +0,0 @@ -# -# Ethereum P2P -# (c) Copyright 2018 -# Status Research & Development GmbH -# -# Licensed under either of -# Apache License, version 2.0, (LICENSE-APACHEv2) -# MIT license (LICENSE-MIT) - -{.used.} - -import - std/[sequtils, options, tables], - chronos, testutils/unittests, - ../../eth/[keys, p2p], ../../eth/p2p/peer_pool, - ../../eth/p2p/rlpx_protocols/whisper_protocol, - ./p2p_test_helper - -proc resetMessageQueues(nodes: varargs[EthereumNode]) = - for node in nodes: - node.resetMessageQueue() - -let safeTTL = 5'u32 -let waitInterval = messageInterval + 150.milliseconds - -procSuite "Whisper connections": - let rng = newRng() - var node1 = setupTestNode(rng, Whisper) - var node2 = setupTestNode(rng, Whisper) - node2.startListening() - waitFor node1.peerPool.connectToNode(newNode(node2.toENode())) - asyncTest "Two peers connected": - check: - node1.peerPool.connectedNodes.len() == 1 - - asyncTest "Filters with encryption and signing": - let encryptKeyPair = KeyPair.random(rng[]) - let signKeyPair = KeyPair.random(rng[]) - var symKey: SymKey - let topic = [byte 0x12, 0, 0, 0] - var filters: seq[string] = @[] - var payloads = [repeat(byte 1, 10), repeat(byte 2, 10), - repeat(byte 3, 10), repeat(byte 4, 10)] - var futures = [newFuture[int](), newFuture[int](), - newFuture[int](), newFuture[int]()] - - proc handler1(msg: ReceivedMessage) = - var count {.global.}: int - check msg.decoded.payload == payloads[0] or msg.decoded.payload == payloads[1] - count += 1 - if count == 2: futures[0].complete(1) - proc handler2(msg: ReceivedMessage) = - check msg.decoded.payload == payloads[1] - futures[1].complete(1) - proc handler3(msg: ReceivedMessage) = - var count {.global.}: int - check msg.decoded.payload == payloads[2] or msg.decoded.payload == payloads[3] - count += 1 - if count == 2: futures[2].complete(1) - proc handler4(msg: ReceivedMessage) = - check msg.decoded.payload == payloads[3] - futures[3].complete(1) - - # Filters - # filter for encrypted asym - filters.add(node1.subscribeFilter(initFilter(privateKey = some(encryptKeyPair.seckey), - topics = @[topic]), handler1)) - # filter for encrypted asym + signed - filters.add(node1.subscribeFilter(initFilter(some(signKeyPair.pubkey), - privateKey = some(encryptKeyPair.seckey), - topics = @[topic]), handler2)) - # filter for encrypted sym - filters.add(node1.subscribeFilter(initFilter(symKey = some(symKey), - topics = @[topic]), handler3)) - # filter for encrypted sym + signed - filters.add(node1.subscribeFilter(initFilter(some(signKeyPair.pubkey), - symKey = some(symKey), - topics = @[topic]), handler4)) - # Messages - check: - # encrypted asym - node2.postMessage(some(encryptKeyPair.pubkey), ttl = safeTTL, - topic = topic, payload = payloads[0]) == true - # encrypted asym + signed - node2.postMessage(some(encryptKeyPair.pubkey), - src = some(signKeyPair.seckey), ttl = safeTTL, - topic = topic, payload = payloads[1]) == true - # encrypted sym - node2.postMessage(symKey = some(symKey), ttl = safeTTL, topic = topic, - payload = payloads[2]) == true - # encrypted sym + signed - node2.postMessage(symKey = some(symKey), - src = some(signKeyPair.seckey), - ttl = safeTTL, topic = topic, - payload = payloads[3]) == true - - node2.protocolState(Whisper).queue.items.len == 4 - - check: - await allFutures(futures).withTimeout(waitInterval) - node1.protocolState(Whisper).queue.items.len == 4 - - for filter in filters: - check node1.unsubscribeFilter(filter) == true - - resetMessageQueues(node1, node2) - - asyncTest "Filters with topics": - let topic1 = [byte 0x12, 0, 0, 0] - let topic2 = [byte 0x34, 0, 0, 0] - var payloads = [repeat(byte 0, 10), repeat(byte 1, 10)] - var futures = [newFuture[int](), newFuture[int]()] - proc handler1(msg: ReceivedMessage) = - check msg.decoded.payload == payloads[0] - futures[0].complete(1) - proc handler2(msg: ReceivedMessage) = - check msg.decoded.payload == payloads[1] - futures[1].complete(1) - - var filter1 = node1.subscribeFilter(initFilter(topics = @[topic1]), handler1) - var filter2 = node1.subscribeFilter(initFilter(topics = @[topic2]), handler2) - - check: - node2.postMessage(ttl = safeTTL + 1, topic = topic1, - payload = payloads[0]) == true - node2.postMessage(ttl = safeTTL, topic = topic2, - payload = payloads[1]) == true - node2.protocolState(Whisper).queue.items.len == 2 - - await allFutures(futures).withTimeout(waitInterval) - node1.protocolState(Whisper).queue.items.len == 2 - - node1.unsubscribeFilter(filter1) == true - node1.unsubscribeFilter(filter2) == true - - resetMessageQueues(node1, node2) - - asyncTest "Filters with PoW": - let topic = [byte 0x12, 0, 0, 0] - var payload = repeat(byte 0, 10) - var futures = [newFuture[int](), newFuture[int]()] - proc handler1(msg: ReceivedMessage) = - check msg.decoded.payload == payload - futures[0].complete(1) - proc handler2(msg: ReceivedMessage) = - check msg.decoded.payload == payload - futures[1].complete(1) - - var filter1 = node1.subscribeFilter(initFilter(topics = @[topic], powReq = 0), - handler1) - var filter2 = node1.subscribeFilter(initFilter(topics = @[topic], - powReq = 1_000_000), handler2) - - check: - node2.postMessage(ttl = safeTTL, topic = topic, payload = payload) == true - - (await futures[0].withTimeout(waitInterval)) == true - (await futures[1].withTimeout(waitInterval)) == false - node1.protocolState(Whisper).queue.items.len == 1 - - node1.unsubscribeFilter(filter1) == true - node1.unsubscribeFilter(filter2) == true - - resetMessageQueues(node1, node2) - - asyncTest "Filters with queues": - let topic = [byte 0, 0, 0, 0] - let payload = repeat(byte 0, 10) - - var filter = node1.subscribeFilter(initFilter(topics = @[topic])) - for i in countdown(10, 1): - check node2.postMessage(ttl = safeTTL, topic = topic, - payload = payload) == true - - await sleepAsync(waitInterval) - check: - node1.getFilterMessages(filter).len() == 10 - node1.getFilterMessages(filter).len() == 0 - node1.unsubscribeFilter(filter) == true - - resetMessageQueues(node1, node2) - - asyncTest "Local filter notify": - let topic = [byte 0, 0, 0, 0] - - var filter = node1.subscribeFilter(initFilter(topics = @[topic])) - check: - node1.postMessage(ttl = safeTTL, topic = topic, - payload = repeat(byte 4, 10)) == true - node1.getFilterMessages(filter).len() == 1 - node1.unsubscribeFilter(filter) == true - - await sleepAsync(waitInterval) - resetMessageQueues(node1, node2) - - asyncTest "Bloomfilter blocking": - let sendTopic1 = [byte 0x12, 0, 0, 0] - let sendTopic2 = [byte 0x34, 0, 0, 0] - let filterTopics = @[[byte 0x34, 0, 0, 0],[byte 0x56, 0, 0, 0]] - let payload = repeat(byte 0, 10) - var f: Future[int] = newFuture[int]() - proc handler(msg: ReceivedMessage) = - check msg.decoded.payload == payload - f.complete(1) - var filter = node1.subscribeFilter(initFilter(topics = filterTopics), handler) - await node1.setBloomFilter(node1.filtersToBloom()) - - check: - node2.postMessage(ttl = safeTTL, topic = sendTopic1, - payload = payload) == true - node2.protocolState(Whisper).queue.items.len == 1 - - (await f.withTimeout(waitInterval)) == false - node1.protocolState(Whisper).queue.items.len == 0 - - resetMessageQueues(node1, node2) - - f = newFuture[int]() - - check: - node2.postMessage(ttl = safeTTL, topic = sendTopic2, - payload = payload) == true - node2.protocolState(Whisper).queue.items.len == 1 - - await f.withTimeout(waitInterval) - f.read() == 1 - node1.protocolState(Whisper).queue.items.len == 1 - - node1.unsubscribeFilter(filter) == true - - await node1.setBloomFilter(fullBloom()) - - resetMessageQueues(node1, node2) - - asyncTest "PoW blocking": - let topic = [byte 0, 0, 0, 0] - let payload = repeat(byte 0, 10) - - await node1.setPowRequirement(1_000_000) - check: - node2.postMessage(ttl = safeTTL, topic = topic, payload = payload) == true - node2.protocolState(Whisper).queue.items.len == 1 - await sleepAsync(waitInterval) - check: - node1.protocolState(Whisper).queue.items.len == 0 - - resetMessageQueues(node1, node2) - - await node1.setPowRequirement(0.0) - check: - node2.postMessage(ttl = safeTTL, topic = topic, payload = payload) == true - node2.protocolState(Whisper).queue.items.len == 1 - await sleepAsync(waitInterval) - check: - node1.protocolState(Whisper).queue.items.len == 1 - - resetMessageQueues(node1, node2) - - asyncTest "Queue pruning": - let topic = [byte 0, 0, 0, 0] - let payload = repeat(byte 0, 10) - # We need a minimum TTL of 2 as when set to 1 there is a small chance that - # it is already expired after messageInterval due to rounding down of float - # to uint32 in postMessage() - let lowerTTL = 2'u32 # Lower TTL as we need to wait for messages to expire - for i in countdown(10, 1): - check node2.postMessage(ttl = lowerTTL, topic = topic, payload = payload) == true - check node2.protocolState(Whisper).queue.items.len == 10 - - await sleepAsync(waitInterval) - check node1.protocolState(Whisper).queue.items.len == 10 - - await sleepAsync(milliseconds((lowerTTL+1)*1000)) - check node1.protocolState(Whisper).queue.items.len == 0 - check node2.protocolState(Whisper).queue.items.len == 0 - - resetMessageQueues(node1, node2) - - asyncTest "P2P post": - let topic = [byte 0, 0, 0, 0] - var f: Future[int] = newFuture[int]() - proc handler(msg: ReceivedMessage) = - check msg.decoded.payload == repeat(byte 4, 10) - f.complete(1) - - var filter = node1.subscribeFilter(initFilter(topics = @[topic], - allowP2P = true), handler) - check: - node1.setPeerTrusted(toNodeId(node2.keys.pubkey)) == true - node2.postMessage(ttl = 10, topic = topic, - payload = repeat(byte 4, 10), - targetPeer = some(toNodeId(node1.keys.pubkey))) == true - - await f.withTimeout(waitInterval) - f.read() == 1 - node1.protocolState(Whisper).queue.items.len == 0 - node2.protocolState(Whisper).queue.items.len == 0 - - node1.unsubscribeFilter(filter) == true - - asyncTest "Light node posting": - var ln1 = setupTestNode(rng, Whisper) - ln1.setLightNode(true) - - await ln1.peerPool.connectToNode(newNode(node2.toENode())) - - let topic = [byte 0, 0, 0, 0] - - check: - # normal post - ln1.postMessage(ttl = safeTTL, topic = topic, - payload = repeat(byte 0, 10)) == false - ln1.protocolState(Whisper).queue.items.len == 0 - # P2P post - ln1.postMessage(ttl = safeTTL, topic = topic, - payload = repeat(byte 0, 10), - targetPeer = some(toNodeId(node2.keys.pubkey))) == true - ln1.protocolState(Whisper).queue.items.len == 0 - - asyncTest "Connect two light nodes": - var ln1 = setupTestNode(rng, Whisper) - var ln2 = setupTestNode(rng, Whisper) - - ln1.setLightNode(true) - ln2.setLightNode(true) - - ln2.startListening() - let peer = await ln1.rlpxConnect(newNode(ln2.toENode())) - check peer.isNil == true