mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 10:01:25 +00:00
swarm: Extend NetworkBehaviour callbacks. (#2011)
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@ -244,6 +244,20 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
})
|
||||
};
|
||||
|
||||
// Build the list of statements to put in the body of `inject_new_listener()`.
|
||||
let inject_new_listener_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_listener(id); },
|
||||
None => quote!{ self.#field_n.inject_new_listener(id); },
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
// Build the list of statements to put in the body of `inject_new_listen_addr()`.
|
||||
let inject_new_listen_addr_stmts = {
|
||||
data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| {
|
||||
@ -252,8 +266,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
}
|
||||
|
||||
Some(match field.ident {
|
||||
Some(ref i) => quote!{ self.#i.inject_new_listen_addr(addr); },
|
||||
None => quote!{ self.#field_n.inject_new_listen_addr(addr); },
|
||||
Some(ref i) => quote!{ self.#i.inject_new_listen_addr(id, addr); },
|
||||
None => quote!{ self.#field_n.inject_new_listen_addr(id, addr); },
|
||||
})
|
||||
})
|
||||
};
|
||||
@ -266,8 +280,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
}
|
||||
|
||||
Some(match field.ident {
|
||||
Some(ref i) => quote!{ self.#i.inject_expired_listen_addr(addr); },
|
||||
None => quote!{ self.#field_n.inject_expired_listen_addr(addr); },
|
||||
Some(ref i) => quote!{ self.#i.inject_expired_listen_addr(id, addr); },
|
||||
None => quote!{ self.#field_n.inject_expired_listen_addr(id, addr); },
|
||||
})
|
||||
})
|
||||
};
|
||||
@ -286,6 +300,20 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
})
|
||||
};
|
||||
|
||||
// Build the list of statements to put in the body of `inject_expired_external_addr()`.
|
||||
let inject_expired_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_expired_external_addr(addr); },
|
||||
None => quote!{ self.#field_n.inject_expired_external_addr(addr); },
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
// Build the list of statements to put in the body of `inject_listener_error()`.
|
||||
let inject_listener_error_stmts = {
|
||||
data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| {
|
||||
@ -504,11 +532,15 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
#(#inject_dial_failure_stmts);*
|
||||
}
|
||||
|
||||
fn inject_new_listen_addr(&mut self, addr: &#multiaddr) {
|
||||
fn inject_new_listener(&mut self, id: #listener_id) {
|
||||
#(#inject_new_listener_stmts);*
|
||||
}
|
||||
|
||||
fn inject_new_listen_addr(&mut self, id: #listener_id, addr: &#multiaddr) {
|
||||
#(#inject_new_listen_addr_stmts);*
|
||||
}
|
||||
|
||||
fn inject_expired_listen_addr(&mut self, addr: &#multiaddr) {
|
||||
fn inject_expired_listen_addr(&mut self, id: #listener_id, addr: &#multiaddr) {
|
||||
#(#inject_expired_listen_addr_stmts);*
|
||||
}
|
||||
|
||||
@ -516,6 +548,10 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
|
||||
#(#inject_new_external_addr_stmts);*
|
||||
}
|
||||
|
||||
fn inject_expired_external_addr(&mut self, addr: &#multiaddr) {
|
||||
#(#inject_expired_external_addr_stmts);*
|
||||
}
|
||||
|
||||
fn inject_listener_error(&mut self, id: #listener_id, err: &(dyn std::error::Error + 'static)) {
|
||||
#(#inject_listener_error_stmts);*
|
||||
}
|
||||
|
Reference in New Issue
Block a user