mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
try fix
This commit is contained in:
parent
267056b3fd
commit
558d9133a6
2 changed files with 8 additions and 9 deletions
|
@ -12,23 +12,22 @@ import (
|
||||||
|
|
||||||
// Comm is some basic TCP communication
|
// Comm is some basic TCP communication
|
||||||
type Comm struct {
|
type Comm struct {
|
||||||
connection net.Conn
|
connection *net.TCPConn
|
||||||
writer *bufio.Writer
|
writer *bufio.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new comm
|
// New returns a new comm
|
||||||
func New(n net.Conn) *Comm {
|
func New(n *net.TCPConn) *Comm {
|
||||||
c := new(Comm)
|
c := new(Comm)
|
||||||
c.connection = n
|
c.connection = n
|
||||||
c.connection.SetReadDeadline(time.Now().Add(3 * time.Hour))
|
c.connection.SetReadDeadline(time.Now().Add(3 * time.Hour))
|
||||||
c.connection.SetDeadline(time.Now().Add(3 * time.Hour))
|
c.connection.SetDeadline(time.Now().Add(3 * time.Hour))
|
||||||
c.connection.SetWriteDeadline(time.Now().Add(3 * time.Hour))
|
c.connection.SetWriteDeadline(time.Now().Add(3 * time.Hour))
|
||||||
c.writer = bufio.NewWriter(n)
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection returns the net.Conn connection
|
// Connection returns the net.TCPConn connection
|
||||||
func (c *Comm) Connection() net.Conn {
|
func (c *Comm) Connection() *net.TCPConn {
|
||||||
return c.connection
|
return c.connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,12 +52,12 @@ func run(port string) (err error) {
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
// spawn a new goroutine whenever a client connects
|
// spawn a new goroutine whenever a client connects
|
||||||
for {
|
for {
|
||||||
connection, err := server.Accept()
|
connection, err := server.AcceptTCP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "problem accepting connection")
|
return errors.Wrap(err, "problem accepting connection")
|
||||||
}
|
}
|
||||||
log.Debugf("client %s connected", connection.RemoteAddr().String())
|
log.Debugf("client %s connected", connection.RemoteAddr().String())
|
||||||
go func(port string, connection net.Conn) {
|
go func(port string, connection *net.TCPConn) {
|
||||||
errCommunication := clientCommuncation(port, comm.New(connection))
|
errCommunication := clientCommuncation(port, comm.New(connection))
|
||||||
if errCommunication != nil {
|
if errCommunication != nil {
|
||||||
log.Warnf("relay-%s: %s", connection.RemoteAddr().String(), errCommunication.Error())
|
log.Warnf("relay-%s: %s", connection.RemoteAddr().String(), errCommunication.Error())
|
||||||
|
@ -126,7 +126,7 @@ func clientCommuncation(port string, c *comm.Comm) (err error) {
|
||||||
|
|
||||||
// chanFromConn creates a channel from a Conn object, and sends everything it
|
// chanFromConn creates a channel from a Conn object, and sends everything it
|
||||||
// Read()s from the socket to the channel.
|
// Read()s from the socket to the channel.
|
||||||
func chanFromConn(conn net.Conn) chan []byte {
|
func chanFromConn(conn *net.TCPConn) chan []byte {
|
||||||
c := make(chan []byte)
|
c := make(chan []byte)
|
||||||
// reader := bufio.NewReader(conn)
|
// reader := bufio.NewReader(conn)
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ func chanFromConn(conn net.Conn) chan []byte {
|
||||||
|
|
||||||
// pipe creates a full-duplex pipe between the two sockets and
|
// pipe creates a full-duplex pipe between the two sockets and
|
||||||
// transfers data from one to the other.
|
// transfers data from one to the other.
|
||||||
func pipe(conn1 net.Conn, conn2 net.Conn) {
|
func pipe(conn1 *net.TCPConn, conn2 *net.TCPConn) {
|
||||||
chan1 := chanFromConn(conn1)
|
chan1 := chanFromConn(conn1)
|
||||||
// chan2 := chanFromConn(conn2)
|
// chan2 := chanFromConn(conn2)
|
||||||
// writer1 := bufio.NewWriter(conn1)
|
// writer1 := bufio.NewWriter(conn1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue