Skip to content

Commit 91f9faf

Browse files
authored
Merge pull request #6 from libp2p/master
update
2 parents 23a399a + 3ebe916 commit 91f9faf

File tree

165 files changed

+3639
-1445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+3639
-1445
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- [`libp2p-core` CHANGELOG](core/CHANGELOG.md)
22
- [`libp2p-deflate` CHANGELOG](protocols/deflate/CHANGELOG.md)
3+
- [`libp2p-dns` CHANGELOG](transports/dns/CHANGELOG.md)
34
- [`libp2p-floodsub` CHANGELOG](protocols/floodsub/CHANGELOG.md)
45
- [`libp2p-gossipsub` CHANGELOG](protocols/gossipsub/CHANGELOG.md)
56
- [`libp2p-identify` CHANGELOG](protocols/identify/CHANGELOG.md)
@@ -10,14 +11,43 @@
1011
- [`libp2p-ping` CHANGELOG](protocols/ping/CHANGELOG.md)
1112
- [`libp2p-plaintext` CHANGELOG](protocols/plaintext/CHANGELOG.md)
1213
- [`libp2p-pnet` CHANGELOG](protocols/pnet/CHANGELOG.md)
14+
- [`libp2p-request-response` CHANGELOG](protocols/request-response/CHANGELOG.md)
1315
- [`libp2p-secio` CHANGELOG](protocols/secio/CHANGELOG.md)
1416
- [`libp2p-swarm` CHANGELOG](swarm/CHANGELOG.md)
1517
- [`libp2p-tcp` CHANGELOG](transports/tcp/CHANGELOG.md)
1618
- [`libp2p-uds` CHANGELOG](transports/uds/CHANGELOG.md)
19+
- [`libp2p-wasm-ext` CHANGELOG](transports/wasm-ext/CHANGELOG.md)
1720
- [`libp2p-websocket` CHANGELOG](transports/websocket/CHANGELOG.md)
1821
- [`libp2p-yamux` CHANGELOG](muxers/yamux/CHANGELOG.md)
1922
- [`multistream-select` CHANGELOG](misc/multistream-select/CHANGELOG.md)
2023
- [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md)
24+
- [`libp2p-core-derive` CHANGELOG](misc/core-derive/CHANGELOG.md)
25+
26+
# Version 0.23.0 (2020-??-??)
27+
28+
- Refactored bandwidth logging ([PR 1670](https://github.com/libp2p/rust-libp2p/pull/1670)).
29+
30+
# Version 0.22.0 (2020-07-17)
31+
32+
**NOTE**: For a smooth upgrade path from `0.21` to `> 0.22`
33+
on an existing deployment using `libp2p-noise`, this version
34+
must not be skipped!
35+
36+
- Bump `libp2p-noise` dependency to `0.21`.
37+
38+
# Version 0.21.1 (2020-07-02)
39+
40+
- Bump `libp2p-websockets` lower bound.
41+
42+
# Version 0.21.0 (2020-07-01)
43+
44+
- Conditional compilation fixes for the `wasm32-wasi` target
45+
([PR 1633](https://github.com/libp2p/rust-libp2p/pull/1633)).
46+
47+
- New `libp2p-request-response` crate
48+
([PR 1596](https://github.com/libp2p/rust-libp2p/pull/1596)).
49+
50+
- Updated libp2p dependencies.
2151

2252
# Version 0.19.1 (2020-05-25)
2353

Cargo.toml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "libp2p"
33
edition = "2018"
44
description = "Peer-to-peer networking library"
5-
version = "0.20.1"
5+
version = "0.22.0"
66
authors = ["Parity Technologies <[email protected]>"]
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"
@@ -23,6 +23,7 @@ default = [
2323
"ping",
2424
"plaintext",
2525
"pnet",
26+
"request-response",
2627
"secio",
2728
"secp256k1",
2829
"tcp-async-std",
@@ -43,6 +44,7 @@ noise = ["libp2p-noise"]
4344
ping = ["libp2p-ping"]
4445
plaintext = ["libp2p-plaintext"]
4546
pnet = ["libp2p-pnet"]
47+
request-response = ["libp2p-request-response"]
4648
secio = ["libp2p-secio"]
4749
tcp-async-std = ["libp2p-tcp", "libp2p-tcp/async-std"]
4850
tcp-tokio = ["libp2p-tcp", "libp2p-tcp/tokio"]
@@ -52,42 +54,47 @@ websocket = ["libp2p-websocket"]
5254
yamux = ["libp2p-yamux"]
5355
secp256k1 = ["libp2p-core/secp256k1", "libp2p-secio/secp256k1"]
5456

57+
[package.metadata.docs.rs]
58+
all-features = true
59+
5560
[dependencies]
61+
atomic = "0.4.6"
5662
bytes = "0.5"
5763
futures = "0.3.1"
5864
lazy_static = "1.2"
59-
libp2p-core = { version = "0.19.2", path = "core" }
60-
libp2p-core-derive = { version = "0.19.1", path = "misc/core-derive" }
61-
libp2p-floodsub = { version = "0.19.1", path = "protocols/floodsub", optional = true }
62-
libp2p-gossipsub = { version = "0.19.3", path = "./protocols/gossipsub", optional = true }
63-
libp2p-identify = { version = "0.19.2", path = "protocols/identify", optional = true }
64-
libp2p-kad = { version = "0.20.1", path = "protocols/kad", optional = true }
65-
libp2p-mplex = { version = "0.19.2", path = "muxers/mplex", optional = true }
66-
libp2p-noise = { version = "0.19.1", path = "protocols/noise", optional = true }
67-
libp2p-ping = { version = "0.19.3", path = "protocols/ping", optional = true }
68-
libp2p-plaintext = { version = "0.19.1", path = "protocols/plaintext", optional = true }
65+
libp2p-core = { version = "0.20.0", path = "core" }
66+
libp2p-core-derive = { version = "0.20.0", path = "misc/core-derive" }
67+
libp2p-floodsub = { version = "0.20.0", path = "protocols/floodsub", optional = true }
68+
libp2p-gossipsub = { version = "0.20.0", path = "./protocols/gossipsub", optional = true }
69+
libp2p-identify = { version = "0.20.0", path = "protocols/identify", optional = true }
70+
libp2p-kad = { version = "0.21.0", path = "protocols/kad", optional = true }
71+
libp2p-mplex = { version = "0.20.0", path = "muxers/mplex", optional = true }
72+
libp2p-noise = { version = "0.21.0", path = "protocols/noise", optional = true }
73+
libp2p-ping = { version = "0.20.0", path = "protocols/ping", optional = true }
74+
libp2p-plaintext = { version = "0.20.0", path = "protocols/plaintext", optional = true }
6975
libp2p-pnet = { version = "0.19.1", path = "protocols/pnet", optional = true }
70-
libp2p-secio = { version = "0.19.2", path = "protocols/secio", default-features = false, optional = true }
71-
libp2p-swarm = { version = "0.19.1", path = "swarm" }
72-
libp2p-uds = { version = "0.19.2", path = "transports/uds", optional = true }
73-
libp2p-wasm-ext = { version = "0.19.0", path = "transports/wasm-ext", optional = true }
74-
libp2p-yamux = { version = "0.19.1", path = "muxers/yamux", optional = true }
76+
libp2p-request-response = { version = "0.1.0", path = "protocols/request-response", optional = true }
77+
libp2p-secio = { version = "0.20.0", path = "protocols/secio", default-features = false, optional = true }
78+
libp2p-swarm = { version = "0.20.0", path = "swarm" }
79+
libp2p-uds = { version = "0.20.0", path = "transports/uds", optional = true }
80+
libp2p-wasm-ext = { version = "0.20.0", path = "transports/wasm-ext", optional = true }
81+
libp2p-yamux = { version = "0.20.0", path = "muxers/yamux", optional = true }
7582
multiaddr = { package = "parity-multiaddr", version = "0.9.1", path = "misc/multiaddr" }
7683
multihash = "0.11.0"
7784
parking_lot = "0.10.0"
7885
pin-project = "0.4.17"
7986
smallvec = "1.0"
8087
wasm-timer = "0.2.4"
8188

82-
[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies]
83-
libp2p-deflate = { version = "0.19.2", path = "protocols/deflate", optional = true }
84-
libp2p-dns = { version = "0.19.0", path = "transports/dns", optional = true }
85-
libp2p-mdns = { version = "0.19.2", path = "protocols/mdns", optional = true }
86-
libp2p-tcp = { version = "0.19.2", path = "transports/tcp", optional = true }
87-
libp2p-websocket = { version = "0.20.0", path = "transports/websocket", optional = true }
89+
[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
90+
libp2p-deflate = { version = "0.20.0", path = "protocols/deflate", optional = true }
91+
libp2p-dns = { version = "0.20.0", path = "transports/dns", optional = true }
92+
libp2p-mdns = { version = "0.20.0", path = "protocols/mdns", optional = true }
93+
libp2p-tcp = { version = "0.20.0", path = "transports/tcp", optional = true }
94+
libp2p-websocket = { version = "0.21.0", path = "transports/websocket", optional = true }
8895

8996
[dev-dependencies]
90-
async-std = "1.5.0"
97+
async-std = "1.6.2"
9198
env_logger = "0.7.1"
9299

93100
[workspace]
@@ -107,6 +114,7 @@ members = [
107114
"protocols/noise",
108115
"protocols/ping",
109116
"protocols/plaintext",
117+
"protocols/request-response",
110118
"protocols/secio",
111119
"swarm",
112120
"transports/dns",

core/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# 0.20.1 [2020-17-17]
2+
3+
- Update ed25519-dalek dependency.
4+
5+
# 0.20.0 [2020-07-01]
6+
7+
- Conditional compilation fixes for the `wasm32-wasi` target
8+
([PR 1633](https://github.com/libp2p/rust-libp2p/pull/1633)).
9+
10+
- Rename `StreamMuxer::poll_inbound` to `poll_event` and change the
11+
return value to `StreamMuxerEvent`. This new `StreamMuxerEvent` makes
12+
it possible for the multiplexing layer to notify the upper layers of
13+
a change in the address of the underlying connection.
14+
15+
- Add `ConnectionHandler::inject_address_change`.
16+
117
# 0.19.2 [2020-06-22]
218

319
- Add PartialOrd and Ord for PeerId

core/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "libp2p-core"
33
edition = "2018"
44
description = "Core traits and structs of libp2p"
5-
version = "0.19.2"
5+
version = "0.20.1"
66
authors = ["Parity Technologies <[email protected]>"]
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"
@@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
1212
[dependencies]
1313
asn1_der = "0.6.1"
1414
bs58 = "0.3.0"
15-
ed25519-dalek = "1.0.0-pre.3"
15+
ed25519-dalek = "1.0.0-pre.4"
1616
either = "1.5"
1717
fnv = "1.0"
1818
futures = { version = "0.3.1", features = ["executor", "thread-pool"] }
@@ -35,11 +35,11 @@ unsigned-varint = "0.4"
3535
void = "1"
3636
zeroize = "1"
3737

38-
[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies]
38+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3939
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
4040

4141
[dev-dependencies]
42-
async-std = "1.5.0"
42+
async-std = "1.6.2"
4343
libp2p-mplex = { path = "../muxers/mplex" }
4444
libp2p-secio = { path = "../protocols/secio" }
4545
libp2p-tcp = { path = "../transports/tcp", features = ["async-std"] }

core/src/connection.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ impl ConnectedPoint {
132132
ConnectedPoint::Listener { .. } => true
133133
}
134134
}
135+
136+
/// Modifies the address of the remote stored in this struct.
137+
///
138+
/// For `Dialer`, this modifies `address`. For `Listener`, this modifies `send_back_addr`.
139+
pub fn set_remote_address(&mut self, new_address: Multiaddr) {
140+
match self {
141+
ConnectedPoint::Dialer { address } => *address = new_address,
142+
ConnectedPoint::Listener { send_back_addr, .. } => *send_back_addr = new_address,
143+
}
144+
}
135145
}
136146

137147
/// Information about a successfully established connection.
@@ -169,6 +179,15 @@ impl ConnectionInfo for PeerId {
169179
}
170180
}
171181

182+
/// Event generated by a [`Connection`].
183+
#[derive(Debug, Clone)]
184+
pub enum Event<T> {
185+
/// Event generated by the [`ConnectionHandler`].
186+
Handler(T),
187+
/// Address of the remote has changed.
188+
AddressChange(Multiaddr),
189+
}
190+
172191
/// A multiplexed connection to a peer with an associated `ConnectionHandler`.
173192
pub struct Connection<TMuxer, THandler>
174193
where
@@ -238,8 +257,8 @@ where
238257

239258
/// Polls the connection for events produced by the associated handler
240259
/// as a result of I/O activity on the substream multiplexer.
241-
pub fn poll(mut self: Pin<&mut Self>, cx: &mut Context)
242-
-> Poll<Result<THandler::OutEvent, ConnectionError<THandler::Error>>>
260+
pub fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>)
261+
-> Poll<Result<Event<THandler::OutEvent>, ConnectionError<THandler::Error>>>
243262
{
244263
loop {
245264
let mut io_pending = false;
@@ -255,6 +274,10 @@ where
255274
let endpoint = SubstreamEndpoint::Dialer(user_data);
256275
self.handler.inject_substream(substream, endpoint)
257276
}
277+
Poll::Ready(Ok(SubstreamEvent::AddressChange(address))) => {
278+
self.handler.inject_address_change(&address);
279+
return Poll::Ready(Ok(Event::AddressChange(address)));
280+
}
258281
Poll::Ready(Err(err)) => return Poll::Ready(Err(ConnectionError::IO(err))),
259282
}
260283

@@ -269,7 +292,7 @@ where
269292
self.muxing.open_substream(user_data);
270293
}
271294
Poll::Ready(Ok(ConnectionHandlerEvent::Custom(event))) => {
272-
return Poll::Ready(Ok(event));
295+
return Poll::Ready(Ok(Event::Handler(event)));
273296
}
274297
Poll::Ready(Err(err)) => return Poll::Ready(Err(ConnectionError::Handler(err))),
275298
}

core/src/connection/handler.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21-
use crate::PeerId;
21+
use crate::{Multiaddr, PeerId};
2222
use std::{task::Context, task::Poll};
2323
use super::{Connected, SubstreamEndpoint};
2424

@@ -58,10 +58,13 @@ pub trait ConnectionHandler {
5858
/// Notifies the handler of an event.
5959
fn inject_event(&mut self, event: Self::InEvent);
6060

61+
/// Notifies the handler of a change in the address of the remote.
62+
fn inject_address_change(&mut self, new_address: &Multiaddr);
63+
6164
/// Polls the handler for events.
6265
///
6366
/// Returning an error will close the connection to the remote.
64-
fn poll(&mut self, cx: &mut Context)
67+
fn poll(&mut self, cx: &mut Context<'_>)
6568
-> Poll<Result<ConnectionHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>>;
6669
}
6770

core/src/connection/listeners.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ where
230230
}
231231

232232
/// Provides an API similar to `Stream`, except that it cannot end.
233-
pub fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<ListenersEvent<TTrans>> {
233+
pub fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<ListenersEvent<TTrans>> {
234234
// We remove each element from `listeners` one by one and add them back.
235235
let mut remaining = self.listeners.len();
236236
while let Some(mut listener) = self.listeners.pop_back() {
@@ -310,7 +310,7 @@ where
310310
{
311311
type Item = ListenersEvent<TTrans>;
312312

313-
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
313+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
314314
ListenersStream::poll(self, cx).map(Option::Some)
315315
}
316316
}

core/src/connection/manager.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ use std::{
3232
collections::hash_map,
3333
error,
3434
fmt,
35+
mem,
3536
pin::Pin,
3637
task::{Context, Poll},
3738
};
3839
use super::{
3940
Connected,
41+
ConnectedPoint,
4042
Connection,
4143
ConnectionError,
4244
ConnectionHandler,
@@ -123,7 +125,7 @@ impl<I, O, H, E, HE, C> fmt::Debug for Manager<I, O, H, E, HE, C>
123125
where
124126
C: fmt::Debug,
125127
{
126-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
128+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127129
f.debug_map()
128130
.entries(self.tasks.iter().map(|(id, task)| (id, &task.state)))
129131
.finish()
@@ -220,7 +222,17 @@ pub enum Event<'a, I, O, H, TE, HE, C> {
220222
entry: EstablishedEntry<'a, I, C>,
221223
/// The produced event.
222224
event: O
223-
}
225+
},
226+
227+
/// A connection to a node has changed its address.
228+
AddressChange {
229+
/// The entry associated with the connection that changed address.
230+
entry: EstablishedEntry<'a, I, C>,
231+
/// The former [`ConnectedPoint`].
232+
old_endpoint: ConnectedPoint,
233+
/// The new [`ConnectedPoint`].
234+
new_endpoint: ConnectedPoint,
235+
},
224236
}
225237

226238
impl<I, O, H, TE, HE, C> Manager<I, O, H, TE, HE, C> {
@@ -334,7 +346,7 @@ impl<I, O, H, TE, HE, C> Manager<I, O, H, TE, HE, C> {
334346
}
335347

336348
/// Polls the manager for events relating to the managed connections.
337-
pub fn poll<'a>(&'a mut self, cx: &mut Context) -> Poll<Event<'a, I, O, H, TE, HE, C>> {
349+
pub fn poll<'a>(&'a mut self, cx: &mut Context<'_>) -> Poll<Event<'a, I, O, H, TE, HE, C>> {
338350
// Advance the content of `local_spawns`.
339351
while let Poll::Ready(Some(_)) = Stream::poll_next(Pin::new(&mut self.local_spawns), cx) {}
340352

@@ -369,6 +381,23 @@ impl<I, O, H, TE, HE, C> Manager<I, O, H, TE, HE, C> {
369381
let _ = task.remove();
370382
Event::PendingConnectionError { id, error, handler }
371383
}
384+
task::Event::AddressChange { id: _, new_address } => {
385+
let (new, old) = if let TaskState::Established(c) = &mut task.get_mut().state {
386+
let mut new_endpoint = c.endpoint.clone();
387+
new_endpoint.set_remote_address(new_address);
388+
let old_endpoint = mem::replace(&mut c.endpoint, new_endpoint.clone());
389+
(new_endpoint, old_endpoint)
390+
} else {
391+
unreachable!(
392+
"`Event::AddressChange` implies (2) occurred on that task and thus (3)."
393+
)
394+
};
395+
Event::AddressChange {
396+
entry: EstablishedEntry { task },
397+
old_endpoint: old,
398+
new_endpoint: new,
399+
}
400+
},
372401
task::Event::Error { id, error } => {
373402
let id = ConnectionId(id);
374403
let task = task.remove();
@@ -439,7 +468,7 @@ impl<'a, I, C> EstablishedEntry<'a, I, C> {
439468
///
440469
/// Returns `Err(())` if the background task associated with the connection
441470
/// is terminating and the connection is about to close.
442-
pub fn poll_ready_notify_handler(&mut self, cx: &mut Context) -> Poll<Result<(),()>> {
471+
pub fn poll_ready_notify_handler(&mut self, cx: &mut Context<'_>) -> Poll<Result<(),()>> {
443472
self.task.get_mut().sender.poll_ready(cx).map_err(|_| ())
444473
}
445474

0 commit comments

Comments
 (0)