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

QUIC support #1334

Closed
wants to merge 247 commits into from
Closed
Show file tree
Hide file tree
Changes from 158 commits
Commits
Show all changes
247 commits
Select commit Hold shift + click to select a range
7492883
Add libp2p-transport-quic crate
Demi-Marie Nov 17, 2019
1f98ed9
Add copyright notice and beginnings of a transport
Demi-Marie Nov 19, 2019
52b8614
Bogus implementation that at least compiles
Demi-Marie Nov 21, 2019
b544f67
Remove an `unimplemented!`
Demi-Marie Nov 21, 2019
432c1b6
Report peer addresses
Demi-Marie Nov 21, 2019
606ede2
Remove code duplication between QUIC and TCP transports
Demi-Marie Nov 21, 2019
10f16ba
Switch back to quinn master
Demi-Marie Nov 21, 2019
bf184c5
Implement `dial`
Demi-Marie Nov 24, 2019
2157f52
Add `use` lines for std future related types
Demi-Marie Nov 24, 2019
b4fd310
Initial StreamMuxer impl
Demi-Marie Nov 30, 2019
752c844
Last version using ‘quinn’
Demi-Marie Dec 1, 2019
202ccda
Compiling (but not working) quinn-proto based libp2p-quic
Demi-Marie Dec 4, 2019
3a0ba66
More progress on libp2p-quic
Demi-Marie Dec 5, 2019
3c27505
The doc test passes!
Demi-Marie Dec 6, 2019
24728a6
Merge branch 'stable-futures' into demi-quic-stable-futures
Demi-Marie Dec 6, 2019
49ebd43
Preserve order of outgoing connections
Demi-Marie Dec 9, 2019
974d117
Test suite compiles!
Demi-Marie Dec 9, 2019
c8ae241
Handle making new connections
Demi-Marie Dec 11, 2019
b35d42a
Merge branch 'stable-futures' into demi-quic-stable-futures
Demi-Marie Dec 12, 2019
e47e5de
All tests compile
Demi-Marie Dec 13, 2019
f19dd46
Remove remaining unimplemented!()
Demi-Marie Dec 14, 2019
67307a3
Merge branch 'stable-futures' into demi-quic-stable-futures
Demi-Marie Dec 16, 2019
f26323c
Simple fixes
Demi-Marie Dec 17, 2019
5ca62ae
Implement sending messages
Demi-Marie Dec 18, 2019
40221da
Pin futures_codec to avoid compilation errors
Demi-Marie Dec 20, 2019
5bf85dc
Fix the rest of the compiler errors
Demi-Marie Dec 20, 2019
67bea72
Bump dependencies
Demi-Marie Dec 21, 2019
2d0c619
Merge branch 'dm-bump-deps' into demi-quic-stable-futures
Demi-Marie Dec 21, 2019
7d9d200
Implement complete QUIC protocol logic
Demi-Marie Dec 22, 2019
804cf95
Fix warning in testsuite
Demi-Marie Dec 23, 2019
514ee6b
Switch to parking_lot
Demi-Marie Dec 23, 2019
827424d
Outbound connections must fail when a connection is lost
Demi-Marie Dec 23, 2019
ac74e6b
Add missing wakeups
Demi-Marie Dec 23, 2019
5395065
Move all of the driver-waking code into a single function
Demi-Marie Dec 23, 2019
9c2f14d
Consolodate the I/O code
Demi-Marie Dec 23, 2019
59d2065
Refactor some common code
Demi-Marie Dec 23, 2019
98cd81a
More cleanups
Demi-Marie Dec 24, 2019
7a43bf0
Formatting cleanups
Demi-Marie Dec 27, 2019
7406e18
Implement certificate generation for libp2p
Demi-Marie Dec 27, 2019
0914f09
Start working on certificate verification
Demi-Marie Dec 28, 2019
f78c89f
Add connection.rs
Demi-Marie Dec 28, 2019
9f5b847
Finish X.509 parsing
Demi-Marie Dec 30, 2019
9e2c63a
Some wrong attempts at certificate verification
Demi-Marie Dec 31, 2019
b8091e4
Use webpki to verify the certificate self-signature
Demi-Marie Dec 31, 2019
2f135c1
Remove spurious debug assertion
Demi-Marie Dec 31, 2019
fbc7e94
Remove commented-out code and excessive logging
Demi-Marie Dec 31, 2019
0bfe0d0
Cleanup certificate verification
Demi-Marie Dec 31, 2019
20f63a4
Remove connection.rs
Demi-Marie Dec 31, 2019
b02cf2e
Get QUIC connections to work
Demi-Marie Jan 1, 2020
9d8c151
Merge branch 'stable-futures' into demi-quic-stable-futures
Demi-Marie Jan 2, 2020
b8b9907
Fix the tests to avoid hangs
Demi-Marie Jan 3, 2020
bb8dd01
testing
Demi-Marie Jan 3, 2020
ef68cb2
Actually accept connections
Demi-Marie Jan 3, 2020
5213f6c
Ensure the driver can actually be woken up
Demi-Marie Jan 4, 2020
920812d
Merge branch 'stable-futures' into demi-quic-stable-futures
Demi-Marie Jan 6, 2020
b7ea623
Futures need to be polled to completion!
Demi-Marie Jan 6, 2020
a6be20e
Clean up the driver and I/O code
Demi-Marie Jan 6, 2020
e765ca8
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Jan 6, 2020
a56a6af
Go much farther before hanging
Demi-Marie Jan 6, 2020
44a6cfb
Make libp2p-quic more robust
Demi-Marie Jan 6, 2020
cc80c1a
Cleanups
Demi-Marie Jan 7, 2020
60dc020
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Jan 7, 2020
040d986
Futures portion of libp2p-quic almost complete
Demi-Marie Jan 9, 2020
4dc5f46
Move the endpoint code into a separate module
Demi-Marie Jan 14, 2020
b6d137b
Sending outgoing traffic must not block processing incoming traffic
Demi-Marie Jan 15, 2020
5e56934
Another failed attempt to fix the hang!
Demi-Marie Jan 17, 2020
d4c6ab1
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Jan 17, 2020
e684c1e
Hopefully fix the hangs
Demi-Marie Jan 17, 2020
522cb33
Fix the hangs for real
Demi-Marie Jan 18, 2020
a5a4cd0
Fix wildcard_expansion test case
Demi-Marie Jan 18, 2020
6ab6114
Don’t use keep alives
Demi-Marie Jan 19, 2020
60a40af
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Jan 22, 2020
7d39812
Add a keep-alive interval to prevent spurious timeouts
Demi-Marie Jan 22, 2020
d7bbbe1
Don’t use Poll::{self, Pending, Ready}
Demi-Marie Jan 22, 2020
9b98ad8
Do not check for ECONNRESET on transmit
Demi-Marie Jan 22, 2020
a30fe76
Refactor networking code
Demi-Marie Jan 22, 2020
0aba2f2
Cleanup I/O paths
Demi-Marie Jan 23, 2020
7c10638
Return peer IDs from Transport impl
Demi-Marie Jan 24, 2020
30c2a1a
Sending endpoint events could require checking for timers
Demi-Marie Jan 25, 2020
62b1f7e
Move the connection code to its own module
Demi-Marie Jan 27, 2020
b2564d4
Don’t rely on a fork of `async-std`
Demi-Marie Jan 28, 2020
3d73033
Avoid a panic and work around a quinn-proto bug
Demi-Marie Jan 29, 2020
5e479bd
Remove unnecessary #[allow(dead_code)]
Demi-Marie Jan 29, 2020
01dca1d
Handle a critical Basic Constraints extension
Demi-Marie Jan 29, 2020
2f33051
Let WebPKI verify the certificate self-signature
Demi-Marie Jan 29, 2020
28b889f
Add error file
Demi-Marie Jan 29, 2020
88400d5
Split up certificate verification
Demi-Marie Jan 29, 2020
e21c7de
Merge branch 'master' into merged
Demi-Marie Jan 29, 2020
c4a86a0
Simplify certificate verification
Demi-Marie Jan 30, 2020
535dda5
Clean up certificate verification code
Demi-Marie Jan 31, 2020
e8ea100
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Jan 31, 2020
6b3ca09
Don’t try to use `ifaddrs` in the browser
Demi-Marie Jan 31, 2020
0f22699
Remove ugly workaround and clean up some code
Demi-Marie Feb 2, 2020
05fae6b
Return an error if an unwritten stream is read
Demi-Marie Feb 3, 2020
7e6029c
Reading from an unwritten stream must fail
Demi-Marie Feb 4, 2020
d678cc4
Refactor connection code
Demi-Marie Feb 4, 2020
a243363
Fix clippy lints and test endpoint shutdown
Demi-Marie Feb 4, 2020
204b9c2
Only forbid warnings when testing
Demi-Marie Feb 4, 2020
35cbc16
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 4, 2020
6fe9091
Add Cargo metadata
Demi-Marie Feb 4, 2020
13e0eb2
Wake up the endpoint driver when needed
Demi-Marie Feb 4, 2020
d54f069
Respond to code review and fix tests
Demi-Marie Feb 6, 2020
6b74ccb
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 6, 2020
8ef346d
Move EndpointMessage to endpoint.rs
Demi-Marie Feb 6, 2020
a105db5
Reformat
Demi-Marie Feb 6, 2020
ee97e31
Move the configuration code into the endpoint
Demi-Marie Feb 6, 2020
e22d2a7
Fix comment
Demi-Marie Feb 7, 2020
e002946
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 7, 2020
ded54d5
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 10, 2020
1f51fd6
Fix broken links in rustdoc
Demi-Marie Feb 10, 2020
f87a4f2
Apply suggestions from code review
Demi-Marie Feb 12, 2020
82755aa
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 12, 2020
2d5981a
Refactor as per @tomaka’s suggestion
Demi-Marie Feb 12, 2020
6db3d49
Implement Transport for Endpoint
Demi-Marie Feb 12, 2020
f3e9fca
QUIC is not QUIC/UDP/IP
Demi-Marie Feb 12, 2020
7fef35f
Avoid &Arc<Self>, as it is unstable.
Demi-Marie Feb 12, 2020
7fe8d67
Merge branch 'demi-quic-stable-futures' of github.com:DemiMarie-parit…
Demi-Marie Feb 12, 2020
40895c2
Avoid references from connection to endpoint
Demi-Marie Feb 12, 2020
599154f
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 12, 2020
321f776
Avoid use of deprecated elided lifetimes
Demi-Marie Feb 13, 2020
36c2e7b
Add a bunch of documentation
Demi-Marie Feb 13, 2020
7e119f5
Fix broken links in documentation
Demi-Marie Feb 13, 2020
df9a149
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 13, 2020
2d8d15c
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 18, 2020
dfe12a8
Bump dependencies of libp2p-quic (only)
Demi-Marie Feb 18, 2020
c18e88e
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 20, 2020
d6794af
Be more selective about enabling lints
Demi-Marie Feb 20, 2020
96aff73
Merge the connection hashmaps and split them into a separate module
Demi-Marie Feb 21, 2020
c851d8b
`Muxer` now uses a wrapper around `Connection`
Demi-Marie Feb 21, 2020
984b75d
Consolidate error messages
Demi-Marie Feb 24, 2020
ba1c5fb
Tests should not require `Outbound` to implement `Stream`
Demi-Marie Feb 24, 2020
0a2a423
Outbound should not implement Future
Demi-Marie Feb 24, 2020
25eb755
Move timer and last timeout to ConnectionDriver
Demi-Marie Feb 24, 2020
5821540
Enhanced logging
Demi-Marie Feb 25, 2020
40e81fe
Fix shutdown and clean up the code
Demi-Marie Feb 25, 2020
b2815d8
Fix doc comments and bump dependencies
Demi-Marie Feb 25, 2020
c99784d
Fix compilation error in websockets
Demi-Marie Feb 25, 2020
e2e75b0
Adapt to changed rustls API
Demi-Marie Feb 25, 2020
557b2a8
Fix error handling
Demi-Marie Feb 26, 2020
487ae32
Use the public type alias for ‘DistinguishedNames’
Demi-Marie Feb 26, 2020
d43ecbc
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Feb 26, 2020
4753706
Fix intra-rustdoc links
Demi-Marie Feb 27, 2020
88d5b45
Use a temporary fork of webpki
Demi-Marie Feb 28, 2020
245b746
Adapt to changed extension handling API in webpki
Demi-Marie Feb 28, 2020
103bd74
Delete unneeded code and refactor
Demi-Marie Feb 28, 2020
a9197a0
Simplify code even more
Demi-Marie Feb 28, 2020
212f4f9
Clean up certificate verification
Demi-Marie Mar 1, 2020
579ce9e
Refactor TLS and connection code
Demi-Marie Mar 1, 2020
7775c1f
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Mar 1, 2020
45793ca
Move libp2p-tls to its own crate
Demi-Marie Mar 1, 2020
04edc7e
Move stream_map and stream up a directory
Demi-Marie Mar 3, 2020
fd358e3
Move task wakeup into stream_map.rs
Demi-Marie Mar 3, 2020
b107974
Inline functions used only once
Demi-Marie Mar 4, 2020
6e1205d
Remove git submodule
Demi-Marie Mar 4, 2020
9e3ef0c
More cleanups
Demi-Marie Mar 4, 2020
50e1053
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Mar 4, 2020
b5b1d10
Fix panic when connection closed too soon
Demi-Marie Mar 7, 2020
9574e01
Be more rigorous about send stream counts
Demi-Marie Mar 8, 2020
5cba805
Use quinn-proto’s built-in send stream count
Demi-Marie Mar 8, 2020
dcf0f42
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Mar 8, 2020
d9c2c67
Use a patch instead of a git dependency
Demi-Marie Mar 8, 2020
4d6c709
Apply suggestions from Max Inden
Demi-Marie Mar 10, 2020
fa935ce
Cleanup docs and remove a callback
Demi-Marie Mar 10, 2020
5bd1743
Add a span for each test run
Demi-Marie Mar 10, 2020
c2d798a
Switch to a working quinn-proto branch
Demi-Marie Mar 11, 2020
a20f95a
Move the multiaddr to the configuration
Demi-Marie Mar 11, 2020
9528dc7
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Mar 15, 2020
8f13f20
Switch back to quinn-proto master
Demi-Marie Mar 15, 2020
8dc4a0a
Fix compilation of tests
Demi-Marie Mar 16, 2020
6c072c9
Implement alternate X.509 verifier
Demi-Marie Mar 17, 2020
ece2ff2
Fix doc tests
Demi-Marie Mar 17, 2020
26fc93b
protocols/tls needs dangerous_configuration
Demi-Marie Mar 17, 2020
fc39b7b
Refactor certificate verification code
Demi-Marie Mar 17, 2020
77fa579
Revert "Refactor certificate verification code"
Demi-Marie Mar 18, 2020
2b701b9
Distinguished unsupported from mismatching signature algorithms
Demi-Marie Mar 18, 2020
35421b6
Replace the old webpki-based verifier
Demi-Marie Mar 19, 2020
ac25552
Minor cleanups
Demi-Marie Mar 20, 2020
050e6e4
Remove use of webpki in certificate verification
Demi-Marie Mar 20, 2020
817851c
Use a working quinn-proto version
Demi-Marie Mar 22, 2020
7666267
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Mar 22, 2020
d2ef7d2
Remove unneeded feature in yasna
Demi-Marie Mar 22, 2020
6362998
Packets cannot send themselves
Demi-Marie Mar 23, 2020
c775c93
Send an empty distinguished name
Demi-Marie Mar 24, 2020
9395b1d
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Mar 24, 2020
4017506
Make tracing optional
Demi-Marie Mar 26, 2020
c3c9393
Update description of libp2p-tls
Demi-Marie Mar 26, 2020
d0ab229
libp2p-tls → libp2p-x509
Demi-Marie Mar 26, 2020
5307280
Fix silly macro error
Demi-Marie Mar 26, 2020
eff0ec8
Bump async-tls
Demi-Marie Mar 30, 2020
d013863
Merge branch 'better-async-tls' into demi-quic-stable-futures
Demi-Marie Mar 30, 2020
729a845
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Apr 3, 2020
def5bd6
Fix silly typos in Cargo.toml
Demi-Marie Apr 3, 2020
9d83c2c
Avoid depending on pem
Demi-Marie Apr 3, 2020
f71cbc1
Implement certificate signature verification manually
Demi-Marie Apr 3, 2020
16d26e9
Switch to x509-signature crate
Demi-Marie Apr 6, 2020
53fd874
Better error handling
Demi-Marie Apr 7, 2020
b367b9d
Switch to a released version of x509-signature
Demi-Marie Apr 8, 2020
7087dc0
Merge branch 'demi-quic-stable-futures' into external-x509
Demi-Marie Apr 8, 2020
072e2c7
Fix bogus unwrap
Demi-Marie Apr 8, 2020
8ab0a3b
Fix doc test
Demi-Marie Apr 8, 2020
63afb4c
Clean up copyright headers
Demi-Marie Apr 8, 2020
941fa6d
Apply suggestions from code review
Demi-Marie Apr 8, 2020
8f8e58c
Merge branch 'demi-quic-stable-futures' of github.com:DemiMarie-parit…
Demi-Marie Apr 8, 2020
b3469a7
Remove unwraps from certificate generation
Demi-Marie Apr 8, 2020
fbcb517
Clean up documentation and lints
Demi-Marie Apr 8, 2020
046ba18
Sort dependencies
Demi-Marie Apr 8, 2020
e31722e
Remove a potential panic and dead code
Demi-Marie Apr 8, 2020
016de39
Explain that QUIC resends lost packets
Demi-Marie Apr 8, 2020
ec3787c
We already ignore transmit I/O errors
Demi-Marie Apr 8, 2020
45fdfd6
Remove unused field
Demi-Marie Apr 8, 2020
4680cab
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Apr 8, 2020
f855893
Update to x509-signature 0.2.0
Demi-Marie Apr 8, 2020
a532c11
Switch to the TLS patch that will be merged
Demi-Marie Apr 13, 2020
8570e45
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Apr 15, 2020
416f99e
err-derive ⇒ thiserror
Demi-Marie Apr 16, 2020
90da0f7
‘err-derive’ ⇒ ‘thiserror’ in libp2p-x509
Demi-Marie Apr 16, 2020
5f8a376
Switch to rustls master
Demi-Marie Apr 16, 2020
81f0b0b
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Apr 20, 2020
ebc2382
Bump rcgen
Demi-Marie Apr 20, 2020
ec5c331
Bump x509-signature dependency
Demi-Marie Apr 21, 2020
5155e78
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie May 1, 2020
b9e0b48
Upgrade to the newest x509-signature crate
Demi-Marie May 6, 2020
54128d9
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie May 6, 2020
2e6fd3f
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie May 13, 2020
a3ba313
Update to quinn-proto and rustls master
Demi-Marie May 14, 2020
aa4a805
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie May 15, 2020
9da5732
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie May 23, 2020
b0c599e
Merge remote-tracking branch 'upstream/master' into quiccc-again
tomaka Jun 9, 2020
a8de82b
QUICk fix
tomaka Jun 9, 2020
341a39d
Working prototype
tomaka Jun 12, 2020
9eb6478
Working well enough
tomaka Jun 16, 2020
5b54d80
Work
tomaka Jun 17, 2020
db4c2aa
Merge branch 'master' into demi-quic-stable-futures
Demi-Marie Jun 24, 2020
b8fcd4c
Trying to get the tests working
Demi-Marie Jun 27, 2020
dfc087c
Merge branch 'master' into quiccc-again
Demi-Marie Jun 27, 2020
63ea646
Do not discard NewAddress messages
Demi-Marie Jun 27, 2020
538f5bb
Merge branch 'quiccc-again' into demi-quic-stable-futures
Demi-Marie Jun 28, 2020
6a5bbe9
Avoid hangs when running tests
Demi-Marie Jun 28, 2020
ce977a9
Wait until the handshake is complete
Demi-Marie Jun 29, 2020
d7ac0cc
A handshake with no certificate is unfinished
Demi-Marie Jun 29, 2020
e7e6d84
Re-enable several tests
Demi-Marie Jun 29, 2020
7f5925f
Fix some warnings in the tests
Demi-Marie Jun 29, 2020
54035a0
Remove some commented-out test code
Demi-Marie Jun 29, 2020
02058a6
Remove unused fields from the endpoint
Demi-Marie Jun 29, 2020
49d6f84
Avoid looping forever if no certificate is sent
Demi-Marie Jun 29, 2020
ac583ad
Working libp2p-quic (again)
Demi-Marie Jun 30, 2020
aac03f8
Remove some disabled code
Demi-Marie Jun 30, 2020
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
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ wasm-timer = "0.2.4"
libp2p-deflate = { version = "0.16.0", path = "protocols/deflate" }
libp2p-dns = { version = "0.16.0", path = "transports/dns" }
libp2p-mdns = { version = "0.16.0", path = "protocols/mdns" }
libp2p-quic = { version = "0.16.0", path = "transports/quic" }
libp2p-tcp = { version = "0.16.0", path = "transports/tcp" }
libp2p-websocket = { version = "0.16.0", path = "transports/websocket", optional = true }

Expand All @@ -70,11 +71,18 @@ members = [
"protocols/ping",
"protocols/plaintext",
"protocols/secio",
"protocols/tls",
"swarm",
"transports/dns",
"transports/quic",
"transports/tcp",
"transports/uds",
"transports/wasm-ext",
"transports/websocket",
"transports/wasm-ext"
]
exclude = [
"webpki"
]

[patch.crates-io]
webpki = { git = "https://github.com/paritytech/webpki", branch = "extension-handlers" }
6 changes: 3 additions & 3 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
//! The main concepts of libp2p-core are:
//!
//! - A [`PeerId`] is a unique global identifier for a node on the network.
//! Each node must have a different `PeerId`. Normally, a `PeerId` is the
//! Each node must have a different [`PeerId`]. Normally, a [`PeerId`] is the
//! hash of the public key used to negotiate encryption on the
//! communication channel, thereby guaranteeing that they cannot be spoofed.
//! - The [`Transport`] trait defines how to reach a remote node or listen for
//! incoming remote connections. See the `transport` module.
//! incoming remote connections. See the [`transport`] module.
//! - The [`StreamMuxer`] trait is implemented on structs that hold a connection
//! to a remote and can subdivide this connection into multiple substreams.
//! See the `muxing` module.
//! See the [`muxing`] module.
//! - The [`UpgradeInfo`], [`InboundUpgrade`] and [`OutboundUpgrade`] traits
//! define how to upgrade each individual substream to use a protocol.
//! See the `upgrade` module.
Expand Down
4 changes: 4 additions & 0 deletions misc/multiaddr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ static_assertions = "1.1"
unsigned-varint = "0.3"
url = { version = "2.1.0", default-features = false }

[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies]
get_if_addrs = "0.5.3"
ipnet = "2.1.0"

[dev-dependencies]
bincode = "1"
quickcheck = "0.9.0"
Expand Down
31 changes: 31 additions & 0 deletions misc/multiaddr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ impl TryFrom<Vec<u8>> for Multiaddr {
}
}

/// Collect all local host addresses and use the provided port number as listen port.
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
pub fn host_addresses(suffix: &[Protocol]) -> io::Result<Vec<(IpAddr, ipnet::IpNet, Multiaddr)>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you're trying to reduce code duplication, but right now the multiaddr crate is a no-std-friendly crate that doesn't rely on any feature of the operating system. I'm not sure that it's worth breaking this assumption.
On the other hand, I don't really know where to put this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make this conditional on an std feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to put this into core, specifically https://github.com/libp2p/rust-libp2p/blob/master/core/src/translation.rs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I get some opinions regarding the suggestion to put this into core? I also think that host_addresses conflates too much functionality for something reusable. Its primary concern is getting the host IP and network addresses which suggests a signature like:

fn host_addresses() -> io::Result<Vec<(IpAddr, ipnet::IpNet)>>;

or even better:

fn host_addresses() -> io::Result<impl Iterator<Item = (IpAddr, ipnet::IpNet)>>;

