Skip to content

Commit f4ca465

Browse files
ellemoutonpositiveblue
authored andcommitted
subservers: start using the subservers manager
1 parent c3bc991 commit f4ca465

File tree

2 files changed

+147
-218
lines changed

2 files changed

+147
-218
lines changed

subservers/manager.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77
"time"
88

9+
"github.com/lightninglabs/lightning-terminal/perms"
910
"github.com/lightninglabs/lndclient"
1011
"github.com/lightningnetwork/lnd/lnrpc"
1112
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
@@ -27,13 +28,16 @@ var (
2728

2829
// Manager manages a set of subServer objects.
2930
type Manager struct {
30-
servers []*subServerWrapper
31-
mu sync.RWMutex
31+
servers []*subServerWrapper
32+
permsMgr *perms.Manager
33+
mu sync.RWMutex
3234
}
3335

3436
// NewManager constructs a new subServerMgr.
35-
func NewManager() *Manager {
36-
return &Manager{}
37+
func NewManager(permsMgr *perms.Manager) *Manager {
38+
return &Manager{
39+
permsMgr: permsMgr,
40+
}
3741
}
3842

3943
// AddServer adds a new subServer to the manager's set.
@@ -112,6 +116,29 @@ func (s *Manager) RegisterRPCServices(server grpc.ServiceRegistrar) {
112116
}
113117
}
114118

119+
// GetRemoteConn checks if any of the manager's sub-servers owns the given uri
120+
// and if so, the remote connection to that sub-server is returned. The bool
121+
// return value indicates if the uri is managed by one of the sub-servers
122+
// running in remote mode.
123+
func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn) {
124+
s.mu.RLock()
125+
defer s.mu.RUnlock()
126+
127+
for _, ss := range s.servers {
128+
if !s.permsMgr.IsSubServerURI(ss.subServer.Name(), uri) {
129+
continue
130+
}
131+
132+
if !ss.subServer.Remote() {
133+
return false, nil
134+
}
135+
136+
return true, ss.remoteConn
137+
}
138+
139+
return false, nil
140+
}
141+
115142
// ValidateMacaroon checks if any of the manager's sub-servers owns the given
116143
// uri and if so, if it is running in remote mode, then true is returned since
117144
// the macaroon will be validated by the remote subserver itself when the
@@ -124,7 +151,9 @@ func (s *Manager) ValidateMacaroon(ctx context.Context,
124151
defer s.mu.RUnlock()
125152

126153
for _, ss := range s.servers {
127-
// TODO(positiveblue): check subserver permissions.
154+
if !s.permsMgr.IsSubServerURI(ss.subServer.Name(), uri) {
155+
continue
156+
}
128157

129158
// If the sub-server is running in remote mode, then we don't
130159
// need to validate the macaroon here since the remote server

0 commit comments

Comments
 (0)