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

Introduce netctx package and PacketConnCtx #253

Merged
merged 10 commits into from
Jul 11, 2023

Conversation

hasheddan
Copy link
Contributor

Description

Moves ConnCtx to the netctx package, which will be expanded to include
additional wrapped network interfaces.

Signed-off-by: Daniel Mangum [email protected]

Adds a PacketConnCtx that wraps net.PacketConn.

Signed-off-by: Daniel Mangum [email protected]

Reference issue

Enables pion/dtls#256

@codecov
Copy link

codecov bot commented Jul 9, 2023

Codecov Report

Patch coverage: 76.14% and project coverage change: -0.56 ⚠️

Comparison is base (4b89bf8) 82.32% compared to head (f7257a2) 81.76%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #253      +/-   ##
==========================================
- Coverage   82.32%   81.76%   -0.56%     
==========================================
  Files          34       37       +3     
  Lines        3010     3203     +193     
==========================================
+ Hits         2478     2619     +141     
- Misses        421      460      +39     
- Partials      111      124      +13     
Flag Coverage Δ
go 81.60% <76.14%> (-0.46%) ⬇️
wasm 74.26% <76.14%> (+0.10%) ⬆️

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

Impacted Files Coverage Δ
connctx/connctx.go 77.08% <ø> (ø)
netctx/pipe.go 0.00% <0.00%> (ø)
netctx/packetconn.go 76.59% <76.59%> (ø)
netctx/conn.go 77.08% <77.08%> (ø)
test/stress.go 76.19% <100.00%> (ø)

... and 2 files with indirect coverage changes

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

Comment on lines 4 to 7
// Package connctx wraps net.Conn using context.Context.
// Deprecated: use netctx instead.
package connctx
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are packages that currently depend on this, so we deprecate while introducing the same functionality in netctx.

@hasheddan hasheddan force-pushed the packetconnctx branch 2 times, most recently from f473f54 to 1fdb254 Compare July 9, 2023 23:22
@hasheddan hasheddan self-assigned this Jul 9, 2023
@stv0g
Copy link
Member

stv0g commented Jul 10, 2023

Hi @hasheddan,

can you briefly motivate why you renamed the existing package and deprecated the old name?

I am interested to learn about the differences between the two packages. Are there any API breaking changes in it?

Copy link
Contributor Author

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

@stv0g in adding PacketConnCtx, I had the option to introduce a new package or add it to the existing connctx package. The connctx package would be a bit of a misnomer for a PacketConnCtx, and introducing a new package such as packetconnctx would have the same duplicate naming that connctx currently has (i.e. connctx.ConnCtx and packetconnctx.PacketConnCtx). What we are really doing here is wrapping net primitives with context, so I instead introduced a package that matches upstream naming so that we have net.Conn / netctx.ConnCtx and net.PacketConn / netctx.PacketConnCtx. The API for ConnCtx remains the same, except for instead of New() the constructor is NewConnCtx(). The connctx package is kept around to not break existing consumers, but they will start getting linter warnings encouraging them to switch to netctx. We can choose to remove the connctx after a sufficient deprecation period if needed.

@hasheddan hasheddan requested a review from stv0g July 10, 2023 19:01
Copy link
Member

@stv0g stv0g left a comment

Choose a reason for hiding this comment

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

Hi @hasheddan,

looks good to me :) I have a few smaller comments.
Ideally, we would also comment all the public methods.
I think here we can largely copy and adjust the respective single line comments from the net package.

We dont need to copy the full comments. But a single sentence per method would be nice.

}

// ReadFromWriterTo is a composite of ReadFromWriterTo.
type ReadFromWriterTo interface {
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually used somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't -- it matches the ReadWriter in ConnCtx, but I don't think we need to include it until it is used 👍🏻

}

// PacketConnCtx is a wrapper of net.PacketConn using context.Context.
type PacketConnCtx interface {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about removing the Ctx from the naming here? Isnt it implicitly given by the package name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a fan! Only kept it for consistency with the existing ConnCtx, but since we are moving it anyway I think we can use netctx.Conn and netctx.PacketConn 👍🏻

}

// NewPacketConn creates a new PacketConnCtx wrapping the given net.PacketConn.
func NewPacketConn(pconn net.PacketConn) PacketConnCtx {
Copy link
Member

Choose a reason for hiding this comment

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

Also in reference to the previous commit. I would find it more harmonized if a NewXXX actually creates a XXX.
But, I would prefer to to simply rename the (Packet)?ConnCtx types to (Packet)?Conn.


select {
case <-p.closed:
return 0, nil, io.EOF
Copy link
Member

Choose a reason for hiding this comment

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

Isn't a net.ErrClosed more appropriate here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems more reasonable to me 👍🏻


select {
case <-c.closed:
return 0, io.EOF
Copy link
Member

Choose a reason for hiding this comment

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

Isn't a net.ErrClosed more appropriate here?

@hasheddan hasheddan requested a review from stv0g July 11, 2023 01:50
Copy link
Contributor Author

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

Thanks @stv0g! Updated based on your suggestions!

@stv0g
Copy link
Member

stv0g commented Jul 11, 2023

Great :) You can merge it if you like

Copy link
Contributor Author

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

Thanks @stv0g! Just updated with the docstrings as well 👍🏻

Moves ConnCtx to the netctx package, which will be expanded to include
additional wrapped network interfaces.

Signed-off-by: Daniel Mangum <[email protected]>
Marks the connctx package as deprecated in favor of netctx.

Signed-off-by: Daniel Mangum <[email protected]>
Updates to construct a new ConnCtx using NewConnCtx rather than New so
that it does not conflict with other wrapped net interfaces.

Signed-off-by: Daniel Mangum <[email protected]>
Adds a PacketConnCtx that wraps net.PacketConn.

Signed-off-by: Daniel Mangum <[email protected]>
Adds unit tests for PacketConnCtx that match the existing unit tests for
ConnCtx.

Signed-off-by: Daniel Mangum <[email protected]>
Moves from using the now deprecated connctx to using netctx in stress
tests.

Signed-off-by: Daniel Mangum <[email protected]>
Refactors to use names that match the upstream net types.

Signed-off-by: Daniel Mangum <[email protected]>
Updates to use net.ErrClosed when connection has been closed.

Signed-off-by: Daniel Mangum <[email protected]>
Adds documentation for all public netctx methods.

Signed-off-by: Daniel Mangum <[email protected]>
Adds Daniel Mangum to AUTHORS.txt.

Signed-off-by: Daniel Mangum <[email protected]>
@hasheddan hasheddan merged commit a789100 into pion:master Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants