aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe <me@christine.website>2022-11-23 21:56:18 -0500
committerXe <me@christine.website>2022-11-23 21:56:18 -0500
commitc62e73f9f8145655485ecf36e8187a5652521855 (patch)
treebfd9119316785a2ea7d7fd0bdf889f62087dd9b2
parent58385c715cd31ce4c89e555167b5ae2cf5306ad8 (diff)
downloadx-1.3.0.tar.xz
x-1.3.0.zip
remove tun2v1.3.0
Signed-off-by: Xe <me@christine.website>
-rw-r--r--go.mod12
-rw-r--r--go.sum40
-rw-r--r--gomod2nix.toml36
-rw-r--r--tun2/backend.go78
-rw-r--r--tun2/backend_test.go212
-rw-r--r--tun2/client.go171
-rw-r--r--tun2/client_test.go21
-rw-r--r--tun2/connection.go162
-rw-r--r--tun2/doc.go11
-rw-r--r--tun2/server.go480
-rw-r--r--tun2/server_test.go171
-rw-r--r--tun2/storage_test.go100
12 files changed, 0 insertions, 1494 deletions
diff --git a/go.mod b/go.mod
index 60a5aec..eead138 100644
--- a/go.mod
+++ b/go.mod
@@ -11,7 +11,6 @@ require (
github.com/bwmarrin/discordgo v0.26.1
github.com/chai2010/webp v1.1.1
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd
- github.com/dgryski/go-failure v0.0.0-20151001134759-4963dbd58fd0
github.com/disintegration/imaging v1.6.1
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51
github.com/fogleman/primitive v0.0.0-20190214200932-673f57e7b1b5
@@ -35,13 +34,10 @@ require (
github.com/posener/complete v1.2.3
github.com/rs/cors v1.8.2
github.com/sebest/xff v0.0.0-20210106013422-671bd2870b3a
- github.com/streamrail/concurrent-map v0.0.0-20160823150647-8bf1e9bacbf6
github.com/sycamoreone/orc v0.0.0-20150204213357-1627eaec2699
github.com/tetratelabs/wazero v1.0.0-pre.3
github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119
- github.com/xtaci/kcp-go v5.4.20+incompatible
- github.com/xtaci/smux v2.0.1+incompatible
go4.org v0.0.0-20190313082347-94abd6928b1d
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f
golang.org/x/exp/errors v0.0.0-20190510132918-efd6b22b2522
@@ -58,7 +54,6 @@ require (
require (
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
- github.com/aclements/go-moremath v0.0.0-20190506201756-286cc0be6f75 // indirect
github.com/akutz/memconn v0.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/aws/aws-sdk-go-v2 v1.16.14 // indirect
@@ -75,7 +70,6 @@ require (
github.com/aws/smithy-go v1.13.2 // indirect
github.com/coreos/go-iptables v0.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/dgryski/go-onlinestats v0.0.0-20170612111826-1c7d19468768 // indirect
github.com/eaburns/peggy v0.0.0-20190420135231-b61cdde6efe6 // indirect
github.com/eaburns/pretty v0.0.0-20190404101635-2e1d2550ef0b // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
@@ -100,8 +94,6 @@ require (
github.com/jsimonetti/rtnetlink v1.1.2-0.20220408201609-d380b505068b // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.15.4 // indirect
- github.com/klauspost/cpuid v1.2.1 // indirect
- github.com/klauspost/reedsolomon v1.9.2 // indirect
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
@@ -121,14 +113,10 @@ require (
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 // indirect
github.com/tcnksm/go-httpstat v0.2.0 // indirect
- github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
- github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b // indirect
- github.com/tjfoc/gmsm v1.0.1 // indirect
github.com/u-root/uio v0.0.0-20220204230159-dac05f7d2cb4 // indirect
github.com/vishvananda/netlink v1.1.1-0.20211118161826-650dca95af54 // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
github.com/x448/float16 v0.8.4 // indirect
- github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae // indirect
github.com/yawning/bulb v0.0.0-20170405033506-85d80d893c3d // indirect
go.etcd.io/bbolt v1.3.2 // indirect
go4.org/mem v0.0.0-20210711025021-927187094b94 // indirect
diff --git a/go.sum b/go.sum
index bd79a0a..df4243a 100644
--- a/go.sum
+++ b/go.sum
@@ -43,14 +43,10 @@ github.com/McKael/madon/v2 v2.0.0-20180929094633-c679abc985d6 h1:9cJcTOeILzInNo+
github.com/McKael/madon/v2 v2.0.0-20180929094633-c679abc985d6/go.mod h1:mvlJhxZCchfiasx3XvN3hBu5RekGwTDm09dKlSM/dQQ=
github.com/Yawning/bulb v0.0.0-20170405033506-85d80d893c3d h1:ASfbc4vPGK69qbMO5qqRtGxfPvUmfbaK1ryEBv9WnQQ=
github.com/Yawning/bulb v0.0.0-20170405033506-85d80d893c3d/go.mod h1:v1YQIDSfaeRRehor57unRn66SBtmgAzxfsCpKIV998I=
-github.com/aclements/go-moremath v0.0.0-20190506201756-286cc0be6f75 h1:OMm3VB/wrXTgQaFh/2z7xTH6fqUy3Q77ybHjmAJ/Ca4=
-github.com/aclements/go-moremath v0.0.0-20190506201756-286cc0be6f75/go.mod h1:idZL3yvz4kzx1dsBOAC+oYv6L92P1oFEhUXUB1A/lwQ=
github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A=
github.com/akutz/memconn v0.1.0/go.mod h1:Jo8rI7m0NieZyLI5e2CDlRdRqRRB4S7Xp77ukDjH+Fw=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 h1:Kk6a4nehpJ3UuJRqlA3JxYxBZEqCeOmATOvrbT4p9RA=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
-github.com/aws/aws-sdk-go v1.44.144 h1:mMWdnYL8HZsobrQe1mwvQ18Xt8UbOVhWgipjuma5Mkg=
-github.com/aws/aws-sdk-go v1.44.144/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.44.145 h1:KMVRrIyjBsNz3xGPuHIRnhIuKlb5h3Ii5e5jbi3cgnc=
github.com/aws/aws-sdk-go v1.44.145/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v1.11.2/go.mod h1:SQfA+m2ltnu1cA0soUkj4dRSsmITiVQUJvBIZjzfPyQ=
@@ -81,8 +77,6 @@ github.com/aws/smithy-go v1.13.2 h1:TBLKyeJfXTrTXRHmsv4qWt9IQGYyWThLYaJWSahTOGE=
github.com/aws/smithy-go v1.13.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/birkelund/boltdbcache v1.0.0 h1:9DlhGw3Gp0DenvEQ7qNVYvz0b4Oi/zAJin+cR0ubpOA=
github.com/birkelund/boltdbcache v1.0.0/go.mod h1:WgJWF40tV+4K0Q7MxAPbWEIkgs4AVUB7EyKVds0EgfQ=
-github.com/bwmarrin/discordgo v0.25.0 h1:NXhdfHRNxtwso6FPdzW2i3uBvvU7UIQTghmV2T4nqAs=
-github.com/bwmarrin/discordgo v0.25.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/bwmarrin/discordgo v0.26.1 h1:AIrM+g3cl+iYBr4yBxCBp9tD9jR3K7upEjl0d89FRkE=
github.com/bwmarrin/discordgo v0.26.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -103,10 +97,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/dgryski/go-failure v0.0.0-20151001134759-4963dbd58fd0 h1:SJzP6kZNFsdxFN4fRtVXu2yrf8QrKnofjQouzaCn36w=
-github.com/dgryski/go-failure v0.0.0-20151001134759-4963dbd58fd0/go.mod h1:vVcpVd0tzL5XdRrkHax1asNJsHVpgA0cd9fHPHU5a/w=
-github.com/dgryski/go-onlinestats v0.0.0-20170612111826-1c7d19468768 h1:Xzl7CSuSnGsyU+9xmSU2h8w3d7Tnis66xeoNN207tLo=
-github.com/dgryski/go-onlinestats v0.0.0-20170612111826-1c7d19468768/go.mod h1:alfmlCqcg4uw9jaoIU1nOp9RFdJLMuu8P07BCEgpgoo=
github.com/disintegration/imaging v1.6.1 h1:JnBbK6ECIZb1NsWIikP9pd8gIlTIRx7fuDNpU9fsxOE=
github.com/disintegration/imaging v1.6.1/go.mod h1:xuIt+sRxDFrHS0drzXUlCJthkJ8k7lkkUojDSR247MQ=
github.com/eaburns/peggy v0.0.0-20180405011029-d685ddd3cbcb/go.mod h1:5tfPwI6ukiK3W5vJzkj5MBQKHHY9Gcy2y6k1FC/23Xk=
@@ -134,8 +124,6 @@ github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzP
github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og=
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
-github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc=
-github.com/garyburd/redigo v1.6.3/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
github.com/garyburd/redigo v1.6.4 h1:LFu2R3+ZOPgSMWMOL+saa/zXRjw0ID2G8FepO53BGlg=
github.com/garyburd/redigo v1.6.4/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
@@ -285,14 +273,9 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.15.4 h1:1kn4/7MepF/CHmYub99/nNX8az0IJjfSOU/jbnTVfqQ=
github.com/klauspost/compress v1.15.4/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
-github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
-github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
-github.com/klauspost/reedsolomon v1.9.2 h1:E9CMS2Pqbv+C7tsrYad4YC9MfhnMVWhMRsTi7U0UB18=
-github.com/klauspost/reedsolomon v1.9.2/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4=
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a h1:+RR6SqnTkDLWyICxS1xpjCi/3dhyV+TgZwA6Ww3KncQ=
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a/go.mod h1:YTtCCM3ryyfiu4F7t8HQ1mxvp1UBdWM2r6Xa+nGWvDk=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
-github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -340,15 +323,11 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
-github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
-github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
github.com/otiai10/copy v1.9.0 h1:7KFNiCgZ91Ru4qW4CWPf/7jqtxLagGRmIxWldPP9VY4=
github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3FczI=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
-github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
-github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/otiai10/mint v1.4.0 h1:umwcf7gbpEwf7WFzqmWwSv0CzbeMsae2u9ZvpP8j2q4=
github.com/otiai10/mint v1.4.0/go.mod h1:gifjb2MYOoULtKLqUAEILUG/9KONW6f7YsJ6vQLTlFI=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
@@ -371,8 +350,6 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
-github.com/rogpeppe/go-internal v1.8.1-0.20211023094830-115ce09fd6b4 h1:Ha8xCaq6ln1a+R91Km45Oq6lPXj2Mla6CRJYcuV2h1w=
-github.com/rogpeppe/go-internal v1.8.1-0.20211023094830-115ce09fd6b4/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
@@ -385,8 +362,6 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM=
-github.com/streamrail/concurrent-map v0.0.0-20160823150647-8bf1e9bacbf6 h1:XklXvOrWxWCDX2n4vdEQWkjuIP820XD6C4kF0O0FzH4=
-github.com/streamrail/concurrent-map v0.0.0-20160823150647-8bf1e9bacbf6/go.mod h1:yqDD2twFAqxvvH5gtpwwgLsj5L1kbNwtoPoDOwBzXcs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -405,14 +380,8 @@ github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 h1:zrsUcqrG2uQ
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85/go.mod h1:NzVQi3Mleb+qzq8VmcWpSkcSYxXIg0DkI6XDzpVkhJ0=
github.com/tcnksm/go-httpstat v0.2.0 h1:rP7T5e5U2HfmOBmZzGgGZjBQ5/GluWUylujl0tJ04I0=
github.com/tcnksm/go-httpstat v0.2.0/go.mod h1:s3JVJFtQxtBEBC9dwcdTTXS9xFnM3SXAZwPG41aurT8=
-github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7SJEOqkIdNDGJXrQIhuIx9D2DBXjavSU=
-github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
-github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b h1:mnG1fcsIB1d/3vbkBak2MM0u+vhGhlQwpeimUi7QncM=
-github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
github.com/tetratelabs/wazero v1.0.0-pre.3 h1:Z5fbogMUGcERzaQb9mQU8+yJSy0bVvv2ce3dfR4wcZg=
github.com/tetratelabs/wazero v1.0.0-pre.3/go.mod h1:M8UDNECGm/HVjOfq0EOe4QfCY9Les1eq54IChMLETbc=
-github.com/tjfoc/gmsm v1.0.1 h1:R11HlqhXkDospckjZEihx9SW/2VW0RgdwrykyWMFOQU=
-github.com/tjfoc/gmsm v1.0.1/go.mod h1:XxO4hdhhrzAd+G4CjDqaOkd0hUzmtPR/d3EiBBMn/wc=
github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef h1:7D6Nm4D6f0ci9yttWaKjM1TMAXrH5Su72dojqYGntFY=
github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef/go.mod h1:WLFStEdnJXpjK8kd4qKLwQKX/1vrDzp5BcDyiZJBHJM=
github.com/u-root/uio v0.0.0-20210528114334-82958018845c/go.mod h1:LpEX5FO/cB+WF4TYGY1V5qktpaZLkKkSegbr0V4eYXA=
@@ -432,12 +401,6 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119 h1:YyPWX3jLOtYKulBR6AScGIs74lLrJcgeKRwcbAuQOG4=
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119/go.mod h1:/nuTSlK+okRfR/vnIPqR89fFKonnWPiZymN5ydRJkX8=
-github.com/xtaci/kcp-go v5.4.20+incompatible h1:TN1uey3Raw0sTz0Fg8GkfM0uH3YwzhnZWQ1bABv5xAg=
-github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE=
-github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae h1:J0GxkO96kL4WF+AIT3M4mfUVinOCPgf2uUWYFUzN0sM=
-github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE=
-github.com/xtaci/smux v2.0.1+incompatible h1:4NrCD5VzuFktMCxK08IShR0C5vKyNICJRShUzvk0U34=
-github.com/xtaci/smux v2.0.1+incompatible/go.mod h1:f+nYm6SpuHMy/SH0zpbvAFHT1QoMcgLOsWcFip5KfPw=
github.com/yawning/bulb v0.0.0-20170405033506-85d80d893c3d h1:74VDH65v2A5bu/HCyrRpGJ8tEZ6PY2MXUMDh9YilfPs=
github.com/yawning/bulb v0.0.0-20170405033506-85d80d893c3d/go.mod h1:2ickkGiASLFhjpaFnwRS1qr2yaY7EgGk73v+DIOL5Bo=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -549,7 +512,6 @@ golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
-golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
@@ -624,13 +586,11 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
-golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
diff --git a/gomod2nix.toml b/gomod2nix.toml
index 376f860..8713053 100644
--- a/gomod2nix.toml
+++ b/gomod2nix.toml
@@ -13,9 +13,6 @@ schema = 3
[mod."github.com/Yawning/bulb"]
version = "v0.0.0-20170405033506-85d80d893c3d"
hash = "sha256-GEFdZJl/T0khRN6me0hBMxD8Dirmc/agr62tsuxh8GQ="
- [mod."github.com/aclements/go-moremath"]
- version = "v0.0.0-20190506201756-286cc0be6f75"
- hash = "sha256-eHnSUgrdMZrcJITle8v2qvKSTEfjtFV3+UIeY3tbdvA="
[mod."github.com/akutz/memconn"]
version = "v0.1.0"
hash = "sha256-WOs/RQYjQbn41ui8ztHgWSd4jxydE+fvIrl/0dmHD9Y="
@@ -79,12 +76,6 @@ schema = 3
[mod."github.com/davecgh/go-spew"]
version = "v1.1.1"
hash = "sha256-nhzSUrE1fCkN0+RL04N4h8jWmRFPPPWbCuDc7Ss0akI="
- [mod."github.com/dgryski/go-failure"]
- version = "v0.0.0-20151001134759-4963dbd58fd0"
- hash = "sha256-wHs8m9sxmCmvZuzIngtO9X8blthbE6jCgUIOirv1Ro0="
- [mod."github.com/dgryski/go-onlinestats"]
- version = "v0.0.0-20170612111826-1c7d19468768"
- hash = "sha256-ABQ0XYHbeIA666j4u0Q/hEobgQggFaHmpacdavlGqbk="
[mod."github.com/disintegration/imaging"]
version = "v1.6.1"
hash = "sha256-3IWhzlxuMQIQzhTYUT6SiToBjOzR9kfyoDCh1EetqgQ="
@@ -190,12 +181,6 @@ schema = 3
[mod."github.com/klauspost/compress"]
version = "v1.15.4"
hash = "sha256-U6v9tYD16Tep9PuqRwCjrzXfj1IfV3KB54Qwnzko+xY="
- [mod."github.com/klauspost/cpuid"]
- version = "v1.2.1"
- hash = "sha256-PZG2qUuB1LglFF7EG7Hy4N8sXQqOu5TW3esMnSHj4YA="
- [mod."github.com/klauspost/reedsolomon"]
- version = "v1.9.2"
- hash = "sha256-Ft/TCFGpgoVaKtryT6DNHK4rMotEg6EsslM3hy0VPVg="
[mod."github.com/kortschak/wol"]
version = "v0.0.0-20200729010619-da482cc4850a"
hash = "sha256-lnr9r/KNv4EeeNohFImC3Vd5E9nJ0N+4ZZ0VHFjwHps="
@@ -274,9 +259,6 @@ schema = 3
[mod."github.com/ssor/bom"]
version = "v0.0.0-20170718123548-6386211fdfcf"
hash = "sha256-jYYzaIOaUFv575h3Sz/T4DPO6EWFRwEpwx1zF00i5SU="
- [mod."github.com/streamrail/concurrent-map"]
- version = "v0.0.0-20160823150647-8bf1e9bacbf6"
- hash = "sha256-rcYSZVaw5TkO3o5d/MGwatT1Rzrcnvfjx1SPGDr/fnU="
[mod."github.com/sycamoreone/orc"]
version = "v0.0.0-20150204213357-1627eaec2699"
hash = "sha256-59mtIQXtEBKaRNriFiHdOrTqxIbZOGdXW2HLkIXCAVw="
@@ -295,18 +277,9 @@ schema = 3
[mod."github.com/tcnksm/go-httpstat"]
version = "v0.2.0"
hash = "sha256-bCWn8E+DcZY6+yPu07AF3hCcDZx3CFdD74qfpDIgVqI="
- [mod."github.com/templexxx/cpufeat"]
- version = "v0.0.0-20180724012125-cef66df7f161"
- hash = "sha256-M11hmgWYZXdmtbK0smFIyYjGxPhJXfjipxrg11TcaqA="
- [mod."github.com/templexxx/xor"]
- version = "v0.0.0-20181023030647-4e92f724b73b"
- hash = "sha256-baRoM5CqX8DwzxrxjhTe0XPX31szJL8c5gjCevPnYPw="
[mod."github.com/tetratelabs/wazero"]
version = "v1.0.0-pre.3"
hash = "sha256-Sj5Uy3jDRSGue9aF/UEyvdyN7IOt1y5JDdQoB/CW84E="
- [mod."github.com/tjfoc/gmsm"]
- version = "v1.0.1"
- hash = "sha256-AyuYHHf3+ZDR+2bJxf1q/xeoXNgl4TwMtiDzZtppL98="
[mod."github.com/tmc/scp"]
version = "v0.0.0-20170824174625-f7b48647feef"
hash = "sha256-qHwQb3JA43VVhJdB18/2zXbxqW/bgw1yvr8YhqFyd74="
@@ -325,15 +298,6 @@ schema = 3
[mod."github.com/xlzd/gotp"]
version = "v0.0.0-20181030022105-c8557ba2c119"
hash = "sha256-NVXamx9Z3l52ZHkyh/b3wdIzaQvtgkxhjoM2uypVv/I="
- [mod."github.com/xtaci/kcp-go"]
- version = "v5.4.20+incompatible"
- hash = "sha256-SBnMuGcLdp0g9D363qtSXvAQGdmkany7ZKRDOuHCkko="
- [mod."github.com/xtaci/lossyconn"]
- version = "v0.0.0-20190602105132-8df528c0c9ae"
- hash = "sha256-hNwfcn/x6i8t2FVhqsMyqklh024JFnP/lH7f7KgpcGk="
- [mod."github.com/xtaci/smux"]
- version = "v2.0.1+incompatible"
- hash = "sha256-3ogbwpvGrJmXrtXA29QHHcw6/yCvMeTuc2szHpJvdIQ="
[mod."github.com/yawning/bulb"]
version = "v0.0.0-20170405033506-85d80d893c3d"
hash = "sha256-GEFdZJl/T0khRN6me0hBMxD8Dirmc/agr62tsuxh8GQ="
diff --git a/tun2/backend.go b/tun2/backend.go
deleted file mode 100644
index d94a1a8..0000000
--- a/tun2/backend.go
+++ /dev/null
@@ -1,78 +0,0 @@
-package tun2
-
-import "time"
-
-// Backend is the public state of an individual Connection.
-type Backend struct {
- ID string
- Proto string
- User string
- Domain string
- Phi float32
- Host string
- Usable bool
-}
-
-type backendMatcher func(*Connection) bool
-
-func (s *Server) getBackendsForMatcher(bm backendMatcher) []Backend {
- s.connlock.Lock()
- defer s.connlock.Unlock()
-
- var result []Backend
-
- for _, c := range s.conns {
- if !bm(c) {
- continue
- }
-
- result = append(result, Backend{
- ID: c.id,
- Proto: c.conn.LocalAddr().Network(),
- User: c.user,
- Domain: c.domain,
- Phi: float32(c.detector.Phi(time.Now())),
- Host: c.conn.RemoteAddr().String(),
- Usable: c.usable,
- })
- }
-
- return result
-}
-
-// KillBackend forcibly disconnects a given backend but doesn't offer a way to
-// "ban" it from reconnecting.
-func (s *Server) KillBackend(id string) error {
- s.connlock.Lock()
- defer s.connlock.Unlock()
-
- for _, c := range s.conns {
- if c.id == id {
- c.cancel()
- return nil
- }
- }
-
- return ErrNoSuchBackend
-}
-
-// GetBackendsForDomain fetches all backends connected to this server associated
-// to a single public domain name.
-func (s *Server) GetBackendsForDomain(domain string) []Backend {
- return s.getBackendsForMatcher(func(c *Connection) bool {
- return c.domain == domain
- })
-}
-
-// GetBackendsForUser fetches all backends connected to this server owned by a
-// given user by username.
-func (s *Server) GetBackendsForUser(uname string) []Backend {
- return s.getBackendsForMatcher(func(c *Connection) bool {
- return c.user == uname
- })
-}
-
-// GetAllBackends fetches every backend connected to this server.
-func (s *Server) GetAllBackends() []Backend {
- return s.getBackendsForMatcher(func(*Connection) bool { return true })
-}
diff --git a/tun2/backend_test.go b/tun2/backend_test.go
deleted file mode 100644
index 3e808d1..0000000
--- a/tun2/backend_test.go
+++ /dev/null
@@ -1,212 +0,0 @@
-package tun2
-
-import (
- "bytes"
- "context"
- "encoding/json"
- "net"
- "net/http"
- "net/http/httptest"
- "os"
- "testing"
- "time"
-)
-
-func TestBackendAuthV1(t *testing.T) {
- st := MockStorage()
-
- s, err := NewServer(&ServerConfig{
- Storage: st,
- })
- if err != nil {
- t.Fatal(err)
- }
- defer s.Close()
-
- st.AddRoute(domain, user)
- st.AddToken(token, user, []string{"connect"})
- st.AddToken(noPermToken, user, nil)
- st.AddToken(otherUserToken, "cadey", []string{"connect"})
-
- cases := []struct {
- name string
- auth Auth
- wantErr bool
- }{
- {
- name: "basic everything should work",
- auth: Auth{
- Token: token,
- Domain: domain,
- },
- wantErr: false,
- },
- {
- name: "invalid domain",
- auth: Auth{
- Token: token,
- Domain: "aw.heck",
- },
- wantErr: true,
- },
- {
- name: "invalid token",
- auth: Auth{
- Token: "asdfwtweg",
- Domain: domain,
- },
- wantErr: true,
- },
- {
- name: "invalid token scopes",
- auth: Auth{
- Token: noPermToken,
- Domain: domain,
- },
- wantErr: true,
- },
- {
- name: "user token doesn't match domain owner",
- auth: Auth{
- Token: otherUserToken,
- Domain: domain,
- },
- wantErr: true,
- },
- }
-
- for _, cs := range cases {
- t.Run(cs.name, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
-
- data, err := json.Marshal(cs.auth)
- if err != nil {
- t.Fatal(err)
- }
-
- _, _, err = s.backendAuthv1(ctx, bytes.NewBuffer(data))
-
- if cs.wantErr && err == nil {
- t.Fatalf("auth did not err as expected")
- }
-
- if !cs.wantErr && err != nil {
- t.Fatalf("unexpected auth err: %v", err)
- }
- })
- }
-}
-
-func TestBackendRouting(t *testing.T) {
- t.Skip()
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
-
- st := MockStorage()
-
- st.AddRoute(domain, user)
- st.AddToken(token, user, []string{"connect"})
-
- s, err := NewServer(&ServerConfig{
- Storage: st,
- })
- if err != nil {
- t.Fatal(err)
- }
- defer s.Close()
-
- l, err := net.Listen("tcp", "127.0.0.1:0")
- if err != nil {
- t.Fatal(err)
- }
- defer l.Close()
-
- go s.Listen(l)
-
- cases := []struct {
- name string
- wantStatusCode int
- handler http.HandlerFunc
- }{
- {
- name: "200 everything's okay",
- wantStatusCode: http.StatusOK,
- handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- http.Error(w, "HTTP 200, everything is okay :)", http.StatusOK)
- }),
- },
- {
- name: "500 internal error",
- wantStatusCode: http.StatusInternalServerError,
- handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- http.Error(w, "HTTP 500, the world is on fire", http.StatusInternalServerError)
- }),
- },
- }
-
- for _, cs := range cases {
- t.Run(cs.name, func(t *testing.T) {
- ts := httptest.NewServer(cs.handler)
- defer ts.Close()
-
- cc := &ClientConfig{
- ConnType: "tcp",
- ServerAddr: l.Addr().String(),
- Token: token,
- BackendURL: ts.URL,
- Domain: domain,
-
- forceTCPClear: true,
- }
-
- c, err := NewClient(cc)
- if err != nil {
- t.Fatal(err)
- }
-
- go c.Connect(ctx) // TODO: fix the client library so this ends up actually getting cleaned up
-
- time.Sleep(125 * time.Millisecond)
-
- req, err := http.NewRequest("GET", "http://cetacean.club/", nil)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := s.RoundTrip(req)
- if err != nil {
- t.Fatalf("error in doing round trip: %v", err)
- }
-
- if cs.wantStatusCode != resp.StatusCode {
- resp.Write(os.Stdout)
- t.Fatalf("got status %d instead of %d", resp.StatusCode, cs.wantStatusCode)
- }
- })
- }
-}
-
-func setupTestServer() (*Server, *mockStorage, net.Listener, error) {
- st := MockStorage()
-
- st.AddRoute(domain, user)
- st.AddToken(token, user, []string{"connect"})
-
- s, err := NewServer(&ServerConfig{
- Storage: st,
- })
- if err != nil {
- return nil, nil, nil, err
- }
- defer s.Close()
-
- l, err := net.Listen("tcp", "127.0.0.1:0")
- if err != nil {
- return nil, nil, nil, err
- }
-
- go s.Listen(l)
-
- return s, st, l, nil
-}
diff --git a/tun2/client.go b/tun2/client.go
deleted file mode 100644
index d7a3982..0000000
--- a/tun2/client.go
+++ /dev/null
@@ -1,171 +0,0 @@
-package tun2
-
-import (
- "context"
- "crypto/tls"
- "encoding/json"
- "errors"
- "io"
- "net"
- "net/http"
- "net/http/httputil"
- "net/url"
-
- "within.website/ln"
- "within.website/ln/opname"
- kcp "github.com/xtaci/kcp-go"
- "github.com/xtaci/smux"
-)
-
-// Client connects to a remote tun2 server and sets up authentication before routing
-// individual HTTP requests to discrete streams that are reverse proxied to the eventual
-// backend.
-type Client struct {
- cfg *ClientConfig
-}
-
-// ClientConfig configures client with settings that the user provides.
-type ClientConfig struct {
- TLSConfig *tls.Config
- ConnType string
- ServerAddr string
- Token string
- Domain string
- BackendURL string
-
- // internal use only
- forceTCPClear bool
-}
-
-// NewClient constructs an instance of Client with a given ClientConfig.
-func NewClient(cfg *ClientConfig) (*Client, error) {
- if cfg == nil {
- return nil, errors.New("tun2: client config needed")
- }
-
- c := &Client{
- cfg: cfg,
- }
-
- return c, nil
-}
-
-// Connect dials the remote server and negotiates a client session with its
-// configured server address. This will then continuously proxy incoming HTTP
-// requests to the backend HTTP server.
-//
-// This is a blocking function.
-func (c *Client) Connect(ctx context.Context) error {
- ctx = opname.With(ctx, "tun2.Client.connect")
- return c.connect(ctx, c.cfg.ServerAddr)
-}
-
-func closeLater(ctx context.Context, clo io.Closer) {
- <-ctx.Done()
- clo.Close()
-}
-
-func (c *Client) connect(ctx context.Context, serverAddr string) error {
- target, err := url.Parse(c.cfg.BackendURL)
- if err != nil {
- return err
- }
-
- s := &http.Server{
- Handler: httputil.NewSingleHostReverseProxy(target),
- }
- go closeLater(ctx, s)
-
- f := ln.F{
- "server_addr": serverAddr,
- "conn_type": c.cfg.ConnType,
- }
-
- var conn net.Conn
-
- switch c.cfg.ConnType {
- case "tcp":
- if c.cfg.forceTCPClear {
- ln.Log(ctx, f, ln.Info("connecting over plain TCP"))
- conn, err = net.Dial("tcp", serverAddr)
- } else {
- conn, err = tls.Dial("tcp", serverAddr, c.cfg.TLSConfig)
- }
-
- if err != nil {
- return err
- }
-
- case "kcp":
- kc, err := kcp.Dial(serverAddr)
- if err != nil {
- return err
- }
- defer kc.Close()
-
- serverHost, _, _ := net.SplitHostPort(serverAddr)
-
- tc := c.cfg.TLSConfig.Clone()
- tc.ServerName = serverHost
- conn = tls.Client(kc, tc)
- }
- go closeLater(ctx, conn)
-
- ln.Log(ctx, f, ln.Info("connected"))
-
- session, err := smux.Client(conn, smux.DefaultConfig())
- if err != nil {
- return err
- }
- go closeLater(ctx, session)
-
- controlStream, err := session.AcceptStream()
- if err != nil {
- return err
- }
- go closeLater(ctx, controlStream)
-
- authData, err := json.Marshal(&Auth{
- Token: c.cfg.Token,
- Domain: c.cfg.Domain,
- })
- if err != nil {
- return err
- }
-
- _, err = controlStream.Write(authData)
- if err != nil {
- return err
- }
-
- err = s.Serve(&smuxListener{
- conn: conn,
- session: session,
- })
- if err != nil {
- return err
- }
-
- if err := ctx.Err(); err != nil {
- ln.Error(ctx, err, f, ln.Info("context error"))
- }
- return nil
-}
-
-// smuxListener wraps a smux session as a net.Listener.
-type smuxListener struct {
- conn net.Conn
- session *smux.Session
-}
-
-func (sl *smuxListener) Accept() (net.Conn, error) {
- return sl.session.AcceptStream()
-}
-
-func (sl *smuxListener) Addr() net.Addr {
- return sl.conn.LocalAddr()
-}
-
-func (sl *smuxListener) Close() error {
- return sl.session.Close()
-}
diff --git a/tun2/client_test.go b/tun2/client_test.go
deleted file mode 100644
index d3127a7..0000000
--- a/tun2/client_test.go
+++ /dev/null
@@ -1,21 +0,0 @@
-package tun2
-
-import (
- "net"
- "testing"
-)
-
-func TestNewClientNullConfig(t *testing.T) {
- _, err := NewClient(nil)
- if err == nil {
- t.Fatalf("expected NewClient(nil) to fail, got non-failure")
- }
-}
-
-func TestSmuxListenerIsNetListener(t *testing.T) {
- var sl interface{} = &smuxListener{}
- _, ok := sl.(net.Listener)
- if !ok {
- t.Fatalf("smuxListener does not implement net.Listener")
- }
-}
diff --git a/tun2/connection.go b/tun2/connection.go
deleted file mode 100644
index ff03e96..0000000
--- a/tun2/connection.go
+++ /dev/null
@@ -1,162 +0,0 @@
-package tun2
-
-import (
- "bufio"
- "context"
- "expvar"
- "net"
- "net/http"
- "sync"
- "time"
-
- failure "github.com/dgryski/go-failure"
- "github.com/pkg/errors"
- "github.com/xtaci/smux"
- "within.website/ln"
- "within.website/ln/opname"
-)
-
-// Connection is a single active client -> server connection and session
-// containing many streams over TCP+TLS or KCP+TLS. Every stream beyond the
-// control stream is assumed to be passed to the underlying backend server.
-//
-// All Connection methods assume this is locked externally.
-type Connection struct {
- id string
- conn net.Conn
- session *smux.Session
- controlStream *smux.Stream
- user string
- domain string
- cf context.CancelFunc
- detector *failure.Detector
- Auth *Auth
- usable bool
-
- sync.Mutex
- counter *expvar.Int
-}
-
-func (c *Connection) cancel() {
- c.cf()
- c.usable = false
-}
-
-// F logs key->value pairs as an ln.Fer
-func (c *Connection) F() ln.F {
- return map[string]interface{}{
- "id": c.id,
- "remote": c.conn.RemoteAddr(),
- "local": c.conn.LocalAddr(),
- "kind": c.conn.LocalAddr().Network(),
- "user": c.user,
- "domain": c.domain,
- }
-}
-
-// Ping ends a "ping" to the client. If the client doesn't respond or the connection
-// dies, then the connection needs to be cleaned up.
-func (c *Connection) Ping() error {
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
- defer cancel()
- ctx = opname.With(ctx, "tun2.Connection.Ping")
- ctx = ln.WithF(ctx, ln.F{"timeout": time.Second})
-
- req, err := http.NewRequest("GET", "http://backend/health", nil)
- if err != nil {
- panic(err)
- }
- req = req.WithContext(ctx)
-
- _, err = c.RoundTrip(req)
- if err != nil {
- ln.Error(ctx, err, c, ln.Action("pinging the backend"))
- return err
- }
-
- c.detector.Ping(time.Now())
-
- return nil
-}
-
-// OpenStream creates a new stream (connection) to the backend server.
-func (c *Connection) OpenStream(ctx context.Context) (net.Conn, error) {
- ctx = opname.With(ctx, "OpenStream")
- if !c.usable {
- return nil, ErrNoSuchBackend
- }
- ctx = ln.WithF(ctx, ln.F{"timeout": time.Second})
-
- err := c.conn.SetDeadline(time.Now().Add(time.Second))
- if err != nil {
- ln.Error(ctx, err, c)
- return nil, err
- }
-
- stream, err := c.session.OpenStream()
- if err != nil {
- ln.Error(ctx, err, c)
- return nil, err
- }
-
- return stream, c.conn.SetDeadline(time.Time{})
-}
-
-// Close destroys resouces specific to the connection.
-func (c *Connection) Close() error {
- err := c.controlStream.Close()
- if err != nil {
- return err
- }
-
- err = c.session.Close()
- if err != nil {
- return err
- }
-
- err = c.conn.Close()
- if err != nil {
- return err
- }
-
- return nil