Permalink
Browse files

Merge remote-tracking branch 'origin/master'

Conflicts:
	Mono.Nat/.gitignore
  • Loading branch information...
seuffert
seuffert committed May 25, 2011
2 parents e9d67b7 + bd2261e commit 66ba66615991301bc9b85bbb5fcdcf4b7814aa48
Showing with 3,917 additions and 13,569 deletions.
  1. +1 −1 Mono.Nat/.gitignore
  2. +2 −2 Mono.Nat/AssemblyInfo.cs
  3. +0 −1 Mono.Nat/ISearcher.cs
  4. +43 −10 Mono.Nat/Mono.Nat.csproj
  5. +9 −6 Mono.Nat/NatUtility.cs
  6. +44 −15 Mono.Nat/Pmp/PmpNatDevice.cs
  7. +63 −15 Mono.Nat/PmpSearcher.cs
  8. +10 −1 Mono.Nat/UpnpSearcher.cs
  9. +1 −1 PacketDotNet/AssemblyInfo.cs
  10. +2 −6 PacketDotNet/EthernetPacket.cs
  11. +0 −67 PacketDotNet/IPProtocol.cs
  12. +0 −1 PacketDotNet/IPv4Packet.cs
  13. +0 −1 PacketDotNet/IPv6Packet.cs
  14. +0 −4 PacketDotNet/IpPacket.cs
  15. +1 −2 PacketDotNet/LinuxSLLPacket.cs
  16. +1 −2 PacketDotNet/PPPPacket.cs
  17. +2 −3 PacketDotNet/PPPoEPacket.cs
  18. +0 −43 PacketDotNet/Packet.cs
  19. +2 −4 PacketDotNet/PacketDotNet.csproj
  20. +0 −13 PacketDotNet/PacketDotNet.csproj.user
  21. +0 −122 PacketDotNet/RawPacket.cs
  22. +0 −10 PacketDotNet/TransportProtocols.cs
  23. +1 −1 SharpPcap/ARP.cs
  24. +9 −9 SharpPcap/AirPcap/AirPcapDevice.cs
  25. +1 −1 SharpPcap/AssemblyInfo.cs
  26. +4 −4 SharpPcap/CaptureEventArgs.cs
  27. +0 −42 SharpPcap/CaptureMode.cs
  28. +7 −2 SharpPcap/ICaptureDevice.cs
  29. +20 −0 SharpPcap/LibPcap/LibPcapLiveDevice.cs
  30. +0 −23 SharpPcap/LibPcap/LibPcapLiveDeviceList.cs
  31. +47 −13 SharpPcap/LibPcap/PcapDevice.cs
  32. +0 −330 SharpPcap/LivePcapDevice.cs
  33. +0 −232 SharpPcap/LivePcapDeviceList.cs
  34. +0 −125 SharpPcap/OfflinePcapDevice.cs
  35. +0 −92 SharpPcap/PcapAddress.cs
  36. +0 −622 SharpPcap/PcapDevice.cs
  37. +0 −399 SharpPcap/PcapDeviceCaptureLoop.cs
  38. +0 −172 SharpPcap/PcapHeader.cs
  39. +0 −182 SharpPcap/PcapInterface.cs
  40. +0 −126 SharpPcap/PcapStatistics.cs
  41. +0 −293 SharpPcap/PcapUnmanagedStructures.cs
  42. +11 −13 {PacketDotNet → SharpPcap}/PosixTimeval.cs
  43. +90 −0 SharpPcap/RawCapture.cs
  44. +0 −302 SharpPcap/SafeNativeMethods.cs
  45. +0 −196 SharpPcap/SendQueue.cs
  46. +0 −41 SharpPcap/SendQueueTransmitModes.cs
  47. +2 −0 SharpPcap/SharpPcap.csproj
  48. +0 −13 SharpPcap/SharpPcap.csproj.user
  49. +0 −173 SharpPcap/Sockaddr.cs
  50. +0 −56 SharpPcap/StatisticsModeEventArgs.cs
  51. +0 −31 SharpPcap/StatisticsModeEventHandler.cs
  52. +0 −74 SharpPcap/StatisticsModePacket.cs
  53. +1 −1 SharpPcap/WinPcap/SendQueue.cs
  54. +2 −2 SharpPcap/WinPcap/StatisticsModeEventArgs.cs
  55. +2 −2 SharpPcap/WinPcap/StatisticsModePacket.cs
  56. +27 −2 SharpPcap/WinPcap/WinPcapDevice.cs
  57. +234 −15 SharpPcap/docs/Api/SharpPcap.xml
  58. +84 −0 XBSlink Installer/VersionCompare.nsh
  59. BIN XBSlink Installer/WinPcap_4_1_2.exe
  60. +16 −3 XBSlink Installer/XBSlink_installer_MUI2.nsi
  61. +25 −7 XBSlink Installer/XBSlink_license.txt
  62. BIN XBSlink Installer/winpcap_setup.exe
  63. +0 −8 XBSlink.sln
  64. +53 −34 XBSlink/CommandLine.cs
  65. +15 −19 XBSlink/DebugWindow.Designer.cs
  66. +89 −32 XBSlink/DebugWindow.cs
  67. +3 −0 XBSlink/DebugWindow.resx
  68. +463 −219 XBSlink/Form1.Designer.cs
  69. +609 −242 XBSlink/Form1.cs
  70. +2 −2 XBSlink/Form1.resx
  71. +2 −2 XBSlink/Properties/AssemblyInfo.cs
  72. +63 −8 XBSlink/Properties/Resources.Designer.cs
  73. +24 −0 XBSlink/Properties/Resources.resx
  74. +278 −23 XBSlink/Properties/Settings.Designer.cs
  75. +74 −6 XBSlink/Properties/Settings.settings
  76. +28 −0 XBSlink/Settings.cs
  77. +9 −4 XBSlink/XBSlink.csproj
  78. +82 −0 XBSlink/XBSlink.exe.config
  79. BIN XBSlink/about_xbslink.rtf
  80. +80 −1 XBSlink/app.config
  81. BIN XBSlink/error_16.png
  82. BIN XBSlink/ok_16.png
  83. BIN XBSlink/warning_16.png
  84. +7 −3 XBSlink/xbs_chat.cs
  85. +37 −27 XBSlink/xbs_cloudlist.cs
  86. +92 −17 XBSlink/xbs_messages.cs
  87. +697 −0 XBSlink/xbs_nat.cs
  88. +45 −86 XBSlink/xbs_natstun.cs
  89. +113 −23 XBSlink/xbs_node.cs
  90. +31 −14 XBSlink/xbs_node_list.cs
  91. +6 −2 XBSlink/xbs_node_message.cs
  92. +14 −103 XBSlink/xbs_settings.cs
  93. +159 −67 XBSlink/xbs_sniffer.cs
  94. +78 −66 XBSlink/xbs_udp_listener.cs
  95. +0 −4 stunlib/.gitignore
  96. +0 −257 stunlib/IO/Base64.cs
  97. +0 −5,910 stunlib/LumiSoft.Net
  98. +0 −23 stunlib/Net.sln
  99. +0 −938 stunlib/Net_Utils.cs
  100. +0 −33 stunlib/Properties/AssemblyInfo.cs
  101. +0 −350 stunlib/STUN/Client/STUN_Client.cs
  102. +0 −59 stunlib/STUN/Client/STUN_NetType.cs
  103. +0 −49 stunlib/STUN/Client/STUN_Result.cs
  104. +0 −684 stunlib/STUN/Message/STUN_Message.cs
  105. +0 −42 stunlib/STUN/Message/STUN_MessageType.cs
  106. +0 −59 stunlib/STUN/Message/STUN_t_ChangeRequest.cs
  107. +0 −52 stunlib/STUN/Message/STUN_t_ErrorCode.cs
  108. +0 −113 stunlib/stunlib.csproj
  109. +0 −59 stunlib/stunlib.csproj.user
