WIP: Update struct decode and encode #2
346
client/client.go
346
client/client.go
@ -1,7 +1,6 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -9,70 +8,16 @@ import (
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/internal/pipe"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/internal/structcode"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/proto"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/internal/pipe"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/internal/structcode"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/proto"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCannotConnect error = errors.New("cannot connect to controller")
|
||||
ErrUnathorized error = errors.New("cannot auth in controller")
|
||||
)
|
||||
var ErrUnauthorized error = errors.New("cannot auth to controller")
|
||||
|
||||
type NewClient struct {
|
||||
type remoteClient struct {
|
||||
Client proto.Client
|
||||
Writer net.Conn
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
Token []byte
|
||||
RemoteAdress netip.AddrPort
|
||||
clientsTCP map[string]net.Conn
|
||||
clientsUDP map[string]net.Conn
|
||||
NewClient chan NewClient
|
||||
|
||||
Conn net.Conn
|
||||
AgentInfo *proto.AgentInfo
|
||||
}
|
||||
|
||||
func CreateClient(Addres netip.AddrPort, Token []byte) (*Client, error) {
|
||||
cli := &Client{
|
||||
Token: Token,
|
||||
RemoteAdress: Addres,
|
||||
clientsTCP: make(map[string]net.Conn),
|
||||
clientsUDP: make(map[string]net.Conn),
|
||||
NewClient: make(chan NewClient),
|
||||
}
|
||||
if err := cli.Setup(); err != nil {
|
||||
return cli, err
|
||||
}
|
||||
return cli, nil
|
||||
}
|
||||
|
||||
func (client *Client) Setup() error {
|
||||
var err error
|
||||
if client.Conn, err = net.DialTCP("tcp", nil, net.TCPAddrFromAddrPort(client.RemoteAdress)); err != nil {
|
||||
return err
|
||||
}
|
||||
for attemps := 0; attemps < 18; attemps++ {
|
||||
if err := structcode.NewEncode(client.Conn, proto.Request{AgentAuth: &client.Token}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var res proto.Response
|
||||
if err = structcode.NewDecode(client.Conn, &res); err != nil {
|
||||
return fmt.Errorf("decode status from server, error: %s", err.Error())
|
||||
} else if res.Unauthorized {
|
||||
return ErrUnathorized
|
||||
} else if res.AgentInfo == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
client.AgentInfo = res.AgentInfo
|
||||
go client.handlers()
|
||||
return nil
|
||||
}
|
||||
return ErrCannotConnect
|
||||
Conn net.Conn
|
||||
}
|
||||
|
||||
type toWr struct {
|
||||
@ -91,113 +36,218 @@ func (t toWr) Write(w []byte) (int, error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
d, _ := json.Marshal(data)
|
||||
fmt.Println(string(d))
|
||||
if err := structcode.NewEncode(t.tun.Conn, data); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return len(w), nil
|
||||
}
|
||||
|
||||
func (tun *Client) GetTargetWrite(Proto proto.Protoc, To netip.AddrPort) io.Writer {
|
||||
return &toWr{Proto: Proto, To: To, tun: tun}
|
||||
type Client struct {
|
||||
Token []byte // Token to auth in Controller if required
|
||||
Conn net.Conn // Connection from Controller
|
||||
Agent *proto.AgentInfo // Agent info to show in UI and listened on controller
|
||||
TCPConns map[string]*net.TCPConn // Clients connections to TCP
|
||||
UDPConns map[string]*net.UDPConn // Clients connections to UDP
|
||||
LastPong time.Time // Last Pong time
|
||||
Latency int64 // Latency response in ms from last Pong
|
||||
|
||||
newListen chan remoteClient // new clients listener in Controller
|
||||
cachErr chan error // Pipe errors to channel
|
||||
closedErr bool
|
||||
}
|
||||
|
||||
func (client *Client) handlers() {
|
||||
var lastPing time.Time = time.Date(0, 0, 0, 0, 0, 0, 0, time.Local)
|
||||
func NewClient(Address string, AuthToken []byte) (*Client, error) {
|
||||
var clientStr Client
|
||||
var err error
|
||||
|
||||
// Dial connection
|
||||
if clientStr.Conn, err = net.Dial("tcp", Address); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res proto.Response
|
||||
if err := structcode.NewEncode(clientStr.Conn, proto.Request{Ping: proto.Point(time.Now())}); err != nil {
|
||||
return nil, err
|
||||
} else if err := structcode.NewDecode(clientStr.Conn, &res); err != nil {
|
||||
return nil, err
|
||||
} else if res.SendAuth && len(AuthToken) == 0 {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
// Auth Session
|
||||
if clientStr.Token = AuthToken; len(clientStr.Token) > 0 {
|
||||
if err := clientStr.Auth(); err != nil {
|
||||
clientStr.Conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
clientStr.cachErr = make(chan error)
|
||||
clientStr.newListen = make(chan remoteClient)
|
||||
clientStr.TCPConns = make(map[string]*net.TCPConn)
|
||||
clientStr.UDPConns = make(map[string]*net.UDPConn)
|
||||
go clientStr.handle() // Process requests
|
||||
return &clientStr, nil
|
||||
}
|
||||
|
||||
// Wait for any error, if catch error close connection and return error
|
||||
func (client *Client) WaitCloseError() error {
|
||||
if err, ok := <-client.cachErr; ok {
|
||||
if err != nil && client.Conn != nil {
|
||||
client.Close()
|
||||
}
|
||||
return err
|
||||
}
|
||||
return io.EOF
|
||||
}
|
||||
|
||||
// Wait for any error
|
||||
func (client *Client) WaitError() error {
|
||||
if err, ok := <-client.cachErr; ok {
|
||||
return err
|
||||
} else if client.Conn == nil {
|
||||
return io.EOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close Clients and Controller connection
|
||||
func (client *Client) Close() error {
|
||||
for remoteClient := range client.TCPConns {
|
||||
d := client.TCPConns[remoteClient]
|
||||
if err := d.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for remoteClient := range client.UDPConns {
|
||||
d := client.UDPConns[remoteClient]
|
||||
if err := d.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if client.Conn != nil {
|
||||
if err := client.Conn.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
client.Conn = nil
|
||||
}
|
||||
client.closedErr = true
|
||||
close(client.cachErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (client *Client) sendErr(err error) {
|
||||
if client.closedErr {
|
||||
return
|
||||
}
|
||||
client.cachErr <- err
|
||||
}
|
||||
|
||||
// Send auth to controller
|
||||
func (client *Client) Auth() error {
|
||||
if err := structcode.NewEncode(client.Conn, proto.Request{AgentAuth: &client.Token}); err != nil {
|
||||
return err
|
||||
}
|
||||
var res proto.Response
|
||||
if err := structcode.NewDecode(client.Conn, &res); err != nil {
|
||||
return err
|
||||
} else if res.BadRequest || res.Unauthorized {
|
||||
return ErrUnauthorized
|
||||
} else if res.AgentInfo == nil {
|
||||
return fmt.Errorf("cannot get agent info")
|
||||
}
|
||||
|
||||
client.Agent = res.AgentInfo
|
||||
return nil
|
||||
}
|
||||
|
||||
// Process Controller responses
|
||||
func (client *Client) handle() {
|
||||
for {
|
||||
if time.Now().UnixMilli()-lastPing.UnixMilli() > 3_000_000 {
|
||||
var req proto.Request
|
||||
req.Ping = new(time.Time)
|
||||
*req.Ping = time.Now()
|
||||
go structcode.NewEncode(client.Conn, req)
|
||||
var res proto.Response
|
||||
if err := structcode.NewDecode(client.Conn, &res); err != nil {
|
||||
client.sendErr(err)
|
||||
return
|
||||
}
|
||||
|
||||
var res proto.Response
|
||||
err := structcode.NewDecode(client.Conn, &res)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
if err == proto.ErrInvalidBody {
|
||||
// Resend auth to Controller
|
||||
if res.SendAuth {
|
||||
if err := client.Auth(); err != nil {
|
||||
client.sendErr(err) // Send to handler
|
||||
return
|
||||
}
|
||||
continue
|
||||
} else if res.Unauthorized {
|
||||
client.sendErr(ErrUnauthorized) // Close connection
|
||||
return
|
||||
}
|
||||
|
||||
// Update current agent info
|
||||
if res.AgentInfo != nil {
|
||||
client.Agent = res.AgentInfo
|
||||
}
|
||||
|
||||
// Server pong time
|
||||
if res.Pong != nil {
|
||||
client.Latency = time.Now().UnixMilli() - res.Pong.UnixMilli()
|
||||
client.LastPong = *res.Pong
|
||||
}
|
||||
|
||||
// Write data to Client
|
||||
if data := res.DataRX; res.DataRX != nil {
|
||||
var ok bool
|
||||
var clientConn net.Conn
|
||||
clientAddr := res.DataRX.Client.Client.String()
|
||||
switch res.DataRX.Client.Proto {
|
||||
case proto.ProtoTCP:
|
||||
if clientConn, ok = client.TCPConns[clientAddr]; !ok {
|
||||
toClient, toAgent := pipe.CreatePipe(data.Client.Client, data.Client.Client)
|
||||
go io.Copy(&toWr{data.Client.Proto, data.Client.Client, client}, toAgent)
|
||||
client.newListen <- remoteClient{res.DataRX.Client, toClient}
|
||||
clientConn = client.TCPConns[clientAddr]
|
||||
}
|
||||
case proto.ProtoUDP:
|
||||
if clientConn, ok = client.UDPConns[clientAddr]; !ok {
|
||||
toClient, toAgent := pipe.CreatePipe(data.Client.Client, data.Client.Client)
|
||||
go io.Copy(&toWr{data.Client.Proto, data.Client.Client, client}, toAgent)
|
||||
client.newListen <- remoteClient{res.DataRX.Client, toClient}
|
||||
clientConn = client.UDPConns[clientAddr]
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if _, err := clientConn.Write(res.DataRX.Data); err != nil {
|
||||
client.sendErr(err)
|
||||
continue
|
||||
}
|
||||
panic(err) // TODO: Require fix to agent shutdown graced
|
||||
}
|
||||
|
||||
d, _ := json.Marshal(res)
|
||||
fmt.Println(string(d))
|
||||
|
||||
if res.Pong != nil {
|
||||
lastPing = *res.Pong
|
||||
continue
|
||||
}
|
||||
if res.Unauthorized || res.NotListened {
|
||||
panic(fmt.Errorf("cannot recive requests")) // TODO: Require fix to agent shutdown graced
|
||||
} else if res.SendAuth {
|
||||
var auth = client.Token
|
||||
for {
|
||||
structcode.NewEncode(client.Conn, proto.Request{AgentAuth: &auth})
|
||||
var res proto.Response
|
||||
if err = structcode.NewDecode(client.Conn, &res); err != nil {
|
||||
panic(err) // TODO: Require fix to agent shutdown graced
|
||||
} else if res.Unauthorized {
|
||||
return
|
||||
} else if res.AgentInfo == nil {
|
||||
continue
|
||||
}
|
||||
client.AgentInfo = res.AgentInfo
|
||||
break
|
||||
}
|
||||
} else if cl := res.CloseClient; res.CloseClient != nil {
|
||||
if cl.Proto == proto.ProtoTCP {
|
||||
if tun, ok := client.clientsTCP[cl.Client.String()]; ok {
|
||||
tun.Close()
|
||||
}
|
||||
} else if cl.Proto == proto.ProtoUDP {
|
||||
if tun, ok := client.clientsUDP[cl.Client.String()]; ok {
|
||||
tun.Close()
|
||||
}
|
||||
}
|
||||
} else if data := res.DataRX; res.DataRX != nil {
|
||||
if data.Client.Proto == proto.ProtoTCP {
|
||||
if _, ok := client.clientsTCP[data.Client.Client.String()]; !ok {
|
||||
toClient, toAgent := pipe.CreatePipe(net.TCPAddrFromAddrPort(data.Client.Client), net.TCPAddrFromAddrPort(data.Client.Client))
|
||||
client.NewClient <- NewClient{
|
||||
Client: data.Client,
|
||||
Writer: toClient,
|
||||
if res.CloseClient != nil {
|
||||
clientAddr := res.DataRX.Client.Client.String()
|
||||
switch res.DataRX.Client.Proto {
|
||||
case proto.ProtoTCP:
|
||||
if clientConn, ok := client.TCPConns[clientAddr]; ok {
|
||||
delete(client.TCPConns, clientAddr)
|
||||
if err := clientConn.Close(); err != nil {
|
||||
client.sendErr(err)
|
||||
}
|
||||
client.clientsTCP[data.Client.Client.String()] = toAgent
|
||||
go func() {
|
||||
io.Copy(client.GetTargetWrite(proto.ProtoTCP, data.Client.Client), toAgent)
|
||||
delete(client.clientsTCP, data.Client.Client.String())
|
||||
}()
|
||||
}
|
||||
} else if data.Client.Proto == proto.ProtoUDP {
|
||||
if _, ok := client.clientsUDP[data.Client.Client.String()]; !ok {
|
||||
toClient, toAgent := pipe.CreatePipe(net.UDPAddrFromAddrPort(data.Client.Client), net.UDPAddrFromAddrPort(data.Client.Client))
|
||||
client.NewClient <- NewClient{
|
||||
Client: data.Client,
|
||||
Writer: toClient,
|
||||
case proto.ProtoUDP:
|
||||
if clientConn, ok := client.UDPConns[clientAddr]; ok {
|
||||
delete(client.UDPConns, clientAddr)
|
||||
if err := clientConn.Close(); err != nil {
|
||||
client.sendErr(err)
|
||||
}
|
||||
client.clientsUDP[data.Client.Client.String()] = toAgent
|
||||
go func() {
|
||||
io.Copy(client.GetTargetWrite(proto.ProtoUDP, data.Client.Client), toAgent)
|
||||
delete(client.clientsUDP, data.Client.Client.String())
|
||||
toAgent.Close()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
if data.Client.Proto == proto.ProtoTCP {
|
||||
if tun, ok := client.clientsTCP[data.Client.Client.String()]; ok {
|
||||
go tun.Write(data.Data)
|
||||
}
|
||||
} else if data.Client.Proto == proto.ProtoUDP {
|
||||
if tun, ok := client.clientsUDP[data.Client.Client.String()]; ok {
|
||||
go tun.Write(data.Data)
|
||||
}
|
||||
} else if res.Pong != nil {
|
||||
fmt.Println(res.Pong.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Accept connection from Controller
|
||||
func (client *Client) Accept() (proto.Protoc, net.Conn, error) {
|
||||
if conn, ok := <-client.newListen; ok {
|
||||
return conn.Client.Proto, conn.Conn, nil
|
||||
}
|
||||
return 0, nil, io.EOF
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/urfave/cli/v2"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/client"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/proto"
|
||||
)
|
||||
|
||||
var CmdClient = cli.Command{
|
||||
Name: "client",
|
||||
Aliases: []string{"c"},
|
||||
Usage: "connect to controller server and bind new requests to local port",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "url",
|
||||
Required: true,
|
||||
Aliases: []string{"host", "u"},
|
||||
Usage: `host string to connect to controller, example: "example.com:5522"`,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "token",
|
||||
Required: true,
|
||||
Usage: "agent token",
|
||||
Aliases: []string{"t"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "dial",
|
||||
Required: true,
|
||||
Usage: `dial connection, default is "localhost:80"`,
|
||||
Aliases: []string{"d"},
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) (err error) {
|
||||
var addr netip.AddrPort
|
||||
if addr, err = netip.ParseAddrPort(ctx.String("url")); err != nil {
|
||||
return
|
||||
}
|
||||
key, _ := uuid.MustParse(ctx.String("token")).MarshalBinary()
|
||||
client, err := client.CreateClient(addr, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Connected, Remote address: %s\n", client.AgentInfo.AddrPort.String())
|
||||
if client.AgentInfo.Protocol == proto.ProtoUDP {
|
||||
fmt.Printf(" Port: UDP %d\n", client.AgentInfo.UDPPort)
|
||||
} else if client.AgentInfo.Protocol == proto.ProtoTCP {
|
||||
fmt.Printf(" Port: TCP %d\n", client.AgentInfo.TCPPort)
|
||||
} else if client.AgentInfo.Protocol == proto.ProtoBoth {
|
||||
fmt.Printf(" Ports UDP %d and TCP %d\n", client.AgentInfo.UDPPort, client.AgentInfo.TCPPort)
|
||||
}
|
||||
|
||||
localConnect := ctx.String("dial")
|
||||
for {
|
||||
client := <-client.NewClient
|
||||
var dial net.Conn
|
||||
if client.Client.Proto == proto.ProtoTCP {
|
||||
if dial, err = net.Dial("tcp", localConnect); err != nil {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if dial, err = net.Dial("udp", localConnect); err != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
go io.Copy(client.Writer, dial)
|
||||
go io.Copy(dial, client.Writer)
|
||||
}
|
||||
},
|
||||
}
|
28
cmd/main.go
28
cmd/main.go
@ -1,28 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/cmd/client"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/cmd/server"
|
||||
)
|
||||
|
||||
var description string = `pproxit is a proxy that allows anyone to host a server without port forwarding. We use tunneling. Only the server needs to run the program, not every player!`
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "pproxit"
|
||||
app.Description = description
|
||||
app.EnableBashCompletion = true
|
||||
app.HideHelpCommand = true
|
||||
app.Commands = []*cli.Command{
|
||||
&server.CmdServer,
|
||||
&client.CmdClient,
|
||||
}
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Fprintf(app.ErrWriter, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/server"
|
||||
)
|
||||
|
||||
var CmdServer = cli.Command{
|
||||
Name: "server",
|
||||
Usage: "Create local server and open controller ports",
|
||||
Aliases: []string{"s"},
|
||||
Flags: []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
Name: "port",
|
||||
Value: 5522,
|
||||
Aliases: []string{"p"},
|
||||
Usage: "Set controller port to watcher UDP requests",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "log",
|
||||
Value: "silence",
|
||||
Aliases: []string{"l"},
|
||||
Usage: "set server log: silence, 0 or verbose, 2",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "db",
|
||||
Value: "./pproxit.db",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "sqlite file path",
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
calls, err := NewCall(ctx.String("db"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pproxitServer, err := server.NewController(calls, netip.AddrPortFrom(netip.IPv4Unspecified(), uint16(ctx.Int("port"))).String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return <-pproxitServer.ProcessError
|
||||
},
|
||||
}
|
23
go.mod
23
go.mod
@ -1,36 +1,31 @@
|
||||
module sirherobrine23.org/Minecraft-Server/go-pproxit
|
||||
module sirherobrine23.com.br/Minecraft-Server/go-pproxit
|
||||
|
||||
go 1.22.3
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/urfave/cli/v2 v2.27.4
|
||||
modernc.org/sqlite v1.33.1
|
||||
xorm.io/xorm v1.3.9
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/goccy/go-json v0.10.3 // indirect
|
||||
github.com/goccy/go-json v0.8.1 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect
|
||||
modernc.org/libc v1.61.0 // indirect
|
||||
golang.org/x/sys v0.22.0 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
|
||||
modernc.org/libc v1.55.3 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
modernc.org/strutil v1.2.0 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
xorm.io/builder v0.3.13 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
)
|
||||
|
49
go.sum
49
go.sum
@ -1,9 +1,5 @@
|
||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
|
||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -14,8 +10,6 @@ github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/goccy/go-json v0.8.1 h1:4/Wjm0JIJaTDm8K1KcGrLHJoa8EsJ13YWeX+6Kfq6uI=
|
||||
github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
|
||||
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
@ -37,8 +31,6 @@ github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwp
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
@ -52,42 +44,26 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
||||
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
|
||||
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
|
||||
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
|
||||
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
|
||||
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
|
||||
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
@ -97,25 +73,18 @@ gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/cc/v4 v4.21.2 h1:dycHFB/jDc3IyacKipCNSDrjIC0Lm1hyoWOZTRR20Lk=
|
||||
modernc.org/cc/v4 v4.21.2/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
|
||||
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ=
|
||||
modernc.org/ccgo/v4 v4.17.10 h1:6wrtRozgrhCxieCeJh85QsxkX/2FFrT9hdaWPlbn4Zo=
|
||||
modernc.org/ccgo/v4 v4.17.10/go.mod h1:0NBHgsqTTpm9cA5z2ccErvGZmtntSM9qD2kFAs6pjXM=
|
||||
modernc.org/ccgo/v4 v4.21.0 h1:kKPI3dF7RIag8YcToh5ZwDcVMIv6VGa0ED5cvh0LMW4=
|
||||
modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
|
||||
modernc.org/ccgo/v4 v4.19.2 h1:lwQZgvboKD0jBwdaeVCTouxhxAyN6iawF3STraAal8Y=
|
||||
modernc.org/ccgo/v4 v4.19.2/go.mod h1:ysS3mxiMV38XGRTTcgo0DQTeTmAO4oCmJl1nX9VFI3s=
|
||||
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||
modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw=
|
||||
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
|
||||
modernc.org/gc/v2 v2.5.0 h1:bJ9ChznK1L1mUtAQtxi0wi5AtAs5jQuw4PrPHO5pb6M=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a h1:CfbpOLEo2IwNzJdMvE8aiRbPMxoTpgAJeyePh0SmO8M=
|
||||
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/libc v1.52.1 h1:uau0VoiT5hnR+SpoWekCKbLqm7v6dhRL3hI+NQhgN3M=
|
||||
modernc.org/libc v1.52.1/go.mod h1:HR4nVzFDSDizP620zcMCgjb1/8xk2lg5p/8yjfGv1IQ=
|
||||
modernc.org/libc v1.61.0 h1:eGFcvWpqlnoGwzZeZe3PWJkkKbM/3SUGyk1DVZQ0TpE=
|
||||
modernc.org/libc v1.61.0/go.mod h1:DvxVX89wtGTu+r72MLGhygpfi3aUGgZRdAYGCAVVud0=
|
||||
modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U=
|
||||
modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
|
||||
@ -124,8 +93,6 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
|
||||
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
|
||||
modernc.org/sqlite v1.30.1 h1:YFhPVfu2iIgUf9kuA1CR7iiHdcEEsI2i+yjRYHscyxk=
|
||||
modernc.org/sqlite v1.30.1/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU=
|
||||
modernc.org/sqlite v1.33.1 h1:trb6Z3YYoeM9eDL1O8do81kP+0ejv+YzgyFo+Gwy0nM=
|
||||
modernc.org/sqlite v1.33.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
@ -134,7 +101,5 @@ modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 h1:bvLlAPW1ZMTWA32LuZMBEGHAUOcATZjzHcotf3SWweM=
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
|
||||
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||
xorm.io/xorm v1.3.9 h1:TUovzS0ko+IQ1XnNLfs5dqK1cJl1H5uHpWbWqAQ04nU=
|
||||
xorm.io/xorm v1.3.9/go.mod h1:LsCCffeeYp63ssk0pKumP6l96WZcHix7ChpurcLNuMw=
|
||||
|
30
gopproxit_test.go
Normal file
30
gopproxit_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
package gopproxit_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/client"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/server"
|
||||
)
|
||||
|
||||
func TestClientServer(t *testing.T) {
|
||||
calls, err := NewCall("./pproxit.db")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
controller, err := server.NewController(calls, 8881)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer controller.ControllConn.Close()
|
||||
token := calls.RegisterRandomUser()
|
||||
|
||||
clientConn, err := client.NewClient(controller.ControllConn.Addr().String(), token)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer clientConn.Close()
|
||||
}
|
@ -7,6 +7,7 @@ package pipe
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
@ -81,7 +82,7 @@ func isClosedChan(c <-chan struct{}) bool {
|
||||
}
|
||||
|
||||
type pipe struct {
|
||||
localAddr, remoteAddr net.Addr
|
||||
localAddr, remoteAddr netip.AddrPort
|
||||
|
||||
wrMu sync.Mutex // Serialize Write operations
|
||||
|
||||
@ -108,7 +109,7 @@ type pipe struct {
|
||||
// Reads on one end are matched with writes on the other,
|
||||
// copying data directly between the two; there is no internal
|
||||
// buffering.
|
||||
func CreatePipe(LocalAddress, RemoteAddress net.Addr) (net.Conn, net.Conn) {
|
||||
func CreatePipe(LocalAddress, RemoteAddress netip.AddrPort) (net.Conn, net.Conn) {
|
||||
cb1 := make(chan []byte)
|
||||
cb2 := make(chan []byte)
|
||||
cn1 := make(chan int)
|
||||
@ -139,8 +140,11 @@ func CreatePipe(LocalAddress, RemoteAddress net.Addr) (net.Conn, net.Conn) {
|
||||
return p1, p2
|
||||
}
|
||||
|
||||
func (p *pipe) LocalAddr() net.Addr { return p.localAddr }
|
||||
func (p *pipe) RemoteAddr() net.Addr { return p.remoteAddr }
|
||||
type addr struct{ netip.AddrPort }
|
||||
|
||||
func (addr) Network() string { return "pipe" }
|
||||
func (p *pipe) LocalAddr() net.Addr { return addr{p.localAddr} }
|
||||
func (p *pipe) RemoteAddr() net.Addr { return addr{p.remoteAddr} }
|
||||
|
||||
func (p *pipe) Read(b []byte) (int, error) {
|
||||
n, err := p.read(b)
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/proto"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/proto"
|
||||
)
|
||||
|
||||
type mapTest map[string]mapStr
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"net/netip"
|
||||
"sync"
|
||||
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/internal/pipe"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/internal/pipe"
|
||||
)
|
||||
|
||||
type writeRoot struct {
|
||||
@ -83,10 +83,10 @@ func (udpListen *UDPServer) handler() {
|
||||
c.bufferCache = new(bytes.Buffer)
|
||||
c.bufioCache = bufio.NewReader(c.bufferCache)
|
||||
|
||||
c.fromAgent, c.toClient = pipe.CreatePipe(from, from)
|
||||
c.fromAgent, c.toClient = pipe.CreatePipe(from.AddrPort(), from.AddrPort())
|
||||
|
||||
udpListen.peers[from.String()] = c
|
||||
go func(){
|
||||
go func() {
|
||||
for _, exist := udpListen.peers[from.String()]; exist; {
|
||||
io.Copy(c.fromAgent, c.bufioCache)
|
||||
}
|
||||
|
@ -42,3 +42,6 @@ type ClientData struct {
|
||||
Client Client // Client Destination
|
||||
Data []byte `json:"-"` // Bytes to send
|
||||
}
|
||||
|
||||
// Return pointer to value
|
||||
func Point[T any](val T) *T { return &val }
|
||||
|
@ -9,8 +9,8 @@ var ErrProtoBothNoSupported error = errors.New("protocol UDP+TCP not supported c
|
||||
|
||||
// Send request to agent and wait response
|
||||
type Request struct {
|
||||
AgentAuth *[]byte `json:",omitempty"` // Send agent authentication to controller
|
||||
Ping *time.Time `json:",omitempty"` // Send ping time to controller in unix milliseconds
|
||||
AgentAuth *[]byte `json:",omitempty"` // Send agent authentication to controller
|
||||
ClientClose *Client `json:",omitempty"` // Close client in controller
|
||||
DataTX *ClientData `json:",omitempty"` // Recive data from agent
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"net/netip"
|
||||
"os"
|
||||
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/internal/structcode"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/proto"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/internal/structcode"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/proto"
|
||||
)
|
||||
|
||||
var ErrAuthAgentFail error = errors.New("cannot authenticate agent") // Send unathorized client and close new accepts from current port
|
||||
@ -26,8 +26,8 @@ type Server struct {
|
||||
Agents map[string]*Tunnel
|
||||
}
|
||||
|
||||
func NewController(calls ServerCall, local string) (*Server, error) {
|
||||
conn, err := net.ListenTCP("tcp", net.TCPAddrFromAddrPort(netip.MustParseAddrPort(local)))
|
||||
func NewController(calls ServerCall, port uint16) (*Server, error) {
|
||||
conn, err := net.ListenTCP("tcp", net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.IPv4Unspecified(), port)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@ -9,9 +8,9 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/internal/structcode"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/internal/udplisterner"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/proto"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/internal/structcode"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/internal/udplisterner"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/proto"
|
||||
)
|
||||
|
||||
type TunnelCall interface {
|
||||
@ -124,8 +123,6 @@ func (tun *Tunnel) Setup() {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
return
|
||||
}
|
||||
d, _ := json.Marshal(req)
|
||||
fmt.Println(string(d))
|
||||
|
||||
if req.AgentAuth != nil {
|
||||
go tun.send(proto.Response{
|
||||
|
@ -1,4 +1,4 @@
|
||||
package server
|
||||
package gopproxit_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -7,8 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/proto"
|
||||
"sirherobrine23.org/Minecraft-Server/go-pproxit/server"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/proto"
|
||||
"sirherobrine23.com.br/Minecraft-Server/go-pproxit/server"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/names"
|
||||
)
|
||||
@ -157,3 +157,18 @@ func (caller *serverCalls) AgentAuthentication(Token []byte) (server.TunnelInfo,
|
||||
Callbacks: &TunCallbcks{tunID: tun.ID, XormEngine: caller.XormEngine, Locker: caller.Locker},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (caller *serverCalls) RegisterRandomUser() []byte {
|
||||
token := []byte{0, 0, 12, 14, 22, 89, 255, 81}
|
||||
caller.XormEngine.Insert(
|
||||
&User{ID: 0, AccountStatus: 1, FullName: "Radon user", Username: "random"},
|
||||
&Tun{
|
||||
User: 0,
|
||||
Token: token,
|
||||
Proto: proto.ProtoBoth,
|
||||
TPCListen: 5522,
|
||||
UDPListen: 5522,
|
||||
},
|
||||
)
|
||||
return token
|
||||
}
|
Reference in New Issue
Block a user