mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:54:03 +03:00
Rework for simplier proxy
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/9seconds/mtg/config"
|
||||
"github.com/9seconds/mtg/mtproto"
|
||||
"github.com/9seconds/mtg/wrappers"
|
||||
)
|
||||
|
||||
type Init func(context.Context, context.CancelFunc, net.Conn, string, *config.Config) (wrappers.Wrap, *mtproto.ConnectionOpts, error)
|
||||
+1
-1
@@ -16,7 +16,7 @@ import (
|
||||
const handshakeTimeout = 10 * time.Second
|
||||
|
||||
func DirectInit(ctx context.Context, cancel context.CancelFunc, socket net.Conn, connID string,
|
||||
conf *config.Config) (wrappers.WrapStreamReadWriteCloser, *mtproto.ConnectionOpts, error) {
|
||||
conf *config.Config) (wrappers.Wrap, *mtproto.ConnectionOpts, error) {
|
||||
if err := config.SetSocketOptions(socket); err != nil {
|
||||
return nil, nil, errors.Annotate(err, "Cannot set socket options")
|
||||
}
|
||||
|
||||
+4
-3
@@ -10,15 +10,16 @@ import (
|
||||
)
|
||||
|
||||
func MiddleInit(ctx context.Context, cancel context.CancelFunc, socket net.Conn, connID string,
|
||||
conf *config.Config) (wrappers.WrapPacketReadWriteCloser, *mtproto.ConnectionOpts, error) {
|
||||
conf *config.Config) (wrappers.Wrap, *mtproto.ConnectionOpts, error) {
|
||||
conn, opts, err := DirectInit(ctx, cancel, socket, connID, conf)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
connStream := conn.(wrappers.WrapStreamReadWriteCloser)
|
||||
|
||||
newConn := wrappers.NewMTProtoAbridged(conn, opts)
|
||||
newConn := wrappers.NewMTProtoAbridged(connStream, opts)
|
||||
if opts.ConnectionType != mtproto.ConnectionTypeAbridged {
|
||||
newConn = wrappers.NewMTProtoIntermediate(conn, opts)
|
||||
newConn = wrappers.NewMTProtoIntermediate(connStream, opts)
|
||||
}
|
||||
|
||||
opts.ConnectionProto = mtproto.ConnectionProtocolIPv4
|
||||
|
||||
Reference in New Issue
Block a user