Skip to content

Commit

Permalink
[clientrpc] add RPCAllowRemoteSendTip and RPCMaxRemoteSendTipAmt conf…
Browse files Browse the repository at this point in the history
…ig params
  • Loading branch information
vctt94 committed Oct 22, 2024
1 parent d1424b8 commit 2144390
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 97 deletions.
17 changes: 14 additions & 3 deletions brclient/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3839,9 +3839,20 @@ func newAppState(sendMsg func(tea.Msg), lndLogLines *sloglinesbuffer.Buffer,
}

payRPCServerCfg := rpcserver.PaymentsServerCfg{
Log: logBknd.logger("RPCS"),
Client: c,
RootReplayMsgLogs: filepath.Join(args.DBRoot, "replaymsglog"),
Log: logBknd.logger("RPCS"),
Client: c,
RootReplayMsgLogs: filepath.Join(args.DBRoot, "replaymsglog"),
RPCAllowRemoteSendTip: args.RPCAllowRemoteSendTip,
RPCMaxRemoteSendTipAmt: args.RPCMaxRemoteSendTipAmt,
OnTipUser: func(uid clientintf.UserID, dcrAmount float64) error {
if !args.RPCAllowRemoteSendTip {
return fmt.Errorf("remote tip sending not allowed")
}
if dcrAmount > args.RPCMaxRemoteSendTipAmt {
return fmt.Errorf("tip exceeds max limit: %v", args.RPCMaxRemoteSendTipAmt)
}
return nil
},
}
err = rpcServer.InitPaymentsService(payRPCServerCfg)
if err != nil {
Expand Down
106 changes: 57 additions & 49 deletions brclient/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ type config struct {
RPCAuthMode string
RPCIssueClientCert bool

// rpc configurable params
RPCAllowRemoteSendTip bool
RPCMaxRemoteSendTipAmt float64

ExternalEditorForComments bool

ResourcesUpstream string
Expand Down Expand Up @@ -336,6 +340,8 @@ func loadConfig() (*config, error) {
flagRPCUser := fs.String("clientrpc.rpcuser", "", "")
flagRPCPass := fs.String("clientrpc.rpcpass", "", "")
flagRPCAuthMode := fs.String("clientrpc.rpcauthmode", "", "")
flagRPCAllowRemoteSendTip := fs.Bool("clientrpc.rpcallowremotesendtip", true, "allow remote send tip")
flagRPCMaxRemoteSendTipAmt := fs.Float64("clientrpc.rpcmaxremotesendtipamt", 0.1, "max remote send tip amount")

// resources
flagResourcesUpstream := fs.String("resources.upstream", "", "Upstream processor of resource requests")
Expand Down Expand Up @@ -494,55 +500,57 @@ func loadConfig() (*config, error) {

// Return the final cfg object.
return &config{
ServerAddr: *flagServerAddr,
Root: *flagRootDir,
DBRoot: filepath.Join(*flagRootDir, "db"),
DownloadsRoot: filepath.Join(*flagRootDir, "downloads"),
EmbedsRoot: filepath.Join(*flagRootDir, "embeds"),
WalletType: *flagWalletType,
MsgRoot: *flagMsgRoot,
LNRPCHost: *flagLNHost,
LNTLSCertPath: *flagLNTLSCert,
LNMacaroonPath: *flagLNMacaroonPath,
LNDebugLevel: *flagLNDebugLevel,
LNMaxLogFiles: *flagLNMaxLogFiles,
LNRPCListen: lnRPCListen,
LogFile: *flagLogFile,
MaxLogFiles: *flagMaxLogFiles,
DebugLevel: *flagDebugLevel,
CompressLevel: *flagCompressLevel,
CmdHistoryPath: cmdHistoryPath,
NickColor: *flagNickColor,
GCOtherColor: *flagGCOtherColor,
PMOtherColor: *flagPMOtherColor,
BlinkCursor: *flagBlinkCursor,
BellCmd: strings.TrimSpace(*flagBellCmd),
Network: *flagNetwork,
CPUProfile: *flagCPUProfile,
CPUProfileHz: *flagCPUProfileHz,
MemProfile: *flagMemProfile,
LogPings: *flagLogPings,
SendRecvReceipts: *flagSendRecvReceipts,
NoLoadChatHistory: *flagNoLoadChatHistory,
ProxyAddr: *flagProxyAddr,
ProxyUser: *flagProxyUser,
ProxyPass: *flagProxyPass,
TorIsolation: *flagTorIsolation,
MinWalletBal: minWalletBal,
MinRecvBal: minRecvBal,
MinSendBal: minSendBal,
WinPin: winpin,
MimeMap: mimeMap,
JSONRPCListen: jrpcListen,
RPCCertPath: *flagRPCCertPath,
RPCKeyPath: *flagRPCKeyPath,
RPCClientCAPath: *flagRPCClientCAPath,
RPCIssueClientCert: *flagRPCIssueClientCert,
RPCUser: *flagRPCUser,
RPCPass: *flagRPCPass,
RPCAuthMode: *flagRPCAuthMode,
InviteFundsAccount: *flagInviteFundsAccount,
ResourcesUpstream: *flagResourcesUpstream,
ServerAddr: *flagServerAddr,
Root: *flagRootDir,
DBRoot: filepath.Join(*flagRootDir, "db"),
DownloadsRoot: filepath.Join(*flagRootDir, "downloads"),
EmbedsRoot: filepath.Join(*flagRootDir, "embeds"),
WalletType: *flagWalletType,
MsgRoot: *flagMsgRoot,
LNRPCHost: *flagLNHost,
LNTLSCertPath: *flagLNTLSCert,
LNMacaroonPath: *flagLNMacaroonPath,
LNDebugLevel: *flagLNDebugLevel,
LNMaxLogFiles: *flagLNMaxLogFiles,
LNRPCListen: lnRPCListen,
LogFile: *flagLogFile,
MaxLogFiles: *flagMaxLogFiles,
DebugLevel: *flagDebugLevel,
CompressLevel: *flagCompressLevel,
CmdHistoryPath: cmdHistoryPath,
NickColor: *flagNickColor,
GCOtherColor: *flagGCOtherColor,
PMOtherColor: *flagPMOtherColor,
BlinkCursor: *flagBlinkCursor,
BellCmd: strings.TrimSpace(*flagBellCmd),
Network: *flagNetwork,
CPUProfile: *flagCPUProfile,
CPUProfileHz: *flagCPUProfileHz,
MemProfile: *flagMemProfile,
LogPings: *flagLogPings,
SendRecvReceipts: *flagSendRecvReceipts,
NoLoadChatHistory: *flagNoLoadChatHistory,
ProxyAddr: *flagProxyAddr,
ProxyUser: *flagProxyUser,
ProxyPass: *flagProxyPass,
TorIsolation: *flagTorIsolation,
MinWalletBal: minWalletBal,
MinRecvBal: minRecvBal,
MinSendBal: minSendBal,
WinPin: winpin,
MimeMap: mimeMap,
JSONRPCListen: jrpcListen,
RPCCertPath: *flagRPCCertPath,
RPCKeyPath: *flagRPCKeyPath,
RPCClientCAPath: *flagRPCClientCAPath,
RPCIssueClientCert: *flagRPCIssueClientCert,
RPCUser: *flagRPCUser,
RPCPass: *flagRPCPass,
RPCAuthMode: *flagRPCAuthMode,
InviteFundsAccount: *flagInviteFundsAccount,
ResourcesUpstream: *flagResourcesUpstream,
RPCAllowRemoteSendTip: *flagRPCAllowRemoteSendTip,
RPCMaxRemoteSendTipAmt: *flagRPCMaxRemoteSendTipAmt,

AutoHandshakeInterval: autoHandshakeInterval,
AutoRemoveIdleUsersInterval: autoRemoveInterval,
Expand Down
12 changes: 10 additions & 2 deletions bruig/flutterui/bruig/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class Config {
late final String rpcUser;
late final String rpcPass;
late final String rpcAuthMode;
late final bool rpcAllowRemoteSendTip;
late final double rpcMaxRemoteSendTipAmt;

Config();
Config.filled(
Expand Down Expand Up @@ -151,7 +153,9 @@ class Config {
this.rpcClientCApath = "",
this.rpcUser = "",
this.rpcPass = "",
this.rpcAuthMode = ""});
this.rpcAuthMode = "",
this.rpcAllowRemoteSendTip = false,
this.rpcMaxRemoteSendTipAmt = 0});
factory Config.newWithRPCHost(
Config cfg, String rpcHost, String tlsCert, String macaroonPath) =>
Config.filled(
Expand Down Expand Up @@ -196,7 +200,9 @@ class Config {
rpcClientCApath: cfg.rpcClientCApath,
rpcUser: cfg.rpcUser,
rpcPass: cfg.rpcPass,
rpcAuthMode: cfg.rpcAuthMode
rpcAuthMode: cfg.rpcAuthMode,
rpcAllowRemoteSendTip: cfg.rpcAllowRemoteSendTip,
rpcMaxRemoteSendTipAmt: cfg.rpcMaxRemoteSendTipAmt,
);

// Save a new config from scratch.
Expand Down Expand Up @@ -426,6 +432,8 @@ Future<Config> loadConfig(String filepath) async {
c.rpcUser = f.get("clientrpc", "rpcuser") ?? "";
c.rpcPass = f.get("clientrpc", "rpcpass") ?? "";
c.rpcAuthMode = f.get("clientrpc", "rpcauthmode") ?? "";
c.rpcAllowRemoteSendTip = getBool("clientrpc", "rpcallowremotesendtip");
c.rpcMaxRemoteSendTipAmt = double.tryParse(f.get("clientrpc", "rpcmaxremotesendtipamt") ?? "0") ?? 0;

return c;
}
Expand Down
4 changes: 3 additions & 1 deletion bruig/flutterui/bruig/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ class _AppState extends State<App> with WindowListener {
cfg.rpcClientCApath,
cfg.rpcUser,
cfg.rpcPass,
cfg.rpcAuthMode);
cfg.rpcAuthMode,
cfg.rpcAllowRemoteSendTip,
cfg.rpcMaxRemoteSendTipAmt);
await Golib.initClient(initArgs);
} catch (exception) {
if ("$exception".contains("client already initialized")) {
Expand Down
82 changes: 43 additions & 39 deletions bruig/flutterui/plugin/lib/definitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,54 +81,58 @@ class InitClient {
final String rpcKeyPath;
@JsonKey(name: 'rpc_issue_client_cert')
final bool rpcIssueClientCert;
@JsonKey(name: 'rpc_client_ca_path')
@JsonKey(name: 'rpc_client_ca_path')
final String rpcClientCAPath;
@JsonKey(name: 'rpc_user')
final String rpcUser;
@JsonKey(name: 'rpc_pass')
final String rpcPass;
@JsonKey(name: 'rpc_auth_mode')
final String rpcAuthMode;

@JsonKey(name: 'rpc_allow_remote_send_tip')
final bool rpcAllowRemoteSendTip;
@JsonKey(name: 'rpc_max_remote_send_tip_amt')
final double rpcMaxRemoteSendTipAmt;

InitClient(
this.dbRoot,
this.downloadsDir,
this.embedsDir,
this.serverAddr,
this.lnRPCHost,
this.lnTLSCertPath,
this.lnMacaroonPath,
this.logFile,
this.msgsRoot,
this.debugLevel,
this.wantsLogNtfns,
this.resourcesUpstream,
this.simpleStorePayType,
this.simpleStoreAccount,
this.simpleStoreShipCharge,
this.proxyaddr,
this.torisolation,
this.proxyUsername,
this.proxyPassword,
this.circuitLimit,
this.noLoadChatHistory,
this.autoHandshakeInterval,
this.autoRemoveIdleUsersInterval,
this.autoRemoveIdleUsersIgnore,
this.sendRecvReceipts,
this.autoSubPosts,
this.logPings,
this.pingIntervalMs,
this.jsonRPCListen,
this.rpcCertPath,
this.rpcKeyPath,
this.rpcIssueClientCert,
this.rpcClientCAPath,
this.rpcUser,
this.rpcPass,
this.rpcAuthMode
);
this.dbRoot,
this.downloadsDir,
this.embedsDir,
this.serverAddr,
this.lnRPCHost,
this.lnTLSCertPath,
this.lnMacaroonPath,
this.logFile,
this.msgsRoot,
this.debugLevel,
this.wantsLogNtfns,
this.resourcesUpstream,
this.simpleStorePayType,
this.simpleStoreAccount,
this.simpleStoreShipCharge,
this.proxyaddr,
this.torisolation,
this.proxyUsername,
this.proxyPassword,
this.circuitLimit,
this.noLoadChatHistory,
this.autoHandshakeInterval,
this.autoRemoveIdleUsersInterval,
this.autoRemoveIdleUsersIgnore,
this.sendRecvReceipts,
this.autoSubPosts,
this.logPings,
this.pingIntervalMs,
this.jsonRPCListen,
this.rpcCertPath,
this.rpcKeyPath,
this.rpcIssueClientCert,
this.rpcClientCAPath,
this.rpcUser,
this.rpcPass,
this.rpcAuthMode,
this.rpcAllowRemoteSendTip,
this.rpcMaxRemoteSendTipAmt);

Map<String, dynamic> toJson() => _$InitClientToJson(this);
}
Expand Down
4 changes: 4 additions & 0 deletions bruig/flutterui/plugin/lib/definitions.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions bruig/golib/command_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,20 @@ func handleInitClient(handle uint32, args initClient) error {
}

payRPCServerCfg := rpcserver.PaymentsServerCfg{
Log: logBknd.logger("RPCS"),
Client: c,
RootReplayMsgLogs: filepath.Join(args.DBRoot, "replaymsglog"),
Log: logBknd.logger("RPCS"),
Client: c,
RootReplayMsgLogs: filepath.Join(args.DBRoot, "replaymsglog"),
RPCAllowRemoteSendTip: args.RPCAllowRemoteSendTip,
RPCMaxRemoteSendTipAmt: args.RPCMaxRemoteSendTipAmt,
OnTipUser: func(uid clientintf.UserID, dcrAmount float64) error {
if !args.RPCAllowRemoteSendTip {
return fmt.Errorf("remote tip sending not allowed")
}
if dcrAmount > args.RPCMaxRemoteSendTipAmt {
return fmt.Errorf("tip exceeds max limit: %v", args.RPCMaxRemoteSendTipAmt)
}
return nil
},
}
err = rpcServer.InitPaymentsService(payRPCServerCfg)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions bruig/golib/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type initClient struct {
RPCPass string `json:"rpc_pass"`
RPCAuthMode string `json:"rpc_auth_mode"`
InviteFundsAccount string `json:"invite_funds_account"`

RPCAllowRemoteSendTip bool `json:"rpc_allow_remote_send_tip"`
RPCMaxRemoteSendTipAmt float64 `json:"rpc_max_remote_send_tip_amt"`
}

type iDInit struct {
Expand Down
4 changes: 4 additions & 0 deletions client/rpcserver/payments_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type PaymentsServerCfg struct {
// Client should be set to the [client.Client] instance.
Client *client.Client

// RPC Server Configurable Params
RPCAllowRemoteSendTip bool
RPCMaxRemoteSendTipAmt float64

// Log should be set to the app's logger.
Log slog.Logger

Expand Down

0 comments on commit 2144390

Please sign in to comment.