code polish and naming lint (#463)

This commit is contained in:
Michael Quigley 2024-09-25 11:06:06 -04:00
parent 1d012b849a
commit 9492f93a1d
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
10 changed files with 37 additions and 37 deletions

View File

@ -22,14 +22,14 @@ type access struct {
bootComplete chan struct{}
bootErr error
a *Agent
agent *Agent
}
func (a *access) monitor() {
if err := proctree.WaitChild(a.process); err != nil {
pfxlog.ChannelLogger(a.token).Error(err)
}
a.a.outAccesses <- a
a.agent.rmAccess <- a
}
func (a *access) tail(data []byte) {

View File

@ -26,7 +26,7 @@ func (i *agentGrpcImpl) AccessPrivate(_ context.Context, req *agentGrpc.AccessPr
bindAddress: req.BindAddress,
responseHeaders: req.ResponseHeaders,
bootComplete: make(chan struct{}),
a: i.a,
agent: i.agent,
}
logrus.Infof("executing '%v'", accCmd)
@ -40,7 +40,7 @@ func (i *agentGrpcImpl) AccessPrivate(_ context.Context, req *agentGrpc.AccessPr
<-acc.bootComplete
if acc.bootErr == nil {
i.a.inAccesses <- acc
i.agent.addAccess <- acc
return &agentGrpc.AccessPrivateResponse{FrontendToken: acc.frontendToken}, nil
}

View File

@ -16,11 +16,11 @@ type Agent struct {
root env_core.Root
agentSocket string
shares map[string]*share
inShares chan *share
outShares chan *share
addShare chan *share
rmShare chan *share
accesses map[string]*access
inAccesses chan *access
outAccesses chan *access
addAccess chan *access
rmAccess chan *access
}
func NewAgent(root env_core.Root) (*Agent, error) {
@ -28,13 +28,13 @@ func NewAgent(root env_core.Root) (*Agent, error) {
return nil, errors.Errorf("unable to load environment; did you 'zrok enable'?")
}
return &Agent{
root: root,
shares: make(map[string]*share),
inShares: make(chan *share),
outShares: make(chan *share),
accesses: make(map[string]*access),
inAccesses: make(chan *access),
outAccesses: make(chan *access),
root: root,
shares: make(map[string]*share),
addShare: make(chan *share),
rmShare: make(chan *share),
accesses: make(map[string]*access),
addAccess: make(chan *access),
rmAccess: make(chan *access),
}, nil
}
@ -57,7 +57,7 @@ func (a *Agent) Run() error {
a.agentSocket = agentSocket
srv := grpc.NewServer()
agentGrpc.RegisterAgentServer(srv, &agentGrpcImpl{a: a})
agentGrpc.RegisterAgentServer(srv, &agentGrpcImpl{agent: a})
if err := srv.Serve(l); err != nil {
return err
}
@ -73,11 +73,11 @@ func (a *Agent) Shutdown() {
}
for _, shr := range a.shares {
logrus.Debugf("stopping share '%v'", shr.token)
a.outShares <- shr
a.rmShare <- shr
}
for _, acc := range a.accesses {
logrus.Debugf("stopping access '%v'", acc.token)
a.outAccesses <- acc
a.rmAccess <- acc
}
}
@ -87,11 +87,11 @@ func (a *Agent) manager() {
for {
select {
case inShare := <-a.inShares:
case inShare := <-a.addShare:
logrus.Infof("adding new share '%v'", inShare.token)
a.shares[inShare.token] = inShare
case outShare := <-a.outShares:
case outShare := <-a.rmShare:
if shr, found := a.shares[outShare.token]; found {
logrus.Infof("removing share '%v'", shr.token)
if err := proctree.StopChild(shr.process); err != nil {
@ -110,11 +110,11 @@ func (a *Agent) manager() {
logrus.Debug("skipping unidentified (orphaned) share removal")
}
case inAccess := <-a.inAccesses:
case inAccess := <-a.addAccess:
logrus.Infof("adding new access '%v'", inAccess.frontendToken)
a.accesses[inAccess.frontendToken] = inAccess
case outAccess := <-a.outAccesses:
case outAccess := <-a.rmAccess:
if acc, found := a.accesses[outAccess.frontendToken]; found {
logrus.Infof("removing access '%v'", acc.frontendToken)
if err := proctree.StopChild(acc.process); err != nil {
@ -152,5 +152,5 @@ func (a *Agent) deleteAccess(token, frontendToken string) error {
type agentGrpcImpl struct {
agentGrpc.UnimplementedAgentServer
a *Agent
agent *Agent
}

View File

@ -8,8 +8,8 @@ import (
)
func (i *agentGrpcImpl) ReleaseAccess(_ context.Context, req *agentGrpc.ReleaseAccessRequest) (*agentGrpc.ReleaseAccessResponse, error) {
if acc, found := i.a.accesses[req.FrontendToken]; found {
i.a.outAccesses <- acc
if acc, found := i.agent.accesses[req.FrontendToken]; found {
i.agent.rmAccess <- acc
logrus.Infof("released access '%v'", acc.frontendToken)
} else {

View File

@ -8,8 +8,8 @@ import (
)
func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareResponse, error) {
if shr, found := i.a.shares[req.Token]; found {
i.a.outShares <- shr
if shr, found := i.agent.shares[req.Token]; found {
i.agent.rmShare <- shr
logrus.Infof("released share '%v'", shr.token)
} else {

View File

@ -34,14 +34,14 @@ type share struct {
bootComplete chan struct{}
bootErr error
a *Agent
agent *Agent
}
func (s *share) monitor() {
if err := proctree.WaitChild(s.process); err != nil {
pfxlog.ChannelLogger(s.token).Error(err)
}
s.a.outShares <- s
s.agent.rmShare <- s
}
func (s *share) tail(data []byte) {

View File

@ -26,7 +26,7 @@ func (i *agentGrpcImpl) SharePrivate(_ context.Context, req *agentGrpc.SharePriv
shareMode: sdk.PrivateShareMode,
backendMode: sdk.BackendMode(req.BackendMode),
bootComplete: make(chan struct{}),
a: i.a,
agent: i.agent,
}
if req.Insecure {
@ -58,7 +58,7 @@ func (i *agentGrpcImpl) SharePrivate(_ context.Context, req *agentGrpc.SharePriv
<-shr.bootComplete
if shr.bootErr == nil {
i.a.inShares <- shr
i.agent.addShare <- shr
return &agentGrpc.SharePrivateResponse{Token: shr.token}, nil
}

View File

@ -26,7 +26,7 @@ func (i *agentGrpcImpl) SharePublic(_ context.Context, req *agentGrpc.SharePubli
shareMode: sdk.PublicShareMode,
backendMode: sdk.BackendMode(req.BackendMode),
bootComplete: make(chan struct{}),
a: i.a,
agent: i.agent,
}
for _, basicAuth := range req.BasicAuth {
@ -82,7 +82,7 @@ func (i *agentGrpcImpl) SharePublic(_ context.Context, req *agentGrpc.SharePubli
<-shr.bootComplete
if shr.bootErr == nil {
i.a.inShares <- shr
i.agent.addShare <- shr
return &agentGrpc.SharePublicResponse{
Token: shr.token,
FrontendEndpoints: shr.frontendEndpoints,

View File

@ -23,7 +23,7 @@ func (i *agentGrpcImpl) ShareReserved(_ context.Context, req *agentGrpc.ShareRes
shr := &share{
reserved: true,
bootComplete: make(chan struct{}),
a: i.a,
agent: i.agent,
}
if req.OverrideEndpoint != "" {
@ -47,7 +47,7 @@ func (i *agentGrpcImpl) ShareReserved(_ context.Context, req *agentGrpc.ShareRes
<-shr.bootComplete
if shr.bootErr == nil {
i.a.inShares <- shr
i.agent.addShare <- shr
return &agentGrpc.ShareReservedResponse{
Token: shr.token,
BackendMode: string(shr.backendMode),

View File

@ -7,7 +7,7 @@ import (
func (i *agentGrpcImpl) Status(_ context.Context, _ *agentGrpc.StatusRequest) (*agentGrpc.StatusResponse, error) {
var accesses []*agentGrpc.AccessDetail
for feToken, acc := range i.a.accesses {
for feToken, acc := range i.agent.accesses {
accesses = append(accesses, &agentGrpc.AccessDetail{
FrontendToken: feToken,
Token: acc.token,
@ -17,7 +17,7 @@ func (i *agentGrpcImpl) Status(_ context.Context, _ *agentGrpc.StatusRequest) (*
}
var shares []*agentGrpc.ShareDetail
for token, shr := range i.a.shares {
for token, shr := range i.agent.shares {
shares = append(shares, &agentGrpc.ShareDetail{
Token: token,
ShareMode: string(shr.shareMode),