Exemple #1
0
            public virtual NATContext PrivateInput(IPAddress sources, IPAddress destination, ushort Identification)
            {
                if (sources == null || destination == null)
                {
                    return(null);
                }
                this.DoEvents();
                long sources_key = Ethernet.GetAddress(sources);

                lock (this.m_AddressToContext)
                {
                    lock (this.m_syncobj)
                    {
                        this.m_AddressToContext.TryGetValue(sources_key, out NATContext context);
                        if (context == null && 0 != Identification)
                        {
                            context = new NATContext()
                            {
                                LocalEP         = new IPEndPoint(this.m_nat.m_ethernetAddress, 0),
                                AgingTimePeriod = new Stopwatch(),
                                Sources         = new IPEndPoint(sources, Identification),
                                Destination     = new IPEndPoint(destination, 0),
                                State           = NATContext.StateCode.TCP_NIL,
                            };
                            this.m_AddressToContext[sources_key] = context;
                        }
                        return(context?.Restart());
                    }
                }
            }
Exemple #2
0
            public virtual int Release(IPAddress sources)
            {
                long sources_key = Ethernet.GetAddress(sources);

                if (sources == null)
                {
                    return(0);
                }
                NATContext context = null;

                lock (this.m_AddressToContext)
                {
                    lock (this.m_syncobj)
                    {
                        this.m_AddressToContext.TryRemove(sources_key, out context);
                        if (context == null)
                        {
                            return(0);
                        }
                    }
                }
                context.Dispose();
                return(1);
            }