Skip to content

Instantly share code, notes, and snippets.

@chux0519
Last active November 24, 2021 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chux0519/ab1b4397b4823480834b3197f3f62c98 to your computer and use it in GitHub Desktop.
Save chux0519/ab1b4397b4823480834b3197f3f62c98 to your computer and use it in GitHub Desktop.
quorum 黑名单

问题一:被 block 的节点还是能正常发送消息

使用 main 分支,启动三个节点,bootstrap,节点 A 和节点 B

  • A 监听 8003 端口提供 API
  • B 监听 8004 端口提供 API

A 创建一个组,owner 是 A

curl -k -X POST -H 'Content-Type: application/json' -d '{"group_name":"test_group_8003", "consensus_type":"poa", "encryption_type":"public", "app_key":"test_app"}' https://localhost:8003/api/v1/group

返回种子

{"genesis_block":{"BlockId":"96aa2e22-c565-40c0-863a-30255062468c","GroupId":"8b0776cd-a94f-4221-b59f-de57c0fc2422","ProducerPubKey":"CAISIQK/+BHiiylveZpJPUzwQuNOiCx7nt5HON/u1TyTTLcONg==","Hash":"RANoR/Oxtp3LhVHRliRVbHGpYrBdzTW5AMuGo+hR454=","Signature":"MEQCIFKI7d9Ura6p1Rx99SQuP6W34LeFijJEPOpZObcnSA9+AiBPnYp2qKvOUXP64/mEhAn3aeKfeFtS7pTx28OT1kpJVA==","TimeStamp":"1637741287381778990"},"group_id":"8b0776cd-a94f-4221-b59f-de57c0fc2422","group_name":"test_group_8003","owner_pubkey":"CAISIQK/+BHiiylveZpJPUzwQuNOiCx7nt5HON/u1TyTTLcONg==","consensus_type":"poa","encryption_type":"public","cipher_key":"a21bef7b110e4189c2c71414a325a30cbad6e6ec7f61308083128fe0d87bc9e7","app_key":"test_app","signature":"3046022100f7bcf1fa9822fc58b7105654d989d4a4507c29794e99e71355481046e7ba9dad022100b465257b14279db152c8188d21b49329464830580187611eac506bb6d1bc63a0"}

B 加入这个组

curl -k -X POST -H 'Content-Type: application/json' -d '{"genesis_block":{"BlockId":"96aa2e22-c565-40c0-863a-30255062468c","GroupId":"8b0776cd-a94f-4221-b59f-de57c0fc2422","ProducerPubKey":"CAISIQK/+BHiiylveZpJPUzwQuNOiCx7nt5HON/u1TyTTLcONg==","Hash":"RANoR/Oxtp3LhVHRliRVbHGpYrBdzTW5AMuGo+hR454=","Signature":"MEQCIFKI7d9Ura6p1Rx99SQuP6W34LeFijJEPOpZObcnSA9+AiBPnYp2qKvOUXP64/mEhAn3aeKfeFtS7pTx28OT1kpJVA==","TimeStamp":"1637741287381778990"},"group_id":"8b0776cd-a94f-4221-b59f-de57c0fc2422","group_name":"test_group_8003","owner_pubkey":"CAISIQK/+BHiiylveZpJPUzwQuNOiCx7nt5HON/u1TyTTLcONg==","consensus_type":"poa","encryption_type":"public","cipher_key":"a21bef7b110e4189c2c71414a325a30cbad6e6ec7f61308083128fe0d87bc9e7","app_key":"test_app","signature":"3046022100f7bcf1fa9822fc58b7105654d989d4a4507c29794e99e71355481046e7ba9dad022100b465257b14279db152c8188d21b49329464830580187611eac506bb6d1bc63a0"}' https://127.0.0.1:8004/api/v1/group/join

分别验证两个节点的组信息

curl -k "https://localhost:8003/api/v1/groups"
curl -k "https://localhost:8004/api/v1/groups"

A, B 各发一条消息

