Skip to content

Commit e8e08e2

Browse files
author
80347547
committed
feat(p2p-04): add client p2p module shell
1 parent 9e4f0ba commit e8e08e2

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

curvine-client/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use orpc::sys::DataSlice;
1717

1818
pub mod block;
1919
pub mod file;
20+
pub mod p2p;
2021
pub mod rpc;
2122
pub mod unified;
2223

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2025 OPPO.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#[derive(Debug, Clone, PartialEq, Eq)]
16+
pub struct DiscoveryPeerSnapshot {
17+
pub peer_id: String,
18+
pub addrs: Vec<String>,
19+
}
20+
21+
#[derive(Debug, Clone, Default, PartialEq, Eq)]
22+
pub struct DiscoverySnapshot {
23+
pub mdns_peers: Vec<DiscoveryPeerSnapshot>,
24+
pub dht_peers: Vec<DiscoveryPeerSnapshot>,
25+
pub bootstrap_peers: Vec<DiscoveryPeerSnapshot>,
26+
}

curvine-client/src/p2p/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2025 OPPO.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod discovery;
16+
pub use self::discovery::{DiscoveryPeerSnapshot, DiscoverySnapshot};
17+
18+
mod transfer;
19+
pub use self::transfer::{ChunkId, TransferRequest, TransferResponse};

curvine-client/src/p2p/transfer.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2025 OPPO.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use bytes::Bytes;
16+
17+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18+
pub struct ChunkId {
19+
pub file_id: i64,
20+
pub version_epoch: i64,
21+
pub block_id: i64,
22+
pub off: i64,
23+
}
24+
25+
impl ChunkId {
26+
pub fn new(block_id: i64, off: i64) -> Self {
27+
Self::with_version(0, 0, block_id, off)
28+
}
29+
30+
pub fn with_version(file_id: i64, version_epoch: i64, block_id: i64, off: i64) -> Self {
31+
Self {
32+
file_id,
33+
version_epoch,
34+
block_id,
35+
off,
36+
}
37+
}
38+
}
39+
40+
#[derive(Debug, Clone, PartialEq, Eq)]
41+
pub struct TransferRequest {
42+
pub chunk_id: ChunkId,
43+
pub len: usize,
44+
}
45+
46+
#[derive(Debug, Clone, PartialEq, Eq)]
47+
pub struct TransferResponse {
48+
pub chunk_id: ChunkId,
49+
pub data: Bytes,
50+
}

0 commit comments

Comments
 (0)