A Multiaddr (with arbitrary suffix) can easily be constructed by mapping over the result.

use get_if_addrs::{get_if_addrs, IfAddr};
use ipnet::{IpNet, Ipv4Net, Ipv6Net};
let mut addrs = Vec::new();
for iface in get_if_addrs()? {
let ip = iface.ip();
let mut ma = Multiaddr::from(ip);
for proto in suffix {
ma = ma.with(proto.clone())
}
let ipn = match iface.addr {
IfAddr::V4(ip4) => {
let prefix_len = (!u32::from_be_bytes(ip4.netmask.octets())).leading_zeros();
let ipnet = Ipv4Net::new(ip4.ip, prefix_len as u8)
.expect("prefix_len is the number of bits in a u32, so can not exceed 32");
IpNet::V4(ipnet)
}
IfAddr::V6(ip6) => {
let prefix_len = (!u128::from_be_bytes(ip6.netmask.octets())).leading_zeros();
let ipnet = Ipv6Net::new(ip6.ip, prefix_len as u8)
.expect("prefix_len is the number of bits in a u128, so can not exceed 128");
IpNet::V6(ipnet)
}
};
addrs.push((ip, ipn, ma))
}
Ok(addrs)
}

impl TryFrom<String> for Multiaddr {
type Error = Error;

Expand Down
29 changes: 29 additions & 0 deletions protocols/tls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "libp2p-tls"
version = "0.16.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
description = "TLS encryption for libp2p"
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking", "tls"]
categories = ["network-programming", "asynchronous"]

[dependencies]
quinn = { git = "https://github.com/djc/quinn", optional = true, package = "quinn-proto" }
rustls = "0.17.0"
ring = "0.16.11"
rcgen = "0.7.0"
webpki = "0.21.2"
untrusted = "0.7.0"
log = "0.4.8"
libp2p-core = { path = "../../core", version = "0.16.0" }
yasna = "0.3.1"

[features]
default = ["quic"]
quic = ["quinn"]

[lib]
name = "libp2p_tls"
path = "src/tls.rs"
Demi-Marie marked this conversation as resolved.
Show resolved Hide resolved
145 changes: 145 additions & 0 deletions protocols/tls/src/certificate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright 2017-2018 Parity Technologies (UK) Ltd.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! Certificate handling for libp2p
//!
//! This handles generation, signing, and verification.
//!
//! This crate uses the `log` crate to emit log output. Events that will occur normally are output
//! at `trace` level, while “expected” error conditions (ones that can result during correct use of the
//! library) are logged at `debug` level.

use super::LIBP2P_SIGNING_PREFIX_LENGTH;
use libp2p_core::identity;
use log::error;

const LIBP2P_OID: &[u64] = &[1, 3, 6, 1, 4, 1, 53594, 1, 1];
const LIBP2P_SIGNATURE_ALGORITHM_PUBLIC_KEY_LENGTH: usize = 65;
static LIBP2P_SIGNATURE_ALGORITHM: &rcgen::SignatureAlgorithm = &rcgen::PKCS_ECDSA_P256_SHA256;
// preferred, but not supported by rustls yet
//const LIBP2P_SIGNATURE_ALGORITHM_PUBLIC_KEY_LENGTH: usize = 32;
//static LIBP2P_SIGNATURE_ALGORITHM: &rcgen::SignatureAlgorithm = &rcgen::PKCS_ED25519;
Demi-Marie marked this conversation as resolved.
Show resolved Hide resolved
// same but with P-384
//const LIBP2P_SIGNATURE_ALGORITHM_PUBLIC_KEY_LENGTH: usize = 97;
//static LIBP2P_SIGNATURE_ALGORITHM: &rcgen::SignatureAlgorithm = &rcgen::PKCS_ECDSA_P384_SHA384;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we ever use P-384 in libp2p?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason.


fn encode_signed_key(public_key: identity::PublicKey, signature: &[u8]) -> rcgen::CustomExtension {
let public_key = public_key.into_protobuf_encoding();
let contents = yasna::construct_der(|writer| {
writer.write_sequence(|writer| {
writer
.next()
.write_bitvec_bytes(&public_key, public_key.len() * 8);
writer
.next()
.write_bitvec_bytes(signature, signature.len() * 8);
})
});
let mut ext = rcgen::CustomExtension::from_oid_content(LIBP2P_OID, contents);
ext.set_criticality(true);
ext
}

fn gen_signed_keypair(keypair: &identity::Keypair) -> (rcgen::KeyPair, rcgen::CustomExtension) {
let temp_keypair = rcgen::KeyPair::generate(&LIBP2P_SIGNATURE_ALGORITHM)
.expect("we pass valid parameters, and assume we have enough memory and randomness; qed");
let mut signing_buf =
[0u8; LIBP2P_SIGNING_PREFIX_LENGTH + LIBP2P_SIGNATURE_ALGORITHM_PUBLIC_KEY_LENGTH];
let public = temp_keypair.public_key_raw();
assert_eq!(
public.len(),
LIBP2P_SIGNATURE_ALGORITHM_PUBLIC_KEY_LENGTH,
"ed25519 public keys are {} bytes",
LIBP2P_SIGNATURE_ALGORITHM_PUBLIC_KEY_LENGTH
);
signing_buf[..LIBP2P_SIGNING_PREFIX_LENGTH].copy_from_slice(&super::LIBP2P_SIGNING_PREFIX[..]);
signing_buf[LIBP2P_SIGNING_PREFIX_LENGTH..].copy_from_slice(public);
let signature = keypair.sign(&signing_buf).expect("signing failed");
(
temp_keypair,
encode_signed_key(keypair.public(), &signature),
)
}

/// Generates a self-signed TLS certificate that includes a libp2p-specific certificate extension
/// containing the public key of the given keypair.
pub(crate) fn make_cert(keypair: &identity::Keypair) -> rcgen::Certificate {
let mut params = rcgen::CertificateParams::new(vec![]);
let (cert_keypair, libp2p_extension) = gen_signed_keypair(keypair);
params.custom_extensions.push(libp2p_extension);
params.alg = &LIBP2P_SIGNATURE_ALGORITHM;
params.key_pair = Some(cert_keypair);
rcgen::Certificate::from_params(params)
.expect("certificate generation with valid params will succeed; qed")
}

/// Extracts the `PeerId` from a certificate’s libp2p extension. It is erroneous
/// to call this unless the certificate is known to be a well-formed X.509
/// certificate with a valid libp2p extension. The certificate verifiers in this
/// crate validate check this.
///
/// If you get `Err` from this function, there is a bug somewhere. Either you
/// called it without checking the preconditions, or there is a bug in this
/// library or one of its dependencies.
pub fn extract_peerid(certificate: &[u8]) -> Result<libp2p_core::PeerId, webpki::Error> {
let mut id = None;
let cb = &mut |oid: untrusted::Input<'_>, value, _, _| match oid.as_slice_less_safe() {
super::LIBP2P_OID_BYTES => {
if id.is_some() {
error!(
"multiple libp2p extensions should have been detected \
earlier; something is wrong"
);
id = Some(Err(webpki::Error::UnknownIssuer))
}
id = Some(match extract_libp2p_peerid(value) {
Demi-Marie marked this conversation as resolved.
Show resolved Hide resolved
Ok(value) => Ok(value),
Err(_) => {
error!(
"bogus libp2p extension should have been detected \
earlier; something is wrong"
);
Err(webpki::Error::UnknownIssuer)
}
});
webpki::Understood::Yes
}
_ => webpki::Understood::No,
};
webpki::EndEntityCert::from_with_extension_cb(certificate, cb)?;
id.unwrap_or(Err(webpki::Error::UnknownIssuer))
}

