Rework for simplier proxy

This commit is contained in:
9seconds
2018-07-08 08:04:29 +03:00
parent cd63483503
commit a0ba89b105
12 changed files with 154 additions and 195 deletions
+12
View File
@@ -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
View File
@@ -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
View File
@@ -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