Beispiel #1
0
        static void ListenToMarketData()
        {
            var cfg = new Config()
            {
                Endpoint = Instance.Prod,
                Products = new List <string>()
                {
                    "BTC-USD"
                },
            };

            using (var restClient = new ExchangeApi.Coinbase.REST.RestClient(cfg.Endpoint.REST, null))
                using (var client = new Client(cfg))
                {
                    var    book         = new OrderBook();
                    var    expectedBook = new OrderBook();
                    Action poll         = () =>
                    {
                        if (book.Sequence < 0)
                        {
                            _log.Info("Haven't received any messages yet");
                            return;
                        }
                        // Sleep on the scheduler thread in order to fall behind on the order book.
                        Thread.Sleep(20000);
                        ExchangeApi.Coinbase.REST.OrderBookResponse full =
                            restClient.SendRequest(new ExchangeApi.Coinbase.REST.OrderBookRequest()
                        {
                            Product = "BTC-USD"
                        }).Result;
                        if (full.Sequence <= book.Sequence)
                        {
                            _log.Info("Order book isn't behind");
                            return;
                        }
                        _log.Info("Expecting sequence {0} in the near future", full.Sequence);
                        Convert(full, expectedBook);
                    };
                    client.OnOrderBook += (string product, TimestampedMsg <OrderBookDelta> msg) =>
                    {
                        if (msg.Value.Bids.Count + msg.Value.Asks.Count > 10)
                        {
                            _log.Info("OnOrderBook({0}, IsLast={1}): {2} bid(s), {3} ask(s)",
                                      product, !client.Scheduler.HasReady(), msg.Value.Bids.Count, msg.Value.Asks.Count);
                        }
                        else
                        {
                            _log.Info("OnOrderBook({0}, IsLast={1}): {2}", product, !client.Scheduler.HasReady(), msg.Value);
                        }
                        ApplyDelta(book, msg.Value);
                        Compare(expectedBook, book);
                    };
                    client.Connect();
                    using (var timer = new PeriodicAction(cfg.Scheduler, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30), poll))
                        while (true)
                        {
                            Thread.Sleep(1000);
                        }
                }
        }
