Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #71: Group #265

Merged
merged 584 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
584 commits
Select commit Hold shift + click to select a range
f19e051
Fix stream & NDN send data bugs
Feb 24, 2023
d8a9f65
Fix usage of lru cache in meta relate cache
lurenpluto Feb 24, 2023
c8f7858
Fix usage of lru cache in failed relate cache
lurenpluto Feb 24, 2023
43e8b98
Perf-client can use in cyfs-stack
weiqiushi Feb 24, 2023
1bdd007
Fix app-manager compile error
weiqiushi Feb 24, 2023
f14fce1
Change old-chunk-client`s get header timeout to 30 secs, DecApp Insta…
weiqiushi Feb 25, 2023
8708a0e
Add perf related definitions to cyfs-base
lurenpluto Feb 25, 2023
6b7bf88
Adapts perf relate impls in cyfs-perf-client with the perf definition…
lurenpluto Feb 25, 2023
e5fde0c
Integrate perf module into cyfs-stack
lurenpluto Feb 25, 2023
5a34747
Add scope relate perf helper macros
lurenpluto Feb 25, 2023
e808a56
Add some perf stub codec into cyfs-noc and cyfs-lib projects
lurenpluto Feb 25, 2023
0695121
Perf-client use post_object when send perf to other device
weiqiushi Feb 25, 2023
3281479
Modify: add reset known sn method to bdt stack
photosssa Feb 25, 2023
9f1fb4e
NamedDataClient use bdt no-sn mode, not listen on tcp port
weiqiushi Feb 25, 2023
36f97a2
Fix a panic that may be caused by an object field being empty in cyfs…
lurenpluto Feb 25, 2023
d6ce01d
Ensure that the object field is not empty during the non output->inpu…
lurenpluto Feb 25, 2023
d6530cd
Add sn_mode to cyfs-stack and loaders
lurenpluto Feb 25, 2023
fd5068a
Fix task type mismatch error for chunk task in trans service
lurenpluto Feb 27, 2023
b6a7f84
Improve test cases
lurenpluto Feb 27, 2023
b93ca4c
Fix the bug that the full version cannot be parsed correctly when ser…
lurenpluto Feb 27, 2023
b5b970c
Fix the bug when system-config's service_version = "default" updated …
lurenpluto Feb 27, 2023
09bd5bc
Fix the bug that the modification of system-config cannot take effect…
lurenpluto Feb 27, 2023
b6ab5b9
Clear meta cache when service list changed
lurenpluto Feb 27, 2023
4ac580f
Switch ndn get_data to normal http requestor instead of surf requestor
lurenpluto Feb 28, 2023
7594fdb
Improve admin and sync test cases
lurenpluto Feb 28, 2023
68c81c8
Set known sn list when sync built-in app repo
weiqiushi Feb 28, 2023
e7ce428
Fix wrong app local repo path
weiqiushi Feb 28, 2023
66969e0
App-manager return error when repo path not exist
weiqiushi Feb 28, 2023
28d86fa
Commit right file
weiqiushi Feb 28, 2023
952dbb6
App-manager returns an error in the case that the command program doe…
weiqiushi Mar 1, 2023
093d774
Add perf-service in misc
weiqiushi Mar 1, 2023
ac0ed15
Do not cache chunk if already exists in data request
lurenpluto Mar 2, 2023
fdc1239
Fix body length error when mime sniffing in cyfs-runtime
lurenpluto Mar 2, 2023
36351c8
Optimize some logs level
lurenpluto Mar 2, 2023
991f817
Fix the bug that build file object access cannot take effect
lurenpluto Mar 2, 2023
5477443
Add chunk length verify to poll_read method in cache reader
lurenpluto Mar 2, 2023
684ef7a
Add chunk length and hash verify when write to local cache
lurenpluto Mar 2, 2023
0030621
Improve congtent-based mime sniffing mechanism in cyfs-runtime
lurenpluto Mar 3, 2023
2fd47a8
Fix: sn client stop ping after second try
photosssa Mar 3, 2023
bbc51ca
Fix: sn client stop ping after second try
photosssa Mar 3, 2023
8a06c03
Add continuous service publish
weiqiushi Mar 6, 2023
4eb4f60
Remove unused publish script params
weiqiushi Mar 6, 2023
c37266b
Remove curstep file when publish finish
weiqiushi Mar 6, 2023
5e41097
Bump and publish cargo packages
weiqiushi Mar 6, 2023
ac7a6ae
AppManager support install web-packed DecApp
weiqiushi Mar 7, 2023
960bea1
Update Cargo.lock
weiqiushi Mar 7, 2023
35a3deb
Fix service pub script
weiqiushi Mar 7, 2023
59f2366
Fix continuous script error
weiqiushi Mar 7, 2023
65124c7
bdt debuger tool support new SN/NDN api and multi streams test
Mar 7, 2023
925411b
Support peer to build tunnel without SN in LAN
jing-git Mar 9, 2023
37adbd3
rebase from buckyos/main
streetycat Mar 10, 2023
08ae627
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 13, 2023
951c199
Adapte to the buckyos
streetycat Mar 13, 2023
39fd47e
Merge pull request #3 from buckyos/group-merge
streetycat Feb 15, 2023
6b21be6
merge from buckyos
streetycat Feb 15, 2023
e391823
rename GroupRPathMgr to GroupManager
streetycat Feb 15, 2023
12a5b3b
integrate GroupState, not finish
streetycat Feb 15, 2023
bce7f2f
integrate GroupState update
streetycat Feb 16, 2023
65e8a18
integrate GroupState load
streetycat Feb 16, 2023
e491cb4
update example for GroupState
streetycat Feb 17, 2023
fbf5244
fix: path error
streetycat Feb 17, 2023
e9196b0
fix: commit storage
streetycat Feb 17, 2023
46babda
fix: type of pre-commits
streetycat Feb 17, 2023
f49ce3b
isolate for test example
streetycat Feb 17, 2023
ff0e2ba
isolate for test example
streetycat Feb 17, 2023
a36f7a3
fix: the round for the first block when restart
streetycat Feb 21, 2023
3e397a9
fix: first block with tc
streetycat Feb 22, 2023
e84c252
prepare for verify
streetycat Feb 22, 2023
33035e2
compile
streetycat Feb 22, 2023
ede4012
Verify the value on sub-path from anyone OOD in group
streetycat Feb 23, 2023
a5395e6
Example for APP-State as tree
streetycat Feb 24, 2023
9865525
Fix: Update the state structure, mount the template dec-state of bloc…
streetycat Feb 24, 2023
508904c
Accept the invalid block with vote it.
streetycat Feb 24, 2023
de22151
Chore unused code
streetycat Feb 24, 2023
78e7c26
get VerifiableState from the admin
streetycat Feb 27, 2023
de8b472
Fix: result-state verify failed
streetycat Feb 27, 2023
5f4584f
Redefine the Group object for Permission
streetycat Feb 28, 2023
f3d3baf
Simplify group definition
streetycat Mar 1, 2023
b942a2c
Move the interface to cyfs-lib
streetycat Mar 1, 2023
bb57a77
Remove the `decide` from proposal, It seems unuseful
streetycat Mar 2, 2023
472aabd
Prepare for export interface to SDK
streetycat Mar 2, 2023
ae2af4d
Implement the events with post_object
streetycat Mar 3, 2023
7db18c2
Rename `control` into `Service`
streetycat Mar 3, 2023
b41129d
Interface in client for DecAPP
streetycat Mar 3, 2023
f42fb9f
Interface in client for DecAPP events
streetycat Mar 3, 2023
0a938ae
Interface for client
streetycat Mar 7, 2023
d4e7a9e
Export to SDK
streetycat Mar 7, 2023
5707639
Remove several unused import
streetycat Mar 8, 2023
bea4e0d
Debug
streetycat Mar 10, 2023
a0e2a1e
Add service_version and preview relate supports into ood-daemon for b…
lurenpluto Feb 22, 2023
2b4925a
Add repeated loading supports to system-config.toml in ood-daemon
lurenpluto Feb 23, 2023
07cd55e
Review cyfs-perf-client, can write stat info to local file. use UniCy…
weiqiushi Feb 24, 2023
107917c
rebase from buckyos/main
streetycat Mar 10, 2023
f1eafc4
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 13, 2023
c4626c5
Adapte to the buckyos
streetycat Mar 13, 2023
8ead91c
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 13, 2023
17e47c5
Adapt interface of RootState, add param(owner)
streetycat Mar 13, 2023
23d5677
Testcase for client
streetycat Mar 14, 2023
39aa17d
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 14, 2023
f925d80
Complete the signature for group
streetycat Mar 14, 2023
e8abf5f
Response for proposal from RPathService
streetycat Mar 15, 2023
e081168
Split the function AnyNamedObject::raw_decode to little.
streetycat Mar 15, 2023
c135ff7
Fix: send cache packages after tunnel connection
jing-git Mar 14, 2023
327ad5e
Fix: Wrong path detection causes dec app installation or startup erro…
weiqiushi Mar 15, 2023
0fae145
Merge branch 'main' into buckyos
weiqiushi Mar 15, 2023
ad8274f
Zone for group
streetycat Mar 15, 2023
fe7627e
Fix: send cache packages after tunnel connection
jing-git Mar 14, 2023
b022487
Fix: Wrong path detection causes dec app installation or startup erro…
weiqiushi Mar 15, 2023
78478dc
Buckyos (#123)
streetycat Mar 15, 2023
c9d58d2
Ensure the result-state is exist on the GroupState
streetycat Mar 16, 2023
4a5876f
Timeout and retry to avoid the long-pending in NON
streetycat Mar 16, 2023
9119a61
Rebuild result-state by DEC.on_verify when it's download from remote …
streetycat Mar 16, 2023
1609d51
Add signature for desc
streetycat Mar 17, 2023
b9a8dda
Remove fields for rights in `Group`.
streetycat Apr 8, 2023
2177748
MetaChain: update group
streetycat Apr 8, 2023
9dd0ff0
Refuse group with empty admins
streetycat Apr 10, 2023
79334cc
Support `None` founder_id
streetycat Apr 10, 2023
5110294
`desc-tools` for `Group`
streetycat Apr 10, 2023
22dbb74
`desc-tool` for `Group`: debug
streetycat Apr 11, 2023
bc486b0
`desc-tool` read signer from `.desc`
streetycat Apr 11, 2023
63d44e1
Sort members by id for encode
streetycat Apr 11, 2023
510347c
Issue #199: Put the closure in heap to avoid the stack overflowed in …
streetycat Apr 12, 2023
33f4bbe
Merge branch 'main' into group-merge
streetycat Feb 15, 2023
aa62ed8
Merge branch 'main' into group-merge
streetycat Feb 15, 2023
9ed23c4
Merge pull request #3 from buckyos/group-merge
streetycat Feb 15, 2023
9c69afe
merge from buckyos
streetycat Feb 15, 2023
e37b4ee
rename GroupRPathMgr to GroupManager
streetycat Feb 15, 2023
e107bdf
integrate GroupState, not finish
streetycat Feb 15, 2023
33d229d
integrate GroupState update
streetycat Feb 16, 2023
09b6a67
integrate GroupState load
streetycat Feb 16, 2023
7e739f6
update example for GroupState
streetycat Feb 17, 2023
8df36eb
fix: path error
streetycat Feb 17, 2023
5080df0
fix: commit storage
streetycat Feb 17, 2023
dabb249
fix: type of pre-commits
streetycat Feb 17, 2023
d505e33
isolate for test example
streetycat Feb 17, 2023
eb2ec9d
isolate for test example
streetycat Feb 17, 2023
d224700
fix: the round for the first block when restart
streetycat Feb 21, 2023
54df3a4
fix: first block with tc
streetycat Feb 22, 2023
cea93a5
prepare for verify
streetycat Feb 22, 2023
c7681f5
compile
streetycat Feb 22, 2023
d530cc2
Verify the value on sub-path from anyone OOD in group
streetycat Feb 23, 2023
7c6acd5
Example for APP-State as tree
streetycat Feb 24, 2023
daeb0ea
Fix: Update the state structure, mount the template dec-state of bloc…
streetycat Feb 24, 2023
2d30374
Accept the invalid block with vote it.
streetycat Feb 24, 2023
abb2ae4
Chore unused code
streetycat Feb 24, 2023
ee43170
get VerifiableState from the admin
streetycat Feb 27, 2023
c47886f
Fix: result-state verify failed
streetycat Feb 27, 2023
8f05448
Redefine the Group object for Permission
streetycat Feb 28, 2023
4a6d79f
Simplify group definition
streetycat Mar 1, 2023
f3591ab
Move the interface to cyfs-lib
streetycat Mar 1, 2023
d6f9b6c
Remove the `decide` from proposal, It seems unuseful
streetycat Mar 2, 2023
36f15bd
Prepare for export interface to SDK
streetycat Mar 2, 2023
bc104af
Implement the events with post_object
streetycat Mar 3, 2023
07efe6d
Rename `control` into `Service`
streetycat Mar 3, 2023
92554e8
Interface in client for DecAPP
streetycat Mar 3, 2023
97de0c0
Interface in client for DecAPP events
streetycat Mar 3, 2023
e6e1613
Interface for client
streetycat Mar 7, 2023
7b8f6ed
Export to SDK
streetycat Mar 7, 2023
648659e
Remove several unused import
streetycat Mar 8, 2023
38f85ca
Debug
streetycat Mar 10, 2023
fed43a0
Add service_version and preview relate supports into ood-daemon for b…
lurenpluto Feb 22, 2023
f10fa39
Add repeated loading supports to system-config.toml in ood-daemon
lurenpluto Feb 23, 2023
ce96f37
Review cyfs-perf-client, can write stat info to local file. use UniCy…
weiqiushi Feb 24, 2023
19d2ec2
rebase from buckyos/main
streetycat Mar 10, 2023
a4f6416
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 13, 2023
065faf6
Adapte to the buckyos
streetycat Mar 13, 2023
23dce2c
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 13, 2023
709456b
Adapt interface of RootState, add param(owner)
streetycat Mar 13, 2023
e9d5480
Testcase for client
streetycat Mar 14, 2023
006952d
Merge pull request #3 from buckyos/group-merge
streetycat Feb 15, 2023
67c3a81
merge from buckyos
streetycat Feb 15, 2023
827b255
rename GroupRPathMgr to GroupManager
streetycat Feb 15, 2023
a082490
integrate GroupState, not finish
streetycat Feb 15, 2023
b1b419e
integrate GroupState update
streetycat Feb 16, 2023
d243a17
integrate GroupState load
streetycat Feb 16, 2023
bd402f5
update example for GroupState
streetycat Feb 17, 2023
fac8c67
fix: path error
streetycat Feb 17, 2023
d9187f5
fix: commit storage
streetycat Feb 17, 2023
ebba896
fix: type of pre-commits
streetycat Feb 17, 2023
055e3c5
isolate for test example
streetycat Feb 17, 2023
79a8bce
isolate for test example
streetycat Feb 17, 2023
00a37a0
fix: the round for the first block when restart
streetycat Feb 21, 2023
b8fdfe3
fix: first block with tc
streetycat Feb 22, 2023
c99b5e2
prepare for verify
streetycat Feb 22, 2023
dc17e28
compile
streetycat Feb 22, 2023
00f92a6
Verify the value on sub-path from anyone OOD in group
streetycat Feb 23, 2023
1dad2ec
Example for APP-State as tree
streetycat Feb 24, 2023
09dcf2a
Fix: Update the state structure, mount the template dec-state of bloc…
streetycat Feb 24, 2023
b4bffb5
Accept the invalid block with vote it.
streetycat Feb 24, 2023
bee578f
Chore unused code
streetycat Feb 24, 2023
de6c912
get VerifiableState from the admin
streetycat Feb 27, 2023
70e8425
Fix: result-state verify failed
streetycat Feb 27, 2023
2286876
Redefine the Group object for Permission
streetycat Feb 28, 2023
02d7727
Simplify group definition
streetycat Mar 1, 2023
1e44e73
Move the interface to cyfs-lib
streetycat Mar 1, 2023
363e060
Remove the `decide` from proposal, It seems unuseful
streetycat Mar 2, 2023
a943eab
Prepare for export interface to SDK
streetycat Mar 2, 2023
d334a09
Implement the events with post_object
streetycat Mar 3, 2023
521bf5e
Rename `control` into `Service`
streetycat Mar 3, 2023
3eaf5b9
Interface in client for DecAPP
streetycat Mar 3, 2023
422b2bb
Interface in client for DecAPP events
streetycat Mar 3, 2023
18935b9
Interface for client
streetycat Mar 7, 2023
b5b39af
Export to SDK
streetycat Mar 7, 2023
cd3cc38
Remove several unused import
streetycat Mar 8, 2023
3bf51f8
Debug
streetycat Mar 10, 2023
99ada9d
Add service_version and preview relate supports into ood-daemon for b…
lurenpluto Feb 22, 2023
559efdf
Add repeated loading supports to system-config.toml in ood-daemon
lurenpluto Feb 23, 2023
7886b59
Review cyfs-perf-client, can write stat info to local file. use UniCy…
weiqiushi Feb 24, 2023
e3510ac
rebase from buckyos/main
streetycat Mar 10, 2023
6fffc4b
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 13, 2023
0560864
Adapte to the buckyos
streetycat Mar 13, 2023
c198947
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 13, 2023
ec6ad35
Adapt interface of RootState, add param(owner)
streetycat Mar 13, 2023
9b30a7c
Testcase for client
streetycat Mar 14, 2023
bc27426
Merge remote-tracking branch 'origin/main' into main
streetycat Mar 14, 2023
3734469
Complete the signature for group
streetycat Mar 14, 2023
01ca46f
Response for proposal from RPathService
streetycat Mar 15, 2023
b5123ba
Zone for group
streetycat Mar 15, 2023
3d62581
Buckyos (#123)
streetycat Mar 15, 2023
e8932a9
Ensure the result-state is exist on the GroupState
streetycat Mar 16, 2023
8057f4c
Timeout and retry to avoid the long-pending in NON
streetycat Mar 16, 2023
000a042
Rebuild result-state by DEC.on_verify when it's download from remote …
streetycat Mar 16, 2023
4c9270f
Add signature for desc
streetycat Mar 17, 2023
06f66fb
Remove fields for rights in `Group`.
streetycat Apr 8, 2023
6139163
MetaChain: update group
streetycat Apr 8, 2023
3256def
Refuse group with empty admins
streetycat Apr 10, 2023
2318c47
Support `None` founder_id
streetycat Apr 10, 2023
fffca53
`desc-tools` for `Group`
streetycat Apr 10, 2023
26daa3c
`desc-tool` for `Group`: debug
streetycat Apr 11, 2023
654febe
`desc-tool` read signer from `.desc`
streetycat Apr 11, 2023
bf63043
Sort members by id for encode
streetycat Apr 11, 2023
00d57f9
Merge remote-tracking branch 'origin/main' into main
streetycat Apr 12, 2023
c8de679
Remove unused export
streetycat Apr 12, 2023
638ebe6
`ObjectShell` for `Group`
streetycat Apr 13, 2023
9258f5d
Fix bugs for `ObjectShell`
streetycat Apr 14, 2023
35861f0
Verify group-zone by `MetaChain`
streetycat Apr 14, 2023
0a37078
Hold lifespan of the history versions of group in `ObjectShell` on `G…
streetycat Apr 15, 2023
9af8958
Add group_shell_id field in Timeout
streetycat Apr 19, 2023
dadb628
Update the `ObjectShell` as a standalone type
streetycat Apr 20, 2023
20fb5f5
Synchronizer
streetycat Apr 21, 2023
f4b17d1
Fix several bugs of synchronization
streetycat Apr 23, 2023
7b9fddc
Debug ok for add oods.
streetycat Apr 25, 2023
acdb5c9
Merge branch 'group' into Issue_#71
streetycat May 12, 2023
a062097
Adapt the parameters
streetycat May 12, 2023
da2337f
Remove StandardObject::SimpleGroup and StandardObject::Org
streetycat May 13, 2023
b0419e7
Use `increase_update_time` to ensure that `update-time` is incrementa…
streetycat May 13, 2023
beec9d0
rename some identify
streetycat May 13, 2023
ceada20
Translate chinese to english and remove redundant parameters
streetycat May 15, 2023
533e8e7
Remove unusefull fields in RPC
streetycat May 16, 2023
c2bfcaf
Combine the `GroupInputRequestCommon` with the request parameters.
streetycat May 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ members = [
"./component/cyfs-chunk-lib",
"./component/cyfs-mobile-stack",
"./component/cyfs-bdt-ext",
"./component/cyfs-group-lib",
"./component/cyfs-group",

"./service/ood-control",
"./service/ood-daemon",
Expand Down Expand Up @@ -74,6 +76,7 @@ members = [
"./tests/cyfs-stack-test",
"./tests/cyfs-bench-mark",
"./tests/cyfs-stack-bench",
"./tests/group-example",
]

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion src/component/cyfs-backup/src/state_backup/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl RootObjectCategoryManager {
list.push(item);

let item = RootObjectCategory {
object_type: ObjectTypeCode::SimpleGroup.to_u16(),
object_type: ObjectTypeCode::Group.to_u16(),
ref_depth: 0,
};
list.push(item);
Expand Down
1 change: 1 addition & 0 deletions src/component/cyfs-base-meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ serde_json = '1.0'
hex = '0.4.2'
async-trait = '0.1.53'
async-std = '1.11'
futures = '0.3.25'
primitive-types = { version = '0.9' }
codec = { package = 'parity-scale-codec', version = '2.0', default-features = false, features = ['derive', 'full'], optional = true }
238 changes: 238 additions & 0 deletions src/component/cyfs-base-meta/src/group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
use std::collections::HashSet;

use cyfs_base::{
BuckyError, BuckyErrorCode, BuckyResult, Group, NamedObject, ObjectDesc, ObjectId,
ObjectTypeCode, People, PeopleId, RawEncode, RsaCPUObjectVerifier, Signature,
SingleKeyObjectDesc, Verifier,
};
use cyfs_core::ToGroupShell;

async fn verify_signature(
signs: Option<&Vec<Signature>>,
data_buf: &[u8],
verifier: &RsaCPUObjectVerifier,
signer_id: &PeopleId,
) -> BuckyResult<()> {
let signs = signs.map_or([].as_slice(), |s| s.as_slice());
let sign = signs.iter().find(|s| match s.sign_source() {
cyfs_base::SignatureSource::Object(signer) => &signer.obj_id == signer_id.object_id(),
_ => false,
});

match sign {
Some(sign) => {
if verifier.verify(data_buf, sign).await {
Ok(())
} else {
let msg = format!("Invalid signature from {}", signer_id);
log::warn!("{}", msg);
Err(BuckyError::new(BuckyErrorCode::InvalidSignature, msg))
}
}
None => {
let msg = format!("Not found signature from {}", signer_id);
log::warn!("{}", msg);
Err(BuckyError::new(BuckyErrorCode::NotFound, msg))
}
}
}

async fn verify_group_signature(
group: &Group,
people_id: &PeopleId,
member_querier: &impl MemberQuerier,
) -> BuckyResult<()> {
let people = member_querier.get_people(people_id).await?;
let verifier = RsaCPUObjectVerifier::new(people.desc().public_key().clone());
let desc_buf = group.desc().raw_hash_value()?;
verify_signature(
group.signs().desc_signs(),
desc_buf.as_slice(),
&verifier,
people_id,
)
.await?;
let body_buf = group.body().as_ref().unwrap().raw_hash_value()?;
verify_signature(
group.signs().body_signs(),
body_buf.as_slice(),
&verifier,
people_id,
)
.await
}

#[async_trait::async_trait]
pub trait MemberQuerier: Send + Sync {
async fn get_people(&self, people_id: &PeopleId) -> BuckyResult<People>;
}

#[async_trait::async_trait]
pub trait GroupVerifier {
// Check the update is allowed
async fn is_update_valid(
&self,
latest_group: Option<&Group>,
member_querier: &impl MemberQuerier,
) -> BuckyResult<()>;
}

#[async_trait::async_trait]
impl GroupVerifier for Group {
async fn is_update_valid(
&self,
latest_group: Option<&Group>,
member_querier: &impl MemberQuerier,
) -> BuckyResult<()> {
let group_id = self.desc().object_id();

if self.admins().len() == 0 {
let msg = format!("Update group({}) with no admins.", group_id);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::Failed, msg));
}

let (last_admins, last_members) = match latest_group {
Some(latest_group) => {
let latest_group_id = latest_group.desc().object_id();
if group_id != latest_group_id {
let msg = format!(
"The new group({}) is unmatch with the latest group({}).",
group_id, latest_group_id
);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::Unmatch, msg));
}

let latest_group_shell = latest_group.to_shell();
let latest_group_shell_id = latest_group_shell.shell_id();
if self.version() != latest_group.version() + 1
|| self.prev_shell_id() != &Some(latest_group_shell_id)
{
let msg = format!("Attempt to update group({}) from unknown version({}-1/{:?}), latest version: {}/{}.", group_id, self.version(), self.prev_shell_id(), latest_group.version(), latest_group_shell_id);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::Unmatch, msg));
}

