From 3cb1ce050cc2c1269d5526a4c90cda03c03d312c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 16 Jan 2016 19:09:41 -0800 Subject: [PATCH] create, and start server within main entry point --- lnd.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lnd.go b/lnd.go index 8561f381..afcc516f 100644 --- a/lnd.go +++ b/lnd.go @@ -4,18 +4,23 @@ import ( "flag" "fmt" "net" + "net/http" + _ "net/http/pprof" "os" "time" "google.golang.org/grpc" "google.golang.org/grpc/grpclog" + "github.com/btcsuite/btcd/chaincfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnwallet" ) var ( - rpcport = flag.Int("port", 10000, "The port for the rpc server") + rpcPort = flag.Int("rpcport", 10009, "The port for the rpc server") + peerPort = flag.String("peerport", "10011", "The port to listen on for incoming p2p connections") + dataDir = flag.String("datadir", "test_wal", "The directory to store lnd's data within") ) func main() { @@ -33,7 +38,8 @@ func main() { // logic, and exposes control via proxy state machines. // TODO(roasbeef): accept config via cli flags, move to real config file // afterwards - config := &lnwallet.Config{PrivatePass: []byte("hello"), DataDir: "test_wal"} + config := &lnwallet.Config{PrivatePass: []byte("hello"), DataDir: *dataDir} + lnwallet, db, err := lnwallet.NewLightningWallet(config) if err != nil { fmt.Printf("unable to create wallet: %v\n", err) @@ -49,16 +55,24 @@ func main() { fmt.Println("wallet open") defer db.Close() + // Set up the core server which will listen for incoming peer + // connections. + defaultListenAddr := []string{net.JoinHostPort("", *peerPort)} + server, err := newServer(defaultListenAddr, &chaincfg.TestNet3Params, + lnwallet) + if err != nil { + fmt.Printf("unable to create server: %v\n", err) + os.Exit(1) + } + server.Start() + // Initialize, and register our implementation of the gRPC server. var opts []grpc.ServerOption - rpcServer := newRpcServer(lnwallet) - // start message handler for incoming LN messages - go OmniHandler(rpcServer) grpcServer := grpc.NewServer(opts...) - lnrpc.RegisterLightningServer(grpcServer, rpcServer) + lnrpc.RegisterLightningServer(grpcServer, server.rpcServer) // Finally, start the grpc server listening for HTTP/2 connections. - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *rpcport)) + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *rpcPort)) if err != nil { grpclog.Fatalf("failed to listen: %v", err) fmt.Printf("failed to listen: %v", err)