瀏覽代碼

Merge pull request #30 from SenseUnit/connection_id

connection_id extension support
Snawoot 8 月之前
父節點
當前提交
50bc42cc52
共有 6 個文件被更改,包括 15 次插入0 次删除
  1. 2 0
      README.md
  2. 4 0
      client/client.go
  3. 1 0
      client/config.go
  4. 4 0
      cmd/dtlspipe/main.go
  5. 1 0
      server/config.go
  6. 3 0
      server/server.go

+ 2 - 0
README.md

@@ -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

+ 4 - 0
client/client.go

@@ -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,
 	}

+ 1 - 0
client/config.go

@@ -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 {

+ 4 - 0
cmd/dtlspipe/main.go

@@ -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
@@ -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)
@@ -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)
@@ -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)

+ 1 - 0
server/config.go

@@ -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 {

+ 3 - 0
server/server.go

@@ -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()