forked from fatedier/frp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
246 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ _testmain.go | |
# Self | ||
bin/ | ||
packages/ | ||
test/bin/ | ||
|
||
# Cache | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ install: | |
- make | ||
|
||
script: | ||
- make test | ||
- make alltest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
pid=`ps aux|grep './bin/echo_server'|grep -v grep|awk {'print $2'}` | ||
if [ -n "${pid}" ]; then | ||
kill ${pid} | ||
fi | ||
|
||
pid=`ps aux|grep './bin/http_server'|grep -v grep|awk {'print $2'}` | ||
if [ -n "${pid}" ]; then | ||
kill ${pid} | ||
fi | ||
|
||
pid=`ps aux|grep './../bin/frps -c ./conf/auto_test_frps.ini'|grep -v grep|awk {'print $2'}` | ||
if [ -n "${pid}" ]; then | ||
kill ${pid} | ||
fi | ||
|
||
pid=`ps aux|grep './../bin/frpc -c ./conf/auto_test_frpc.ini'|grep -v grep|awk {'print $2'}` | ||
if [ -n "${pid}" ]; then | ||
kill ${pid} | ||
fi | ||
|
||
rm -f ./frps.log | ||
rm -f ./frpc.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[common] | ||
server_addr = 0.0.0.0 | ||
server_port = 10700 | ||
log_file = ./frpc.log | ||
# debug, info, warn, error | ||
log_level = debug | ||
auth_token = 123 | ||
|
||
[echo] | ||
type = tcp | ||
local_ip = 127.0.0.1 | ||
local_port = 10701 | ||
use_encryption = true | ||
|
||
[web] | ||
type = http | ||
local_ip = 127.0.0.1 | ||
local_port = 10702 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[common] | ||
bind_addr = 0.0.0.0 | ||
bind_port = 10700 | ||
vhost_http_port = 10710 | ||
log_file = ./frps.log | ||
log_level = debug | ||
|
||
[echo] | ||
type = tcp | ||
auth_token = 123 | ||
bind_addr = 0.0.0.0 | ||
listen_port = 10711 | ||
|
||
[web] | ||
type = http | ||
auth_token = 123 | ||
custom_domains = 127.0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"frp/utils/conn" | ||
) | ||
|
||
var ( | ||
PORT int64 = 10701 | ||
) | ||
|
||
func main() { | ||
l, err := conn.Listen("0.0.0.0", PORT) | ||
if err != nil { | ||
fmt.Printf("echo server listen error: %v\n", err) | ||
return | ||
} | ||
|
||
for { | ||
c, err := l.Accept() | ||
if err != nil { | ||
fmt.Printf("echo server accept error: %v\n", err) | ||
return | ||
} | ||
|
||
go echoWorker(c) | ||
} | ||
} | ||
|
||
func echoWorker(c *conn.Conn) { | ||
for { | ||
buff, err := c.ReadLine() | ||
if err != nil { | ||
fmt.Printf("echo server read error: %v\n", err) | ||
return | ||
} | ||
|
||
c.Write(buff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"frp/utils/conn" | ||
) | ||
|
||
var ( | ||
ECHO_PORT int64 = 10711 | ||
HTTP_PORT int64 = 10710 | ||
ECHO_TEST_STR string = "Hello World\n" | ||
HTTP_RES_STR string = "Hello World" | ||
) | ||
|
||
func TestEchoServer(t *testing.T) { | ||
c, err := conn.ConnectServer("0.0.0.0", ECHO_PORT) | ||
if err != nil { | ||
t.Fatalf("connect to echo server error: %v", err) | ||
} | ||
timer := time.Now().Add(time.Duration(5) * time.Second) | ||
c.SetDeadline(timer) | ||
|
||
c.Write(ECHO_TEST_STR) | ||
|
||
buff, err := c.ReadLine() | ||
if err != nil { | ||
t.Fatalf("read from echo server error: %v", err) | ||
} | ||
|
||
if ECHO_TEST_STR != buff { | ||
t.Fatalf("content error, send [%s], get [%s]", strings.Trim(ECHO_TEST_STR, "\n"), strings.Trim(buff, "\n")) | ||
} | ||
} | ||
|
||
func TestHttpServer(t *testing.T) { | ||
client := &http.Client{} | ||
req, _ := http.NewRequest("GET", fmt.Sprintf("http://127.0.0.1:%d", HTTP_PORT), nil) | ||
res, err := client.Do(req) | ||
if err != nil { | ||
t.Fatalf("do http request error: %v", err) | ||
} | ||
if res.StatusCode == 200 { | ||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
t.Fatalf("read from http server error: %v", err) | ||
} | ||
bodystr := string(body) | ||
if bodystr != HTTP_RES_STR { | ||
t.Fatalf("content from http server error [%s], correct string is [%s]", bodystr, HTTP_RES_STR) | ||
} | ||
} else { | ||
t.Fatalf("http code from http server error [%d]", res.StatusCode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
var ( | ||
PORT int64 = 10702 | ||
HTTP_RES_STR string = "Hello World" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/", request) | ||
http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", PORT), nil) | ||
} | ||
|
||
func request(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(HTTP_RES_STR)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
./bin/echo_server & | ||
./bin/http_server & | ||
./../bin/frps -c ./conf/auto_test_frps.ini & | ||
sleep 1 | ||
./../bin/frpc -c ./conf/auto_test_frpc.ini & | ||
|
||
# wait until proxies are connected | ||
for((i=1; i<15; i++)) | ||
do | ||
sleep 1 | ||
str=`ss -ant|grep 10700|grep LISTEN` | ||
if [ -z "${str}" ]; then | ||
echo "kong" | ||
continue | ||
fi | ||
|
||
str=`ss -ant|grep 10710|grep LISTEN` | ||
if [ -z "${str}" ]; then | ||
echo "kong" | ||
continue | ||
fi | ||
|
||
str=`ss -ant|grep 10711|grep LISTEN` | ||
if [ -z "${str}" ]; then | ||
echo "kong" | ||
continue | ||
fi | ||
|
||
break | ||
done | ||
|
||
sleep 1 |