Просмотр исходного кода

Temporarily patch vendored gotapdance

- Guard against divide by zero when there are no decoys.
Rod Hynes 5 лет назад
Родитель
Сommit
ab1f3e0244
1 измененных файлов с 13 добавлено и 3 удалено
  1. 13 3
      vendor/github.com/refraction-networking/gotapdance/tapdance/conjure.go

+ 13 - 3
vendor/github.com/refraction-networking/gotapdance/tapdance/conjure.go

@@ -50,7 +50,13 @@ func (r DecoyRegistrar) Register(cjSession *ConjureSession, ctx context.Context)
 	Logger().Debugf("%v Registering V4 and V6 via DecoyRegistrar", cjSession.IDString())
 	Logger().Debugf("%v Registering V4 and V6 via DecoyRegistrar", cjSession.IDString())
 
 
 	// Choose N (width) decoys from decoylist
 	// Choose N (width) decoys from decoylist
-	cjSession.RegDecoys = SelectDecoys(cjSession.Keys.SharedSecret, cjSession.V6Support.include, cjSession.Width)
+	decoys, err := SelectDecoys(cjSession.Keys.SharedSecret, cjSession.V6Support.include, cjSession.Width)
+	if err != nil {
+		Logger().Warnf("%v failed to select decoys: %v", cjSession.IDString(), err)
+		return nil, err
+	}
+	cjSession.RegDecoys = decoys
+
 	phantom4, phantom6, err := SelectPhantom(cjSession.Keys.ConjureSeed, cjSession.V6Support.include)
 	phantom4, phantom6, err := SelectPhantom(cjSession.Keys.ConjureSeed, cjSession.V6Support.include)
 	if err != nil {
 	if err != nil {
 		Logger().Warnf("%v failed to select Phantom: %v", cjSession.IDString(), err)
 		Logger().Warnf("%v failed to select Phantom: %v", cjSession.IDString(), err)
@@ -898,7 +904,7 @@ func rttInt(millis uint32) int {
 }
 }
 
 
 // SelectDecoys - Get an array of `width` decoys to be used for registration
 // SelectDecoys - Get an array of `width` decoys to be used for registration
-func SelectDecoys(sharedSecret []byte, version uint, width uint) []*pb.TLSDecoySpec {
+func SelectDecoys(sharedSecret []byte, version uint, width uint) ([]*pb.TLSDecoySpec, error) {
 
 
 	//[reference] prune to v6 only decoys if useV6 is true
 	//[reference] prune to v6 only decoys if useV6 is true
 	var allDecoys []*pb.TLSDecoySpec
 	var allDecoys []*pb.TLSDecoySpec
@@ -913,6 +919,10 @@ func SelectDecoys(sharedSecret []byte, version uint, width uint) []*pb.TLSDecoyS
 		allDecoys = Assets().GetAllDecoys()
 		allDecoys = Assets().GetAllDecoys()
 	}
 	}
 
 
+	if len(allDecoys) == 0 {
+		return nil, fmt.Errorf("no decoys")
+	}
+
 	decoys := make([]*pb.TLSDecoySpec, width)
 	decoys := make([]*pb.TLSDecoySpec, width)
 	numDecoys := big.NewInt(int64(len(allDecoys)))
 	numDecoys := big.NewInt(int64(len(allDecoys)))
 	hmacInt := new(big.Int)
 	hmacInt := new(big.Int)
@@ -928,7 +938,7 @@ func SelectDecoys(sharedSecret []byte, version uint, width uint) []*pb.TLSDecoyS
 		idx.Mod(hmacInt, numDecoys)
 		idx.Mod(hmacInt, numDecoys)
 		decoys[i] = allDecoys[int(idx.Int64())]
 		decoys[i] = allDecoys[int(idx.Int64())]
 	}
 	}
-	return decoys
+	return decoys, nil
 }
 }
 
 
 // var phantomSubnets = []conjurePhantomSubnet{
 // var phantomSubnets = []conjurePhantomSubnet{