udp: Add comments to pass lint
This commit is contained in:
parent
4c3cd6cc0a
commit
f98c675bc7
3 changed files with 8 additions and 3 deletions
|
@ -11,11 +11,14 @@ import (
|
|||
"crypto/rand"
|
||||
)
|
||||
|
||||
// ConnectionIDGenerator represents the logic to generate 64-bit UDP
|
||||
// connection IDs from peer IP addresses.
|
||||
type ConnectionIDGenerator struct {
|
||||
iv, iv2 []byte
|
||||
block cipher.Block
|
||||
}
|
||||
|
||||
// Init generates the AES key and sets up the first initialization vector.
|
||||
func (g *ConnectionIDGenerator) Init() error {
|
||||
key := make([]byte, 16)
|
||||
_, err := rand.Read(key)
|
||||
|
@ -31,6 +34,7 @@ func (g *ConnectionIDGenerator) Init() error {
|
|||
return g.NewIV()
|
||||
}
|
||||
|
||||
// Generate returns the 64-bit connection ID for an IP
|
||||
func (g *ConnectionIDGenerator) Generate(ip []byte) []byte {
|
||||
return g.generate(ip, g.iv)
|
||||
}
|
||||
|
@ -55,6 +59,8 @@ func (g *ConnectionIDGenerator) generate(ip []byte, iv []byte) []byte {
|
|||
return ct[:8]
|
||||
}
|
||||
|
||||
// Matches checks if the given connection ID matches an IP with the current or
|
||||
// previous initialization vectors.
|
||||
func (g *ConnectionIDGenerator) Matches(id []byte, ip []byte) bool {
|
||||
if expected := g.generate(ip, g.iv); bytes.Equal(id, expected) {
|
||||
return true
|
||||
|
@ -69,6 +75,7 @@ func (g *ConnectionIDGenerator) Matches(id []byte, ip []byte) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// NewIV generates a new initialization vector and rotates the current one.
|
||||
func (g *ConnectionIDGenerator) NewIV() error {
|
||||
newiv := make([]byte, 16)
|
||||
if _, err := rand.Read(newiv); err != nil {
|
||||
|
|
|
@ -129,8 +129,6 @@ func (s *Server) newAnnounce(packet []byte, ip net.IP) (*models.Announce, error)
|
|||
ip = ipv4
|
||||
}
|
||||
|
||||
// TODO(pushrax): what exactly is the key "key" used for?
|
||||
|
||||
numWant := binary.BigEndian.Uint32(packet[92:96])
|
||||
port := binary.BigEndian.Uint16(packet[96:98])
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ func (w *Writer) WriteAnnounce(res *models.AnnounceResponse) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// WriteAnnounce encodes a scrape response according to the UDP spec.
|
||||
// WriteScrape encodes a scrape response according to the UDP spec.
|
||||
func (w *Writer) WriteScrape(res *models.ScrapeResponse) error {
|
||||
w.writeHeader(2)
|
||||
|
||||
|
|
Loading…
Reference in a new issue