(
HashSet::<ObjectId>::from_iter(
latest_group
.admins()
.keys()
.filter(|m| m.obj_type_code() == ObjectTypeCode::People)
.map(|m| *m),
),
HashSet::<ObjectId>::from_iter(
latest_group
.members()
.keys()
.filter(|m| m.obj_type_code() == ObjectTypeCode::People)
.map(|m| *m),
),
)
}
None => match self.prev_shell_id() {
Some(prev_shell_id) => {
let msg = format!(
"The latest group({}) is necessary for update. prev_shell_id: {}",
group_id, prev_shell_id
);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::Unmatch, msg));
}
None => {
if let Some(founder) = self.founder_id() {
if self.admins().values().find(|m| &m.id == founder).is_none() {
let msg = format!(
"Update group({}) the founder({}) must be an administrator.",
group_id, founder
);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::Failed, msg));
}
}
(HashSet::new(), HashSet::new())
}
},
};

// admins: > 1/2
// new members: all

let add_admins = HashSet::<ObjectId>::from_iter(
self.admins()
.keys()
.filter(|m| {
m.obj_type_code() == ObjectTypeCode::People && !last_admins.contains(*m)
})
.map(|m| *m),
);
let add_members = HashSet::<ObjectId>::from_iter(
self.members()
.keys()
.filter(|m| {
m.obj_type_code() == ObjectTypeCode::People && !last_members.contains(*m)
})
.map(|m| *m),
);

