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

avoid type confusion between protocol.PacketType and logging.PacketType #3108

Merged
merged 1 commit into from
Apr 2, 2021

Conversation

marten-seemann
Copy link
Member

The enums have completely different meanings. protocol.PacketType only defines long header types, whereas logging.PacketType defines all different types of QUIC packets (including short header packets).

This led to a bug in metrics implementation in libp2p: There, we were doing something along those lines:

func (m *tracer) getEncLevel(hdr *logging.ExtendedHeader) string {
	if hdr.Type == logging.PacketType0RTT {
		return "0-RTT"
	}
        // ....
}

This leads to wrong results, as hdr.Type is a protocol.PacketType and not a logging.PacketType. It just compiled because we defined logging.PacketType as an alias for protocol.PacketType. With this PR, the code snippet above will fail to compile.

The enums have completely different meanings. protocol.PacketType only
defines long header types, whereas logging.PacketType defines all
different types of QUIC packets (including short header packets).
@codecov
Copy link

codecov bot commented Mar 21, 2021

Codecov Report

Merging #3108 (e9b4f9b) into master (81d16a9) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3108      +/-   ##
==========================================
+ Coverage   85.47%   85.48%   +0.01%     
==========================================
  Files         131      131              
  Lines        9650     9650              
==========================================
+ Hits         8248     8249       +1     
+ Misses       1034     1033       -1     
  Partials      368      368              
Impacted Files Coverage Δ
internal/utils/rand.go 75.00% <0.00%> (+12.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81d16a9...e9b4f9b. Read the comment docs.

Copy link
Member

@lucas-clemente lucas-clemente left a comment

Choose a reason for hiding this comment

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

IIRC we initially did this because the protocol pkg is internal, so you wouldn't be able to use APIs with PacketTypes. Is that not an issue anymore?

@marten-seemann
Copy link
Member Author

That's not an issue when we set an alias, as we do for many other types.
The issue here is that the values defined for the logging.PacketType and the protocol.PacketType are different. For example, the protocol.PacketType doesn't define a type for short header packets.

@marten-seemann marten-seemann merged commit 0c42736 into master Apr 2, 2021
@marten-seemann marten-seemann deleted the avoid-packet-type-confusion branch April 2, 2021 10:28
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
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