forked from miyu/libdipc
/
LocalRouter.cs
49 lines (42 loc) · 1.47 KB
/
LocalRouter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Dargon.Ipc.Messaging;
using ItzWarty;
namespace Dargon.Ipc
{
public class LocalRouter : DipNodeBase
{
private readonly ILocalRouterConfiguration m_config;
public LocalRouter(ILocalRouterConfiguration config)
: base(DipRole.LocalRouter, config.Guid != Guid.Empty ? config.Guid : Guid.NewGuid(), config.NodeIdentifier)
{
m_config = config;
}
protected override IPeeringResult PeerParent(IDipNode parent)
{
var result = parent.PeerChildAsync(this).Result;
return new PeeringResult(result.PeeringState, parent, result.Exception);
}
protected override IPeeringResult PeerChild(IDipNode child)
{
if (child.Role.HasFlag(DipRole.RemoteTerminal))
return PeeringFailure(child, new InvalidOperationException("Local nodes cannot directly peer with remote terminals"));
var result = child.PeerParentAsync(this).Result;
return new PeeringResult(result.PeeringState, child, result.Exception);
}
public override void SendV1<T>(IEnvelopeV1<T> envelope)
{
this.RouteEnvelope(envelope);
}
public override void ReceiveV1<T>(IEnvelopeV1<T> envelope)
{
this.RouteEnvelope(envelope);
}
}
}