mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-27 17:25:20 -04:00
AB#1903 Push keys to restarting nodes on trigger RPC
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
152e3985f7
commit
37aff14cab
9 changed files with 193 additions and 24 deletions
|
@ -3,16 +3,19 @@ package pubapi
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/coordinator/atls"
|
||||
"github.com/edgelesssys/constellation/coordinator/pubapi/pubproto"
|
||||
"github.com/edgelesssys/constellation/state/setup"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/peer"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -34,11 +37,12 @@ type API struct {
|
|||
stopUpdate chan struct{}
|
||||
wgClose sync.WaitGroup
|
||||
resourceVersion int
|
||||
peerFromContext PeerFromContextFunc
|
||||
pubproto.UnimplementedAPIServer
|
||||
}
|
||||
|
||||
// New creates a new API.
|
||||
func New(logger *zap.Logger, core Core, dialer Dialer, vpnAPIServer VPNAPIServer, validator atls.Validator, getPublicIPAddr GetIPAddrFunc) *API {
|
||||
func New(logger *zap.Logger, core Core, dialer Dialer, vpnAPIServer VPNAPIServer, validator atls.Validator, getPublicIPAddr GetIPAddrFunc, peerFromContext PeerFromContextFunc) *API {
|
||||
return &API{
|
||||
logger: logger,
|
||||
core: core,
|
||||
|
@ -47,6 +51,7 @@ func New(logger *zap.Logger, core Core, dialer Dialer, vpnAPIServer VPNAPIServer
|
|||
validator: validator,
|
||||
getPublicIPAddr: getPublicIPAddr,
|
||||
stopUpdate: make(chan struct{}, 1),
|
||||
peerFromContext: peerFromContext,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,3 +117,21 @@ type VPNAPIServer interface {
|
|||
}
|
||||
|
||||
type GetIPAddrFunc func() (string, error)
|
||||
|
||||
// PeerFromContextFunc returns a peer endpoint (IP:port) from a given context.
|
||||
type PeerFromContextFunc func(context.Context) (string, error)
|
||||
|
||||
// GetRecoveryPeerFromContext returns the context's IP joined with the Coordinator's default port.
|
||||
func GetRecoveryPeerFromContext(ctx context.Context) (string, error) {
|
||||
peer, ok := peer.FromContext(ctx)
|
||||
if !ok {
|
||||
return "", errors.New("unable to get peer from context")
|
||||
}
|
||||
|
||||
peerIP, _, err := net.SplitHostPort(peer.Addr.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return net.JoinHostPort(peerIP, setup.RecoveryPort), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue