Esempio n. 1
0
        private void addrMsgHandle(P2PState state)
        {
            var peer = this.Peers.Where(p => p.IP == state.IP && p.Port == state.Port).FirstOrDefault();

            if (peer != null && peer.IsConnected)
            {
                var payload = new AddrMsg();
                int index   = 0;
                payload.Deserialize(state.Command.Payload, ref index);

                foreach (var item in payload.AddressList)
                {
                    if (this.Peers.Where(p => !p.IsTrackerServer && p.IP == item.Key && p.Port == item.Value && p.IsConnected).Count() == 0)
                    {
                        this.ConnectToNewPeer(item.Key, item.Value);
                    }
                }
            }
        }
Esempio n. 2
0
        private void addrMsgHandle(P2PState state)
        {
            var peers = this.p2pComponent.GetNodes();
            var peer  = peers.Where(p => p.IP == state.IP && p.Port == state.Port).FirstOrDefault();

            if (peer != null && peer.IsConnected)
            {
                var payload = new AddrMsg();
                int index   = 0;
                payload.Deserialize(state.Command.Payload, ref index);

                foreach (var item in payload.AddressList)
                {
                    if (peers.Where(p => !p.IsTrackerServer && p.IP == item.Ip && p.Port == item.Port && p.IsConnected).Count() == 0)
                    {
                        this.p2pComponent.AddNode(item.Ip, item.Port);
                    }
                }
            }
        }