-
Notifications
You must be signed in to change notification settings - Fork 56
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
Conversation
Codecov ReportPatch coverage:
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
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
connctx/connctx.go
Outdated
// Package connctx wraps net.Conn using context.Context. | ||
// Deprecated: use netctx instead. | ||
package connctx |
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.
There are packages that currently depend on this, so we deprecate while introducing the same functionality in netctx
.
f473f54
to
1fdb254
Compare
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? |
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.
@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.
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.
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.
netctx/packetconnctx.go
Outdated
} | ||
|
||
// ReadFromWriterTo is a composite of ReadFromWriterTo. | ||
type ReadFromWriterTo interface { |
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.
Is this actually used somewhere?
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.
It isn't -- it matches the ReadWriter
in ConnCtx
, but I don't think we need to include it until it is used 👍🏻
netctx/packetconnctx.go
Outdated
} | ||
|
||
// PacketConnCtx is a wrapper of net.PacketConn using context.Context. | ||
type PacketConnCtx interface { |
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.
What do you think about removing the Ctx
from the naming here? Isnt it implicitly given by the package name?
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.
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
👍🏻
netctx/packetconnctx.go
Outdated
} | ||
|
||
// NewPacketConn creates a new PacketConnCtx wrapping the given net.PacketConn. | ||
func NewPacketConn(pconn net.PacketConn) PacketConnCtx { |
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.
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
.
netctx/packetconnctx.go
Outdated
|
||
select { | ||
case <-p.closed: | ||
return 0, nil, io.EOF |
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.
Isn't a net.ErrClosed
more appropriate here?
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.
That seems more reasonable to me 👍🏻
netctx/connctx.go
Outdated
|
||
select { | ||
case <-c.closed: | ||
return 0, io.EOF |
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.
Isn't a net.ErrClosed
more appropriate here?
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.
Thanks @stv0g! Updated based on your suggestions!
Great :) You can merge it if you like |
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.
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]>
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