loop: add initiator string to user agent

pull/316/head
Oliver Gugger 3 years ago
parent e6e533aeda
commit 2a732a4385
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -34,6 +34,7 @@ var (
MaxPrepayAmount: 100, MaxPrepayAmount: 100,
MaxPrepayRoutingFee: 75000, MaxPrepayRoutingFee: 75000,
MaxSwapRoutingFee: 70000, MaxSwapRoutingFee: 70000,
Initiator: "test",
} }
swapInvoiceDesc = "swap" swapInvoiceDesc = "swap"

@ -81,6 +81,11 @@ type OutRequest struct {
// Label contains an optional label for the swap. // Label contains an optional label for the swap.
Label string Label string
// Initiator is an optional string that identifies what software
// initiated the swap (loop CLI, autolooper, LiT UI and so on) and is
// appended to the user agent string.
Initiator string
} }
// Out contains the full details of a loop out request. This includes things // Out contains the full details of a loop out request. This includes things
@ -196,6 +201,11 @@ type LoopInRequest struct {
// Label contains an optional label for the swap. // Label contains an optional label for the swap.
Label string Label string
// Initiator is an optional string that identifies what software
// initiated the swap (loop CLI, autolooper, LiT UI and so on) and is
// appended to the user agent string.
Initiator string
} }
// LoopInTerms are the server terms on which it executes loop in swaps. // LoopInTerms are the server terms on which it executes loop in swaps.

@ -166,7 +166,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
log.Infof("Initiating swap request at height %v", currentHeight) log.Infof("Initiating swap request at height %v", currentHeight)
swapResp, err := cfg.server.NewLoopInSwap(globalCtx, swapHash, swapResp, err := cfg.server.NewLoopInSwap(globalCtx, swapHash,
request.Amount, senderKey, swapInvoice, probeInvoice, request.Amount, senderKey, swapInvoice, probeInvoice,
request.LastHop, request.LastHop, request.Initiator,
) )
probeWaitCancel() probeWaitCancel()
if err != nil { if err != nil {

@ -21,6 +21,7 @@ var (
Amount: btcutil.Amount(50000), Amount: btcutil.Amount(50000),
MaxSwapFee: btcutil.Amount(1000), MaxSwapFee: btcutil.Amount(1000),
HtlcConfTarget: 2, HtlcConfTarget: 2,
Initiator: "test",
} }
) )

@ -114,7 +114,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
// latest swap publication time. // latest swap publication time.
swapResp, err := cfg.server.NewLoopOutSwap( swapResp, err := cfg.server.NewLoopOutSwap(
globalCtx, swapHash, request.Amount, request.Expiry, globalCtx, swapHash, request.Amount, request.Expiry,
receiverKey, request.SwapPublicationDeadline, receiverKey, request.SwapPublicationDeadline, request.Initiator,
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot initiate swap: %v", err) return nil, fmt.Errorf("cannot initiate swap: %v", err)

@ -64,10 +64,9 @@ func newServerMock(lnd *test.LndMockServices) *serverMock {
} }
} }
func (s *serverMock) NewLoopOutSwap(ctx context.Context, func (s *serverMock) NewLoopOutSwap(_ context.Context, swapHash lntypes.Hash,
swapHash lntypes.Hash, amount btcutil.Amount, expiry int32, amount btcutil.Amount, _ int32, _ [33]byte, _ time.Time,
receiverKey [33]byte, _ time.Time) ( _ string) (*newLoopOutResponse, error) {
*newLoopOutResponse, error) {
_, senderKey := test.CreateKey(100) _, senderKey := test.CreateKey(100)
@ -138,10 +137,9 @@ func getInvoice(hash lntypes.Hash, amt btcutil.Amount, memo string) (string, err
return reqString, nil return reqString, nil
} }
func (s *serverMock) NewLoopInSwap(ctx context.Context, func (s *serverMock) NewLoopInSwap(_ context.Context, swapHash lntypes.Hash,
swapHash lntypes.Hash, amount btcutil.Amount, amount btcutil.Amount, _ [33]byte, swapInvoice, _ string,
senderKey [33]byte, swapInvoice, probeInvoice string, _ *route.Vertex, _ string) (*newLoopInResponse, error) {
lastHop *route.Vertex) (*newLoopInResponse, error) {
_, receiverKey := test.CreateKey(101) _, receiverKey := test.CreateKey(101)

@ -55,9 +55,8 @@ type swapServerClient interface {
NewLoopOutSwap(ctx context.Context, NewLoopOutSwap(ctx context.Context,
swapHash lntypes.Hash, amount btcutil.Amount, expiry int32, swapHash lntypes.Hash, amount btcutil.Amount, expiry int32,
receiverKey [33]byte, receiverKey [33]byte, swapPublicationDeadline time.Time,
swapPublicationDeadline time.Time) ( initiator string) (*newLoopOutResponse, error)
*newLoopOutResponse, error)
PushLoopOutPreimage(ctx context.Context, PushLoopOutPreimage(ctx context.Context,
preimage lntypes.Preimage) error preimage lntypes.Preimage) error
@ -65,7 +64,8 @@ type swapServerClient interface {
NewLoopInSwap(ctx context.Context, NewLoopInSwap(ctx context.Context,
swapHash lntypes.Hash, amount btcutil.Amount, swapHash lntypes.Hash, amount btcutil.Amount,
senderKey [33]byte, swapInvoice, probeInvoice string, senderKey [33]byte, swapInvoice, probeInvoice string,
lastHop *route.Vertex) (*newLoopInResponse, error) lastHop *route.Vertex, initiator string) (*newLoopInResponse,
error)
// SubscribeLoopOutUpdates subscribes to loop out server state. // SubscribeLoopOutUpdates subscribes to loop out server state.
SubscribeLoopOutUpdates(ctx context.Context, SubscribeLoopOutUpdates(ctx context.Context,
@ -220,8 +220,8 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context, func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
swapHash lntypes.Hash, amount btcutil.Amount, expiry int32, swapHash lntypes.Hash, amount btcutil.Amount, expiry int32,
receiverKey [33]byte, swapPublicationDeadline time.Time) ( receiverKey [33]byte, swapPublicationDeadline time.Time,
*newLoopOutResponse, error) { initiator string) (*newLoopOutResponse, error) {
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
@ -233,7 +233,7 @@ func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
SwapPublicationDeadline: swapPublicationDeadline.Unix(), SwapPublicationDeadline: swapPublicationDeadline.Unix(),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
Expiry: expiry, Expiry: expiry,
UserAgent: UserAgent(), UserAgent: UserAgent(initiator),
}, },
) )
if err != nil { if err != nil {
@ -276,7 +276,8 @@ func (s *grpcSwapServerClient) PushLoopOutPreimage(ctx context.Context,
func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context, func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
swapHash lntypes.Hash, amount btcutil.Amount, senderKey [33]byte, swapHash lntypes.Hash, amount btcutil.Amount, senderKey [33]byte,
swapInvoice, probeInvoice string, lastHop *route.Vertex) (*newLoopInResponse, error) { swapInvoice, probeInvoice string, lastHop *route.Vertex,
initiator string) (*newLoopInResponse, error) {
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel() defer rpcCancel()
@ -288,7 +289,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
SwapInvoice: swapInvoice, SwapInvoice: swapInvoice,
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
ProbeInvoice: probeInvoice, ProbeInvoice: probeInvoice,
UserAgent: UserAgent(), UserAgent: UserAgent(initiator),
} }
if lastHop != nil { if lastHop != nil {
req.LastHop = lastHop[:] req.LastHop = lastHop[:]

@ -53,10 +53,21 @@ func Version() string {
// UserAgent returns the full user agent string that identifies the software // UserAgent returns the full user agent string that identifies the software
// that is submitting swaps to the loop server. // that is submitting swaps to the loop server.
func UserAgent() string { func UserAgent(initiator string) string {
// We'll only allow "safe" characters in the initiator portion of the
// user agent string and spaces only if surrounded by other characters.
initiatorAlphabet := semanticAlphabet + ". "
cleanInitiator := normalizeVerString(
strings.TrimSpace(initiator), initiatorAlphabet,
)
if len(cleanInitiator) > 0 {
cleanInitiator = fmt.Sprintf(",initiator=%s", cleanInitiator)
}
// Assemble full string, including the commit hash of current build. // Assemble full string, including the commit hash of current build.
return fmt.Sprintf( return fmt.Sprintf(
"%s/v%s/commit=%s", AgentName, semanticVersion(), Commit, "%s/v%s/commit=%s%s", AgentName, semanticVersion(), Commit,
cleanInitiator,
) )
} }

Loading…
Cancel
Save