Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
986 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// +build routerrpc | ||
|
||
package routerrpc | ||
|
||
import ( | ||
"github.com/btcsuite/btcd/chaincfg" | ||
"github.com/lightningnetwork/lnd/macaroons" | ||
"github.com/lightningnetwork/lnd/routing" | ||
) | ||
|
||
// Config is the main configuration file for the router RPC server. It contains | ||
// all the items required for the router RPC server to carry out its duties. | ||
// The fields with struct tags are meant to be parsed as normal configuration | ||
// options, while if able to be populated, the latter fields MUST also be | ||
// specified. | ||
type Config struct { | ||
// RouterMacPath is the path for the router macaroon. If unspecified | ||
// then we assume that the macaroon will be found under the network | ||
// directory, named DefaultRouterMacFilename. | ||
RouterMacPath string `long:"routermacaroonpath" description:"Path to the router macaroon"` | ||
|
||
// NetworkDir is the main network directory wherein the router rpc | ||
// server will find the macaroon named DefaultRouterMacFilename. | ||
NetworkDir string | ||
|
||
// ActiveNetParams are the network parameters of the primary network | ||
// that the route is operating on. This is necessary so we can ensure | ||
// that we receive payment requests that send to destinations on our | ||
// network. | ||
ActiveNetParams *chaincfg.Params | ||
|
||
// MacService is the main macaroon service that we'll use to handle | ||
// authentication for the Router rpc server. | ||
MacService *macaroons.Service | ||
|
||
// Router is the main channel router instance that backs this RPC | ||
// server. | ||
// | ||
// TODO(roasbeef): make into pkg lvl interface? | ||
// | ||
// TODO(roasbeef): assumes router handles saving payment state | ||
Router *routing.ChannelRouter | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build !routerrpc | ||
|
||
package routerrpc | ||
|
||
// Config is the default config for the package. When the build tag isn't | ||
// specified, then we output a blank config. | ||
type Config struct{} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// +build routerrpc | ||
|
||
package routerrpc | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/lightningnetwork/lnd/lnrpc" | ||
) | ||
|
||
// createNewSubServer is a helper method that will create the new router sub | ||
// server given the main config dispatcher method. If we're unable to find the | ||
// config that is meant for us in the config dispatcher, then we'll exit with | ||
// an error. | ||
func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) ( | ||
lnrpc.SubServer, lnrpc.MacaroonPerms, error) { | ||
|
||
// We'll attempt to look up the config that we expect, according to our | ||
// subServerName name. If we can't find this, then we'll exit with an | ||
// error, as we're unable to properly initialize ourselves without this | ||
// config. | ||
routeServerConf, ok := configRegistry.FetchConfig(subServerName) | ||
if !ok { | ||
return nil, nil, fmt.Errorf("unable to find config for "+ | ||
"subserver type %s", subServerName) | ||
} | ||
|
||
// Now that we've found an object mapping to our service name, we'll | ||
// ensure that it's the type we need. | ||
config, ok := routeServerConf.(*Config) | ||
if !ok { | ||
return nil, nil, fmt.Errorf("wrong type of config for "+ | ||
"subserver %s, expected %T got %T", subServerName, | ||
&Config{}, routeServerConf) | ||
} | ||
|
||
// Before we try to make the new router service instance, we'll perform | ||
// some sanity checks on the arguments to ensure that they're useable. | ||
switch { | ||
case config.Router == nil: | ||
return nil, nil, fmt.Errorf("Router must be set to create " + | ||
"Routerpc") | ||
} | ||
|
||
return New(config) | ||
} | ||
|
||
func init() { | ||
subServer := &lnrpc.SubServerDriver{ | ||
SubServerName: subServerName, | ||
New: func(c lnrpc.SubServerConfigDispatcher) (lnrpc.SubServer, lnrpc.MacaroonPerms, error) { | ||
return createNewSubServer(c) | ||
}, | ||
} | ||
|
||
// If the build tag is active, then we'll register ourselves as a | ||
// sub-RPC server within the global lnrpc package namespace. | ||
if err := lnrpc.RegisterSubServer(subServer); err != nil { | ||
panic(fmt.Sprintf("failed to register sub server driver '%s': %v", | ||
subServerName, err)) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package routerrpc | ||
|
||
import ( | ||
"github.com/btcsuite/btclog" | ||
"github.com/lightningnetwork/lnd/build" | ||
) | ||
|
||
// log is a logger that is initialized with no output filters. This | ||
// means the package will not perform any logging by default until the caller | ||
// requests it. | ||
var log btclog.Logger | ||
|
||
// The default amount of logging is none. | ||
func init() { | ||
UseLogger(build.NewSubLogger("RRPC", nil)) | ||
} | ||
|
||
// DisableLog disables all library log output. Logging output is disabled | ||
// by default until UseLogger is called. | ||
func DisableLog() { | ||
UseLogger(btclog.Disabled) | ||
} | ||
|
||
// UseLogger uses a specified Logger to output package logging info. | ||
// This should be used in preference to SetLogWriter if the caller is also | ||
// using btclog. | ||
func UseLogger(logger btclog.Logger) { | ||
log = logger | ||
} | ||
|
||
// logClosure is used to provide a closure over expensive logging operations so | ||
// don't have to be performed when the logging level doesn't warrant it. | ||
type logClosure func() string | ||
|
||
// String invokes the underlying function and returns the result. | ||
func (c logClosure) String() string { | ||
return c() | ||
} | ||
|
||
// newLogClosure returns a new closure over a function that returns a string | ||
// which itself provides a Stringer interface so that it can be used with the | ||
// logging system. | ||
func newLogClosure(c func() string) logClosure { | ||
return logClosure(c) | ||
} |
Oops, something went wrong.