Ejemplo n.º 1
0
 void UpdateP2PList()
 {
     if (m_SendP2PList == null)
     {
         m_SendP2PList = SendP2PList;
     }
     if (m_PeerToPeerListDirty)
     {
         m_PeerToPeerListDirty = false;
         var revision = m_PeerToPeerList.Revision;
         revision++;
         var randamKey = P2PTask.GetHostRandamKey();
         m_PeerToPeerList = new PeerToPeerList(SelfId, revision, m_PeerManager.CreatePeerInfoList(randamKey));
     }
     m_PeerManager.ForEach(m_SendP2PList, m_PeerToPeerList);
 }
Ejemplo n.º 2
0
        internal P2PConnectionImpl(LocalHostConfig config) : base(new UdpSocket(), new EncryptorGenerator())
        {
            m_IsOwner = true;
            m_CookieProvider.Update();
            m_Socket.Bind(new IPEndPoint(config.Address, 0), false);
            SelfId = Random.GenInt();
            P2PTask.CreateHostRandamKey();
            var randamKey = P2PTask.GetHostRandamKey();
            var data      = new PeerToPeerRoomData(SelfId, m_CookieProvider.Cookie, randamKey).Pack();

            m_DiscoveryService = new DiscoveryService(config.RoomName, m_Socket.LocalEP, data, config.DiscoveryServicePort);
            m_DiscoveryService.OnHolePunchRequest += (ep) =>
            {
                var packet = new DiscoveryHolePunch().Pack();
                m_Socket.Send(packet, 0, packet.Length, ep);
            };
            m_DiscoveryService.Start(config.DiscoveryQueryMatch);
        }