-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Working on new TransportTuple.hash implementation #839
Conversation
This branch should be applied on `webrtcserver` branch or in `v3` once the former is merged. Not happy at all yet because: - `SetHash()` implementation in this branch is too simple. We should consider local IP:port and protocol as well, but we cannot just "sum" those numbers since there is a chance to collide. - And if we collide (if we have 2 tuples with same `hash` in the same `WebRtcServer`) then we'll have an assertion problem: ``` RTC::WebRtcServer::OnWebRtcTransportTransportTupleRemoved() | failed assertion `this->mapTupleWebRtcTransport.find(tuple->hash) != this->mapTupleWebRtcTransport.end()': tuple not handled ``` - So IMHO we need `hash` to be `int64_t` and we should concatenate remote IP:port first then local IP:port plus protocol somewhere. But summing protocol cannot be just about doing + 1 or +2. imagine this: ``` - Client A connects from udp:1.2.3.4:5001 to udp:9.9.9.9:9000. - Client B connects from tcp:1.2.3.4:5000 to tcp:9.9.9.9:9000. - If tcp protocol just means "adding 1 to the hash" then both hashes will be the same (BUMPP!).
For example, assuming that the client IP is IPv6 1:2:3:4:A:B:C:D, This is the current (not completed of course) code: auto* remoteSockAddrIn6 = reinterpret_cast<const struct sockaddr_in6*>(remoteSockAddr);
auto* a = reinterpret_cast<const uint32_t*>(std::addressof(remoteSockAddrIn6->sin6_addr));
this->hash += a[0] ^ a[1] ^ a[2] ^ a[3];
this->hash += ntohs(remoteSockAddrIn6->sin6_port); However when client IP is IPv4 192.168.1.100, auto* remoteSockAddrIn = reinterpret_cast<const struct sockaddr_in*>(remoteSockAddr);
this->hash += ntohl(remoteSockAddrIn->sin_addr.s_addr);
this->hash += ntohs(remoteSockAddrIn->sin_port); ok, with client's IPv6 9999:8888:777:6:AAAA:BBB:CC:D it produces hashes like 948198608, 948199393, so it's ok. |
Here a guy with similar concerns:
Here the implementation in baresip: |
I've changed |
worker/src/RTC/TransportTuple.cpp
Outdated
const auto address = ntohl(remoteSockAddrIn->sin_addr.s_addr); | ||
const uint64_t port = (ntohs(remoteSockAddrIn->sin_port)); | ||
|
||
std::cout << "address " << std::bitset<64>{address} << std::endl; |
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.
Add include bitset at the top of the file if we go this way
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.
Yep, though the log is temporal
TCP example:
UDP example:
|
New implementation is much more complex, what are we getting by going this route? |
Why do you say it's more complex? it's just shifting numbers into a uint64_t type? |
Which route, getting the hash out of the remote socket? Sorry @nazar-pc, I don't follow. |
So before we just concatenated a string and hashed it. Simple enough, we can compare the strings later to know if things are identical. Now we're doing a bunch of bit manipulations, which for me is more complex. But if there any significant performance or memory usage difference of doing any of this comparing to just having a string? |
One of the concerns of using strings is the fact that they would be used as key in a map in the new |
I get that, it was my original concern as well, just not clear to me how expensive that actually is. |
Generating a string which is a concatenation of numbers converted into strings plus using |
I think we can merge this and keep working in the other branch. |
Let's merge this. |
This branch should be applied on
webrtcserver
branch or inv3
once the former is merged.Not happy at all yet because:
SetHash()
implementation in this branch is too simple. We should consider local IP:port and protocol as well, but we cannot just "sum" those numbers since there is a chance to collide.hash
in the sameWebRtcServer
) then we'll have an assertion problem:hash
to beint64_t
and we should concatenate remote IP:port first then local IP:port plus protocol somewhere. But summing protocol cannot be just about doing + 1 or +2. imagine this: