feat: allow providing a custom --maxbytes param for a relay server

making the MAXBYTES customizable helps to run relay servers
which can allow an arbitary amount of max bytes. By default, the
MaxBytes will be set to 40000.

To set a custom MaxBytes variable value:

croc relay --maxbytes 10000000
This commit is contained in:
Srevin Saju 2021-03-14 22:25:11 +03:00
parent 20bf7dd91d
commit e03d54635d
No known key found for this signature in database
GPG Key ID: 1007816766D390D7
3 changed files with 10 additions and 1 deletions

View File

@ -80,6 +80,7 @@ func Run() (err error) {
Flags: []cli.Flag{
&cli.StringFlag{Name: "host", Usage: "host of the relay"},
&cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the relay"},
&cli.IntFlag{Name: "maxbytes", Value: comm.MaxBytes, Usage: "maximum bytes which can be relayed"},
},
},
}
@ -463,6 +464,8 @@ func relay(c *cli.Context) (err error) {
debugString = "debug"
}
host := c.String("host")
comm.MaxBytes = c.Int("maxbytes")
log.Debugf("setting the maxbytes allowed for relay as %d", comm.MaxBytes)
ports := strings.Split(c.String("ports"), ",")
tcpPorts := strings.Join(ports[1:], ",")
for i, port := range ports {

View File

@ -18,6 +18,7 @@ import (
var Socks5Proxy = ""
var MAGIC_BYTES = []byte("croc")
var MaxBytes = 4000000
// Comm is some basic TCP communication
type Comm struct {
@ -150,6 +151,11 @@ func (c *Comm) Read() (buf []byte, numBytes int, bs []byte, err error) {
return
}
numBytes = int(numBytesUint32)
if numBytes > MaxBytes {
err = fmt.Errorf("too many bytes: %d", numBytes)
log.Debug(err)
return
}
// shorten the reading deadline in case getting weird data
if err := c.connection.SetReadDeadline(time.Now().Add(10 * time.Second)); err != nil {

View File

@ -11,7 +11,7 @@ import (
)
func TestComm(t *testing.T) {
token := make([]byte, 3000)
token := make([]byte, MaxBytes)
if _, err := rand.Read(token); err != nil {
t.Error(err)
}