Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Voice Gateway V4 and new encryption modes (#651)
* Added support for suffix/lite encryption * Move to vgw v4 * Use IP given from discord payload rather than original endpoint * Reduce required allocations for en-/decryption * Remove un-used createEchoPacket method * Fix deadlock when changing connection listener in its own methods * Reduce packet provider to single buffer
- Loading branch information
1 parent
da41772
commit 16437e1
Showing
11 changed files
with
514 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/net/dv8tion/jda/core/audio/AudioEncryption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2015-2018 Austin Keener & Michael Ritter & Florian Spieß | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.dv8tion.jda.core.audio; | ||
|
||
import org.json.JSONArray; | ||
|
||
public enum AudioEncryption | ||
{ | ||
// these are ordered by priority, lite > suffix > normal | ||
// we prefer lite because it uses only 4 bytes for its nonce while the others use 24 bytes | ||
XSALSA20_POLY1305_LITE, | ||
XSALSA20_POLY1305_SUFFIX, | ||
XSALSA20_POLY1305; | ||
|
||
private final String key; | ||
|
||
AudioEncryption() | ||
{ | ||
this.key = name().toLowerCase(); | ||
} | ||
|
||
public String getKey() | ||
{ | ||
return key; | ||
} | ||
|
||
public static AudioEncryption getPreferredMode(JSONArray array) | ||
{ | ||
AudioEncryption encryption = null; | ||
for (Object o : array) | ||
{ | ||
try | ||
{ | ||
String name = ((String) o).toUpperCase(); | ||
AudioEncryption e = valueOf(name); | ||
if (encryption == null || e.ordinal() < encryption.ordinal()) | ||
encryption = e; | ||
} | ||
catch (IllegalArgumentException ignored) {} | ||
} | ||
return encryption; | ||
} | ||
} |
Oops, something went wrong.