Beispiel #1
0
        static void MyDestination_DataReceived(ClientDestination dest, BufLen data)
        {
            var compareok = DataSent is null ? false : DataSent == data;

            Logging.LogInformation($"Program {MyDestination}: MyDestination data received. Matches send: {compareok} {data:15}");
            PublishedDestination.Send(MyOrigin.Destination, data);
        }
Beispiel #2
0
        internal void TunnelTimeout(Tunnel tunnel)
        {
            ClientDestination client = FindClient(tunnel);

            if (client == null)
            {
                return;
            }

            var replace = FindReplaceRecord(tunnel);

            if (replace != null)
            {
                DebugUtils.LogDebug("ClientTunnelProvider: TunnelTimeout: Failed replacing " + replace.OldTunnel.ToString() +
                                    " with " + tunnel.ToString());

                /*
                 * if ( replace.OldTunnel.Expired )
                 * {
                 *  DebugUtils.LogDebug( "ClientTunnelProvider: TunnelTimeout: Old tunnel expired. " + replace.OldTunnel.ToString() );
                 *
                 *  client.RemovePoolTunnel( replace.OldTunnel );
                 * }*/

                ReplaceTunnel(tunnel, client, replace);
            }

            client.RemoveTunnel(tunnel);
        }
Beispiel #3
0
        internal ClientDestination CreateDestination(I2PDestinationInfo dest, bool publish)
        {
            var newclient = new ClientDestination(this, dest, publish);

            Clients.Add(newclient);
            return(newclient);
        }
Beispiel #4
0
        internal void TunnelEstablished(Tunnel tunnel)
        {
            TunnelUnderReplacement replace = null;

            ClientDestination client = FindClient(tunnel);

            if (client == null)
            {
                return;
            }

            client.TunnelEstablished(tunnel);

            lock ( RunningReplacements )
            {
                replace = RunningReplacements.Where(p => p.Value.NewTunnels.Any(t => t.Equals(tunnel))).
                          Select(p => p.Value).SingleOrDefault();
                if (replace != null)
                {
                    RunningReplacements.Remove(replace.OldTunnel);
                }
            }

            if (replace != null)
            {
                DebugUtils.LogDebug("ClientTunnelProvider: TunnelEstablished: Successfully replaced old tunnel " + replace.OldTunnel.ToString() +
                                    " with new tunnel " + tunnel.ToString());

                RemoveTunnelUnderReplacement(replace.OldTunnel);
                //client.RemoveTunnel( replace.OldTunnel );
                //TunnelMgr.RemoveTunnel( replace.OldTunnel );
                //replace.OldTunnel.Shutdown();
                return;
            }
        }
Beispiel #5
0
        private void ReplaceTunnel(Tunnel tunnel, ClientDestination client, TunnelUnderReplacement replace)
        {
            if (tunnel != replace.OldTunnel)
            {
                replace.NewTunnels.RemoveAll(t => t.Equals(tunnel));
            }

            while (replace.NewTunnels.Count < NewTunnelCreationFactor)
            {
                switch (tunnel.Config.Direction)
                {
                case TunnelConfig.TunnelDirection.Outbound:
                    var newouttunnel = CreateOutboundTunnel(client, null);
                    replace.NewTunnels.Add(newouttunnel);
                    DebugUtils.LogDebug(() => string.Format("ClientTunnelProvider: ReplaceTunnel: Started to replace {0} with {1}.",
                                                            tunnel, newouttunnel));
                    break;

                case TunnelConfig.TunnelDirection.Inbound:
                    var newintunnel = CreateInboundTunnel(client, null);
                    replace.NewTunnels.Add(newintunnel);
                    DebugUtils.LogDebug(() => string.Format("ClientTunnelProvider: ReplaceTunnel: Started to replace {0} with {1}.",
                                                            tunnel, newintunnel));
                    break;

                default:
                    throw new NotImplementedException("Only out and inbound tunnels should be reported here.");
                }
            }
        }
Beispiel #6
0
 public TestSessionKeyOrigin(
     ClientDestination owner,
     I2PDestination mydest,
     I2PDestination remotedest)
     : base(owner, mydest, remotedest)
 {
 }
Beispiel #7
0
    private void HasBeenServed()
    {
        Vector3 outOfScreenDestination = ClientDestination.ComputeSpawnOrQuitPosition();

        PutMoneyOnCounter();
        // Clients leaving are shown behind every other clients
        outOfScreenDestination.z = 1;
        StartCoroutine(MoveTowardsDestination(outOfScreenDestination, DestroyClient));
    }
Beispiel #8
0
        static void MyDestination_DataReceived(ClientDestination dest, BufLen data)
        {
            Logging.LogInformation($"Program {UnpublishedDestination}: data received {data:20}");

            var reader = new BufRefLen(data);
            var unzip  = LZUtils.BCGZipDecompressNew((BufLen)reader);
            var packet = new StreamingPacket((BufRefLen)unzip);

            Logging.LogInformation($"Program {UnpublishedDestination}: {packet}");
        }