Beispiel #2
0
        public Client(Config cfg)
        {
            Condition.Requires(cfg.Endpoint, "cfg.Endpoint").IsNotNull();
            Condition.Requires(cfg.Products, "cfg.Products").IsNotNull();
            Condition.Requires(cfg.Scheduler, "cfg.Scheduler").IsNotNull();
            if (cfg.Keys != null)
            {
                Condition.Requires(cfg.Keys.ApiKey, "cfg.Keys.ApiKey").IsNotNullOrWhiteSpace();
                Condition.Requires(cfg.Keys.SecretKey, "cfg.Keys.SecretKey").IsNotNullOrWhiteSpace();
            }
            if (cfg.EnableTrading)
            {
                Condition.Requires(cfg.Keys, "cfg.Keys").IsNotNull();
            }
            _cfg      = cfg.Clone();
            _cfg.Keys = _cfg.Keys ?? new Keys()
            {
                ApiKey = "NONE", SecretKey = "NONE"
            };
            var connector = new CodingConnector <IMessageIn, IMessageOut>(
                new ExchangeApi.WebSocket.Connector(_cfg.Endpoint.WebSocket), new WebSocket.Codec(_cfg.Keys));

            _connection = new DurableConnection <IMessageIn, IMessageOut>(connector, _cfg.Scheduler);
            _gateway    = new WebSocket.Gateway(_connection);
            _connection.OnConnection += OnConnection;
            _connection.OnMessage    += OnMessage;
            _restClient           = new REST.RestClient(_cfg.Endpoint.REST, _cfg.Keys);
            _pinger               = new PeriodicAction(_cfg.Scheduler, PingPeriod, PingPeriod, Ping);
            _futurePositionPoller = new FuturePositionPoller(
                _restClient, _cfg.Scheduler,
                _cfg.EnableTrading ? _cfg.Products : new List <Product>());
            _futurePositionPoller.OnFuturePositions += msg => OnFuturePositionsUpdate?.Invoke(msg);
            _spotPositionPoller = new PeriodicAction(_cfg.Scheduler, SpotPositionPollPeriod, SpotPositionPollPeriod, PollSpotPositions);
        }
    public override void applyPassive(Transform player)
    {
        PeriodicAction action = player.gameObject.AddComponent <PeriodicAction>();

        passiveActionID = action.GetInstanceID();
        action.init(activeEffect, cooldown, passiveProcChance);
    }
 public TransactionOverloadDetector(ITransactionAgentStatistics statistics, IOptions <TransactionRateLoadSheddingOptions> options)
 {
     this.statistics     = statistics;
     this.options        = options.Value;
     this.monitor        = new PeriodicAction(MetricsCheck, this.RecordStatistics);
     this.lastStatistics = TransactionAgentStatistics.Copy(statistics);
     this.lastCheckTime  = DateTime.UtcNow;
 }
        public void StartMonitoring()
        {
            if (periodic_ != null)
            {
                ResetState_();
                return;
            }

            periodic_ = new PeriodicAction(interval_, PeriodicActionHandler_, true);
        }
        /// <inheritdoc />
        public void StopMonitoring()
        {
            if (periodic_ != null)
            {
                periodic_.Dispose();
                periodic_ = null;
            }

            ResetState_();
        }
        internal TagsTransferWindow(DestinationSession session, OutboundTunnelSelector tunnelsel)
        {
            Window = new TimeWindowDictionary <uint, GarlicCreationInfo>(GarlicResendTimeLimit);
            OutstandingMessageIds = new TimeWindowDictionary <uint, GarlicCreationInfo>(GarlicTimeBetweenResends * 10);

            Resend = new PeriodicAction(GarlicTimeBetweenResends / 4);

            Session        = session;
            TunnelSelector = tunnelsel;

            TunnelProvider.DeliveryStatusReceived += new Action <DeliveryStatusMessage>(TunnelProvider_DeliveryStatusReceived);
            InboundTunnel.DeliveryStatusReceived  += new Action <DeliveryStatusMessage>(InboundTunnel_DeliveryStatusReceived);
        }
Beispiel #8
0
        private void Run()
        {
            try
            {
                DebugUtils.LogInformation("NetDb: Path: " + NetDbPath);
                DebugUtils.Log("Reading NetDb...");
                var sw1 = new Stopwatch();
                sw1.Start();
                Load();
                sw1.Stop();
                DebugUtils.Log(string.Format("Done reading NetDb. {0}. {1} entries.", sw1.Elapsed, RouterInfos.Count));

                LoadFinished.Set();
                while (TransportProvider.Inst == null)
                {
                    Thread.Sleep(500);
                }

                var PeriodicSave = new PeriodicAction(TickSpan.Minutes(5));

                var PeriodicFFUpdate = new PeriodicAction(TickSpan.Seconds(5));
                var FloodfillUpdate  = new FloodfillUpdater();

                while (!Terminated)
                {
                    try
                    {
                        PeriodicSave.Do(() => Save(true));
                        PeriodicFFUpdate.Do(() => FloodfillUpdate.Run());
                        IdentHashLookup.Run();
                        Thread.Sleep(2000);
                    }
                    catch (ThreadAbortException ex)
                    {
                        DebugUtils.Log(ex);
                        Terminated = true;
                    }
                    catch (Exception ex)
                    {
                        DebugUtils.Log(ex);
                    }
                }
            }
            finally
            {
                Terminated = true;
            }
        }
    public override void undoPassive(Transform player)
    {
        PeriodicAction[] actions = player.gameObject.GetComponents <PeriodicAction>();
        PeriodicAction   action  = null;

        foreach (PeriodicAction a in actions)
        {
            if (a.GetInstanceID() == passiveActionID)
            {
                action = a;
            }
        }
        if (action)
        {
            Destroy(action);
        }
    }
