Exemplo n.º 1
0
Arquivo: Dht.cs Projeto: Renha/Tox.NET
        private DhtFriend AddNode(IPEndPoint endpoint, byte[] publicKey)
        {
            lock (_friendsLock)
            {
                var friend = GetNode(endpoint, publicKey);
                if (friend != null)
                    return friend;

                //if the list is full, remove a node that's further away
                //TODO: actually remove the node with the biggest distance difference
                int index = _friends.Count;
                if (_friends.Count == _friends.Capacity)
                {
                    if (ShouldInsert(publicKey, ref index))
                        return null;

                    if (_friends.Count == _friends.Capacity)
                        _friends.RemoveAt(index);
                }

                byte[] sharedKey = CryptoBox.BeforeNm(publicKey, KeyPair.SecretKey);
                friend = new DhtFriend(endpoint, publicKey, sharedKey);

                _friends.Insert(index, friend);
                Console.WriteLine("Added a new node to our close list: {0}", endpoint);

                return friend;
            }
        }
Exemplo n.º 2
0
 public void SendPacket(DhtFriend friend, IToxPacket packet)
 {
     byte[] data = packet.Pack(friend.SharedKey);
     Socket.SendTo(data, friend.EndPoint);
 }
Exemplo n.º 3
0
Arquivo: Dht.cs Projeto: Renha/Tox.NET
        private void SendPingRequest(DhtFriend friend)
        {
            var pingRequest = new PingRequest(KeyPair.PublicKey, CryptoRandom.NextUInt64());
            friend.AddPing(pingRequest.PingID);

            _net.SendPacket(friend, pingRequest);
        }
Exemplo n.º 4
0
Arquivo: Dht.cs Projeto: Renha/Tox.NET
 private void SendPingResponse(DhtFriend friend, ulong pingID)
 {
     var response = new PingResponse(KeyPair.PublicKey, pingID);
     _net.SendPacket(friend, response);
 }
Exemplo n.º 5
0
Arquivo: Dht.cs Projeto: Renha/Tox.NET
        private void SendGetNodes(DhtFriend friend, byte[] publicKey)
        {
            var packet = new GetNodesRequest(KeyPair.PublicKey, publicKey);
            friend.AddPing(packet.PingID);

            _net.SendPacket(friend, packet);
            _lastGetNodes = DateTime.Now;
        }