mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:24:03 +03:00
Return back timeoutrwc
This commit is contained in:
+3
-4
@@ -13,9 +13,7 @@ import (
|
|||||||
"github.com/9seconds/mtg/wrappers"
|
"github.com/9seconds/mtg/wrappers"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const handshakeTimeout = 10 * time.Second
|
||||||
handshakeTimeout = 10 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
// DirectInit initializes client to access Telegram bypassing middleproxies.
|
// DirectInit initializes client to access Telegram bypassing middleproxies.
|
||||||
func DirectInit(conn net.Conn, conf *config.Config) (*mtproto.ConnectionOpts, io.ReadWriteCloser, error) {
|
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
|
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
|
return connOpts, socket, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ const (
|
|||||||
BufferReadSize = 32 * 1024
|
BufferReadSize = 32 * 1024
|
||||||
BufferSizeCopy = 32 * 1024
|
BufferSizeCopy = 32 * 1024
|
||||||
|
|
||||||
|
TimeoutRead = time.Minute
|
||||||
|
TimeoutWrite = time.Minute
|
||||||
|
|
||||||
keepAlivePeriod = 20 * time.Second
|
keepAlivePeriod = 20 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -8,11 +8,10 @@ import (
|
|||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/config"
|
"github.com/9seconds/mtg/config"
|
||||||
|
"github.com/9seconds/mtg/wrappers"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const telegramDialTimeout = 10 * time.Second
|
||||||
telegramDialTimeout = 10 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
type tgDialer struct {
|
type tgDialer struct {
|
||||||
net.Dialer
|
net.Dialer
|
||||||
@@ -36,5 +35,5 @@ func (t *tgDialer) dialRWC(addr string) (io.ReadWriteCloser, error) {
|
|||||||
return nil, err
|
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