2023-09-18 16:52:28 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-09-28 17:55:37 +02:00
|
|
|
"log"
|
2023-09-19 14:45:49 +02:00
|
|
|
|
2023-10-01 20:01:35 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/conf"
|
2023-09-18 16:52:28 +02:00
|
|
|
ctrlserver "github.com/tim-beatham/wgmesh/pkg/ctrlserver"
|
2023-10-05 18:48:54 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/ip"
|
2023-09-29 16:00:20 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/ipc"
|
2023-10-02 17:03:41 +02:00
|
|
|
logging "github.com/tim-beatham/wgmesh/pkg/log"
|
2023-10-01 20:01:35 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/middleware"
|
2023-09-29 16:00:20 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/robin"
|
2023-10-20 13:41:06 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/sync"
|
2023-09-19 14:45:49 +02:00
|
|
|
wg "github.com/tim-beatham/wgmesh/pkg/wg"
|
2023-09-18 16:52:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-10-02 17:03:41 +02:00
|
|
|
conf, err := conf.ParseConfiguration("./configuration.yaml")
|
2023-09-19 14:45:49 +02:00
|
|
|
if err != nil {
|
2023-10-02 17:03:41 +02:00
|
|
|
log.Fatalln("Could not parse configuration")
|
2023-09-19 14:45:49 +02:00
|
|
|
}
|
|
|
|
|
2023-10-20 13:41:06 +02:00
|
|
|
wgClient, err := wg.CreateClient(conf.IfName, conf.WgPort)
|
2023-10-01 20:01:35 +02:00
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
var robinRpc robin.RobinRpc
|
|
|
|
var robinIpc robin.RobinIpc
|
|
|
|
var authProvider middleware.AuthRpcProvider
|
2023-10-20 13:41:06 +02:00
|
|
|
var syncProvider sync.SyncServiceImpl
|
2023-10-02 17:03:41 +02:00
|
|
|
|
|
|
|
ctrlServerParams := ctrlserver.NewCtrlServerParams{
|
|
|
|
WgClient: wgClient,
|
|
|
|
Conf: conf,
|
|
|
|
AuthProvider: &authProvider,
|
|
|
|
CtrlProvider: &robinRpc,
|
2023-10-20 13:41:06 +02:00
|
|
|
SyncProvider: &syncProvider,
|
2023-10-01 20:01:35 +02:00
|
|
|
}
|
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
ctrlServer, err := ctrlserver.NewCtrlServer(&ctrlServerParams)
|
2023-10-20 13:41:06 +02:00
|
|
|
syncProvider.Server = ctrlServer
|
|
|
|
syncRequester := sync.NewSyncRequester(ctrlServer)
|
|
|
|
syncScheduler := sync.NewSyncScheduler(ctrlServer, syncRequester, 2)
|
2023-10-05 18:48:54 +02:00
|
|
|
|
|
|
|
robinIpcParams := robin.RobinIpcParams{
|
|
|
|
CtrlServer: ctrlServer,
|
|
|
|
Allocator: &ip.ULABuilder{},
|
|
|
|
}
|
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
robinRpc.Server = ctrlServer
|
2023-10-05 18:48:54 +02:00
|
|
|
robinIpc = robin.NewRobinIpc(robinIpcParams)
|
2023-10-01 20:01:35 +02:00
|
|
|
|
|
|
|
if err != nil {
|
2023-10-24 01:12:38 +02:00
|
|
|
logging.Log.WriteErrorf(err.Error())
|
|
|
|
return
|
2023-10-01 20:01:35 +02:00
|
|
|
}
|
|
|
|
|
2023-09-28 17:55:37 +02:00
|
|
|
log.Println("Running IPC Handler")
|
2023-09-19 19:29:35 +02:00
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
go ipc.RunIpcHandler(&robinIpc)
|
2023-10-20 13:41:06 +02:00
|
|
|
go syncScheduler.Run()
|
2023-09-29 16:00:20 +02:00
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
err = ctrlServer.ConnectionServer.Listen()
|
2023-10-01 20:01:35 +02:00
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
if err != nil {
|
2023-10-24 01:12:38 +02:00
|
|
|
logging.Log.WriteErrorf(err.Error())
|
|
|
|
|
|
|
|
return
|
2023-09-19 19:29:35 +02:00
|
|
|
}
|
2023-09-20 15:34:34 +02:00
|
|
|
|
2023-10-20 13:41:06 +02:00
|
|
|
defer syncScheduler.Stop()
|
2023-10-24 01:12:38 +02:00
|
|
|
defer ctrlServer.Close()
|
|
|
|
defer wgClient.Close()
|
2023-09-18 16:52:28 +02:00
|
|
|
}
|