mirror of https://github.com/fatedier/frp
fatedier
3 years ago
14 changed files with 127 additions and 43 deletions
@ -0,0 +1,47 @@
|
||||
package features |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strings" |
||||
"time" |
||||
|
||||
"github.com/fatedier/frp/test/e2e/framework" |
||||
"github.com/fatedier/frp/test/e2e/framework/consts" |
||||
"github.com/fatedier/frp/test/e2e/mock/server/streamserver" |
||||
"github.com/fatedier/frp/test/e2e/pkg/request" |
||||
|
||||
. "github.com/onsi/ginkgo" |
||||
) |
||||
|
||||
var _ = Describe("[Feature: Bandwidth Limit]", func() { |
||||
f := framework.NewDefaultFramework() |
||||
|
||||
It("Proxy Bandwidth Limit", func() { |
||||
serverConf := consts.DefaultServerConfig |
||||
clientConf := consts.DefaultClientConfig |
||||
|
||||
localPort := f.AllocPort() |
||||
localServer := streamserver.New(streamserver.TCP, streamserver.WithBindPort(localPort)) |
||||
f.RunServer("", localServer) |
||||
|
||||
remotePort := f.AllocPort() |
||||
clientConf += fmt.Sprintf(` |
||||
[tcp] |
||||
type = tcp |
||||
local_port = %d |
||||
remote_port = %d |
||||
bandwidth_limit = 10KB |
||||
`, localPort, remotePort) |
||||
|
||||
f.RunProcesses([]string{serverConf}, []string{clientConf}) |
||||
|
||||
content := strings.Repeat("a", 50*1024) // 5KB
|
||||
start := time.Now() |
||||
framework.NewRequestExpect(f).Port(remotePort).RequestModify(func(r *request.Request) { |
||||
r.Body([]byte(content)).Timeout(30 * time.Second) |
||||
}).ExpectResp([]byte(content)).Ensure() |
||||
duration := time.Now().Sub(start) |
||||
|
||||
framework.ExpectTrue(duration.Seconds() > 7, "100Kb with 10KB limit, want > 7 seconds, but got %d seconds", duration.Seconds()) |
||||
}) |
||||
}) |
@ -1,4 +1,4 @@
|
||||
package basic |
||||
package features |
||||
|
||||
import ( |
||||
"fmt" |
@ -1,4 +1,4 @@
|
||||
package basic |
||||
package features |
||||
|
||||
import ( |
||||
"fmt" |
@ -0,0 +1,20 @@
|
||||
package features |
||||
|
||||
import ( |
||||
"github.com/fatedier/frp/test/e2e/framework" |
||||
|
||||
. "github.com/onsi/ginkgo" |
||||
) |
||||
|
||||
var _ = Describe("[Feature: Real IP]", func() { |
||||
f := framework.NewDefaultFramework() |
||||
|
||||
It("HTTP X-Forwarded-For", func() { |
||||
// TODO
|
||||
_ = f |
||||
}) |
||||
|
||||
It("Proxy Protocol", func() { |
||||
// TODO
|
||||
}) |
||||
}) |
@ -0,0 +1,35 @@
|
||||
package rpc |
||||
|
||||
import ( |
||||
"bufio" |
||||
"bytes" |
||||
"encoding/binary" |
||||
"errors" |
||||
"io" |
||||
) |
||||
|
||||
func WriteBytes(w io.Writer, buf []byte) (int, error) { |
||||
out := bytes.NewBuffer(nil) |
||||
binary.Write(out, binary.BigEndian, int64(len(buf))) |
||||
out.Write(buf) |
||||
return w.Write(out.Bytes()) |
||||
} |
||||
|
||||
func ReadBytes(r io.Reader) ([]byte, error) { |
||||
// To compatible with UDP connection, use bufio reader here to avoid lost conent.
|
||||
rd := bufio.NewReader(r) |
||||
|
||||
var length int64 |
||||
if err := binary.Read(rd, binary.BigEndian, &length); err != nil { |
||||
return nil, err |
||||
} |
||||
buffer := make([]byte, length) |
||||
n, err := io.ReadFull(rd, buffer) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if int64(n) != length { |
||||
return nil, errors.New("invalid length") |
||||
} |
||||
return buffer, nil |
||||
} |
Loading…
Reference in new issue