mirror of https://github.com/cbeuw/Cloak
Move pipe to util
This commit is contained in:
parent
bf83273f6e
commit
f933c7b453
|
|
@ -23,27 +23,6 @@ import (
|
||||||
|
|
||||||
var version string
|
var version string
|
||||||
|
|
||||||
func pipe(dst io.ReadWriteCloser, src io.ReadWriteCloser) {
|
|
||||||
// The maximum size of TLS message will be 16380+12+16. 12 because of the stream header and 16
|
|
||||||
// because of the salt/mac
|
|
||||||
// 16408 is the max TLS message size on Firefox
|
|
||||||
buf := make([]byte, 16380)
|
|
||||||
for {
|
|
||||||
i, err := io.ReadAtLeast(src, buf, 1)
|
|
||||||
if err != nil {
|
|
||||||
go dst.Close()
|
|
||||||
go src.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
i, err = dst.Write(buf[:i])
|
|
||||||
if err != nil {
|
|
||||||
go dst.Close()
|
|
||||||
go src.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This establishes a connection with ckserver and performs a handshake
|
// This establishes a connection with ckserver and performs a handshake
|
||||||
func makeRemoteConn(sta *client.State) (net.Conn, []byte, error) {
|
func makeRemoteConn(sta *client.State) (net.Conn, []byte, error) {
|
||||||
|
|
||||||
|
|
@ -253,8 +232,8 @@ func main() {
|
||||||
stream.Close()
|
stream.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go pipe(localConn, stream)
|
go util.Pipe(localConn, stream)
|
||||||
pipe(stream, localConn)
|
util.Pipe(stream, localConn)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,27 +24,6 @@ import (
|
||||||
var b64 = base64.StdEncoding.EncodeToString
|
var b64 = base64.StdEncoding.EncodeToString
|
||||||
var version string
|
var version string
|
||||||
|
|
||||||
func pipe(dst io.ReadWriteCloser, src io.ReadWriteCloser) {
|
|
||||||
// The maximum size of TLS message will be 16380+12+16. 12 because of the stream header and 16
|
|
||||||
// because of the salt/mac
|
|
||||||
// 16408 is the max TLS message size on Firefox
|
|
||||||
buf := make([]byte, 16380)
|
|
||||||
for {
|
|
||||||
i, err := io.ReadAtLeast(src, buf, 1)
|
|
||||||
if err != nil {
|
|
||||||
go dst.Close()
|
|
||||||
go src.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
i, err = dst.Write(buf[:i])
|
|
||||||
if err != nil {
|
|
||||||
go dst.Close()
|
|
||||||
go src.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func dispatchConnection(conn net.Conn, sta *server.State) {
|
func dispatchConnection(conn net.Conn, sta *server.State) {
|
||||||
remoteAddr := conn.RemoteAddr()
|
remoteAddr := conn.RemoteAddr()
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -73,8 +52,8 @@ func dispatchConnection(conn net.Conn, sta *server.State) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to send first packet to redirection server", err)
|
log.Error("Failed to send first packet to redirection server", err)
|
||||||
}
|
}
|
||||||
go pipe(webConn, conn)
|
go util.Pipe(webConn, conn)
|
||||||
go pipe(conn, webConn)
|
go util.Pipe(conn, webConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
ch, err := server.ParseClientHello(data)
|
ch, err := server.ParseClientHello(data)
|
||||||
|
|
@ -197,8 +176,8 @@ func dispatchConnection(conn net.Conn, sta *server.State) {
|
||||||
sesh.Close()
|
sesh.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go pipe(localConn, newStream)
|
go util.Pipe(localConn, newStream)
|
||||||
go pipe(newStream, localConn)
|
go util.Pipe(newStream, localConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,3 +124,24 @@ func AddRecordLayer(input []byte, typ []byte, ver []byte) []byte {
|
||||||
copy(ret[5:], input)
|
copy(ret[5:], input)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Pipe(dst io.ReadWriteCloser, src io.ReadWriteCloser) {
|
||||||
|
// The maximum size of TLS message will be 16380+12+16. 12 because of the stream header and 16
|
||||||
|
// because of the salt/mac
|
||||||
|
// 16408 is the max TLS message size on Firefox
|
||||||
|
buf := make([]byte, 16380)
|
||||||
|
for {
|
||||||
|
i, err := io.ReadAtLeast(src, buf, 1)
|
||||||
|
if err != nil {
|
||||||
|
go dst.Close()
|
||||||
|
go src.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
i, err = dst.Write(buf[:i])
|
||||||
|
if err != nil {
|
||||||
|
go dst.Close()
|
||||||
|
go src.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue