Add NetworkBehaviour::inject_new_external_addr (#1063)

This commit is contained in:
Pierre Krieger
2019-04-16 17:00:20 +02:00
committed by GitHub
parent bee5c58b27
commit a953b613cf
4 changed files with 28 additions and 0 deletions

View File

@ -270,6 +270,20 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
})
};
// Build the list of statements to put in the body of `inject_new_external_addr()`.
let inject_new_external_addr_stmts = {
data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| {
if is_ignored(&field) {
return None;
}
Some(match field.ident {
Some(ref i) => quote!{ self.#i.inject_new_external_addr(addr); },
None => quote!{ self.#field_n.inject_new_external_addr(addr); },
})
})
};
// Build the list of variants to put in the body of `inject_node_event()`.
//
// The event type is a construction of nested `#either_ident`s of the events of the children.
@ -449,6 +463,10 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
#(#inject_expired_listen_addr_stmts);*
}
fn inject_new_external_addr(&mut self, addr: &#multiaddr) {
#(#inject_new_external_addr_stmts);*
}
fn inject_node_event(
&mut self,
peer_id: #peer_id,