Created
November 6, 2020 15:05
-
-
Save knocte/4aabc711a6c202a348b1dda1574e1a5c to your computer and use it in GitHub Desktop.
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
diff --git a/STUN/STUNClient.cs b/STUN/STUNClient.cs | |
index 280a2cc..1d1c51d 100644 | |
--- a/STUN/STUNClient.cs | |
+++ b/STUN/STUNClient.cs | |
@@ -30,7 +30,7 @@ namespace STUN | |
/// </param> | |
public static Task<STUNQueryResult> QueryAsync(IPEndPoint server, STUNQueryType queryType, bool closeSocket) | |
{ | |
- return Task.Run(() => Query(server, queryType, closeSocket)); | |
+ return Task.Run(() => QueryInternal(server, queryType, closeSocket)); | |
} | |
/// <param name="socket">A UDP <see cref="Socket"/> that will use for query. You can also use <see cref="UdpClient.Client"/></param> | |
@@ -42,13 +42,28 @@ namespace STUN | |
return Task.Run(() => Query(socket, server, queryType, natTypeDetectionRfc)); | |
} | |
+ private static STUNQueryResult Query(IPEndPoint server, STUNQueryType queryType, bool closeSocket, | |
+ NATTypeDetectionRFC natTypeDetectionRfc = NATTypeDetectionRFC.Rfc3489) | |
+ { | |
+ var result = QueryInternal(server, queryType, closeSocket, natTypeDetectionRfc); | |
+ if (result.QueryError != STUNQueryError.Success) | |
+ throw new STUNExcepttion(result.QueryError); | |
+ return result; | |
+ } | |
+ | |
+ private static STUNQueryResult TryQuery(IPEndPoint server, STUNQueryType queryType, bool closeSocket, | |
+ NATTypeDetectionRFC natTypeDetectionRfc = NATTypeDetectionRFC.Rfc3489) | |
+ { | |
+ return QueryInternal(server, queryType, closeSocket, natTypeDetectionRfc); | |
+ } | |
+ | |
/// <param name="server">Server address</param> | |
/// <param name="queryType">Query type</param> | |
/// <param name="closeSocket"> | |
/// Set to true if created socket should closed after the query | |
/// else <see cref="STUNQueryResult.Socket"/> will leave open and can be used. | |
/// </param> | |
- public static STUNQueryResult Query(IPEndPoint server, STUNQueryType queryType, bool closeSocket, | |
+ private static STUNQueryResult QueryInternal(IPEndPoint server, STUNQueryType queryType, bool closeSocket, | |
NATTypeDetectionRFC natTypeDetectionRfc = NATTypeDetectionRFC.Rfc3489) | |
{ | |
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment