add constructor for core server struct
This commit is contained in:
parent
7ecbb2debc
commit
1f1b82fe3f
20
rpcserver.go
20
rpcserver.go
@ -24,11 +24,15 @@ var (
|
||||
)
|
||||
|
||||
// rpcServer...
|
||||
type rpcServer struct { // doesn't count as globals I think
|
||||
lnwallet *lnwallet.LightningWallet // interface to the bitcoin network
|
||||
CnMap map[[16]byte]net.Conn //interface to the lightning network
|
||||
OmniChan chan []byte // channel for all incoming messages from LN nodes.
|
||||
// can split the OmniChan up if that is helpful. So far 1 seems OK.
|
||||
type rpcServer struct {
|
||||
started int32 // To be used atomically.
|
||||
shutdown int32 // To be used atomically.
|
||||
|
||||
server *server
|
||||
|
||||
wg sync.WaitGroup
|
||||
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
type LNAdr struct {
|
||||
@ -94,10 +98,8 @@ func (l *LNAdr) ParseFromString(s string) error {
|
||||
var _ lnrpc.LightningServer = (*rpcServer)(nil)
|
||||
|
||||
// newRpcServer...
|
||||
func newRpcServer(wallet *lnwallet.LightningWallet) *rpcServer {
|
||||
return &rpcServer{wallet,
|
||||
make(map[[16]byte]net.Conn), // initialize with empty CnMap
|
||||
make(chan []byte)} // init OmniChan (size 1 ok...?)
|
||||
func newRpcServer(s *server) *rpcServer {
|
||||
return &rpcServer{server: s, quit: make(chan struct{}, 1)}
|
||||
}
|
||||
|
||||
// Stop...
|
||||
|
49
server.go
49
server.go
@ -1,39 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lightningnetwork/lnd/lndc"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
)
|
||||
|
||||
// server...
|
||||
type server struct {
|
||||
listeners []net.Listener
|
||||
peers map[int32]*peer
|
||||
|
||||
started int32 // atomic
|
||||
shutdown int32 // atomic
|
||||
|
||||
bitcoinNet *chaincfg.Params
|
||||
longTermPriv *btcec.PrivateKey
|
||||
bitcoinNet *chaincfg.Params
|
||||
|
||||
listeners []net.Listener
|
||||
peers map[int32]*peer
|
||||
|
||||
rpcServer *rpcServer
|
||||
lnwallet *lnwallet.LightningWallet
|
||||
|
||||
db walletdb.DB
|
||||
db walletdb.DB
|
||||
|
||||
newPeers chan *peer
|
||||
donePeers chan *peer
|
||||
queries chan interface{}
|
||||
|
||||
wg sync.WaitGroup
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
// newServer...
|
||||
func newServer(listenAddrs []string, bitcoinNet *chaincfg.Params,
|
||||
wallet *lnwallet.LightningWallet) (*server, error) {
|
||||
privKey, err := getIdentityPrivKey(wallet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
listeners := make([]net.Listener, len(listenAddrs))
|
||||
for i, addr := range listenAddrs {
|
||||
listeners[i], err = lndc.NewListener(privKey, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
s := &server{
|
||||
longTermPriv: privKey,
|
||||
listeners: listeners,
|
||||
peers: make(map[int32]*peer),
|
||||
newPeers: make(chan *peer, 100),
|
||||
donePeers: make(chan *peer, 100),
|
||||
lnwallet: wallet,
|
||||
queries: make(chan interface{}),
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
s.rpcServer = newRpcServer(s)
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// addPeer...
|
||||
func (s *server) addPeer(p *peer) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user