let additionals = add_admins
.union(&add_members)
.map(|id| *id)
.collect::<Vec<_>>();
if additionals.len() != add_admins.len() + add_members.len() {
let msg = format!(
"Update group({}) with admins is not necessary in members.",
group_id
);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::Failed, msg));
}

let check_peoples =
futures::future::join_all(last_admins.iter().chain(additionals.iter()).map(
|people_id| async move {
let people_id = PeopleId::try_from(people_id).unwrap();
verify_group_signature(self, &people_id, member_querier).await
},
))
.await;

let (last_admin_signs, add_member_signs) = check_peoples.split_at(last_admins.len());
let last_admin_sign_count = last_admin_signs.iter().filter(|s| s.is_ok()).count();
if last_admins.len() > 0 && last_admin_sign_count <= last_admins.len() / 2 {
let msg = format!(
"Update group({}) failed for signatures from admins in latest version is not enough: expected {}, got {}.",
group_id,
last_admins.len() / 2 + 1,
last_admin_sign_count
);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::InvalidSignature, msg));
}

let failed_add_member_sign_pos = add_member_signs.iter().position(|s| s.is_err());
match failed_add_member_sign_pos {
Some(pos) => {
let msg = format!(
"Update group({}) failed for signatures from additional member({:?}) is invalid.",
group_id,
additionals.get(pos)
);
log::warn!("{}", msg);
return Err(BuckyError::new(BuckyErrorCode::InvalidSignature, msg));
}
None => {
log::info!(
"Update group({}) verify ok, from {:?}/{:?}, to {}/{}",
group_id,
latest_group.map(|group| group.version()),
self.prev_shell_id(),
self.version(),
self.to_shell().shell_id()
);
Ok(())
}
}
}
}
26 changes: 14 additions & 12 deletions src/component/cyfs-base-meta/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
extern crate alloc;

pub use block::*;
pub use code::*;
pub use config::*;
pub use contract::*;
pub use event::*;
pub use extension::*;
pub use group::*;
pub use nft::*;
pub use sn_service::*;
pub use spv::*;
pub use tx::*;
pub use types::*;
pub use view::*;
pub use code::*;
pub use contract::*;
pub use nft::*;

mod types;
mod config;
mod block;
mod view;
mod event;
mod tx;
mod sn_service;
mod spv;
mod extension;
mod code;
mod config;
mod contract;
mod nft;
mod event;
pub mod evm_def;
mod extension;
mod group;
mod nft;
mod sn_service;
mod spv;
mod tx;
mod types;
mod view;
Loading