Skip to content

Commit 3b960f8

Browse files
author
Elad Zelingher
committed
Merge branch 'develop' into wampv2
2 parents aaa6a2e + b23c0d2 commit 3b960f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+611
-183
lines changed

src/mono/WampSharp.WAMP1/WampSharp.WAMP1.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@
151151
<Compile Include="..\..\net45\WampSharp.WAMP1\WAMP1\V1\Core\Listener\IWampSessionIdGenerator.cs">
152152
<Link>WAMP1\V1\Core\Listener\IWampSessionIdGenerator.cs</Link>
153153
</Compile>
154+
<Compile Include="..\..\net45\WampSharp.WAMP1\WAMP1\V1\Core\Listener\WampClientContainer.cs">
155+
<Link>WAMP1\V1\Core\Listener\WampClientContainer.cs</Link>
156+
</Compile>
154157
<Compile Include="..\..\net45\WampSharp.WAMP1\WAMP1\V1\Core\Listener\WampListener.cs">
155158
<Link>WAMP1\V1\Core\Listener\WampListener.cs</Link>
156159
</Compile>

src/mono/WampSharp/WampSharp.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@
234234
<Compile Include="..\..\net45\WampSharp\Core\Utilities\GenericTypeExtensions.cs">
235235
<Link>Core\Utilities\GenericTypeExtensions.cs</Link>
236236
</Compile>
237+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\IdMapperBase.cs">
238+
<Link>Core\Utilities\IdMapperBase.cs</Link>
239+
</Compile>
237240
<Compile Include="..\..\net45\WampSharp\Core\Utilities\Method.cs">
238241
<Link>Core\Utilities\Method.cs</Link>
239242
</Compile>
@@ -252,6 +255,9 @@
252255
<Compile Include="..\..\net45\WampSharp\Core\Utilities\SwapHashSet.cs">
253256
<Link>Core\Utilities\SwapHashSet.cs</Link>
254257
</Compile>
258+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\ThreadSafeRandom.cs">
259+
<Link>Core\Utilities\ThreadSafeRandom.cs</Link>
260+
</Compile>
255261
<Compile Include="..\..\net45\WampSharp\Properties\AssemblyInfo.cs">
256262
<Link>Properties\AssemblyInfo.cs</Link>
257263
</Compile>
@@ -348,6 +354,9 @@
348354
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\Client\Session\WampAuthenticationNotImplementedException.cs">
349355
<Link>WAMP2\V2\Client\Session\WampAuthenticationNotImplementedException.cs</Link>
350356
</Compile>
357+
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\Core\Listener\WampClientContainer.cs">
358+
<Link>WAMP2\V2\Core\Listener\WampClientContainer.cs</Link>
359+
</Compile>
351360
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\PCL\CodeGeneration\CalleeProxyCodeGenerator.cs">
352361
<Link>WAMP2\V2\PCL\CodeGeneration\CalleeProxyCodeGenerator.cs</Link>
353362
</Compile>
@@ -399,6 +408,9 @@
399408
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\PubSub\ExactTopicContainer.cs">
400409
<Link>WAMP2\V2\PubSub\ExactTopicContainer.cs</Link>
401410
</Compile>
411+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\ImmutableHashSetInterlocked.cs">
412+
<Link>Core\Utilities\ImmutableHashSetInterlocked.cs</Link>
413+
</Compile>
402414
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\PubSub\Interfaces\IWampPubSubServer.cs">
403415
<Link>WAMP2\V2\PubSub\Interfaces\IWampPubSubServer.cs</Link>
404416
</Compile>

src/net40/WampSharp.WAMP1/WampSharp.WAMP1.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
<Compile Include="..\..\net45\WampSharp.WAMP1\WAMP1\V1\Core\Listener\IWampSessionIdGenerator.cs">
153153
<Link>WAMP1\V1\Core\Listener\IWampSessionIdGenerator.cs</Link>
154154
</Compile>
155+
<Compile Include="..\..\net45\WampSharp.WAMP1\WAMP1\V1\Core\Listener\WampClientContainer.cs">
156+
<Link>WAMP1\V1\Core\Listener\WampClientContainer.cs</Link>
157+
</Compile>
155158
<Compile Include="..\..\net45\WampSharp.WAMP1\WAMP1\V1\Core\Listener\WampListener.cs">
156159
<Link>WAMP1\V1\Core\Listener\WampListener.cs</Link>
157160
</Compile>

