-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.go
70 lines (62 loc) · 1.5 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package test
import (
"time"
"fmt"
"crypto/tls"
"io/ioutil"
"github.com/astaxie/beego/logs"
"crypto/x509"
"port-forward/utils"
)
func TestTime(){
start_time := time.Now().Unix()
fmt.Println(start_time)
time.Sleep(2*time.Second)
stop_time := time.Now().Unix()
fmt.Println(stop_time)
fmt.Println((stop_time-start_time))
}
func StartTLSClient(targetPort string) (conn tls.Conn,err error) {
cert, err := tls.LoadX509KeyPair("data/client.pem", "data/client.key")
if err != nil {
logs.Debug(err)
return tls.Conn{},err
}
certBytes, err := ioutil.ReadFile("data/client.pem")
if err != nil {
logs.Debug("Unable to read cert.pem")
}
clientCertPool := x509.NewCertPool()
ok := clientCertPool.AppendCertsFromPEM(certBytes)
if !ok {
logs.Debug("failed to parse root certificate")
}
conf := &tls.Config{
RootCAs: clientCertPool,
Certificates: []tls.Certificate{cert},
InsecureSkipVerify: true,
}
targetConn,err := tls.Dial("tcp", targetPort, conf)
if err != nil {
logs.Debug("failed to Dial up :",err)
return tls.Conn{},err
}
defer targetConn.Close()
return *targetConn,nil
}
func test(){
addr := "127.0.0.1"
port := "8778"
tslConn,_ := StartTLSClient((addr+":"+port))
temp_b := make([]byte, 1000)
utils.GetCipherText(temp_b,"astaxie12798akljzmknm.ahkjkljl;k")
fmt.Println("连接建立,开始测试。")
for i:=0;i>10;i++{
n,err:=tslConn.Write(temp_b)
if err !=nil{
fmt.Println("写入数据失败:",err)
break
}
fmt.Println("写入:",n,i)
}
}