mirror of
https://github.com/lightninglabs/loop
synced 2024-11-04 06:00:21 +00:00
loop: add initiator string to user agent
This commit is contained in:
parent
e6e533aeda
commit
2a732a4385
@ -34,6 +34,7 @@ var (
|
||||
MaxPrepayAmount: 100,
|
||||
MaxPrepayRoutingFee: 75000,
|
||||
MaxSwapRoutingFee: 70000,
|
||||
Initiator: "test",
|
||||
}
|
||||
|
||||
swapInvoiceDesc = "swap"
|
||||
|
10
interface.go
10
interface.go
@ -81,6 +81,11 @@ type OutRequest struct {
|
||||
|
||||
// Label contains an optional label for the swap.
|
||||
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
|
||||
@ -196,6 +201,11 @@ type LoopInRequest struct {
|
||||
|
||||
// Label contains an optional label for the swap.
|
||||
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.
|
||||
|
@ -166,7 +166,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
|
||||
log.Infof("Initiating swap request at height %v", currentHeight)
|
||||
swapResp, err := cfg.server.NewLoopInSwap(globalCtx, swapHash,
|
||||
request.Amount, senderKey, swapInvoice, probeInvoice,
|
||||
request.LastHop,
|
||||
request.LastHop, request.Initiator,
|
||||
)
|
||||
probeWaitCancel()
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,7 @@ var (
|
||||
Amount: btcutil.Amount(50000),
|
||||
MaxSwapFee: btcutil.Amount(1000),
|
||||
HtlcConfTarget: 2,
|
||||
Initiator: "test",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -114,7 +114,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
|
||||
// latest swap publication time.
|
||||
swapResp, err := cfg.server.NewLoopOutSwap(
|
||||
globalCtx, swapHash, request.Amount, request.Expiry,
|
||||
receiverKey, request.SwapPublicationDeadline,
|
||||
receiverKey, request.SwapPublicationDeadline, request.Initiator,
|
||||
)
|
||||
if err != nil {
|
||||
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,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount, expiry int32,
|
||||
receiverKey [33]byte, _ time.Time) (
|
||||
*newLoopOutResponse, error) {
|
||||
func (s *serverMock) NewLoopOutSwap(_ context.Context, swapHash lntypes.Hash,
|
||||
amount btcutil.Amount, _ int32, _ [33]byte, _ time.Time,
|
||||
_ string) (*newLoopOutResponse, error) {
|
||||
|
||||
_, senderKey := test.CreateKey(100)
|
||||
|
||||
@ -138,10 +137,9 @@ func getInvoice(hash lntypes.Hash, amt btcutil.Amount, memo string) (string, err
|
||||
return reqString, nil
|
||||
}
|
||||
|
||||
func (s *serverMock) NewLoopInSwap(ctx context.Context,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount,
|
||||
senderKey [33]byte, swapInvoice, probeInvoice string,
|
||||
lastHop *route.Vertex) (*newLoopInResponse, error) {
|
||||
func (s *serverMock) NewLoopInSwap(_ context.Context, swapHash lntypes.Hash,
|
||||
amount btcutil.Amount, _ [33]byte, swapInvoice, _ string,
|
||||
_ *route.Vertex, _ string) (*newLoopInResponse, error) {
|
||||
|
||||
_, receiverKey := test.CreateKey(101)
|
||||
|
||||
|
@ -55,9 +55,8 @@ type swapServerClient interface {
|
||||
|
||||
NewLoopOutSwap(ctx context.Context,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount, expiry int32,
|
||||
receiverKey [33]byte,
|
||||
swapPublicationDeadline time.Time) (
|
||||
*newLoopOutResponse, error)
|
||||
receiverKey [33]byte, swapPublicationDeadline time.Time,
|
||||
initiator string) (*newLoopOutResponse, error)
|
||||
|
||||
PushLoopOutPreimage(ctx context.Context,
|
||||
preimage lntypes.Preimage) error
|
||||
@ -65,7 +64,8 @@ type swapServerClient interface {
|
||||
NewLoopInSwap(ctx context.Context,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount,
|
||||
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(ctx context.Context,
|
||||
@ -220,8 +220,8 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
|
||||
|
||||
func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount, expiry int32,
|
||||
receiverKey [33]byte, swapPublicationDeadline time.Time) (
|
||||
*newLoopOutResponse, error) {
|
||||
receiverKey [33]byte, swapPublicationDeadline time.Time,
|
||||
initiator string) (*newLoopOutResponse, error) {
|
||||
|
||||
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
|
||||
defer rpcCancel()
|
||||
@ -233,7 +233,7 @@ func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
|
||||
SwapPublicationDeadline: swapPublicationDeadline.Unix(),
|
||||
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
|
||||
Expiry: expiry,
|
||||
UserAgent: UserAgent(),
|
||||
UserAgent: UserAgent(initiator),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@ -276,7 +276,8 @@ func (s *grpcSwapServerClient) PushLoopOutPreimage(ctx context.Context,
|
||||
|
||||
func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
|
||||
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)
|
||||
defer rpcCancel()
|
||||
@ -288,7 +289,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
|
||||
SwapInvoice: swapInvoice,
|
||||
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
|
||||
ProbeInvoice: probeInvoice,
|
||||
UserAgent: UserAgent(),
|
||||
UserAgent: UserAgent(initiator),
|
||||
}
|
||||
if lastHop != nil {
|
||||
req.LastHop = lastHop[:]
|
||||
|
15
version.go
15
version.go
@ -53,10 +53,21 @@ func Version() string {
|
||||
|
||||
// UserAgent returns the full user agent string that identifies the software
|
||||
// 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.
|
||||
return fmt.Sprintf(
|
||||
"%s/v%s/commit=%s", AgentName, semanticVersion(), Commit,
|
||||
"%s/v%s/commit=%s%s", AgentName, semanticVersion(), Commit,
|
||||
cleanInitiator,
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user