Skip to content

Commit

Permalink
Merge pull request #30 from SenseUnit/connection_id
Browse files Browse the repository at this point in the history
connection_id extension support
  • Loading branch information
Snawoot authored Jul 26, 2024
2 parents 23c76dc + 7ab7bb2 commit 50bc42c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ dtlspipe version
Print program version and exit.
Options:
-cid
enable connection_id extension (default true)
-ciphers value
colon-separated list of ciphers to use
-cpuprofile string
Expand Down
4 changes: 4 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func New(cfg *Config) (*Client, error) {
CipherSuites: cfg.CipherSuites,
EllipticCurves: cfg.EllipticCurves,
}
if cfg.EnableCID {
client.dtlsConfig.ConnectionIDGenerator = dtls.OnlySendCIDGenerator()
}

lc := udp.ListenConfig{
Backlog: Backlog,
}
Expand Down
1 change: 1 addition & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
StaleMode util.StaleMode
TimeLimitFunc func() time.Duration
AllowFunc func(net.Addr) bool
EnableCID bool
}

func (cfg *Config) populateDefaults() *Config {
Expand Down
4 changes: 4 additions & 0 deletions cmd/dtlspipe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ var (
mtu = flag.Int("mtu", 1400, "MTU used for DTLS fragments")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
skipHelloVerify = flag.Bool("skip-hello-verify", true, "(server only) skip hello verify request. Useful to workaround DPI")
connectionIDExt = flag.Bool("cid", true, "enable connection_id extension")
ciphersuites = cipherlistArg{}
curves = curvelistArg{}
staleMode = util.EitherStale
Expand Down Expand Up @@ -253,6 +254,7 @@ func cmdClient(bindAddress, remoteAddress string) int {
StaleMode: staleMode,
TimeLimitFunc: util.TimeLimitFunc(timeLimit.low, timeLimit.high),
AllowFunc: util.AllowByRatelimit(rateLimit.value),
EnableCID: *connectionIDExt,
}

clt, err := client.New(&cfg)
Expand Down Expand Up @@ -306,6 +308,7 @@ func cmdHoppingClient(args []string) int {
StaleMode: staleMode,
TimeLimitFunc: util.TimeLimitFunc(timeLimit.low, timeLimit.high),
AllowFunc: util.AllowByRatelimit(rateLimit.value),
EnableCID: *connectionIDExt,
}

clt, err := client.New(&cfg)
Expand Down Expand Up @@ -345,6 +348,7 @@ func cmdServer(bindAddress, remoteAddress string) int {
StaleMode: staleMode,
TimeLimitFunc: util.TimeLimitFunc(timeLimit.low, timeLimit.high),
AllowFunc: util.AllowByRatelimit(rateLimit.value),
EnableCID: *connectionIDExt,
}

srv, err := server.New(&cfg)
Expand Down
1 change: 1 addition & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
StaleMode util.StaleMode
TimeLimitFunc func() time.Duration
AllowFunc func(net.Addr) bool
EnableCID bool
}

func (cfg *Config) populateDefaults() *Config {
Expand Down
3 changes: 3 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func New(cfg *Config) (*Server, error) {
return nil
},
}
if cfg.EnableCID {
srv.dtlsConfig.ConnectionIDGenerator = dtls.RandomCIDGenerator(8)
}
srv.listener, err = dtls.Listen("udp", net.UDPAddrFromAddrPort(lAddrPort), srv.dtlsConfig)
if err != nil {
cancelCtx()
Expand Down

0 comments on commit 50bc42c

Please sign in to comment.