mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:14:02 +03:00
Propagate connection protocol
This commit is contained in:
+1
-1
@@ -41,7 +41,7 @@ func (t *directTelegram) Dial(connOpts *mtproto.ConnectionOpts) (io.ReadWriteClo
|
||||
dc = 1
|
||||
}
|
||||
|
||||
return t.baseTelegram.dial(dc - 1)
|
||||
return t.baseTelegram.dial(dc-1, connOpts.ConnectionProto)
|
||||
}
|
||||
|
||||
func (t *directTelegram) Init(connOpts *mtproto.ConnectionOpts, conn io.ReadWriteCloser) (io.ReadWriteCloser, error) {
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ type middleTelegram struct {
|
||||
middleTelegramCaller
|
||||
}
|
||||
|
||||
func NewMiddleTelegram(conf *config.Config, logger *zap.SugaredLogger) Telegram {
|
||||
func NewMiddleTelegram(conf *config.Config, logger *zap.SugaredLogger) *middleTelegram {
|
||||
tg := &middleTelegram{
|
||||
middleTelegramCaller: middleTelegramCaller{
|
||||
baseTelegram: baseTelegram{
|
||||
|
||||
@@ -47,7 +47,7 @@ func (t *middleTelegramCaller) Dial(connOpts *mtproto.ConnectionOpts) (io.ReadWr
|
||||
t.dialerMutex.RLock()
|
||||
defer t.dialerMutex.RUnlock()
|
||||
|
||||
return t.baseTelegram.dial(dc)
|
||||
return t.baseTelegram.dial(dc, connOpts.ConnectionProto)
|
||||
}
|
||||
|
||||
func (t *middleTelegramCaller) autoUpdate() {
|
||||
|
||||
+10
-5
@@ -24,13 +24,18 @@ type baseTelegram struct {
|
||||
v6Addresses map[int16][]string
|
||||
}
|
||||
|
||||
func (b *baseTelegram) dial(dcIdx int16) (io.ReadWriteCloser, error) {
|
||||
func (b *baseTelegram) dial(dcIdx int16, proto mtproto.ConnectionProtocol) (io.ReadWriteCloser, error) {
|
||||
addrs := make([]string, 2)
|
||||
if addr, ok := b.v6Addresses[dcIdx]; ok && len(addr) > 0 {
|
||||
addrs = append(addrs, addr[rand.Intn(len(addr))])
|
||||
|
||||
if proto&mtproto.ConnectionProtocolIPv6 != 0 {
|
||||
if addr, ok := b.v6Addresses[dcIdx]; ok && len(addr) > 0 {
|
||||
addrs = append(addrs, addr[rand.Intn(len(addr))])
|
||||
}
|
||||
}
|
||||
if addr, ok := b.v4Addresses[dcIdx]; ok && len(addr) > 0 {
|
||||
addrs = append(addrs, addr[rand.Intn(len(addr))])
|
||||
if proto&mtproto.ConnectionProtocolIPv4 != 0 {
|
||||
if addr, ok := b.v4Addresses[dcIdx]; ok && len(addr) > 0 {
|
||||
addrs = append(addrs, addr[rand.Intn(len(addr))])
|
||||
}
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
|
||||
Reference in New Issue
Block a user