Beispiel #10
0
        public void ShouldFailOnDoubleDisposeOfAction()
        {
            VirtualClock clock = new VirtualClock();

            PeriodicAction action = clock.CreateAction(TimeSpan.FromSeconds(1.0d), () => { });

            action.Dispose();

            try
            {
                action.Dispose();
                Assert.Fail("Expected exception was not thrown.");
            }
            catch (InvalidOperationException)
            {
            }
        }
        public BufferedCheckpointManager(ICheckpointManager bufferCheckpointManager, ICheckpointManager targetCheckpointManager, int bufferInterval)
        {
            Guard.ArgumentNotNull(bufferCheckpointManager, nameof(bufferCheckpointManager));
            Guard.ArgumentNotNull(targetCheckpointManager, nameof(targetCheckpointManager));

            _bufferCheckpointManager = bufferCheckpointManager;
            _targetCheckpointManager = targetCheckpointManager;
            _bufferInterval          = bufferInterval;

            var bufferCheckpoint = _bufferCheckpointManager.GetCheckpoint();
            var targetCheckpoint = _targetCheckpointManager.GetCheckpoint();

            if (bufferCheckpoint > targetCheckpoint)
            {
                _targetCheckpointManager.SaveCheckpoint(bufferCheckpoint);
            }
            _timer = new PeriodicAction(SendBufferToTarget, bufferInterval);
        }
Beispiel #12
0
        public EfDistributedLock(Func <AggregateDbContext> contextFactory, EfDistributedLockRecord record, TimeSpan expiration, Action expirationAction = null)
        {
            Guard.ArgumentNotNull(contextFactory, nameof(contextFactory));
            Guard.ArgumentNotNull(record, nameof(record));
            Guard.ArgumentNotNull(expiration, nameof(expiration));

            _action         = expirationAction;
            _contextFactory = contextFactory;
            Expiry          = expiration;
            ExpirationTime  = record.LockDateTime;
            IsAcquired      = record.IsAcquired();
            LockName        = record.Name;
            LockId          = record.LockId;
            var extendTime = (expiration.TotalMilliseconds * 0.9).Do(Convert.ToInt32);

            _timer = new PeriodicAction(ct => ExtendLockAsync(ct), extendTime, null, true);
            _timer.Start();
        }
Beispiel #13
0
        public FuturePositionPoller(REST.RestClient restClient, Scheduler scheduler, IEnumerable <Product> products)
        {
            Condition.Requires(restClient, "restClient").IsNotNull();
            _restClient = restClient;
            _products   = products
                          .Where(p => p.ProductType == ProductType.Future)
                          .Select(p => Tuple.Create(p.Currency, p.CoinType))
                          .Dedup()
                          .ToArray();

            _pollers = new PeriodicAction[_products.Length];
            try
            {
                for (int i = 0; i != _pollers.Length; ++i)
                {
                    var p = _products[i];
                    // Spread polling of different products over the polling period.
                    // While we are polling positions, we aren't processing market data and order updates.
                    // To reduce downtime we query positions for one product at a time.
                    var delay = PollPeriod.Mul(i + 1).Div(_pollers.Length);
                    // PollOne can throw. That's OK -- PeriodicAction will log it and continue.
                    _pollers[i] = new PeriodicAction(scheduler, delay, PollPeriod, () =>
                    {
                        if (Connected)
                        {
                            PollOne(p.Item1, p.Item2);
                        }
                    });
                }
            }
            catch
            {
                foreach (PeriodicAction a in _pollers)
                {
                    if (a != null)
                    {
                        a.Dispose();
                    }
                }
                throw;
            }
        }
