package transport
import (
"bytes"
"io"
"net"
"github.com/go-faster/errors"
"go.uber.org/multierr"
"github.com/gotd/td/internal/mtproxy/obfuscated2"
"github.com/gotd/td/internal/proto/codec"
)
type obfListener struct {
listener net .Listener
}
type obfConn struct {
reader io .Reader
writer io .Writer
net .Conn
}
func (c *obfConn ) Read (p []byte ) (int , error ) {
return c .reader .Read (p )
}
func (c *obfConn ) Write (p []byte ) (int , error ) {
return c .writer .Write (p )
}
func ObfuscatedListener (listener net .Listener ) net .Listener {
return obfListener {listener : listener }
}
func (l obfListener ) Accept () (_ net .Conn , err error ) {
conn , err := l .listener .Accept ()
if err != nil {
return nil , err
}
defer func () {
if err != nil {
multierr .AppendInto (&err , conn .Close ())
}
}()
rw , md , err := obfuscated2 .Accept (conn , nil )
if err != nil {
return nil , errors .Wrap (err , "accept" )
}
var tag *bytes .Reader
if md .Protocol [0 ] == codec .AbridgedClientStart [0 ] {
tag = bytes .NewReader (md .Protocol [:1 ])
} else {
tag = bytes .NewReader (md .Protocol [:])
}
accepted := &obfConn {
reader : io .MultiReader (tag , rw ),
writer : rw ,
Conn : conn ,
}
return accepted , nil
}
func (l obfListener ) Close () error {
return l .listener .Close ()
}
func (l obfListener ) Addr () net .Addr {
return l .listener .Addr ()
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .