Skip to content

Commit

Permalink
Make VSP clients respect tor config.
Browse files Browse the repository at this point in the history
Ensure dialer is set correctly so VSPs are reached over tor if requested
in config.
  • Loading branch information
jholdstock committed Sep 18, 2024
1 parent e0384fa commit 2e34b2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func run(ctx context.Context) error {
// Start wallet, voting and network gRPC services after a
// wallet is loaded.
loader.RunAfterLoad(func(w *wallet.Wallet) {
rpcserver.StartWalletService(gRPCServer, w)
rpcserver.StartWalletService(gRPCServer, w, cfg.dial)
rpcserver.StartNetworkService(gRPCServer, w)
rpcserver.StartVotingService(gRPCServer, w)
})
Expand Down
22 changes: 12 additions & 10 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type versionServer struct {
type walletServer struct {
ready atomic.Uint32
wallet *wallet.Wallet
dialer wallet.DialFunc
pb.UnimplementedWalletServiceServer
}

Expand Down Expand Up @@ -211,6 +212,7 @@ type accountMixerServer struct {
type ticketbuyerServer struct {
ready atomic.Uint32
loader *loader.Loader
dialer wallet.DialFunc
pb.UnimplementedTicketBuyerServiceServer
}

Expand Down Expand Up @@ -321,13 +323,12 @@ func (*versionServer) Version(ctx context.Context, req *pb.VersionRequest) (*pb.
}, nil
}

type dialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

// StartWalletService starts the WalletService.
func StartWalletService(server *grpc.Server, wallet *wallet.Wallet) {
func StartWalletService(server *grpc.Server, wallet *wallet.Wallet, dialer wallet.DialFunc) {
if walletService.ready.Swap(1) != 0 {
panic("service already started")
}
walletService.dialer = dialer
walletService.wallet = wallet
}

Expand Down Expand Up @@ -1817,7 +1818,7 @@ func (s *walletServer) PurchaseTickets(ctx context.Context,
cfg := wallet.VSPClientConfig{
URL: vspHost,
PubKey: vspPubKey,
Dialer: nil,
Dialer: s.dialer,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
FeeAcct: req.Account,
Expand Down Expand Up @@ -2593,8 +2594,9 @@ func (t *accountMixerServer) checkReady() bool {
}

// StartTicketBuyerService starts the TicketBuyerService.
func StartTicketBuyerService(server *grpc.Server, loader *loader.Loader) {
func StartTicketBuyerService(server *grpc.Server, loader *loader.Loader, dialer wallet.DialFunc) {
ticketBuyerService.loader = loader
ticketBuyerService.dialer = dialer
if ticketBuyerService.ready.Swap(1) != 0 {
panic("service already started")
}
Expand Down Expand Up @@ -2626,7 +2628,7 @@ func (t *ticketbuyerServer) RunTicketBuyer(req *pb.RunTicketBuyerRequest, svr pb
cfg := wallet.VSPClientConfig{
URL: vspHost,
PubKey: vspPubKey,
Dialer: nil,
Dialer: t.dialer,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
FeeAcct: req.Account,
Expand Down Expand Up @@ -4112,7 +4114,7 @@ func (s *walletServer) SyncVSPFailedTickets(ctx context.Context, req *pb.SyncVSP
cfg := wallet.VSPClientConfig{
URL: vspHost,
PubKey: vspPubKey,
Dialer: nil,
Dialer: s.dialer,
Policy: policy,
}
vspClient, err := s.wallet.VSP(cfg)
Expand Down Expand Up @@ -4159,7 +4161,7 @@ func (s *walletServer) ProcessManagedTickets(ctx context.Context, req *pb.Proces
cfg := wallet.VSPClientConfig{
URL: vspHost,
PubKey: vspPubKey,
Dialer: nil,
Dialer: s.dialer,
Policy: policy,
}
vspClient, err := s.wallet.VSP(cfg)
Expand Down Expand Up @@ -4199,7 +4201,7 @@ func (s *walletServer) ProcessUnmanagedTickets(ctx context.Context, req *pb.Proc
cfg := wallet.VSPClientConfig{
URL: vspHost,
PubKey: vspPubKey,
Dialer: nil,
Dialer: s.dialer,
Policy: policy,
}
vspClient, err := s.wallet.VSP(cfg)
Expand Down Expand Up @@ -4236,7 +4238,7 @@ func (s *walletServer) SetVspdVoteChoices(ctx context.Context, req *pb.SetVspdVo
cfg := wallet.VSPClientConfig{
URL: vspHost,
PubKey: vspPubKey,
Dialer: nil,
Dialer: s.dialer,
Policy: policy,
}
vspClient, err := s.wallet.VSP(cfg)
Expand Down
2 changes: 1 addition & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func startRPCServers(walletLoader *loader.Loader) (*grpc.Server, *jsonrpc.Server
)
rpcserver.RegisterServices(server)
rpcserver.StartWalletLoaderService(server, walletLoader, activeNet)
rpcserver.StartTicketBuyerService(server, walletLoader)
rpcserver.StartTicketBuyerService(server, walletLoader, cfg.dial)
rpcserver.StartAccountMixerService(server, walletLoader)
rpcserver.StartAgendaService(server, activeNet.Params)
rpcserver.StartDecodeMessageService(server, activeNet.Params)
Expand Down

0 comments on commit 2e34b2a

Please sign in to comment.