This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathclient.go
54 lines (46 loc) · 1.45 KB
/
client.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
package main
import (
"fmt"
"github.com/xtaci/tcpraw"
"github.com/yzslab/kcp-go"
"log"
"time"
)
func startClient(config *ClientConfig) error {
config.CommonConfig.PrintSummary()
block := createBlock(&config.CommonConfig)
remoteAddr := fmt.Sprintf("%s:%d", config.GetIP(), config.GetPort())
log.Printf("connecting to %s", remoteAddr)
var session *kcp.UDPSession
var err error
if config.EnableTCPSimulation {
conn, err := tcpraw.Dial("tcp", remoteAddr)
if err != nil {
return err
}
session, err = kcp.NewConn(remoteAddr, block, config.GetDatashard(), config.GetParityshard(), conn)
} else {
session, err = kcp.DialWithOptions(remoteAddr, block, config.GetDatashard(), config.GetParityshard())
}
if err != nil {
return err
}
defer session.Close()
session.SetStreamMode(true)
session.SetWriteDelay(false)
session.SetNoDelay(config.GetNodelay(), config.GetInterval(), config.GetResend(), config.GetNoCongestion())
session.SetMtu(int(config.GetUDPMTU()))
session.SetWindowSize(config.GetSendWindowSize(), config.GetReceiveWindowSize())
session.SetACKNoDelay(config.GetAckNodelay())
if config.Datashard != 0 && config.Parityshard != 0 {
session.SetRapidFec(config.EnableRapidFec)
session.SetRapidFecMinInterval(time.Duration(config.GetInterval()) * time.Millisecond)
}
server, err := NewVPNServer(session, config, config.IsVNIPersistent())
if err != nil {
return err
}
defer server.Close()
_, err = IterateState(server)
return err
}