Example #1
0
        public async void Init()
        {
            if (running)
            {
                return;
            }
            running        = true;
            adapterFactory = AdapterConfig.GetAdapterFactoryFromDefaultFile();
            dispatchWorker = Task.Run(() => doWork());

            w.PacketPoped            += W_PopPacket;
            w.DnsPacketPoped         += W_DnsPacketPoped;
            TcpSocket.EstablishedTcp += W_EstablishTcp;

            w.Init();
            while (running)
            {
                await Task.Delay(250);
                await executeLwipTask(() =>
                {
                    w.CheckTimeout();
                    return(0);
                });
            }
        }
Example #2
0
        public async void Init()
        {
            if (running)
            {
                return;
            }
            adapterFactory = await AdapterConfig.GetAdapterFactoryFromDefaultFile();

            running     = true;
            taskChannel = Channel.CreateUnbounded <Action>(new UnboundedChannelOptions()
            {
                SingleReader = true
            });
            var _ = Task.Run(() => doWork());

            wintun.PacketPoped       += W_PopPacket;
            TcpSocket.EstablishedTcp += W_EstablishTcp;

            wintun.Init();
            int i = 0;

            while (running)
            {
                i++;
                await executeLwipTask(() =>
                {
                    wintun.CheckTimeout();
                    return(0);
                }).ConfigureAwait(false);

                if (i % 10 == 0)
                {
                    tunAdapters.RemoveAll(w => !w.TryGetTarget(out var a) /* TODO: || a.IsShutdown == 1 */);
                    if (DebugLogger.LogNeeded())
                    {
                        DebugLogger.Log("# of connections in local stack: " + ConnectionCount);
                        DebugLogger.Log($"# of open/all adapters: {TunSocketAdapter.OpenCount} {tunAdapters.Count}");
                        DebugLogger.Log($"# of recv/send: {TunSocketAdapter.RecvingCount} {TunSocketAdapter.SendingCount}");
                    }
                }
                await Task.Delay(250).ConfigureAwait(false);
            }
        }