mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-27 09:15:22 -04:00
pubapi: extract StartVPNAPIServer and StartUpdateLoop as separate functions
Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
parent
77b0237dd5
commit
f2b3fc328b
4 changed files with 25 additions and 18 deletions
|
@ -4,6 +4,7 @@ package pubapi
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -55,6 +56,21 @@ func (a *API) GetState(ctx context.Context, in *pubproto.GetStateRequest) (*pubp
|
|||
return &pubproto.GetStateResponse{State: uint32(a.core.GetState())}, nil
|
||||
}
|
||||
|
||||
// StartVPNAPIServer starts the VPN-API server.
|
||||
func (a *API) StartVPNAPIServer(vpnIP string) error {
|
||||
if err := a.vpnAPIServer.Listen(net.JoinHostPort(vpnIP, vpnAPIPort)); err != nil {
|
||||
return fmt.Errorf("start vpnAPIServer: %v", err)
|
||||
}
|
||||
a.wgClose.Add(1)
|
||||
go func() {
|
||||
defer a.wgClose.Done()
|
||||
if err := a.vpnAPIServer.Serve(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the API.
|
||||
func (a *API) Close() {
|
||||
a.stopUpdate <- struct{}{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue