Skip to content

Commit

Permalink
Start refactoring helloworld app
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Oct 23, 2019
1 parent 437ee36 commit 031f535
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
24 changes: 23 additions & 1 deletion cmd/apps/helloworld/helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,35 @@ import (
"log"
"os"

"github.com/skycoin/skywire/pkg/app2/appserver"

"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire/pkg/app2"

"github.com/skycoin/dmsg/cipher"

"github.com/skycoin/skywire/pkg/app"
"github.com/skycoin/skywire/pkg/routing"
)

func main() {
pk, _ := cipher.GenerateKeyPair()

// TODO(darkrengarius): make this elegant
appKey := os.Getenv("APP_KEY")
if appKey == "" {
log.Fatalf("App key env is not set")
}

sockFile := os.Getenv("SW_UNIX")
if sockFile == "" {
log.Fatalf("Sock file env is not set")
}

app, err := app2.NewClient(logging.MustGetLogger("helloworld"), pk, sockFile, appserver.Key(appKey))
if err != nil {
log.Fatalf("Error creating app client: %v\n", err)
}

helloworldApp, err := app.Setup(&app.Config{AppName: "helloworld", AppVersion: "1.0", ProtocolVersion: "0.0.1"})
if err != nil {
log.Fatal("Setup failure:", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/app2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"net"
"net/rpc"

"github.com/skycoin/skywire/pkg/app2/appserver"

"github.com/skycoin/skywire/pkg/app2/apputil"

"github.com/pkg/errors"
Expand Down Expand Up @@ -31,7 +33,7 @@ type Client struct {
// - pid: The procID assigned for the process that Client is being used by.
// - sockFile: unix socket file to connect to the app server.
// - appKey: application key to authenticate within app server.
func NewClient(log *logging.Logger, localPK cipher.PubKey, pid apputil.ProcID, sockFile, appKey string) (*Client, error) {
func NewClient(log *logging.Logger, localPK cipher.PubKey, sockFile string, appKey appserver.Key) (*Client, error) {
rpcCl, err := rpc.Dial("unix", sockFile)
if err != nil {
return nil, errors.Wrap(err, "error connecting to the app server")
Expand All @@ -40,7 +42,6 @@ func NewClient(log *logging.Logger, localPK cipher.PubKey, pid apputil.ProcID, s
return &Client{
log: log,
pk: localPK,
pid: pid,
rpc: NewRPCClient(rpcCl, appKey),
lm: idmanager.New(),
cm: idmanager.New(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/app2/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ type RPCClient interface {
// rpcClient implements `RPCClient`.
type rpcCLient struct {
rpc *rpc.Client
appKey string
appKey appserver.Key
}

// NewRPCClient constructs new `rpcClient`.
func NewRPCClient(rpc *rpc.Client, appKey string) RPCClient {
func NewRPCClient(rpc *rpc.Client, appKey appserver.Key) RPCClient {
return &rpcCLient{
rpc: rpc,
appKey: appKey,
Expand Down

0 comments on commit 031f535

Please sign in to comment.