src/net40/WampSharp/WampSharp.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@
238238
<Compile Include="..\..\net45\WampSharp\Core\Utilities\GenericTypeExtensions.cs">
239239
<Link>Core\Utilities\GenericTypeExtensions.cs</Link>
240240
</Compile>
241+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\IdMapperBase.cs">
242+
<Link>Core\Utilities\IdMapperBase.cs</Link>
243+
</Compile>
241244
<Compile Include="..\..\net45\WampSharp\Core\Utilities\Method.cs">
242245
<Link>Core\Utilities\Method.cs</Link>
243246
</Compile>
@@ -256,6 +259,9 @@
256259
<Compile Include="..\..\net45\WampSharp\Core\Utilities\SwapHashSet.cs">
257260
<Link>Core\Utilities\SwapHashSet.cs</Link>
258261
</Compile>
262+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\ThreadSafeRandom.cs">
263+
<Link>Core\Utilities\ThreadSafeRandom.cs</Link>
264+
</Compile>
259265
<Compile Include="..\..\net45\WampSharp\Properties\AssemblyInfo.cs">
260266
<Link>Properties\AssemblyInfo.cs</Link>
261267
</Compile>
@@ -352,6 +358,9 @@
352358
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\Client\Session\WampAuthenticationNotImplementedException.cs">
353359
<Link>WAMP2\V2\Client\Session\WampAuthenticationNotImplementedException.cs</Link>
354360
</Compile>
361+
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\Core\Listener\WampClientContainer.cs">
362+
<Link>WAMP2\V2\Core\Listener\WampClientContainer.cs</Link>
363+
</Compile>
355364
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\PCL\CodeGeneration\CalleeProxyCodeGenerator.cs">
356365
<Link>WAMP2\V2\PCL\CodeGeneration\CalleeProxyCodeGenerator.cs</Link>
357366
</Compile>
@@ -403,6 +412,9 @@
403412
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\PubSub\ExactTopicContainer.cs">
404413
<Link>WAMP2\V2\PubSub\ExactTopicContainer.cs</Link>
405414
</Compile>
415+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\ImmutableHashSetInterlocked.cs">
416+
<Link>Core\Utilities\ImmutableHashSetInterlocked.cs</Link>
417+
</Compile>
406418
<Compile Include="..\..\net45\WampSharp\WAMP2\V2\PubSub\Interfaces\IWampPubSubServer.cs">
407419
<Link>WAMP2\V2\PubSub\Interfaces\IWampPubSubServer.cs</Link>
408420
</Compile>

src/net45/Default/WampSharp.Fleck/Fleck/FleckWampConnection.cs

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
using System;
2+
using System.Reactive;
3+
using System.Reactive.Linq;
4+
using System.Reactive.Threading.Tasks;
5+
using System.Threading.Tasks;
26
using Fleck;
37
using WampSharp.Core.Listener;
8+
using WampSharp.Logging;
49

510
namespace WampSharp.Fleck
611
{
712
internal abstract class FleckWampConnection<TMessage> : AsyncWampConnection<TMessage>
813
{
914
protected IWebSocketConnection mWebSocketConnection;
10-
11-
public FleckWampConnection(IWebSocketConnection webSocketConnection)
15+
private readonly byte[] mPingBuffer = new byte[8];
16+
private readonly TimeSpan mAutoSendPingInterval;
17+
18+
public FleckWampConnection(IWebSocketConnection webSocketConnection,
19+
TimeSpan? autoSendPingInterval = null)
1220
{
1321
mWebSocketConnection = webSocketConnection;
22+
mAutoSendPingInterval = autoSendPingInterval ?? TimeSpan.FromSeconds(45);
1423
mWebSocketConnection.OnOpen = OnConnectionOpen;
1524
mWebSocketConnection.OnError = OnConnectionError;
1625
mWebSocketConnection.OnClose = OnConnectionClose;
@@ -19,6 +28,73 @@ public FleckWampConnection(IWebSocketConnection webSocketConnection)
1928
private void OnConnectionOpen()
2029
{
2130
RaiseConnectionOpen();
31+
32+
StartPing();
33+
}
34+
35+
#if NET40
36+
private void StartPing()
37+
{
38+
Observable.Defer
39+
(() => Observable.FromAsync
40+
(() =>
41+
{
42+
byte[] ticks = GetCurrentTicks();
43+
return mWebSocketConnection.SendPing(ticks);
44+
})
45+
.Concat(Observable.Timer(mAutoSendPingInterval)
46+
.Select(y => Unit.Default))
47+
)
48+
.Repeat()
49+
.ToTask()
50+
.ContinueWith(x =>
51+
{
52+
if (x.Exception != null)
53+
{
54+
mLogger.WarnException("Failed pinging remote peer", x.Exception);
55+
}
56+
});
57+
}
58+
59+
#elif NET45
60+
private void StartPing()
61+
{
62+
Task.Run((Action)Ping);
63+
}
64+
65+
// We currently detect only disconnected clients and not "zombies",
66+
// i.e. clients that respond relatively slow.
67+
private async void Ping()
68+
{
69+
while (IsConnected)
70+
{
71+
try
72+
{
73+
byte[] ticks = GetCurrentTicks();
74+
await mWebSocketConnection.SendPing(ticks);
75+
await Task.Delay(mAutoSendPingInterval);
76+
}
77+
catch (Exception ex)
78+
{
79+
mLogger.WarnException("Failed pinging remote peer", ex);
80+
}
81+
}
82+
}
83+
#endif
84+
85+
private byte[] GetCurrentTicks()
86+
{
87+
DateTime now = DateTime.Now;
88+
long ticks = now.Ticks;
89+
long bytes = ticks;
90+
91+
for (int i = 0; i < 8; i++)
92+
{
93+
mPingBuffer[i] = (byte) bytes;
94+
bytes = bytes >> 8;
95+
}
96+
97+
return mPingBuffer;
2298
}
2399

24100
private void OnConnectionError(Exception exception)

src/net45/Default/WampSharp.Fleck/Fleck/FleckWebSocketTransport.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
using Fleck;
1+
using System;
2+
using Fleck;
23
using WampSharp.Core.Listener;
4+
using WampSharp.Logging;
35
using WampSharp.V2.Binding;
46
using WampSharp.V2.Transports;
7+
using LogLevel = Fleck.LogLevel;
58

69
namespace WampSharp.Fleck
710
{
@@ -20,6 +23,46 @@ public class FleckWebSocketTransport : WebSocketTransport<IWebSocketConnection>
2023
public FleckWebSocketTransport(string location)
2124
{
2225
mServer = new WebSocketServer(location);
26+
27+
RouteLogs();
28+
}
29+
30+
private void RouteLogs()
31+
{
32+
Action<LogLevel, string, Exception> logAction = FleckLog.LogAction;
33+
34+
if (logAction != null &&
35+
logAction.Method.DeclaringType == typeof (FleckLog))
36+
{
37+
FleckLog.LogAction = ConvertLog;
38+
}
39+
}
40+
41+
private void ConvertLog(LogLevel logLevel, string message, Exception exception)
42+
{
43+
switch (logLevel)
44+
{
45+
case LogLevel.Debug:
46+
{
47+
mLogger.DebugException(message, exception);
48+
break;
49+
}
50+
case LogLevel.Info:
51+
{
52+
mLogger.InfoException(message, exception);
53+
break;
54+
}
55+
case LogLevel.Warn:
56+
{
57+
mLogger.WarnException(message, exception);
58+
break;
59+
}
60+
case LogLevel.Error:
61+
{
62+
mLogger.ErrorException(message, exception);
63+
break;
64+
}
65+
}
2366
}
2467

2568
protected override void OpenConnection<TMessage>(IWampConnection<TMessage> connection)

src/net45/Tests/WampSharp.Tests.Wampv2/TestHelpers/Integration/WampClientPlayground.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using WampSharp.V2;
66
using WampSharp.V2.Binding;
77
using WampSharp.V2.Client;
8-
using WampSharp.V2.Core;
98
using WampSharp.V2.Core.Contracts;
9+
using WampSharp.V2.Core.Listener;
1010
using WampSharp.V2.Core.Listener.ClientBuilder;
1111

1212
namespace WampSharp.Tests.TestHelpers.Integration
@@ -51,13 +51,12 @@ private static void BuildServerMockHandler<TMessage>(IWampServer<TMessage> serve
5151
{
5252
WampClientBuilderFactory<TMessage> factory =
5353
new WampClientBuilderFactory<TMessage>
54-
(new WampIdGenerator(),
55-
new WampOutgoingRequestSerializer<TMessage>(binding.Formatter),
54+
(new WampOutgoingRequestSerializer<TMessage>(binding.Formatter),
5655
new WampOutgoingMessageHandlerBuilder<TMessage>(),
5756
binding);
5857

59-
WampClientContainer<TMessage, IWampClientProxy<TMessage>> container =
60-
new WampClientContainer<TMessage, IWampClientProxy<TMessage>>(factory);
58+
WampClientContainer<TMessage> container =
59+
new WampClientContainer<TMessage>(factory);
6160

6261
WampIncomingMessageHandler<TMessage, IWampClientProxy<TMessage>> incomingMessageHandler =
6362
new WampIncomingMessageHandler<TMessage, IWampClientProxy<TMessage>>

src/net45/Tests/WampSharp.Tests/ClientServerIntegrationTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@ private WampListener<JToken> GetListener(IWampConnectionListener<JToken> listene
190190
return new WampListener<JToken>
191191
(listener,
192192
handler,
193-
new WampClientContainer<JToken, IWampClient>
193+
new WampClientContainer<JToken>
194194
(new WampClientBuilderFactory<JToken>
195-
(new WampSessionIdGenerator(),
196-
new WampOutgoingRequestSerializer<JToken>(mFormatter),
195+
(new WampOutgoingRequestSerializer<JToken>(mFormatter),
197196
new WampOutgoingMessageHandlerBuilder<JToken>())));
198197
}
199198

src/net45/Tests/WampSharp.Tests/ListenerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using WampSharp.Newtonsoft;
1010
using WampSharp.V1.Core.Contracts;
1111
using WampSharp.V1.Core.Listener;
12+
using WampSharp.V1.Core.Listener.ClientBuilder;
1213

1314
namespace WampSharp.Tests
1415
{
@@ -64,7 +65,7 @@ private WampListener<JToken> GetListener(IWampConnectionListener<JToken> listene
6465
return new WampListener<JToken>
6566
(listener,
6667
handler,
67-
new WampClientContainer<JToken, IWampClient>(factory.Object));
68+
new WampClientContainer<JToken>(factory.Object));
6869
}
6970

7071
private IWampIncomingMessageHandler<JToken, IWampClient> GetHandler(IWampServer<JToken> wampServer)

src/net45/Tests/WampSharp.Tests/Proxy/Helpers/MockClientContainer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ public bool TryGetClient(IWampConnection<MockRaw> connection, out IWampClient cl
2626
{
2727
throw new System.NotImplementedException();
2828
}
29+
30+
public object GenerateClientId(IWampClient client)
31+
{
32+
return "v59mbCGDXZ7WTyxB";
33+
}
2934
}
3035
}

src/net45/Tests/WampSharp.Tests/Proxy/WampClientBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public void Setup()
2525
mOutgoingMessageHandler = new MockOutgoingMessageHandler(mFormatter);
2626

2727
mBuilder =
28-
new WampClientBuilder<MockRaw>(new MockSessionGuidGenerator(),
29-
new WampOutgoingRequestSerializer<MockRaw>(formatter),
28+
new WampClientBuilder<MockRaw>(new WampOutgoingRequestSerializer<MockRaw>(formatter),
3029
new MockOutgoingMessageHandlerBuilder(mOutgoingMessageHandler),
3130
new MockClientContainer());
3231

src/net45/WampSharp.WAMP1/WAMP1/V1/Api/Server/WampHost.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static WampListener<TMessage> GetWampListener(IWampConnectionListener<TM
4444
GetWampClientBuilder(formatter);
4545

4646
IWampClientContainer<TMessage, IWampClient> clientContainer =
47-
new WampClientContainer<TMessage, IWampClient>(clientBuilderFactory);
47+
new WampClientContainer<TMessage>(clientBuilderFactory);
4848

4949
IWampRequestMapper<TMessage> requestMapper =
5050
new WampRequestMapper<TMessage>(server.GetType(),
@@ -66,18 +66,14 @@ private static WampListener<TMessage> GetWampListener(IWampConnectionListener<TM
6666

6767
private static WampClientBuilderFactory<TMessage> GetWampClientBuilder(IWampFormatter<TMessage> formatter)
6868
{
69-
WampSessionIdGenerator wampSessionIdGenerator =
70-
new WampSessionIdGenerator();
71-
7269
WampOutgoingRequestSerializer<TMessage> wampOutgoingRequestSerializer =
7370
new WampOutgoingRequestSerializer<TMessage>(formatter);
7471

7572
WampOutgoingMessageHandlerBuilder<TMessage> wampOutgoingMessageHandlerBuilder =
7673
new WampOutgoingMessageHandlerBuilder<TMessage>();
77-
74+
7875
return new WampClientBuilderFactory<TMessage>
79-
(wampSessionIdGenerator,
80-
wampOutgoingRequestSerializer,
76+
(wampOutgoingRequestSerializer,
8177
wampOutgoingMessageHandlerBuilder);
8278
}
8379

0 commit comments

Comments
 (0)