Added support for default load balancer method.
This commit is contained in:
parent
5dae8b1f9e
commit
4696ec4ec2
|
@ -13,4 +13,7 @@ rvpn:
|
|||
secret: abc123
|
||||
test3.daplie.me:
|
||||
secret: abc123
|
||||
loadbalancing:
|
||||
defaultmethod: 'round-robin'
|
||||
|
||||
|
||||
|
|
8
main.go
8
main.go
|
@ -32,6 +32,7 @@ var (
|
|||
idle int
|
||||
dwell int
|
||||
cancelcheck int
|
||||
lbDefaultMethod string
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -59,6 +60,7 @@ func main() {
|
|||
idle = deadtime.(map[string]interface{})["idle"].(int)
|
||||
dwell = deadtime.(map[string]interface{})["dwell"].(int)
|
||||
cancelcheck = deadtime.(map[string]interface{})["cancelcheck"].(int)
|
||||
lbDefaultMethod = viper.Get("rvpn.loadbalancing.defaultmethod").(string)
|
||||
|
||||
loginfo.Println("startup")
|
||||
|
||||
|
@ -91,8 +93,10 @@ func main() {
|
|||
connectionTable = genericlistener.NewTable(dwell, idle)
|
||||
go connectionTable.Run(ctx)
|
||||
|
||||
genericListeners := genericlistener.NewGenerListeners(ctx, connectionTable, connectionTracking, secretKey, certbundle, wssHostName, adminHostName, cancelcheck)
|
||||
go genericListeners.Run(ctx, argGenericBinding)
|
||||
genericListeners := genericlistener.NewGenerListeners(ctx, connectionTable, connectionTracking, secretKey, certbundle, wssHostName,
|
||||
adminHostName, cancelcheck, lbDefaultMethod)
|
||||
|
||||
genericListeners.Run(ctx, argGenericBinding)
|
||||
|
||||
//Run for 10 minutes and then shutdown cleanly
|
||||
time.Sleep(6000 * time.Second)
|
||||
|
|
|
@ -26,14 +26,15 @@ type contextKey string
|
|||
|
||||
//CtxConnectionTrack
|
||||
const (
|
||||
ctxSecretKey contextKey = "secretKey"
|
||||
ctxConnectionTable contextKey = "connectionTable"
|
||||
ctxConfig contextKey = "config"
|
||||
ctxListenerRegistration contextKey = "listenerRegistration"
|
||||
ctxConnectionTrack contextKey = "connectionTrack"
|
||||
ctxWssHostName contextKey = "wsshostname"
|
||||
ctxAdminHostName contextKey = "adminHostName"
|
||||
ctxCancelCheck contextKey = "cancelcheck"
|
||||
ctxSecretKey contextKey = "secretKey"
|
||||
ctxConnectionTable contextKey = "connectionTable"
|
||||
ctxConfig contextKey = "config"
|
||||
ctxListenerRegistration contextKey = "listenerRegistration"
|
||||
ctxConnectionTrack contextKey = "connectionTrack"
|
||||
ctxWssHostName contextKey = "wsshostname"
|
||||
ctxAdminHostName contextKey = "adminHostName"
|
||||
ctxCancelCheck contextKey = "cancelcheck"
|
||||
ctxLoadbalanceDefaultMethod contextKey = "lbdefaultmethod"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -56,10 +56,12 @@ type GenericListeners struct {
|
|||
wssHostName string
|
||||
adminHostName string
|
||||
cancelCheck int
|
||||
lbDefaultMethod string
|
||||
}
|
||||
|
||||
//NewGenerListeners --
|
||||
func NewGenerListeners(ctx context.Context, connectionTable *Table, connectionTrack *Tracking, secretKey string, certbundle tls.Certificate, wssHostName string, adminHostName string, cancelCheck int) (p *GenericListeners) {
|
||||
func NewGenerListeners(ctx context.Context, connectionTable *Table, connectionTrack *Tracking, secretKey string, certbundle tls.Certificate,
|
||||
wssHostName string, adminHostName string, cancelCheck int, lbDefaultMethod string) (p *GenericListeners) {
|
||||
p = new(GenericListeners)
|
||||
p.listeners = make(map[*net.Listener]int)
|
||||
p.ctx = ctx
|
||||
|
@ -71,6 +73,7 @@ func NewGenerListeners(ctx context.Context, connectionTable *Table, connectionTr
|
|||
p.wssHostName = wssHostName
|
||||
p.adminHostName = adminHostName
|
||||
p.cancelCheck = cancelCheck
|
||||
p.lbDefaultMethod = lbDefaultMethod
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -93,6 +96,7 @@ func (gl *GenericListeners) Run(ctx context.Context, initialPort int) {
|
|||
ctx = context.WithValue(ctx, ctxWssHostName, gl.wssHostName)
|
||||
ctx = context.WithValue(ctx, ctxAdminHostName, gl.adminHostName)
|
||||
ctx = context.WithValue(ctx, ctxCancelCheck, gl.cancelCheck)
|
||||
ctx = context.WithValue(ctx, ctxLoadbalanceDefaultMethod, gl.lbDefaultMethod)
|
||||
|
||||
go func(ctx context.Context) {
|
||||
for {
|
||||
|
|
Loading…
Reference in New Issue