curl -k -X POST -H 'Content-Type: application/json' -d '{"type":"Add","object":{"type":"Note","content":"from 8003","name":"from 8003"},"target":{"id":"8b0776cd-a94f-4221-b59f-de57c0fc2422","type":"Group"}}' https://localhost:8003/api/v1/group/content

curl -k -X POST -H 'Content-Type: application/json' -d '{"type":"Add","object":{"type":"Note","content":"from 8004","name":"from 8004"},"target":{"id":"8b0776cd-a94f-4221-b59f-de57c0fc2422","type":"Group"}}' https://localhost:8004/api/v1/group/content

等待同步,然后分别验证两个节点都有内容

curl -k -X POST -H 'Content-Type: application/json' -d '' "https://localhost:8003/app/api/v1/group/8b0776cd-a94f-4221-b59f-de57c0fc2422/content?revers=true&num=10"
curl -k -X POST -H 'Content-Type: application/json' -d '' "https://localhost:8004/app/api/v1/group/8b0776cd-a94f-4221-b59f-de57c0fc2422/content?revers=true&num=10"

owner(A) 将 B 添加进黑名单

# 获取 B 的 id
curl -k -H 'Content-Type: application/json' "https://localhost:8004/api/v1/node"

# 16Uiu2HAmV3FCZbfyVis5pQPRqdxZMg8qcoLsm1SWcZ7yAukGSbBc

curl -k -X POST -H 'Content-Type: application/json' -d '{"action": "add", "peer_id": "16Uiu2HAmV3FCZbfyVis5pQPRqdxZMg8qcoLsm1SWcZ7yAukGSbBc", "group_id":"8b0776cd-a94f-4221-b59f-de57c0fc2422", "memo":""}' "https://localhost:8003/api/v1/group/deniedlist"

等待同步,然后验证两个节点都获取到了黑名单内容

curl -k "https://localhost:8003/api/v1/group/8b0776cd-a94f-4221-b59f-de57c0fc2422/deniedlist"
curl -k "https://localhost:8004/api/v1/group/8b0776cd-a94f-4221-b59f-de57c0fc2422/deniedlist"

这时理论上 B 已经没办法发送消息了,使用 B 尝试发送

curl -k -X POST -H 'Content-Type: application/json' -d '{"type":"Add","object":{"type":"Note","content":"from 8004, should block","name":"from 8004, should block"},"target":{"id":"8b0776cd-a94f-4221-b59f-de57c0fc2422","type":"Group"}}' https://localhost:8004/api/v1/group/content

等待,然后获取内容,发现 B 刚刚还是发送成功了

curl -k -X POST -H 'Content-Type: application/json' -d '' "https://localhost:8003/app/api/v1/group/8b0776cd-a94f-4221-b59f-de57c0fc2422/content?revers=true&num=10"
curl -k -X POST -H 'Content-Type: application/json' -d '' "https://localhost:8004/app/api/v1/group/8b0776cd-a94f-4221-b59f-de57c0fc2422/content?revers=true&num=10"

会返回不相关组的黑名单。 比如 A 再创建一个组,id 是 0fe8d26c-60fc-42db-9bc7-f9826c1bddc4,这时

[yongsheng@hp835g7 peer1]$ curl -k "https://localhost:8003/api/v1/group/0fe8d26c-60fc-42db-9bc7-f9826c1bddc4/deniedlist"
[{"GroupId":"8b0776cd-a94f-4221-b59f-de57c0fc2422","PeerId":"16Uiu2HAmV3FCZbfyVis5pQPRqdxZMg8qcoLsm1SWcZ7yAukGSbBc","GroupOwnerPubkey":"CAISIQK/+BHiiylveZpJPUzwQuNOiCx7nt5HON/u1TyTTLcONg==","GroupOwnerSign":"304502205b4301b7c2a606d5f1720b7c05aa4c7b9c5faa6a1c930d51fed401096c73befc022100a03b8576fc41fe687e5ef365744e5f00571815b2eab409f13d1f46ff833cc7b1","TimeStamp":1637741734016410958,"Action":"add","Memo":""}]

这个组是新创建的,并没有加黑名单,返回应该是空才对,这里返回了刚刚添加的,之前那个组的黑名单内容

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment