Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user agent and initiator string to account open and order submission calls #211

Merged
merged 10 commits into from
Jan 29, 2021
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')

COMMIT := $(shell git describe --abbrev=40 --dirty)
LDFLAGS := -X $(PKG).Commit=$(COMMIT)

RM := rm -f
CP := cp
MAKE := make
Expand All @@ -32,7 +35,7 @@ include make/release_flags.mk

# For the release, we want to remove the symbol table and debug information (-s)
# and omit the DWARF symbol table (-w). Also we clear the build ID.
RELEASE_LDFLAGS := $(call make_ldflags, $(RELEASE_TAGS), -s -w -buildid=)
RELEASE_LDFLAGS := -s -w -buildid= $(LDFLAGS)

# Linting uses a lot of memory, so keep it under control by limiting the number
# of workers if requested.
Expand Down Expand Up @@ -74,18 +77,18 @@ $(GOACC_BIN):

build:
@$(call print, "Building Pool.")
$(GOBUILD) $(PKG)/cmd/pool
$(GOBUILD) $(PKG)/cmd/poold
$(GOBUILD) -ldflags="$(LDFLAGS)" $(PKG)/cmd/pool
$(GOBUILD) -ldflags="$(LDFLAGS)" $(PKG)/cmd/poold

install:
@$(call print, "Installing Pool.")
$(GOINSTALL) $(PKG)/cmd/pool
$(GOINSTALL) $(PKG)/cmd/poold
$(GOINSTALL) -ldflags="$(LDFLAGS)" $(PKG)/cmd/pool
$(GOINSTALL) -ldflags="$(LDFLAGS)" $(PKG)/cmd/poold

release:
@$(call print, "Releasing pool and poold binaries.")
$(VERSION_CHECK)
./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "" "$(RELEASE_LDFLAGS)"

scratch: build

Expand Down
9 changes: 8 additions & 1 deletion auctioneer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ type Config struct {
// BatchCleaner provides functionality to clean up the state of a
// trader's pending batch.
BatchCleaner BatchCleaner

// GenUserAgent is a function that generates a complete user agent
// string given the incoming request context.
GenUserAgent func(context.Context) string
}

// Client performs the client side part of auctions. This interface exists to be
Expand Down Expand Up @@ -287,6 +291,7 @@ func (c *Client) InitAccount(ctx context.Context, account *account.Account) erro
AccountValue: uint64(account.Value),
AccountExpiry: account.Expiry,
TraderKey: account.TraderKey.PubKey.SerializeCompressed(),
UserAgent: c.cfg.GenUserAgent(ctx),
},
)
return err
Expand Down Expand Up @@ -355,7 +360,9 @@ func (c *Client) SubmitOrder(ctx context.Context, o order.Order,

// Prepare everything that is common to both ask and bid orders.
nonce := o.Nonce()
rpcRequest := &auctioneerrpc.ServerSubmitOrderRequest{}
rpcRequest := &auctioneerrpc.ServerSubmitOrderRequest{
UserAgent: c.cfg.GenUserAgent(ctx),
}
nodeAddrs := make([]*auctioneerrpc.NodeAddress, 0, len(serverParams.Addrs))
for _, addr := range serverParams.Addrs {
nodeAddrs = append(nodeAddrs, &auctioneerrpc.NodeAddress{
Expand Down
556 changes: 294 additions & 262 deletions auctioneerrpc/auctioneer.pb.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions auctioneerrpc/auctioneer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ message ServerInitAccountRequest {
The trader's account key.
*/
bytes trader_key = 5;

// The user agent string that identifies the software running on the user's
// side. This can be changed in the user's client software but it _SHOULD_
// conform to the following pattern and use less than 256 characters:
// Agent-Name/semver-version(/additional-info)
// Examples:
// poold/v0.4.2-beta/commit=3b635821,initiator=pool-cli
// litd/v0.4.0-alpha/commit=326d754,initiator=lit-ui
string user_agent = 6;
}
message ServerInitAccountResponse {
}
Expand All @@ -116,6 +125,15 @@ message ServerSubmitOrderRequest {
*/
ServerBid bid = 2;
}

// The user agent string that identifies the software running on the user's
// side. This can be changed in the user's client software but it _SHOULD_
// conform to the following pattern and use less than 256 characters:
// Agent-Name/semver-version(/additional-info)
// Examples:
// poold/v0.4.2-beta/commit=3b635821,initiator=pool-cli
// litd/v0.4.0-alpha/commit=326d754,initiator=lit-ui
string user_agent = 3;
guggero marked this conversation as resolved.
Show resolved Hide resolved
}
message ServerSubmitOrderResponse {
oneof details {
Expand Down
1 change: 1 addition & 0 deletions cmd/pool/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func newAccount(ctx *cli.Context) error {
Fees: &poolrpc.InitAccountRequest_ConfTarget{
ConfTarget: uint32(ctx.Uint64("conf_target")),
},
Initiator: defaultInitiator,
}

// Parse the expiry in either of its forms. We'll always prefer the
Expand Down
8 changes: 8 additions & 0 deletions cmd/pool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ var (
}
)

const (
// defaultInitiator is the name of the pool CLI binary that is sent as
// the initiator field in some of the calls. The initiator identifies
// the software that initiated a certain RPC call and is appended to the
// static user agent string of the daemon binary.
defaultInitiator = "pool-cli"
)

type invalidUsageError struct {
ctx *cli.Context
command string
Expand Down
2 changes: 2 additions & 0 deletions cmd/pool/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func ordersSubmitAsk(ctx *cli.Context) error { // nolint: dupl
Details: &poolrpc.SubmitOrderRequest_Ask{
Ask: ask,
},
Initiator: defaultInitiator,
},
)
if err != nil {
Expand Down Expand Up @@ -475,6 +476,7 @@ func ordersSubmitBid(ctx *cli.Context) error { // nolint: dupl
Details: &poolrpc.SubmitOrderRequest_Bid{
Bid: bid,
},
Initiator: defaultInitiator,
},
)
if err != nil {
Expand Down
Loading