func (a *AddrBook) moveToOld(ka *knownAddress) {
	// Sanity check
	if ka.isOld() {
		log.Warn(Fmt("Cannot promote address that is already old %v", ka))
		return
	}
	if len(ka.Buckets) == 0 {
		log.Warn(Fmt("Cannot promote address that isn't in any new buckets %v", ka))
		return
	}

	// Remember one of the buckets in which ka is in.
	freedBucket := ka.Buckets[0]
	// Remove from all (new) buckets.
	a.removeFromAllBuckets(ka)
	// It's officially old now.
	ka.BucketType = bucketTypeOld

	// Try to add it to its oldBucket destination.
	oldBucketIdx := a.calcOldBucket(ka.Addr)
	added := a.addToOldBucket(ka, oldBucketIdx)
	if !added {
		// No room, must evict something
		oldest := a.pickOldest(bucketTypeOld, oldBucketIdx)
		a.removeFromBucket(oldest, bucketTypeOld, oldBucketIdx)
		// Find new bucket to put oldest in
		newBucketIdx := a.calcNewBucket(oldest.Addr, oldest.Src)
		added := a.addToNewBucket(oldest, newBucketIdx)
		// No space in newBucket either, just put it in freedBucket from above.
		if !added {
			added := a.addToNewBucket(oldest, freedBucket)
			if !added {
				log.Warn(Fmt("Could not migrate oldest %v to freedBucket %v", oldest, freedBucket))
			}
		}
		// Finally, add to bucket again.
		added = a.addToOldBucket(ka, oldBucketIdx)
		if !added {
			log.Warn(Fmt("Could not re-add ka %v to oldBucketIdx %v", ka, oldBucketIdx))
		}
	}
}
func (a *AddrBook) moveToOld(ka *knownAddress) {
	
	if ka.isOld() {
		log.Warn(Fmt("Cannot promote address that is already old %v", ka))
		return
	}
	if len(ka.Buckets) == 0 {
		log.Warn(Fmt("Cannot promote address that isn't in any new buckets %v", ka))
		return
	}

	
	freedBucket := ka.Buckets[0]
	
	a.removeFromAllBuckets(ka)
	
	ka.BucketType = bucketTypeOld

	
	oldBucketIdx := a.calcOldBucket(ka.Addr)
	added := a.addToOldBucket(ka, oldBucketIdx)
	if !added {
		
		oldest := a.pickOldest(bucketTypeOld, oldBucketIdx)
		a.removeFromBucket(oldest, bucketTypeOld, oldBucketIdx)
		
		newBucketIdx := a.calcNewBucket(oldest.Addr, oldest.Src)
		added := a.addToNewBucket(oldest, newBucketIdx)
		
		if !added {
			added := a.addToNewBucket(oldest, freedBucket)
			if !added {
				log.Warn(Fmt("Could not migrate oldest %v to freedBucket %v", oldest, freedBucket))
			}
		}
		
		added = a.addToOldBucket(ka, oldBucketIdx)
		if !added {
			log.Warn(Fmt("Could not re-add ka %v to oldBucketIdx %v", ka, oldBucketIdx))
		}
	}
}
func ( a * AddrBook ) moveToOld ( ka * knownAddress ) { // Sanity check if ka . isOld ( ) { log . Warn ( Fmt ( " " , ka ) ) return } if len ( ka . Buckets ) == 0 { log . Warn ( Fmt ( " " , ka ) ) return } // Remember one of the buckets in which ka is in. freedBucket := ka . Buckets [ 0 ] // Remove from all (new) buckets. a . removeFromAllBuckets ( ka ) // It's officially old now. ka . BucketType = bucketTypeOld // Try to add it to its oldBucket destination. oldBucketIdx := a . calcOldBucket ( ka . Addr ) added := a . addToOldBucket ( ka , oldBucketIdx ) if ! added { // No room, must evict something oldest := a . pickOldest ( bucketTypeOld , oldBucketIdx ) a . removeFromBucket ( oldest , bucketTypeOld , oldBucketIdx ) // Find new bucket to put oldest in newBucketIdx := a . calcNewBucket ( oldest . Addr , oldest . Src ) added := a . addToNewBucket ( oldest , newBucketIdx ) // No space in newBucket either, just put it in freedBucket from above. if ! added { added := a . addToNewBucket ( oldest , freedBucket ) if ! added { log . Warn ( Fmt ( " " , oldest , freedBucket ) ) } } // Finally, add to bucket again. added = a . addToOldBucket ( ka , oldBucketIdx ) if ! added { log . Warn ( Fmt ( " " , ka , oldBucketIdx ) ) } } }
// Promotes an address from new to old.
// TODO: Move to old probabilistically.
// The better a node is, the less likely it should be evicted from an old bucket.
Promotes an address from new to old . TODO : Move to old probabilistically . The better a node is the less likely it should be evicted from an old bucket .