Skip to content

Commit 6552bf4

Browse files
authored
Merge pull request #316 from guggero/user-agent-initiator
Add initiator field to user agent string
2 parents b50a99f + e91d632 commit 6552bf4

20 files changed

+542
-427
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ GOINSTALL := GO111MODULE=on go install -v
1010
GOMOD := GO111MODULE=on go mod
1111

1212
COMMIT := $(shell git describe --abbrev=40 --dirty)
13-
LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)"
13+
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
1414
DEV_TAGS = dev
1515

1616
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
@@ -72,3 +72,7 @@ install:
7272
@$(call print, "Installing loop and loopd.")
7373
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loop
7474
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loopd
75+
76+
rpc:
77+
@$(call print, "Compiling RPC protos.")
78+
cd looprpc; ./gen_protos.sh

client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
MaxPrepayAmount: 100,
3535
MaxPrepayRoutingFee: 75000,
3636
MaxSwapRoutingFee: 70000,
37+
Initiator: "test",
3738
}
3839

3940
swapInvoiceDesc = "swap"

cmd/loop/loopin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func loopIn(ctx *cli.Context) error {
150150
ExternalHtlc: external,
151151
HtlcConfTarget: htlcConfTarget,
152152
Label: label,
153+
Initiator: defaultInitiator,
153154
}
154155

155156
if ctx.IsSet(lastHopFlag.Name) {

cmd/loop/loopout.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func loopOut(ctx *cli.Context) error {
195195
HtlcConfirmations: htlcConfs,
196196
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
197197
Label: label,
198+
Initiator: defaultInitiator,
198199
})
199200
if err != nil {
200201
return err

cmd/loop/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ var (
4848
// that we set when sending it over the line.
4949
defaultMacaroonTimeout int64 = 60
5050

51+
// defaultInitiator is the default value for the "initiator" part of the
52+
// user agent string we send when using the command line utility.
53+
defaultInitiator = "loop-cli"
54+
5155
loopDirFlag = cli.StringFlag{
5256
Name: "loopdir",
5357
Value: loopd.LoopDirBase,

interface.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ type OutRequest struct {
8181

8282
// Label contains an optional label for the swap.
8383
Label string
84+
85+
// Initiator is an optional string that identifies what software
86+
// initiated the swap (loop CLI, autolooper, LiT UI and so on) and is
87+
// appended to the user agent string.
88+
Initiator string
8489
}
8590

8691
// Out contains the full details of a loop out request. This includes things
@@ -196,6 +201,11 @@ type LoopInRequest struct {
196201

197202
// Label contains an optional label for the swap.
198203
Label string
204+
205+
// Initiator is an optional string that identifies what software
206+
// initiated the swap (loop CLI, autolooper, LiT UI and so on) and is
207+
// appended to the user agent string.
208+
Initiator string
199209
}
200210

201211
// LoopInTerms are the server terms on which it executes loop in swaps.

liquidity/autoloop_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func TestAutoLoopEnabled(t *testing.T) {
146146
SweepConfTarget: params.SweepConfTarget,
147147
OutgoingChanSet: loopdb.ChannelSet{chanID1.ToUint64()},
148148
Label: labels.AutoOutLabel(),
149+
Initiator: autoloopSwapInitiator,
149150
}
150151

151152
chan2Swap = &loop.OutRequest{
@@ -161,6 +162,7 @@ func TestAutoLoopEnabled(t *testing.T) {
161162
SweepConfTarget: params.SweepConfTarget,
162163
OutgoingChanSet: loopdb.ChannelSet{chanID2.ToUint64()},
163164
Label: labels.AutoOutLabel(),
165+
Initiator: autoloopSwapInitiator,
164166
}
165167

166168
loopOuts = []loopOutRequestResp{

liquidity/liquidity.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const (
9999
// DefaultAutoOutTicker is the default amount of time between automated
100100
// loop out checks.
101101
DefaultAutoOutTicker = time.Minute * 10
102+
103+
// autoloopSwapInitiator is the value we send in the initiator field of
104+
// a swap request when issuing an automatic swap.
105+
autoloopSwapInitiator = "autoloop"
102106
)
103107

104108
var (
@@ -704,6 +708,7 @@ func (m *Manager) makeLoopOutRequest(ctx context.Context,
704708
MaxSwapFee: quote.SwapFee,
705709
MaxPrepayAmount: quote.PrepayAmount,
706710
SweepConfTarget: m.params.SweepConfTarget,
711+
Initiator: autoloopSwapInitiator,
707712
}
708713

709714
if autoOut {

liquidity/liquidity_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var (
6868
MaxSwapFee: testQuote.SwapFee,
6969
MaxPrepayAmount: testQuote.PrepayAmount,
7070
SweepConfTarget: loop.DefaultSweepConfTarget,
71+
Initiator: autoloopSwapInitiator,
7172
}
7273

7374
// chan2Rec is the suggested swap for channel 2 when we use chanRule.
@@ -80,6 +81,7 @@ var (
8081
MaxPrepayAmount: testQuote.PrepayAmount,
8182
MaxSwapFee: testQuote.SwapFee,
8283
SweepConfTarget: loop.DefaultSweepConfTarget,
84+
Initiator: autoloopSwapInitiator,
8385
}
8486

8587
// chan1Out is a contract that uses channel 1, used to represent on

loopd/swapclient_server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
9999
SwapPublicationDeadline: time.Unix(
100100
int64(in.SwapPublicationDeadline), 0,
101101
),
102-
Label: in.Label,
102+
Label: in.Label,
103+
Initiator: in.Initiator,
103104
}
104105

105106
switch {
@@ -496,6 +497,7 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
496497
HtlcConfTarget: htlcConfTarget,
497498
ExternalHtlc: in.ExternalHtlc,
498499
Label: in.Label,
500+
Initiator: in.Initiator,
499501
}
500502
if in.LastHop != nil {
501503
lastHop, err := route.NewVertexFromBytes(in.LastHop)

0 commit comments

Comments
 (0)