Skip to content

Commit 53bd428

Browse files
dvc94chelenaf9
authored andcommitted
Initial commit.
1 parent c13f033 commit 53bd428

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ categories = ["network-programming", "asynchronous"]
1111

1212
[features]
1313
default = [
14+
"autonat",
1415
"deflate",
1516
"dns-async-std",
1617
"floodsub",
@@ -33,6 +34,7 @@ default = [
3334
"websocket",
3435
"yamux",
3536
]
37+
autonat = ["libp2p-autonat"]
3638
deflate = ["libp2p-deflate"]
3739
dns-async-std = ["libp2p-dns", "libp2p-dns/async-std"]
3840
dns-tokio = ["libp2p-dns", "libp2p-dns/tokio"]
@@ -68,6 +70,7 @@ atomic = "0.5.0"
6870
bytes = "1"
6971
futures = "0.3.1"
7072
lazy_static = "1.2"
73+
libp2p-autonat = { version = "0.20.0", path = "protocols/autonat", optional = true }
7174
libp2p-core = { version = "0.30.0", path = "core", default-features = false }
7275
libp2p-floodsub = { version = "0.31.0", path = "protocols/floodsub", optional = true }
7376
libp2p-gossipsub = { version = "0.33.0", path = "./protocols/gossipsub", optional = true }
@@ -116,6 +119,7 @@ members = [
116119
"misc/peer-id-generator",
117120
"muxers/mplex",
118121
"muxers/yamux",
122+
"protocols/autonat",
119123
"protocols/floodsub",
120124
"protocols/gossipsub",
121125
"protocols/rendezvous",

protocols/autonat/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "libp2p-autonat"
3+
version = "0.20.0"
4+
authors = ["David Craven <david@craven.ch>"]
5+
edition = "2018"
6+
license = "MIT"
7+
repository = "https://github.com/libp2p/rust-libp2p"
8+
keywords = ["peer-to-peer", "libp2p", "networking"]
9+
categories = ["network-programming", "asynchronous"]
10+
11+
[build-dependencies]
12+
prost-build = "0.6"
13+
14+
[dependencies]
15+
libp2p-core = { version = "0.30.0", path = "../../core" }
16+
libp2p-swarm = { version = "0.31.0", path = "../../swarm" }
17+
prost = "0.8.0"

protocols/autonat/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2020 Parity Technologies (UK) Ltd.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the "Software"),
5+
// to deal in the Software without restriction, including without limitation
6+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
// and/or sell copies of the Software, and to permit persons to whom the
8+
// Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
// DEALINGS IN THE SOFTWARE.
20+
21+
fn main() {
22+
prost_build::compile_protos(&["src/structs.proto"], &["src"]).unwrap();
23+
}

protocols/autonat/src/autonat.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 Parity Technologies (UK) Ltd.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the "Software"),
5+
// to deal in the Software without restriction, including without limitation
6+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
// and/or sell copies of the Software, and to permit persons to whom the
8+
// Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
// DEALINGS IN THE SOFTWARE.
20+
21+
pub struct AutoNat;
22+
23+
pub enum AutoNatEvent {}

protocols/autonat/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 Parity Technologies (UK) Ltd.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the "Software"),
5+
// to deal in the Software without restriction, including without limitation
6+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
// and/or sell copies of the Software, and to permit persons to whom the
8+
// Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
// DEALINGS IN THE SOFTWARE.
20+
21+
//! Implementation of the [AutoNAT] protocol.
22+
23+
pub use self::autonat::{AutoNat, AutoNatEvent};
24+
25+
mod autonat;
26+
27+
mod structs_proto {
28+
include!(concat!(env!("OUT_DIR"), "/structs.rs"));
29+
}

protocols/autonat/src/structs.proto

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
syntax = "proto2";
2+
3+
package structs;
4+
5+
message Message {
6+
enum MessageType {
7+
DIAL = 0;
8+
DIAL_RESPONSE = 1;
9+
}
10+
11+
enum ResponseStatus {
12+
OK = 0;
13+
E_DIAL_ERROR = 100;
14+
E_DIAL_REFUSED = 101;
15+
E_BAD_REQUEST = 200;
16+
E_INTERNAL_ERROR = 300;
17+
}
18+
19+
message PeerInfo {
20+
optional bytes id = 1;
21+
repeated bytes addrs = 2;
22+
}
23+
24+
message Dial {
25+
optional PeerInfo peer = 1;
26+
}
27+
28+
message DialResponse {
29+
optional ResponseStatus status = 1;
30+
optional string statusText = 2;
31+
optional bytes addr = 3;
32+
}
33+
34+
optional MessageType type = 1;
35+
optional Dial dial = 2;
36+
optional DialResponse dialResponse = 3;
37+
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ pub use libp2p_core::multihash;
4040
#[doc(inline)]
4141
pub use multiaddr;
4242

43+
#[cfg(feature = "autonat")]
44+
#[cfg_attr(docsrs, doc(cfg(feature = "autonat")))]
45+
#[doc(inline)]
46+
pub use libp2p_autonat as autonat;
4347
#[doc(inline)]
4448
pub use libp2p_core as core;
4549
#[cfg(feature = "deflate")]

0 commit comments

Comments
 (0)