fix: support list guest and knock

This commit is contained in:
Daniel Ding
2024-01-02 11:14:54 +08:00
parent 9a039a6d3c
commit 1af91f2f65
9 changed files with 131 additions and 34 deletions

69
pkg/api/api.go Executable file
View File

@@ -0,0 +1,69 @@
package api
import (
co "github.com/luscis/openlan/pkg/config"
"github.com/luscis/openlan/pkg/libol"
cn "github.com/luscis/openlan/pkg/network"
"github.com/luscis/openlan/pkg/schema"
)
type Switcher interface {
UUID() string
UpTime() int64
Alias() string
Config() *co.Switch
Server() libol.SocketServer
Reload()
Save()
}
func NewWorkerSchema(s Switcher) schema.Worker {
protocol := ""
if cfg := s.Config(); cfg != nil {
protocol = cfg.Protocol
}
return schema.Worker{
UUID: s.UUID(),
Uptime: s.UpTime(),
Alias: s.Alias(),
Protocol: protocol,
}
}
type ZTruster interface {
AddGuest(name, source string) error
DelGuest(name, source string) error
Knock(name string, protocol, dest, port string, age int) error
ListGuest(call func(obj schema.ZGuest))
ListKnock(name string, call func(obj schema.KnockRule))
}
type Networker interface {
String() string
ID() string
Initialize()
Start(v Switcher)
Stop()
Bridge() cn.Bridger
Config() *co.Network
Subnet() string
Reload(v Switcher)
Provider() string
ZTruster() ZTruster
}
var workers = make(map[string]Networker)
func AddWorker(name string, obj Networker) {
workers[name] = obj
}
func GetWorker(name string) Networker {
return workers[name]
}
func ListWorker(call func(w Networker)) {
for _, worker := range workers {
call(worker)
}
}