Exemple #1
0
        // inbound
        public TcpConnect(TcpHandler control)
        {
            TcpControl = control;
            Network    = TcpControl.Network;
            Core       = TcpControl.Core;

            Bandwidth = new BandwidthLog(Core.RecordBandwidthSeconds);
        }
Exemple #2
0
        // inbound
        public TcpConnect(TcpHandler control)
        {
            TcpControl = control;
            Network    = TcpControl.Network;
            Core       = TcpControl.Core;

            Bandwidth = new BandwidthLog(Core.RecordBandwidthSeconds);
        }
Exemple #3
0
        // outbound
        public TcpConnect(TcpHandler control, DhtAddress address, ushort tcpPort)
        {
            Debug.Assert(address.UserID != 0);

            TcpControl = control;
            Network    = TcpControl.Network;
            Core       = TcpControl.Core;

            Bandwidth = new BandwidthLog(Core.RecordBandwidthSeconds);

            Outbound = true;

            RemoteIP = address.IP;
            TcpPort  = tcpPort;
            UdpPort  = address.UdpPort;
            UserID   = address.UserID;

            try
            {
                IPEndPoint endpoint = new IPEndPoint(RemoteIP, TcpPort);

                if (Core.Sim != null)
                {
                    Core.Sim.Internet.SendPacket(SimPacketType.TcpConnect, Network, null, endpoint, this);
                    return;
                }

                TcpSocket = new Socket(address.IP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                TcpSocket.BeginConnect((EndPoint)endpoint, new AsyncCallback(Socket_Connect), TcpSocket);
            }
            catch (Exception ex)
            {
                LogException("TcpSocket", ex.Message);
                Disconnect();
            }
        }
Exemple #4
0
        // outbound
        public TcpConnect(TcpHandler control, DhtAddress address, ushort tcpPort)
        {
            Debug.Assert(address.UserID != 0);

            TcpControl = control;
            Network = TcpControl.Network;
            Core = TcpControl.Core;

            Bandwidth = new BandwidthLog(Core.RecordBandwidthSeconds);

            Outbound = true;

            RemoteIP = address.IP;
            TcpPort  = tcpPort;
            UdpPort  = address.UdpPort;
            UserID    = address.UserID;

            try
            {
                IPEndPoint endpoint = new IPEndPoint(RemoteIP, TcpPort);

                if (Core.Sim != null)
                {
                    Core.Sim.Internet.SendPacket(SimPacketType.TcpConnect, Network, null, endpoint, this);
                    return;
                }

                TcpSocket = new Socket(address.IP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                TcpSocket.BeginConnect((EndPoint)endpoint, new AsyncCallback(Socket_Connect), TcpSocket);
            }
            catch (Exception ex)
            {
                LogException("TcpSocket", ex.Message);
                Disconnect();
            }
        }
Exemple #5
0
        public DhtNetwork(OpCore core, bool lookup)
        {
            Core = core;
            IsLookup = lookup;

            Cache = new OpCache(this); // lookup config loads cache entries

            if (IsLookup)
            {
                Core.Context.LookupConfig.Load(this);
                Lookup = Core.Context.LookupConfig;
            }

            Local = new DhtClient();
            Local.UserID = IsLookup ? Lookup.Ports.UserID : Utilities.KeytoID(Core.User.Settings.KeyPublic);
            Local.ClientID = (ushort)Core.RndGen.Next(1, ushort.MaxValue);

            OpID = Utilities.KeytoID(IsLookup ? LookupKey : Core.User.Settings.OpKey);

            OpCrypt = new RijndaelManaged();

            // load encryption
            if (IsLookup)
                OpCrypt.Key = LookupKey;
            else
                OpCrypt.Key = Core.User.Settings.OpKey;

            LocalAugmentedKey = GetAugmentedKey(Local.UserID);

            Protocol = new G2Protocol();
            TcpControl = new TcpHandler(this);
            UdpControl = new UdpHandler(this);
            LanControl = new LanHandler(this);
            RudpControl = new RudpHandler(this);
            LightComm = new LightCommHandler(this);
            UPnPControl = new UPnPHandler(this);

            Routing = new DhtRouting(this);
            Store = new DhtStore(this);
            Searches = new DhtSearchControl(this);
        }