Enhance the swarm a bit (#711)

* Replace the &mut TTopology with a &mut PollParameters

* Add supported_protocols

* Add external_addresses

* Report out addresses in Kademlia

* Fix the custom derive

* Some comments

* Fix compilation on stable
This commit is contained in:
Pierre Krieger
2018-12-01 13:34:57 +01:00
committed by GitHub
parent 69eafd9869
commit c5d08ab48c
8 changed files with 113 additions and 26 deletions

View File

@ -79,6 +79,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
quote!{#n}
};
let poll_parameters = quote!{::libp2p::core::swarm::PollParameters<#topology_generic>};
// Build the generics.
let impl_generics = {
let tp = ast.generics.type_params();
@ -306,7 +308,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
Some(quote!{
loop {
match #field_name.poll(topology) {
match #field_name.poll(poll_params) {
Async::Ready(#network_behaviour_action::GenerateEvent(event)) => {
#handling
}
@ -322,6 +324,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
event: #wrapped_event,
});
}
Async::Ready(#network_behaviour_action::ReportObservedAddr { address }) => {
return Async::Ready(#network_behaviour_action::ReportObservedAddr { address });
}
Async::NotReady => break,
}
}
@ -363,7 +368,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
}
}
fn poll(&mut self, topology: &mut #topology_generic) -> ::libp2p::futures::Async<#network_behaviour_action<<Self::ProtocolsHandler as #protocols_handler>::InEvent, Self::OutEvent>> {
fn poll(&mut self, poll_params: &mut #poll_parameters) -> ::libp2p::futures::Async<#network_behaviour_action<<Self::ProtocolsHandler as #protocols_handler>::InEvent, Self::OutEvent>> {
use libp2p::futures::prelude::*;
#(#poll_stmts)*
let f: ::libp2p::futures::Async<#network_behaviour_action<<Self::ProtocolsHandler as #protocols_handler>::InEvent, Self::OutEvent>> = #poll_method;