make the ping queue use a more compact data structure #16

Merged
merged 2 commits into from Aug 14, 2016

Projects

None yet

2 participants

@arvidn
Contributor
arvidn commented Aug 14, 2016

and reduce some IPv4/IPv6 code duplication.

@arvidn arvidn commented on the diff Aug 14, 2016
@@ -390,19 +390,6 @@ struct bound_socket
char packet[1500];
};
-// this is the type of each node queued up
-// to be pinged at some point in the future
-struct queued_node_t
@arvidn
arvidn Aug 14, 2016 Contributor

I moved this down a bit and stripped out fields that aren't used externally

@arvidn arvidn commented on the diff Aug 14, 2016
@@ -442,97 +429,110 @@ struct ip_set
std::unordered_set<decltype(extract_key(std::declval<Address>()))> m_ips;
};
+struct queued_node_t
+{
+ udp::endpoint ep;
+ int sock_idx;
+};
+
+template <typename Address>
struct ping_queue_t
@arvidn
arvidn Aug 14, 2016 Contributor

while working on this increasingly more fields started having an IPv4 and IPv6 version, so making it a template made that a lot cleaner. I also moved in the queue entry type as an inner class

@arvidn arvidn and 1 other commented on an outdated diff Aug 14, 2016
}
private:
+ // this is the type of each node queued up to be pinged at some point in the
+ // future
+ struct queue_entry_t
+ {
+ typename Address::bytes_type addr;
+
+ // the index of the socket this node was seen on, and should be pinged
+ // back via
+ std::uint32_t sock_idx:2;
+
+ // expiration in seconds (relative to the ping_queue creation time)
+ std::uint32_t expire:30;
@arvidn
arvidn Aug 14, 2016 edited Contributor

I suppose technically there will always be 2 bytes padding here, so the bitfield may be a bit redundant

@ssiloti
ssiloti Aug 14, 2016 Contributor

Yeah, as-is the bitfield is just generating slower code for no gain.

@ssiloti
Contributor
ssiloti commented Aug 14, 2016

lgtm

@arvidn arvidn merged commit 44e19b0 into bittorrent:master Aug 14, 2016
@arvidn arvidn deleted the arvidn:compact-ping-queue branch Aug 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment