aboutsummaryrefslogtreecommitdiff
path: root/tun2/backend.go
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 /tun2/backend.go
parent58385c715cd31ce4c89e555167b5ae2cf5306ad8 (diff)
downloadx-1.3.0.tar.xz
x-1.3.0.zip
remove tun2v1.3.0
Signed-off-by: Xe <me@christine.website>
Diffstat (limited to 'tun2/backend.go')
-rw-r--r--tun2/backend.go78
1 files changed, 0 insertions, 78 deletions
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 })
-}