-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add NetworkBehaviour::inject_replaced #914
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a Q about the increased code complexity.
@@ -191,6 +191,28 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { | |||
}) | |||
}; | |||
|
|||
// Build the list of statements to put in the body of `inject_replaced()`. | |||
let inject_replaced_stmts = { | |||
let num_fields = data_struct.fields.iter().filter(|f| !is_ignored(f)).count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you doing this count and all the rather complex looking code below only to save three clone
s? Are these three structs so heavy that this warrants the extra looping and increased code complexity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! The plan is to ultimately remove this custom derive, which is why no effort has been put into making its code more readable.
misc/core-derive/src/lib.rs
Outdated
} | ||
} else { | ||
match field.ident { | ||
Some(ref i) => quote!{ self.#i.inject_replaced(peer_id.clone(), closed_endpoint.clone(), new_endpoint.clone()); }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please wrap - this and the line below.
I pushed another commit that adds a call to |
Also pushed another commit that adds the incoming address to kbuckets. |
Instead of calling "disconnected" followed with "connected", allows implementers to override an
inject_replaced
method.The Kademlia behaviour needs this so that it can re-send the RPC query without marking the node as unreachable.