Beispiel #14
0
        public async Task <IDistributedLock> CreateLockAsync(string name, TimeSpan expiry, TimeSpan wait, TimeSpan retry, CancellationToken cancellationToken, Action expirationAction = null)
        {
            IDistributedLock result = null;
            PeriodicAction   timer  = null;

            timer = new PeriodicAction(async ct =>
            {
                var dlock = await TryAquireLock(name, expiry, expirationAction);
                if (dlock != null)
                {
                    result = dlock;
                    timer?.Stop();
                }
            }, Convert.ToInt32(retry.TotalMilliseconds), wait);
            cancellationToken.Register(() => timer.Stop());
            using (var scope = TraceContext.Begin())
            {
                _logger.TraceVerboseEvent($"Starting trying to acquire lock {name} for {wait} each {retry}");
                await timer.Start();

                return(result ?? new EfDistributedLock(name));
            }
        }
Beispiel #15
0
        public void ShouldNotInvokeRemovedAction()
        {
            VirtualClock  clock       = new VirtualClock();
            TimeSpan      interval1   = TimeSpan.FromSeconds(2.0d);
            TimeSpan      interval2   = TimeSpan.FromSeconds(4.0d);
            List <string> invocations = new List <string>();

            clock.Sleep(TimeSpan.FromTicks(interval1.Ticks / 2));

            PeriodicAction action1 = clock.CreateAction(interval1, () => invocations.Add("A"));

            clock.Sleep(TimeSpan.FromTicks(interval1.Ticks / 2));

            PeriodicAction action2 = clock.CreateAction(interval2, () => invocations.Add("B"));

            CollectionAssert.AreEqual(new string[0], invocations.ToArray());

            action1.Dispose();

            clock.Sleep(interval1 + interval2);

            CollectionAssert.AreEqual(new string[] { "B" }, invocations.ToArray());
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            PeriodicAction LsLookup = new PeriodicAction(TickSpan.Minutes(5));

            DebugUtils.LogToConsole = true;
            DebugUtils.LogToFile("i2p.log");
            DebugUtils.LogInformation("Me: " + RouterContext.Inst.MyRouterIdentity.IdentHash.Id32);

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "--addr":
                    if (args.Length > i)
                    {
                        RouterContext.Inst.DefaultExtAddress = IPAddress.Parse(args[++i]);
                    }
                    break;

                case "--port":
                    if (args.Length > i)
                    {
                        var port = int.Parse(args[++i]);
                        RouterContext.Inst.DefaultTCPPort = port;
                        RouterContext.Inst.DefaultUDPPort = port;
                    }
                    break;

                case "--nofw":
                    RouterContext.Inst.IsFirewalled = false;
                    break;

                default:
                    Console.WriteLine("Usage: I2P.exe --addr 12.34.56.78 --port 8081 --nofw");
                    break;
                }
            }

            RouterContext.Inst.ApplyNewSettings();

            var pnp = new UPnp();

            Thread.Sleep(5000);   // Give UPnp a chance

            Router.Start();

            while (true)
            {
                try
                {
                    Connected = true;

                    var dest   = new I2PDestinationInfo(I2PSigningKey.SigningKeyTypes.EdDSA_SHA512_Ed25519);
                    var mydest = Router.CreateDestination(dest, false);
                    mydest.DataReceived += new ClientDestination.DestinationDataReceived(mydest_DataReceived);

                    var hashes = new I2PIdentHash[] {
                        new I2PIdentHash("udhdrtrcetjm5sxaskjyr5ztseszydbh4dpl3pl4utgqqw2v4jna.b32.i2p"),
                        new I2PIdentHash("7tbay5p4kzemkxvyvbf6v7eau3zemsnnl2aoyqhg5jzpr5eke7tq.b32.i2p"),
                        new I2PIdentHash("ukeu3k5oycga3uneqgtnvselmt4yemvoilkln7jpvafvfx7dnkdq.b32.i2p")
                    };

                    while (Connected)
                    {
                        Thread.Sleep(20000);

                        /*
                         * if ( LS != null )
                         * {
                         *  mydest.Send( LS, BufUtils.Random( 200 ), false );
                         * }*/
                        LsLookup.Do(() => mydest.LookupDestination(hashes.Random(), new ClientDestination.DestinationLookupResult(LookupResult)));
                    }
                }
                catch (SocketException ex)
                {
                    DebugUtils.Log(ex);
                }
                catch (IOException ex)
                {
                    DebugUtils.Log(ex);
                }
                catch (Exception ex)
                {
                    DebugUtils.Log(ex);
                }
            }
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            Logging.ReadAppConfig();
            Logging.LogToDebug   = false;
            Logging.LogToConsole = true;

            RouterContext.RouterSettingsFile = "EchoClientRouter.bin";
            RouterContext.Inst = new RouterContext(
                new I2PCertificate(
                    I2PSigningKey.SigningKeyTypes.DSA_SHA1));

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "--addr":
                case "--address":
                    if (args.Length > i + 1)
                    {
                        RouterContext.Inst.DefaultExtAddress = IPAddress.Parse(args[++i]);
                        Console.WriteLine($"addr {RouterContext.Inst.DefaultExtAddress}");
                    }
                    else
                    {
                        Console.WriteLine("--addr require ip number");
                        return;
                    }
                    break;

                case "--port":
                    if (args.Length > i + 1)
                    {
                        var port = int.Parse(args[++i]);
                        RouterContext.Inst.DefaultTCPPort = port;
                        RouterContext.Inst.DefaultUDPPort = port;
                        Console.WriteLine($"port {port}");
                    }
                    else
                    {
                        Console.WriteLine("--port require port number");
                        return;
                    }
                    break;

                case "--nofw":
                    RouterContext.Inst.IsFirewalled = false;
                    Console.WriteLine($"Firewalled {RouterContext.Inst.IsFirewalled}");
                    break;

                default:
                    Console.WriteLine(args[i]);
                    Console.WriteLine("Usage: I2P.exe --addr 12.34.56.78 --port 8081 --nofw");
                    break;
                }
            }

            RouterContext.Inst.ApplyNewSettings();
            Router.Start();

            var destb32    = AppSettings["RemoteDestination"];
            var remotedest = new I2PIdentHash(destb32);

            MyDestinationInfo      = new I2PDestinationInfo(I2PSigningKey.SigningKeyTypes.EdDSA_SHA512_Ed25519);
            UnpublishedDestination = Router.CreateDestination(MyDestinationInfo, false, out _);
            UnpublishedDestination.DataReceived += MyDestination_DataReceived;
            UnpublishedDestination.Name          = "UnpublishedDestination";

            Logging.LogInformation($"MyDestination: {UnpublishedDestination.Destination.IdentHash} {MyDestinationInfo.Destination.Certificate}");

            var interval = new PeriodicAction(TickSpan.Seconds(40));

            while (true)
            {
                try
                {
                    Connected = true;

                    while (Connected)
                    {
                        Thread.Sleep(2000);

                        uint recvid = BufUtils.RandomUintNZ();

                        interval.Do(() =>
                        {
                            Logging.LogInformation($"Program {UnpublishedDestination}: Looking for {remotedest}.");
                            UnpublishedDestination.LookupDestination(remotedest, (hash, ls, tag) =>
                            {
                                if (ls is null)
                                {
                                    Logging.LogInformation($"Program {UnpublishedDestination}: Failed to lookup {hash.Id32Short}.");
                                    return;
                                }

                                var test = new I2PIdentHash(ls.Destination);
                                Logging.LogInformation($"Program {UnpublishedDestination}: Found {remotedest}, test: {test.Id32Short}.");

                                var s  = new BufRefStream();
                                var sh = new StreamingPacket(
                                    PacketFlags.SYNCHRONIZE
                                    | PacketFlags.FROM_INCLUDED
                                    | PacketFlags.SIGNATURE_INCLUDED
                                    | PacketFlags.MAX_PACKET_SIZE_INCLUDED
                                    | PacketFlags.NO_ACK)
                                {
                                    From            = UnpublishedDestination.Destination,
                                    SigningKey      = MyDestinationInfo.PrivateSigningKey,
                                    ReceiveStreamId = recvid,
                                    NACKs           = new List <uint>(),
                                    Payload         = new BufLen(new byte[0]),
                                };

                                sh.Write(s);
                                var buf    = s.ToByteArray();
                                var zipped = LZUtils.BCGZipCompressNew(new BufLen(buf));
                                zipped.PokeFlip16(4353, 4);                // source port
                                zipped.PokeFlip16(25, 6);                  // dest port
                                zipped[9] = (byte)PayloadFormat.Streaming; // streaming

                                Logging.LogInformation($"Program {UnpublishedDestination}: Sending {zipped:20}.");

                                UnpublishedDestination.Send(ls.Destination, zipped);
                            });
                        });
                    }
                }
                catch (SocketException ex)
                {
                    Logging.Log(ex);
                }
                catch (IOException ex)
                {
                    Logging.Log(ex);
                }
                catch (Exception ex)
                {
                    Logging.Log(ex);
                }
            }
        }
