mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:34:01 +03:00
Return back timeoutrwc
This commit is contained in:
+3
-4
@@ -13,9 +13,7 @@ import (
|
||||
"github.com/9seconds/mtg/wrappers"
|
||||
)
|
||||
|
||||
const (
|
||||
handshakeTimeout = 10 * time.Second
|
||||
)
|
||||
const handshakeTimeout = 10 * time.Second
|
||||
|
||||
// DirectInit initializes client to access Telegram bypassing middleproxies.
|
||||
func DirectInit(conn net.Conn, conf *config.Config) (*mtproto.ConnectionOpts, io.ReadWriteCloser, error) {
|
||||
@@ -36,7 +34,8 @@ func DirectInit(conn net.Conn, conf *config.Config) (*mtproto.ConnectionOpts, io
|
||||
}
|
||||
connOpts.ConnectionProto = mtproto.ConnectionProtocolAny
|
||||
|
||||
socket := wrappers.NewStreamCipherRWC(conn, obfs2.Encryptor, obfs2.Decryptor)
|
||||
socket := wrappers.NewTimeoutRWC(conn)
|
||||
socket = wrappers.NewStreamCipherRWC(socket, obfs2.Encryptor, obfs2.Decryptor)
|
||||
|
||||
return connOpts, socket, nil
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ const (
|
||||
BufferReadSize = 32 * 1024
|
||||
BufferSizeCopy = 32 * 1024
|
||||
|
||||
TimeoutRead = time.Minute
|
||||
TimeoutWrite = time.Minute
|
||||
|
||||
keepAlivePeriod = 20 * time.Second
|
||||
)
|
||||
|
||||
|
||||
+3
-4
@@ -8,11 +8,10 @@ import (
|
||||
"github.com/juju/errors"
|
||||
|
||||
"github.com/9seconds/mtg/config"
|
||||
"github.com/9seconds/mtg/wrappers"
|
||||
)
|
||||
|
||||
const (
|
||||
telegramDialTimeout = 10 * time.Second
|
||||
)
|
||||
const telegramDialTimeout = 10 * time.Second
|
||||
|
||||
type tgDialer struct {
|
||||
net.Dialer
|
||||
@@ -36,5 +35,5 @@ func (t *tgDialer) dialRWC(addr string) (io.ReadWriteCloser, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return conn, nil
|
||||
return wrappers.NewTimeoutRWC(conn), nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package wrappers
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/9seconds/mtg/config"
|
||||
)
|
||||
|
||||
type TimeoutReadWriteCloser struct {
|
||||
conn net.Conn
|
||||
}
|
||||
|
||||
func (t *TimeoutReadWriteCloser) Read(p []byte) (int, error) {
|
||||
t.conn.SetReadDeadline(time.Now().Add(config.TimeoutRead))
|
||||
return t.conn.Read(p)
|
||||
}
|
||||
|
||||
func (t *TimeoutReadWriteCloser) Write(p []byte) (int, error) {
|
||||
t.conn.SetWriteDeadline(time.Now().Add(config.TimeoutWrite))
|
||||
return t.conn.Write(p)
|
||||
}
|
||||
|
||||
func (t *TimeoutReadWriteCloser) Close() error {
|
||||
return t.conn.Close()
|
||||
}
|
||||
|
||||
func NewTimeoutRWC(conn net.Conn) io.ReadWriteCloser {
|
||||
return &TimeoutReadWriteCloser{conn}
|
||||
}
|
||||
Reference in New Issue
Block a user