This repository has been archived on 2024-07-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
go-playit/tunnel/tcp_tunnel.go
Matheus Sampaio Queiroga a3c4994e66 Common
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2024-05-21 23:11:16 -03:00

25 lines
683 B
Go

package tunnel
import "net"
type TcpTunnel struct {
ClaimInstructions ClaimInstructions
}
func (tcp *TcpTunnel) Connect() (*net.TCPConn, error) {
stream, err := net.DialTCP("tcp", nil, net.TCPAddrFromAddrPort(tcp.ClaimInstructions.Address.AddrPort))
if err != nil {
LogDebug.Printf("%q: Failed to establish connection to tunnel server\n", tcp.ClaimInstructions.Address.AddrPort.String())
return nil, err
}
if _, err := stream.Write(tcp.ClaimInstructions.Token); err != nil {
stream.Close()
return nil, err
}
res := make([]byte, 8)
if _, err := stream.Read(res); err != nil {
stream.Close()
return nil, err
}
LogDebug.Printf("%+v\n", res)
return stream, nil
}