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

Commit 16ea98e

Browse files
authored
fix: use 74-byte packets for IP Discovery (#525)
1 parent dd8e29c commit 16ea98e

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

voiceconnection.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,33 +191,37 @@ waiter:
191191
return
192192
}
193193

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

202-
ipBuffer := make([]byte, 70)
206+
ipBuffer := make([]byte, 74)
203207
var n int
204208
n, err = voice.udp.Read(ipBuffer)
205209
if err != nil {
206210
return
207211
}
208-
if n < 70 {
209-
err = errors.New("udp packet received from discord is not the required 70 bytes")
212+
if n < 74 {
213+
err = errors.New("udp packet received from discord is not the required 74 bytes")
210214
return
211215
}
212216

213-
ipb := string(ipBuffer[4:68])
217+
ipb := string(ipBuffer[8:72])
214218
nullPos := strings.Index(ipb, "\x00")
215219
if nullPos < 0 {
216220
err = errors.New("udp ip discovery did not contain a null terminator")
217221
return
218222
}
219223
ip := ipb[:nullPos]
220-
port := binary.LittleEndian.Uint16(ipBuffer[68:70])
224+
port := binary.LittleEndian.Uint16(ipBuffer[72:74])
221225

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

0 commit comments

Comments
 (0)