squash refactor

This commit is contained in:
AJ ONeal 2020-05-01 00:12:16 -06:00
parent e0330dbad9
commit e57917a252
7 changed files with 79 additions and 109 deletions

View File

@ -7,15 +7,16 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log" golog "log"
"net/http" "net/http"
"os" "os"
"strings" "strings"
telebit "git.coolaj86.com/coolaj86/go-telebitd" telebit "git.coolaj86.com/coolaj86/go-telebitd"
"git.coolaj86.com/coolaj86/go-telebitd/log"
"git.coolaj86.com/coolaj86/go-telebitd/relay" "git.coolaj86.com/coolaj86/go-telebitd/relay"
"git.coolaj86.com/coolaj86/go-telebitd/relay/api" "git.coolaj86.com/coolaj86/go-telebitd/relay/api"
"git.coolaj86.com/coolaj86/go-telebitd/server" "git.coolaj86.com/coolaj86/go-telebitd/relay/mplexy"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -24,14 +25,18 @@ import (
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"
) )
var Loginfo = log.Loginfo
var Logdebug = log.Logdebug
func init() {
log.LogFlags = golog.Ldate | golog.Lmicroseconds | golog.Lshortfile
}
var ( var (
logfile = "stdout" logfile = "stdout"
configPath = "./" configPath = "./"
configFile = "telebit-relay" configFile = "telebit-relay"
loginfo *log.Logger
logdebug *log.Logger
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
argWssClientListener string argWssClientListener string
tcpPort int tcpPort int
argServerBinding string argServerBinding string
@ -86,10 +91,7 @@ func main() {
} }
// send the output io.Writing to the other packages // send the output io.Writing to the other packages
server.InitLogging(logoutput) log.InitLogging(logoutput)
loginfo = log.New(logoutput, "INFO: main: ", logFlags)
logdebug = log.New(logoutput, "DEBUG: main:", logFlags)
viper.SetConfigName(configFile) viper.SetConfigName(configFile)
viper.AddConfigPath(configPath) viper.AddConfigPath(configPath)
@ -111,7 +113,7 @@ func main() {
lbDefaultMethod = viper.Get("rvpn.loadbalancing.defaultmethod").(string) lbDefaultMethod = viper.Get("rvpn.loadbalancing.defaultmethod").(string)
nickname = viper.Get("rvpn.serverName").(string) nickname = viper.Get("rvpn.serverName").(string)
loginfo.Println("startup") Loginfo.Println("startup")
ctx, cancelContext := context.WithCancel(context.Background()) ctx, cancelContext := context.WithCancel(context.Background())
defer cancelContext() defer cancelContext()
@ -139,7 +141,7 @@ func main() {
}, },
} }
authorizer := func(r *http.Request) (*server.Authz, error) { authorizer := func(r *http.Request) (*mplexy.Authz, error) {
// do we have a valid wss_client? // do we have a valid wss_client?
var tokenString string var tokenString string
@ -158,7 +160,7 @@ func main() {
return nil, err return nil, err
} }
authz := &server.Authz{ authz := &mplexy.Authz{
Domains: []string{ Domains: []string{
"target.rootprojects.org", "target.rootprojects.org",
}, },
@ -174,7 +176,7 @@ func main() {
if err != nil || !result.Valid { if err != nil || !result.Valid {
w.WriteHeader(http.StatusForbidden) w.WriteHeader(http.StatusForbidden)
w.Write([]byte("Not Authorized")) w.Write([]byte("Not Authorized"))
loginfo.Println("access_token invalid...closing connection") Loginfo.Println("access_token invalid...closing connection")
return return
} }

View File

@ -1,4 +1,4 @@
package server package log
import ( import (
"io" "io"
@ -8,22 +8,19 @@ import (
var ( var (
//Logoutput -- passing the output writer from main //Logoutput -- passing the output writer from main
loginfo *log.Logger Loginfo *log.Logger
logdebug *log.Logger Logdebug *log.Logger
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile LogFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
connectionID int64
) )
func init() { func init() {
loginfo = log.New(os.Stdout, "INFO: server: ", logFlags) Loginfo = log.New(os.Stdout, "INFO: ", LogFlags)
logdebug = log.New(os.Stdout, "DEBUG: server:", logFlags) Logdebug = log.New(os.Stdout, "DEBUG: ", LogFlags)
connectionID = 0
} }
//InitLogging -- after main sets up output, it will init all packages InitLogging //InitLogging -- after main sets up output, it will init all packages InitLogging
//I am sure I am doing this wrong, but I could not find a way to have package level //I am sure I am doing this wrong, but I could not find a way to have package level
//logging with the flags I wanted and the ability to run lumberjack file management //logging with the flags I wanted and the ability to run lumberjack file management
func InitLogging(logoutput io.Writer) { func InitLogging(logoutput io.Writer) {
loginfo.SetOutput(logoutput) Loginfo.SetOutput(logoutput)
} }

View File

@ -10,7 +10,7 @@ import (
telebit "git.coolaj86.com/coolaj86/go-telebitd" telebit "git.coolaj86.com/coolaj86/go-telebitd"
"git.coolaj86.com/coolaj86/go-telebitd/relay/api" "git.coolaj86.com/coolaj86/go-telebitd/relay/api"
"git.coolaj86.com/coolaj86/go-telebitd/server" "git.coolaj86.com/coolaj86/go-telebitd/relay/mplexy"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -26,7 +26,7 @@ var serverStatusAPI *api.Status
//ListenAndServe - //ListenAndServe -
// - expecting an existing oneConnListener with a qualified wss client connected. // - expecting an existing oneConnListener with a qualified wss client connected.
// - auth will happen again since we were just peeking at the token. // - auth will happen again since we were just peeking at the token.
func ListenAndServe(mx *server.MPlexy, adminListener net.Listener) error { func ListenAndServe(mx *mplexy.MPlexy, adminListener net.Listener) error {
//serverStatus = mx.ctx.Value(ctxServerStatus).(*Status) //serverStatus = mx.ctx.Value(ctxServerStatus).(*Status)
connectionTable = mx.Status.ConnectionTable connectionTable = mx.Status.ConnectionTable

View File

@ -1,4 +1,4 @@
package server package mplexy
import ( import (
"bufio" "bufio"
@ -7,7 +7,6 @@ import (
"crypto/tls" "crypto/tls"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"log"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
@ -56,19 +55,19 @@ const (
// - if TLS, consume connection with TLS certbundle, pass to request identifier // - if TLS, consume connection with TLS certbundle, pass to request identifier
// - else, just pass to the request identififer // - else, just pass to the request identififer
func (mx *MPlexy) multiListenAndServe(ctx context.Context, listenerRegistration *ListenerRegistration) { func (mx *MPlexy) multiListenAndServe(ctx context.Context, listenerRegistration *ListenerRegistration) {
loginfo.Println(":" + string(listenerRegistration.port)) Loginfo.Println(":" + string(listenerRegistration.port))
cancelCheck := ctx.Value(ctxCancelCheck).(int) cancelCheck := ctx.Value(ctxCancelCheck).(int)
listenAddr, err := net.ResolveTCPAddr("tcp", ":"+strconv.Itoa(listenerRegistration.port)) listenAddr, err := net.ResolveTCPAddr("tcp", ":"+strconv.Itoa(listenerRegistration.port))
if nil != err { if nil != err {
loginfo.Println(err) Loginfo.Println(err)
return return
} }
ln, err := net.ListenTCP("tcp", listenAddr) ln, err := net.ListenTCP("tcp", listenAddr)
if err != nil { if err != nil {
loginfo.Println("unable to bind", err) Loginfo.Println("unable to bind", err)
listenerRegistration.status = listenerFault listenerRegistration.status = listenerFault
listenerRegistration.err = err listenerRegistration.err = err
listenerRegistration.commCh <- listenerRegistration listenerRegistration.commCh <- listenerRegistration
@ -81,7 +80,7 @@ func (mx *MPlexy) multiListenAndServe(ctx context.Context, listenerRegistration
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
loginfo.Println("Cancel signal hit") Loginfo.Println("Cancel signal hit")
return return
default: default:
ln.SetDeadline(time.Now().Add(time.Duration(cancelCheck) * time.Second)) ln.SetDeadline(time.Now().Add(time.Duration(cancelCheck) * time.Second))
@ -92,7 +91,7 @@ func (mx *MPlexy) multiListenAndServe(ctx context.Context, listenerRegistration
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() { if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
continue continue
} }
log.Println(err) Loginfo.Println(err)
return return
} }
@ -115,10 +114,10 @@ func (mx *MPlexy) accept(ctx context.Context, wConn *tunnel.WedgeConn) {
encryptMode := encryptNone encryptMode := encryptNone
loginfo.Println("new conn", wConn, wConn.LocalAddr().String(), wConn.RemoteAddr().String()) Loginfo.Println("new conn", wConn, wConn.LocalAddr().String(), wConn.RemoteAddr().String())
peek, err := wConn.Peek(peekCnt) peek, err := wConn.Peek(peekCnt)
if err != nil { if err != nil {
loginfo.Println("error while peeking") Loginfo.Println("error while peeking")
wConn.Close() wConn.Close()
return return
} }
@ -132,7 +131,7 @@ func (mx *MPlexy) accept(ctx context.Context, wConn *tunnel.WedgeConn) {
} else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x01}) { } else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x01}) {
encryptMode = encryptTLS10 encryptMode = encryptTLS10
loginfo.Println("TLS10") Loginfo.Println("TLS10")
} else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x02}) { } else if bytes.Contains(peek[0:3], []byte{0x16, 0x03, 0x02}) {
encryptMode = encryptTLS11 encryptMode = encryptTLS11
@ -146,19 +145,19 @@ func (mx *MPlexy) accept(ctx context.Context, wConn *tunnel.WedgeConn) {
} }
if encryptMode == encryptSSLV2 { if encryptMode == encryptSSLV2 {
loginfo.Println("<= SSLv2 is not accepted") Loginfo.Println("<= SSLv2 is not accepted")
wConn.Close() wConn.Close()
return return
} }
if encryptMode == encryptNone { if encryptMode == encryptNone {
loginfo.Println("Handle Unencrypted") Loginfo.Println("Handle Unencrypted")
mx.acceptPlainStream(ctx, wConn, false) mx.acceptPlainStream(ctx, wConn, false)
return return
} }
loginfo.Println("Handle Encryption") Loginfo.Println("Handle Encryption")
mx.acceptEncryptedStream(ctx, wConn) mx.acceptEncryptedStream(ctx, wConn)
} }
@ -167,21 +166,21 @@ func (mx *MPlexy) acceptEncryptedStream(ctx context.Context, wConn *tunnel.Wedge
peek, err := wConn.PeekAll() peek, err := wConn.PeekAll()
if err != nil { if err != nil {
loginfo.Println("Bad socket: read error from", wConn.RemoteAddr(), err) Loginfo.Println("Bad socket: read error from", wConn.RemoteAddr(), err)
loginfo.Println(hex.Dump(peek[0:])) Loginfo.Println(hex.Dump(peek[0:]))
wConn.Close() wConn.Close()
return return
} }
sniHostName, err := sni.GetHostname(peek) sniHostName, err := sni.GetHostname(peek)
if err != nil { if err != nil {
loginfo.Println("Bad socket: no SNI from", wConn.RemoteAddr(), err) Loginfo.Println("Bad socket: no SNI from", wConn.RemoteAddr(), err)
loginfo.Println(err) Loginfo.Println(err)
wConn.Close() wConn.Close()
return return
} }
loginfo.Println("SNI:", sniHostName) Loginfo.Println("SNI:", sniHostName)
if sniHostName == mx.wssHostName || sniHostName == mx.adminHostName { if sniHostName == mx.wssHostName || sniHostName == mx.adminHostName {
// The TLS should be terminated and handled internally // The TLS should be terminated and handled internally
@ -195,7 +194,7 @@ func (mx *MPlexy) acceptEncryptedStream(ctx context.Context, wConn *tunnel.Wedge
//oneConn := &oneConnListener{wConn} //oneConn := &oneConnListener{wConn}
// TLS remains intact and shall be routed downstream, wholesale // TLS remains intact and shall be routed downstream, wholesale
loginfo.Println("processing non terminating traffic", mx.wssHostName, sniHostName) Loginfo.Println("processing non terminating traffic", mx.wssHostName, sniHostName)
go mx.routeToTarget(ctx, wConn, sniHostName, "https") go mx.routeToTarget(ctx, wConn, sniHostName, "https")
} }
@ -208,13 +207,13 @@ func (mx *MPlexy) acceptEncryptedStream(ctx context.Context, wConn *tunnel.Wedge
// - else handle as raw http // - else handle as raw http
// - handle other? // - handle other?
func (mx *MPlexy) acceptPlainStream(ctx context.Context, wConn *tunnel.WedgeConn, encrypted bool) { func (mx *MPlexy) acceptPlainStream(ctx context.Context, wConn *tunnel.WedgeConn, encrypted bool) {
loginfo.Println("Plain Conn", wConn.LocalAddr().String(), wConn.RemoteAddr().String()) Loginfo.Println("Plain Conn", wConn.LocalAddr().String(), wConn.RemoteAddr().String())
// TODO couldn't reading everything be dangerous? Or is it limited to a single packet? // TODO couldn't reading everything be dangerous? Or is it limited to a single packet?
peek, err := wConn.PeekAll() peek, err := wConn.PeekAll()
if err != nil { if err != nil {
loginfo.Println("error while peeking", err) Loginfo.Println("error while peeking", err)
loginfo.Println(hex.Dump(peek[0:])) Loginfo.Println(hex.Dump(peek[0:]))
wConn.Close() wConn.Close()
return return
} }
@ -234,17 +233,17 @@ func (mx *MPlexy) acceptPlainStream(ctx context.Context, wConn *tunnel.WedgeConn
return return
} }
loginfo.Println("identified HTTP") Loginfo.Println("identified HTTP")
r, err := http.ReadRequest(bufio.NewReader(bytes.NewReader(peek))) r, err := http.ReadRequest(bufio.NewReader(bytes.NewReader(peek)))
if err != nil { if err != nil {
loginfo.Println("identified as HTTP, failed request parsing", err) Loginfo.Println("identified as HTTP, failed request parsing", err)
wConn.Close() wConn.Close()
return return
} }
if strings.Contains(r.Host, telebit.InvalidAdminDomain) { if strings.Contains(r.Host, telebit.InvalidAdminDomain) {
loginfo.Println("admin") Loginfo.Println("admin")
// TODO mx.Admin.CheckRemoteIP(conn) here // TODO mx.Admin.CheckRemoteIP(conn) here
// handle admin path // handle admin path
mx.AcceptAdminClient(wConn) mx.AcceptAdminClient(wConn)
@ -256,15 +255,15 @@ func (mx *MPlexy) acceptPlainStream(ctx context.Context, wConn *tunnel.WedgeConn
// TODO check if this is a websocket // TODO check if this is a websocket
_, err = mx.AuthorizeTarget(r) _, err = mx.AuthorizeTarget(r)
if err == nil { if err == nil {
loginfo.Println("Valid WSS dected...sending to handler") Loginfo.Println("Valid WSS dected...sending to handler")
mx.AcceptTargetServer(wConn) mx.AcceptTargetServer(wConn)
return return
} }
// TODO sniHostName is the key to the route, which could also be a port or hostname // TODO sniHostName is the key to the route, which could also be a port or hostname
//traffic not terminating on the rvpn do not decrypt //traffic not terminating on the rvpn do not decrypt
loginfo.Println("processing non terminating traffic", mx.wssHostName, r.Host) Loginfo.Println("processing non terminating traffic", mx.wssHostName, r.Host)
loginfo.Println(hex.Dump(peek)) Loginfo.Println(hex.Dump(peek))
if !encrypted { if !encrypted {
// TODO request and cache http resources as a feature?? // TODO request and cache http resources as a feature??
go mx.routeToTarget(ctx, wConn, r.Host, "http") go mx.routeToTarget(ctx, wConn, r.Host, "http")
@ -272,7 +271,7 @@ func (mx *MPlexy) acceptPlainStream(ctx context.Context, wConn *tunnel.WedgeConn
} }
// This is not presently possible // This is not presently possible
loginfo.Println("impossible condition: local decryption of routable client", mx.wssHostName, r.Host) Loginfo.Println("impossible condition: local decryption of routable client", mx.wssHostName, r.Host)
go mx.routeToTarget(ctx, wConn, r.Host, "https") go mx.routeToTarget(ctx, wConn, r.Host, "https")
} }
@ -294,7 +293,7 @@ func (mx *MPlexy) routeToTarget(ctx context.Context, extConn *tunnel.WedgeConn,
conn, ok := serverStatus.ConnectionTable.ConnByDomain(hostname) conn, ok := serverStatus.ConnectionTable.ConnByDomain(hostname)
if !ok { if !ok {
//matching connection can not be found based on ConnByDomain //matching connection can not be found based on ConnByDomain
loginfo.Println("unable to match ", hostname, " to an existing connection") Loginfo.Println("unable to match ", hostname, " to an existing connection")
//http.Error(, "Domain not supported", http.StatusBadRequest) //http.Error(, "Domain not supported", http.StatusBadRequest)
return return
} }
@ -303,15 +302,15 @@ func (mx *MPlexy) routeToTarget(ctx context.Context, extConn *tunnel.WedgeConn,
serverStatus.ExtConnectionRegister(track) serverStatus.ExtConnectionRegister(track)
remoteStr := extConn.RemoteAddr().String() remoteStr := extConn.RemoteAddr().String()
loginfo.Println("Domain Accepted", hostname, remoteStr) Loginfo.Println("Domain Accepted", hostname, remoteStr)
var header *packer.Header var header *packer.Header
if rAddr, rPort, err := net.SplitHostPort(remoteStr); err != nil { if rAddr, rPort, err := net.SplitHostPort(remoteStr); err != nil {
loginfo.Println("unable to decode hostport", remoteStr, err) Loginfo.Println("unable to decode hostport", remoteStr, err)
} else if port, err := strconv.Atoi(rPort); err != nil { } else if port, err := strconv.Atoi(rPort); err != nil {
loginfo.Printf("unable to parse port string %q: %v\n", rPort, err) Loginfo.Printf("unable to parse port string %q: %v\n", rPort, err)
} else if header, err = packer.NewHeader(rAddr, port, service); err != nil { } else if header, err = packer.NewHeader(rAddr, port, service); err != nil {
loginfo.Println("unable to create packer header", err) Loginfo.Println("unable to create packer header", err)
} }
if header == nil { if header == nil {
@ -321,17 +320,17 @@ func (mx *MPlexy) routeToTarget(ctx context.Context, extConn *tunnel.WedgeConn,
for { for {
buffer, err := extConn.PeekAll() buffer, err := extConn.PeekAll()
if err != nil { if err != nil {
loginfo.Println("unable to peekAll", err) Loginfo.Println("unable to peekAll", err)
return return
} }
loginfo.Println("Before Packer", hex.Dump(buffer)) Loginfo.Println("Before Packer", hex.Dump(buffer))
p := packer.NewPacker(header) p := packer.NewPacker(header)
p.Data.AppendBytes(buffer) p.Data.AppendBytes(buffer)
buf := p.PackV1() buf := p.PackV1()
//loginfo.Println(hex.Dump(buf.Bytes())) //Loginfo.Println(hex.Dump(buf.Bytes()))
//Bundle up the send request and dispatch //Bundle up the send request and dispatch
sendTrack := api.NewSendTrack(buf.Bytes(), hostname) sendTrack := api.NewSendTrack(buf.Bytes(), hostname)
@ -339,7 +338,7 @@ func (mx *MPlexy) routeToTarget(ctx context.Context, extConn *tunnel.WedgeConn,
cnt := len(buffer) cnt := len(buffer)
if _, err = extConn.Discard(cnt); err != nil { if _, err = extConn.Discard(cnt); err != nil {
loginfo.Println("unable to discard", cnt, err) Loginfo.Println("unable to discard", cnt, err)
return return
} }

View File

@ -1,4 +1,4 @@
package server package mplexy
import ( import (
"context" "context"
@ -6,9 +6,13 @@ import (
"net" "net"
"net/http" "net/http"
"git.coolaj86.com/coolaj86/go-telebitd/log"
"git.coolaj86.com/coolaj86/go-telebitd/relay/api" "git.coolaj86.com/coolaj86/go-telebitd/relay/api"
) )
var Loginfo = log.Loginfo
var connectionID int64 = 0
//ListenerRegistrationStatus - post registration status //ListenerRegistrationStatus - post registration status
type ListenerRegistrationStatus int type ListenerRegistrationStatus int
@ -112,9 +116,9 @@ func New(
// - execute the GenericLister // - execute the GenericLister
// - pass initial port, we'll announce that // - pass initial port, we'll announce that
func (mx *MPlexy) Run() error { func (mx *MPlexy) Run() error {
loginfo.Println("ConnectionTable starting") Loginfo.Println("ConnectionTable starting")
loginfo.Println(mx.connectionTracking) Loginfo.Println(mx.connectionTracking)
ctx := mx.ctx ctx := mx.ctx
@ -134,29 +138,29 @@ func (mx *MPlexy) Run() error {
select { select {
case <-ctx.Done(): case <-ctx.Done():
loginfo.Println("Cancel signal hit") Loginfo.Println("Cancel signal hit")
return nil return nil
case registration := <-mx.register: case registration := <-mx.register:
loginfo.Println("register fired", registration.port) Loginfo.Println("register fired", registration.port)
// check to see if port is already running // check to see if port is already running
for listener := range mx.listeners { for listener := range mx.listeners {
if mx.listeners[listener] == registration.port { if mx.listeners[listener] == registration.port {
loginfo.Println("listener already running", registration.port) Loginfo.Println("listener already running", registration.port)
registration.status = listenerExists registration.status = listenerExists
registration.commCh <- registration registration.commCh <- registration
} }
} }
loginfo.Println("listener starting up ", registration.port) Loginfo.Println("listener starting up ", registration.port)
loginfo.Println(ctx.Value(ctxConnectionTrack).(*api.Tracking)) Loginfo.Println(ctx.Value(ctxConnectionTrack).(*api.Tracking))
go mx.multiListenAndServe(ctx, registration) go mx.multiListenAndServe(ctx, registration)
status := <-registration.commCh status := <-registration.commCh
if status.status == listenerAdded { if status.status == listenerAdded {
mx.listeners[status.listener] = status.port mx.listeners[status.listener] = status.port
} else if status.status == listenerFault { } else if status.status == listenerFault {
loginfo.Println("Unable to create a new listerer", registration.port) Loginfo.Println("Unable to create a new listerer", registration.port)
} }
} }
} }

View File

@ -9,7 +9,7 @@ import (
"git.coolaj86.com/coolaj86/go-telebitd/relay/admin" "git.coolaj86.com/coolaj86/go-telebitd/relay/admin"
"git.coolaj86.com/coolaj86/go-telebitd/relay/api" "git.coolaj86.com/coolaj86/go-telebitd/relay/api"
"git.coolaj86.com/coolaj86/go-telebitd/server" "git.coolaj86.com/coolaj86/go-telebitd/relay/mplexy"
"git.coolaj86.com/coolaj86/go-telebitd/tunnel" "git.coolaj86.com/coolaj86/go-telebitd/tunnel"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -20,12 +20,12 @@ import (
type Relay struct { type Relay struct {
ctx context.Context ctx context.Context
status *api.Status status *api.Status
mx *server.MPlexy mx *mplexy.MPlexy
table *api.Table table *api.Table
} }
// New initializes and returns a relay service // New initializes and returns a relay service
func New(ctx context.Context, tlsConfig *tls.Config, authz server.Authorizer, status *api.Status, table *api.Table) *Relay { func New(ctx context.Context, tlsConfig *tls.Config, authz mplexy.Authorizer, status *api.Status, table *api.Table) *Relay {
// TODO do we need this already setup here? or is it just for logging? // TODO do we need this already setup here? or is it just for logging?
status.ConnectionTracking = api.NewTracking() status.ConnectionTracking = api.NewTracking()
status.ConnectionTable = table status.ConnectionTable = table
@ -34,7 +34,7 @@ func New(ctx context.Context, tlsConfig *tls.Config, authz server.Authorizer, st
ctx: ctx, ctx: ctx,
status: status, status: status,
table: table, table: table,
mx: server.New(ctx, tlsConfig, authAdmin, authz, status), // TODO Accept mx: mplexy.New(ctx, tlsConfig, authAdmin, authz, status), // TODO Accept
} }
return r return r
} }
@ -78,7 +78,7 @@ func (r *Relay) ListenAndServe(port int) error {
return r.mx.Run() return r.mx.Run()
} }
func listenAndServeTargets(mx *server.MPlexy, handler net.Listener) error { func listenAndServeTargets(mx *mplexy.MPlexy, handler net.Listener) error {
serverStatus := mx.Status serverStatus := mx.Status
router := mux.NewRouter().StrictSlash(true) router := mux.NewRouter().StrictSlash(true)

View File

@ -1,32 +0,0 @@
package server
import (
"io"
"net"
)
type oneConnListener struct {
conn net.Conn
}
func (l *oneConnListener) Accept() (net.Conn, error) {
if l.conn == nil {
loginfo.Println("oneConnListener Accept EOF")
return nil, io.EOF
}
c := l.conn
l.conn = nil
loginfo.Println("Accept", c.LocalAddr().String(), c.RemoteAddr().String())
return c, nil
}
func (l *oneConnListener) Close() error {
loginfo.Println("oneConnListener close")
return nil
}
func (l *oneConnListener) Addr() net.Addr {
loginfo.Println("oneConnLister addr")
return nil
}