Beispiel #18
0
 public TransactionAgentStatistics(ITelemetryProducer telemetryProducer, IOptions <StatisticsOptions> options)
 {
     this.telemetryProducer = telemetryProducer;
     this.lastReportTime    = DateTime.UtcNow;
     this.monitor           = new PeriodicAction(options.Value.PerfCountersWriteInterval, this.ReportMetrics);
 }
 public override void DoPeriodicAction()
 {
     PeriodicAction?.Invoke();
 }
Beispiel #20
0
 public TransactionAgentMetrics(ITelemetryProducer producer, TimeSpan interval)
 {
     this.telemetryProducer = producer;
     this.periodicMonitor   = new PeriodicAction(interval, this.ReportMetrics);
 }
Beispiel #21
0
 public TransactionManagerMetrics(ITelemetryProducer telemetryProducer, TimeSpan metricReportInterval)
 {
     this.telemetryProducer = telemetryProducer;
     this.monitor           = new PeriodicAction(metricReportInterval, this.ReportMetrics);
 }
Beispiel #22
0
        static void Main(string[] args)
        {
            PeriodicAction SendInterval = new PeriodicAction(TickSpan.Seconds(20));

            Logging.ReadAppConfig();
            Logging.LogToDebug   = false;
            Logging.LogToConsole = true;

            RouterContext.RouterSettingsFile = "I2PDemo.bin";

            MyDestinationInfo = new I2PDestinationInfo(I2PSigningKey.SigningKeyTypes.EdDSA_SHA512_Ed25519);

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "--addr":
                case "--address":
                    if (args.Length > i + 1)
                    {
                        RouterContext.Inst.DefaultExtAddress = IPAddress.Parse(args[++i]);
                        Console.WriteLine($"addr {RouterContext.Inst.DefaultExtAddress}");
                    }
                    else
                    {
                        Console.WriteLine("--addr require ip number");
                        return;
                    }
                    break;

                case "--port":
                    if (args.Length > i + 1)
                    {
                        var port = int.Parse(args[++i]);
                        RouterContext.Inst.DefaultTCPPort = port;
                        RouterContext.Inst.DefaultUDPPort = port;
                        Console.WriteLine($"port {port}");
                    }
                    else
                    {
                        Console.WriteLine("--port require port number");
                        return;
                    }
                    break;

                case "--nofw":
                    RouterContext.Inst.IsFirewalled = false;
                    Console.WriteLine($"Firewalled {RouterContext.Inst.IsFirewalled}");
                    break;

                case "--mkdest":
                case "--create-destination":
                    var certtype = 0;
                    if (args.Length > i + 1)
                    {
                        certtype = int.Parse(args[++i]);
                    }

                    I2PSigningKey.SigningKeyTypes ct;
                    I2PDestinationInfo            d;

                    switch (certtype)
                    {
                    default:
                    case 0:
                        ct = I2PSigningKey.SigningKeyTypes.EdDSA_SHA512_Ed25519;
                        d  = new I2PDestinationInfo(ct);
                        break;

                    case 1:
                        ct = I2PSigningKey.SigningKeyTypes.DSA_SHA1;
                        d  = new I2PDestinationInfo(ct);
                        break;

                    case 2:
                        ct = I2PSigningKey.SigningKeyTypes.ECDSA_SHA256_P256;
                        d  = new I2PDestinationInfo(ct);
                        break;

                    case 3:
                        ct = I2PSigningKey.SigningKeyTypes.ECDSA_SHA384_P384;
                        d  = new I2PDestinationInfo(ct);
                        break;
                    }

                    Console.WriteLine($"New destination {ct}: {d.ToBase64()}");
                    return;

                case "--destination":
                    if (args.Length > i + 1)
                    {
                        MyDestinationInfo = new I2PDestinationInfo(args[++i]);
                        Console.WriteLine($"Destination {MyDestinationInfo}");
                    }
                    else
                    {
                        Console.WriteLine("Base64 encoded Destination required");
                        return;
                    }
                    break;

                default:
                    Console.WriteLine(args[i]);
                    Console.WriteLine("Usage: I2P.exe --addr 12.34.56.78 --port 8081 --nofw --create-destination [0-3] --destination b64...");
                    break;
                }
            }

            RouterContext.Inst.ApplyNewSettings();

            var pnp = new UPnp();

            Thread.Sleep(5000);   // Give UPnp a chance

            Router.Start();

            // Create new identities for this run

            MyDestination = MyDestinationInfo.Destination;

