smegmesh/cmd/wgmeshd/main.go

59 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
2023-09-28 17:55:37 +02:00
"log"
"net"
2023-09-19 14:45:49 +02:00
2023-10-01 20:01:35 +02:00
"github.com/tim-beatham/wgmesh/pkg/conf"
"github.com/tim-beatham/wgmesh/pkg/conn"
ctrlserver "github.com/tim-beatham/wgmesh/pkg/ctrlserver"
2023-09-29 16:00:20 +02:00
"github.com/tim-beatham/wgmesh/pkg/ipc"
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"
"github.com/tim-beatham/wgmesh/pkg/rpc"
2023-09-19 14:45:49 +02:00
wg "github.com/tim-beatham/wgmesh/pkg/wg"
)
2023-09-28 17:55:37 +02:00
const ifName = "wgmesh"
func main() {
2023-09-28 17:55:37 +02:00
wgClient, err := wg.CreateClient(ifName)
2023-09-19 14:45:49 +02:00
if err != nil {
2023-09-28 17:55:37 +02:00
log.Fatalf("Could not create interface %s\n", ifName)
2023-09-19 14:45:49 +02:00
}
2023-10-01 20:01:35 +02:00
conf, err := conf.ParseConfiguration("./configuration.yaml")
newConnParams := conn.NewConnectionsParams{
CertificatePath: conf.CertificatePath,
PrivateKey: conf.PrivateKeyPath,
SkipCertVerification: conf.SkipCertVerification,
}
conn, err := conn.NewConnection(&newConnParams)
if err != nil {
return
}
ctrlServer := ctrlserver.NewCtrlServer(wgClient, conn, "wgmesh")
2023-09-28 17:55:37 +02:00
log.Println("Running IPC Handler")
2023-09-29 16:00:20 +02:00
robinIpc := robin.NewRobinIpc(ctrlServer)
robinRpc := robin.NewRobinRpc(ctrlServer)
go ipc.RunIpcHandler(robinIpc)
2023-10-01 20:01:35 +02:00
grpc := conn.Listen(ctrlServer.JwtManager.GetAuthInterceptor())
rpc.NewRpcServer(grpc, robinRpc, middleware.NewAuthProvider(ctrlServer))
lis, err := net.Listen("tcp", ":8080")
if err := grpc.Serve(lis); err != nil {
2023-09-28 17:55:37 +02:00
log.Fatal(err.Error())
}
2023-09-20 15:34:34 +02:00
defer wgClient.Close()
}