fn extract_libp2p_peerid(
extension: untrusted::Input<'_>,
) -> Result<libp2p_core::PeerId, ring::error::Unspecified> {
use ring::{error::Unspecified, io::der};
extension
.read_all(Unspecified, |mut reader| {
let inner = der::expect_tag_and_get_value(&mut reader, der::Tag::Sequence)?;
inner.read_all(Unspecified, |mut reader| {
let public_key =
der::bit_string_with_no_unused_bits(&mut reader)?.as_slice_less_safe();
der::bit_string_with_no_unused_bits(&mut reader)?;
identity::PublicKey::from_protobuf_encoding(public_key).map_err(|_| Unspecified)
})
})
.map(From::from)
}
125 changes: 125 additions & 0 deletions protocols/tls/src/tls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! TLS configuration for `libp2p-quic`.
#![deny(
Demi-Marie marked this conversation as resolved.
Show resolved Hide resolved
exceeding_bitshifts,
invalid_type_param_default,
missing_fragment_specifier,
mutable_transmutes,
no_mangle_const_items,
overflowing_literals,
patterns_in_fns_without_body,
pub_use_of_private_extern_crate,
unknown_crate_types,
const_err,
order_dependent_trait_objects,
illegal_floating_point_literal_pattern,
improper_ctypes,
late_bound_lifetime_arguments,
non_camel_case_types,
non_shorthand_field_patterns,
non_snake_case,
non_upper_case_globals,
no_mangle_generic_items,
path_statements,
private_in_public,
safe_packed_borrows,
stable_features,
type_alias_bounds,
tyvar_behind_raw_pointer,
unconditional_recursion,
unused,
unused_allocation,
unused_comparisons,
unused_mut,
unreachable_pub,
while_true,
anonymous_parameters,
bare_trait_objects,
elided_lifetimes_in_paths,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
clippy::all
)]
#![forbid(unsafe_code)]

