2017-02-12 04:13:29 +00:00
|
|
|
package rvpnmain
|
|
|
|
|
|
|
|
import (
|
2017-02-26 05:17:39 +00:00
|
|
|
"crypto/tls"
|
2017-02-12 04:13:29 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2017-02-26 05:17:39 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"context"
|
2017-02-12 04:13:29 +00:00
|
|
|
|
2017-02-25 05:56:40 +00:00
|
|
|
"git.daplie.com/Daplie/go-rvpn-server/rvpn/genericlistener"
|
2017-02-12 20:39:50 +00:00
|
|
|
"git.daplie.com/Daplie/go-rvpn-server/rvpn/xlate"
|
2017-02-12 04:13:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
loginfo *log.Logger
|
|
|
|
logdebug *log.Logger
|
|
|
|
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
2017-02-25 05:56:40 +00:00
|
|
|
argWssClientListener string
|
|
|
|
argGenericBinding string
|
2017-02-12 04:13:29 +00:00
|
|
|
argServerBinding string
|
|
|
|
argServerAdminBinding string
|
|
|
|
argServerExternalBinding string
|
2017-02-26 05:17:39 +00:00
|
|
|
argDeadTime int
|
2017-03-03 00:47:59 +00:00
|
|
|
connectionTable *genericlistener.Table
|
2017-02-12 20:39:50 +00:00
|
|
|
wssMapping *xlate.WssMapping
|
2017-02-12 04:13:29 +00:00
|
|
|
secretKey = "abc123"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-02-26 05:17:39 +00:00
|
|
|
flag.IntVar(&argDeadTime, "dead-time-counter", 5, "deadtime counter in seconds")
|
|
|
|
flag.StringVar(&argGenericBinding, "generic-listener", ":8443", "generic SSL Listener")
|
2017-02-25 05:56:40 +00:00
|
|
|
flag.StringVar(&argWssClientListener, "wss-client-listener", ":3502", "wss client listener address:port")
|
2017-02-12 04:13:29 +00:00
|
|
|
flag.StringVar(&argServerAdminBinding, "admin-server-port", "127.0.0.2:8000", "admin server Bind listener")
|
|
|
|
flag.StringVar(&argServerExternalBinding, "external-server-port", "127.0.0.1:8080", "external server Bind listener")
|
|
|
|
}
|
|
|
|
|
|
|
|
//Run -- main entry point
|
|
|
|
func Run() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
loginfo = log.New(os.Stdout, "INFO: packer: ", logFlags)
|
|
|
|
logdebug = log.New(os.Stdout, "DEBUG: packer:", logFlags)
|
|
|
|
|
|
|
|
loginfo.Println("startup")
|
|
|
|
|
2017-02-14 00:47:16 +00:00
|
|
|
fmt.Println("-=-=-=-=-=-=-=-=-=-=")
|
2017-02-12 04:13:29 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
certbundle, err := tls.LoadX509KeyPair("certs/fullchain.pem", "certs/privkey.pem")
|
|
|
|
if err != nil {
|
|
|
|
loginfo.Println(err)
|
|
|
|
return
|
|
|
|
}
|
2017-02-25 05:56:40 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
ctx, cancelContext := context.WithCancel(context.Background())
|
|
|
|
defer cancelContext()
|
2017-02-12 20:39:50 +00:00
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
// Setup for GenericListenServe.
|
|
|
|
// - establish context for the generic listener
|
|
|
|
// - startup listener
|
|
|
|
// - accept with peek buffer.
|
|
|
|
// - peek at the 1st 30 bytes.
|
|
|
|
// - check for tls
|
|
|
|
// - if tls, establish, protocol peek buffer, else decrypted
|
|
|
|
// - match protocol
|
|
|
|
|
2017-03-03 00:47:59 +00:00
|
|
|
connectionTracking := genericlistener.NewTracking()
|
|
|
|
go connectionTracking.Run(ctx)
|
|
|
|
|
|
|
|
connectionTable = genericlistener.NewTable()
|
|
|
|
go connectionTable.Run(ctx)
|
|
|
|
|
|
|
|
genericListeners := genericlistener.NewGenerListeners(ctx, connectionTable, connectionTracking, secretKey, certbundle, argDeadTime)
|
2017-02-26 23:27:38 +00:00
|
|
|
go genericListeners.Run(ctx, 8443)
|
2017-02-26 05:17:39 +00:00
|
|
|
|
2017-02-26 23:27:38 +00:00
|
|
|
//go genericlistener.GenericListenAndServe(ctx, connectionTable, secretKey, argGenericBinding, certbundle, argDeadTime)
|
|
|
|
|
|
|
|
time.Sleep(300 * time.Second)
|
2017-02-26 05:17:39 +00:00
|
|
|
cancelContext()
|
|
|
|
time.Sleep(60 * time.Second)
|
|
|
|
|
|
|
|
//wssMapping = xlate.NewwssMapping()
|
|
|
|
//go wssMapping.Run()
|
2017-02-25 05:56:40 +00:00
|
|
|
|
|
|
|
//go client.LaunchClientListener(connectionTable, &secretKey, &argServerBinding)
|
2017-02-18 21:21:36 +00:00
|
|
|
//go external.LaunchWebRequestExternalListener(&argServerExternalBinding, connectionTable)
|
2017-02-25 05:56:40 +00:00
|
|
|
//go external.LaunchExternalServer(argServerExternalBinding, connectionTable)
|
|
|
|
//err = admin.LaunchAdminListener(&argServerAdminBinding, connectionTable)
|
|
|
|
//if err != nil {
|
|
|
|
// loginfo.Println("LauchAdminListener failed: ", err)
|
|
|
|
//}
|
|
|
|
|
2017-02-26 05:17:39 +00:00
|
|
|
//genericlistener.LaunchWssListener(connectionTable, secretKey, argWssClientListener, "certs/fullchain.pem", "certs/privkey.pem")
|
2017-02-12 04:13:29 +00:00
|
|
|
}
|