public synchronized void add(Contact contact)
	{
		consecutiveFailures = 0;
		
		if (contact.getNodeId().equals(localNode.getNodeId()))
		{
			// The local node cannot be added to the route table
			//throw new IllegalArgumentException("Cannot add the local node to the route table");
			return;
		}
		NodeId nodeId = contact.getNodeId();
        Bucket bucket = bucketTrie.select(nodeId);//selects the bucket whose id is the closest to contact's id

        if (!bucket.containsBucketContact(contact.getNodeId()))
        {
        	if (!bucket.isBucketFull())
        	{
        		addContactToBucket(bucket, contact);
                //addContactToCache(bucket, contact);
        	}
        	else if (split(bucket))
        	{
        		add(contact); // re-try to add the contact after the bucket splitting
        	}
        	else
        	{
        		//try to replace an old bucket contact, or add it to bucket's cache 
        		replaceContactInBucket(bucket, contact); 
        	}
        }
        else
        {
        	bucket.get(contact.getNodeId()).refresh();
        }
        
        bucket.touch();
	}