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

Use 74 byte payload for udp discovery #2413

Merged
merged 2 commits into from Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -29,7 +29,7 @@ plugins {
id("com.github.johnrengelman.shadow") version "5.1.0"
}

val versionObj = Version(major = "4", minor = "4", revision = "0")
val versionObj = Version(major = "4", minor = "4", revision = "1")

project.group = "net.dv8tion"
project.version = "$versionObj"
Expand Down
Expand Up @@ -583,8 +583,8 @@ private InetSocketAddress handleUdpDiscovery(InetSocketAddress address, int ssrc
//Create new UDP socket for communication
audioConnection.udpSocket = new DatagramSocket();

//Create a byte array of length 70 containing our ssrc.
ByteBuffer buffer = ByteBuffer.allocate(70); //70 taken from documentation
//Create a byte array of length 74 containing our ssrc.
ByteBuffer buffer = ByteBuffer.allocate(74); //74 taken from documentation
buffer.putShort((short) 1); // 1 = send (receive will be 2)
buffer.putShort((short) 70); // length = 70 bytes (required)
buffer.putInt(ssrc); // Put the ssrc that we were given into the packet to send back to discord.
Expand All @@ -595,7 +595,7 @@ private InetSocketAddress handleUdpDiscovery(InetSocketAddress address, int ssrc
audioConnection.udpSocket.send(discoveryPacket);

//Discord responds to our packet, returning a packet containing our external ip and the port we connected through.
DatagramPacket receivedPacket = new DatagramPacket(new byte[70], 70); //Give a buffer the same size as the one we sent.
DatagramPacket receivedPacket = new DatagramPacket(new byte[74], 74); //Give a buffer the same size as the one we sent.
audioConnection.udpSocket.setSoTimeout(1000);
audioConnection.udpSocket.receive(receivedPacket);

Expand All @@ -609,7 +609,7 @@ private InetSocketAddress handleUdpDiscovery(InetSocketAddress address, int ssrc

//Take bytes between SSRC and PORT and put them into a string
// null bytes at the beginning are skipped and the rest are appended to the end of the string
String ourIP = new String(received, 4, received.length - 6);
String ourIP = new String(received, 8, received.length - 10);
// Removes the extra nulls attached to the end of the IP string
ourIP = ourIP.trim();

Expand Down