Beispiel #9
0
        TunnelInfo CreateOutgoingTunnelChain(ClientDestination dest)
        {
            var hops = new List <HopInfo>();

            for (int i = 0; i < dest.OutboundTunnelHopCount; ++i)
            {
                var ih = NetDb.Inst.GetRandomRouterForTunnelBuild(false);
                hops.Add(new HopInfo(NetDb.Inst[ih].Identity, new I2PTunnelId()));
            }

            return(new TunnelInfo(hops));
        }
Beispiel #10
0
        private OutboundTunnel CreateOutboundTunnel(ClientDestination dest, TunnelInfo prototype)
        {
            var config = new TunnelConfig(
                TunnelConfig.TunnelDirection.Outbound,
                TunnelConfig.TunnelPool.Client,
                prototype == null ? CreateOutgoingTunnelChain(dest): prototype);

            var tunnel = (OutboundTunnel)TunnelMgr.CreateTunnel(config);

            if (tunnel != null)
            {
                TunnelMgr.AddTunnel(tunnel);
                dest.AddOutboundPending(tunnel);
                lock (Destinations) Destinations[tunnel] = dest;
            }
            return(tunnel);
        }
Beispiel #11
0
        static void MyDestination_DataReceived(ClientDestination dest, BufLen data)
        {
            Logging.LogInformation($"Program {PublishedDestination}: data received {data:15}");

            var reader = new BufRefLen(data);
            var unzip  = LZUtils.BCGZipDecompressNew((BufLen)reader);
            var packet = new StreamingPacket((BufRefLen)unzip);

            Logging.LogInformation($"Program {PublishedDestination}: {packet} {packet.Payload}");

            PublishedDestination.LookupDestination(packet?.From.IdentHash, (hash, ls, tag) =>
            {
                if (ls is null)
                {
                    Logging.LogInformation($"Program {PublishedDestination}: Failed to lookup {hash?.Id32Short}.");
                    return;
                }

                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            = PublishedDestination.Destination,
                    SigningKey      = MyDestinationInfo.PrivateSigningKey,
                    ReceiveStreamId = packet.ReceiveStreamId,
                    SendStreamId    = SendId,
                    NACKs           = new List <uint>(),
                    Payload         = new BufLen(BufUtils.RandomBytes(30)),
                };

                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 {PublishedDestination}: Sending {zipped:20}.");
                PublishedDestination.Send(ls.Destination, zipped);
            });
        }
Beispiel #12
0
        private InboundTunnel CreateInboundTunnel(ClientDestination dest, TunnelInfo prototype)
        {
            var config = new TunnelConfig(
                TunnelConfig.TunnelDirection.Inbound,
                TunnelConfig.TunnelPool.Client,
                prototype == null ? CreateIncommingTunnelChain(dest): prototype);

            var tunnel = (InboundTunnel)TunnelMgr.CreateTunnel(config);

            if (tunnel != null)
            {
                tunnel.GarlicMessageReceived += new Action <GarlicMessage>(tunnel_GarlicMessageReceived);
                TunnelMgr.AddTunnel(tunnel);
                dest.AddInboundPending(tunnel);
                lock (Destinations) Destinations[tunnel] = dest;
            }
            return(tunnel);
        }
Beispiel #13
0
        internal void TunnelBuildTimeout(Tunnel tunnel)
        {
            ClientDestination client = FindClient(tunnel);

            if (client == null)
            {
                return;
            }

            client.RemoveTunnel(tunnel);

            lock ( Destinations )
            {
                Destinations.Remove(tunnel);
            }

            var replace = FindReplaceRecord(tunnel);

            if (replace != null)
            {
                DebugUtils.LogDebug("ClientTunnelProvider: TunnelBuildTimeout: Failed replacing " + replace.OldTunnel.ToString() +
                                    " with " + tunnel.ToString());

                if (replace.OldTunnel.Expired)
                {
                    DebugUtils.LogDebug("ClientTunnelProvider: TunnelBuildTimeout: Old tunnel expired. " + replace.OldTunnel.ToString());

                    client.RemoveTunnel(replace.OldTunnel);
                }

                tunnel.Shutdown();
                ReplaceTunnel(tunnel, client, replace);
            }
            else
            {
/*
 #if DEBUG
 *              DebugUtils.LogDebug( "ClientTunnelProvider: TunnelBuildTimeout: Unable to find a matching tunnel under replacement for " +
 *                  tunnel.ToString() );
 #endif
 */
            }
        }