mod certificate;
mod verifier;

pub use certificate::extract_peerid;
use std::sync::Arc;

const LIBP2P_SIGNING_PREFIX: [u8; 21] = *b"libp2p-tls-handshake:";
const LIBP2P_SIGNING_PREFIX_LENGTH: usize = LIBP2P_SIGNING_PREFIX.len();
const LIBP2P_OID_BYTES: &[u8] = &[43, 6, 1, 4, 1, 131, 162, 90, 1, 1];

fn make_client_config(
certificate: rustls::Certificate,
key: rustls::PrivateKey,
verifier: Arc<verifier::Libp2pCertificateVerifier>,
) -> rustls::ClientConfig {
let mut crypto = rustls::ClientConfig::new();
crypto.versions = vec![rustls::ProtocolVersion::TLSv1_3];
crypto.enable_early_data = true;
crypto
.set_single_client_cert(vec![certificate], key)
.expect("we have a valid certificate; qed");
crypto.dangerous().set_certificate_verifier(verifier);
crypto
}

fn make_server_config(
certificate: rustls::Certificate,
key: rustls::PrivateKey,
verifier: Arc<verifier::Libp2pCertificateVerifier>,
) -> rustls::ServerConfig {
let mut crypto = rustls::ServerConfig::new(verifier);
crypto.versions = vec![rustls::ProtocolVersion::TLSv1_3];
crypto
.set_single_cert(vec![certificate], key)
.expect("we have a valid certificate; qed");
crypto
}

/// Create TLS client and server configurations for libp2p.
pub fn make_tls_config(
keypair: &libp2p_core::identity::Keypair,
) -> (rustls::ClientConfig, rustls::ServerConfig) {
let cert = certificate::make_cert(&keypair);
let private_key = cert.serialize_private_key_der();
let verifier = Arc::new(verifier::Libp2pCertificateVerifier);
let cert = rustls::Certificate(
cert.serialize_der()
.expect("serialization of a valid cert will succeed; qed"),
);
let key = rustls::PrivateKey(private_key);
(
make_client_config(cert.clone(), key.clone(), verifier.clone()),
make_server_config(cert, key, verifier),
)
}
Loading