Verified Commit ca4b054a authored by meskio's avatar meskio 🏔️
Browse files

Telegram distributor hands both new and old bridges to old accounts

After the transition from bridgedb to rdsys many 'telegram' bridges (old
bridges) are comming from 'moat' or other distributors that could be blocked in
certain locations. For old telegram accounts let's distribute bridges from both
pools the dynamic 'new' bridges and the bridge authority 'old' bridges.

Closes: #101
parent d1084403
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -41,13 +41,6 @@ type TelegramDistributor struct {
}

func (d *TelegramDistributor) GetResources(id int64) []core.Resource {
	hashring := d.oldHashring
	pool := "old"
	if d.cfg.MinUserID != 0 && id > d.cfg.MinUserID {
		hashring = d.newHashring
		pool = "new"
	}

	now := time.Now().Unix() / (60 * 60)
	period := now / int64(d.cfg.RotationPeriodHours)
	hashKey := core.NewHashkey(fmt.Sprintf("%d-%d", id, period))
@@ -58,13 +51,24 @@ func (d *TelegramDistributor) GetResources(id int64) []core.Resource {
	}
	d.requestHashKeys[hashKey] = time.Now()

	resources, err := hashring.GetMany(hashKey, d.cfg.NumBridgesPerRequest)
	resources, err := d.newHashring.GetMany(hashKey, d.cfg.NumBridgesPerRequest)
	if err != nil {
		log.Println("Error getting resources from the hashring:", err)
		status = "error"
	}

	d.bridgeRequestsCount.WithLabelValues(pool, status).Inc()
	pool := "new"
	if id >= d.cfg.MinUserID {
		pool = "old"
		oldResources, err := d.oldHashring.GetMany(hashKey, d.cfg.NumBridgesPerRequest)
		if err != nil {
			log.Println("Error getting resources from the old hashring:", err)
			status = "error"
		}
		resources = append(oldResources, resources...)
	}

	bridgeRequestsCount.WithLabelValues(pool, status).Inc()
	return resources
}