Skip to content
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

Use new pion/transport Net interface #471

Merged
merged 5 commits into from
Feb 8, 2023
Merged

Conversation

stv0g
Copy link
Member

@stv0g stv0g commented Sep 1, 2022

See pion/transport#204 for a detailed description

Also closes #509

@codecov
Copy link

codecov bot commented Sep 1, 2022

Codecov Report

Base: 78.28% // Head: 77.82% // Decreases project coverage by -0.46% ⚠️

Coverage data is based on head (3f55ead) compared to base (c8cff3a).
Patch coverage: 56.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #471      +/-   ##
==========================================
- Coverage   78.28%   77.82%   -0.46%     
==========================================
  Files          36       36              
  Lines        4273     4307      +34     
==========================================
+ Hits         3345     3352       +7     
- Misses        722      743      +21     
- Partials      206      212       +6     
Flag Coverage Δ
go 77.82% <56.00%> (-0.46%) ⬇️
wasm 24.79% <0.00%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
agent_config.go 82.14% <ø> (ø)
candidate_peer_reflexive.go 80.64% <ø> (ø)
candidate_server_reflexive.go 80.00% <ø> (ø)
tcp_packet_conn.go 76.02% <ø> (ø)
udp_muxed_conn.go 71.95% <ø> (ø)
agent.go 82.01% <43.75%> (-0.41%) ⬇️
udp_mux.go 81.25% <50.00%> (-1.03%) ⬇️
gather.go 64.57% <51.85%> (-1.41%) ⬇️
udp_mux_multi.go 52.94% <52.94%> (-1.78%) ⬇️
mdns.go 83.33% <100.00%> (+16.66%) ⬆️
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@stv0g stv0g changed the title WIP: Use new pion/transport Net interface Use new pion/transport Net interface Nov 12, 2022
@stv0g stv0g marked this pull request as draft November 12, 2022 14:51
@stv0g stv0g force-pushed the net-interface branch 2 times, most recently from 47468e2 to 1a11255 Compare November 15, 2022 12:36
@stv0g stv0g force-pushed the net-interface branch 3 times, most recently from 9cba962 to d8dba3a Compare January 10, 2023 00:04
@stv0g stv0g force-pushed the net-interface branch 2 times, most recently from 7ec3723 to 3fd03ff Compare January 31, 2023 13:34
@stv0g stv0g marked this pull request as ready for review January 31, 2023 14:32
stv0g added 2 commits February 7, 2023 17:24
This change adapts pion/ice to use a new interface for most network
related operations. The interface was formerly a simple struct vnet.Net
which was originally intended to facilicate testing. By replacing it
with an interface we have greater flexibility and allow users to hook
into the networking stack by providing their own implementation of
the interface.
Fix linter warnings
candidate_server_reflexive.go Outdated Show resolved Hide resolved
udp_mux.go Outdated
@@ -49,6 +50,7 @@ const maxAddrSize = 512
type UDPMuxParams struct {
Logger logging.LeveledLogger
UDPConn net.PacketConn
Net transport.Net
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/pion/ice/pull/471/files?diff=unified&w=1#diff-a8e331e8f7ba49ca6692af8fc922967307339ad6fe58eb62549602b8988d9bb3L64-L66

  // For unspecified addresses, the correct behavior is to return errListenUnspecified, but
  // it will break the applications that are already using unspecified UDP connection
  // with UDPMuxDefault, so print a warn log and create a local address list for mux.

Seems be used only for the fallback to the wrong usage of NewUDPMuxDefault.
If user want to specify transport.New, they should use NewMultiUDPMuxFromPort instead.

It would be better to add some comment to this field.

Copy link
Member

@enobufs enobufs Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stv0g
This is an API change beyond what this PR is aiming for. I think the reason why it uses vnet (or transport.Net) is just to reuse localInterfaces() that requires vnet/transport.Net. In fact, it only requires net.Interfaces, and

vnet.NewNet(nil) // <-- *NetConfig being nil

would return what you can get from the original net.Interfaces, so the code we have here did not intend to use "virtual interface" but to use localInterfaces just for convenience. Therefore, I think we don't need to add transport.Net field to this public struct. (Let's focus on introducing transport.Net for now with minimal impact to users)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually tried it without adding the field. However that breaks the tests as the integration will create a UDPMux which attempts to listen on addresses of the real host rather than the virtual interfaces of the vnet.VNet.

This will cause vnet/Net.ListenUDP to fail as it can not bind to a non-existing local address.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For normal (non-test usage) the field will be initialized with nil and hence use the stdnet.Net implementation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@at-wat I added a comment to the new field.

Copy link
Member

@enobufs enobufs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left one comment. (I will review again when it comes out of the draft state.)

udp_mux.go Outdated
@@ -49,6 +50,7 @@ const maxAddrSize = 512
type UDPMuxParams struct {
Logger logging.LeveledLogger
UDPConn net.PacketConn
Net transport.Net
Copy link
Member

@enobufs enobufs Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stv0g
This is an API change beyond what this PR is aiming for. I think the reason why it uses vnet (or transport.Net) is just to reuse localInterfaces() that requires vnet/transport.Net. In fact, it only requires net.Interfaces, and

vnet.NewNet(nil) // <-- *NetConfig being nil

would return what you can get from the original net.Interfaces, so the code we have here did not intend to use "virtual interface" but to use localInterfaces just for convenience. Therefore, I think we don't need to add transport.Net field to this public struct. (Let's focus on introducing transport.Net for now with minimal impact to users)

stv0g added 2 commits February 8, 2023 12:51
Remove duplicate package comment
@stv0g
Copy link
Member Author

stv0g commented Feb 8, 2023

Thanks @enobufs and @at-wat for your reviews.

I will review again when it comes out of the draft state

The PR is now ready for merging when you are happy with it :)

Copy link
Member

@edaniels edaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! One actual change to make and one suggested.

gather.go Outdated Show resolved Hide resolved
udp_mux_multi.go Outdated Show resolved Hide resolved
Co-authored-by: Eric Daniels <[email protected]>
@stv0g
Copy link
Member Author

stv0g commented Feb 8, 2023

Thanks @edaniels,

I committed your proposed changed 👍

Copy link
Member

@edaniels edaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@stv0g stv0g merged commit 228c31f into pion:master Feb 8, 2023
@stv0g stv0g deleted the net-interface branch February 8, 2023 20:58
mlsmaycon added a commit to netbirdio/netbird that referenced this pull request Feb 24, 2023
Among other improvements, it fixes a memory leak with
srfx conn channels not being closed

it also make use of new pion/transport Net interface
pion/ice#471
braginini pushed a commit to netbirdio/netbird that referenced this pull request Feb 24, 2023
Among other improvements, it fixes a memory leak with
srfx conn channels not being closed

it also make use of new pion/transport Net interface
pion/ice#471
pulsastrix pushed a commit to pulsastrix/netbird that referenced this pull request Dec 24, 2023
Among other improvements, it fixes a memory leak with
srfx conn channels not being closed

it also make use of new pion/transport Net interface
pion/ice#471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants