public void CanConnectToPiper_Messages() { var pipeOptions = new PipeOptions { Port = 22222 }; using (var pipeListener = new TcpListenerPiper(pipeOptions, CancellationToken.None)) { var outgoingPipe = new OutgoingPipe(new NodeConnectionInfo { Host = "localhost", Port = pipeOptions.Port }, CancellationToken.None, new PipeOptions(), pipeListener); for (int i = 0; i < 10; i++) { outgoingPipe.Write(new MyMsg { i = i }); } for (int i = 0; i < 10; i++) { var read = pipeListener.Read(CancellationToken.None).Result; Assert.Equal(i, ((MyMsg)read.Item1).i); } } }
public void Join(NodeConnectionInfo dest) { var destPipe = new OutgoingPipe(dest, _cancellationTokenSource.Token, _options, _tcpListenerPiper); _tempConnections.TryAdd(destPipe, dest); destPipe.Write(new JoinMessage { SenderInfo = _senderInfo }); }
public void CanConnectToPiper() { var pipeOptions = new PipeOptions(); using (var pipeListener = new TcpListenerPiper(pipeOptions, CancellationToken.None)) { var outgoingPipe = new OutgoingPipe(new NodeConnectionInfo { Host = "localhost", Port = pipeOptions.Port }, CancellationToken.None, new PipeOptions(), pipeListener); outgoingPipe.Write("hello there"); var read = pipeListener.Read(CancellationToken.None).Result; Assert.Equal("hello there", read.Item1); } }
private async Task HeartbeatTask() { var random = new Random(); while (_cancellationTokenSource.IsCancellationRequested == false) { await Task.Delay(_options.Heartbeat, _cancellationTokenSource.Token); if (_activeView.Count == 0 && _passiveView.Length == 0) { continue; } Pipe pipe; var next = random.Next(0, _activeView.Count + _passiveView.Length); if (next < _activeView.Count) { var kvp = _activeView.ElementAt(next); pipe = kvp.Value; _log.Debug("Sending heartbeat to active {0}", kvp.Key); } else { var connectionInfo = _passiveView.ElementAt(next); _log.Debug("Sending heartbeat to passive {0}", connectionInfo); pipe = new OutgoingPipe(connectionInfo, _cancellationTokenSource.Token, _options, _tcpListenerPiper); _tempConnections.TryAdd(pipe, connectionInfo); } var priority = NeighborPriority.Low; if (_activeView.Count == _options.MaxActiveView) { priority = NeighborPriority.Passive; } else if (_activeView.Count == 0) { priority = NeighborPriority.High; } pipe.Write(new NeighborMessage { Priority = priority, SenderInfo = _senderInfo }); } }
private void ForwardJoin(ForwardJoinMessage msg, Pipe sender) { _log.Info("Forwarded join message for {0} from {1}, ttl: {2}", msg.ForwardedNodeInfo, sender, msg.TimeToLive); if (KnownNode(msg.ForwardedNodeInfo)) { return; } if (msg.TimeToLive == 0 || _activeView.Count <= 1) { var newNode = new OutgoingPipe(msg.ForwardedNodeInfo, _cancellationTokenSource.Token, _options, _tcpListenerPiper); AddToActiveView(newNode, msg.ForwardedNodeInfo); return; } if (msg.TimeToLive == _options.PassiveRandomWalkLength) { AddNodePassiveView(msg.ForwardedNodeInfo); } }