-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roughed in grpc infrastructure for agent (#463)
- Loading branch information
1 parent
bd0f2d7
commit 95098e6
Showing
9 changed files
with
85 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
package agent | ||
|
||
type Daemon struct { | ||
import ( | ||
agentGrpc "github.com/openziti/zrok/agent/grpc" | ||
"github.com/openziti/zrok/environment/env_core" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"google.golang.org/grpc" | ||
"net" | ||
) | ||
|
||
type Agent struct { | ||
root env_core.Root | ||
shares map[string]*share | ||
accesses map[string]*access | ||
} | ||
|
||
func NewDaemon() *Daemon { | ||
return &Daemon{ | ||
func NewAgent(root env_core.Root) (*Agent, error) { | ||
if !root.IsEnabled() { | ||
return nil, errors.Errorf("unable to load environment; did you 'zrok enable'?") | ||
} | ||
return &Agent{ | ||
root: root, | ||
shares: make(map[string]*share), | ||
accesses: make(map[string]*access), | ||
}, nil | ||
} | ||
|
||
func (a *Agent) Run() error { | ||
logrus.Infof("started") | ||
agentSocket, err := a.root.AgentSocket() | ||
if err != nil { | ||
return err | ||
} | ||
l, err := net.Listen("unix", agentSocket) | ||
if err != nil { | ||
return err | ||
} | ||
srv := grpc.NewServer() | ||
agentGrpc.RegisterAgentServer(srv, &agentGrpcImpl{}) | ||
if err := srv.Serve(l); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters