From e61bdfc8f1c0968e91837048965668afec40426f Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Sun, 27 Dec 2020 05:49:36 -0800 Subject: [PATCH 1/7] Switched to go modules --- go.mod | 10 +++++++ go.sum | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a790dbd --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/adodon2go/cmux + +go 1.15 + +require ( + github.com/soheilhy/cmux v0.1.4 + golang.org/x/net v0.0.0-20201224014010-6772e930b67b + google.golang.org/grpc v1.31.0 + google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e959981 --- /dev/null +++ b/go.sum @@ -0,0 +1,87 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= +golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200624020401-64a14ca9d1ad h1:uAwc13+y0Y8QZLTYhLCu6lHhnG99ecQU5FYTj8zxAng= +google.golang.org/genproto v0.0.0-20200624020401-64a14ca9d1ad/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3 h1:t+U9ilJcG3/vcPrg4bWCCkkPCN9tiHDcZiIFzQbOTY4= +google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3/go.mod h1:wQWkdCkP0Pl3MzFPvfqTNUnXA2eIVY4eakDiKJvniKc= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From b0ec03f6be80693230592b6a897326e08433c332 Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Sun, 27 Dec 2020 09:20:35 -0800 Subject: [PATCH 2/7] Updated modules --- example_recursive_test.go | 2 +- example_test.go | 2 +- example_tls_test.go | 2 +- go.mod | 3 ++- go.sum | 2 -- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/example_recursive_test.go b/example_recursive_test.go index 1962cd0..80b4e49 100644 --- a/example_recursive_test.go +++ b/example_recursive_test.go @@ -24,7 +24,7 @@ import ( "net/rpc" "strings" - "github.com/soheilhy/cmux" + "github.com/adodon2go/cmux" ) type recursiveHTTPHandler struct{} diff --git a/example_test.go b/example_test.go index 7144f5e..be8b5bb 100644 --- a/example_test.go +++ b/example_test.go @@ -28,7 +28,7 @@ import ( "golang.org/x/net/context" "golang.org/x/net/websocket" - "github.com/soheilhy/cmux" + "github.com/adodon2go/cmux" grpchello "google.golang.org/grpc/examples/helloworld/helloworld" ) diff --git a/example_tls_test.go b/example_tls_test.go index d01f846..556c62a 100644 --- a/example_tls_test.go +++ b/example_tls_test.go @@ -23,7 +23,7 @@ import ( "net/http" "strings" - "github.com/soheilhy/cmux" + "github.com/adodon2go/cmux" ) type anotherHTTPHandler struct{} diff --git a/go.mod b/go.mod index a790dbd..200f54b 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,9 @@ module github.com/adodon2go/cmux go 1.15 require ( - github.com/soheilhy/cmux v0.1.4 golang.org/x/net v0.0.0-20201224014010-6772e930b67b google.golang.org/grpc v1.31.0 google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3 ) + +replace google.golang.org/grpc/examples/helloworld/helloworld => google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3 diff --git a/go.sum b/go.sum index e959981..068875d 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= From d7b7d46d30734da21674f274dd23f892e8ef12ac Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Sun, 27 Dec 2020 10:41:00 -0800 Subject: [PATCH 3/7] Update dependencies in go.mod --- go.mod | 3 +-- go.sum | 62 +++++----------------------------------------------------- 2 files changed, 6 insertions(+), 59 deletions(-) diff --git a/go.mod b/go.mod index 200f54b..99d2628 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.15 require ( golang.org/x/net v0.0.0-20201224014010-6772e930b67b google.golang.org/grpc v1.31.0 - google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3 ) -replace google.golang.org/grpc/examples/helloworld/helloworld => google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3 +replace google.golang.org/grpc => google.golang.org/grpc v1.23.0 diff --git a/go.sum b/go.sum index 068875d..ebbea1b 100644 --- a/go.sum +++ b/go.sum @@ -1,47 +1,20 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -50,36 +23,11 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200624020401-64a14ca9d1ad h1:uAwc13+y0Y8QZLTYhLCu6lHhnG99ecQU5FYTj8zxAng= -google.golang.org/genproto v0.0.0-20200624020401-64a14ca9d1ad/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3 h1:t+U9ilJcG3/vcPrg4bWCCkkPCN9tiHDcZiIFzQbOTY4= -google.golang.org/grpc/examples v0.0.0-20200818224027-0f73133e3aa3/go.mod h1:wQWkdCkP0Pl3MzFPvfqTNUnXA2eIVY4eakDiKJvniKc= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From bdf581d40a44d41cffc69a29fedf14f9fef419d5 Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Mon, 4 Jan 2021 09:19:00 -0800 Subject: [PATCH 4/7] Remove useless files --- example_recursive_test.go | 123 ---------------------------------- example_test.go | 134 -------------------------------------- example_tls_test.go | 89 ------------------------- 3 files changed, 346 deletions(-) delete mode 100644 example_recursive_test.go delete mode 100644 example_test.go delete mode 100644 example_tls_test.go diff --git a/example_recursive_test.go b/example_recursive_test.go deleted file mode 100644 index 80b4e49..0000000 --- a/example_recursive_test.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux_test - -import ( - "crypto/rand" - "crypto/tls" - "fmt" - "log" - "net" - "net/http" - "net/rpc" - "strings" - - "github.com/adodon2go/cmux" -) - -type recursiveHTTPHandler struct{} - -func (h *recursiveHTTPHandler) ServeHTTP(w http.ResponseWriter, - r *http.Request) { - - fmt.Fprintf(w, "example http response") -} - -func recursiveServeHTTP(l net.Listener) { - s := &http.Server{ - Handler: &recursiveHTTPHandler{}, - } - if err := s.Serve(l); err != cmux.ErrListenerClosed { - panic(err) - } -} - -func tlsListener(l net.Listener) net.Listener { - // Load certificates. - certificate, err := tls.LoadX509KeyPair("cert.pem", "key.pem") - if err != nil { - log.Panic(err) - } - - config := &tls.Config{ - Certificates: []tls.Certificate{certificate}, - Rand: rand.Reader, - } - - // Create TLS listener. - tlsl := tls.NewListener(l, config) - return tlsl -} - -type RecursiveRPCRcvr struct{} - -func (r *RecursiveRPCRcvr) Cube(i int, j *int) error { - *j = i * i - return nil -} - -func recursiveServeRPC(l net.Listener) { - s := rpc.NewServer() - if err := s.Register(&RecursiveRPCRcvr{}); err != nil { - panic(err) - } - for { - conn, err := l.Accept() - if err != nil { - if err != cmux.ErrListenerClosed { - panic(err) - } - return - } - go s.ServeConn(conn) - } -} - -// This is an example for serving HTTP, HTTPS, and GoRPC/TLS on the same port. -func Example_recursiveCmux() { - // Create the TCP listener. - l, err := net.Listen("tcp", "127.0.0.1:50051") - if err != nil { - log.Panic(err) - } - - // Create a mux. - tcpm := cmux.New(l) - - // We first match on HTTP 1.1 methods. - httpl := tcpm.Match(cmux.HTTP1Fast()) - - // If not matched, we assume that its TLS. - tlsl := tcpm.Match(cmux.Any()) - tlsl = tlsListener(tlsl) - - // Now, we build another mux recursively to match HTTPS and GoRPC. - // You can use the same trick for SSH. - tlsm := cmux.New(tlsl) - httpsl := tlsm.Match(cmux.HTTP1Fast()) - gorpcl := tlsm.Match(cmux.Any()) - go recursiveServeHTTP(httpl) - go recursiveServeHTTP(httpsl) - go recursiveServeRPC(gorpcl) - - go func() { - if err := tlsm.Serve(); err != cmux.ErrListenerClosed { - panic(err) - } - }() - if err := tcpm.Serve(); !strings.Contains(err.Error(), "use of closed network connection") { - panic(err) - } -} diff --git a/example_test.go b/example_test.go deleted file mode 100644 index be8b5bb..0000000 --- a/example_test.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux_test - -import ( - "fmt" - "io" - "log" - "net" - "net/http" - "net/rpc" - "strings" - - "google.golang.org/grpc" - - "golang.org/x/net/context" - "golang.org/x/net/websocket" - - "github.com/adodon2go/cmux" - grpchello "google.golang.org/grpc/examples/helloworld/helloworld" -) - -type exampleHTTPHandler struct{} - -func (h *exampleHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "example http response") -} - -func serveHTTP(l net.Listener) { - s := &http.Server{ - Handler: &exampleHTTPHandler{}, - } - if err := s.Serve(l); err != cmux.ErrListenerClosed { - panic(err) - } -} - -func EchoServer(ws *websocket.Conn) { - if _, err := io.Copy(ws, ws); err != nil { - panic(err) - } -} - -func serveWS(l net.Listener) { - s := &http.Server{ - Handler: websocket.Handler(EchoServer), - } - if err := s.Serve(l); err != cmux.ErrListenerClosed { - panic(err) - } -} - -type ExampleRPCRcvr struct{} - -func (r *ExampleRPCRcvr) Cube(i int, j *int) error { - *j = i * i - return nil -} - -func serveRPC(l net.Listener) { - s := rpc.NewServer() - if err := s.Register(&ExampleRPCRcvr{}); err != nil { - panic(err) - } - for { - conn, err := l.Accept() - if err != nil { - if err != cmux.ErrListenerClosed { - panic(err) - } - return - } - go s.ServeConn(conn) - } -} - -type grpcServer struct{} - -func (s *grpcServer) SayHello(ctx context.Context, in *grpchello.HelloRequest) ( - *grpchello.HelloReply, error) { - - return &grpchello.HelloReply{Message: "Hello " + in.Name + " from cmux"}, nil -} - -func serveGRPC(l net.Listener) { - grpcs := grpc.NewServer() - grpchello.RegisterGreeterServer(grpcs, &grpcServer{}) - if err := grpcs.Serve(l); err != cmux.ErrListenerClosed { - panic(err) - } -} - -func Example() { - l, err := net.Listen("tcp", "127.0.0.1:50051") - if err != nil { - log.Panic(err) - } - - m := cmux.New(l) - - // We first match the connection against HTTP2 fields. If matched, the - // connection will be sent through the "grpcl" listener. - grpcl := m.Match(cmux.HTTP2HeaderFieldPrefix("content-type", "application/grpc")) - //Otherwise, we match it againts a websocket upgrade request. - wsl := m.Match(cmux.HTTP1HeaderField("Upgrade", "websocket")) - - // Otherwise, we match it againts HTTP1 methods. If matched, - // it is sent through the "httpl" listener. - httpl := m.Match(cmux.HTTP1Fast()) - // If not matched by HTTP, we assume it is an RPC connection. - rpcl := m.Match(cmux.Any()) - - // Then we used the muxed listeners. - go serveGRPC(grpcl) - go serveWS(wsl) - go serveHTTP(httpl) - go serveRPC(rpcl) - - if err := m.Serve(); !strings.Contains(err.Error(), "use of closed network connection") { - panic(err) - } -} diff --git a/example_tls_test.go b/example_tls_test.go deleted file mode 100644 index 556c62a..0000000 --- a/example_tls_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux_test - -import ( - "crypto/rand" - "crypto/tls" - "fmt" - "log" - "net" - "net/http" - "strings" - - "github.com/adodon2go/cmux" -) - -type anotherHTTPHandler struct{} - -func (h *anotherHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "example http response") -} - -func serveHTTP1(l net.Listener) { - s := &http.Server{ - Handler: &anotherHTTPHandler{}, - } - if err := s.Serve(l); err != cmux.ErrListenerClosed { - panic(err) - } -} - -func serveHTTPS(l net.Listener) { - // Load certificates. - certificate, err := tls.LoadX509KeyPair("cert.pem", "key.pem") - if err != nil { - log.Panic(err) - } - - config := &tls.Config{ - Certificates: []tls.Certificate{certificate}, - Rand: rand.Reader, - } - - // Create TLS listener. - tlsl := tls.NewListener(l, config) - - // Serve HTTP over TLS. - serveHTTP1(tlsl) -} - -// This is an example for serving HTTP and HTTPS on the same port. -func Example_bothHTTPAndHTTPS() { - // Create the TCP listener. - l, err := net.Listen("tcp", "127.0.0.1:50051") - if err != nil { - log.Panic(err) - } - - // Create a mux. - m := cmux.New(l) - - // We first match on HTTP 1.1 methods. - httpl := m.Match(cmux.HTTP1Fast()) - - // If not matched, we assume that its TLS. - // - // Note that you can take this listener, do TLS handshake and - // create another mux to multiplex the connections over TLS. - tlsl := m.Match(cmux.Any()) - - go serveHTTP1(httpl) - go serveHTTPS(tlsl) - - if err := m.Serve(); !strings.Contains(err.Error(), "use of closed network connection") { - panic(err) - } -} From 75deba9357b8e05ec77e2bf8a458f5ca180d0e91 Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Tue, 12 Jan 2021 13:20:32 -0800 Subject: [PATCH 5/7] Update module path to vanity import --- go.mod | 7 ++----- go.sum | 25 ------------------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 99d2628..615d1aa 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,7 @@ -module github.com/adodon2go/cmux +module cisco-app-networking.github.io/cmux go 1.15 -require ( - golang.org/x/net v0.0.0-20201224014010-6772e930b67b - google.golang.org/grpc v1.31.0 -) +require golang.org/x/net v0.0.0-20201224014010-6772e930b67b replace google.golang.org/grpc => google.golang.org/grpc v1.23.0 diff --git a/go.sum b/go.sum index ebbea1b..631e237 100644 --- a/go.sum +++ b/go.sum @@ -1,33 +1,8 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 23bb1d7533777adde8e9a79a60783fd283c893bd Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Tue, 12 Jan 2021 13:22:10 -0800 Subject: [PATCH 6/7] Update module path to vanity import --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index 615d1aa..a0fd0d5 100644 --- a/go.mod +++ b/go.mod @@ -3,5 +3,3 @@ module cisco-app-networking.github.io/cmux go 1.15 require golang.org/x/net v0.0.0-20201224014010-6772e930b67b - -replace google.golang.org/grpc => google.golang.org/grpc v1.23.0 From b7bb46d04890a38fce83631791ee8f04923ff40b Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Fri, 29 Jan 2021 13:35:18 -0800 Subject: [PATCH 7/7] Revert module path to its original one --- bench_test.go | 142 --------- cmux_test.go | 763 ----------------------------------------------- go.mod | 2 +- go.sum | 1 - patricia_test.go | 56 ---- 5 files changed, 1 insertion(+), 963 deletions(-) delete mode 100644 bench_test.go delete mode 100644 cmux_test.go delete mode 100644 patricia_test.go diff --git a/bench_test.go b/bench_test.go deleted file mode 100644 index 53b0367..0000000 --- a/bench_test.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux - -import ( - "bytes" - "io" - "net" - "sync" - "testing" - "time" - - "golang.org/x/net/http2" -) - -var ( - benchHTTP1Payload = make([]byte, 4096) - benchHTTP2Payload = make([]byte, 4096) -) - -func init() { - copy(benchHTTP1Payload, []byte("GET http://www.w3.org/ HTTP/1.1")) - copy(benchHTTP2Payload, http2.ClientPreface) -} - -type mockConn struct { - net.Conn - r io.Reader -} - -func (c *mockConn) Read(b []byte) (n int, err error) { - return c.r.Read(b) -} - -func (c *mockConn) SetReadDeadline(time.Time) error { - return nil -} - -func discard(l net.Listener) { - for { - if _, err := l.Accept(); err != nil { - return - } - } -} - -func BenchmarkCMuxConnHTTP1(b *testing.B) { - m := New(nil).(*cMux) - l := m.Match(HTTP1Fast()) - - go discard(l) - - donec := make(chan struct{}) - var wg sync.WaitGroup - wg.Add(b.N) - - b.ResetTimer() - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - wg.Add(1) - m.serve(&mockConn{ - r: bytes.NewReader(benchHTTP1Payload), - }, donec, &wg) - } - }) -} - -func BenchmarkCMuxConnHTTP2(b *testing.B) { - m := New(nil).(*cMux) - l := m.Match(HTTP2()) - go discard(l) - - donec := make(chan struct{}) - var wg sync.WaitGroup - wg.Add(b.N) - - b.ResetTimer() - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - wg.Add(1) - m.serve(&mockConn{ - r: bytes.NewReader(benchHTTP2Payload), - }, donec, &wg) - } - }) -} - -func BenchmarkCMuxConnHTTP1n2(b *testing.B) { - m := New(nil).(*cMux) - l1 := m.Match(HTTP1Fast()) - l2 := m.Match(HTTP2()) - - go discard(l1) - go discard(l2) - - donec := make(chan struct{}) - var wg sync.WaitGroup - - b.ResetTimer() - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - wg.Add(1) - m.serve(&mockConn{ - r: bytes.NewReader(benchHTTP2Payload), - }, donec, &wg) - } - }) -} - -func BenchmarkCMuxConnHTTP2n1(b *testing.B) { - m := New(nil).(*cMux) - l2 := m.Match(HTTP2()) - l1 := m.Match(HTTP1Fast()) - - go discard(l1) - go discard(l2) - - donec := make(chan struct{}) - var wg sync.WaitGroup - - b.ResetTimer() - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - wg.Add(1) - m.serve(&mockConn{ - r: bytes.NewReader(benchHTTP1Payload), - }, donec, &wg) - } - }) -} diff --git a/cmux_test.go b/cmux_test.go deleted file mode 100644 index 6ef66dc..0000000 --- a/cmux_test.go +++ /dev/null @@ -1,763 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux - -import ( - "bytes" - "crypto/rand" - "crypto/tls" - "errors" - "fmt" - "go/build" - "io" - "io/ioutil" - "log" - "net" - "net/http" - "net/rpc" - "os" - "os/exec" - "runtime" - "sort" - "strings" - "sync" - "sync/atomic" - "testing" - "time" - - "golang.org/x/net/http2" - "golang.org/x/net/http2/hpack" -) - -const ( - testHTTP1Resp = "http1" - rpcVal = 1234 -) - -func safeServe(errCh chan<- error, muxl CMux) { - if err := muxl.Serve(); !strings.Contains(err.Error(), "use of closed") { - errCh <- err - } -} - -func safeDial(t *testing.T, addr net.Addr) (*rpc.Client, func()) { - c, err := rpc.Dial(addr.Network(), addr.String()) - if err != nil { - t.Fatal(err) - } - return c, func() { - if err := c.Close(); err != nil { - t.Fatal(err) - } - } -} - -type chanListener struct { - net.Listener - connCh chan net.Conn -} - -func newChanListener() *chanListener { - return &chanListener{connCh: make(chan net.Conn, 1)} -} - -func (l *chanListener) Accept() (net.Conn, error) { - if c, ok := <-l.connCh; ok { - return c, nil - } - return nil, errors.New("use of closed network connection") -} - -func testListener(t *testing.T) (net.Listener, func()) { - l, err := net.Listen("tcp", "127.0.0.1:0") - if err != nil { - t.Fatal(err) - } - var once sync.Once - return l, func() { - once.Do(func() { - if err := l.Close(); err != nil { - t.Fatal(err) - } - }) - } -} - -type testHTTP1Handler struct{} - -func (h *testHTTP1Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, testHTTP1Resp) -} - -func runTestHTTPServer(errCh chan<- error, l net.Listener) { - var mu sync.Mutex - conns := make(map[net.Conn]struct{}) - - defer func() { - mu.Lock() - for c := range conns { - if err := c.Close(); err != nil { - errCh <- err - } - } - mu.Unlock() - }() - - s := &http.Server{ - Handler: &testHTTP1Handler{}, - ConnState: func(c net.Conn, state http.ConnState) { - mu.Lock() - switch state { - case http.StateNew: - conns[c] = struct{}{} - case http.StateClosed: - delete(conns, c) - } - mu.Unlock() - }, - } - if err := s.Serve(l); err != ErrListenerClosed { - errCh <- err - } -} - -func generateTLSCert(t *testing.T) { - err := exec.Command("go", "run", build.Default.GOROOT+"/src/crypto/tls/generate_cert.go", "--host", "*").Run() - if err != nil { - t.Fatal(err) - } -} - -func cleanupTLSCert(t *testing.T) { - err := os.Remove("cert.pem") - if err != nil { - t.Error(err) - } - err = os.Remove("key.pem") - if err != nil { - t.Error(err) - } -} - -func runTestTLSServer(errCh chan<- error, l net.Listener) { - certificate, err := tls.LoadX509KeyPair("cert.pem", "key.pem") - if err != nil { - errCh <- err - log.Printf("1") - return - } - - config := &tls.Config{ - Certificates: []tls.Certificate{certificate}, - Rand: rand.Reader, - } - - tlsl := tls.NewListener(l, config) - runTestHTTPServer(errCh, tlsl) -} - -func runTestHTTP1Client(t *testing.T, addr net.Addr) { - runTestHTTPClient(t, "http", addr) -} - -func runTestTLSClient(t *testing.T, addr net.Addr) { - runTestHTTPClient(t, "https", addr) -} - -func runTestHTTPClient(t *testing.T, proto string, addr net.Addr) { - client := http.Client{ - Timeout: 5 * time.Second, - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }, - } - r, err := client.Get(proto + "://" + addr.String()) - if err != nil { - t.Fatal(err) - } - - defer func() { - if err = r.Body.Close(); err != nil { - t.Fatal(err) - } - }() - - b, err := ioutil.ReadAll(r.Body) - if err != nil { - t.Fatal(err) - } - if string(b) != testHTTP1Resp { - t.Fatalf("invalid response: want=%s got=%s", testHTTP1Resp, b) - } -} - -type TestRPCRcvr struct{} - -func (r TestRPCRcvr) Test(i int, j *int) error { - *j = i - return nil -} - -func runTestRPCServer(errCh chan<- error, l net.Listener) { - s := rpc.NewServer() - if err := s.Register(TestRPCRcvr{}); err != nil { - errCh <- err - } - for { - c, err := l.Accept() - if err != nil { - if err != ErrListenerClosed { - errCh <- err - } - return - } - go s.ServeConn(c) - } -} - -func runTestRPCClient(t *testing.T, addr net.Addr) { - c, cleanup := safeDial(t, addr) - defer cleanup() - - var num int - if err := c.Call("TestRPCRcvr.Test", rpcVal, &num); err != nil { - t.Fatal(err) - } - - if num != rpcVal { - t.Errorf("wrong rpc response: want=%d got=%v", rpcVal, num) - } -} - -const ( - handleHTTP1Close = 1 - handleHTTP1Request = 2 - handleAnyClose = 3 - handleAnyRequest = 4 -) - -func TestTimeout(t *testing.T) { - defer leakCheck(t)() - lis, Close := testListener(t) - defer Close() - result := make(chan int, 5) - testDuration := time.Millisecond * 500 - m := New(lis) - m.SetReadTimeout(testDuration) - http1 := m.Match(HTTP1Fast()) - any := m.Match(Any()) - go func() { - _ = m.Serve() - }() - go func() { - con, err := http1.Accept() - if err != nil { - result <- handleHTTP1Close - } else { - _, _ = con.Write([]byte("http1")) - _ = con.Close() - result <- handleHTTP1Request - } - }() - go func() { - con, err := any.Accept() - if err != nil { - result <- handleAnyClose - } else { - _, _ = con.Write([]byte("any")) - _ = con.Close() - result <- handleAnyRequest - } - }() - time.Sleep(testDuration) // wait to prevent timeouts on slow test-runners - client, err := net.Dial("tcp", lis.Addr().String()) - if err != nil { - log.Fatal("testTimeout client failed: ", err) - } - defer func() { - _ = client.Close() - }() - time.Sleep(testDuration / 2) - if len(result) != 0 { - log.Print("tcp ") - t.Fatal("testTimeout failed: accepted to fast: ", len(result)) - } - _ = client.SetReadDeadline(time.Now().Add(testDuration * 3)) - buffer := make([]byte, 10) - rl, err := client.Read(buffer) - if err != nil { - t.Fatal("testTimeout failed: client error: ", err, rl) - } - Close() - if rl != 3 { - log.Print("testTimeout failed: response from wrong sevice ", rl) - } - if string(buffer[0:3]) != "any" { - log.Print("testTimeout failed: response from wrong sevice ") - } - time.Sleep(testDuration * 2) - if len(result) != 2 { - t.Fatal("testTimeout failed: accepted to less: ", len(result)) - } - if a := <-result; a != handleAnyRequest { - t.Fatal("testTimeout failed: any rule did not match") - } - if a := <-result; a != handleHTTP1Close { - t.Fatal("testTimeout failed: no close an http rule") - } -} - -func TestRead(t *testing.T) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - const payload = "hello world\r\n" - const mult = 2 - - writer, reader := net.Pipe() - go func() { - if _, err := io.WriteString(writer, strings.Repeat(payload, mult)); err != nil { - t.Fatal(err) - } - if err := writer.Close(); err != nil { - t.Fatal(err) - } - }() - - l := newChanListener() - defer close(l.connCh) - l.connCh <- reader - muxl := New(l) - // Register a bogus matcher to force buffering exactly the right amount. - // Before this fix, this would trigger a bug where `Read` would incorrectly - // report `io.EOF` when only the buffer had been consumed. - muxl.Match(func(r io.Reader) bool { - var b [len(payload)]byte - _, _ = r.Read(b[:]) - return false - }) - anyl := muxl.Match(Any()) - go safeServe(errCh, muxl) - muxedConn, err := anyl.Accept() - if err != nil { - t.Fatal(err) - } - for i := 0; i < mult; i++ { - var b [len(payload)]byte - n, err := muxedConn.Read(b[:]) - if err != nil { - t.Error(err) - continue - } - if e := len(b); n != e { - t.Errorf("expected to read %d bytes, but read %d bytes", e, n) - } - } - var b [1]byte - if _, err := muxedConn.Read(b[:]); err != io.EOF { - t.Errorf("unexpected error %v, expected %v", err, io.EOF) - } -} - -func TestAny(t *testing.T) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - l, cleanup := testListener(t) - defer cleanup() - - muxl := New(l) - httpl := muxl.Match(Any()) - - go runTestHTTPServer(errCh, httpl) - go safeServe(errCh, muxl) - - runTestHTTP1Client(t, l.Addr()) -} - -func TestTLS(t *testing.T) { - generateTLSCert(t) - defer cleanupTLSCert(t) - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - l, cleanup := testListener(t) - defer cleanup() - - muxl := New(l) - tlsl := muxl.Match(TLS()) - httpl := muxl.Match(Any()) - - go runTestTLSServer(errCh, tlsl) - go runTestHTTPServer(errCh, httpl) - go safeServe(errCh, muxl) - - runTestHTTP1Client(t, l.Addr()) - runTestTLSClient(t, l.Addr()) -} - -func TestHTTP2(t *testing.T) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - writer, reader := net.Pipe() - go func() { - if _, err := io.WriteString(writer, http2.ClientPreface); err != nil { - t.Fatal(err) - } - if err := writer.Close(); err != nil { - t.Fatal(err) - } - }() - - l := newChanListener() - l.connCh <- reader - muxl := New(l) - // Register a bogus matcher that only reads one byte. - muxl.Match(func(r io.Reader) bool { - var b [1]byte - _, _ = r.Read(b[:]) - return false - }) - h2l := muxl.Match(HTTP2()) - go safeServe(errCh, muxl) - muxedConn, err := h2l.Accept() - close(l.connCh) - if err != nil { - t.Fatal(err) - } - var b [len(http2.ClientPreface)]byte - var n int - // We have the sniffed buffer first... - if n, err = muxedConn.Read(b[:]); err == io.EOF { - t.Fatal(err) - } - // and then we read from the source. - if _, err = muxedConn.Read(b[n:]); err != io.EOF { - t.Fatal(err) - } - if string(b[:]) != http2.ClientPreface { - t.Errorf("got unexpected read %s, expected %s", b, http2.ClientPreface) - } -} - -func TestHTTP2MatchHeaderField(t *testing.T) { - testHTTP2MatchHeaderField(t, HTTP2HeaderField, "value", "value", "anothervalue") -} - -func TestHTTP2MatchHeaderFieldPrefix(t *testing.T) { - testHTTP2MatchHeaderField(t, HTTP2HeaderFieldPrefix, "application/grpc+proto", "application/grpc", "application/json") -} - -func testHTTP2MatchHeaderField( - t *testing.T, - matcherConstructor func(string, string) Matcher, - headerValue string, - matchValue string, - notMatchValue string, -) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - name := "name" - writer, reader := net.Pipe() - go func() { - if _, err := io.WriteString(writer, http2.ClientPreface); err != nil { - t.Fatal(err) - } - var buf bytes.Buffer - enc := hpack.NewEncoder(&buf) - if err := enc.WriteField(hpack.HeaderField{Name: name, Value: headerValue}); err != nil { - t.Fatal(err) - } - framer := http2.NewFramer(writer, nil) - err := framer.WriteHeaders(http2.HeadersFrameParam{ - StreamID: 1, - BlockFragment: buf.Bytes(), - EndStream: true, - EndHeaders: true, - }) - if err != nil { - t.Fatal(err) - } - if err := writer.Close(); err != nil { - t.Fatal(err) - } - }() - - l := newChanListener() - l.connCh <- reader - muxl := New(l) - // Register a bogus matcher that only reads one byte. - muxl.Match(func(r io.Reader) bool { - var b [1]byte - _, _ = r.Read(b[:]) - return false - }) - // Create a matcher that cannot match the response. - muxl.Match(matcherConstructor(name, notMatchValue)) - // Then match with the expected field. - h2l := muxl.Match(matcherConstructor(name, matchValue)) - go safeServe(errCh, muxl) - muxedConn, err := h2l.Accept() - close(l.connCh) - if err != nil { - t.Fatal(err) - } - var b [len(http2.ClientPreface)]byte - // We have the sniffed buffer first... - if _, err := muxedConn.Read(b[:]); err == io.EOF { - t.Fatal(err) - } - if string(b[:]) != http2.ClientPreface { - t.Errorf("got unexpected read %s, expected %s", b, http2.ClientPreface) - } -} - -func TestHTTPGoRPC(t *testing.T) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - l, cleanup := testListener(t) - defer cleanup() - - muxl := New(l) - httpl := muxl.Match(HTTP2(), HTTP1Fast()) - rpcl := muxl.Match(Any()) - - go runTestHTTPServer(errCh, httpl) - go runTestRPCServer(errCh, rpcl) - go safeServe(errCh, muxl) - - runTestHTTP1Client(t, l.Addr()) - runTestRPCClient(t, l.Addr()) -} - -func TestErrorHandler(t *testing.T) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - l, cleanup := testListener(t) - defer cleanup() - - muxl := New(l) - httpl := muxl.Match(HTTP2(), HTTP1Fast()) - - go runTestHTTPServer(errCh, httpl) - go safeServe(errCh, muxl) - - var errCount uint32 - muxl.HandleError(func(err error) bool { - if atomic.AddUint32(&errCount, 1) == 1 { - if _, ok := err.(ErrNotMatched); !ok { - t.Errorf("unexpected error: %v", err) - } - } - return true - }) - - c, cleanup := safeDial(t, l.Addr()) - defer cleanup() - - var num int - for atomic.LoadUint32(&errCount) == 0 { - if err := c.Call("TestRPCRcvr.Test", rpcVal, &num); err == nil { - // The connection is simply closed. - t.Errorf("unexpected rpc success after %d errors", atomic.LoadUint32(&errCount)) - } - } -} - -func TestMultipleMatchers(t *testing.T) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - l, cleanup := testListener(t) - defer cleanup() - - matcher := func(r io.Reader) bool { - return true - } - unmatcher := func(r io.Reader) bool { - return false - } - - muxl := New(l) - lis := muxl.Match(unmatcher, matcher, unmatcher) - - go runTestHTTPServer(errCh, lis) - go safeServe(errCh, muxl) - - runTestHTTP1Client(t, l.Addr()) -} - -func TestClose(t *testing.T) { - defer leakCheck(t)() - errCh := make(chan error) - defer func() { - select { - case err := <-errCh: - t.Fatal(err) - default: - } - }() - l := newChanListener() - - c1, c2 := net.Pipe() - - muxl := New(l) - anyl := muxl.Match(Any()) - - go safeServe(errCh, muxl) - - l.connCh <- c1 - - // First connection goes through. - if _, err := anyl.Accept(); err != nil { - t.Fatal(err) - } - - // Second connection is sent - l.connCh <- c2 - - // Listener is closed. - close(l.connCh) - - // Second connection either goes through or it is closed. - if _, err := anyl.Accept(); err != nil { - if err != ErrListenerClosed { - t.Fatal(err) - } - // The error is either io.ErrClosedPipe or net.OpError wrapping - // a net.pipeError depending on the go version. - if _, err := c2.Read([]byte{}); !strings.Contains(err.Error(), "closed") { - t.Fatalf("connection is not closed and is leaked: %v", err) - } - } -} - -// Cribbed from google.golang.org/grpc/test/end2end_test.go. - -// interestingGoroutines returns all goroutines we care about for the purpose -// of leak checking. It excludes testing or runtime ones. -func interestingGoroutines() (gs []string) { - buf := make([]byte, 2<<20) - buf = buf[:runtime.Stack(buf, true)] - for _, g := range strings.Split(string(buf), "\n\n") { - sl := strings.SplitN(g, "\n", 2) - if len(sl) != 2 { - continue - } - stack := strings.TrimSpace(sl[1]) - if strings.HasPrefix(stack, "testing.RunTests") { - continue - } - - if stack == "" || - strings.Contains(stack, "main.main()") || - strings.Contains(stack, "testing.Main(") || - strings.Contains(stack, "runtime.goexit") || - strings.Contains(stack, "created by runtime.gc") || - strings.Contains(stack, "interestingGoroutines") || - strings.Contains(stack, "runtime.MHeap_Scavenger") { - continue - } - gs = append(gs, g) - } - sort.Strings(gs) - return -} - -// leakCheck snapshots the currently-running goroutines and returns a -// function to be run at the end of tests to see whether any -// goroutines leaked. -func leakCheck(t testing.TB) func() { - orig := map[string]bool{} - for _, g := range interestingGoroutines() { - orig[g] = true - } - return func() { - // Loop, waiting for goroutines to shut down. - // Wait up to 5 seconds, but finish as quickly as possible. - deadline := time.Now().Add(5 * time.Second) - for { - var leaked []string - for _, g := range interestingGoroutines() { - if !orig[g] { - leaked = append(leaked, g) - } - } - if len(leaked) == 0 { - return - } - if time.Now().Before(deadline) { - time.Sleep(50 * time.Millisecond) - continue - } - for _, g := range leaked { - t.Errorf("Leaked goroutine: %v", g) - } - return - } - } -} diff --git a/go.mod b/go.mod index a0fd0d5..b7d9bde 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module cisco-app-networking.github.io/cmux +module github.com/soheilhy/cmux go 1.15 diff --git a/go.sum b/go.sum index 631e237..12656ae 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= diff --git a/patricia_test.go b/patricia_test.go deleted file mode 100644 index c13cbcf..0000000 --- a/patricia_test.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux - -import ( - "strings" - "testing" -) - -func testPTree(t *testing.T, strs ...string) { - pt := newPatriciaTreeString(strs...) - for _, s := range strs { - if !pt.match(strings.NewReader(s)) { - t.Errorf("%s is not matched by %s", s, s) - } - - if !pt.matchPrefix(strings.NewReader(s + s)) { - t.Errorf("%s is not matched as a prefix by %s", s+s, s) - } - - if pt.match(strings.NewReader(s + s)) { - t.Errorf("%s matches %s", s+s, s) - } - - // The following tests are just to catch index out of - // range and off-by-one errors and not the functionality. - pt.matchPrefix(strings.NewReader(s[:len(s)-1])) - pt.match(strings.NewReader(s[:len(s)-1])) - pt.matchPrefix(strings.NewReader(s + "$")) - pt.match(strings.NewReader(s + "$")) - } -} - -func TestPatriciaOnePrefix(t *testing.T) { - testPTree(t, "prefix") -} - -func TestPatriciaNonOverlapping(t *testing.T) { - testPTree(t, "foo", "bar", "dummy") -} - -func TestPatriciaOverlapping(t *testing.T) { - testPTree(t, "foo", "far", "farther", "boo", "ba", "bar") -}