Skip to content

Commit dcea2ba

Browse files
committed
Fix sdp strings and use (now configurable) port allocator config more aligned with vanilla client
Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
1 parent 68df415 commit dcea2ba

6 files changed

Lines changed: 48 additions & 39 deletions

File tree

‎gradle.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Only update version on publishing to Maven Central
2-
version=1.6.0
2+
version=1.6.1

‎transport-nethernet/src/main/java/dev/kastle/netty/channel/nethernet/NetherNetClientChannel.java‎

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public class NetherNetClientChannel extends NetherNetChannel {
5151

5252
privatevolatileScheduledFuture<?> handshakeTimeoutTask;
5353

54-
privatevolatileStringlocalUfrag;
55-
5654
privateintretryCount = 0;
5755

5856
/**
@@ -204,6 +202,7 @@ private void resetAndRetryHandshake() {
204202

205203
privatevoidinitWebRTC(List<NetherNetSignaling.IceServerInfo> iceServers) {
206204
RTCConfigurationrtcConfig = newRTCConfiguration();
205+
rtcConfig.portAllocatorConfig = this.config.getOption(NetherChannelOption.NETHER_PORT_ALLOCATOR_CONFIG);
207206
rtcConfig.bundlePolicy = RTCBundlePolicy.MAX_BUNDLE;
208207

209208
if (iceServers != null) {
@@ -219,24 +218,10 @@ private void initWebRTC(List<NetherNetSignaling.IceServerInfo> iceServers) {
219218
peerConnection = factory.createPeerConnection(rtcConfig, newPeerConnectionObserver() {
220219
@Override
221220
publicvoidonIceCandidate(RTCIceCandidatecandidate) {
222-
// Wait until we have the ufrag (usually available immediately after createOffer)
223-
if (localUfrag == null) {
224-
log.warn("Generated ICE candidate before local ufrag was available. Skipping.");
225-
return;
226-
}
227-
228-
Stringsdp = candidate.sdp.trim();
229-
230-
// Format: <StandardSDP> ufrag <LocalUfrag> network-id <LocalNetworkID> network-cost 0
231-
StringBuildersb = newStringBuilder(sdp)
232-
.append(" ufrag ").append(localUfrag)
233-
.append(" network-id ").append(signaling.getLocalNetworkId())
234-
.append(" network-cost 0");
235-
236221
try {
237222
signaling.sendSignal(
238223
targetNetworkId,
239-
NetherNetConstants.buildSignalCandidateAdd(connectionId, sb.toString())
224+
NetherNetConstants.buildSignalCandidateAdd(connectionId, candidate.sdp)
240225
);
241226
} catch (Exceptione) {
242227
log.error("Failed to send ICE candidate", e);
@@ -261,29 +246,12 @@ public void onConnectionChange(RTCPeerConnectionState state) {
261246
setupDataChannels();
262247
}
263248

264-
privateStringextractUfrag(Stringsdp) {
265-
if (sdp == null) return"";
266-
for (Stringline : sdp.split("\\r?\\n")) {
267-
line = line.trim();
268-
if (line.startsWith("a=ice-ufrag:")) {
269-
returnline.substring("a=ice-ufrag:".length()).trim();
270-
}
271-
// Some implementations might omit 'a='
272-
if (line.startsWith("ice-ufrag:")) {
273-
returnline.substring("ice-ufrag:".length()).trim();
274-
}
275-
}
276-
log.warn("Could not find ice-ufrag in local SDP!");
277-
return"";
278-
}
279-
280249
privatevoidcreateAndSendOffer() {
281250
if (peerConnection == null) return;
282251
peerConnection.createOffer(newRTCOfferOptions(), newCreateSessionDescriptionObserver() {
283252
@Override
284253
publicvoidonSuccess(RTCSessionDescriptiondescription) {
285254
if (peerConnection == null) return;
286-
NetherNetClientChannel.this.localUfrag = extractUfrag(description.sdp);
287255
peerConnection.setLocalDescription(description, newSetSessionDescriptionObserver() {
288256
@Override
289257
publicvoidonSuccess() {

‎transport-nethernet/src/main/java/dev/kastle/netty/channel/nethernet/NetherNetServerChannel.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ protected void doBind(SocketAddress localAddress) throws Exception {
7777

7878
publicvoidacceptConnection(longconnectionId, StringofferSdp, StringremoteNetworkId) {
7979
RTCConfigurationrtcConfig = newRTCConfiguration();
80+
rtcConfig.portAllocatorConfig = this.config.getOption(NetherChannelOption.NETHER_PORT_ALLOCATOR_CONFIG);
8081
rtcConfig.bundlePolicy = RTCBundlePolicy.MAX_BUNDLE;
8182

8283
// Inject ICE servers if the signaling implementation supports it
Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packagedev.kastle.netty.channel.nethernet.config;
22

3+
importdev.kastle.webrtc.PortAllocatorConfig;
34
importio.netty.channel.Channel;
45
importio.netty.channel.ChannelOption;
56
importio.netty.channel.DefaultChannelConfig;
@@ -10,25 +11,56 @@
1011
publicclassDefaultNetherChannelConfigextendsDefaultChannelConfig {
1112
privatefinalMap<ChannelOption<?>, Object> options = newConcurrentHashMap<>();
1213

14+
privatevolatilePortAllocatorConfigportAllocatorConfig = newPortAllocatorConfig()
15+
.setDisableTcp(true)
16+
.setEnableIpv6(true)
17+
.setEnableIpv6OnWifi(true)
18+
.setEnableAnyAddressPorts(true)
19+
.setDisableAdapterEnumeration(false)
20+
.setEnableSharedSocket(true)
21+
.setEnableAnyAddressPorts(true)
22+
.setDisableCostlyNetworks(true)
23+
.setDisableLinkLocalNetworks(true);
24+
1325
publicDefaultNetherChannelConfig(Channelchannel) {
1426
super(channel);
1527
}
1628

29+
@Override
30+
publicMap<ChannelOption<?>, Object> getOptions() {
31+
returnthis.getOptions(
32+
super.getOptions(),
33+
NetherChannelOption.NETHER_PORT_ALLOCATOR_CONFIG
34+
);
35+
}
36+
1737
@SuppressWarnings("unchecked")
1838
@Override
1939
public <T> TgetOption(ChannelOption<T> option) {
20-
if (options.containsKey(option)) {
40+
41+
if (option == NetherChannelOption.NETHER_PORT_ALLOCATOR_CONFIG) {
42+
return (T) this.portAllocatorConfig;
43+
} elseif (options.containsKey(option)) {
2144
return (T) options.get(option);
2245
}
46+
2347
returnsuper.getOption(option);
2448
}
2549

2650
@Override
2751
public <T> booleansetOption(ChannelOption<T> option, Tvalue) {
28-
if (super.setOption(option, value)) {
52+
if (option == NetherChannelOption.NETHER_PORT_ALLOCATOR_CONFIG) {
53+
this.setPortAllocatorConfig((PortAllocatorConfig) value);
54+
returntrue;
55+
} elseif (super.setOption(option, value)) {
56+
returntrue;
57+
} else {
58+
options.put(option, value);
2959
returntrue;
3060
}
31-
options.put(option, value);
32-
returntrue;
61+
}
62+
63+
voidsetPortAllocatorConfig(PortAllocatorConfigportAllocatorConfig) {
64+
this.portAllocatorConfig = portAllocatorConfig;
3365
}
3466
}

‎transport-nethernet/src/main/java/dev/kastle/netty/channel/nethernet/config/NetherChannelOption.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
packagedev.kastle.netty.channel.nethernet.config;
22

3+
importdev.kastle.webrtc.PortAllocatorConfig;
34
importio.netty.channel.ChannelOption;
45

56
publicclassNetherChannelOption<T> extendsChannelOption<T> {
67

8+
/**
9+
* The PortAllocatorConfig used for WebRTC connections.
10+
*/
11+
publicstaticfinalChannelOption<PortAllocatorConfig> NETHER_PORT_ALLOCATOR_CONFIG =
12+
valueOf(NetherChannelOption.class, "NETHER_PORT_ALLOCATOR_CONFIG");
13+
714
/**
815
* The timeout in seconds for completing the WebRTC handshake on the client before retrying.
916
*/

‎transport-nethernet/src/main/java/dev/kastle/netty/channel/nethernet/signaling/NetherNetXboxSignaling.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ private void handleNotFound(JsonObject json, String rawText) {
231231
}
232232

233233
privatevoidhandleSignal(JsonObjectjson) {
234+
log.trace("Received Signal: {}", json.toString());
234235
Stringsender = json.has("From") ? json.get("From").getAsString() : "0";
235236
if (!json.has("Message")) {
236237
log.warn("Received SIGNAL (1) without Message payload.");

0 commit comments

Comments
 (0)