Beispiel #14
0
        internal void TunnelReplacementNeeded(Tunnel tunnel)
        {
            ClientDestination client = FindClient(tunnel);

            if (client == null)
            {
                return;
            }

            TunnelUnderReplacement replace;

            lock ( RunningReplacements )
            {
                if (!RunningReplacements.TryGetValue(tunnel, out replace))
                {
                    return;                                                            // Already being replaced
                }
                // Too many tunnels already?
                if (tunnel is InboundTunnel)
                {
                    if (client.InboundTunnelsNeeded < 0)
                    {
                        return;
                    }
                }
                else
                {
                    if (client.OutboundTunnelsNeeded < 0)
                    {
                        return;
                    }
                }

                replace = new TunnelUnderReplacement(tunnel, client);
                lock ( RunningReplacements )
                {
                    RunningReplacements[tunnel] = replace;
                }
            }

            ReplaceTunnel(tunnel, client, replace);
        }
Beispiel #15
0
        internal void TunnelBuildTimeout(Tunnel tunnel)
        {
            ClientDestination client = FindClient(tunnel);

            if (client == null)
            {
                return;
            }

            client.RemoveTunnel(tunnel);

            lock ( Destinations )
            {
                Destinations.Remove(tunnel);
            }

            var replace = FindReplaceRecord(tunnel);

            if (replace != null)
            {
                Logging.LogDebug($"ClientTunnelProvider: TunnelBuildTimeout: " +
                                 $"Failed replacing {replace.OldTunnel} with {tunnel}");

                if (replace.OldTunnel.Expired)
                {
                    Logging.LogDebug($"ClientTunnelProvider: TunnelBuildTimeout: " +
                                     $"Old tunnel expired. {replace.OldTunnel}");

                    client.RemoveTunnel(replace.OldTunnel);
                }

                tunnel.Shutdown();
                ReplaceTunnel(tunnel, client, replace);
            }
            else
            {
/*
 *              Logging.LogDebug( $"ClientTunnelProvider: TunnelBuildTimeout: " +
 *                  $"Unable to find a matching tunnel under replacement for {tunnel}" );
 */
            }
        }
Beispiel #16
0
    private void SpawnClient()
    {
        Client     clientSpawned;
        ClientData clientDataToSpawn;
        GameObject clientSpawnedGameObject;
        GameObject orderSpawnedGameObject;

        clientDataToSpawn       = (_isClientsInfinite) ? (_clientGenerator.GetNextClient()) : (_clientsList.Dequeue());
        clientSpawnedGameObject = Instantiate(_clientGenericPrefab, ClientDestination.ComputeSpawnOrQuitPosition(), Quaternion.identity, transform);
        if (!clientSpawnedGameObject.TryGetComponent <Client>(out clientSpawned))
        {
            Debug.LogError("Error: No Component 'Client' was found on gameObject '" + clientSpawnedGameObject.name + "'.");
        }
        else
        {
            orderSpawnedGameObject = Instantiate(_orderUIPrefab, Camera.main.WorldToScreenPoint(clientSpawnedGameObject.transform.GetChild(0).transform.position), Quaternion.identity, _orderParent);
            clientSpawned.CreateClient(clientDataToSpawn, orderSpawnedGameObject.GetComponent <InteractibleOrder>());
            orderSpawnedGameObject.SetActive(false);
        }
    }
Beispiel #17
0
        static void Main(string[] args)
        {
            Logging.ReadAppConfig();
            Logging.LogToDebug   = false;
            Logging.LogToConsole = true;

            RouterContext.RouterSettingsFile = "EchoServerRouter.bin";
            //RouterContext.Inst = new RouterContext(
            //new I2PCertificate(
            //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;

                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["Destination"];

            MyDestinationInfo = new I2PDestinationInfo(destb32);

            PublishedDestination = Router.CreateDestination(MyDestinationInfo, true, out _);
            PublishedDestination.DataReceived += MyDestination_DataReceived;
            PublishedDestination.Name          = "PublishedDestination";

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

            while (true)
            {
                try
                {
                    Connected = true;

                    while (Connected)
                    {
                        Thread.Sleep(2000);
                    }
                }
                catch (SocketException ex)
                {
                    Logging.Log(ex);
                }
                catch (IOException ex)
                {
                    Logging.Log(ex);
                }
                catch (Exception ex)
                {
                    Logging.Log(ex);
                }
            }
        }
Beispiel #18
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 #19
0
 static void MyOrigin_ClientStateChanged(ClientDestination dest, ClientDestination.ClientStates state)
 {
     Logging.LogInformation($"Program {MyOrigin}: Client state {state}");
 }
Beispiel #20
0
 static void MyOrigin_DataReceived(ClientDestination dest, BufLen data)
 {
     Logging.LogInformation($"Program {MyOrigin}: data received. {data:15}");
 }
Beispiel #21
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);
                }
            }
        }
Beispiel #22
0
 internal TunnelUnderReplacement(Tunnel old, ClientDestination dest)
 {
     OldTunnel   = old;
     Destination = dest;
 }