2023-09-29 16:00:20 +02:00
|
|
|
/*
|
|
|
|
* ctrlserver controls the WireGuard mesh. Contains an IpcHandler for
|
|
|
|
* handling commands fired by wgmesh command.
|
|
|
|
* Contains an RpcHandler for handling commands fired by another server.
|
|
|
|
*/
|
2023-09-18 16:52:28 +02:00
|
|
|
package ctrlserver
|
|
|
|
|
|
|
|
import (
|
2023-10-02 17:03:41 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/conf"
|
2023-10-01 20:01:35 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/conn"
|
2023-10-05 18:48:54 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/manager"
|
2023-10-02 17:03:41 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/rpc"
|
2023-09-19 14:45:49 +02:00
|
|
|
"golang.zx2c4.com/wireguard/wgctrl"
|
2023-09-18 16:52:28 +02:00
|
|
|
)
|
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
type NewCtrlServerParams struct {
|
|
|
|
WgClient *wgctrl.Client
|
|
|
|
Conf *conf.WgMeshConfiguration
|
|
|
|
AuthProvider rpc.AuthenticationServer
|
|
|
|
CtrlProvider rpc.MeshCtrlServerServer
|
2023-10-20 13:41:06 +02:00
|
|
|
SyncProvider rpc.SyncServiceServer
|
2023-10-02 17:03:41 +02:00
|
|
|
}
|
|
|
|
|
2023-09-18 16:52:28 +02:00
|
|
|
/*
|
2023-09-29 16:00:20 +02:00
|
|
|
* NewCtrlServer creates a new instance of the ctrlserver.
|
|
|
|
* It is associated with a WireGuard client and an interface.
|
|
|
|
* wgClient: Represents the WireGuard control client.
|
|
|
|
* ifName: WireGuard interface name
|
2023-09-18 16:52:28 +02:00
|
|
|
*/
|
2023-10-02 17:03:41 +02:00
|
|
|
func NewCtrlServer(params *NewCtrlServerParams) (*MeshCtrlServer, error) {
|
2023-09-18 16:52:28 +02:00
|
|
|
ctrlServer := new(MeshCtrlServer)
|
2023-10-02 17:03:41 +02:00
|
|
|
ctrlServer.Client = params.WgClient
|
2023-10-20 18:35:02 +02:00
|
|
|
ctrlServer.MeshManager = manager.NewMeshManager(*params.WgClient, *params.Conf)
|
2023-10-10 21:14:40 +02:00
|
|
|
ctrlServer.Conf = params.Conf
|
2023-10-02 17:03:41 +02:00
|
|
|
|
2023-10-05 18:48:54 +02:00
|
|
|
connManagerParams := conn.NewJwtConnectionManagerParams{
|
2023-10-02 17:03:41 +02:00
|
|
|
CertificatePath: params.Conf.CertificatePath,
|
|
|
|
PrivateKey: params.Conf.PrivateKeyPath,
|
|
|
|
SkipCertVerification: params.Conf.SkipCertVerification,
|
|
|
|
}
|
|
|
|
|
2023-10-05 18:48:54 +02:00
|
|
|
connMgr, err := conn.NewJwtConnectionManager(&connManagerParams)
|
2023-10-02 17:03:41 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctrlServer.ConnectionManager = connMgr
|
|
|
|
|
|
|
|
connServerParams := conn.NewConnectionServerParams{
|
2023-10-10 21:14:40 +02:00
|
|
|
Conf: params.Conf,
|
|
|
|
AuthProvider: params.AuthProvider,
|
|
|
|
CtrlProvider: params.CtrlProvider,
|
2023-10-20 13:41:06 +02:00
|
|
|
SyncProvider: params.SyncProvider,
|
2023-10-02 17:03:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
connServer, err := conn.NewConnectionServer(&connServerParams)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctrlServer.ConnectionServer = connServer
|
|
|
|
return ctrlServer, nil
|
2023-09-18 16:52:28 +02:00
|
|
|
}
|