Skip to content

Commit

Permalink
little change in dc selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
geovex committed Aug 21, 2024
1 parent f6fa410 commit bf32281
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/network_exchange/dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/geovex/tgp/internal/maplist"
"github.com/geovex/tgp/internal/tgcrypt_encryption"
"golang.org/x/exp/rand"

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.21, 0)

no required module provides package golang.org/x/exp/rand; to add it:

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.21, 1)

no required module provides package golang.org/x/exp/rand; to add it:

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22, 0)

no required module provides package golang.org/x/exp/rand; to add it:

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22, 1)

no required module provides package golang.org/x/exp/rand; to add it:

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (windows-latest, 1.21, 0)

no required module provides package golang.org/x/exp/rand; to add it:

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (windows-latest, 1.21, 1)

no required module provides package golang.org/x/exp/rand; to add it:

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (windows-latest, 1.22, 0)

no required module provides package golang.org/x/exp/rand; to add it:

Check failure on line 10 in internal/network_exchange/dc.go

View workflow job for this annotation

GitHub Actions / build (windows-latest, 1.22, 1)

no required module provides package golang.org/x/exp/rand; to add it:
"golang.org/x/net/proxy"
)

Expand Down Expand Up @@ -37,11 +38,14 @@ func getDcAddr(dc int16) (ipv4, ipv6 string, err error) {
dc = -dc
}
if dc < 1 || dc > dcMaxIdx {
return "", "", fmt.Errorf("invalid dc number %d", dc)
//return "", "", fmt.Errorf("invalid dc number %d", dc)
//instead return random dc
dc = rand.Intn(dcMaxIdx) + 1
}
ipv4, _ = dc_ip4.GetRandom(dc)
ipv6, _ = dc_ip6.GetRandom(dc)
if ipv4 == "" && ipv6 == "" {
// TODO may be panic here?
return "", "", fmt.Errorf("invalid dc number %d", dc)
}
return ipv4, ipv6, nil
Expand All @@ -60,6 +64,8 @@ type DcDirectConnector struct {
allowIPv6 bool
}

var _ DCConnector = &DcDirectConnector{}

// creates a new DcDirectConnector
func NewDcDirectConnector(allowIPv6 bool) *DcDirectConnector {
return &DcDirectConnector{
Expand Down Expand Up @@ -101,6 +107,8 @@ type DcSocksConnector struct {
socks5 string
}

var _ DCConnector = &DcSocksConnector{}

// Create a new DcSocksConnector
func NewDcSocksConnector(allowIPv6 bool, socks5 string, user, pass *string) *DcSocksConnector {
return &DcSocksConnector{
Expand Down Expand Up @@ -201,10 +209,12 @@ func setNoDelay(c net.Conn) {
}
}

// do not reobfuscate connection to dc (there are really no need for it)
func LoginDC(sock io.ReadWriteCloser, protocol uint8) *rawStream {
return newRawStream(sock, protocol)
}

// in case you need to obfuscate connection to dc, you can do it
func ObfuscateDC(sock io.ReadWriteCloser, ctx *tgcrypt_encryption.DcCtx) *obfuscatedStream {
// TODO: handle negative dc
return newObfuscatedStream(sock, ctx, &ctx.Nonce, ctx.Protocol)
Expand Down

0 comments on commit bf32281

Please sign in to comment.