addrbook.go
func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool {
	// Sanity check
	if ka.isOld() {
		log.Warn(Fmt("Cannot add address already in old bucket to a new bucket: %v", ka))
		return false
	}

	addrStr := ka.Addr.String()
	bucket := a.getBucket(bucketTypeNew, bucketIdx)

	// Already exists?
	if _, ok := bucket[addrStr]; ok {
		return true
	}

	// Enforce max addresses.
	if len(bucket) > newBucketSize {
		log.Notice("new bucket is full, expiring old ")
		a.expireNew(bucketIdx)
	}

	// Add to bucket.
	bucket[addrStr] = ka
	if ka.addBucketRef(bucketIdx) == 1 {
		a.nNew++
	}

	// Ensure in addrLookup
	a.addrLookup[addrStr] = ka

	return true
}
func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool {
	// Sanity check
	if ka.isOld() {
		log.Warn(Fmt("Cannot add address already in old bucket to a new bucket: %v", ka))
		return false
	}

	addrStr := ka.Addr.String()
	bucket := a.getBucket(bucketTypeNew, bucketIdx)

	// Already exists?
	if _, ok := bucket[addrStr]; ok {
		return true
	}

	// Enforce max addresses.
	if len(bucket) > newBucketSize {
		log.Notice("new bucket is full, expiring old ")
		a.expireNew(bucketIdx)
	}

	// Add to bucket.
	bucket[addrStr] = ka
	if ka.addBucketRef(bucketIdx) == 1 {
		a.nNew++
	}

	// Ensure in addrLookup
	a.addrLookup[addrStr] = ka

	return true
}
func ( a * AddrBook ) addToNewBucket ( ka * knownAddress , bucketIdx int ) bool { // Sanity check if ka . isOld ( ) { log . Warn ( Fmt ( " " , ka ) ) return false } addrStr := ka . Addr . String ( ) bucket := a . getBucket ( bucketTypeNew , bucketIdx ) // Already exists? if _ , ok := bucket [ addrStr ] ; ok { return true } // Enforce max addresses. if len ( bucket ) > newBucketSize { log . Notice ( " " ) a . expireNew ( bucketIdx ) } // Add to bucket. bucket [ addrStr ] = ka if ka . addBucketRef ( bucketIdx ) == 1 { a . nNew ++ } // Ensure in addrLookup a . addrLookup [ addrStr ] = ka return true }
// Adds ka to new bucket. Returns false if it couldn't do it cuz buckets full.
// NOTE: currently it always returns true.
Adds ka to new bucket . Returns false if it couldn t do it cuz buckets full . NOTE : currently it always returns true .