View
@@ -1,4 +1,4 @@
/bin/
/obj/
/Mono.Nat.pidb
-/*.csproj.user
+/*.Nat.csproj.user
View
@@ -13,7 +13,7 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("c8e81e95-9f15-4eb8-8982-3d2c9cd95dee")]
-[assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyFileVersion("1.0.2.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: CLSCompliant(false)]
View
@@ -14,7 +14,6 @@ internal interface ISearcher
event EventHandler<DeviceEventArgs> DeviceLost;
void Search();
- IPEndPoint SearchEndpoint { get; }
void Handle(IPAddress localAddress, byte[] response, IPEndPoint endpoint);
DateTime NextSearch { get; }
}
View
@@ -8,30 +8,44 @@
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>Mono.Nat</AssemblyName>
<RootNamespace>Mono.Nat</RootNamespace>
- <ProductVersion>9.0.30729</ProductVersion>
+ <ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <UpgradeBackupLocation>
- </UpgradeBackupLocation>
+ <OldToolsVersion>2.0</OldToolsVersion>
+ <UpgradeBackupLocation />
<TargetFrameworkProfile />
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>false</DebugSymbols>
+ <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>TRACE;DEBUG</DefineConstants>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>4</WarningLevel>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputType>Library</OutputType>
<RootNamespace>Mono.Nat</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugSymbols>false</DebugSymbols>
- <DebugType>none</DebugType>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
@@ -80,7 +94,26 @@
<Compile Include="Upnp\UpnpNatDevice.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
+ <BootstrapperPackage Include=".NETFramework,Version=v4.0">
+ <Visible>False</Visible>
+ <ProductName>Microsoft .NET Framework 4 %28x86 und x64%29</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
View
@@ -36,7 +36,7 @@ namespace Mono.Nat
{
public static class NatUtility
{
- private static bool searching;
+ private static ManualResetEvent searching;
public static event EventHandler<DeviceEventArgs> DeviceFound;
public static event EventHandler<DeviceEventArgs> DeviceLost;
@@ -60,9 +60,11 @@ public static bool Verbose
static NatUtility()
{
+ searching = new ManualResetEvent(false);
+
controllers = new List<ISearcher>();
controllers.Add(UpnpSearcher.Instance);
- //controllers.Add(PmpSearcher.Instance);
+ controllers.Add(PmpSearcher.Instance);
foreach (ISearcher searcher in controllers)
{
@@ -93,13 +95,15 @@ private static void SearchAndListen()
{
while (true)
{
+ searching.WaitOne();
+
try
{
Receive(UpnpSearcher.Instance, UpnpSearcher.sockets);
Receive(PmpSearcher.Instance, PmpSearcher.sockets);
foreach (ISearcher s in controllers)
- if (s.NextSearch < DateTime.Now && searching)
+ if (s.NextSearch < DateTime.Now)
{
Log("Searching for: {0}", s.GetType().Name);
s.Search();
@@ -130,13 +134,12 @@ static void Receive (ISearcher searcher, List<UdpClient> clients)
public static void StartDiscovery ()
{
- searching = true;
+ searching.Set();
}
public static void StopDiscovery ()
{
- controllers.Clear();
- searching = false;
+ searching.Reset();
}
[Obsolete ("This method serves no purpose and shouldn't be used")]
@@ -59,14 +59,28 @@ public override IPAddress GetExternalIP ()
public override IAsyncResult BeginCreatePortMap(Mapping mapping, AsyncCallback callback, object asyncState)
{
PortMapAsyncResult pmar = new PortMapAsyncResult (mapping.Protocol, mapping.PublicPort, PmpConstants.DefaultLeaseTime, callback, asyncState);
- CreatePortMap (pmar.Mapping, true);
+ ThreadPool.QueueUserWorkItem (delegate {
+ try {
+ CreatePortMap(pmar.Mapping, true);
+ pmar.Complete();
+ } catch (Exception e) {
+ pmar.Complete(e);
+ }
+ });
return pmar;
}
public override IAsyncResult BeginDeletePortMap (Mapping mapping, AsyncCallback callback, object asyncState)
{
PortMapAsyncResult pmar = new PortMapAsyncResult (mapping, callback, asyncState);
- CreatePortMap (pmar.Mapping, false);
+ ThreadPool.QueueUserWorkItem (delegate {
+ try {
+ CreatePortMap(pmar.Mapping, false);
+ pmar.Complete();
+ } catch (Exception e) {
+ pmar.Complete(e);
+ }
+ });
return pmar;
}
@@ -195,7 +209,7 @@ private void CreatePortMapAsync (object obj)
CreatePortMapAsyncState state = obj as CreatePortMapAsyncState;
UdpClient udpClient = new UdpClient ();
- CreatePortMapListenState listenState = new CreatePortMapListenState (state);
+ CreatePortMapListenState listenState = new CreatePortMapListenState (state, udpClient);
int attempt = 0;
int delay = PmpConstants.RetryDelay;
@@ -204,6 +218,7 @@ private void CreatePortMapAsync (object obj)
while (attempt < PmpConstants.RetryAttempts && !listenState.Success) {
udpClient.Send (state.Buffer, state.Buffer.Length, new IPEndPoint (localAddress, PmpConstants.ServerPort));
+ listenState.UdpClientReady.Set();
attempt++;
delay *= 2;
@@ -220,11 +235,21 @@ private void CreatePortMapListen (object obj)
{
CreatePortMapListenState state = obj as CreatePortMapListenState;
- UdpClient udpClient = new UdpClient (5351);
- IPEndPoint endPoint = new IPEndPoint (publicAddress, PmpConstants.ServerPort);
+ UdpClient udpClient = state.UdpClient;
+ state.UdpClientReady.WaitOne(); // Evidently UdpClient has some lazy-init Send/Receive race?
+ IPEndPoint endPoint = new IPEndPoint (localAddress, PmpConstants.ServerPort);
while (!state.Success) {
- byte[] data = udpClient.Receive (ref endPoint);
+ byte[] data;
+ try
+ {
+ data = udpClient.Receive(ref endPoint);
+ }
+ catch (SocketException)
+ {
+ state.Success = false;
+ return;
+ }
if (data.Length < 16)
continue;
@@ -238,13 +263,13 @@ private void CreatePortMapListen (object obj)
if (opCode == PmpConstants.OperationCodeUdp)
protocol = Protocol.Udp;
- short resultCode = BitConverter.ToInt16 (data, 2);
- int epoch = BitConverter.ToInt32 (data, 4);
+ short resultCode = IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, 2));
+ uint epoch = (uint)IPAddress.NetworkToHostOrder (BitConverter.ToInt32 (data, 4));
- short privatePort = BitConverter.ToInt16 (data, 8);
- short publicPort = BitConverter.ToInt16 (data, 10);
+ int privatePort = (ushort)IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, 8));
+ int publicPort = (ushort)IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, 10));
- int lifetime = BitConverter.ToInt32 (data, 12);
+ uint lifetime = (uint)IPAddress.NetworkToHostOrder (BitConverter.ToInt32 (data, 12));
if (resultCode != PmpConstants.ResultCodeSuccess) {
state.Success = false;
@@ -261,8 +286,9 @@ private void CreatePortMapListen (object obj)
//TODO: verify that the private port+protocol are a match
Mapping mapping = state.Mapping;
mapping.PublicPort = publicPort;
+ mapping.Protocol = protocol;
mapping.Expiration = DateTime.Now.AddSeconds (lifetime);
-
+
state.Success = true;
}
}
@@ -291,12 +317,15 @@ private class CreatePortMapAsyncState
private class CreatePortMapListenState
{
- internal bool Success;
+ internal volatile bool Success;
internal Mapping Mapping;
+ internal UdpClient UdpClient;
+ internal ManualResetEvent UdpClientReady;
- internal CreatePortMapListenState (CreatePortMapAsyncState state)
+ internal CreatePortMapListenState (CreatePortMapAsyncState state, UdpClient client)
{
- Mapping = state.Mapping;
+ Mapping = state.Mapping;
+ UdpClient = client; UdpClientReady = new ManualResetEvent(false);
}
}
}
Oops, something went wrong.

0 comments on commit 66ba666

Please sign in to comment.