Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
fix: use 74-byte packets for IP Discovery (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
crivasr committed Mar 10, 2023
1 parent dd8e29c commit 16ea98e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions voiceconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,33 +191,37 @@ waiter:
return
}

// SendOpusFrame our SSRC with no further data for the IP discovery process.
ssrcBuffer := make([]byte, 70)
binary.BigEndian.PutUint32(ssrcBuffer, ready.SSRC)
// SendOpusFrame our SSRC for the IP discovery process.
ssrcBuffer := make([]byte, 74)
// Packet type (0x1 is request, 0x2 is response)
binary.BigEndian.PutUint16(ssrcBuffer, 0x1)
// Packet length (excluding type and length fields)
binary.BigEndian.PutUint16(ssrcBuffer[2:], 70)
binary.BigEndian.PutUint32(ssrcBuffer[4:], ready.SSRC)
_, err = voice.udp.Write(ssrcBuffer)
if err != nil {
return
}

ipBuffer := make([]byte, 70)
ipBuffer := make([]byte, 74)
var n int
n, err = voice.udp.Read(ipBuffer)
if err != nil {
return
}
if n < 70 {
err = errors.New("udp packet received from discord is not the required 70 bytes")
if n < 74 {
err = errors.New("udp packet received from discord is not the required 74 bytes")
return
}

ipb := string(ipBuffer[4:68])
ipb := string(ipBuffer[8:72])
nullPos := strings.Index(ipb, "\x00")
if nullPos < 0 {
err = errors.New("udp ip discovery did not contain a null terminator")
return
}
ip := ipb[:nullPos]
port := binary.LittleEndian.Uint16(ipBuffer[68:70])
port := binary.LittleEndian.Uint16(ipBuffer[72:74])

// Tell the websocket which encryption mode we want to use. We'll go with XSalsa20 and Poly1305 since that's what
// libSodium/NaCl and golang.org/x/crypto/nacl/secretbox use. If both Discord and Go both start supporting more
Expand Down

0 comments on commit 16ea98e

Please sign in to comment.