FILE / ScuroNeko/mtg

client/middle.go

Исходный файл и его история в репозитории.
FILE a3933e6ede78eb40ea347b699b7a7637d7bca18d
Files
mtg/client/middle.go
T
2018-07-06 17:29:24 +03:00

31 lines
816 B
Go

package client
import (
"net"
"github.com/9seconds/mtg/config"
"github.com/9seconds/mtg/mtproto"
mtwrappers "github.com/9seconds/mtg/mtproto/wrappers"
"github.com/9seconds/mtg/wrappers"
)
func MiddleInit(conn net.Conn, socketID string, conf *config.Config) (wrappers.ReadWriteCloserWithAddr, *mtproto.ConnectionOpts, error) {
newConn, opts, err := DirectInit(conn, socketID, conf)
if err != nil {
return nil, nil, err
}
if opts.ConnectionType == mtproto.ConnectionTypeAbridged {
newConn = mtwrappers.NewAbridgedRWC(newConn, opts)
} else {
newConn = mtwrappers.NewIntermediateRWC(newConn, opts)
}
opts.ConnectionProto = mtproto.ConnectionProtocolIPv4
if conn.LocalAddr().(*net.TCPAddr).IP.To4() == nil {
opts.ConnectionProto = mtproto.ConnectionProtocolIPv6
}
return newConn, opts, nil
}