Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
obfsvpn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leap
obfsvpn
Commits
4fdf6cf0
Commit
4fdf6cf0
authored
7 months ago
by
Maxb
Browse files
Options
Downloads
Patches
Plain Diff
Provide more command line flags for tuning KCP
parent
96ef1b03
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!49
Provide more command line flags for tuning KCP
Pipeline
#231129
passed
7 months ago
Stage: test
Stage: build
Stage: release
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/client/main.go
+36
-21
36 additions, 21 deletions
cmd/client/main.go
cmd/server/main.go
+69
-43
69 additions, 43 deletions
cmd/server/main.go
obfsvpn/kcp.go
+40
-16
40 additions, 16 deletions
obfsvpn/kcp.go
with
145 additions
and
80 deletions
cmd/client/main.go
+
36
−
21
View file @
4fdf6cf0
...
...
@@ -21,22 +21,27 @@ func main() {
// setup command line flags.
var
(
hoppingPT
bool
hopJitter
uint
=
5
kcp
bool
kcpSendWindowSize
int
=
obfsvpn
.
DefaultKCPSendWindowSize
kcpReceiveWindowSize
int
=
obfsvpn
.
DefaultKCPReceiveWindowSize
kcpReadBuffer
int
=
obfsvpn
.
DefaultKCPReadBuffer
kcpWriteBuffer
int
=
obfsvpn
.
DefaultKCPWriteBuffer
minHopSeconds
uint
=
5
portSeed
int64
=
1
portCount
uint
=
100
proxyPort
string
proxyHost
string
obfs4Certs
string
obfs4Remotes
string
obfs4RemotePort
string
verbose
bool
hoppingPT
bool
hopJitter
uint
=
5
kcp
bool
kcpSendWindowSize
int
=
obfsvpn
.
DefaultKCPSendWindowSize
kcpReceiveWindowSize
int
=
obfsvpn
.
DefaultKCPReceiveWindowSize
kcpReadBuffer
int
=
obfsvpn
.
DefaultKCPReadBuffer
kcpWriteBuffer
int
=
obfsvpn
.
DefaultKCPWriteBuffer
kcpNoDelay
bool
=
obfsvpn
.
DefaultNoDelay
kcpInterval
int
=
obfsvpn
.
DefaultInterval
kcpResend
int
=
obfsvpn
.
DefaultResend
kcpDisableFlowControl
=
obfsvpn
.
DefaultDisableFlowControl
kcpMTU
=
obfsvpn
.
DefaultMTU
minHopSeconds
uint
=
5
portSeed
int64
=
1
portCount
uint
=
100
proxyPort
string
proxyHost
string
obfs4Certs
string
obfs4Remotes
string
obfs4RemotePort
string
verbose
bool
)
proxyPort
=
"8080"
...
...
@@ -48,6 +53,11 @@ func main() {
flags
.
IntVar
(
&
kcpReceiveWindowSize
,
"kcp-receive-window-size"
,
kcpReceiveWindowSize
,
"KCP ReceiveWindowSize"
)
flags
.
IntVar
(
&
kcpReadBuffer
,
"kcp-read-buffer"
,
kcpReadBuffer
,
"KCP ReadBuffer"
)
flags
.
IntVar
(
&
kcpWriteBuffer
,
"kcp-write-buffer"
,
kcpWriteBuffer
,
"KCP WriteBuffer"
)
flags
.
BoolVar
(
&
kcpNoDelay
,
"kcp-no-delay"
,
kcpNoDelay
,
"KCP NoDelay"
)
flags
.
IntVar
(
&
kcpInterval
,
"kcp-interval"
,
kcpInterval
,
"KCP Interval"
)
flags
.
IntVar
(
&
kcpResend
,
"kcp-resend"
,
kcpResend
,
"KCP Resend"
)
flags
.
BoolVar
(
&
kcpDisableFlowControl
,
"kcp-disable-flow-control"
,
kcpDisableFlowControl
,
"KCP DisableFlowControl"
)
flags
.
IntVar
(
&
kcpMTU
,
"kcp-mtu"
,
kcpMTU
,
"KCP MTU"
)
flags
.
BoolVar
(
&
verbose
,
"v"
,
verbose
,
"Enable verbose logging"
)
flags
.
BoolVar
(
&
hoppingPT
,
"h"
,
hoppingPT
,
"Connect with openvpn over udp in hopping mode"
)
flags
.
StringVar
(
&
obfs4Certs
,
"c"
,
obfs4Certs
,
"The remote obfs4 certificates separated by commas. If hopping is not enabled only the first cert will be used"
)
...
...
@@ -83,11 +93,16 @@ func main() {
ctx
,
stop
:=
signal
.
NotifyContext
(
context
.
Background
(),
os
.
Interrupt
)
kcpConfig
:=
obfsvpn
.
KCPConfig
{
Enabled
:
kcp
,
SendWindowSize
:
kcpSendWindowSize
,
ReceiveWindowSize
:
kcpReceiveWindowSize
,
ReadBuffer
:
kcpReadBuffer
,
WriteBuffer
:
kcpWriteBuffer
,
Enabled
:
kcp
,
SendWindowSize
:
kcpSendWindowSize
,
ReceiveWindowSize
:
kcpReceiveWindowSize
,
ReadBuffer
:
kcpReadBuffer
,
WriteBuffer
:
kcpWriteBuffer
,
NoDelay
:
kcpNoDelay
,
Interval
:
kcpInterval
,
Resend
:
kcpResend
,
DisableFlowControl
:
kcpDisableFlowControl
,
MTU
:
kcpMTU
,
}
var
config
client
.
Config
...
...
This diff is collapsed.
Click to expand it.
cmd/server/main.go
+
69
−
43
View file @
4fdf6cf0
...
...
@@ -33,14 +33,19 @@ var (
kcpReceiveWindowSize
=
"kcp-receive-window-size"
kcpReadBuffer
=
"kcp-read-buffer"
//nolint:gosec // gosec somehow thinks this next line is Potential hardcoded credentials 🤷
kcpWriteBuffer
=
"kcp-write-buffer"
persist
=
"persist"
port
=
"port"
portSeed
=
"port-seed"
portCount
=
"port-count"
stateDir
=
"state"
remote
=
"remote"
verbose
=
"v"
kcpWriteBuffer
=
"kcp-write-buffer"
kcpNoDelay
=
"kcp-no-delay"
kcpInterval
=
"kcp-interval"
kcpResend
=
"kcp-resend"
kcpDisableFlowControl
=
"kcp-disable-flow-control"
kcpMTU
=
"kcp-mtu"
persist
=
"persist"
port
=
"port"
portSeed
=
"port-seed"
portCount
=
"port-count"
stateDir
=
"state"
remote
=
"remote"
verbose
=
"v"
)
var
(
...
...
@@ -50,21 +55,26 @@ var (
)
type
config
struct
{
addr
string
cfgFile
string
port
int
hop
bool
udp
bool
kcp
bool
kcpSendWindowSize
int
kcpReceiveWindowSize
int
kcpReadBuffer
int
kcpWriteBuffer
int
portSeed
int64
portCount
uint
stateDir
string
remote
string
verbose
bool
addr
string
cfgFile
string
port
int
hop
bool
udp
bool
kcp
bool
kcpSendWindowSize
int
kcpReceiveWindowSize
int
kcpReadBuffer
int
kcpWriteBuffer
int
kcpNoDelay
bool
kcpInterval
int
kcpResend
int
kcpDisableFlowControl
bool
kcpMTU
int
portSeed
int64
portCount
uint
stateDir
string
remote
string
verbose
bool
}
func
newConfigFromViper
(
logger
*
log
.
Logger
)
*
config
{
...
...
@@ -89,21 +99,27 @@ func newConfigFromViper(logger *log.Logger) *config {
}
cfg
:=
&
config
{
addr
:
addrValue
,
cfgFile
:
viper
.
GetString
(
cfgFile
),
port
:
portValue
,
hop
:
viper
.
GetBool
(
hop
),
udp
:
viper
.
GetBool
(
udp
),
kcp
:
viper
.
GetBool
(
kcp
),
kcpSendWindowSize
:
viper
.
GetInt
(
kcpSendWindowSize
),
kcpReceiveWindowSize
:
viper
.
GetInt
(
kcpReceiveWindowSize
),
kcpReadBuffer
:
viper
.
GetInt
(
kcpReadBuffer
),
kcpWriteBuffer
:
viper
.
GetInt
(
kcpWriteBuffer
),
portSeed
:
viper
.
GetInt64
(
portSeed
),
portCount
:
viper
.
GetUint
(
portCount
),
stateDir
:
getStateDir
(),
remote
:
viper
.
GetString
(
remote
),
verbose
:
viper
.
GetBool
(
verbose
),
addr
:
addrValue
,
cfgFile
:
viper
.
GetString
(
cfgFile
),
port
:
portValue
,
hop
:
viper
.
GetBool
(
hop
),
udp
:
viper
.
GetBool
(
udp
),
kcp
:
viper
.
GetBool
(
kcp
),
kcpSendWindowSize
:
viper
.
GetInt
(
kcpSendWindowSize
),
kcpReceiveWindowSize
:
viper
.
GetInt
(
kcpReceiveWindowSize
),
kcpReadBuffer
:
viper
.
GetInt
(
kcpReadBuffer
),
kcpWriteBuffer
:
viper
.
GetInt
(
kcpWriteBuffer
),
kcpNoDelay
:
viper
.
GetBool
(
kcpNoDelay
),
kcpInterval
:
viper
.
GetInt
(
kcpInterval
),
kcpResend
:
viper
.
GetInt
(
kcpResend
),
kcpDisableFlowControl
:
viper
.
GetBool
(
kcpDisableFlowControl
),
kcpMTU
:
viper
.
GetInt
(
kcpMTU
),
portSeed
:
viper
.
GetInt64
(
portSeed
),
portCount
:
viper
.
GetUint
(
portCount
),
stateDir
:
getStateDir
(),
remote
:
viper
.
GetString
(
remote
),
verbose
:
viper
.
GetBool
(
verbose
),
}
// Sanity check on the configuration
...
...
@@ -187,6 +203,11 @@ func main() {
flag
.
Int
(
kcpReceiveWindowSize
,
obfsvpn
.
DefaultKCPReceiveWindowSize
,
"KCP ReceiveWindowSize"
)
flag
.
Int
(
kcpReadBuffer
,
obfsvpn
.
DefaultKCPReadBuffer
,
"KCP ReadBuffer"
)
flag
.
Int
(
kcpWriteBuffer
,
obfsvpn
.
DefaultKCPWriteBuffer
,
"KCP WriteBuffer"
)
flag
.
Bool
(
kcpNoDelay
,
obfsvpn
.
DefaultNoDelay
,
"KCP NoDelay"
)
flag
.
Int
(
kcpInterval
,
obfsvpn
.
DefaultInterval
,
"KCP Interval"
)
flag
.
Int
(
kcpResend
,
obfsvpn
.
DefaultResend
,
"KCP Resend"
)
flag
.
Bool
(
kcpDisableFlowControl
,
obfsvpn
.
DefaultDisableFlowControl
,
"KCP DisableFlowControl"
)
flag
.
Int
(
kcpMTU
,
obfsvpn
.
DefaultMTU
,
"KCP MTU"
)
flag
.
Int64
(
portSeed
,
1
,
"The seed to use for generating random ports"
)
flag
.
Uint
(
portCount
,
100
,
"The number of random ports to listen on"
)
flag
.
String
(
stateDir
,
""
,
"A directory in which to store bridge state"
)
...
...
@@ -257,11 +278,16 @@ func main() {
}
kcpConfig
:=
obfsvpn
.
KCPConfig
{
Enabled
:
cfg
.
kcp
,
ReceiveWindowSize
:
cfg
.
kcpReceiveWindowSize
,
SendWindowSize
:
cfg
.
kcpSendWindowSize
,
WriteBuffer
:
cfg
.
kcpWriteBuffer
,
ReadBuffer
:
cfg
.
kcpReadBuffer
,
Enabled
:
cfg
.
kcp
,
ReceiveWindowSize
:
cfg
.
kcpReceiveWindowSize
,
SendWindowSize
:
cfg
.
kcpSendWindowSize
,
WriteBuffer
:
cfg
.
kcpWriteBuffer
,
ReadBuffer
:
cfg
.
kcpReadBuffer
,
NoDelay
:
cfg
.
kcpNoDelay
,
Interval
:
cfg
.
kcpInterval
,
Resend
:
cfg
.
kcpResend
,
DisableFlowControl
:
cfg
.
kcpDisableFlowControl
,
MTU
:
cfg
.
kcpMTU
,
}
serverCfg
:=
server
.
ServerConfig
{
...
...
This diff is collapsed.
Click to expand it.
obfsvpn/kcp.go
+
40
−
16
View file @
4fdf6cf0
...
...
@@ -7,27 +7,43 @@ import (
)
const
(
DefaultKCPSendWindowSize
int
=
65535
DefaultKCPReceiveWindowSize
int
=
65535
DefaultKCPReadBuffer
int
=
16
*
1024
*
1024
DefaultKCPWriteBuffer
int
=
16
*
1024
*
1024
DefaultKCPSendWindowSize
int
=
65535
DefaultKCPReceiveWindowSize
int
=
65535
DefaultKCPReadBuffer
int
=
16
*
1024
*
1024
DefaultKCPWriteBuffer
int
=
16
*
1024
*
1024
DefaultNoDelay
bool
=
false
DefaultInterval
int
=
40
DefaultResend
int
=
0
DefaultDisableFlowControl
bool
=
false
DefaultMTU
int
=
1400
)
// https://github.com/skywind3000/kcp/blob/master/README.en.md#protocol-configuration
type
KCPConfig
struct
{
Enabled
bool
SendWindowSize
int
ReceiveWindowSize
int
ReadBuffer
int
WriteBuffer
int
Enabled
bool
SendWindowSize
int
ReceiveWindowSize
int
ReadBuffer
int
WriteBuffer
int
NoDelay
bool
Interval
int
Resend
int
DisableFlowControl
bool
MTU
int
}
func
DefaultKCPConfig
()
*
KCPConfig
{
return
&
KCPConfig
{
Enabled
:
true
,
SendWindowSize
:
DefaultKCPSendWindowSize
,
ReceiveWindowSize
:
DefaultKCPReceiveWindowSize
,
ReadBuffer
:
DefaultKCPReadBuffer
,
WriteBuffer
:
DefaultKCPWriteBuffer
,
Enabled
:
true
,
SendWindowSize
:
DefaultKCPSendWindowSize
,
ReceiveWindowSize
:
DefaultKCPReceiveWindowSize
,
ReadBuffer
:
DefaultKCPReadBuffer
,
WriteBuffer
:
DefaultKCPWriteBuffer
,
NoDelay
:
DefaultNoDelay
,
Interval
:
DefaultInterval
,
Resend
:
DefaultResend
,
DisableFlowControl
:
DefaultDisableFlowControl
,
MTU
:
DefaultMTU
,
}
}
...
...
@@ -48,8 +64,16 @@ func GetKCPDialer(kcpConfig KCPConfig, logger func(format string, a ...interface
if
err
:=
kcpSession
.
SetWriteBuffer
(
kcpConfig
.
WriteBuffer
);
err
!=
nil
{
return
nil
,
err
}
// https://github.com/skywind3000/kcp/blob/master/README.en.md#protocol-configuration
kcpSession
.
SetNoDelay
(
1
,
10
,
2
,
1
)
nd
:=
0
if
kcpConfig
.
NoDelay
{
nd
=
1
}
nc
:=
0
if
kcpConfig
.
DisableFlowControl
{
nc
=
1
}
kcpSession
.
SetNoDelay
(
nd
,
kcpConfig
.
Interval
,
kcpConfig
.
Resend
,
nc
)
kcpSession
.
SetMtu
(
kcpConfig
.
MTU
)
return
kcpSession
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment