TMROOT env variable. Panic less.

This commit is contained in:
Jae Kwon
2014-07-16 13:15:18 -07:00
parent ca159b2726
commit 45adb24d43
3 changed files with 26 additions and 13 deletions

View File

@@ -386,7 +386,8 @@ func (a *AddrBook) getBucket(bucketType byte, bucketIdx int) map[string]*knownAd
func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool {
// Sanity check
if ka.isOld() {
panic("Cannot add address already in old bucket to a new bucket")
log.Warning("Cannot add address already in old bucket to a new bucket: %v", ka)
return false
}
addrStr := ka.Addr.String()
@@ -419,10 +420,12 @@ func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool {
func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool {
// Sanity check
if ka.isNew() {
panic("Cannot add new address to old bucket")
log.Warning("Cannot add new address to old bucket: %v", ka)
return false
}
if len(ka.Buckets) != 0 {
panic("Cannot add already old address to another old bucket")
log.Warning("Cannot add already old address to another old bucket: %v", ka)
return false
}
addrStr := ka.Addr.String()
@@ -452,7 +455,8 @@ func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool {
func (a *AddrBook) removeFromBucket(ka *knownAddress, bucketType byte, bucketIdx int) {
if ka.BucketType != bucketType {
panic("Bucket type mismatch")
log.Warning("Bucket type mismatch: %v", ka)
return
}
bucket := a.getBucket(bucketType, bucketIdx)
delete(bucket, ka.Addr.String())
@@ -493,7 +497,8 @@ func (a *AddrBook) pickOldest(bucketType byte, bucketIdx int) *knownAddress {
func (a *AddrBook) addAddress(addr, src *NetAddress) {
if !addr.Routable() {
panic("Cannot add non-routable address")
log.Warning("Cannot add non-routable address %v", addr)
return
}
ka := a.addrLookup[addr.String()]
@@ -545,10 +550,12 @@ func (a *AddrBook) expireNew(bucketIdx int) {
func (a *AddrBook) moveToOld(ka *knownAddress) {
// Sanity check
if ka.isOld() {
panic("Cannot promote address that is already old")
log.Warning("Cannot promote address that is already old %v", ka)
return
}
if len(ka.Buckets) == 0 {
panic("Cannot promote address that isn't in any new buckets")
log.Warning("Cannot promote address that isn't in any new buckets %v", ka)
return
}
// Remember one of the buckets in which ka is in.
@@ -725,7 +732,8 @@ func (ka *knownAddress) markGood() {
func (ka *knownAddress) addBucketRef(bucketIdx int) int {
for _, bucket := range ka.Buckets {
if bucket == bucketIdx {
panic("Bucket already exists in ka.Buckets")
log.Warning("Bucket already exists in ka.Buckets: %v", ka)
return -1
}
}
ka.Buckets = append(ka.Buckets, bucketIdx)
@@ -740,7 +748,8 @@ func (ka *knownAddress) removeBucketRef(bucketIdx int) int {
}
}
if len(buckets) != len(ka.Buckets)-1 {
panic("bucketIdx not found in ka.Buckets")
log.Warning("bucketIdx not found in ka.Buckets: %v", ka)
return -1
}
ka.Buckets = buckets
return len(ka.Buckets)