#if MANUAL_SIGN
            PublishedDestination = Router.CreateDestination(
                MyDestination,
                MyDestinationInfo.PrivateKey,
                true,
                out _);      // Publish our destinaiton
            PublishedDestination.SignLeasesRequest += MyDestination_SignLeasesRequest;
#else
            PublishedDestination = Router.CreateDestination(MyDestinationInfo, true, out _);   // Publish our destinaiton
#endif
            PublishedDestination.DataReceived += MyDestination_DataReceived;
            PublishedDestination.Name          = "PublishedDestination";

            MyOriginInfo = new I2PDestinationInfo(I2PSigningKey.SigningKeyTypes.DSA_SHA1);
            MyOrigin     = Router.CreateDestination(MyOriginInfo, false, out _);
            MyOrigin.ClientStateChanged += MyOrigin_ClientStateChanged;
            MyOrigin.DataReceived       += MyOrigin_DataReceived;
            MyOrigin.Name = "MyOrigin";

            Logging.LogInformation($"MyDestination: {PublishedDestination.Destination.IdentHash} {MyDestinationInfo.Destination.Certificate}");

            while (true)
            {
                try
                {
                    Connected = true;

                    MyOrigin.LookupDestination(PublishedDestination.Destination.IdentHash, LookupResult);

                    var sendevents = 0;

                    while (Connected)
                    {
                        Thread.Sleep(2000);

                        if (LookedUpDestination != null &&
                            MyOrigin.ClientState == ClientDestination.ClientStates.Established)
                        {
                            SendInterval.Do(() =>
                            {
                                if (sendevents++ < 10)
                                {
                                    // Send some data to the MyDestination
                                    DataSent = new BufLen(
                                        BufUtils.RandomBytes(
                                            (int)(1 + BufUtils.RandomDouble(25) * 1024)));

                                    var ok = MyOrigin.Send(LookedUpDestination, DataSent);
                                    Logging.LogInformation($"Program {MyOrigin}: Send[{sendevents}] {ok}, {DataSent:15}");
                                }

                                if (sendevents > 100)
                                {
                                    sendevents = 0;
                                }
                            });
                        }
                    }
                }
                catch (SocketException ex)
                {
                    Logging.Log(ex);
                }
                catch (IOException ex)
                {
                    Logging.Log(ex);
                }
                catch (Exception ex)
                {
                    Logging.Log(ex);
                }
            }
        }