Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

addr_set.go 557B

123456789101112131415161718192021222324252627282930313233
  1. package dc
  2. import "math/rand/v2"
  3. type dcAddrSet struct {
  4. v4 map[int][]Addr
  5. v6 map[int][]Addr
  6. }
  7. func (d dcAddrSet) getV4(dc int) []Addr {
  8. if d.v4 == nil {
  9. return nil
  10. }
  11. return d.get(d.v4[dc])
  12. }
  13. func (d dcAddrSet) getV6(dc int) []Addr {
  14. if d.v6 == nil {
  15. return nil
  16. }
  17. return d.get(d.v6[dc])
  18. }
  19. func (d dcAddrSet) get(addrs []Addr) []Addr {
  20. otherSet := make([]Addr, 0, len(addrs))
  21. otherSet = append(otherSet, addrs...)
  22. rand.Shuffle(len(otherSet), func(i, j int) {
  23. otherSet[i], otherSet[j] = otherSet[j], otherSet[i]
  24. })
  25. return otherSet
  26. }