Compare commits
19 Commits
v2.2.0
...
a31a0b4829
| Author | SHA1 | Date | |
|---|---|---|---|
| a31a0b4829 | |||
|
|
959d1e3c1f | ||
|
|
bda5aa9238 | ||
|
|
4e5da3f322 | ||
|
|
826576516f | ||
|
|
933c7cc307 | ||
|
|
9471f0b5ac | ||
|
|
4d774937df | ||
|
|
3702654ec3 | ||
|
|
7d63422555 | ||
|
|
fa6fc5fb34 | ||
|
|
86d865ce1b | ||
|
|
516dd6b611 | ||
|
|
df421fcccb | ||
|
|
a050189e12 | ||
|
|
7bcdc3276f | ||
|
|
9f9e25a796 | ||
|
|
c4a095a094 | ||
|
|
bf4716e8df |
26
.github/workflows/docker-build.yml
vendored
26
.github/workflows/docker-build.yml
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
# Tagging based on: https://docs.docker.com/build/ci/github-actions/manage-tags-labels/
|
||||||
|
# Multi platform based on: https://docs.docker.com/build/ci/github-actions/multi-platform/
|
||||||
name: build
|
name: build
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -12,15 +14,15 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: "Setup"
|
- name: "Setup"
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.16'
|
go-version: '1.22'
|
||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
|
||||||
@@ -28,11 +30,11 @@ jobs:
|
|||||||
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
|
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||||
|
|
||||||
- name: Upload code coverage
|
- name: Upload code coverage
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v3
|
||||||
|
|
||||||
- name: Generate docker image labels and tags
|
- name: Generate docker image labels and tags
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
uses: crazy-max/ghaction-docker-meta@v2
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/diebietse/invertergui
|
images: ghcr.io/diebietse/invertergui
|
||||||
tags: |
|
tags: |
|
||||||
@@ -41,21 +43,21 @@ jobs:
|
|||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.CR_PAT }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push to GitHub Container Registry
|
- name: Build and push to GitHub Container Registry
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
|
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,3 +22,5 @@ _testmain.go
|
|||||||
*.exe
|
*.exe
|
||||||
*.test
|
*.test
|
||||||
*.prof
|
*.prof
|
||||||
|
|
||||||
|
vendor/
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
run:
|
|
||||||
deadline: 10m
|
|
||||||
|
|
||||||
linters:
|
|
||||||
enable-all: false
|
|
||||||
enable:
|
|
||||||
# Enabled by default in golangci-lint v1.13.2
|
|
||||||
- deadcode
|
|
||||||
- errcheck
|
|
||||||
- govet
|
|
||||||
- ineffassign
|
|
||||||
- typecheck
|
|
||||||
- varcheck
|
|
||||||
# Disabled by default in golangci-lint v1.13.2
|
|
||||||
- dupl
|
|
||||||
- goconst
|
|
||||||
- gofmt
|
|
||||||
- golint
|
|
||||||
- unconvert
|
|
||||||
# The following result in high memory usage (>1GB)
|
|
||||||
# https://github.com/golangci/golangci-lint/issues/337
|
|
||||||
- staticcheck
|
|
||||||
- structcheck
|
|
||||||
- gosimple
|
|
||||||
- unused
|
|
||||||
|
|
||||||
issues:
|
|
||||||
max-per-linter: 0
|
|
||||||
max-same-issues: 0
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.16-alpine as builder
|
FROM golang:1.22-alpine as builder
|
||||||
|
|
||||||
RUN mkdir /build
|
RUN mkdir /build
|
||||||
COPY . /build/
|
COPY . /build/
|
||||||
|
|||||||
6
Makefile
6
Makefile
@@ -47,7 +47,7 @@ docker:
|
|||||||
lint:
|
lint:
|
||||||
docker run --rm -it \
|
docker run --rm -it \
|
||||||
-w /src -v $(shell pwd):/src \
|
-w /src -v $(shell pwd):/src \
|
||||||
golangci/golangci-lint:v1.39 golangci-lint run \
|
golangci/golangci-lint:v1.56 golangci-lint run \
|
||||||
-v -c .golangci.yml
|
-v -c .golangci.yml
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@@ -56,3 +56,7 @@ clean:
|
|||||||
vendor:
|
vendor:
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod vendor
|
go mod vendor
|
||||||
|
|
||||||
|
.PHONY: upgrade-vendor
|
||||||
|
upgrade-vendor:
|
||||||
|
go get -u ./...
|
||||||
|
|||||||
108
README.md
108
README.md
@@ -21,7 +21,7 @@ docker run --name invertergui --device /dev/ttyUSB0:/dev/ttyUSB0 -p 8080:8080 gh
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
This project makes use of [Go Modules](https://github.com/golang/go/wiki/Modules). The minimum version for Go is 1.16
|
This project makes use of [Go Modules](https://github.com/golang/go/wiki/Modules). The minimum supported version for Go is 1.22
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
@@ -37,10 +37,17 @@ Application Options:
|
|||||||
--cli.enabled Enable CLI output. [$CLI_ENABLED]
|
--cli.enabled Enable CLI output. [$CLI_ENABLED]
|
||||||
--mqtt.enabled Enable MQTT publishing. [$MQTT_ENABLED]
|
--mqtt.enabled Enable MQTT publishing. [$MQTT_ENABLED]
|
||||||
--mqtt.broker= Set the host port and scheme of the MQTT broker. (default: tcp://localhost:1883) [$MQTT_BROKER]
|
--mqtt.broker= Set the host port and scheme of the MQTT broker. (default: tcp://localhost:1883) [$MQTT_BROKER]
|
||||||
--mqtt.client_id= Set the client ID for the MQTT connection. (default: interter-gui) [$MQTT_CLIENT_ID]
|
--mqtt.client_id= Set the client ID for the MQTT connection. (default: inverter-gui) [$MQTT_CLIENT_ID]
|
||||||
--mqtt.topic= Set the MQTT topic updates published to. (default: invertergui/updates) [$MQTT_TOPIC]
|
--mqtt.topic= Set the MQTT topic updates published to. (default: invertergui/updates) [$MQTT_TOPIC]
|
||||||
|
--mqtt.command_topic= Set the MQTT topic that receives write commands for Victron settings/RAM variables. (default: invertergui/settings/set) [$MQTT_COMMAND_TOPIC]
|
||||||
|
--mqtt.status_topic= Set the MQTT topic where write command status updates are published. (default: invertergui/settings/status) [$MQTT_STATUS_TOPIC]
|
||||||
|
--mqtt.ha.enabled Enable Home Assistant MQTT discovery integration. [$MQTT_HA_ENABLED]
|
||||||
|
--mqtt.ha.discovery_prefix= Set Home Assistant MQTT discovery prefix. (default: homeassistant) [$MQTT_HA_DISCOVERY_PREFIX]
|
||||||
|
--mqtt.ha.node_id= Set Home Assistant node ID used for discovery topics and unique IDs. (default: invertergui) [$MQTT_HA_NODE_ID]
|
||||||
|
--mqtt.ha.device_name= Set Home Assistant device display name. (default: Victron Inverter) [$MQTT_HA_DEVICE_NAME]
|
||||||
--mqtt.username= Set the MQTT username [$MQTT_USERNAME]
|
--mqtt.username= Set the MQTT username [$MQTT_USERNAME]
|
||||||
--mqtt.password= Set the MQTT password [$MQTT_PASSWORD]
|
--mqtt.password= Set the MQTT password [$MQTT_PASSWORD]
|
||||||
|
--mqtt.password-file= Path to a file containing the MQTT password [$MQTT_PASSWORD_FILE]
|
||||||
--loglevel= The log level to generate logs at. ("panic", "fatal", "error", "warn", "info", "debug", "trace") (default: info) [$LOGLEVEL]
|
--loglevel= The log level to generate logs at. ("panic", "fatal", "error", "warn", "info", "debug", "trace") (default: info) [$LOGLEVEL]
|
||||||
|
|
||||||
Help Options:
|
Help Options:
|
||||||
@@ -82,6 +89,20 @@ Battery Power: -0.659 W
|
|||||||
Battery Charge: 100.000 %
|
Battery Charge: 100.000 %
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The web UI also includes a **Remote Panel Control** section for:
|
||||||
|
|
||||||
|
- Remote Panel Mode (`on`, `off`, `charger_only`, `inverter_only`)
|
||||||
|
- Remote Panel Current Limit (AC input current limit in amps)
|
||||||
|
- Remote Panel Standby (prevent sleep while turned off)
|
||||||
|
|
||||||
|
The combined mode + current limit action maps to the same behavior as
|
||||||
|
`set_remote_panel_state` in `victron-mk3`.
|
||||||
|
|
||||||
|
The backing HTTP API endpoints are:
|
||||||
|
|
||||||
|
- `GET/POST /api/remote-panel/state`
|
||||||
|
- `GET/POST /api/remote-panel/standby`
|
||||||
|
|
||||||
### Munin
|
### Munin
|
||||||
|
|
||||||
The Munin plugin location is at /munin (http://localhost:8080/munin).
|
The Munin plugin location is at /munin (http://localhost:8080/munin).
|
||||||
@@ -281,16 +302,97 @@ The MQTT client will publish updates to the given broker at the set topic.
|
|||||||
```bash
|
```bash
|
||||||
--mqtt.enabled Enable MQTT publishing. [$MQTT_ENABLED]
|
--mqtt.enabled Enable MQTT publishing. [$MQTT_ENABLED]
|
||||||
--mqtt.broker= Set the host port and scheme of the MQTT broker. (default: tcp://localhost:1883) [$MQTT_BROKER]
|
--mqtt.broker= Set the host port and scheme of the MQTT broker. (default: tcp://localhost:1883) [$MQTT_BROKER]
|
||||||
--mqtt.client_id= Set the client ID for the MQTT connection. (default: interter-gui) [$MQTT_CLIENT_ID]
|
--mqtt.client_id= Set the client ID for the MQTT connection. (default: inverter-gui) [$MQTT_CLIENT_ID]
|
||||||
--mqtt.topic= Set the MQTT topic updates published to. (default: invertergui/updates) [$MQTT_TOPIC]
|
--mqtt.topic= Set the MQTT topic updates published to. (default: invertergui/updates) [$MQTT_TOPIC]
|
||||||
|
--mqtt.command_topic= Set the MQTT topic that receives write commands for Victron settings/RAM variables. (default: invertergui/settings/set) [$MQTT_COMMAND_TOPIC]
|
||||||
|
--mqtt.status_topic= Set the MQTT topic where write command status updates are published. (default: invertergui/settings/status) [$MQTT_STATUS_TOPIC]
|
||||||
|
--mqtt.ha.enabled Enable Home Assistant MQTT discovery integration. [$MQTT_HA_ENABLED]
|
||||||
|
--mqtt.ha.discovery_prefix= Set Home Assistant MQTT discovery prefix. (default: homeassistant) [$MQTT_HA_DISCOVERY_PREFIX]
|
||||||
|
--mqtt.ha.node_id= Set Home Assistant node ID used for discovery topics and unique IDs. (default: invertergui) [$MQTT_HA_NODE_ID]
|
||||||
|
--mqtt.ha.device_name= Set Home Assistant device display name. (default: Victron Inverter) [$MQTT_HA_DEVICE_NAME]
|
||||||
--mqtt.username= Set the MQTT username [$MQTT_USERNAME]
|
--mqtt.username= Set the MQTT username [$MQTT_USERNAME]
|
||||||
--mqtt.password= Set the MQTT password [$MQTT_PASSWORD]
|
--mqtt.password= Set the MQTT password [$MQTT_PASSWORD]
|
||||||
|
--mqtt.password-file= Path to a file containing the MQTT password [$MQTT_PASSWORD_FILE]
|
||||||
```
|
```
|
||||||
|
|
||||||
The MQTT client can be enabled by setting the environment variable `MQTT_ENABLED=true` or flag `--mqtt.enabled`.
|
The MQTT client can be enabled by setting the environment variable `MQTT_ENABLED=true` or flag `--mqtt.enabled`.
|
||||||
All MQTT configuration can be done via flags or as environment variables.
|
All MQTT configuration can be done via flags or as environment variables.
|
||||||
The URI for the broker can be configured format should be `scheme://host:port`, where "scheme" is one of "tcp", "ssl", or "ws".
|
The URI for the broker can be configured format should be `scheme://host:port`, where "scheme" is one of "tcp", "ssl", or "ws".
|
||||||
|
|
||||||
|
When `--mqtt.command_topic` is configured, the application subscribes to that topic and accepts JSON write commands.
|
||||||
|
The recommended command for inverter control follows the same model used by `victron-mk3`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"request_id": "optional-correlation-id",
|
||||||
|
"kind": "panel_state",
|
||||||
|
"switch": "on",
|
||||||
|
"current_limit": 16.5
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`switch` supports `charger_only`, `inverter_only`, `on`, and `off` (or numeric values `1..4`).
|
||||||
|
`current_limit` is in amps and optional. If omitted, only the switch state is changed.
|
||||||
|
To update only the current limit (while preserving the last known mode), send:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"kind": "panel_state",
|
||||||
|
"current_limit": 12.0
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If no prior mode is known (for example on a fresh broker state), this command is rejected until a mode command is sent once.
|
||||||
|
|
||||||
|
Standby can be controlled with:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"kind": "standby",
|
||||||
|
"standby": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Low-level writes are still supported:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"kind": "setting",
|
||||||
|
"id": 15,
|
||||||
|
"value": 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`kind` supports `panel_state`, `setting`, and `ram_var` (with aliases for each).
|
||||||
|
The result is published to `--mqtt.status_topic` with status `ok` or `error`.
|
||||||
|
|
||||||
|
### Home Assistant
|
||||||
|
|
||||||
|
Enable Home Assistant auto-discovery with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
--mqtt.ha.enabled
|
||||||
|
```
|
||||||
|
|
||||||
|
When enabled, `invertergui` publishes retained discovery payloads and availability under:
|
||||||
|
|
||||||
|
- `{topic-root}/homeassistant/availability` (`online`/`offline`)
|
||||||
|
- `{discovery_prefix}/sensor/{node_id}/.../config`
|
||||||
|
- `{discovery_prefix}/binary_sensor/{node_id}/.../config`
|
||||||
|
- `{discovery_prefix}/select/{node_id}/remote_panel_mode/config` (if command topic is configured)
|
||||||
|
- `{discovery_prefix}/number/{node_id}/remote_panel_current_limit/config` (if command topic is configured)
|
||||||
|
- `{discovery_prefix}/switch/{node_id}/remote_panel_standby/config` (if command topic is configured)
|
||||||
|
|
||||||
|
The discovered entities include battery/input/output sensors, a data-valid diagnostic binary sensor,
|
||||||
|
plus remote panel controls for:
|
||||||
|
|
||||||
|
- `Remote Panel Mode` (`on`, `off`, `charger_only`, `inverter_only`)
|
||||||
|
- `Remote Panel Current Limit` (AC input current limit in amps)
|
||||||
|
- `Remote Panel Standby` (prevent device sleep while off)
|
||||||
|
|
||||||
|
The combined mode + current limit behavior is provided through the `panel_state` MQTT command kind,
|
||||||
|
which mirrors `victron_mk3.set_remote_panel_state`.
|
||||||
|
|
||||||
## TTY Device
|
## TTY Device
|
||||||
|
|
||||||
The intertergui application makes use of a serial tty device to monitor the Multiplus.
|
The intertergui application makes use of a serial tty device to monitor the Multiplus.
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jessevdk/go-flags"
|
"github.com/jessevdk/go-flags"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,10 +21,19 @@ type config struct {
|
|||||||
MQTT struct {
|
MQTT struct {
|
||||||
Enabled bool `long:"mqtt.enabled" env:"MQTT_ENABLED" description:"Enable MQTT publishing."`
|
Enabled bool `long:"mqtt.enabled" env:"MQTT_ENABLED" description:"Enable MQTT publishing."`
|
||||||
Broker string `long:"mqtt.broker" env:"MQTT_BROKER" default:"tcp://localhost:1883" description:"Set the host port and scheme of the MQTT broker."`
|
Broker string `long:"mqtt.broker" env:"MQTT_BROKER" default:"tcp://localhost:1883" description:"Set the host port and scheme of the MQTT broker."`
|
||||||
ClientID string `long:"mqtt.client_id" env:"MQTT_CLIENT_ID" default:"interter-gui" description:"Set the client ID for the MQTT connection."`
|
ClientID string `long:"mqtt.client_id" env:"MQTT_CLIENT_ID" default:"inverter-gui" description:"Set the client ID for the MQTT connection."`
|
||||||
Topic string `long:"mqtt.topic" env:"MQTT_TOPIC" default:"invertergui/updates" description:"Set the MQTT topic updates published to."`
|
Topic string `long:"mqtt.topic" env:"MQTT_TOPIC" default:"invertergui/updates" description:"Set the MQTT topic updates published to."`
|
||||||
|
CommandTopic string `long:"mqtt.command_topic" env:"MQTT_COMMAND_TOPIC" default:"invertergui/settings/set" description:"Set the MQTT topic that receives write commands for Victron settings/RAM variables."`
|
||||||
|
StatusTopic string `long:"mqtt.status_topic" env:"MQTT_STATUS_TOPIC" default:"invertergui/settings/status" description:"Set the MQTT topic where write command status updates are published."`
|
||||||
|
HA struct {
|
||||||
|
Enabled bool `long:"mqtt.ha.enabled" env:"MQTT_HA_ENABLED" description:"Enable Home Assistant MQTT discovery integration."`
|
||||||
|
DiscoveryPrefix string `long:"mqtt.ha.discovery_prefix" env:"MQTT_HA_DISCOVERY_PREFIX" default:"homeassistant" description:"Set Home Assistant MQTT discovery prefix."`
|
||||||
|
NodeID string `long:"mqtt.ha.node_id" env:"MQTT_HA_NODE_ID" default:"invertergui" description:"Set Home Assistant node ID used for discovery topics and unique IDs."`
|
||||||
|
DeviceName string `long:"mqtt.ha.device_name" env:"MQTT_HA_DEVICE_NAME" default:"Victron Inverter" description:"Set Home Assistant device display name."`
|
||||||
|
}
|
||||||
Username string `long:"mqtt.username" env:"MQTT_USERNAME" default:"" description:"Set the MQTT username"`
|
Username string `long:"mqtt.username" env:"MQTT_USERNAME" default:"" description:"Set the MQTT username"`
|
||||||
Password string `long:"mqtt.password" env:"MQTT_PASSWORD" default:"" description:"Set the MQTT password"`
|
Password string `long:"mqtt.password" env:"MQTT_PASSWORD" default:"" description:"Set the MQTT password"`
|
||||||
|
PasswordFile string `long:"mqtt.password-file" env:"MQTT_PASSWORD_FILE" default:"" description:"Path to a file containing the MQTT password"`
|
||||||
}
|
}
|
||||||
Loglevel string `long:"loglevel" env:"LOGLEVEL" default:"info" description:"The log level to generate logs at. (\"panic\", \"fatal\", \"error\", \"warn\", \"info\", \"debug\", \"trace\")"`
|
Loglevel string `long:"loglevel" env:"LOGLEVEL" default:"info" description:"The log level to generate logs at. (\"panic\", \"fatal\", \"error\", \"warn\", \"info\", \"debug\", \"trace\")"`
|
||||||
}
|
}
|
||||||
@@ -31,5 +44,30 @@ func parseConfig() (*config, error) {
|
|||||||
if _, err := parser.Parse(); err != nil {
|
if _, err := parser.Parse(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err := resolvePasswordFile(conf); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resolvePasswordFile(conf *config) error {
|
||||||
|
if conf.MQTT.PasswordFile != "" && conf.MQTT.Password != "" {
|
||||||
|
return fmt.Errorf("mqtt.password and mqtt.password-file are mutually exclusive")
|
||||||
|
}
|
||||||
|
if conf.MQTT.PasswordFile != "" {
|
||||||
|
password, err := readPasswordFile(conf.MQTT.PasswordFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
conf.MQTT.Password = password
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readPasswordFile(path string) (string, error) {
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("could not read MQTT password file: %w", err)
|
||||||
|
}
|
||||||
|
return strings.TrimRight(string(data), "\n\r"), nil
|
||||||
|
}
|
||||||
|
|||||||
107
cmd/invertergui/config_test.go
Normal file
107
cmd/invertergui/config_test.go
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testInlineSecret = "inline-secret"
|
||||||
|
|
||||||
|
func TestReadPasswordFile(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
content string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "plain password",
|
||||||
|
content: "secret",
|
||||||
|
expected: "secret",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "password with trailing newline",
|
||||||
|
content: "secret\n",
|
||||||
|
expected: "secret",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "password with trailing carriage return and newline",
|
||||||
|
content: "secret\r\n",
|
||||||
|
expected: "secret",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty file",
|
||||||
|
content: "",
|
||||||
|
expected: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
path := filepath.Join(t.TempDir(), "password")
|
||||||
|
if err := os.WriteFile(path, []byte(tt.content), 0o600); err != nil {
|
||||||
|
t.Fatalf("failed to write test file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := readPasswordFile(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if got != tt.expected {
|
||||||
|
t.Errorf("got %q, want %q", got, tt.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadPasswordFile_NotFound(t *testing.T) {
|
||||||
|
_, err := readPasswordFile("/nonexistent/path/password")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error for missing file, got nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolvePassword_MutuallyExclusive(t *testing.T) {
|
||||||
|
path := filepath.Join(t.TempDir(), "password")
|
||||||
|
if err := os.WriteFile(path, []byte("secret"), 0o600); err != nil {
|
||||||
|
t.Fatalf("failed to write test file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
conf := &config{}
|
||||||
|
conf.MQTT.Password = testInlineSecret
|
||||||
|
conf.MQTT.PasswordFile = path
|
||||||
|
|
||||||
|
err := resolvePasswordFile(conf)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error when both mqtt.password and mqtt.password-file are set, got nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolvePassword_FromFile(t *testing.T) {
|
||||||
|
path := filepath.Join(t.TempDir(), "password")
|
||||||
|
if err := os.WriteFile(path, []byte("file-secret\n"), 0o600); err != nil {
|
||||||
|
t.Fatalf("failed to write test file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
conf := &config{}
|
||||||
|
conf.MQTT.PasswordFile = path
|
||||||
|
|
||||||
|
if err := resolvePasswordFile(conf); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if conf.MQTT.Password != "file-secret" {
|
||||||
|
t.Errorf("got %q, want %q", conf.MQTT.Password, "file-secret")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolvePassword_NoFile(t *testing.T) {
|
||||||
|
conf := &config{}
|
||||||
|
conf.MQTT.Password = testInlineSecret
|
||||||
|
|
||||||
|
if err := resolvePasswordFile(conf); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if conf.MQTT.Password != testInlineSecret {
|
||||||
|
t.Errorf("got %q, want %q", conf.MQTT.Password, testInlineSecret)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,14 +37,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2core"
|
"invertergui/mk2core"
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
"github.com/diebietse/invertergui/plugins/cli"
|
"invertergui/plugins/cli"
|
||||||
"github.com/diebietse/invertergui/plugins/mqttclient"
|
"invertergui/plugins/mqttclient"
|
||||||
"github.com/diebietse/invertergui/plugins/munin"
|
"invertergui/plugins/munin"
|
||||||
"github.com/diebietse/invertergui/plugins/prometheus"
|
"invertergui/plugins/prometheus"
|
||||||
"github.com/diebietse/invertergui/plugins/webui"
|
"invertergui/plugins/webui"
|
||||||
"github.com/diebietse/invertergui/plugins/webui/static"
|
"invertergui/plugins/webui/static"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/tarm/serial"
|
"github.com/tarm/serial"
|
||||||
@@ -77,9 +77,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Webgui
|
// Webgui
|
||||||
gui := webui.NewWebGui(core.NewSubscription())
|
var writer mk2driver.SettingsWriter
|
||||||
|
if w, ok := mk2.(mk2driver.SettingsWriter); ok {
|
||||||
|
writer = w
|
||||||
|
}
|
||||||
|
gui := webui.NewWebGui(core.NewSubscription(), writer)
|
||||||
http.Handle("/", static.New())
|
http.Handle("/", static.New())
|
||||||
http.Handle("/ws", http.HandlerFunc(gui.ServeHub))
|
http.Handle("/ws", http.HandlerFunc(gui.ServeHub))
|
||||||
|
http.Handle("/api/remote-panel/state", http.HandlerFunc(gui.ServeRemotePanelState))
|
||||||
|
http.Handle("/api/remote-panel/standby", http.HandlerFunc(gui.ServeRemotePanelStandby))
|
||||||
|
|
||||||
// Munin
|
// Munin
|
||||||
mu := munin.NewMunin(core.NewSubscription())
|
mu := munin.NewMunin(core.NewSubscription())
|
||||||
@@ -95,11 +101,22 @@ func main() {
|
|||||||
mqttConf := mqttclient.Config{
|
mqttConf := mqttclient.Config{
|
||||||
Broker: conf.MQTT.Broker,
|
Broker: conf.MQTT.Broker,
|
||||||
Topic: conf.MQTT.Topic,
|
Topic: conf.MQTT.Topic,
|
||||||
|
CommandTopic: conf.MQTT.CommandTopic,
|
||||||
|
StatusTopic: conf.MQTT.StatusTopic,
|
||||||
ClientID: conf.MQTT.ClientID,
|
ClientID: conf.MQTT.ClientID,
|
||||||
|
HomeAssistant: mqttclient.HomeAssistantConfig{
|
||||||
|
Enabled: conf.MQTT.HA.Enabled,
|
||||||
|
DiscoveryPrefix: conf.MQTT.HA.DiscoveryPrefix,
|
||||||
|
NodeID: conf.MQTT.HA.NodeID,
|
||||||
|
DeviceName: conf.MQTT.HA.DeviceName,
|
||||||
|
},
|
||||||
Username: conf.MQTT.Username,
|
Username: conf.MQTT.Username,
|
||||||
Password: conf.MQTT.Password,
|
Password: conf.MQTT.Password,
|
||||||
}
|
}
|
||||||
if err := mqttclient.New(core.NewSubscription(), mqttConf); err != nil {
|
if writer == nil {
|
||||||
|
log.Warn("MK2 data source does not support write commands; MQTT command topic will be ignored")
|
||||||
|
}
|
||||||
|
if err := mqttclient.New(core.NewSubscription(), writer, mqttConf); err != nil {
|
||||||
log.Fatalf("Could not setup MQTT client: %v", err)
|
log.Fatalf("Could not setup MQTT client: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
coverage:
|
|
||||||
precision: 2
|
|
||||||
round: down
|
|
||||||
range: "65...100"
|
|
||||||
34
go.mod
34
go.mod
@@ -1,13 +1,31 @@
|
|||||||
module github.com/diebietse/invertergui
|
module invertergui
|
||||||
|
|
||||||
|
go 1.26
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/eclipse/paho.mqtt.golang v1.3.3
|
github.com/eclipse/paho.mqtt.golang v1.5.1
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/jessevdk/go-flags v1.5.0
|
github.com/jessevdk/go-flags v1.6.1
|
||||||
github.com/prometheus/client_golang v1.10.0
|
github.com/prometheus/client_golang v1.23.2
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.9.4
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.11.1
|
||||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
||||||
)
|
)
|
||||||
|
|
||||||
go 1.16
|
require (
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.6.2 // indirect
|
||||||
|
github.com/prometheus/common v0.67.5 // indirect
|
||||||
|
github.com/prometheus/procfs v0.19.2 // indirect
|
||||||
|
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||||
|
golang.org/x/net v0.50.0 // indirect
|
||||||
|
golang.org/x/sync v0.19.0 // indirect
|
||||||
|
golang.org/x/sys v0.41.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.11 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
|||||||
487
go.sum
487
go.sum
@@ -1,426 +1,93 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
|
||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
|
||||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
|
||||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
|
||||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
|
||||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
|
||||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
|
||||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
|
||||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
|
||||||
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
|
||||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
|
||||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
|
||||||
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
|
||||||
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
|
||||||
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
|
||||||
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
|
||||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
|
||||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
|
||||||
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
|
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
|
||||||
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
|
||||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
|
||||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
|
||||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
|
||||||
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
|
||||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik=
|
||||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE=
|
||||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
|
||||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
|
||||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.3.3 h1:Fh1zsLniMFJByLqKrSB9ZRjkbpU0k1Xne23ZqEE/O08=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.3.3/go.mod h1:eTzb4gxwwyWpqBUHGQZ4ABAV7+Jgm1PklsYT/eo8Hcc=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||||
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
|
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
|
||||||
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
|
|
||||||
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
|
||||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
|
||||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
|
||||||
github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
|
|
||||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
|
||||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
|
||||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
|
||||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
|
||||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
|
||||||
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
|
||||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
|
||||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
|
||||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
|
||||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
|
||||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
|
||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
|
||||||
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
|
||||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
|
||||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
|
||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
|
||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
|
||||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
|
||||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
|
||||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
|
||||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
|
||||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
|
||||||
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
|
||||||
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
|
||||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
|
||||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
|
||||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
|
||||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
|
||||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
|
||||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
|
||||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
|
||||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
|
||||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
|
||||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
|
||||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
|
||||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
|
||||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
|
||||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
|
||||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
|
||||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
|
||||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
|
||||||
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
||||||
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
|
||||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
|
||||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
|
||||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
|
||||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
|
||||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
|
||||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
|
||||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
|
||||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
|
||||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
|
||||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
|
||||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
|
||||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
|
||||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
|
||||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
|
||||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
|
||||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
|
||||||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
|
||||||
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
|
|
||||||
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
|
|
||||||
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
|
||||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
|
||||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
|
||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
|
||||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
|
||||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
|
||||||
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
|
||||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
|
||||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
|
||||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
|
||||||
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
|
|
||||||
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
|
||||||
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
|
||||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
|
||||||
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
|
|
||||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
|
||||||
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
|
||||||
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
|
||||||
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
|
|
||||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
|
||||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
|
||||||
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
|
||||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
|
||||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
|
||||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
|
||||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
|
||||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
|
||||||
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos=
|
||||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8=
|
||||||
github.com/prometheus/client_golang v1.10.0 h1:/o0BDeWzLWXNZ+4q5gXltUvaMpJqckTa+jTNoB+z4cg=
|
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
||||||
github.com/prometheus/client_golang v1.10.0/go.mod h1:WJM3cc3yu7XKBKa/I8WeZm+V3eltZnBwfENSU7mdogU=
|
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
|
||||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ=
|
||||||
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ=
|
||||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
|
||||||
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o=
|
||||||
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
|
github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g=
|
||||||
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
|
||||||
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
|
||||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
github.com/prometheus/common v0.18.0 h1:WCVKW7aL6LEe1uryfI9dnEc2ZqNB1Fn0ok930v0iL1Y=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
|
||||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
|
||||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
|
||||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
|
||||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
|
||||||
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
|
||||||
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
|
|
||||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
|
||||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
|
||||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
|
||||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
|
||||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
|
||||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
|
||||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
|
||||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
|
||||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
|
||||||
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
|
||||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
|
||||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
|
||||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
|
||||||
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
|
||||||
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
||||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
|
||||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
|
||||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
|
||||||
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
|
||||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
|
||||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
|
||||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
|
||||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
|
||||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
|
||||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
|
||||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
|
||||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
|
||||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
|
||||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
|
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc=
|
|
||||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
|
||||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
|
||||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
|
||||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
|
||||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
|
||||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
|
||||||
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
|
|
||||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
|
||||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
|
||||||
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
|
|
||||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
|
||||||
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
|
||||||
google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
|
||||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
|
||||||
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
|
||||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
|
||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
|
||||||
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
|
||||||
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
|
||||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
|
||||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
|
||||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
|
||||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mk2core
|
package mk2core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Core struct {
|
type Core struct {
|
||||||
|
|||||||
286
mk2driver/mk2.go
286
mk2driver/mk2.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -43,18 +44,31 @@ const (
|
|||||||
const (
|
const (
|
||||||
infoFrameHeader = 0x20
|
infoFrameHeader = 0x20
|
||||||
frameHeader = 0xff
|
frameHeader = 0xff
|
||||||
|
bootupFrameHeader = 0x0
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
acL1InfoFrame = 0x08
|
acL1InfoFrame = 0x08
|
||||||
dcInfoFrame = 0x0C
|
dcInfoFrame = 0x0C
|
||||||
|
interfaceFrame = 0x48 // H
|
||||||
setTargetFrame = 0x41
|
setTargetFrame = 0x41
|
||||||
infoReqFrame = 0x46 //F
|
infoReqFrame = 0x46 //F
|
||||||
ledFrame = 0x4C
|
ledFrame = 0x4C
|
||||||
|
stateFrame = 0x53 // S
|
||||||
vFrame = 0x56
|
vFrame = 0x56
|
||||||
winmonFrame = 0x57
|
winmonFrame = 0x57
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
panelStateVariant2Flags = 0x80
|
||||||
|
|
||||||
|
interfacePanelDetectFlag = 0x01
|
||||||
|
interfaceStandbyFlag = 0x02
|
||||||
|
|
||||||
|
panelCurrentLimitUnknown = 0x8000
|
||||||
|
panelCurrentLimitMax = 0x7FFF
|
||||||
|
)
|
||||||
|
|
||||||
// info frame types
|
// info frame types
|
||||||
const (
|
const (
|
||||||
infoReqAddrDC = 0x00
|
infoReqAddrDC = 0x00
|
||||||
@@ -64,12 +78,21 @@ const (
|
|||||||
// winmon frame commands
|
// winmon frame commands
|
||||||
const (
|
const (
|
||||||
commandReadRAMVar = 0x30
|
commandReadRAMVar = 0x30
|
||||||
|
commandWriteRAMVar = 0x32
|
||||||
|
commandWriteSetting = 0x33
|
||||||
|
commandWriteData = 0x34
|
||||||
commandGetRAMVarInfo = 0x36
|
commandGetRAMVarInfo = 0x36
|
||||||
|
|
||||||
|
commandUnsupportedResponse = 0x80
|
||||||
commandReadRAMResponse = 0x85
|
commandReadRAMResponse = 0x85
|
||||||
|
commandWriteRAMResponse = 0x87
|
||||||
|
commandWriteSettingResponse = 0x88
|
||||||
|
commandWriteNotAllowedResponse = 0x9B
|
||||||
commandGetRAMVarInfoResponse = 0x8E
|
commandGetRAMVarInfoResponse = 0x8E
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const writeResponseTimeout = 3 * time.Second
|
||||||
|
|
||||||
type mk2Ser struct {
|
type mk2Ser struct {
|
||||||
info *Mk2Info
|
info *Mk2Info
|
||||||
p io.ReadWriter
|
p io.ReadWriter
|
||||||
@@ -78,6 +101,10 @@ type mk2Ser struct {
|
|||||||
run chan struct{}
|
run chan struct{}
|
||||||
frameLock bool
|
frameLock bool
|
||||||
infochan chan *Mk2Info
|
infochan chan *Mk2Info
|
||||||
|
commandMu sync.Mutex
|
||||||
|
writeAck chan byte
|
||||||
|
stateAck chan struct{}
|
||||||
|
ifaceAck chan byte
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +115,9 @@ func NewMk2Connection(dev io.ReadWriter) (Mk2, error) {
|
|||||||
mk2.scaleCount = 0
|
mk2.scaleCount = 0
|
||||||
mk2.frameLock = false
|
mk2.frameLock = false
|
||||||
mk2.scales = make([]scaling, 0, ramVarMaxOffset)
|
mk2.scales = make([]scaling, 0, ramVarMaxOffset)
|
||||||
|
mk2.writeAck = make(chan byte, 4)
|
||||||
|
mk2.stateAck = make(chan struct{}, 1)
|
||||||
|
mk2.ifaceAck = make(chan byte, 1)
|
||||||
mk2.setTarget()
|
mk2.setTarget()
|
||||||
mk2.run = make(chan struct{})
|
mk2.run = make(chan struct{})
|
||||||
mk2.infochan = make(chan *Mk2Info)
|
mk2.infochan = make(chan *Mk2Info)
|
||||||
@@ -152,6 +182,233 @@ func (m *mk2Ser) C() chan *Mk2Info {
|
|||||||
return m.infochan
|
return m.infochan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) WriteRAMVar(id uint16, value int16) error {
|
||||||
|
return m.writeByID(commandWriteRAMVar, commandWriteRAMResponse, id, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) WriteSetting(id uint16, value int16) error {
|
||||||
|
return m.writeByID(commandWriteSetting, commandWriteSettingResponse, id, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) SetPanelState(switchState PanelSwitchState, currentLimitA *float64) error {
|
||||||
|
if !validPanelSwitchState(switchState) {
|
||||||
|
return fmt.Errorf("invalid panel switch state: %d", switchState)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLimitRaw, err := encodePanelCurrentLimit(currentLimitA)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.commandMu.Lock()
|
||||||
|
defer m.commandMu.Unlock()
|
||||||
|
|
||||||
|
m.clearStateResponses()
|
||||||
|
m.sendCommandLocked([]byte{
|
||||||
|
stateFrame,
|
||||||
|
byte(switchState),
|
||||||
|
byte(currentLimitRaw),
|
||||||
|
byte(currentLimitRaw >> 8),
|
||||||
|
0x01,
|
||||||
|
panelStateVariant2Flags,
|
||||||
|
})
|
||||||
|
|
||||||
|
return m.waitForStateResponse()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) SetStandby(enabled bool) error {
|
||||||
|
lineState := byte(interfacePanelDetectFlag)
|
||||||
|
if enabled {
|
||||||
|
lineState |= interfaceStandbyFlag
|
||||||
|
}
|
||||||
|
|
||||||
|
m.commandMu.Lock()
|
||||||
|
defer m.commandMu.Unlock()
|
||||||
|
|
||||||
|
m.clearInterfaceResponses()
|
||||||
|
m.sendCommandLocked([]byte{
|
||||||
|
interfaceFrame,
|
||||||
|
lineState,
|
||||||
|
})
|
||||||
|
|
||||||
|
return m.waitForInterfaceResponse(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func validPanelSwitchState(switchState PanelSwitchState) bool {
|
||||||
|
switch switchState {
|
||||||
|
case PanelSwitchChargerOnly, PanelSwitchInverterOnly, PanelSwitchOn, PanelSwitchOff:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodePanelCurrentLimit(currentLimitA *float64) (uint16, error) {
|
||||||
|
if currentLimitA == nil {
|
||||||
|
return panelCurrentLimitUnknown, nil
|
||||||
|
}
|
||||||
|
if *currentLimitA < 0 {
|
||||||
|
return 0, fmt.Errorf("current_limit must be >= 0, got %.3f", *currentLimitA)
|
||||||
|
}
|
||||||
|
|
||||||
|
raw := math.Round(*currentLimitA * 10)
|
||||||
|
if raw > panelCurrentLimitMax {
|
||||||
|
return 0, fmt.Errorf("current_limit %.3f A is above MK2 maximum %.1f A", *currentLimitA, panelCurrentLimitMax/10.0)
|
||||||
|
}
|
||||||
|
return uint16(raw), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) writeByID(selectCommand, expectedResponse byte, id uint16, value int16) error {
|
||||||
|
m.commandMu.Lock()
|
||||||
|
defer m.commandMu.Unlock()
|
||||||
|
|
||||||
|
m.clearWriteResponses()
|
||||||
|
|
||||||
|
m.sendCommandLocked([]byte{
|
||||||
|
winmonFrame,
|
||||||
|
selectCommand,
|
||||||
|
byte(id),
|
||||||
|
byte(id >> 8),
|
||||||
|
})
|
||||||
|
|
||||||
|
rawValue := uint16(value)
|
||||||
|
m.sendCommandLocked([]byte{
|
||||||
|
winmonFrame,
|
||||||
|
commandWriteData,
|
||||||
|
byte(rawValue),
|
||||||
|
byte(rawValue >> 8),
|
||||||
|
})
|
||||||
|
|
||||||
|
return m.waitForWriteResponse(expectedResponse)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) clearWriteResponses() {
|
||||||
|
if m.writeAck == nil {
|
||||||
|
m.writeAck = make(chan byte, 4)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-m.writeAck:
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) waitForWriteResponse(expectedResponse byte) error {
|
||||||
|
if m.writeAck == nil {
|
||||||
|
return errors.New("write response channel is not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case response := <-m.writeAck:
|
||||||
|
switch response {
|
||||||
|
case expectedResponse:
|
||||||
|
return nil
|
||||||
|
case commandUnsupportedResponse:
|
||||||
|
return errors.New("write command is not supported by this device firmware")
|
||||||
|
case commandWriteNotAllowedResponse:
|
||||||
|
return errors.New("write command rejected by device access level")
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unexpected write response 0x%02x", response)
|
||||||
|
}
|
||||||
|
case <-time.After(writeResponseTimeout):
|
||||||
|
return fmt.Errorf("timed out waiting for write response after %s", writeResponseTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) pushWriteResponse(response byte) {
|
||||||
|
if m.writeAck == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case m.writeAck <- response:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) clearStateResponses() {
|
||||||
|
if m.stateAck == nil {
|
||||||
|
m.stateAck = make(chan struct{}, 1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-m.stateAck:
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) waitForStateResponse() error {
|
||||||
|
if m.stateAck == nil {
|
||||||
|
return errors.New("panel state response channel is not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-m.stateAck:
|
||||||
|
return nil
|
||||||
|
case <-time.After(writeResponseTimeout):
|
||||||
|
return fmt.Errorf("timed out waiting for panel state response after %s", writeResponseTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) pushStateResponse() {
|
||||||
|
if m.stateAck == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case m.stateAck <- struct{}{}:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) clearInterfaceResponses() {
|
||||||
|
if m.ifaceAck == nil {
|
||||||
|
m.ifaceAck = make(chan byte, 1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-m.ifaceAck:
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) waitForInterfaceResponse(expectedStandby bool) error {
|
||||||
|
if m.ifaceAck == nil {
|
||||||
|
return errors.New("interface response channel is not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case lineState := <-m.ifaceAck:
|
||||||
|
standbyEnabled := lineState&interfaceStandbyFlag != 0
|
||||||
|
if standbyEnabled != expectedStandby {
|
||||||
|
return fmt.Errorf("unexpected standby line state 0x%02x", lineState)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
case <-time.After(writeResponseTimeout):
|
||||||
|
return fmt.Errorf("timed out waiting for standby response after %s", writeResponseTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) pushInterfaceResponse(lineState byte) {
|
||||||
|
if m.ifaceAck == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case m.ifaceAck <- lineState:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mk2Ser) readByte() byte {
|
func (m *mk2Ser) readByte() byte {
|
||||||
buffer := make([]byte, 1)
|
buffer := make([]byte, 1)
|
||||||
_, err := io.ReadFull(m.p, buffer)
|
_, err := io.ReadFull(m.p, buffer)
|
||||||
@@ -164,6 +421,7 @@ func (m *mk2Ser) readByte() byte {
|
|||||||
|
|
||||||
// Adds error to error slice.
|
// Adds error to error slice.
|
||||||
func (m *mk2Ser) addError(err error) {
|
func (m *mk2Ser) addError(err error) {
|
||||||
|
logrus.Errorf("Mk2 serial slice error: %q", err.Error())
|
||||||
if m.info.Errors == nil {
|
if m.info.Errors == nil {
|
||||||
m.info.Errors = make([]error, 0)
|
m.info.Errors = make([]error, 0)
|
||||||
}
|
}
|
||||||
@@ -183,11 +441,19 @@ func (m *mk2Ser) updateReport() {
|
|||||||
|
|
||||||
// Checks for valid frame and chooses decoding.
|
// Checks for valid frame and chooses decoding.
|
||||||
func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
||||||
logrus.Debugf("frame %#v", frame)
|
logrus.Debugf("[handleFrame] frame %#v", frame)
|
||||||
if checkChecksum(l, frame[0], frame[1:]) {
|
if checkChecksum(l, frame[0], frame[1:]) {
|
||||||
switch frame[0] {
|
switch frame[0] {
|
||||||
|
case bootupFrameHeader:
|
||||||
|
m.setTarget()
|
||||||
case frameHeader:
|
case frameHeader:
|
||||||
switch frame[1] {
|
switch frame[1] {
|
||||||
|
case interfaceFrame:
|
||||||
|
if len(frame) > 2 {
|
||||||
|
m.pushInterfaceResponse(frame[2])
|
||||||
|
}
|
||||||
|
case stateFrame:
|
||||||
|
m.pushStateResponse()
|
||||||
case vFrame:
|
case vFrame:
|
||||||
m.versionDecode(frame[2:])
|
m.versionDecode(frame[2:])
|
||||||
case winmonFrame:
|
case winmonFrame:
|
||||||
@@ -196,10 +462,16 @@ func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
|||||||
m.scaleDecode(frame[2:])
|
m.scaleDecode(frame[2:])
|
||||||
case commandReadRAMResponse:
|
case commandReadRAMResponse:
|
||||||
m.stateDecode(frame[2:])
|
m.stateDecode(frame[2:])
|
||||||
|
case commandWriteRAMResponse, commandWriteSettingResponse, commandUnsupportedResponse, commandWriteNotAllowedResponse:
|
||||||
|
m.pushWriteResponse(frame[2])
|
||||||
|
default:
|
||||||
|
logrus.Warnf("[handleFrame] invalid winmonFrame %v", frame[2:])
|
||||||
}
|
}
|
||||||
|
|
||||||
case ledFrame:
|
case ledFrame:
|
||||||
m.ledDecode(frame[2:])
|
m.ledDecode(frame[2:])
|
||||||
|
default:
|
||||||
|
logrus.Warnf("[handleFrame] invalid frameHeader %v", frame[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
case infoFrameHeader:
|
case infoFrameHeader:
|
||||||
@@ -208,10 +480,14 @@ func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
|||||||
m.dcDecode(frame[1:])
|
m.dcDecode(frame[1:])
|
||||||
case acL1InfoFrame:
|
case acL1InfoFrame:
|
||||||
m.acDecode(frame[1:])
|
m.acDecode(frame[1:])
|
||||||
|
default:
|
||||||
|
logrus.Warnf("[handleFrame] invalid infoFrameHeader %v", frame[5])
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
logrus.Warnf("[handleFrame] Invalid frame %v", frame[0])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Errorf("Invalid incoming frame checksum: %x", frame)
|
logrus.Errorf("[handleFrame] Invalid incoming frame checksum: %x", frame)
|
||||||
m.frameLock = false
|
m.frameLock = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,6 +694,12 @@ func getLEDs(ledsOn, ledsBlink byte) map[Led]LEDstate {
|
|||||||
|
|
||||||
// Adds header and trailing crc for frame to send.
|
// Adds header and trailing crc for frame to send.
|
||||||
func (m *mk2Ser) sendCommand(data []byte) {
|
func (m *mk2Ser) sendCommand(data []byte) {
|
||||||
|
m.commandMu.Lock()
|
||||||
|
defer m.commandMu.Unlock()
|
||||||
|
m.sendCommandLocked(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) sendCommandLocked(data []byte) {
|
||||||
l := len(data)
|
l := len(data)
|
||||||
dataOut := make([]byte, l+3)
|
dataOut := make([]byte, l+3)
|
||||||
dataOut[0] = byte(l + 1)
|
dataOut[0] = byte(l + 1)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -42,6 +43,7 @@ type testIo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewIOStub(readBuffer []byte) io.ReadWriter {
|
func NewIOStub(readBuffer []byte) io.ReadWriter {
|
||||||
|
writeBuffer = bytes.NewBuffer(nil)
|
||||||
return &testIo{
|
return &testIo{
|
||||||
Reader: bytes.NewBuffer(readBuffer),
|
Reader: bytes.NewBuffer(readBuffer),
|
||||||
Writer: writeBuffer,
|
Writer: writeBuffer,
|
||||||
@@ -309,3 +311,127 @@ func Test_mk2Ser_calcFreq(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_WriteSetting(t *testing.T) {
|
||||||
|
testIO := NewIOStub(nil)
|
||||||
|
m := &mk2Ser{
|
||||||
|
p: testIO,
|
||||||
|
writeAck: make(chan byte, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
m.pushWriteResponse(commandWriteSettingResponse)
|
||||||
|
}()
|
||||||
|
|
||||||
|
err := m.WriteSetting(0x1234, 1234)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
expected := []byte{
|
||||||
|
0x05, 0xff, 0x57, 0x33, 0x34, 0x12, 0x2c,
|
||||||
|
0x05, 0xff, 0x57, 0x34, 0xd2, 0x04, 0x9b,
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, writeBuffer.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_WriteRAMVarRejected(t *testing.T) {
|
||||||
|
testIO := NewIOStub(nil)
|
||||||
|
m := &mk2Ser{
|
||||||
|
p: testIO,
|
||||||
|
writeAck: make(chan byte, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
m.pushWriteResponse(commandWriteNotAllowedResponse)
|
||||||
|
}()
|
||||||
|
|
||||||
|
err := m.WriteRAMVar(0x000d, 1)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.ErrorContains(t, err, "rejected")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_SetPanelState(t *testing.T) {
|
||||||
|
testIO := NewIOStub(nil)
|
||||||
|
m := &mk2Ser{
|
||||||
|
p: testIO,
|
||||||
|
stateAck: make(chan struct{}, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
m.pushStateResponse()
|
||||||
|
}()
|
||||||
|
|
||||||
|
currentLimit := 16.5
|
||||||
|
err := m.SetPanelState(PanelSwitchOn, ¤tLimit)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
expected := []byte{
|
||||||
|
0x07, 0xff, 0x53, 0x03, 0xa5, 0x00, 0x01, 0x80, 0x7e,
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, writeBuffer.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_SetPanelState_SwitchOnly(t *testing.T) {
|
||||||
|
testIO := NewIOStub(nil)
|
||||||
|
m := &mk2Ser{
|
||||||
|
p: testIO,
|
||||||
|
stateAck: make(chan struct{}, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
m.pushStateResponse()
|
||||||
|
}()
|
||||||
|
|
||||||
|
err := m.SetPanelState(PanelSwitchOff, nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
expected := []byte{
|
||||||
|
0x07, 0xff, 0x53, 0x04, 0x00, 0x80, 0x01, 0x80, 0xa2,
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, writeBuffer.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_SetStandby(t *testing.T) {
|
||||||
|
testIO := NewIOStub(nil)
|
||||||
|
m := &mk2Ser{
|
||||||
|
p: testIO,
|
||||||
|
ifaceAck: make(chan byte, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
m.pushInterfaceResponse(interfacePanelDetectFlag | interfaceStandbyFlag)
|
||||||
|
}()
|
||||||
|
|
||||||
|
err := m.SetStandby(true)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
expected := []byte{
|
||||||
|
0x03, 0xff, 0x48, 0x03, 0xb3,
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, writeBuffer.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_SetStandby_Disabled(t *testing.T) {
|
||||||
|
testIO := NewIOStub(nil)
|
||||||
|
m := &mk2Ser{
|
||||||
|
p: testIO,
|
||||||
|
ifaceAck: make(chan byte, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
m.pushInterfaceResponse(interfacePanelDetectFlag)
|
||||||
|
}()
|
||||||
|
|
||||||
|
err := m.SetStandby(false)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
expected := []byte{
|
||||||
|
0x03, 0xff, 0x48, 0x01, 0xb5,
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, writeBuffer.Bytes())
|
||||||
|
}
|
||||||
|
|||||||
@@ -76,3 +76,29 @@ type Mk2 interface {
|
|||||||
C() chan *Mk2Info
|
C() chan *Mk2Info
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PanelSwitchState byte
|
||||||
|
|
||||||
|
const (
|
||||||
|
// PanelSwitchChargerOnly enables charging only.
|
||||||
|
PanelSwitchChargerOnly PanelSwitchState = 0x01
|
||||||
|
// PanelSwitchInverterOnly enables inverter output and disables charging.
|
||||||
|
PanelSwitchInverterOnly PanelSwitchState = 0x02
|
||||||
|
// PanelSwitchOn enables both inverter and charger.
|
||||||
|
PanelSwitchOn PanelSwitchState = 0x03
|
||||||
|
// PanelSwitchOff disables inverter and charger.
|
||||||
|
PanelSwitchOff PanelSwitchState = 0x04
|
||||||
|
)
|
||||||
|
|
||||||
|
type SettingsWriter interface {
|
||||||
|
// WriteRAMVar writes a signed 16-bit value to a RAM variable id.
|
||||||
|
WriteRAMVar(id uint16, value int16) error
|
||||||
|
// WriteSetting writes a signed 16-bit value to a setting id.
|
||||||
|
WriteSetting(id uint16, value int16) error
|
||||||
|
// SetPanelState sends the MK2 "S" command using a virtual panel switch state.
|
||||||
|
// If currentLimitA is nil, the command does not update the AC current limit.
|
||||||
|
SetPanelState(switchState PanelSwitchState, currentLimitA *float64) error
|
||||||
|
// SetStandby configures the remote panel standby line.
|
||||||
|
// When enabled, the inverter is prevented from sleeping while switched off.
|
||||||
|
SetStandby(enabled bool) error
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,6 +37,22 @@ func (m *mock) Close() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mock) WriteRAMVar(_ uint16, _ int16) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mock) WriteSetting(_ uint16, _ int16) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mock) SetPanelState(_ PanelSwitchState, _ *float64) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mock) SetStandby(_ bool) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mock) genMockValues() {
|
func (m *mock) genMockValues() {
|
||||||
mult := 1.0
|
mult := 1.0
|
||||||
ledState := LedOff
|
ledState := LedOff
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,14 @@ package mqttclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@@ -13,42 +18,758 @@ var log = logrus.WithField("ctx", "inverter-gui-mqtt")
|
|||||||
|
|
||||||
const keepAlive = 5 * time.Second
|
const keepAlive = 5 * time.Second
|
||||||
|
|
||||||
|
const (
|
||||||
|
commandKindSetting = "setting"
|
||||||
|
commandKindRAMVar = "ram_var"
|
||||||
|
commandKindPanel = "panel_state"
|
||||||
|
commandKindStandby = "standby"
|
||||||
|
|
||||||
|
writeStatusOK = "ok"
|
||||||
|
writeStatusError = "error"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HomeAssistantConfig struct {
|
||||||
|
Enabled bool
|
||||||
|
DiscoveryPrefix string
|
||||||
|
NodeID string
|
||||||
|
DeviceName string
|
||||||
|
}
|
||||||
|
|
||||||
// Config sets MQTT client configuration
|
// Config sets MQTT client configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Broker string
|
Broker string
|
||||||
ClientID string
|
ClientID string
|
||||||
Topic string
|
Topic string
|
||||||
|
CommandTopic string
|
||||||
|
StatusTopic string
|
||||||
|
HomeAssistant HomeAssistantConfig
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates an MQTT client that starts publishing MK2 data as it is received.
|
type writeCommand struct {
|
||||||
func New(mk2 mk2driver.Mk2, config Config) error {
|
RequestID string
|
||||||
|
Kind string
|
||||||
|
ID uint16
|
||||||
|
Value int16
|
||||||
|
HasSwitch bool
|
||||||
|
SwitchState mk2driver.PanelSwitchState
|
||||||
|
SwitchName string
|
||||||
|
CurrentLimitA *float64
|
||||||
|
Standby *bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type writeCommandPayload struct {
|
||||||
|
RequestID string `json:"request_id"`
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
ID *uint16 `json:"id"`
|
||||||
|
Value json.RawMessage `json:"value"`
|
||||||
|
Switch string `json:"switch"`
|
||||||
|
SwitchState string `json:"switch_state"`
|
||||||
|
CurrentLimitA *float64 `json:"current_limit"`
|
||||||
|
Standby *bool `json:"standby"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type writeStatus struct {
|
||||||
|
RequestID string `json:"request_id,omitempty"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Kind string `json:"kind,omitempty"`
|
||||||
|
ID uint16 `json:"id"`
|
||||||
|
Value int16 `json:"value"`
|
||||||
|
Switch string `json:"switch,omitempty"`
|
||||||
|
CurrentLimitA *float64 `json:"current_limit,omitempty"`
|
||||||
|
Standby *bool `json:"standby,omitempty"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
Timestamp time.Time `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type haDiscoveryDefinition struct {
|
||||||
|
Component string
|
||||||
|
ObjectID string
|
||||||
|
Config map[string]any
|
||||||
|
}
|
||||||
|
|
||||||
|
type panelStateCache struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
hasSwitch bool
|
||||||
|
switchName string
|
||||||
|
switchState mk2driver.PanelSwitchState
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an MQTT client that publishes MK2 updates and optionally handles setting write commands.
|
||||||
|
func New(mk2 mk2driver.Mk2, writer mk2driver.SettingsWriter, config Config) error {
|
||||||
c := mqtt.NewClient(getOpts(config))
|
c := mqtt.NewClient(getOpts(config))
|
||||||
if token := c.Connect(); token.Wait() && token.Error() != nil {
|
if token := c.Connect(); token.Wait() && token.Error() != nil {
|
||||||
return token.Error()
|
return token.Error()
|
||||||
}
|
}
|
||||||
|
cache := &panelStateCache{}
|
||||||
|
|
||||||
|
if config.HomeAssistant.Enabled {
|
||||||
|
if err := publishHAAvailability(c, config, "online"); err != nil {
|
||||||
|
return fmt.Errorf("could not publish Home Assistant availability: %w", err)
|
||||||
|
}
|
||||||
|
if err := publishHADiscovery(c, config); err != nil {
|
||||||
|
return fmt.Errorf("could not publish Home Assistant discovery payloads: %w", err)
|
||||||
|
}
|
||||||
|
if writer != nil {
|
||||||
|
if err := subscribeHAPanelModeState(c, config, cache); err != nil {
|
||||||
|
log.Warnf("Could not subscribe to Home Assistant panel mode state topic: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.CommandTopic != "" {
|
||||||
|
if writer == nil {
|
||||||
|
log.Warnf("MQTT command topic %q configured, but no settings writer is available", config.CommandTopic)
|
||||||
|
} else {
|
||||||
|
t := c.Subscribe(config.CommandTopic, 1, commandHandler(c, writer, config, cache))
|
||||||
|
t.Wait()
|
||||||
|
if t.Error() != nil {
|
||||||
|
return fmt.Errorf("could not subscribe to MQTT command topic %q: %w", config.CommandTopic, t.Error())
|
||||||
|
}
|
||||||
|
log.Infof("Subscribed to MQTT command topic: %s", config.CommandTopic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for e := range mk2.C() {
|
for e := range mk2.C() {
|
||||||
if e.Valid {
|
if e == nil || !e.Valid {
|
||||||
data, err := json.Marshal(e)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Could not parse data source: %v", err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if err := publishJSON(c, config.Topic, e, 0, false); err != nil {
|
||||||
t := c.Publish(config.Topic, 0, false, data)
|
log.Errorf("Could not publish update to MQTT topic %q: %v", config.Topic, err)
|
||||||
t.Wait()
|
|
||||||
if t.Error() != nil {
|
|
||||||
log.Errorf("Could not publish data: %v", t.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func subscribeHAPanelModeState(client mqtt.Client, config Config, cache *panelStateCache) error {
|
||||||
|
if cache == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
stateTopic := haPanelSwitchStateTopic(config)
|
||||||
|
t := client.Subscribe(stateTopic, 1, func(_ mqtt.Client, msg mqtt.Message) {
|
||||||
|
switchState, switchName, err := normalizePanelSwitch(string(msg.Payload()))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cache.remember(writeCommand{
|
||||||
|
Kind: commandKindPanel,
|
||||||
|
HasSwitch: true,
|
||||||
|
SwitchState: switchState,
|
||||||
|
SwitchName: switchName,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
t.Wait()
|
||||||
|
return t.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
func commandHandler(client mqtt.Client, writer mk2driver.SettingsWriter, config Config, cache *panelStateCache) mqtt.MessageHandler {
|
||||||
|
if cache == nil {
|
||||||
|
cache = &panelStateCache{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return func(_ mqtt.Client, msg mqtt.Message) {
|
||||||
|
cmd, err := decodeWriteCommand(msg.Payload())
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Invalid MQTT write command payload from topic %q: %v", msg.Topic(), err)
|
||||||
|
publishWriteStatus(client, config.StatusTopic, writeStatus{
|
||||||
|
Status: writeStatusError,
|
||||||
|
Error: err.Error(),
|
||||||
|
Timestamp: time.Now().UTC(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
execCmd := cmd
|
||||||
|
status := writeStatus{
|
||||||
|
RequestID: cmd.RequestID,
|
||||||
|
Status: writeStatusOK,
|
||||||
|
Kind: cmd.Kind,
|
||||||
|
Timestamp: time.Now().UTC(),
|
||||||
|
}
|
||||||
|
switch cmd.Kind {
|
||||||
|
case commandKindPanel:
|
||||||
|
execCmd, err = cache.resolvePanelCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
status.Status = writeStatusError
|
||||||
|
status.Error = err.Error()
|
||||||
|
log.Errorf("Invalid MQTT write command %s: %v", formatWriteCommandLog(cmd), err)
|
||||||
|
publishWriteStatus(client, config.StatusTopic, status)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
status.Switch = execCmd.SwitchName
|
||||||
|
status.CurrentLimitA = execCmd.CurrentLimitA
|
||||||
|
case commandKindStandby:
|
||||||
|
status.Standby = copyBoolPtr(execCmd.Standby)
|
||||||
|
default:
|
||||||
|
status.ID = cmd.ID
|
||||||
|
status.Value = cmd.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := executeWriteCommand(writer, execCmd); err != nil {
|
||||||
|
status.Status = writeStatusError
|
||||||
|
status.Error = err.Error()
|
||||||
|
log.Errorf("Failed MQTT write command %s: %v", formatWriteCommandLog(execCmd), err)
|
||||||
|
} else {
|
||||||
|
log.Infof("Applied MQTT write command %s", formatWriteCommandLog(execCmd))
|
||||||
|
cache.remember(execCmd)
|
||||||
|
if config.HomeAssistant.Enabled {
|
||||||
|
if err := publishHAControlState(client, config, execCmd); err != nil {
|
||||||
|
log.Errorf("Could not publish Home Assistant control state update: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishWriteStatus(client, config.StatusTopic, status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *panelStateCache) resolvePanelCommand(cmd writeCommand) (writeCommand, error) {
|
||||||
|
if cmd.Kind != commandKindPanel {
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.HasSwitch {
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
if !c.hasSwitch {
|
||||||
|
return writeCommand{}, errors.New("panel_state command missing switch and no prior mode is known; set mode once first")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.HasSwitch = true
|
||||||
|
cmd.SwitchName = c.switchName
|
||||||
|
cmd.SwitchState = c.switchState
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *panelStateCache) remember(cmd writeCommand) {
|
||||||
|
if cmd.Kind != commandKindPanel || !cmd.HasSwitch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.mu.Lock()
|
||||||
|
c.hasSwitch = true
|
||||||
|
c.switchName = cmd.SwitchName
|
||||||
|
c.switchState = cmd.SwitchState
|
||||||
|
c.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeWriteCommand(payload []byte) (writeCommand, error) {
|
||||||
|
msg := writeCommandPayload{}
|
||||||
|
if err := json.Unmarshal(payload, &msg); err != nil {
|
||||||
|
return writeCommand{}, fmt.Errorf("invalid JSON payload: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
kind := msg.Kind
|
||||||
|
if kind == "" {
|
||||||
|
kind = msg.Type
|
||||||
|
}
|
||||||
|
normalizedKind, err := normalizeWriteKind(kind)
|
||||||
|
if err != nil {
|
||||||
|
return writeCommand{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if normalizedKind == commandKindPanel {
|
||||||
|
switchName := msg.Switch
|
||||||
|
if switchName == "" {
|
||||||
|
switchName = msg.SwitchState
|
||||||
|
}
|
||||||
|
|
||||||
|
hasSwitch := false
|
||||||
|
switchState := mk2driver.PanelSwitchState(0)
|
||||||
|
normalizedSwitchName := ""
|
||||||
|
if switchName != "" {
|
||||||
|
var err error
|
||||||
|
switchState, normalizedSwitchName, err = normalizePanelSwitch(switchName)
|
||||||
|
if err != nil {
|
||||||
|
return writeCommand{}, err
|
||||||
|
}
|
||||||
|
hasSwitch = true
|
||||||
|
}
|
||||||
|
if msg.CurrentLimitA != nil && *msg.CurrentLimitA < 0 {
|
||||||
|
return writeCommand{}, fmt.Errorf("current_limit must be >= 0, got %.3f", *msg.CurrentLimitA)
|
||||||
|
}
|
||||||
|
if !hasSwitch && msg.CurrentLimitA == nil {
|
||||||
|
return writeCommand{}, errors.New(`missing required field "switch" (or "switch_state"), or "current_limit"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return writeCommand{
|
||||||
|
RequestID: msg.RequestID,
|
||||||
|
Kind: normalizedKind,
|
||||||
|
HasSwitch: hasSwitch,
|
||||||
|
SwitchState: switchState,
|
||||||
|
SwitchName: normalizedSwitchName,
|
||||||
|
CurrentLimitA: msg.CurrentLimitA,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if normalizedKind == commandKindStandby {
|
||||||
|
standby, err := decodeStandbyValue(msg)
|
||||||
|
if err != nil {
|
||||||
|
return writeCommand{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return writeCommand{
|
||||||
|
RequestID: msg.RequestID,
|
||||||
|
Kind: normalizedKind,
|
||||||
|
Standby: &standby,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.ID == nil {
|
||||||
|
return writeCommand{}, errors.New(`missing required field "id"`)
|
||||||
|
}
|
||||||
|
value, err := decodeInt16Value(msg.Value)
|
||||||
|
if err != nil {
|
||||||
|
return writeCommand{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return writeCommand{
|
||||||
|
RequestID: msg.RequestID,
|
||||||
|
Kind: normalizedKind,
|
||||||
|
ID: *msg.ID,
|
||||||
|
Value: value,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeWriteKind(raw string) (string, error) {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(raw)) {
|
||||||
|
case "setting", "settings":
|
||||||
|
return commandKindSetting, nil
|
||||||
|
case "ram", "ramvar", "ram_var", "ram-variable", "ramvariable":
|
||||||
|
return commandKindRAMVar, nil
|
||||||
|
case "panel", "panel_state", "switch", "remote_panel":
|
||||||
|
return commandKindPanel, nil
|
||||||
|
case "standby", "panel_standby", "remote_panel_standby":
|
||||||
|
return commandKindStandby, nil
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("unsupported write command kind %q", raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizePanelSwitch(raw string) (mk2driver.PanelSwitchState, string, error) {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(raw)) {
|
||||||
|
case "1", "charger_only", "charger-only", "charger":
|
||||||
|
return mk2driver.PanelSwitchChargerOnly, "charger_only", nil
|
||||||
|
case "2", "inverter_only", "inverter-only", "inverter":
|
||||||
|
return mk2driver.PanelSwitchInverterOnly, "inverter_only", nil
|
||||||
|
case "3", "on":
|
||||||
|
return mk2driver.PanelSwitchOn, "on", nil
|
||||||
|
case "4", "off":
|
||||||
|
return mk2driver.PanelSwitchOff, "off", nil
|
||||||
|
default:
|
||||||
|
return 0, "", fmt.Errorf("unsupported panel switch %q", raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeWriteCommand(writer mk2driver.SettingsWriter, cmd writeCommand) error {
|
||||||
|
if writer == nil {
|
||||||
|
return errors.New("settings writer is not available")
|
||||||
|
}
|
||||||
|
switch cmd.Kind {
|
||||||
|
case commandKindPanel:
|
||||||
|
if !cmd.HasSwitch {
|
||||||
|
return errors.New("panel_state command requires a switch state")
|
||||||
|
}
|
||||||
|
return writer.SetPanelState(cmd.SwitchState, cmd.CurrentLimitA)
|
||||||
|
case commandKindStandby:
|
||||||
|
if cmd.Standby == nil {
|
||||||
|
return errors.New("standby command missing standby value")
|
||||||
|
}
|
||||||
|
return writer.SetStandby(*cmd.Standby)
|
||||||
|
case commandKindRAMVar:
|
||||||
|
return writer.WriteRAMVar(cmd.ID, cmd.Value)
|
||||||
|
case commandKindSetting:
|
||||||
|
return writer.WriteSetting(cmd.ID, cmd.Value)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unsupported write command kind %q", cmd.Kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatWriteCommandLog(cmd writeCommand) string {
|
||||||
|
switch cmd.Kind {
|
||||||
|
case commandKindPanel:
|
||||||
|
switchName := cmd.SwitchName
|
||||||
|
if switchName == "" {
|
||||||
|
switchName = "<cached>"
|
||||||
|
}
|
||||||
|
if cmd.CurrentLimitA == nil {
|
||||||
|
return fmt.Sprintf("kind=%s switch=%s", cmd.Kind, switchName)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("kind=%s switch=%s current_limit=%.3f", cmd.Kind, switchName, *cmd.CurrentLimitA)
|
||||||
|
case commandKindStandby:
|
||||||
|
if cmd.Standby == nil {
|
||||||
|
return fmt.Sprintf("kind=%s standby=<unset>", cmd.Kind)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("kind=%s standby=%t", cmd.Kind, *cmd.Standby)
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("kind=%s id=%d value=%d", cmd.Kind, cmd.ID, cmd.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeInt16Value(raw json.RawMessage) (int16, error) {
|
||||||
|
if len(raw) == 0 {
|
||||||
|
return 0, errors.New(`missing required field "value"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
var value int16
|
||||||
|
if err := json.Unmarshal(raw, &value); err != nil {
|
||||||
|
return 0, fmt.Errorf(`field "value" must be a signed integer: %w`, err)
|
||||||
|
}
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeStandbyValue(msg writeCommandPayload) (bool, error) {
|
||||||
|
if msg.Standby != nil {
|
||||||
|
return *msg.Standby, nil
|
||||||
|
}
|
||||||
|
if len(msg.Value) == 0 {
|
||||||
|
return false, errors.New(`missing required field "standby" (or boolean "value")`)
|
||||||
|
}
|
||||||
|
|
||||||
|
var boolValue bool
|
||||||
|
if err := json.Unmarshal(msg.Value, &boolValue); err == nil {
|
||||||
|
return boolValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var stringValue string
|
||||||
|
if err := json.Unmarshal(msg.Value, &stringValue); err == nil {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(stringValue)) {
|
||||||
|
case "1", "true", "on", "enable", "enabled":
|
||||||
|
return true, nil
|
||||||
|
case "0", "false", "off", "disable", "disabled":
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var intValue int
|
||||||
|
if err := json.Unmarshal(msg.Value, &intValue); err == nil {
|
||||||
|
switch intValue {
|
||||||
|
case 1:
|
||||||
|
return true, nil
|
||||||
|
case 0:
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, errors.New(`field "standby" must be true/false`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func publishWriteStatus(client mqtt.Client, topic string, status writeStatus) {
|
||||||
|
if topic == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := publishJSON(client, topic, status, 1, false); err != nil {
|
||||||
|
log.Errorf("Could not publish command status to MQTT topic %q: %v", topic, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func publishHADiscovery(client mqtt.Client, config Config) error {
|
||||||
|
definitions := buildHADiscoveryDefinitions(config)
|
||||||
|
prefix := haDiscoveryPrefix(config)
|
||||||
|
nodeID := haNodeID(config)
|
||||||
|
|
||||||
|
for _, def := range definitions {
|
||||||
|
topic := fmt.Sprintf("%s/%s/%s/%s/config", prefix, def.Component, nodeID, def.ObjectID)
|
||||||
|
if err := publishJSON(client, topic, def.Config, 1, true); err != nil {
|
||||||
|
return fmt.Errorf("could not publish discovery for %s/%s: %w", def.Component, def.ObjectID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildHADiscoveryDefinitions(config Config) []haDiscoveryDefinition {
|
||||||
|
if !config.HomeAssistant.Enabled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeID := haNodeID(config)
|
||||||
|
device := map[string]any{
|
||||||
|
"identifiers": []string{fmt.Sprintf("invertergui_%s", nodeID)},
|
||||||
|
"name": haDeviceName(config),
|
||||||
|
"manufacturer": "Victron Energy",
|
||||||
|
"model": "MultiPlus",
|
||||||
|
"sw_version": "invertergui",
|
||||||
|
}
|
||||||
|
availabilityTopic := haAvailabilityTopic(config)
|
||||||
|
stateTopic := config.Topic
|
||||||
|
|
||||||
|
sensors := []haDiscoveryDefinition{
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "battery_voltage", "Battery Voltage", "{{ value_json.BatVoltage }}", "V", "voltage", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "battery_current", "Battery Current", "{{ value_json.BatCurrent }}", "A", "current", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "battery_charge", "Battery Charge", "{{ ((value_json.ChargeState | float(0)) * 100) | round(1) }}", "%", "battery", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "input_voltage", "Input Voltage", "{{ value_json.InVoltage }}", "V", "voltage", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "input_current", "Input Current", "{{ value_json.InCurrent }}", "A", "current", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "input_frequency", "Input Frequency", "{{ value_json.InFrequency }}", "Hz", "frequency", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "output_voltage", "Output Voltage", "{{ value_json.OutVoltage }}", "V", "voltage", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "output_current", "Output Current", "{{ value_json.OutCurrent }}", "A", "current", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "output_frequency", "Output Frequency", "{{ value_json.OutFrequency }}", "Hz", "frequency", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "input_power", "Input Power", "{{ ((value_json.InVoltage | float(0)) * (value_json.InCurrent | float(0))) | round(1) }}", "VA", "", "measurement"),
|
||||||
|
buildHASensor(device, availabilityTopic, stateTopic, nodeID, "output_power", "Output Power", "{{ ((value_json.OutVoltage | float(0)) * (value_json.OutCurrent | float(0))) | round(1) }}", "VA", "", "measurement"),
|
||||||
|
{
|
||||||
|
Component: "binary_sensor",
|
||||||
|
ObjectID: "data_valid",
|
||||||
|
Config: map[string]any{
|
||||||
|
"name": "Data Valid",
|
||||||
|
"unique_id": fmt.Sprintf("%s_data_valid", nodeID),
|
||||||
|
"state_topic": stateTopic,
|
||||||
|
"value_template": "{{ value_json.Valid }}",
|
||||||
|
"payload_on": "true",
|
||||||
|
"payload_off": "false",
|
||||||
|
"availability_topic": availabilityTopic,
|
||||||
|
"device": device,
|
||||||
|
"entity_category": "diagnostic",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.CommandTopic != "" {
|
||||||
|
sensors = append(sensors,
|
||||||
|
haDiscoveryDefinition{
|
||||||
|
Component: "select",
|
||||||
|
ObjectID: "remote_panel_mode",
|
||||||
|
Config: map[string]any{
|
||||||
|
"name": "Remote Panel Mode",
|
||||||
|
"unique_id": fmt.Sprintf("%s_remote_panel_mode", nodeID),
|
||||||
|
"state_topic": haPanelSwitchStateTopic(config),
|
||||||
|
"command_topic": config.CommandTopic,
|
||||||
|
"command_template": "{\"kind\":\"panel_state\",\"switch\":\"{{ value }}\"}",
|
||||||
|
"options": []string{"charger_only", "inverter_only", "on", "off"},
|
||||||
|
"availability_topic": availabilityTopic,
|
||||||
|
"device": device,
|
||||||
|
"icon": "mdi:transmission-tower-export",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
haDiscoveryDefinition{
|
||||||
|
Component: "number",
|
||||||
|
ObjectID: "remote_panel_current_limit",
|
||||||
|
Config: map[string]any{
|
||||||
|
"name": "Remote Panel Current Limit",
|
||||||
|
"unique_id": fmt.Sprintf("%s_remote_panel_current_limit", nodeID),
|
||||||
|
"state_topic": haCurrentLimitStateTopic(config),
|
||||||
|
"command_topic": config.CommandTopic,
|
||||||
|
"command_template": "{\"kind\":\"panel_state\",\"current_limit\":{{ value | float(0) }}}",
|
||||||
|
"unit_of_measurement": "A",
|
||||||
|
"device_class": "current",
|
||||||
|
"mode": "box",
|
||||||
|
"min": 0,
|
||||||
|
"max": 100,
|
||||||
|
"step": 0.1,
|
||||||
|
"availability_topic": availabilityTopic,
|
||||||
|
"device": device,
|
||||||
|
"icon": "mdi:current-ac",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
haDiscoveryDefinition{
|
||||||
|
Component: "switch",
|
||||||
|
ObjectID: "remote_panel_standby",
|
||||||
|
Config: map[string]any{
|
||||||
|
"name": "Remote Panel Standby",
|
||||||
|
"unique_id": fmt.Sprintf("%s_remote_panel_standby", nodeID),
|
||||||
|
"state_topic": haStandbyStateTopic(config),
|
||||||
|
"command_topic": config.CommandTopic,
|
||||||
|
"payload_on": "{\"kind\":\"standby\",\"standby\":true}",
|
||||||
|
"payload_off": "{\"kind\":\"standby\",\"standby\":false}",
|
||||||
|
"state_on": "ON",
|
||||||
|
"state_off": "OFF",
|
||||||
|
"availability_topic": availabilityTopic,
|
||||||
|
"device": device,
|
||||||
|
"icon": "mdi:power-sleep",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return sensors
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildHASensor(device map[string]any, availabilityTopic, stateTopic, nodeID, objectID, name, valueTemplate, unit, deviceClass, stateClass string) haDiscoveryDefinition {
|
||||||
|
config := map[string]any{
|
||||||
|
"name": name,
|
||||||
|
"unique_id": fmt.Sprintf("%s_%s", nodeID, objectID),
|
||||||
|
"state_topic": stateTopic,
|
||||||
|
"value_template": valueTemplate,
|
||||||
|
"availability_topic": availabilityTopic,
|
||||||
|
"device": device,
|
||||||
|
}
|
||||||
|
if unit != "" {
|
||||||
|
config["unit_of_measurement"] = unit
|
||||||
|
}
|
||||||
|
if deviceClass != "" {
|
||||||
|
config["device_class"] = deviceClass
|
||||||
|
}
|
||||||
|
if stateClass != "" {
|
||||||
|
config["state_class"] = stateClass
|
||||||
|
}
|
||||||
|
|
||||||
|
return haDiscoveryDefinition{
|
||||||
|
Component: "sensor",
|
||||||
|
ObjectID: objectID,
|
||||||
|
Config: config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func publishHAAvailability(client mqtt.Client, config Config, status string) error {
|
||||||
|
return publishString(client, haAvailabilityTopic(config), status, 1, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func publishHAControlState(client mqtt.Client, config Config, cmd writeCommand) error {
|
||||||
|
switch cmd.Kind {
|
||||||
|
case commandKindPanel:
|
||||||
|
if err := publishString(client, haPanelSwitchStateTopic(config), cmd.SwitchName, 1, true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if cmd.CurrentLimitA != nil {
|
||||||
|
limit := strconv.FormatFloat(*cmd.CurrentLimitA, 'f', 1, 64)
|
||||||
|
if err := publishString(client, haCurrentLimitStateTopic(config), limit, 1, true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case commandKindStandby:
|
||||||
|
if cmd.Standby == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
state := "OFF"
|
||||||
|
if *cmd.Standby {
|
||||||
|
state = "ON"
|
||||||
|
}
|
||||||
|
if err := publishString(client, haStandbyStateTopic(config), state, 1, true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func publishJSON(client mqtt.Client, topic string, payload any, qos byte, retained bool) error {
|
||||||
|
if topic == "" {
|
||||||
|
return errors.New("topic is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not marshal payload: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t := client.Publish(topic, qos, retained, data)
|
||||||
|
t.Wait()
|
||||||
|
if t.Error() != nil {
|
||||||
|
return t.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func publishString(client mqtt.Client, topic, payload string, qos byte, retained bool) error {
|
||||||
|
if topic == "" {
|
||||||
|
return errors.New("topic is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
t := client.Publish(topic, qos, retained, payload)
|
||||||
|
t.Wait()
|
||||||
|
if t.Error() != nil {
|
||||||
|
return t.Error()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mqttTopicRoot(topic string) string {
|
||||||
|
t := strings.Trim(strings.TrimSpace(topic), "/")
|
||||||
|
if t == "" {
|
||||||
|
return "invertergui"
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(t, "/updates") {
|
||||||
|
root := strings.TrimSuffix(t, "/updates")
|
||||||
|
if root != "" {
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func haAvailabilityTopic(config Config) string {
|
||||||
|
return fmt.Sprintf("%s/homeassistant/availability", mqttTopicRoot(config.Topic))
|
||||||
|
}
|
||||||
|
|
||||||
|
func haPanelSwitchStateTopic(config Config) string {
|
||||||
|
return fmt.Sprintf("%s/homeassistant/remote_panel_mode/state", mqttTopicRoot(config.Topic))
|
||||||
|
}
|
||||||
|
|
||||||
|
func haCurrentLimitStateTopic(config Config) string {
|
||||||
|
return fmt.Sprintf("%s/homeassistant/remote_panel_current_limit/state", mqttTopicRoot(config.Topic))
|
||||||
|
}
|
||||||
|
|
||||||
|
func haStandbyStateTopic(config Config) string {
|
||||||
|
return fmt.Sprintf("%s/homeassistant/remote_panel_standby/state", mqttTopicRoot(config.Topic))
|
||||||
|
}
|
||||||
|
|
||||||
|
func haDiscoveryPrefix(config Config) string {
|
||||||
|
prefix := strings.Trim(strings.TrimSpace(config.HomeAssistant.DiscoveryPrefix), "/")
|
||||||
|
if prefix == "" {
|
||||||
|
return "homeassistant"
|
||||||
|
}
|
||||||
|
return prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
func haNodeID(config Config) string {
|
||||||
|
nodeID := normalizeID(config.HomeAssistant.NodeID)
|
||||||
|
if nodeID == "" {
|
||||||
|
nodeID = normalizeID(config.ClientID)
|
||||||
|
}
|
||||||
|
if nodeID == "" {
|
||||||
|
return "invertergui"
|
||||||
|
}
|
||||||
|
return nodeID
|
||||||
|
}
|
||||||
|
|
||||||
|
func haDeviceName(config Config) string {
|
||||||
|
name := strings.TrimSpace(config.HomeAssistant.DeviceName)
|
||||||
|
if name == "" {
|
||||||
|
return "Victron Inverter"
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeID(in string) string {
|
||||||
|
trimmed := strings.TrimSpace(strings.ToLower(in))
|
||||||
|
if trimmed == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
var b strings.Builder
|
||||||
|
lastUnderscore := false
|
||||||
|
for _, r := range trimmed {
|
||||||
|
valid := (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '-' || r == '_'
|
||||||
|
if valid {
|
||||||
|
b.WriteRune(r)
|
||||||
|
lastUnderscore = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !lastUnderscore {
|
||||||
|
b.WriteRune('_')
|
||||||
|
lastUnderscore = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Trim(b.String(), "_")
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyBoolPtr(in *bool) *bool {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
value := *in
|
||||||
|
return &value
|
||||||
|
}
|
||||||
|
|
||||||
func getOpts(config Config) *mqtt.ClientOptions {
|
func getOpts(config Config) *mqtt.ClientOptions {
|
||||||
opts := mqtt.NewClientOptions()
|
opts := mqtt.NewClientOptions()
|
||||||
opts.AddBroker(config.Broker)
|
opts.AddBroker(config.Broker)
|
||||||
@@ -60,14 +781,16 @@ func getOpts(config Config) *mqtt.ClientOptions {
|
|||||||
if config.Password != "" {
|
if config.Password != "" {
|
||||||
opts.SetPassword(config.Password)
|
opts.SetPassword(config.Password)
|
||||||
}
|
}
|
||||||
|
if config.HomeAssistant.Enabled {
|
||||||
|
opts.SetWill(haAvailabilityTopic(config), "offline", 1, true)
|
||||||
|
}
|
||||||
opts.SetKeepAlive(keepAlive)
|
opts.SetKeepAlive(keepAlive)
|
||||||
|
|
||||||
opts.SetOnConnectHandler(func(mqtt.Client) {
|
opts.SetOnConnectHandler(func(mqtt.Client) {
|
||||||
log.Info("Client connected to broker")
|
log.Info("Client connected to broker")
|
||||||
})
|
})
|
||||||
opts.SetConnectionLostHandler(func(cli mqtt.Client, err error) {
|
opts.SetConnectionLostHandler(func(_ mqtt.Client, err error) {
|
||||||
log.Errorf("Client connection to broker lost: %v", err)
|
log.Errorf("Client connection to broker lost: %v", err)
|
||||||
|
|
||||||
})
|
})
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|||||||
316
plugins/mqttclient/mqtt_test.go
Normal file
316
plugins/mqttclient/mqtt_test.go
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
package mqttclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"invertergui/mk2driver"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
type fakeWriter struct {
|
||||||
|
lastKind string
|
||||||
|
lastID uint16
|
||||||
|
lastValue int16
|
||||||
|
lastSwitchState mk2driver.PanelSwitchState
|
||||||
|
lastCurrentLimit *float64
|
||||||
|
lastStandby *bool
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeWriter) WriteRAMVar(id uint16, value int16) error {
|
||||||
|
f.lastKind = commandKindRAMVar
|
||||||
|
f.lastID = id
|
||||||
|
f.lastValue = value
|
||||||
|
return f.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeWriter) WriteSetting(id uint16, value int16) error {
|
||||||
|
f.lastKind = commandKindSetting
|
||||||
|
f.lastID = id
|
||||||
|
f.lastValue = value
|
||||||
|
return f.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeWriter) SetPanelState(switchState mk2driver.PanelSwitchState, currentLimitA *float64) error {
|
||||||
|
f.lastKind = commandKindPanel
|
||||||
|
f.lastSwitchState = switchState
|
||||||
|
f.lastCurrentLimit = currentLimitA
|
||||||
|
return f.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeWriter) SetStandby(standby bool) error {
|
||||||
|
f.lastKind = commandKindStandby
|
||||||
|
f.lastStandby = &standby
|
||||||
|
return f.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_decodeWriteCommand(t *testing.T) {
|
||||||
|
currentLimit := 16.5
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
payload string
|
||||||
|
check func(*testing.T, writeCommand)
|
||||||
|
wantErr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "setting",
|
||||||
|
payload: `{"request_id":"abc","kind":"setting","id":15,"value":-5}`,
|
||||||
|
check: func(t *testing.T, got writeCommand) {
|
||||||
|
assert.Equal(t, writeCommand{
|
||||||
|
RequestID: "abc",
|
||||||
|
Kind: commandKindSetting,
|
||||||
|
ID: 15,
|
||||||
|
Value: -5,
|
||||||
|
}, got)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ram_var alias from type",
|
||||||
|
payload: `{"type":"ramvar","id":2,"value":7}`,
|
||||||
|
check: func(t *testing.T, got writeCommand) {
|
||||||
|
assert.Equal(t, writeCommand{
|
||||||
|
Kind: commandKindRAMVar,
|
||||||
|
ID: 2,
|
||||||
|
Value: 7,
|
||||||
|
}, got)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "panel state",
|
||||||
|
payload: `{"kind":"panel_state","switch":"on","current_limit":16.5}`,
|
||||||
|
check: func(t *testing.T, got writeCommand) {
|
||||||
|
assert.Equal(t, commandKindPanel, got.Kind)
|
||||||
|
assert.True(t, got.HasSwitch)
|
||||||
|
assert.Equal(t, mk2driver.PanelSwitchOn, got.SwitchState)
|
||||||
|
assert.Equal(t, "on", got.SwitchName)
|
||||||
|
if assert.NotNil(t, got.CurrentLimitA) {
|
||||||
|
assert.Equal(t, currentLimit, *got.CurrentLimitA)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "panel current limit only",
|
||||||
|
payload: `{"kind":"panel_state","current_limit":12.0}`,
|
||||||
|
check: func(t *testing.T, got writeCommand) {
|
||||||
|
assert.Equal(t, commandKindPanel, got.Kind)
|
||||||
|
assert.False(t, got.HasSwitch)
|
||||||
|
assert.Nil(t, got.Standby)
|
||||||
|
if assert.NotNil(t, got.CurrentLimitA) {
|
||||||
|
assert.Equal(t, 12.0, *got.CurrentLimitA)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "standby bool",
|
||||||
|
payload: `{"kind":"standby","standby":true}`,
|
||||||
|
check: func(t *testing.T, got writeCommand) {
|
||||||
|
assert.Equal(t, commandKindStandby, got.Kind)
|
||||||
|
if assert.NotNil(t, got.Standby) {
|
||||||
|
assert.True(t, *got.Standby)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "standby using value string",
|
||||||
|
payload: `{"kind":"standby","value":"OFF"}`,
|
||||||
|
check: func(t *testing.T, got writeCommand) {
|
||||||
|
assert.Equal(t, commandKindStandby, got.Kind)
|
||||||
|
if assert.NotNil(t, got.Standby) {
|
||||||
|
assert.False(t, *got.Standby)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing id",
|
||||||
|
payload: `{"kind":"setting","value":1}`,
|
||||||
|
wantErr: `missing required field "id"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing panel switch and current limit",
|
||||||
|
payload: `{"kind":"panel_state"}`,
|
||||||
|
wantErr: `missing required field "switch"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid standby",
|
||||||
|
payload: `{"kind":"standby","value":"banana"}`,
|
||||||
|
wantErr: `field "standby" must be true/false`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid kind",
|
||||||
|
payload: `{"kind":"unknown","id":1,"value":1}`,
|
||||||
|
wantErr: `unsupported write command kind "unknown"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := decodeWriteCommand([]byte(tt.payload))
|
||||||
|
if tt.wantErr != "" {
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.ErrorContains(t, err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
tt.check(t, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_executeWriteCommand(t *testing.T) {
|
||||||
|
limit := 8.0
|
||||||
|
standby := true
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
cmd writeCommand
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "setting",
|
||||||
|
cmd: writeCommand{
|
||||||
|
Kind: commandKindSetting,
|
||||||
|
ID: 9,
|
||||||
|
Value: 2,
|
||||||
|
},
|
||||||
|
want: commandKindSetting,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ram_var",
|
||||||
|
cmd: writeCommand{
|
||||||
|
Kind: commandKindRAMVar,
|
||||||
|
ID: 3,
|
||||||
|
Value: -1,
|
||||||
|
},
|
||||||
|
want: commandKindRAMVar,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "panel_state",
|
||||||
|
cmd: writeCommand{
|
||||||
|
Kind: commandKindPanel,
|
||||||
|
HasSwitch: true,
|
||||||
|
SwitchState: mk2driver.PanelSwitchInverterOnly,
|
||||||
|
CurrentLimitA: &limit,
|
||||||
|
},
|
||||||
|
want: commandKindPanel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "standby",
|
||||||
|
cmd: writeCommand{
|
||||||
|
Kind: commandKindStandby,
|
||||||
|
Standby: &standby,
|
||||||
|
},
|
||||||
|
want: commandKindStandby,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
writer := &fakeWriter{}
|
||||||
|
err := executeWriteCommand(writer, tt.cmd)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, tt.want, writer.lastKind)
|
||||||
|
switch tt.want {
|
||||||
|
case commandKindPanel:
|
||||||
|
assert.Equal(t, tt.cmd.SwitchState, writer.lastSwitchState)
|
||||||
|
if assert.NotNil(t, writer.lastCurrentLimit) {
|
||||||
|
assert.Equal(t, *tt.cmd.CurrentLimitA, *writer.lastCurrentLimit)
|
||||||
|
}
|
||||||
|
case commandKindStandby:
|
||||||
|
if assert.NotNil(t, writer.lastStandby) {
|
||||||
|
assert.Equal(t, *tt.cmd.Standby, *writer.lastStandby)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
assert.Equal(t, tt.cmd.ID, writer.lastID)
|
||||||
|
assert.Equal(t, tt.cmd.Value, writer.lastValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_buildHADiscoveryDefinitions(t *testing.T) {
|
||||||
|
cfg := Config{
|
||||||
|
Topic: "invertergui/updates",
|
||||||
|
CommandTopic: "invertergui/settings/set",
|
||||||
|
HomeAssistant: HomeAssistantConfig{
|
||||||
|
Enabled: true,
|
||||||
|
DiscoveryPrefix: "homeassistant",
|
||||||
|
NodeID: "victron_main",
|
||||||
|
DeviceName: "Shed Victron",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
definitions := buildHADiscoveryDefinitions(cfg)
|
||||||
|
assert.NotEmpty(t, definitions)
|
||||||
|
|
||||||
|
var panelMode *haDiscoveryDefinition
|
||||||
|
var panelCurrentLimit *haDiscoveryDefinition
|
||||||
|
var panelStandby *haDiscoveryDefinition
|
||||||
|
var batteryVoltage *haDiscoveryDefinition
|
||||||
|
for i := range definitions {
|
||||||
|
def := &definitions[i]
|
||||||
|
if def.Component == "select" && def.ObjectID == "remote_panel_mode" {
|
||||||
|
panelMode = def
|
||||||
|
}
|
||||||
|
if def.Component == "number" && def.ObjectID == "remote_panel_current_limit" {
|
||||||
|
panelCurrentLimit = def
|
||||||
|
}
|
||||||
|
if def.Component == "switch" && def.ObjectID == "remote_panel_standby" {
|
||||||
|
panelStandby = def
|
||||||
|
}
|
||||||
|
if def.Component == "sensor" && def.ObjectID == "battery_voltage" {
|
||||||
|
batteryVoltage = def
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if assert.NotNil(t, panelMode) {
|
||||||
|
assert.Equal(t, cfg.CommandTopic, panelMode.Config["command_topic"])
|
||||||
|
assert.Equal(t, haPanelSwitchStateTopic(cfg), panelMode.Config["state_topic"])
|
||||||
|
}
|
||||||
|
if assert.NotNil(t, panelCurrentLimit) {
|
||||||
|
assert.Equal(t, cfg.CommandTopic, panelCurrentLimit.Config["command_topic"])
|
||||||
|
assert.Equal(t, haCurrentLimitStateTopic(cfg), panelCurrentLimit.Config["state_topic"])
|
||||||
|
}
|
||||||
|
if assert.NotNil(t, panelStandby) {
|
||||||
|
assert.Equal(t, cfg.CommandTopic, panelStandby.Config["command_topic"])
|
||||||
|
assert.Equal(t, haStandbyStateTopic(cfg), panelStandby.Config["state_topic"])
|
||||||
|
}
|
||||||
|
if assert.NotNil(t, batteryVoltage) {
|
||||||
|
assert.Equal(t, cfg.Topic, batteryVoltage.Config["state_topic"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_panelStateCacheResolvePanelCommand(t *testing.T) {
|
||||||
|
cache := &panelStateCache{}
|
||||||
|
|
||||||
|
_, err := cache.resolvePanelCommand(writeCommand{
|
||||||
|
Kind: commandKindPanel,
|
||||||
|
CurrentLimitA: float64Ptr(12),
|
||||||
|
})
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
cache.remember(writeCommand{
|
||||||
|
Kind: commandKindPanel,
|
||||||
|
HasSwitch: true,
|
||||||
|
SwitchState: mk2driver.PanelSwitchOn,
|
||||||
|
SwitchName: "on",
|
||||||
|
})
|
||||||
|
|
||||||
|
resolved, err := cache.resolvePanelCommand(writeCommand{
|
||||||
|
Kind: commandKindPanel,
|
||||||
|
CurrentLimitA: float64Ptr(10),
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, resolved.HasSwitch)
|
||||||
|
assert.Equal(t, mk2driver.PanelSwitchOn, resolved.SwitchState)
|
||||||
|
assert.Equal(t, "on", resolved.SwitchName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func float64Ptr(in float64) *float64 {
|
||||||
|
return &in
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_normalizeID(t *testing.T) {
|
||||||
|
assert.Equal(t, "victron_main_01", normalizeID("Victron Main #01"))
|
||||||
|
assert.Equal(t, "inverter-gui", normalizeID(" inverter-gui "))
|
||||||
|
assert.Equal(t, "", normalizeID(" "))
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ func NewMunin(mk2 mk2driver.Mk2) *Munin {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Munin) ServeMuninHTTP(rw http.ResponseWriter, r *http.Request) {
|
func (m *Munin) ServeMuninHTTP(rw http.ResponseWriter, _ *http.Request) {
|
||||||
muninDat := <-m.muninResponse
|
muninDat := <-m.muninResponse
|
||||||
if muninDat.timesUpdated == 0 {
|
if muninDat.timesUpdated == 0 {
|
||||||
log.Error("No data returned")
|
log.Error("No data returned")
|
||||||
@@ -103,7 +103,7 @@ func (m *Munin) ServeMuninHTTP(rw http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Munin) ServeMuninConfigHTTP(rw http.ResponseWriter, r *http.Request) {
|
func (m *Munin) ServeMuninConfigHTTP(rw http.ResponseWriter, _ *http.Request) {
|
||||||
output := muninConfig
|
output := muninConfig
|
||||||
_, err := rw.Write([]byte(output))
|
_, err := rw.Write([]byte(output))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -127,7 +127,7 @@ func (m *Munin) run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Munin only samples once every 5 minutes so averages have to be calculated for some values.
|
// Munin only samples once every 5 minutes so averages have to be calculated for some values.
|
||||||
func calcMuninValues(m *muninData, newStatus *mk2driver.Mk2Info) {
|
func calcMuninValues(m *muninData, newStatus *mk2driver.Mk2Info) {
|
||||||
m.timesUpdated++
|
m.timesUpdated++
|
||||||
m.status.OutCurrent += newStatus.OutCurrent
|
m.status.OutCurrent += newStatus.OutCurrent
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package munin
|
package munin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServer(t *testing.T) {
|
func TestServer(_ *testing.T) {
|
||||||
|
|
||||||
mockMk2 := mk2driver.NewMk2Mock()
|
mockMk2 := mk2driver.NewMk2Mock()
|
||||||
muninServer := NewMunin(mockMk2)
|
muninServer := NewMunin(mockMk2)
|
||||||
@@ -21,7 +21,7 @@ func TestServer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
_, err = ioutil.ReadAll(res.Body)
|
_, err = io.ReadAll(res.Body)
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
package prometheus
|
package prometheus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,117 @@
|
|||||||
<div class="alert alert-danger" role="alert" v-if="error.has_error">
|
<div class="alert alert-danger" role="alert" v-if="error.has_error">
|
||||||
{{ error.error_message }}
|
{{ error.error_message }}
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
class="alert"
|
||||||
|
v-if="control.message !== ''"
|
||||||
|
v-bind:class="[control.has_error ? 'alert-danger' : 'alert-success']"
|
||||||
|
>
|
||||||
|
{{ control.message }}
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-body">
|
||||||
|
<h4 class="card-title">Remote Panel Control</h4>
|
||||||
|
<p class="text-muted mb-2">
|
||||||
|
Mode and current limit are applied together, equivalent to
|
||||||
|
<code>set_remote_panel_state</code>.
|
||||||
|
</p>
|
||||||
|
<p class="mb-1">
|
||||||
|
<strong>Current Mode:</strong>
|
||||||
|
{{ remoteModeLabel(state.remote_panel) }}
|
||||||
|
</p>
|
||||||
|
<p class="mb-1">
|
||||||
|
<strong>Current Limit:</strong>
|
||||||
|
{{ state.remote_panel.current_limit === null || state.remote_panel.current_limit === undefined ? 'Unknown' : state.remote_panel.current_limit + ' A' }}
|
||||||
|
</p>
|
||||||
|
<p class="mb-3">
|
||||||
|
<strong>Standby:</strong>
|
||||||
|
{{ remoteStandbyLabel(state.remote_panel) }}
|
||||||
|
</p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<form v-on:submit.prevent="applyRemotePanelState">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label for="modeSelect">Remote Panel Mode</label>
|
||||||
|
<select
|
||||||
|
class="form-control"
|
||||||
|
id="modeSelect"
|
||||||
|
v-model="remote_form.mode"
|
||||||
|
v-bind:disabled="!state.remote_panel.writable || control.busy"
|
||||||
|
>
|
||||||
|
<option value="on">on</option>
|
||||||
|
<option value="off">off</option>
|
||||||
|
<option value="charger_only">charger_only</option>
|
||||||
|
<option value="inverter_only">inverter_only</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label for="currentLimitInput">AC Input Current Limit (A)</label>
|
||||||
|
<input
|
||||||
|
id="currentLimitInput"
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="0.1"
|
||||||
|
class="form-control"
|
||||||
|
v-model="remote_form.current_limit"
|
||||||
|
placeholder="leave blank to keep current"
|
||||||
|
v-bind:disabled="!state.remote_panel.writable || control.busy"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-primary"
|
||||||
|
v-bind:disabled="!state.remote_panel.writable || control.busy"
|
||||||
|
>
|
||||||
|
Apply Mode + Current Limit
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form v-on:submit.prevent="applyStandby">
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="form-check mt-4">
|
||||||
|
<input
|
||||||
|
id="standbySwitch"
|
||||||
|
type="checkbox"
|
||||||
|
class="form-check-input"
|
||||||
|
v-model="remote_form.standby"
|
||||||
|
v-bind:disabled="!state.remote_panel.writable || control.busy"
|
||||||
|
/>
|
||||||
|
<label class="form-check-label" for="standbySwitch">
|
||||||
|
Prevent sleep while off
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-secondary"
|
||||||
|
v-bind:disabled="!state.remote_panel.writable || control.busy"
|
||||||
|
>
|
||||||
|
Apply Standby
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 text-muted" v-if="state.remote_panel.last_updated">
|
||||||
|
Last update {{ state.remote_panel.last_updated }}
|
||||||
|
<span v-if="state.remote_panel.last_command">
|
||||||
|
({{ state.remote_panel.last_command }})
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="mt-2 text-danger" v-if="state.remote_panel.last_error">
|
||||||
|
{{ state.remote_panel.last_error }}
|
||||||
|
</div>
|
||||||
|
<div class="mt-2 text-warning" v-if="!state.remote_panel.writable">
|
||||||
|
Remote control is unavailable for this data source.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<hr />
|
<hr />
|
||||||
|
|||||||
@@ -3,15 +3,20 @@ const timeoutMax = 30000;
|
|||||||
const timeoutMin = 1000;
|
const timeoutMin = 1000;
|
||||||
var timeout = timeoutMin;
|
var timeout = timeoutMin;
|
||||||
|
|
||||||
function loadContent() {
|
function defaultRemotePanelState() {
|
||||||
app = new Vue({
|
return {
|
||||||
el: "#app",
|
writable: false,
|
||||||
data: {
|
mode: "unknown",
|
||||||
error: {
|
current_limit: null,
|
||||||
has_error: false,
|
standby: null,
|
||||||
error_message: ""
|
last_command: "",
|
||||||
},
|
last_error: "",
|
||||||
state: {
|
last_updated: ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultState() {
|
||||||
|
return {
|
||||||
output_current: null,
|
output_current: null,
|
||||||
output_voltage: 0,
|
output_voltage: 0,
|
||||||
output_frequency: 0,
|
output_frequency: 0,
|
||||||
@@ -24,20 +29,194 @@ function loadContent() {
|
|||||||
battery_voltage: 0,
|
battery_voltage: 0,
|
||||||
battery_charge: 0,
|
battery_charge: 0,
|
||||||
battery_power: 0,
|
battery_power: 0,
|
||||||
led_map: [
|
led_map: {
|
||||||
{ led_mains: "dot-off" },
|
led_mains: "dot-off",
|
||||||
{ led_absorb: "dot-off" },
|
led_absorb: "dot-off",
|
||||||
{ led_bulk: "dot-off" },
|
led_bulk: "dot-off",
|
||||||
{ led_float: "dot-off" },
|
led_float: "dot-off",
|
||||||
{ led_inverter: "dot-off" },
|
led_inverter: "dot-off",
|
||||||
{ led_overload: "dot-off" },
|
led_overload: "dot-off",
|
||||||
{ led_bat_low: "dot-off" },
|
led_bat_low: "dot-off",
|
||||||
{ led_over_temp: "dot-off" }
|
led_over_temp: "dot-off"
|
||||||
]
|
},
|
||||||
|
remote_panel: defaultRemotePanelState()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadContent() {
|
||||||
|
app = new Vue({
|
||||||
|
el: "#app",
|
||||||
|
data: {
|
||||||
|
error: {
|
||||||
|
has_error: false,
|
||||||
|
error_message: ""
|
||||||
|
},
|
||||||
|
control: {
|
||||||
|
busy: false,
|
||||||
|
has_error: false,
|
||||||
|
message: ""
|
||||||
|
},
|
||||||
|
remote_form: {
|
||||||
|
mode: "on",
|
||||||
|
current_limit: "",
|
||||||
|
standby: false
|
||||||
|
},
|
||||||
|
state: defaultState()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
syncRemoteFormFromState: function(remoteState) {
|
||||||
|
if (!remoteState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (remoteState.mode && remoteState.mode !== "unknown") {
|
||||||
|
this.remote_form.mode = remoteState.mode;
|
||||||
|
}
|
||||||
|
if (remoteState.current_limit === null || remoteState.current_limit === undefined) {
|
||||||
|
this.remote_form.current_limit = "";
|
||||||
|
} else {
|
||||||
|
this.remote_form.current_limit = String(remoteState.current_limit);
|
||||||
|
}
|
||||||
|
if (remoteState.standby === null || remoteState.standby === undefined) {
|
||||||
|
this.remote_form.standby = false;
|
||||||
|
} else {
|
||||||
|
this.remote_form.standby = !!remoteState.standby;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
remoteModeLabel: function(remoteState) {
|
||||||
|
var mode = (remoteState && remoteState.mode) || "unknown";
|
||||||
|
if (mode === "charger_only") {
|
||||||
|
return "Charger Only";
|
||||||
|
}
|
||||||
|
if (mode === "inverter_only") {
|
||||||
|
return "Inverter Only";
|
||||||
|
}
|
||||||
|
if (mode === "on") {
|
||||||
|
return "On";
|
||||||
|
}
|
||||||
|
if (mode === "off") {
|
||||||
|
return "Off";
|
||||||
|
}
|
||||||
|
return "Unknown";
|
||||||
|
},
|
||||||
|
remoteStandbyLabel: function(remoteState) {
|
||||||
|
if (!remoteState || remoteState.standby === null || remoteState.standby === undefined) {
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
return remoteState.standby ? "Enabled" : "Disabled";
|
||||||
|
},
|
||||||
|
refreshRemoteState: function() {
|
||||||
|
var self = this;
|
||||||
|
fetch(getAPIURI("api/remote-panel/state"))
|
||||||
|
.then(function(resp) {
|
||||||
|
if (!resp.ok) {
|
||||||
|
throw new Error("Could not load remote panel state.");
|
||||||
|
}
|
||||||
|
return resp.json();
|
||||||
|
})
|
||||||
|
.then(function(payload) {
|
||||||
|
self.state.remote_panel = payload;
|
||||||
|
self.syncRemoteFormFromState(payload);
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
self.control.has_error = true;
|
||||||
|
self.control.message = err.message;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
applyRemotePanelState: function() {
|
||||||
|
var self = this;
|
||||||
|
if (!self.state.remote_panel.writable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var body = {
|
||||||
|
mode: self.remote_form.mode
|
||||||
|
};
|
||||||
|
if (self.remote_form.current_limit !== "") {
|
||||||
|
var parsed = parseFloat(self.remote_form.current_limit);
|
||||||
|
if (isNaN(parsed)) {
|
||||||
|
self.control.has_error = true;
|
||||||
|
self.control.message = "Current limit must be numeric.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
body.current_limit = parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.control.busy = true;
|
||||||
|
self.control.has_error = false;
|
||||||
|
self.control.message = "";
|
||||||
|
fetch(getAPIURI("api/remote-panel/state"), {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
})
|
||||||
|
.then(function(resp) {
|
||||||
|
if (!resp.ok) {
|
||||||
|
return resp.text().then(function(text) {
|
||||||
|
throw new Error(text || "Failed to set remote panel mode/current limit.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return resp.json();
|
||||||
|
})
|
||||||
|
.then(function(payload) {
|
||||||
|
self.state.remote_panel = payload;
|
||||||
|
self.syncRemoteFormFromState(payload);
|
||||||
|
self.control.has_error = false;
|
||||||
|
self.control.message = "Remote panel state updated.";
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
self.control.has_error = true;
|
||||||
|
self.control.message = err.message;
|
||||||
|
})
|
||||||
|
.finally(function() {
|
||||||
|
self.control.busy = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
applyStandby: function() {
|
||||||
|
var self = this;
|
||||||
|
if (!self.state.remote_panel.writable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.control.busy = true;
|
||||||
|
self.control.has_error = false;
|
||||||
|
self.control.message = "";
|
||||||
|
fetch(getAPIURI("api/remote-panel/standby"), {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
standby: !!self.remote_form.standby
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(function(resp) {
|
||||||
|
if (!resp.ok) {
|
||||||
|
return resp.text().then(function(text) {
|
||||||
|
throw new Error(text || "Failed to set standby mode.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return resp.json();
|
||||||
|
})
|
||||||
|
.then(function(payload) {
|
||||||
|
self.state.remote_panel = payload;
|
||||||
|
self.syncRemoteFormFromState(payload);
|
||||||
|
self.control.has_error = false;
|
||||||
|
self.control.message = "Standby mode updated.";
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
self.control.has_error = true;
|
||||||
|
self.control.message = err.message;
|
||||||
|
})
|
||||||
|
.finally(function() {
|
||||||
|
self.control.busy = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.refreshRemoteState();
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +240,7 @@ function connect() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
conn.onopen = function(evt) {
|
conn.onopen = function() {
|
||||||
timeout = timeoutMin;
|
timeout = timeoutMin;
|
||||||
app.error.has_error = false;
|
app.error.has_error = false;
|
||||||
};
|
};
|
||||||
@@ -69,6 +248,9 @@ function connect() {
|
|||||||
conn.onmessage = function(evt) {
|
conn.onmessage = function(evt) {
|
||||||
var update = JSON.parse(evt.data);
|
var update = JSON.parse(evt.data);
|
||||||
app.state = update;
|
app.state = update;
|
||||||
|
if (!app.control.busy) {
|
||||||
|
app.syncRemoteFormFromState(update.remote_panel);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
app.error.has_error = true;
|
app.error.has_error = true;
|
||||||
@@ -88,3 +270,11 @@ function getURI() {
|
|||||||
new_uri += loc.pathname + "ws";
|
new_uri += loc.pathname + "ws";
|
||||||
return new_uri;
|
return new_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAPIURI(path) {
|
||||||
|
var base = window.location.pathname;
|
||||||
|
if (base.slice(-1) !== "/") {
|
||||||
|
base += "/";
|
||||||
|
}
|
||||||
|
return base + path.replace(/^\/+/, "");
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,13 +31,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
package webui
|
package webui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
"github.com/diebietse/invertergui/websocket"
|
"invertergui/websocket"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,25 +53,53 @@ const (
|
|||||||
BlinkGreen = "blink-green"
|
BlinkGreen = "blink-green"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
modeChargerOnly = "charger_only"
|
||||||
|
modeInverterOnly = "inverter_only"
|
||||||
|
modeOn = "on"
|
||||||
|
modeOff = "off"
|
||||||
|
modeUnknown = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
type WebGui struct {
|
type WebGui struct {
|
||||||
mk2driver.Mk2
|
mk2driver.Mk2
|
||||||
|
writer mk2driver.SettingsWriter
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
hub *websocket.Hub
|
hub *websocket.Hub
|
||||||
|
|
||||||
|
stateMu sync.RWMutex
|
||||||
|
latest *templateInput
|
||||||
|
remote remotePanelState
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebGui(source mk2driver.Mk2) *WebGui {
|
func NewWebGui(source mk2driver.Mk2, writer mk2driver.SettingsWriter) *WebGui {
|
||||||
w := &WebGui{
|
w := &WebGui{
|
||||||
stopChan: make(chan struct{}),
|
stopChan: make(chan struct{}),
|
||||||
Mk2: source,
|
Mk2: source,
|
||||||
|
writer: writer,
|
||||||
hub: websocket.NewHub(),
|
hub: websocket.NewHub(),
|
||||||
|
remote: remotePanelState{
|
||||||
|
Writable: writer != nil,
|
||||||
|
Mode: modeUnknown,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
w.wg.Add(1)
|
w.wg.Add(1)
|
||||||
go w.dataPoll()
|
go w.dataPoll()
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type remotePanelState struct {
|
||||||
|
Writable bool `json:"writable"`
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
CurrentLimit *float64 `json:"current_limit,omitempty"`
|
||||||
|
Standby *bool `json:"standby,omitempty"`
|
||||||
|
LastCommand string `json:"last_command,omitempty"`
|
||||||
|
LastError string `json:"last_error,omitempty"`
|
||||||
|
LastUpdated string `json:"last_updated,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type templateInput struct {
|
type templateInput struct {
|
||||||
Error []error `json:"errors"`
|
Error []error `json:"errors"`
|
||||||
|
|
||||||
@@ -94,12 +124,125 @@ type templateInput struct {
|
|||||||
OutFreq string `json:"output_frequency"`
|
OutFreq string `json:"output_frequency"`
|
||||||
|
|
||||||
LedMap map[string]string `json:"led_map"`
|
LedMap map[string]string `json:"led_map"`
|
||||||
|
|
||||||
|
RemotePanel remotePanelState `json:"remote_panel"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type setRemotePanelStateRequest struct {
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
CurrentLimit *float64 `json:"current_limit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type setRemotePanelStandbyRequest struct {
|
||||||
|
Standby bool `json:"standby"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebGui) ServeHub(rw http.ResponseWriter, r *http.Request) {
|
func (w *WebGui) ServeHub(rw http.ResponseWriter, r *http.Request) {
|
||||||
w.hub.ServeHTTP(rw, r)
|
w.hub.ServeHTTP(rw, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WebGui) ServeRemotePanelState(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
writeJSON(rw, http.StatusOK, w.getRemotePanelState())
|
||||||
|
case http.MethodPost:
|
||||||
|
w.handleSetRemotePanelState(rw, r)
|
||||||
|
default:
|
||||||
|
http.Error(rw, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebGui) ServeRemotePanelStandby(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
writeJSON(rw, http.StatusOK, w.getRemotePanelState())
|
||||||
|
case http.MethodPost:
|
||||||
|
w.handleSetRemotePanelStandby(rw, r)
|
||||||
|
default:
|
||||||
|
http.Error(rw, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebGui) handleSetRemotePanelState(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
if w.writer == nil {
|
||||||
|
http.Error(rw, "remote control is not supported by this data source", http.StatusNotImplemented)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req := setRemotePanelStateRequest{}
|
||||||
|
if err := decodeJSONBody(r, &req); err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switchState, normalizedMode, err := parsePanelMode(req.Mode)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.writer.SetPanelState(switchState, req.CurrentLimit); err != nil {
|
||||||
|
w.updateRemotePanelState(func(state *remotePanelState) {
|
||||||
|
state.LastCommand = "set_remote_panel_state"
|
||||||
|
state.LastError = err.Error()
|
||||||
|
})
|
||||||
|
http.Error(rw, err.Error(), http.StatusBadGateway)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.updateRemotePanelState(func(state *remotePanelState) {
|
||||||
|
state.Mode = normalizedMode
|
||||||
|
state.CurrentLimit = copyFloat64Ptr(req.CurrentLimit)
|
||||||
|
state.LastCommand = "set_remote_panel_state"
|
||||||
|
state.LastError = ""
|
||||||
|
})
|
||||||
|
writeJSON(rw, http.StatusOK, w.getRemotePanelState())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebGui) handleSetRemotePanelStandby(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
if w.writer == nil {
|
||||||
|
http.Error(rw, "remote control is not supported by this data source", http.StatusNotImplemented)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req := setRemotePanelStandbyRequest{}
|
||||||
|
if err := decodeJSONBody(r, &req); err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.writer.SetStandby(req.Standby); err != nil {
|
||||||
|
w.updateRemotePanelState(func(state *remotePanelState) {
|
||||||
|
state.LastCommand = "set_remote_panel_standby"
|
||||||
|
state.LastError = err.Error()
|
||||||
|
})
|
||||||
|
http.Error(rw, err.Error(), http.StatusBadGateway)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.updateRemotePanelState(func(state *remotePanelState) {
|
||||||
|
state.Standby = copyBoolPtr(&req.Standby)
|
||||||
|
state.LastCommand = "set_remote_panel_standby"
|
||||||
|
state.LastError = ""
|
||||||
|
})
|
||||||
|
writeJSON(rw, http.StatusOK, w.getRemotePanelState())
|
||||||
|
}
|
||||||
|
|
||||||
|
func parsePanelMode(raw string) (mk2driver.PanelSwitchState, string, error) {
|
||||||
|
switch strings.TrimSpace(strings.ToLower(raw)) {
|
||||||
|
case modeChargerOnly:
|
||||||
|
return mk2driver.PanelSwitchChargerOnly, modeChargerOnly, nil
|
||||||
|
case modeInverterOnly:
|
||||||
|
return mk2driver.PanelSwitchInverterOnly, modeInverterOnly, nil
|
||||||
|
case modeOn:
|
||||||
|
return mk2driver.PanelSwitchOn, modeOn, nil
|
||||||
|
case modeOff:
|
||||||
|
return mk2driver.PanelSwitchOff, modeOff, nil
|
||||||
|
default:
|
||||||
|
return 0, "", fmt.Errorf("unsupported panel mode %q", raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ledName(led mk2driver.Led) string {
|
func ledName(led mk2driver.Led) string {
|
||||||
name, ok := mk2driver.LedNames[led]
|
name, ok := mk2driver.LedNames[led]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -162,15 +305,17 @@ func (w *WebGui) Stop() {
|
|||||||
w.wg.Wait()
|
w.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// dataPoll waits for data from the w.poller channel. It will send its currently stored status
|
|
||||||
// to respChan if anything reads from it.
|
|
||||||
func (w *WebGui) dataPoll() {
|
func (w *WebGui) dataPoll() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case s := <-w.C():
|
case s := <-w.C():
|
||||||
if s.Valid {
|
if s.Valid {
|
||||||
err := w.hub.Broadcast(buildTemplateInput(s))
|
payload := buildTemplateInput(s)
|
||||||
if err != nil {
|
w.stateMu.Lock()
|
||||||
|
payload.RemotePanel = w.remote
|
||||||
|
w.latest = payload
|
||||||
|
w.stateMu.Unlock()
|
||||||
|
if err := w.hub.Broadcast(payload); err != nil {
|
||||||
log.Errorf("Could not send update to clients: %v", err)
|
log.Errorf("Could not send update to clients: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,3 +325,93 @@ func (w *WebGui) dataPoll() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WebGui) getRemotePanelState() remotePanelState {
|
||||||
|
w.stateMu.RLock()
|
||||||
|
defer w.stateMu.RUnlock()
|
||||||
|
return copyRemotePanelState(w.remote)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebGui) updateRemotePanelState(update func(state *remotePanelState)) {
|
||||||
|
w.stateMu.Lock()
|
||||||
|
update(&w.remote)
|
||||||
|
w.remote.LastUpdated = time.Now().UTC().Format(time.RFC3339)
|
||||||
|
snapshot := w.snapshotLocked()
|
||||||
|
w.stateMu.Unlock()
|
||||||
|
|
||||||
|
if snapshot != nil {
|
||||||
|
if err := w.hub.Broadcast(snapshot); err != nil {
|
||||||
|
log.Errorf("Could not send control update to clients: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebGui) snapshotLocked() *templateInput {
|
||||||
|
if w.latest == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshot := cloneTemplateInput(w.latest)
|
||||||
|
snapshot.RemotePanel = copyRemotePanelState(w.remote)
|
||||||
|
return snapshot
|
||||||
|
}
|
||||||
|
|
||||||
|
func cloneTemplateInput(in *templateInput) *templateInput {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := *in
|
||||||
|
|
||||||
|
if in.Error != nil {
|
||||||
|
out.Error = append([]error(nil), in.Error...)
|
||||||
|
}
|
||||||
|
if in.LedMap != nil {
|
||||||
|
out.LedMap = make(map[string]string, len(in.LedMap))
|
||||||
|
for k, v := range in.LedMap {
|
||||||
|
out.LedMap[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out.RemotePanel = copyRemotePanelState(in.RemotePanel)
|
||||||
|
return &out
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyRemotePanelState(in remotePanelState) remotePanelState {
|
||||||
|
in.CurrentLimit = copyFloat64Ptr(in.CurrentLimit)
|
||||||
|
in.Standby = copyBoolPtr(in.Standby)
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyFloat64Ptr(in *float64) *float64 {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
value := *in
|
||||||
|
return &value
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyBoolPtr(in *bool) *bool {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
value := *in
|
||||||
|
return &value
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeJSONBody(r *http.Request, destination any) error {
|
||||||
|
defer r.Body.Close()
|
||||||
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
decoder.DisallowUnknownFields()
|
||||||
|
if err := decoder.Decode(destination); err != nil {
|
||||||
|
return fmt.Errorf("invalid request body: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeJSON(rw http.ResponseWriter, statusCode int, payload any) {
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
rw.WriteHeader(statusCode)
|
||||||
|
if err := json.NewEncoder(rw).Encode(payload); err != nil {
|
||||||
|
log.Errorf("Could not encode webui API response: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2driver"
|
"invertergui/mk2driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type templateTest struct {
|
type templateTest struct {
|
||||||
@@ -91,3 +91,53 @@ func TestTemplateInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParsePanelMode(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
want mk2driver.PanelSwitchState
|
||||||
|
wantRaw string
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "on",
|
||||||
|
input: "on",
|
||||||
|
want: mk2driver.PanelSwitchOn,
|
||||||
|
wantRaw: "on",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "charger_only",
|
||||||
|
input: "charger_only",
|
||||||
|
want: mk2driver.PanelSwitchChargerOnly,
|
||||||
|
wantRaw: "charger_only",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid",
|
||||||
|
input: "banana",
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, gotRaw, err := parsePanelMode(tt.input)
|
||||||
|
if tt.wantErr {
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error, got nil")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if got != tt.want {
|
||||||
|
t.Fatalf("got switch %d, want %d", got, tt.want)
|
||||||
|
}
|
||||||
|
if gotRaw != tt.wantRaw {
|
||||||
|
t.Fatalf("got mode %q, want %q", gotRaw, tt.wantRaw)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
8
vendor/github.com/cespare/xxhash/v2/.travis.yml
generated
vendored
8
vendor/github.com/cespare/xxhash/v2/.travis.yml
generated
vendored
@@ -1,8 +0,0 @@
|
|||||||
language: go
|
|
||||||
go:
|
|
||||||
- "1.x"
|
|
||||||
- master
|
|
||||||
env:
|
|
||||||
- TAGS=""
|
|
||||||
- TAGS="-tags purego"
|
|
||||||
script: go test $TAGS -v ./...
|
|
||||||
37
vendor/github.com/cespare/xxhash/v2/README.md
generated
vendored
37
vendor/github.com/cespare/xxhash/v2/README.md
generated
vendored
@@ -1,10 +1,9 @@
|
|||||||
# xxhash
|
# xxhash
|
||||||
|
|
||||||
[](https://godoc.org/github.com/cespare/xxhash)
|
[](https://pkg.go.dev/github.com/cespare/xxhash/v2)
|
||||||
[](https://travis-ci.org/cespare/xxhash)
|
[](https://github.com/cespare/xxhash/actions/workflows/test.yml)
|
||||||
|
|
||||||
xxhash is a Go implementation of the 64-bit
|
xxhash is a Go implementation of the 64-bit [xxHash] algorithm, XXH64. This is a
|
||||||
[xxHash](http://cyan4973.github.io/xxHash/) algorithm, XXH64. This is a
|
|
||||||
high-quality hashing algorithm that is much faster than anything in the Go
|
high-quality hashing algorithm that is much faster than anything in the Go
|
||||||
standard library.
|
standard library.
|
||||||
|
|
||||||
@@ -25,8 +24,11 @@ func (*Digest) WriteString(string) (int, error)
|
|||||||
func (*Digest) Sum64() uint64
|
func (*Digest) Sum64() uint64
|
||||||
```
|
```
|
||||||
|
|
||||||
This implementation provides a fast pure-Go implementation and an even faster
|
The package is written with optimized pure Go and also contains even faster
|
||||||
assembly implementation for amd64.
|
assembly implementations for amd64 and arm64. If desired, the `purego` build tag
|
||||||
|
opts into using the Go code even on those architectures.
|
||||||
|
|
||||||
|
[xxHash]: http://cyan4973.github.io/xxHash/
|
||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
@@ -46,22 +48,27 @@ Here are some quick benchmarks comparing the pure-Go and assembly
|
|||||||
implementations of Sum64.
|
implementations of Sum64.
|
||||||
|
|
||||||
| input size | purego | asm |
|
| input size | purego | asm |
|
||||||
| --- | --- | --- |
|
| ---------- | --------- | --------- |
|
||||||
| 5 B | 979.66 MB/s | 1291.17 MB/s |
|
| 4 B | 1.3 GB/s | 1.2 GB/s |
|
||||||
| 100 B | 7475.26 MB/s | 7973.40 MB/s |
|
| 16 B | 2.9 GB/s | 3.5 GB/s |
|
||||||
| 4 KB | 17573.46 MB/s | 17602.65 MB/s |
|
| 100 B | 6.9 GB/s | 8.1 GB/s |
|
||||||
| 10 MB | 17131.46 MB/s | 17142.16 MB/s |
|
| 4 KB | 11.7 GB/s | 16.7 GB/s |
|
||||||
|
| 10 MB | 12.0 GB/s | 17.3 GB/s |
|
||||||
|
|
||||||
These numbers were generated on Ubuntu 18.04 with an Intel i7-8700K CPU using
|
These numbers were generated on Ubuntu 20.04 with an Intel Xeon Platinum 8252C
|
||||||
the following commands under Go 1.11.2:
|
CPU using the following commands under Go 1.19.2:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ go test -tags purego -benchtime 10s -bench '/xxhash,direct,bytes'
|
benchstat <(go test -tags purego -benchtime 500ms -count 15 -bench 'Sum64$')
|
||||||
$ go test -benchtime 10s -bench '/xxhash,direct,bytes'
|
benchstat <(go test -benchtime 500ms -count 15 -bench 'Sum64$')
|
||||||
```
|
```
|
||||||
|
|
||||||
## Projects using this package
|
## Projects using this package
|
||||||
|
|
||||||
- [InfluxDB](https://github.com/influxdata/influxdb)
|
- [InfluxDB](https://github.com/influxdata/influxdb)
|
||||||
- [Prometheus](https://github.com/prometheus/prometheus)
|
- [Prometheus](https://github.com/prometheus/prometheus)
|
||||||
|
- [VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics)
|
||||||
- [FreeCache](https://github.com/coocood/freecache)
|
- [FreeCache](https://github.com/coocood/freecache)
|
||||||
|
- [FastCache](https://github.com/VictoriaMetrics/fastcache)
|
||||||
|
- [Ristretto](https://github.com/dgraph-io/ristretto)
|
||||||
|
- [Badger](https://github.com/dgraph-io/badger)
|
||||||
|
|||||||
3
vendor/github.com/cespare/xxhash/v2/go.mod
generated
vendored
3
vendor/github.com/cespare/xxhash/v2/go.mod
generated
vendored
@@ -1,3 +0,0 @@
|
|||||||
module github.com/cespare/xxhash/v2
|
|
||||||
|
|
||||||
go 1.11
|
|
||||||
0
vendor/github.com/cespare/xxhash/v2/go.sum
generated
vendored
0
vendor/github.com/cespare/xxhash/v2/go.sum
generated
vendored
10
vendor/github.com/cespare/xxhash/v2/testall.sh
generated
vendored
Normal file
10
vendor/github.com/cespare/xxhash/v2/testall.sh
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eu -o pipefail
|
||||||
|
|
||||||
|
# Small convenience script for running the tests with various combinations of
|
||||||
|
# arch/tags. This assumes we're running on amd64 and have qemu available.
|
||||||
|
|
||||||
|
go test ./...
|
||||||
|
go test -tags purego ./...
|
||||||
|
GOARCH=arm64 go test
|
||||||
|
GOARCH=arm64 go test -tags purego
|
||||||
71
vendor/github.com/cespare/xxhash/v2/xxhash.go
generated
vendored
71
vendor/github.com/cespare/xxhash/v2/xxhash.go
generated
vendored
@@ -16,21 +16,16 @@ const (
|
|||||||
prime5 uint64 = 2870177450012600261
|
prime5 uint64 = 2870177450012600261
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTE(caleb): I'm using both consts and vars of the primes. Using consts where
|
// Store the primes in an array as well.
|
||||||
// possible in the Go code is worth a small (but measurable) performance boost
|
//
|
||||||
// by avoiding some MOVQs. Vars are needed for the asm and also are useful for
|
// The consts are used when possible in Go code to avoid MOVs but we need a
|
||||||
// convenience in the Go code in a few places where we need to intentionally
|
// contiguous array for the assembly code.
|
||||||
// avoid constant arithmetic (e.g., v1 := prime1 + prime2 fails because the
|
var primes = [...]uint64{prime1, prime2, prime3, prime4, prime5}
|
||||||
// result overflows a uint64).
|
|
||||||
var (
|
|
||||||
prime1v = prime1
|
|
||||||
prime2v = prime2
|
|
||||||
prime3v = prime3
|
|
||||||
prime4v = prime4
|
|
||||||
prime5v = prime5
|
|
||||||
)
|
|
||||||
|
|
||||||
// Digest implements hash.Hash64.
|
// Digest implements hash.Hash64.
|
||||||
|
//
|
||||||
|
// Note that a zero-valued Digest is not ready to receive writes.
|
||||||
|
// Call Reset or create a Digest using New before calling other methods.
|
||||||
type Digest struct {
|
type Digest struct {
|
||||||
v1 uint64
|
v1 uint64
|
||||||
v2 uint64
|
v2 uint64
|
||||||
@@ -41,19 +36,31 @@ type Digest struct {
|
|||||||
n int // how much of mem is used
|
n int // how much of mem is used
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Digest that computes the 64-bit xxHash algorithm.
|
// New creates a new Digest with a zero seed.
|
||||||
func New() *Digest {
|
func New() *Digest {
|
||||||
|
return NewWithSeed(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWithSeed creates a new Digest with the given seed.
|
||||||
|
func NewWithSeed(seed uint64) *Digest {
|
||||||
var d Digest
|
var d Digest
|
||||||
d.Reset()
|
d.ResetWithSeed(seed)
|
||||||
return &d
|
return &d
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset clears the Digest's state so that it can be reused.
|
// Reset clears the Digest's state so that it can be reused.
|
||||||
|
// It uses a seed value of zero.
|
||||||
func (d *Digest) Reset() {
|
func (d *Digest) Reset() {
|
||||||
d.v1 = prime1v + prime2
|
d.ResetWithSeed(0)
|
||||||
d.v2 = prime2
|
}
|
||||||
d.v3 = 0
|
|
||||||
d.v4 = -prime1v
|
// ResetWithSeed clears the Digest's state so that it can be reused.
|
||||||
|
// It uses the given seed to initialize the state.
|
||||||
|
func (d *Digest) ResetWithSeed(seed uint64) {
|
||||||
|
d.v1 = seed + prime1 + prime2
|
||||||
|
d.v2 = seed + prime2
|
||||||
|
d.v3 = seed
|
||||||
|
d.v4 = seed - prime1
|
||||||
d.total = 0
|
d.total = 0
|
||||||
d.n = 0
|
d.n = 0
|
||||||
}
|
}
|
||||||
@@ -69,21 +76,23 @@ func (d *Digest) Write(b []byte) (n int, err error) {
|
|||||||
n = len(b)
|
n = len(b)
|
||||||
d.total += uint64(n)
|
d.total += uint64(n)
|
||||||
|
|
||||||
|
memleft := d.mem[d.n&(len(d.mem)-1):]
|
||||||
|
|
||||||
if d.n+n < 32 {
|
if d.n+n < 32 {
|
||||||
// This new data doesn't even fill the current block.
|
// This new data doesn't even fill the current block.
|
||||||
copy(d.mem[d.n:], b)
|
copy(memleft, b)
|
||||||
d.n += n
|
d.n += n
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.n > 0 {
|
if d.n > 0 {
|
||||||
// Finish off the partial block.
|
// Finish off the partial block.
|
||||||
copy(d.mem[d.n:], b)
|
c := copy(memleft, b)
|
||||||
d.v1 = round(d.v1, u64(d.mem[0:8]))
|
d.v1 = round(d.v1, u64(d.mem[0:8]))
|
||||||
d.v2 = round(d.v2, u64(d.mem[8:16]))
|
d.v2 = round(d.v2, u64(d.mem[8:16]))
|
||||||
d.v3 = round(d.v3, u64(d.mem[16:24]))
|
d.v3 = round(d.v3, u64(d.mem[16:24]))
|
||||||
d.v4 = round(d.v4, u64(d.mem[24:32]))
|
d.v4 = round(d.v4, u64(d.mem[24:32]))
|
||||||
b = b[32-d.n:]
|
b = b[c:]
|
||||||
d.n = 0
|
d.n = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,21 +142,20 @@ func (d *Digest) Sum64() uint64 {
|
|||||||
|
|
||||||
h += d.total
|
h += d.total
|
||||||
|
|
||||||
i, end := 0, d.n
|
b := d.mem[:d.n&(len(d.mem)-1)]
|
||||||
for ; i+8 <= end; i += 8 {
|
for ; len(b) >= 8; b = b[8:] {
|
||||||
k1 := round(0, u64(d.mem[i:i+8]))
|
k1 := round(0, u64(b[:8]))
|
||||||
h ^= k1
|
h ^= k1
|
||||||
h = rol27(h)*prime1 + prime4
|
h = rol27(h)*prime1 + prime4
|
||||||
}
|
}
|
||||||
if i+4 <= end {
|
if len(b) >= 4 {
|
||||||
h ^= uint64(u32(d.mem[i:i+4])) * prime1
|
h ^= uint64(u32(b[:4])) * prime1
|
||||||
h = rol23(h)*prime2 + prime3
|
h = rol23(h)*prime2 + prime3
|
||||||
i += 4
|
b = b[4:]
|
||||||
}
|
}
|
||||||
for i < end {
|
for ; len(b) > 0; b = b[1:] {
|
||||||
h ^= uint64(d.mem[i]) * prime5
|
h ^= uint64(b[0]) * prime5
|
||||||
h = rol11(h) * prime1
|
h = rol11(h) * prime1
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h ^= h >> 33
|
h ^= h >> 33
|
||||||
@@ -193,7 +201,6 @@ func (d *Digest) UnmarshalBinary(b []byte) error {
|
|||||||
b, d.v4 = consumeUint64(b)
|
b, d.v4 = consumeUint64(b)
|
||||||
b, d.total = consumeUint64(b)
|
b, d.total = consumeUint64(b)
|
||||||
copy(d.mem[:], b)
|
copy(d.mem[:], b)
|
||||||
b = b[len(d.mem):]
|
|
||||||
d.n = int(d.total % uint64(len(d.mem)))
|
d.n = int(d.total % uint64(len(d.mem)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
308
vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s
generated
vendored
308
vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s
generated
vendored
@@ -1,215 +1,209 @@
|
|||||||
|
//go:build !appengine && gc && !purego
|
||||||
// +build !appengine
|
// +build !appengine
|
||||||
// +build gc
|
// +build gc
|
||||||
// +build !purego
|
// +build !purego
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
// Register allocation:
|
// Registers:
|
||||||
// AX h
|
#define h AX
|
||||||
// CX pointer to advance through b
|
#define d AX
|
||||||
// DX n
|
#define p SI // pointer to advance through b
|
||||||
// BX loop end
|
#define n DX
|
||||||
// R8 v1, k1
|
#define end BX // loop end
|
||||||
// R9 v2
|
#define v1 R8
|
||||||
// R10 v3
|
#define v2 R9
|
||||||
// R11 v4
|
#define v3 R10
|
||||||
// R12 tmp
|
#define v4 R11
|
||||||
// R13 prime1v
|
#define x R12
|
||||||
// R14 prime2v
|
#define prime1 R13
|
||||||
// R15 prime4v
|
#define prime2 R14
|
||||||
|
#define prime4 DI
|
||||||
|
|
||||||
// round reads from and advances the buffer pointer in CX.
|
#define round(acc, x) \
|
||||||
// It assumes that R13 has prime1v and R14 has prime2v.
|
IMULQ prime2, x \
|
||||||
#define round(r) \
|
ADDQ x, acc \
|
||||||
MOVQ (CX), R12 \
|
ROLQ $31, acc \
|
||||||
ADDQ $8, CX \
|
IMULQ prime1, acc
|
||||||
IMULQ R14, R12 \
|
|
||||||
ADDQ R12, r \
|
|
||||||
ROLQ $31, r \
|
|
||||||
IMULQ R13, r
|
|
||||||
|
|
||||||
// mergeRound applies a merge round on the two registers acc and val.
|
// round0 performs the operation x = round(0, x).
|
||||||
// It assumes that R13 has prime1v, R14 has prime2v, and R15 has prime4v.
|
#define round0(x) \
|
||||||
#define mergeRound(acc, val) \
|
IMULQ prime2, x \
|
||||||
IMULQ R14, val \
|
ROLQ $31, x \
|
||||||
ROLQ $31, val \
|
IMULQ prime1, x
|
||||||
IMULQ R13, val \
|
|
||||||
XORQ val, acc \
|
// mergeRound applies a merge round on the two registers acc and x.
|
||||||
IMULQ R13, acc \
|
// It assumes that prime1, prime2, and prime4 have been loaded.
|
||||||
ADDQ R15, acc
|
#define mergeRound(acc, x) \
|
||||||
|
round0(x) \
|
||||||
|
XORQ x, acc \
|
||||||
|
IMULQ prime1, acc \
|
||||||
|
ADDQ prime4, acc
|
||||||
|
|
||||||
|
// blockLoop processes as many 32-byte blocks as possible,
|
||||||
|
// updating v1, v2, v3, and v4. It assumes that there is at least one block
|
||||||
|
// to process.
|
||||||
|
#define blockLoop() \
|
||||||
|
loop: \
|
||||||
|
MOVQ +0(p), x \
|
||||||
|
round(v1, x) \
|
||||||
|
MOVQ +8(p), x \
|
||||||
|
round(v2, x) \
|
||||||
|
MOVQ +16(p), x \
|
||||||
|
round(v3, x) \
|
||||||
|
MOVQ +24(p), x \
|
||||||
|
round(v4, x) \
|
||||||
|
ADDQ $32, p \
|
||||||
|
CMPQ p, end \
|
||||||
|
JLE loop
|
||||||
|
|
||||||
// func Sum64(b []byte) uint64
|
// func Sum64(b []byte) uint64
|
||||||
TEXT ·Sum64(SB), NOSPLIT, $0-32
|
TEXT ·Sum64(SB), NOSPLIT|NOFRAME, $0-32
|
||||||
// Load fixed primes.
|
// Load fixed primes.
|
||||||
MOVQ ·prime1v(SB), R13
|
MOVQ ·primes+0(SB), prime1
|
||||||
MOVQ ·prime2v(SB), R14
|
MOVQ ·primes+8(SB), prime2
|
||||||
MOVQ ·prime4v(SB), R15
|
MOVQ ·primes+24(SB), prime4
|
||||||
|
|
||||||
// Load slice.
|
// Load slice.
|
||||||
MOVQ b_base+0(FP), CX
|
MOVQ b_base+0(FP), p
|
||||||
MOVQ b_len+8(FP), DX
|
MOVQ b_len+8(FP), n
|
||||||
LEAQ (CX)(DX*1), BX
|
LEAQ (p)(n*1), end
|
||||||
|
|
||||||
// The first loop limit will be len(b)-32.
|
// The first loop limit will be len(b)-32.
|
||||||
SUBQ $32, BX
|
SUBQ $32, end
|
||||||
|
|
||||||
// Check whether we have at least one block.
|
// Check whether we have at least one block.
|
||||||
CMPQ DX, $32
|
CMPQ n, $32
|
||||||
JLT noBlocks
|
JLT noBlocks
|
||||||
|
|
||||||
// Set up initial state (v1, v2, v3, v4).
|
// Set up initial state (v1, v2, v3, v4).
|
||||||
MOVQ R13, R8
|
MOVQ prime1, v1
|
||||||
ADDQ R14, R8
|
ADDQ prime2, v1
|
||||||
MOVQ R14, R9
|
MOVQ prime2, v2
|
||||||
XORQ R10, R10
|
XORQ v3, v3
|
||||||
XORQ R11, R11
|
XORQ v4, v4
|
||||||
SUBQ R13, R11
|
SUBQ prime1, v4
|
||||||
|
|
||||||
// Loop until CX > BX.
|
blockLoop()
|
||||||
blockLoop:
|
|
||||||
round(R8)
|
|
||||||
round(R9)
|
|
||||||
round(R10)
|
|
||||||
round(R11)
|
|
||||||
|
|
||||||
CMPQ CX, BX
|
MOVQ v1, h
|
||||||
JLE blockLoop
|
ROLQ $1, h
|
||||||
|
MOVQ v2, x
|
||||||
|
ROLQ $7, x
|
||||||
|
ADDQ x, h
|
||||||
|
MOVQ v3, x
|
||||||
|
ROLQ $12, x
|
||||||
|
ADDQ x, h
|
||||||
|
MOVQ v4, x
|
||||||
|
ROLQ $18, x
|
||||||
|
ADDQ x, h
|
||||||
|
|
||||||
MOVQ R8, AX
|
mergeRound(h, v1)
|
||||||
ROLQ $1, AX
|
mergeRound(h, v2)
|
||||||
MOVQ R9, R12
|
mergeRound(h, v3)
|
||||||
ROLQ $7, R12
|
mergeRound(h, v4)
|
||||||
ADDQ R12, AX
|
|
||||||
MOVQ R10, R12
|
|
||||||
ROLQ $12, R12
|
|
||||||
ADDQ R12, AX
|
|
||||||
MOVQ R11, R12
|
|
||||||
ROLQ $18, R12
|
|
||||||
ADDQ R12, AX
|
|
||||||
|
|
||||||
mergeRound(AX, R8)
|
|
||||||
mergeRound(AX, R9)
|
|
||||||
mergeRound(AX, R10)
|
|
||||||
mergeRound(AX, R11)
|
|
||||||
|
|
||||||
JMP afterBlocks
|
JMP afterBlocks
|
||||||
|
|
||||||
noBlocks:
|
noBlocks:
|
||||||
MOVQ ·prime5v(SB), AX
|
MOVQ ·primes+32(SB), h
|
||||||
|
|
||||||
afterBlocks:
|
afterBlocks:
|
||||||
ADDQ DX, AX
|
ADDQ n, h
|
||||||
|
|
||||||
// Right now BX has len(b)-32, and we want to loop until CX > len(b)-8.
|
ADDQ $24, end
|
||||||
ADDQ $24, BX
|
CMPQ p, end
|
||||||
|
JG try4
|
||||||
|
|
||||||
CMPQ CX, BX
|
loop8:
|
||||||
JG fourByte
|
MOVQ (p), x
|
||||||
|
ADDQ $8, p
|
||||||
|
round0(x)
|
||||||
|
XORQ x, h
|
||||||
|
ROLQ $27, h
|
||||||
|
IMULQ prime1, h
|
||||||
|
ADDQ prime4, h
|
||||||
|
|
||||||
wordLoop:
|
CMPQ p, end
|
||||||
// Calculate k1.
|
JLE loop8
|
||||||
MOVQ (CX), R8
|
|
||||||
ADDQ $8, CX
|
|
||||||
IMULQ R14, R8
|
|
||||||
ROLQ $31, R8
|
|
||||||
IMULQ R13, R8
|
|
||||||
|
|
||||||
XORQ R8, AX
|
try4:
|
||||||
ROLQ $27, AX
|
ADDQ $4, end
|
||||||
IMULQ R13, AX
|
CMPQ p, end
|
||||||
ADDQ R15, AX
|
JG try1
|
||||||
|
|
||||||
CMPQ CX, BX
|
MOVL (p), x
|
||||||
JLE wordLoop
|
ADDQ $4, p
|
||||||
|
IMULQ prime1, x
|
||||||
|
XORQ x, h
|
||||||
|
|
||||||
fourByte:
|
ROLQ $23, h
|
||||||
ADDQ $4, BX
|
IMULQ prime2, h
|
||||||
CMPQ CX, BX
|
ADDQ ·primes+16(SB), h
|
||||||
JG singles
|
|
||||||
|
|
||||||
MOVL (CX), R8
|
try1:
|
||||||
ADDQ $4, CX
|
ADDQ $4, end
|
||||||
IMULQ R13, R8
|
CMPQ p, end
|
||||||
XORQ R8, AX
|
|
||||||
|
|
||||||
ROLQ $23, AX
|
|
||||||
IMULQ R14, AX
|
|
||||||
ADDQ ·prime3v(SB), AX
|
|
||||||
|
|
||||||
singles:
|
|
||||||
ADDQ $4, BX
|
|
||||||
CMPQ CX, BX
|
|
||||||
JGE finalize
|
JGE finalize
|
||||||
|
|
||||||
singlesLoop:
|
loop1:
|
||||||
MOVBQZX (CX), R12
|
MOVBQZX (p), x
|
||||||
ADDQ $1, CX
|
ADDQ $1, p
|
||||||
IMULQ ·prime5v(SB), R12
|
IMULQ ·primes+32(SB), x
|
||||||
XORQ R12, AX
|
XORQ x, h
|
||||||
|
ROLQ $11, h
|
||||||
|
IMULQ prime1, h
|
||||||
|
|
||||||
ROLQ $11, AX
|
CMPQ p, end
|
||||||
IMULQ R13, AX
|
JL loop1
|
||||||
|
|
||||||
CMPQ CX, BX
|
|
||||||
JL singlesLoop
|
|
||||||
|
|
||||||
finalize:
|
finalize:
|
||||||
MOVQ AX, R12
|
MOVQ h, x
|
||||||
SHRQ $33, R12
|
SHRQ $33, x
|
||||||
XORQ R12, AX
|
XORQ x, h
|
||||||
IMULQ R14, AX
|
IMULQ prime2, h
|
||||||
MOVQ AX, R12
|
MOVQ h, x
|
||||||
SHRQ $29, R12
|
SHRQ $29, x
|
||||||
XORQ R12, AX
|
XORQ x, h
|
||||||
IMULQ ·prime3v(SB), AX
|
IMULQ ·primes+16(SB), h
|
||||||
MOVQ AX, R12
|
MOVQ h, x
|
||||||
SHRQ $32, R12
|
SHRQ $32, x
|
||||||
XORQ R12, AX
|
XORQ x, h
|
||||||
|
|
||||||
MOVQ AX, ret+24(FP)
|
MOVQ h, ret+24(FP)
|
||||||
RET
|
RET
|
||||||
|
|
||||||
// writeBlocks uses the same registers as above except that it uses AX to store
|
|
||||||
// the d pointer.
|
|
||||||
|
|
||||||
// func writeBlocks(d *Digest, b []byte) int
|
// func writeBlocks(d *Digest, b []byte) int
|
||||||
TEXT ·writeBlocks(SB), NOSPLIT, $0-40
|
TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40
|
||||||
// Load fixed primes needed for round.
|
// Load fixed primes needed for round.
|
||||||
MOVQ ·prime1v(SB), R13
|
MOVQ ·primes+0(SB), prime1
|
||||||
MOVQ ·prime2v(SB), R14
|
MOVQ ·primes+8(SB), prime2
|
||||||
|
|
||||||
// Load slice.
|
// Load slice.
|
||||||
MOVQ b_base+8(FP), CX
|
MOVQ b_base+8(FP), p
|
||||||
MOVQ b_len+16(FP), DX
|
MOVQ b_len+16(FP), n
|
||||||
LEAQ (CX)(DX*1), BX
|
LEAQ (p)(n*1), end
|
||||||
SUBQ $32, BX
|
SUBQ $32, end
|
||||||
|
|
||||||
// Load vN from d.
|
// Load vN from d.
|
||||||
MOVQ d+0(FP), AX
|
MOVQ s+0(FP), d
|
||||||
MOVQ 0(AX), R8 // v1
|
MOVQ 0(d), v1
|
||||||
MOVQ 8(AX), R9 // v2
|
MOVQ 8(d), v2
|
||||||
MOVQ 16(AX), R10 // v3
|
MOVQ 16(d), v3
|
||||||
MOVQ 24(AX), R11 // v4
|
MOVQ 24(d), v4
|
||||||
|
|
||||||
// We don't need to check the loop condition here; this function is
|
// We don't need to check the loop condition here; this function is
|
||||||
// always called with at least one block of data to process.
|
// always called with at least one block of data to process.
|
||||||
blockLoop:
|
blockLoop()
|
||||||
round(R8)
|
|
||||||
round(R9)
|
|
||||||
round(R10)
|
|
||||||
round(R11)
|
|
||||||
|
|
||||||
CMPQ CX, BX
|
|
||||||
JLE blockLoop
|
|
||||||
|
|
||||||
// Copy vN back to d.
|
// Copy vN back to d.
|
||||||
MOVQ R8, 0(AX)
|
MOVQ v1, 0(d)
|
||||||
MOVQ R9, 8(AX)
|
MOVQ v2, 8(d)
|
||||||
MOVQ R10, 16(AX)
|
MOVQ v3, 16(d)
|
||||||
MOVQ R11, 24(AX)
|
MOVQ v4, 24(d)
|
||||||
|
|
||||||
// The number of bytes written is CX minus the old base pointer.
|
// The number of bytes written is p minus the old base pointer.
|
||||||
SUBQ b_base+8(FP), CX
|
SUBQ b_base+8(FP), p
|
||||||
MOVQ CX, ret+32(FP)
|
MOVQ p, ret+32(FP)
|
||||||
|
|
||||||
RET
|
RET
|
||||||
|
|||||||
183
vendor/github.com/cespare/xxhash/v2/xxhash_arm64.s
generated
vendored
Normal file
183
vendor/github.com/cespare/xxhash/v2/xxhash_arm64.s
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
//go:build !appengine && gc && !purego
|
||||||
|
// +build !appengine
|
||||||
|
// +build gc
|
||||||
|
// +build !purego
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// Registers:
|
||||||
|
#define digest R1
|
||||||
|
#define h R2 // return value
|
||||||
|
#define p R3 // input pointer
|
||||||
|
#define n R4 // input length
|
||||||
|
#define nblocks R5 // n / 32
|
||||||
|
#define prime1 R7
|
||||||
|
#define prime2 R8
|
||||||
|
#define prime3 R9
|
||||||
|
#define prime4 R10
|
||||||
|
#define prime5 R11
|
||||||
|
#define v1 R12
|
||||||
|
#define v2 R13
|
||||||
|
#define v3 R14
|
||||||
|
#define v4 R15
|
||||||
|
#define x1 R20
|
||||||
|
#define x2 R21
|
||||||
|
#define x3 R22
|
||||||
|
#define x4 R23
|
||||||
|
|
||||||
|
#define round(acc, x) \
|
||||||
|
MADD prime2, acc, x, acc \
|
||||||
|
ROR $64-31, acc \
|
||||||
|
MUL prime1, acc
|
||||||
|
|
||||||
|
// round0 performs the operation x = round(0, x).
|
||||||
|
#define round0(x) \
|
||||||
|
MUL prime2, x \
|
||||||
|
ROR $64-31, x \
|
||||||
|
MUL prime1, x
|
||||||
|
|
||||||
|
#define mergeRound(acc, x) \
|
||||||
|
round0(x) \
|
||||||
|
EOR x, acc \
|
||||||
|
MADD acc, prime4, prime1, acc
|
||||||
|
|
||||||
|
// blockLoop processes as many 32-byte blocks as possible,
|
||||||
|
// updating v1, v2, v3, and v4. It assumes that n >= 32.
|
||||||
|
#define blockLoop() \
|
||||||
|
LSR $5, n, nblocks \
|
||||||
|
PCALIGN $16 \
|
||||||
|
loop: \
|
||||||
|
LDP.P 16(p), (x1, x2) \
|
||||||
|
LDP.P 16(p), (x3, x4) \
|
||||||
|
round(v1, x1) \
|
||||||
|
round(v2, x2) \
|
||||||
|
round(v3, x3) \
|
||||||
|
round(v4, x4) \
|
||||||
|
SUB $1, nblocks \
|
||||||
|
CBNZ nblocks, loop
|
||||||
|
|
||||||
|
// func Sum64(b []byte) uint64
|
||||||
|
TEXT ·Sum64(SB), NOSPLIT|NOFRAME, $0-32
|
||||||
|
LDP b_base+0(FP), (p, n)
|
||||||
|
|
||||||
|
LDP ·primes+0(SB), (prime1, prime2)
|
||||||
|
LDP ·primes+16(SB), (prime3, prime4)
|
||||||
|
MOVD ·primes+32(SB), prime5
|
||||||
|
|
||||||
|
CMP $32, n
|
||||||
|
CSEL LT, prime5, ZR, h // if n < 32 { h = prime5 } else { h = 0 }
|
||||||
|
BLT afterLoop
|
||||||
|
|
||||||
|
ADD prime1, prime2, v1
|
||||||
|
MOVD prime2, v2
|
||||||
|
MOVD $0, v3
|
||||||
|
NEG prime1, v4
|
||||||
|
|
||||||
|
blockLoop()
|
||||||
|
|
||||||
|
ROR $64-1, v1, x1
|
||||||
|
ROR $64-7, v2, x2
|
||||||
|
ADD x1, x2
|
||||||
|
ROR $64-12, v3, x3
|
||||||
|
ROR $64-18, v4, x4
|
||||||
|
ADD x3, x4
|
||||||
|
ADD x2, x4, h
|
||||||
|
|
||||||
|
mergeRound(h, v1)
|
||||||
|
mergeRound(h, v2)
|
||||||
|
mergeRound(h, v3)
|
||||||
|
mergeRound(h, v4)
|
||||||
|
|
||||||
|
afterLoop:
|
||||||
|
ADD n, h
|
||||||
|
|
||||||
|
TBZ $4, n, try8
|
||||||
|
LDP.P 16(p), (x1, x2)
|
||||||
|
|
||||||
|
round0(x1)
|
||||||
|
|
||||||
|
// NOTE: here and below, sequencing the EOR after the ROR (using a
|
||||||
|
// rotated register) is worth a small but measurable speedup for small
|
||||||
|
// inputs.
|
||||||
|
ROR $64-27, h
|
||||||
|
EOR x1 @> 64-27, h, h
|
||||||
|
MADD h, prime4, prime1, h
|
||||||
|
|
||||||
|
round0(x2)
|
||||||
|
ROR $64-27, h
|
||||||
|
EOR x2 @> 64-27, h, h
|
||||||
|
MADD h, prime4, prime1, h
|
||||||
|
|
||||||
|
try8:
|
||||||
|
TBZ $3, n, try4
|
||||||
|
MOVD.P 8(p), x1
|
||||||
|
|
||||||
|
round0(x1)
|
||||||
|
ROR $64-27, h
|
||||||
|
EOR x1 @> 64-27, h, h
|
||||||
|
MADD h, prime4, prime1, h
|
||||||
|
|
||||||
|
try4:
|
||||||
|
TBZ $2, n, try2
|
||||||
|
MOVWU.P 4(p), x2
|
||||||
|
|
||||||
|
MUL prime1, x2
|
||||||
|
ROR $64-23, h
|
||||||
|
EOR x2 @> 64-23, h, h
|
||||||
|
MADD h, prime3, prime2, h
|
||||||
|
|
||||||
|
try2:
|
||||||
|
TBZ $1, n, try1
|
||||||
|
MOVHU.P 2(p), x3
|
||||||
|
AND $255, x3, x1
|
||||||
|
LSR $8, x3, x2
|
||||||
|
|
||||||
|
MUL prime5, x1
|
||||||
|
ROR $64-11, h
|
||||||
|
EOR x1 @> 64-11, h, h
|
||||||
|
MUL prime1, h
|
||||||
|
|
||||||
|
MUL prime5, x2
|
||||||
|
ROR $64-11, h
|
||||||
|
EOR x2 @> 64-11, h, h
|
||||||
|
MUL prime1, h
|
||||||
|
|
||||||
|
try1:
|
||||||
|
TBZ $0, n, finalize
|
||||||
|
MOVBU (p), x4
|
||||||
|
|
||||||
|
MUL prime5, x4
|
||||||
|
ROR $64-11, h
|
||||||
|
EOR x4 @> 64-11, h, h
|
||||||
|
MUL prime1, h
|
||||||
|
|
||||||
|
finalize:
|
||||||
|
EOR h >> 33, h
|
||||||
|
MUL prime2, h
|
||||||
|
EOR h >> 29, h
|
||||||
|
MUL prime3, h
|
||||||
|
EOR h >> 32, h
|
||||||
|
|
||||||
|
MOVD h, ret+24(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// func writeBlocks(d *Digest, b []byte) int
|
||||||
|
TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40
|
||||||
|
LDP ·primes+0(SB), (prime1, prime2)
|
||||||
|
|
||||||
|
// Load state. Assume v[1-4] are stored contiguously.
|
||||||
|
MOVD d+0(FP), digest
|
||||||
|
LDP 0(digest), (v1, v2)
|
||||||
|
LDP 16(digest), (v3, v4)
|
||||||
|
|
||||||
|
LDP b_base+8(FP), (p, n)
|
||||||
|
|
||||||
|
blockLoop()
|
||||||
|
|
||||||
|
// Store updated state.
|
||||||
|
STP (v1, v2), 0(digest)
|
||||||
|
STP (v3, v4), 16(digest)
|
||||||
|
|
||||||
|
BIC $31, n
|
||||||
|
MOVD n, ret+32(FP)
|
||||||
|
RET
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
|
//go:build (amd64 || arm64) && !appengine && gc && !purego
|
||||||
|
// +build amd64 arm64
|
||||||
// +build !appengine
|
// +build !appengine
|
||||||
// +build gc
|
// +build gc
|
||||||
// +build !purego
|
// +build !purego
|
||||||
|
|
||||||
package xxhash
|
package xxhash
|
||||||
|
|
||||||
// Sum64 computes the 64-bit xxHash digest of b.
|
// Sum64 computes the 64-bit xxHash digest of b with a zero seed.
|
||||||
//
|
//
|
||||||
//go:noescape
|
//go:noescape
|
||||||
func Sum64(b []byte) uint64
|
func Sum64(b []byte) uint64
|
||||||
24
vendor/github.com/cespare/xxhash/v2/xxhash_other.go
generated
vendored
24
vendor/github.com/cespare/xxhash/v2/xxhash_other.go
generated
vendored
@@ -1,8 +1,9 @@
|
|||||||
// +build !amd64 appengine !gc purego
|
//go:build (!amd64 && !arm64) || appengine || !gc || purego
|
||||||
|
// +build !amd64,!arm64 appengine !gc purego
|
||||||
|
|
||||||
package xxhash
|
package xxhash
|
||||||
|
|
||||||
// Sum64 computes the 64-bit xxHash digest of b.
|
// Sum64 computes the 64-bit xxHash digest of b with a zero seed.
|
||||||
func Sum64(b []byte) uint64 {
|
func Sum64(b []byte) uint64 {
|
||||||
// A simpler version would be
|
// A simpler version would be
|
||||||
// d := New()
|
// d := New()
|
||||||
@@ -14,10 +15,10 @@ func Sum64(b []byte) uint64 {
|
|||||||
var h uint64
|
var h uint64
|
||||||
|
|
||||||
if n >= 32 {
|
if n >= 32 {
|
||||||
v1 := prime1v + prime2
|
v1 := primes[0] + prime2
|
||||||
v2 := prime2
|
v2 := prime2
|
||||||
v3 := uint64(0)
|
v3 := uint64(0)
|
||||||
v4 := -prime1v
|
v4 := -primes[0]
|
||||||
for len(b) >= 32 {
|
for len(b) >= 32 {
|
||||||
v1 = round(v1, u64(b[0:8:len(b)]))
|
v1 = round(v1, u64(b[0:8:len(b)]))
|
||||||
v2 = round(v2, u64(b[8:16:len(b)]))
|
v2 = round(v2, u64(b[8:16:len(b)]))
|
||||||
@@ -36,19 +37,18 @@ func Sum64(b []byte) uint64 {
|
|||||||
|
|
||||||
h += uint64(n)
|
h += uint64(n)
|
||||||
|
|
||||||
i, end := 0, len(b)
|
for ; len(b) >= 8; b = b[8:] {
|
||||||
for ; i+8 <= end; i += 8 {
|
k1 := round(0, u64(b[:8]))
|
||||||
k1 := round(0, u64(b[i:i+8:len(b)]))
|
|
||||||
h ^= k1
|
h ^= k1
|
||||||
h = rol27(h)*prime1 + prime4
|
h = rol27(h)*prime1 + prime4
|
||||||
}
|
}
|
||||||
if i+4 <= end {
|
if len(b) >= 4 {
|
||||||
h ^= uint64(u32(b[i:i+4:len(b)])) * prime1
|
h ^= uint64(u32(b[:4])) * prime1
|
||||||
h = rol23(h)*prime2 + prime3
|
h = rol23(h)*prime2 + prime3
|
||||||
i += 4
|
b = b[4:]
|
||||||
}
|
}
|
||||||
for ; i < end; i++ {
|
for ; len(b) > 0; b = b[1:] {
|
||||||
h ^= uint64(b[i]) * prime5
|
h ^= uint64(b[0]) * prime5
|
||||||
h = rol11(h) * prime1
|
h = rol11(h) * prime1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
vendor/github.com/cespare/xxhash/v2/xxhash_safe.go
generated
vendored
3
vendor/github.com/cespare/xxhash/v2/xxhash_safe.go
generated
vendored
@@ -1,10 +1,11 @@
|
|||||||
|
//go:build appengine
|
||||||
// +build appengine
|
// +build appengine
|
||||||
|
|
||||||
// This file contains the safe implementations of otherwise unsafe-using code.
|
// This file contains the safe implementations of otherwise unsafe-using code.
|
||||||
|
|
||||||
package xxhash
|
package xxhash
|
||||||
|
|
||||||
// Sum64String computes the 64-bit xxHash digest of s.
|
// Sum64String computes the 64-bit xxHash digest of s with a zero seed.
|
||||||
func Sum64String(s string) uint64 {
|
func Sum64String(s string) uint64 {
|
||||||
return Sum64([]byte(s))
|
return Sum64([]byte(s))
|
||||||
}
|
}
|
||||||
|
|||||||
60
vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go
generated
vendored
60
vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go
generated
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !appengine
|
||||||
// +build !appengine
|
// +build !appengine
|
||||||
|
|
||||||
// This file encapsulates usage of unsafe.
|
// This file encapsulates usage of unsafe.
|
||||||
@@ -6,41 +7,52 @@
|
|||||||
package xxhash
|
package xxhash
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Notes:
|
|
||||||
//
|
|
||||||
// See https://groups.google.com/d/msg/golang-nuts/dcjzJy-bSpw/tcZYBzQqAQAJ
|
|
||||||
// for some discussion about these unsafe conversions.
|
|
||||||
//
|
|
||||||
// In the future it's possible that compiler optimizations will make these
|
// In the future it's possible that compiler optimizations will make these
|
||||||
// unsafe operations unnecessary: https://golang.org/issue/2205.
|
// XxxString functions unnecessary by realizing that calls such as
|
||||||
//
|
// Sum64([]byte(s)) don't need to copy s. See https://go.dev/issue/2205.
|
||||||
// Both of these wrapper functions still incur function call overhead since they
|
// If that happens, even if we keep these functions they can be replaced with
|
||||||
// will not be inlined. We could write Go/asm copies of Sum64 and Digest.Write
|
// the trivial safe code.
|
||||||
// for strings to squeeze out a bit more speed. Mid-stack inlining should
|
|
||||||
// eventually fix this.
|
|
||||||
|
|
||||||
// Sum64String computes the 64-bit xxHash digest of s.
|
// NOTE: The usual way of doing an unsafe string-to-[]byte conversion is:
|
||||||
|
//
|
||||||
|
// var b []byte
|
||||||
|
// bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||||
|
// bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
|
||||||
|
// bh.Len = len(s)
|
||||||
|
// bh.Cap = len(s)
|
||||||
|
//
|
||||||
|
// Unfortunately, as of Go 1.15.3 the inliner's cost model assigns a high enough
|
||||||
|
// weight to this sequence of expressions that any function that uses it will
|
||||||
|
// not be inlined. Instead, the functions below use a different unsafe
|
||||||
|
// conversion designed to minimize the inliner weight and allow both to be
|
||||||
|
// inlined. There is also a test (TestInlining) which verifies that these are
|
||||||
|
// inlined.
|
||||||
|
//
|
||||||
|
// See https://github.com/golang/go/issues/42739 for discussion.
|
||||||
|
|
||||||
|
// Sum64String computes the 64-bit xxHash digest of s with a zero seed.
|
||||||
// It may be faster than Sum64([]byte(s)) by avoiding a copy.
|
// It may be faster than Sum64([]byte(s)) by avoiding a copy.
|
||||||
func Sum64String(s string) uint64 {
|
func Sum64String(s string) uint64 {
|
||||||
var b []byte
|
b := *(*[]byte)(unsafe.Pointer(&sliceHeader{s, len(s)}))
|
||||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
|
||||||
bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
|
|
||||||
bh.Len = len(s)
|
|
||||||
bh.Cap = len(s)
|
|
||||||
return Sum64(b)
|
return Sum64(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteString adds more data to d. It always returns len(s), nil.
|
// WriteString adds more data to d. It always returns len(s), nil.
|
||||||
// It may be faster than Write([]byte(s)) by avoiding a copy.
|
// It may be faster than Write([]byte(s)) by avoiding a copy.
|
||||||
func (d *Digest) WriteString(s string) (n int, err error) {
|
func (d *Digest) WriteString(s string) (n int, err error) {
|
||||||
var b []byte
|
d.Write(*(*[]byte)(unsafe.Pointer(&sliceHeader{s, len(s)})))
|
||||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
// d.Write always returns len(s), nil.
|
||||||
bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
|
// Ignoring the return output and returning these fixed values buys a
|
||||||
bh.Len = len(s)
|
// savings of 6 in the inliner's cost model.
|
||||||
bh.Cap = len(s)
|
return len(s), nil
|
||||||
return d.Write(b)
|
}
|
||||||
|
|
||||||
|
// sliceHeader is similar to reflect.SliceHeader, but it assumes that the layout
|
||||||
|
// of the first two words is the same as the layout of a string.
|
||||||
|
type sliceHeader struct {
|
||||||
|
s string
|
||||||
|
cap int
|
||||||
}
|
}
|
||||||
|
|||||||
15
vendor/github.com/eclipse/paho.mqtt.golang/DISTRIBUTION
generated
vendored
15
vendor/github.com/eclipse/paho.mqtt.golang/DISTRIBUTION
generated
vendored
@@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
Eclipse Distribution License - v 1.0
|
|
||||||
|
|
||||||
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
|
|
||||||
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
296
vendor/github.com/eclipse/paho.mqtt.golang/LICENSE
generated
vendored
296
vendor/github.com/eclipse/paho.mqtt.golang/LICENSE
generated
vendored
@@ -1,20 +1,294 @@
|
|||||||
This project is dual licensed under the Eclipse Public License 1.0 and the
|
Eclipse Public License - v 2.0 (EPL-2.0)
|
||||||
Eclipse Distribution License 1.0 as described in the epl-v10 and edl-v10 files.
|
|
||||||
|
|
||||||
The EDL is copied below in order to pass the pkg.go.dev license check (https://pkg.go.dev/license-policy).
|
This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
For an explanation of what dual-licensing means to you, see:
|
||||||
|
https://www.eclipse.org/legal/eplfaq.php#DUALLIC
|
||||||
|
|
||||||
****
|
****
|
||||||
Eclipse Distribution License - v 1.0
|
The epl-2.0 is copied below in order to pass the pkg.go.dev license check (https://pkg.go.dev/license-policy).
|
||||||
|
****
|
||||||
|
Eclipse Public License - v 2.0
|
||||||
|
|
||||||
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
|
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
|
||||||
|
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
|
||||||
|
OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
||||||
|
|
||||||
All rights reserved.
|
1. DEFINITIONS
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
"Contribution" means:
|
||||||
|
|
||||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
a) in the case of the initial Contributor, the initial content
|
||||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
Distributed under this Agreement, and
|
||||||
Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
b) in the case of each subsequent Contributor:
|
||||||
|
i) changes to the Program, and
|
||||||
|
ii) additions to the Program;
|
||||||
|
where such changes and/or additions to the Program originate from
|
||||||
|
and are Distributed by that particular Contributor. A Contribution
|
||||||
|
"originates" from a Contributor if it was added to the Program by
|
||||||
|
such Contributor itself or anyone acting on such Contributor's behalf.
|
||||||
|
Contributions do not include changes or additions to the Program that
|
||||||
|
are not Modified Works.
|
||||||
|
|
||||||
|
"Contributor" means any person or entity that Distributes the Program.
|
||||||
|
|
||||||
|
"Licensed Patents" mean patent claims licensable by a Contributor which
|
||||||
|
are necessarily infringed by the use or sale of its Contribution alone
|
||||||
|
or when combined with the Program.
|
||||||
|
|
||||||
|
"Program" means the Contributions Distributed in accordance with this
|
||||||
|
Agreement.
|
||||||
|
|
||||||
|
"Recipient" means anyone who receives the Program under this Agreement
|
||||||
|
or any Secondary License (as applicable), including Contributors.
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source Code or other
|
||||||
|
form, that is based on (or derived from) the Program and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship.
|
||||||
|
|
||||||
|
"Modified Works" shall mean any work in Source Code or other form that
|
||||||
|
results from an addition to, deletion from, or modification of the
|
||||||
|
contents of the Program, including, for purposes of clarity any new file
|
||||||
|
in Source Code form that contains any contents of the Program. Modified
|
||||||
|
Works shall not include works that contain only declarations,
|
||||||
|
interfaces, types, classes, structures, or files of the Program solely
|
||||||
|
in each case in order to link to, bind by name, or subclass the Program
|
||||||
|
or Modified Works thereof.
|
||||||
|
|
||||||
|
"Distribute" means the acts of a) distributing or b) making available
|
||||||
|
in any manner that enables the transfer of a copy.
|
||||||
|
|
||||||
|
"Source Code" means the form of a Program preferred for making
|
||||||
|
modifications, including but not limited to software source code,
|
||||||
|
documentation source, and configuration files.
|
||||||
|
|
||||||
|
"Secondary License" means either the GNU General Public License,
|
||||||
|
Version 2.0, or any later versions of that license, including any
|
||||||
|
exceptions or additional permissions as identified by the initial
|
||||||
|
Contributor.
|
||||||
|
|
||||||
|
2. GRANT OF RIGHTS
|
||||||
|
|
||||||
|
a) Subject to the terms of this Agreement, each Contributor hereby
|
||||||
|
grants Recipient a non-exclusive, worldwide, royalty-free copyright
|
||||||
|
license to reproduce, prepare Derivative Works of, publicly display,
|
||||||
|
publicly perform, Distribute and sublicense the Contribution of such
|
||||||
|
Contributor, if any, and such Derivative Works.
|
||||||
|
|
||||||
|
b) Subject to the terms of this Agreement, each Contributor hereby
|
||||||
|
grants Recipient a non-exclusive, worldwide, royalty-free patent
|
||||||
|
license under Licensed Patents to make, use, sell, offer to sell,
|
||||||
|
import and otherwise transfer the Contribution of such Contributor,
|
||||||
|
if any, in Source Code or other form. This patent license shall
|
||||||
|
apply to the combination of the Contribution and the Program if, at
|
||||||
|
the time the Contribution is added by the Contributor, such addition
|
||||||
|
of the Contribution causes such combination to be covered by the
|
||||||
|
Licensed Patents. The patent license shall not apply to any other
|
||||||
|
combinations which include the Contribution. No hardware per se is
|
||||||
|
licensed hereunder.
|
||||||
|
|
||||||
|
c) Recipient understands that although each Contributor grants the
|
||||||
|
licenses to its Contributions set forth herein, no assurances are
|
||||||
|
provided by any Contributor that the Program does not infringe the
|
||||||
|
patent or other intellectual property rights of any other entity.
|
||||||
|
Each Contributor disclaims any liability to Recipient for claims
|
||||||
|
brought by any other entity based on infringement of intellectual
|
||||||
|
property rights or otherwise. As a condition to exercising the
|
||||||
|
rights and licenses granted hereunder, each Recipient hereby
|
||||||
|
assumes sole responsibility to secure any other intellectual
|
||||||
|
property rights needed, if any. For example, if a third party
|
||||||
|
patent license is required to allow Recipient to Distribute the
|
||||||
|
Program, it is Recipient's responsibility to acquire that license
|
||||||
|
before distributing the Program.
|
||||||
|
|
||||||
|
d) Each Contributor represents that to its knowledge it has
|
||||||
|
sufficient copyright rights in its Contribution, if any, to grant
|
||||||
|
the copyright license set forth in this Agreement.
|
||||||
|
|
||||||
|
e) Notwithstanding the terms of any Secondary License, no
|
||||||
|
Contributor makes additional grants to any Recipient (other than
|
||||||
|
those set forth in this Agreement) as a result of such Recipient's
|
||||||
|
receipt of the Program under the terms of a Secondary License
|
||||||
|
(if permitted under the terms of Section 3).
|
||||||
|
|
||||||
|
3. REQUIREMENTS
|
||||||
|
|
||||||
|
3.1 If a Contributor Distributes the Program in any form, then:
|
||||||
|
|
||||||
|
a) the Program must also be made available as Source Code, in
|
||||||
|
accordance with section 3.2, and the Contributor must accompany
|
||||||
|
the Program with a statement that the Source Code for the Program
|
||||||
|
is available under this Agreement, and informs Recipients how to
|
||||||
|
obtain it in a reasonable manner on or through a medium customarily
|
||||||
|
used for software exchange; and
|
||||||
|
|
||||||
|
b) the Contributor may Distribute the Program under a license
|
||||||
|
different than this Agreement, provided that such license:
|
||||||
|
i) effectively disclaims on behalf of all other Contributors all
|
||||||
|
warranties and conditions, express and implied, including
|
||||||
|
warranties or conditions of title and non-infringement, and
|
||||||
|
implied warranties or conditions of merchantability and fitness
|
||||||
|
for a particular purpose;
|
||||||
|
|
||||||
|
ii) effectively excludes on behalf of all other Contributors all
|
||||||
|
liability for damages, including direct, indirect, special,
|
||||||
|
incidental and consequential damages, such as lost profits;
|
||||||
|
|
||||||
|
iii) does not attempt to limit or alter the recipients' rights
|
||||||
|
in the Source Code under section 3.2; and
|
||||||
|
|
||||||
|
iv) requires any subsequent distribution of the Program by any
|
||||||
|
party to be under a license that satisfies the requirements
|
||||||
|
of this section 3.
|
||||||
|
|
||||||
|
3.2 When the Program is Distributed as Source Code:
|
||||||
|
|
||||||
|
a) it must be made available under this Agreement, or if the
|
||||||
|
Program (i) is combined with other material in a separate file or
|
||||||
|
files made available under a Secondary License, and (ii) the initial
|
||||||
|
Contributor attached to the Source Code the notice described in
|
||||||
|
Exhibit A of this Agreement, then the Program may be made available
|
||||||
|
under the terms of such Secondary Licenses, and
|
||||||
|
|
||||||
|
b) a copy of this Agreement must be included with each copy of
|
||||||
|
the Program.
|
||||||
|
|
||||||
|
3.3 Contributors may not remove or alter any copyright, patent,
|
||||||
|
trademark, attribution notices, disclaimers of warranty, or limitations
|
||||||
|
of liability ("notices") contained within the Program from any copy of
|
||||||
|
the Program which they Distribute, provided that Contributors may add
|
||||||
|
their own appropriate notices.
|
||||||
|
|
||||||
|
4. COMMERCIAL DISTRIBUTION
|
||||||
|
|
||||||
|
Commercial distributors of software may accept certain responsibilities
|
||||||
|
with respect to end users, business partners and the like. While this
|
||||||
|
license is intended to facilitate the commercial use of the Program,
|
||||||
|
the Contributor who includes the Program in a commercial product
|
||||||
|
offering should do so in a manner which does not create potential
|
||||||
|
liability for other Contributors. Therefore, if a Contributor includes
|
||||||
|
the Program in a commercial product offering, such Contributor
|
||||||
|
("Commercial Contributor") hereby agrees to defend and indemnify every
|
||||||
|
other Contributor ("Indemnified Contributor") against any losses,
|
||||||
|
damages and costs (collectively "Losses") arising from claims, lawsuits
|
||||||
|
and other legal actions brought by a third party against the Indemnified
|
||||||
|
Contributor to the extent caused by the acts or omissions of such
|
||||||
|
Commercial Contributor in connection with its distribution of the Program
|
||||||
|
in a commercial product offering. The obligations in this section do not
|
||||||
|
apply to any claims or Losses relating to any actual or alleged
|
||||||
|
intellectual property infringement. In order to qualify, an Indemnified
|
||||||
|
Contributor must: a) promptly notify the Commercial Contributor in
|
||||||
|
writing of such claim, and b) allow the Commercial Contributor to control,
|
||||||
|
and cooperate with the Commercial Contributor in, the defense and any
|
||||||
|
related settlement negotiations. The Indemnified Contributor may
|
||||||
|
participate in any such claim at its own expense.
|
||||||
|
|
||||||
|
For example, a Contributor might include the Program in a commercial
|
||||||
|
product offering, Product X. That Contributor is then a Commercial
|
||||||
|
Contributor. If that Commercial Contributor then makes performance
|
||||||
|
claims, or offers warranties related to Product X, those performance
|
||||||
|
claims and warranties are such Commercial Contributor's responsibility
|
||||||
|
alone. Under this section, the Commercial Contributor would have to
|
||||||
|
defend claims against the other Contributors related to those performance
|
||||||
|
claims and warranties, and if a court requires any other Contributor to
|
||||||
|
pay any damages as a result, the Commercial Contributor must pay
|
||||||
|
those damages.
|
||||||
|
|
||||||
|
5. NO WARRANTY
|
||||||
|
|
||||||
|
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
||||||
|
PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS"
|
||||||
|
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF
|
||||||
|
TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. Each Recipient is solely responsible for determining the
|
||||||
|
appropriateness of using and distributing the Program and assumes all
|
||||||
|
risks associated with its exercise of rights under this Agreement,
|
||||||
|
including but not limited to the risks and costs of program errors,
|
||||||
|
compliance with applicable laws, damage to or loss of data, programs
|
||||||
|
or equipment, and unavailability or interruption of operations.
|
||||||
|
|
||||||
|
6. DISCLAIMER OF LIABILITY
|
||||||
|
|
||||||
|
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
||||||
|
PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS
|
||||||
|
SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
|
||||||
|
PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
|
||||||
|
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
7. GENERAL
|
||||||
|
|
||||||
|
If any provision of this Agreement is invalid or unenforceable under
|
||||||
|
applicable law, it shall not affect the validity or enforceability of
|
||||||
|
the remainder of the terms of this Agreement, and without further
|
||||||
|
action by the parties hereto, such provision shall be reformed to the
|
||||||
|
minimum extent necessary to make such provision valid and enforceable.
|
||||||
|
|
||||||
|
If Recipient institutes patent litigation against any entity
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that the
|
||||||
|
Program itself (excluding combinations of the Program with other software
|
||||||
|
or hardware) infringes such Recipient's patent(s), then such Recipient's
|
||||||
|
rights granted under Section 2(b) shall terminate as of the date such
|
||||||
|
litigation is filed.
|
||||||
|
|
||||||
|
All Recipient's rights under this Agreement shall terminate if it
|
||||||
|
fails to comply with any of the material terms or conditions of this
|
||||||
|
Agreement and does not cure such failure in a reasonable period of
|
||||||
|
time after becoming aware of such noncompliance. If all Recipient's
|
||||||
|
rights under this Agreement terminate, Recipient agrees to cease use
|
||||||
|
and distribution of the Program as soon as reasonably practicable.
|
||||||
|
However, Recipient's obligations under this Agreement and any licenses
|
||||||
|
granted by Recipient relating to the Program shall continue and survive.
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute copies of this Agreement,
|
||||||
|
but in order to avoid inconsistency the Agreement is copyrighted and
|
||||||
|
may only be modified in the following manner. The Agreement Steward
|
||||||
|
reserves the right to publish new versions (including revisions) of
|
||||||
|
this Agreement from time to time. No one other than the Agreement
|
||||||
|
Steward has the right to modify this Agreement. The Eclipse Foundation
|
||||||
|
is the initial Agreement Steward. The Eclipse Foundation may assign the
|
||||||
|
responsibility to serve as the Agreement Steward to a suitable separate
|
||||||
|
entity. Each new version of the Agreement will be given a distinguishing
|
||||||
|
version number. The Program (including Contributions) may always be
|
||||||
|
Distributed subject to the version of the Agreement under which it was
|
||||||
|
received. In addition, after a new version of the Agreement is published,
|
||||||
|
Contributor may elect to Distribute the Program (including its
|
||||||
|
Contributions) under the new version.
|
||||||
|
|
||||||
|
Except as expressly stated in Sections 2(a) and 2(b) above, Recipient
|
||||||
|
receives no rights or licenses to the intellectual property of any
|
||||||
|
Contributor under this Agreement, whether expressly, by implication,
|
||||||
|
estoppel or otherwise. All rights in the Program not expressly granted
|
||||||
|
under this Agreement are reserved. Nothing in this Agreement is intended
|
||||||
|
to be enforceable by any entity that is not a Contributor or Recipient.
|
||||||
|
No third-party beneficiary rights are created under this Agreement.
|
||||||
|
|
||||||
|
Exhibit A - Form of Secondary Licenses Notice
|
||||||
|
|
||||||
|
"This Source Code may also be made available under the following
|
||||||
|
Secondary Licenses when the conditions for such availability set forth
|
||||||
|
in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
|
||||||
|
version(s), and exceptions or additional permissions here}."
|
||||||
|
|
||||||
|
Simply including a copy of this Agreement, including this Exhibit A
|
||||||
|
is not sufficient to license the Source Code under Secondary Licenses.
|
||||||
|
|
||||||
|
If it is not possible or desirable to put the notice in a particular
|
||||||
|
file, then You may include the notice in a location (such as a LICENSE
|
||||||
|
file in a relevant directory) where a recipient would be likely to
|
||||||
|
look for such a notice.
|
||||||
|
|
||||||
|
You may add additional accurate notices of copyright ownership.
|
||||||
|
|||||||
77
vendor/github.com/eclipse/paho.mqtt.golang/NOTICE.md
generated
vendored
Normal file
77
vendor/github.com/eclipse/paho.mqtt.golang/NOTICE.md
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# Notices for paho.mqtt.golang
|
||||||
|
|
||||||
|
This content is produced and maintained by the Eclipse Paho project.
|
||||||
|
|
||||||
|
* Project home: https://www.eclipse.org/paho/
|
||||||
|
|
||||||
|
Note that a [separate mqtt v5 client](https://github.com/eclipse/paho.golang) also exists (this is a full rewrite
|
||||||
|
and deliberately incompatible with this library).
|
||||||
|
|
||||||
|
## Trademarks
|
||||||
|
|
||||||
|
Eclipse Mosquitto trademarks of the Eclipse Foundation. Eclipse, and the
|
||||||
|
Eclipse Logo are registered trademarks of the Eclipse Foundation.
|
||||||
|
|
||||||
|
Paho is a trademark of the Eclipse Foundation. Eclipse, and the Eclipse Logo are
|
||||||
|
registered trademarks of the Eclipse Foundation.
|
||||||
|
|
||||||
|
## Copyright
|
||||||
|
|
||||||
|
All content is the property of the respective authors or their employers.
|
||||||
|
For more information regarding authorship of content, please consult the
|
||||||
|
listed source code repository logs.
|
||||||
|
|
||||||
|
## Declared Project Licenses
|
||||||
|
|
||||||
|
This program and the accompanying materials are made available under the terms of the
|
||||||
|
Eclipse Public License v2.0 and Eclipse Distribution License v1.0 which accompany this
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
For an explanation of what dual-licensing means to you, see:
|
||||||
|
https://www.eclipse.org/legal/eplfaq.php#DUALLIC
|
||||||
|
|
||||||
|
SPDX-License-Identifier: EPL-2.0 or BSD-3-Clause
|
||||||
|
|
||||||
|
## Source Code
|
||||||
|
|
||||||
|
The project maintains the following source code repositories:
|
||||||
|
|
||||||
|
* https://github.com/eclipse/paho.mqtt.golang
|
||||||
|
|
||||||
|
## Third-party Content
|
||||||
|
|
||||||
|
This project makes use of the follow third party projects.
|
||||||
|
|
||||||
|
Go Programming Language and Standard Library
|
||||||
|
|
||||||
|
* License: BSD-style license (https://golang.org/LICENSE)
|
||||||
|
* Project: https://golang.org/
|
||||||
|
|
||||||
|
Go Networking
|
||||||
|
|
||||||
|
* License: BSD 3-Clause style license and patent grant.
|
||||||
|
* Project: https://cs.opensource.google/go/x/net
|
||||||
|
|
||||||
|
Go Sync
|
||||||
|
|
||||||
|
* License: BSD 3-Clause style license and patent grant.
|
||||||
|
* Project: https://cs.opensource.google/go/x/sync/
|
||||||
|
|
||||||
|
Gorilla Websockets v1.4.2
|
||||||
|
|
||||||
|
* License: BSD 2-Clause "Simplified" License
|
||||||
|
* Project: https://github.com/gorilla/websocket
|
||||||
|
|
||||||
|
## Cryptography
|
||||||
|
|
||||||
|
Content may contain encryption software. The country in which you are currently
|
||||||
|
may have restrictions on the import, possession, and use, and/or re-export to
|
||||||
|
another country, of encryption software. BEFORE using any encryption software,
|
||||||
|
please check the country's laws, regulations and policies concerning the import,
|
||||||
|
possession, or use, and re-export of encryption software, to see if this is
|
||||||
|
permitted.
|
||||||
55
vendor/github.com/eclipse/paho.mqtt.golang/README.md
generated
vendored
55
vendor/github.com/eclipse/paho.mqtt.golang/README.md
generated
vendored
@@ -111,36 +111,56 @@ identifier; this is as per the [spec](https://docs.oasis-open.org/mqtt/mqtt/v3.1
|
|||||||
`ClientOptions.SetOrderMatters(false)` set). If you wish to perform a long-running task, or publish a message, then
|
`ClientOptions.SetOrderMatters(false)` set). If you wish to perform a long-running task, or publish a message, then
|
||||||
please use a go routine (blocking in the handler is a common cause of unexpected `pingresp
|
please use a go routine (blocking in the handler is a common cause of unexpected `pingresp
|
||||||
not received, disconnecting` errors).
|
not received, disconnecting` errors).
|
||||||
* When QOS1+ subscriptions have been created previously and you connect with `CleanSession` set to false it is possible that the broker will deliver retained
|
* When QOS1+ subscriptions have been created previously and you connect with `CleanSession` set to false it is possible
|
||||||
messages before `Subscribe` can be called. To process these messages either configure a handler with `AddRoute` or
|
that the broker will deliver retained messages before `Subscribe` can be called. To process these messages either
|
||||||
set a `DefaultPublishHandler`.
|
configure a handler with `AddRoute` or set a `DefaultPublishHandler`. If there is no handler (or `DefaultPublishHandler`)
|
||||||
|
then inbound messages will not be acknowledged. Adding a handler (even if it's `opts.SetDefaultPublishHandler(func(mqtt.Client, mqtt.Message) {})`)
|
||||||
|
is highly recommended to avoid inadvertently hitting inflight message limits.
|
||||||
* Loss of network connectivity may not be detected immediately. If this is an issue then consider setting
|
* Loss of network connectivity may not be detected immediately. If this is an issue then consider setting
|
||||||
`ClientOptions.KeepAlive` (sends regular messages to check the link is active).
|
`ClientOptions.KeepAlive` (sends regular messages to check the link is active).
|
||||||
* Brokers offer many configuration options; some settings may lead to unexpected results. If using Mosquitto check
|
* Reusing a `Client` is not completely safe. After calling `Disconnect` please create a new Client (`NewClient()`) rather
|
||||||
`max_inflight_messages`, `max_queued_messages`, `persistence` (the defaults may not be what you expect).
|
than attempting to reuse the existing one (note that features such as `SetAutoReconnect` mean this is rarely necessary).
|
||||||
|
* Brokers offer many configuration options; some settings may lead to unexpected results.
|
||||||
|
* Publish tokens will complete if the connection is lost and re-established using the default
|
||||||
|
options.SetAutoReconnect(true) functionality (token.Error() will return nil). Attempts will be made to re-deliver the
|
||||||
|
message but there is currently no easy way know when such messages are delivered.
|
||||||
|
|
||||||
|
If using Mosquitto then there are a range of fairly common issues:
|
||||||
|
* `listener` - By default [Mosquitto v2+](https://mosquitto.org/documentation/migrating-to-2-0/) listens on loopback
|
||||||
|
interfaces only (meaning it will only accept connections made from the computer its running on).
|
||||||
|
* `max_inflight_messages` - Unless this is set to 1 mosquitto does not guarantee ordered delivery of messages.
|
||||||
|
* `max_queued_messages` / `max_queued_bytes` - These impose limits on the number/size of queued messages. The defaults
|
||||||
|
may lead to messages being silently dropped.
|
||||||
|
* `persistence` - Defaults to false (messages will not survive a broker restart)
|
||||||
|
* `max_keepalive` - defaults to 65535 and, from version 2.0.12, `SetKeepAlive(0)` will result in a rejected connection
|
||||||
|
by default.
|
||||||
|
|
||||||
Reporting bugs
|
Reporting bugs
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Please report bugs by raising issues for this project in github https://github.com/eclipse/paho.mqtt.golang/issues
|
Please report bugs by raising issues for this project in github https://github.com/eclipse/paho.mqtt.golang/issues
|
||||||
|
|
||||||
*A limited number of contributors monitor the issues section so if you have a general question please consider the
|
A limited number of contributors monitor the issues section so if you have a general question please see the
|
||||||
resources in the [more information](#more-information) section (your question will be seen by more people, and you are
|
resources in the [more information](#more-information) section for help.
|
||||||
likely to receive an answer more quickly).*
|
|
||||||
|
|
||||||
We welcome bug reports, but it is important they are actionable. A significant percentage of issues reported are not
|
We welcome bug reports, but it is important they are actionable. A significant percentage of issues reported are not
|
||||||
resolved due to a lack of information. If we cannot replicate the problem then it is unlikely we will be able to fix it.
|
resolved due to a lack of information. If we cannot replicate the problem then it is unlikely we will be able to fix it.
|
||||||
The information required will vary from issue to issue but consider including:
|
The information required will vary from issue to issue but almost all bug reports would be expected to include:
|
||||||
|
|
||||||
* Which version of the package you are using (tag or commit - this should be in your go.mod file)
|
* Which version of the package you are using (tag or commit - this should be in your `go.mod` file)
|
||||||
|
* A full, clear, description of the problem (detail what you are expecting vs what actually happens).
|
||||||
|
* Configuration information (code showing how you connect, please include all references to `ClientOption`)
|
||||||
|
* Broker details (name and version).
|
||||||
|
|
||||||
|
If at all possible please also include:
|
||||||
|
* Details of your attempts to resolve the issue (what have you tried, what worked, what did not).
|
||||||
* A [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Providing an example
|
* A [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Providing an example
|
||||||
is the best way to demonstrate the issue you are facing; it is important this includes all relevant information
|
is the best way to demonstrate the issue you are facing; it is important this includes all relevant information
|
||||||
(including broker configuration). Docker (see `cmd/docker`) makes it relatively simple to provide a working end-to-end
|
(including broker configuration). Docker (see `cmd/docker`) makes it relatively simple to provide a working end-to-end
|
||||||
example.
|
example.
|
||||||
* A full, clear, description of the problem (detail what you are expecting vs what actually happens).
|
* Broker logs covering the period the issue occurred.
|
||||||
* Details of your attempts to resolve the issue (what have you tried, what worked, what did not).
|
* [Application Logs](#logging) covering the period the issue occurred. Unless you have isolated the root cause of the
|
||||||
* [Application Logs](#logging) covering the period the issue occurred. Unless you have isolated the root cause of the issue please include a link to a full log (including data from well before the problem arose).
|
issue please include a link to a full log (including data from well before the problem arose).
|
||||||
* Broker Logs covering the period the issue occurred.
|
|
||||||
|
|
||||||
It is important to remember that this library does not stand alone; it communicates with a broker and any issues you are
|
It is important to remember that this library does not stand alone; it communicates with a broker and any issues you are
|
||||||
seeing may be due to:
|
seeing may be due to:
|
||||||
@@ -167,11 +187,12 @@ note of the requirement that the commit record contain a "Signed-off-by" entry.
|
|||||||
More information
|
More information
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
[Stack Overflow](https://stackoverflow.com/questions/tagged/mqtt+go) has a range questions/answers covering a range of
|
||||||
|
common issues (both relating to use of this library and MQTT in general). This is the best place to ask general questions
|
||||||
|
(including those relating to the use of this library).
|
||||||
|
|
||||||
Discussion of the Paho clients takes place on the [Eclipse paho-dev mailing list](https://dev.eclipse.org/mailman/listinfo/paho-dev).
|
Discussion of the Paho clients takes place on the [Eclipse paho-dev mailing list](https://dev.eclipse.org/mailman/listinfo/paho-dev).
|
||||||
|
|
||||||
General questions about the MQTT protocol are discussed in the [MQTT Google Group](https://groups.google.com/forum/?hl=en-US&fromgroups#!forum/mqtt).
|
General questions about the MQTT protocol are discussed in the [MQTT Google Group](https://groups.google.com/forum/?hl=en-US&fromgroups#!forum/mqtt).
|
||||||
|
|
||||||
There is much more information available via the [MQTT community site](http://mqtt.org).
|
There is much more information available via the [MQTT community site](http://mqtt.org).
|
||||||
|
|
||||||
[Stack Overflow](https://stackoverflow.com/questions/tagged/mqtt+go) has a range questions covering a range of common
|
|
||||||
issues (both relating to use of this library and MQTT in general).
|
|
||||||
|
|||||||
41
vendor/github.com/eclipse/paho.mqtt.golang/about.html
generated
vendored
41
vendor/github.com/eclipse/paho.mqtt.golang/about.html
generated
vendored
@@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
||||||
<title>About</title>
|
|
||||||
</head>
|
|
||||||
<body lang="EN-US">
|
|
||||||
<h2>About This Content</h2>
|
|
||||||
|
|
||||||
<p><em>December 9, 2013</em></p>
|
|
||||||
<h3>License</h3>
|
|
||||||
|
|
||||||
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
|
|
||||||
indicated below, the Content is provided to you under the terms and conditions of the
|
|
||||||
Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL").
|
|
||||||
A copy of the EPL is available at
|
|
||||||
<a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>
|
|
||||||
and a copy of the EDL is available at
|
|
||||||
<a href="http://www.eclipse.org/org/documents/edl-v10.php">http://www.eclipse.org/org/documents/edl-v10.php</a>.
|
|
||||||
For purposes of the EPL, "Program" will mean the Content.</p>
|
|
||||||
|
|
||||||
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
|
|
||||||
being redistributed by another party ("Redistributor") and different terms and conditions may
|
|
||||||
apply to your use of any object code in the Content. Check the Redistributor's license that was
|
|
||||||
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
|
|
||||||
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
|
|
||||||
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Third Party Content</h3>
|
|
||||||
<p>The Content includes items that have been sourced from third parties as set out below. If you
|
|
||||||
did not receive this Content directly from the Eclipse Foundation, the following is provided
|
|
||||||
for informational purposes only, and you should look to the Redistributor's license for
|
|
||||||
terms and conditions of use.</p>
|
|
||||||
<p><em>
|
|
||||||
<strong>None</strong> <br><br>
|
|
||||||
<br><br>
|
|
||||||
</em></p>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body></html>
|
|
||||||
104
vendor/github.com/eclipse/paho.mqtt.golang/backoff.go
generated
vendored
Normal file
104
vendor/github.com/eclipse/paho.mqtt.golang/backoff.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Matt Brittan
|
||||||
|
* Daichi Tomaru
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Controller for sleep with backoff when the client attempts reconnection
|
||||||
|
// It has statuses for each situations cause reconnection.
|
||||||
|
type backoffController struct {
|
||||||
|
sync.RWMutex
|
||||||
|
statusMap map[string]*backoffStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
type backoffStatus struct {
|
||||||
|
lastSleepPeriod time.Duration
|
||||||
|
lastErrorTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBackoffController() *backoffController {
|
||||||
|
return &backoffController{
|
||||||
|
statusMap: map[string]*backoffStatus{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate next sleep period from the specified parameters.
|
||||||
|
// Returned values are next sleep period and whether the error situation is continual.
|
||||||
|
// If connection errors continuouslly occurs, its sleep period is exponentially increased.
|
||||||
|
// Also if there is a lot of time between last and this error, sleep period is initialized.
|
||||||
|
func (b *backoffController) getBackoffSleepTime(
|
||||||
|
situation string, initSleepPeriod time.Duration, maxSleepPeriod time.Duration, processTime time.Duration, skipFirst bool,
|
||||||
|
) (time.Duration, bool) {
|
||||||
|
// Decide first sleep time if the situation is not continual.
|
||||||
|
var firstProcess = func(status *backoffStatus, init time.Duration, skip bool) (time.Duration, bool) {
|
||||||
|
if skip {
|
||||||
|
status.lastSleepPeriod = 0
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
status.lastSleepPeriod = init
|
||||||
|
return init, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prioritize maxSleep.
|
||||||
|
if initSleepPeriod > maxSleepPeriod {
|
||||||
|
initSleepPeriod = maxSleepPeriod
|
||||||
|
}
|
||||||
|
b.Lock()
|
||||||
|
defer b.Unlock()
|
||||||
|
|
||||||
|
status, exist := b.statusMap[situation]
|
||||||
|
if !exist {
|
||||||
|
b.statusMap[situation] = &backoffStatus{initSleepPeriod, time.Now()}
|
||||||
|
return firstProcess(b.statusMap[situation], initSleepPeriod, skipFirst)
|
||||||
|
}
|
||||||
|
|
||||||
|
oldTime := status.lastErrorTime
|
||||||
|
status.lastErrorTime = time.Now()
|
||||||
|
|
||||||
|
// When there is a lot of time between last and this error, sleep period is initialized.
|
||||||
|
if status.lastErrorTime.Sub(oldTime) > (processTime * 2 + status.lastSleepPeriod) {
|
||||||
|
return firstProcess(status, initSleepPeriod, skipFirst)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status.lastSleepPeriod == 0 {
|
||||||
|
status.lastSleepPeriod = initSleepPeriod
|
||||||
|
return initSleepPeriod, true
|
||||||
|
}
|
||||||
|
|
||||||
|
if nextSleepPeriod := status.lastSleepPeriod * 2; nextSleepPeriod <= maxSleepPeriod {
|
||||||
|
status.lastSleepPeriod = nextSleepPeriod
|
||||||
|
} else {
|
||||||
|
status.lastSleepPeriod = maxSleepPeriod
|
||||||
|
}
|
||||||
|
|
||||||
|
return status.lastSleepPeriod, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute sleep the time returned from getBackoffSleepTime.
|
||||||
|
func (b *backoffController) sleepWithBackoff(
|
||||||
|
situation string, initSleepPeriod time.Duration, maxSleepPeriod time.Duration, processTime time.Duration, skipFirst bool,
|
||||||
|
) (time.Duration, bool) {
|
||||||
|
sleep, isFirst := b.getBackoffSleepTime(situation, initSleepPeriod, maxSleepPeriod, processTime, skipFirst)
|
||||||
|
if sleep != 0 {
|
||||||
|
time.Sleep(sleep)
|
||||||
|
}
|
||||||
|
return sleep, isFirst
|
||||||
|
}
|
||||||
448
vendor/github.com/eclipse/paho.mqtt.golang/client.go
generated
vendored
448
vendor/github.com/eclipse/paho.mqtt.golang/client.go
generated
vendored
@@ -1,15 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
* Allan Stockdill-Mander
|
* Allan Stockdill-Mander
|
||||||
* Mike Robertson
|
* Mike Robertson
|
||||||
|
* Matt Brittan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Portions copyright © 2018 TIBCO Software Inc.
|
// Portions copyright © 2018 TIBCO Software Inc.
|
||||||
@@ -19,6 +24,7 @@ package mqtt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@@ -27,14 +33,9 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eclipse/paho.mqtt.golang/packets"
|
"golang.org/x/sync/semaphore"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
disconnected uint32 = iota
|
|
||||||
connecting
|
|
||||||
reconnecting
|
|
||||||
connected
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client is the interface definition for a Client as used by this
|
// Client is the interface definition for a Client as used by this
|
||||||
@@ -44,9 +45,12 @@ const (
|
|||||||
// with an MQTT server using non-blocking methods that allow work
|
// with an MQTT server using non-blocking methods that allow work
|
||||||
// to be done in the background.
|
// to be done in the background.
|
||||||
// An application may connect to an MQTT server using:
|
// An application may connect to an MQTT server using:
|
||||||
// A plain TCP socket
|
//
|
||||||
// A secure SSL/TLS socket
|
// A plain TCP socket (e.g. mqtt://test.mosquitto.org:1833)
|
||||||
// A websocket
|
// A secure SSL/TLS socket (e.g. tls://test.mosquitto.org:8883)
|
||||||
|
// A websocket (e.g ws://test.mosquitto.org:8080 or wss://test.mosquitto.org:8081)
|
||||||
|
// Something else (using `options.CustomOpenConnectionFn`)
|
||||||
|
//
|
||||||
// To enable ensured message delivery at Quality of Service (QoS) levels
|
// To enable ensured message delivery at Quality of Service (QoS) levels
|
||||||
// described in the MQTT spec, a message persistence mechanism must be
|
// described in the MQTT spec, a message persistence mechanism must be
|
||||||
// used. This is done by providing a type which implements the Store
|
// used. This is done by providing a type which implements the Store
|
||||||
@@ -120,8 +124,7 @@ type client struct {
|
|||||||
lastReceived atomic.Value // time.Time - the last time a packet was successfully received from network
|
lastReceived atomic.Value // time.Time - the last time a packet was successfully received from network
|
||||||
pingOutstanding int32 // set to 1 if a ping has been sent but response not ret received
|
pingOutstanding int32 // set to 1 if a ping has been sent but response not ret received
|
||||||
|
|
||||||
status uint32 // see const definitions at top of file for possible values
|
status connectionStatus // see constants in status.go for values
|
||||||
sync.RWMutex // Protects the above two variables (note: atomic writes are also used somewhat inconsistently)
|
|
||||||
|
|
||||||
messageIds // effectively a map from message id to token completor
|
messageIds // effectively a map from message id to token completor
|
||||||
|
|
||||||
@@ -138,6 +141,8 @@ type client struct {
|
|||||||
stop chan struct{} // Closed to request that workers stop
|
stop chan struct{} // Closed to request that workers stop
|
||||||
workers sync.WaitGroup // used to wait for workers to complete (ping, keepalive, errwatch, resume)
|
workers sync.WaitGroup // used to wait for workers to complete (ping, keepalive, errwatch, resume)
|
||||||
commsStopped chan struct{} // closed when the comms routines have stopped (kept running until after workers have closed to avoid deadlocks)
|
commsStopped chan struct{} // closed when the comms routines have stopped (kept running until after workers have closed to avoid deadlocks)
|
||||||
|
|
||||||
|
backoff *backoffController
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient will create an MQTT v3.1.1 client with all of the options specified
|
// NewClient will create an MQTT v3.1.1 client with all of the options specified
|
||||||
@@ -161,12 +166,12 @@ func NewClient(o *ClientOptions) Client {
|
|||||||
c.options.protocolVersionExplicit = false
|
c.options.protocolVersionExplicit = false
|
||||||
}
|
}
|
||||||
c.persist = c.options.Store
|
c.persist = c.options.Store
|
||||||
c.status = disconnected
|
|
||||||
c.messageIds = messageIds{index: make(map[uint16]tokenCompletor)}
|
c.messageIds = messageIds{index: make(map[uint16]tokenCompletor)}
|
||||||
c.msgRouter = newRouter()
|
c.msgRouter = newRouter()
|
||||||
c.msgRouter.setDefaultHandler(c.options.DefaultPublishHandler)
|
c.msgRouter.setDefaultHandler(c.options.DefaultPublishHandler)
|
||||||
c.obound = make(chan *PacketAndToken)
|
c.obound = make(chan *PacketAndToken)
|
||||||
c.oboundP = make(chan *PacketAndToken)
|
c.oboundP = make(chan *PacketAndToken)
|
||||||
|
c.backoff = newBackoffController()
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,47 +193,27 @@ func (c *client) AddRoute(topic string, callback MessageHandler) {
|
|||||||
// the client is connected or not.
|
// the client is connected or not.
|
||||||
// connected means that the connection is up now OR it will
|
// connected means that the connection is up now OR it will
|
||||||
// be established/reestablished automatically when possible
|
// be established/reestablished automatically when possible
|
||||||
|
// Warning: The connection status may change at any time so use this with care!
|
||||||
func (c *client) IsConnected() bool {
|
func (c *client) IsConnected() bool {
|
||||||
c.RLock()
|
// This will need to change if additional statuses are added
|
||||||
defer c.RUnlock()
|
s, r := c.status.ConnectionStatusRetry()
|
||||||
status := atomic.LoadUint32(&c.status)
|
|
||||||
switch {
|
switch {
|
||||||
case status == connected:
|
case s == connected:
|
||||||
return true
|
return true
|
||||||
case c.options.AutoReconnect && status > connecting:
|
case c.options.ConnectRetry && s == connecting:
|
||||||
return true
|
|
||||||
case c.options.ConnectRetry && status == connecting:
|
|
||||||
return true
|
return true
|
||||||
|
case c.options.AutoReconnect:
|
||||||
|
return s == reconnecting || (s == disconnecting && r) // r indicates we will reconnect
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsConnectionOpen return a bool signifying whether the client has an active
|
// IsConnectionOpen return a bool signifying whether the client has an active
|
||||||
// connection to mqtt broker, i.e not in disconnected or reconnect mode
|
// connection to mqtt broker, i.e. not in disconnected or reconnect mode
|
||||||
|
// Warning: The connection status may change at any time so use this with care!
|
||||||
func (c *client) IsConnectionOpen() bool {
|
func (c *client) IsConnectionOpen() bool {
|
||||||
c.RLock()
|
return c.status.ConnectionStatus() == connected
|
||||||
defer c.RUnlock()
|
|
||||||
status := atomic.LoadUint32(&c.status)
|
|
||||||
switch {
|
|
||||||
case status == connected:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *client) connectionStatus() uint32 {
|
|
||||||
c.RLock()
|
|
||||||
defer c.RUnlock()
|
|
||||||
status := atomic.LoadUint32(&c.status)
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *client) setConnected(status uint32) {
|
|
||||||
c.Lock()
|
|
||||||
defer c.Unlock()
|
|
||||||
atomic.StoreUint32(&c.status, status)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrNotConnected is the error returned from function calls that are
|
// ErrNotConnected is the error returned from function calls that are
|
||||||
@@ -245,58 +230,69 @@ func (c *client) Connect() Token {
|
|||||||
t := newToken(packets.Connect).(*ConnectToken)
|
t := newToken(packets.Connect).(*ConnectToken)
|
||||||
DEBUG.Println(CLI, "Connect()")
|
DEBUG.Println(CLI, "Connect()")
|
||||||
|
|
||||||
if c.options.ConnectRetry && atomic.LoadUint32(&c.status) != disconnected {
|
connectionUp, err := c.status.Connecting()
|
||||||
// if in any state other than disconnected and ConnectRetry is
|
if err != nil {
|
||||||
// enabled then the connection will come up automatically
|
if err == errAlreadyConnectedOrReconnecting && c.options.AutoReconnect {
|
||||||
// client can assume connection is up
|
// When reconnection is active we don't consider calls tro Connect to ba an error (mainly for compatability)
|
||||||
WARN.Println(CLI, "Connect() called but not disconnected")
|
WARN.Println(CLI, "Connect() called but not disconnected")
|
||||||
t.returnCode = packets.Accepted
|
t.returnCode = packets.Accepted
|
||||||
t.flowComplete()
|
t.flowComplete()
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
ERROR.Println(CLI, err) // CONNECT should never be called unless we are disconnected
|
||||||
|
t.setError(err)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
c.persist.Open()
|
c.persist.Open()
|
||||||
if c.options.ConnectRetry {
|
if c.options.ConnectRetry {
|
||||||
c.reserveStoredPublishIDs() // Reserve IDs to allow publish before connect complete
|
c.reserveStoredPublishIDs() // Reserve IDs to allow publishing before connect complete
|
||||||
}
|
}
|
||||||
c.setConnected(connecting)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if len(c.options.Servers) == 0 {
|
if len(c.options.Servers) == 0 {
|
||||||
t.setError(fmt.Errorf("no servers defined to connect to"))
|
t.setError(fmt.Errorf("no servers defined to connect to"))
|
||||||
|
if err := connectionUp(false); err != nil {
|
||||||
|
ERROR.Println(CLI, err.Error())
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var attemptCount int
|
||||||
|
|
||||||
RETRYCONN:
|
RETRYCONN:
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
var rc byte
|
var rc byte
|
||||||
var err error
|
var err error
|
||||||
conn, rc, t.sessionPresent, err = c.attemptConnection()
|
conn, rc, t.sessionPresent, err = c.attemptConnection(false, attemptCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
attemptCount++
|
||||||
if c.options.ConnectRetry {
|
if c.options.ConnectRetry {
|
||||||
DEBUG.Println(CLI, "Connect failed, sleeping for", int(c.options.ConnectRetryInterval.Seconds()), "seconds and will then retry")
|
DEBUG.Println(CLI, "Connect failed, sleeping for", int(c.options.ConnectRetryInterval.Seconds()), "seconds and will then retry, error:", err.Error())
|
||||||
time.Sleep(c.options.ConnectRetryInterval)
|
time.Sleep(c.options.ConnectRetryInterval)
|
||||||
|
|
||||||
if atomic.LoadUint32(&c.status) == connecting {
|
if c.status.ConnectionStatus() == connecting { // Possible connection aborted elsewhere
|
||||||
goto RETRYCONN
|
goto RETRYCONN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ERROR.Println(CLI, "Failed to connect to a broker")
|
ERROR.Println(CLI, "Failed to connect to a broker")
|
||||||
c.setConnected(disconnected)
|
|
||||||
c.persist.Close()
|
c.persist.Close()
|
||||||
t.returnCode = rc
|
t.returnCode = rc
|
||||||
t.setError(err)
|
t.setError(err)
|
||||||
|
if err := connectionUp(false); err != nil {
|
||||||
|
ERROR.Println(CLI, err.Error())
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
inboundFromStore := make(chan packets.ControlPacket) // there may be some inbound comms packets in the store that are awaiting processing
|
inboundFromStore := make(chan packets.ControlPacket) // there may be some inbound comms packets in the store that are awaiting processing
|
||||||
if c.startCommsWorkers(conn, inboundFromStore) {
|
if c.startCommsWorkers(conn, connectionUp, inboundFromStore) { // note that this takes care of updating the status (to connected or disconnected)
|
||||||
// Take care of any messages in the store
|
// Take care of any messages in the store
|
||||||
if !c.options.CleanSession {
|
if !c.options.CleanSession {
|
||||||
c.resume(c.options.ResumeSubs, inboundFromStore)
|
c.resume(c.options.ResumeSubs, inboundFromStore)
|
||||||
} else {
|
} else {
|
||||||
c.persist.Reset()
|
c.persist.Reset()
|
||||||
}
|
}
|
||||||
} else {
|
} else { // Note: With the new status subsystem this should only happen if Disconnect called simultaneously with the above
|
||||||
WARN.Println(CLI, "Connect() called but connection established in another goroutine")
|
WARN.Println(CLI, "Connect() called but connection established in another goroutine")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,48 +304,45 @@ func (c *client) Connect() Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// internal function used to reconnect the client when it loses its connection
|
// internal function used to reconnect the client when it loses its connection
|
||||||
func (c *client) reconnect() {
|
// The connection status MUST be reconnecting prior to calling this function (via call to status.connectionLost)
|
||||||
|
func (c *client) reconnect(connectionUp connCompletedFn) {
|
||||||
DEBUG.Println(CLI, "enter reconnect")
|
DEBUG.Println(CLI, "enter reconnect")
|
||||||
var (
|
var (
|
||||||
sleep = 1 * time.Second
|
initSleep = 1 * time.Second
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// If the reason of connection lost is same as the before one, sleep timer is set before attempting connection is started.
|
||||||
|
// Sleep time is exponentially increased as the same situation continues
|
||||||
|
if slp, isContinual := c.backoff.sleepWithBackoff("connectionLost", initSleep, c.options.MaxReconnectInterval, 3*time.Second, true); isContinual {
|
||||||
|
DEBUG.Println(CLI, "Detect continual connection lost after reconnect, slept for", int(slp.Seconds()), "seconds")
|
||||||
|
}
|
||||||
|
|
||||||
|
var attemptCount int
|
||||||
for {
|
for {
|
||||||
if nil != c.options.OnReconnecting {
|
if nil != c.options.OnReconnecting {
|
||||||
c.options.OnReconnecting(c, &c.options)
|
c.options.OnReconnecting(c, &c.options)
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
conn, _, _, err = c.attemptConnection()
|
conn, _, _, err = c.attemptConnection(true, attemptCount)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
DEBUG.Println(CLI, "Reconnect failed, sleeping for", int(sleep.Seconds()), "seconds:", err)
|
attemptCount++
|
||||||
time.Sleep(sleep)
|
sleep, _ := c.backoff.sleepWithBackoff("attemptReconnection", initSleep, c.options.MaxReconnectInterval, c.options.ConnectTimeout, false)
|
||||||
if sleep < c.options.MaxReconnectInterval {
|
DEBUG.Println(CLI, "Reconnect failed, slept for", int(sleep.Seconds()), "seconds:", err)
|
||||||
sleep *= 2
|
|
||||||
}
|
|
||||||
|
|
||||||
if sleep > c.options.MaxReconnectInterval {
|
if c.status.ConnectionStatus() != reconnecting { // Disconnect may have been called
|
||||||
sleep = c.options.MaxReconnectInterval
|
if err := connectionUp(false); err != nil { // Should always return an error
|
||||||
}
|
ERROR.Println(CLI, err.Error())
|
||||||
// Disconnect may have been called
|
|
||||||
if atomic.LoadUint32(&c.status) == disconnected {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disconnect() must have been called while we were trying to reconnect.
|
|
||||||
if c.connectionStatus() == disconnected {
|
|
||||||
if conn != nil {
|
|
||||||
conn.Close()
|
|
||||||
}
|
}
|
||||||
DEBUG.Println(CLI, "Client moved to disconnected state while reconnecting, abandoning reconnect")
|
DEBUG.Println(CLI, "Client moved to disconnected state while reconnecting, abandoning reconnect")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inboundFromStore := make(chan packets.ControlPacket) // there may be some inbound comms packets in the store that are awaiting processing
|
inboundFromStore := make(chan packets.ControlPacket) // there may be some inbound comms packets in the store that are awaiting processing
|
||||||
if c.startCommsWorkers(conn, inboundFromStore) {
|
if c.startCommsWorkers(conn, connectionUp, inboundFromStore) { // note that this takes care of updating the status (to connected or disconnected)
|
||||||
c.resume(c.options.ResumeSubs, inboundFromStore)
|
c.resume(c.options.ResumeSubs, inboundFromStore)
|
||||||
}
|
}
|
||||||
close(inboundFromStore)
|
close(inboundFromStore)
|
||||||
@@ -363,7 +356,7 @@ func (c *client) reconnect() {
|
|||||||
// byte - Return code (packets.Accepted indicates a successful connection).
|
// byte - Return code (packets.Accepted indicates a successful connection).
|
||||||
// bool - SessionPresent flag from the connect ack (only valid if packets.Accepted)
|
// bool - SessionPresent flag from the connect ack (only valid if packets.Accepted)
|
||||||
// err - Error (err != nil guarantees that conn has been set to active connection).
|
// err - Error (err != nil guarantees that conn has been set to active connection).
|
||||||
func (c *client) attemptConnection() (net.Conn, byte, bool, error) {
|
func (c *client) attemptConnection(isReconnect bool, attempt int) (net.Conn, byte, bool, error) {
|
||||||
protocolVersion := c.options.ProtocolVersion
|
protocolVersion := c.options.ProtocolVersion
|
||||||
var (
|
var (
|
||||||
sessionPresent bool
|
sessionPresent bool
|
||||||
@@ -372,6 +365,10 @@ func (c *client) attemptConnection() (net.Conn, byte, bool, error) {
|
|||||||
rc byte
|
rc byte
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if c.options.OnConnectionNotification != nil {
|
||||||
|
c.options.OnConnectionNotification(c, ConnectionNotificationConnecting{isReconnect, attempt})
|
||||||
|
}
|
||||||
|
|
||||||
c.optionsMu.Lock() // Protect c.options.Servers so that servers can be added in test cases
|
c.optionsMu.Lock() // Protect c.options.Servers so that servers can be added in test cases
|
||||||
brokers := c.options.Servers
|
brokers := c.options.Servers
|
||||||
c.optionsMu.Unlock()
|
c.optionsMu.Unlock()
|
||||||
@@ -379,26 +376,54 @@ func (c *client) attemptConnection() (net.Conn, byte, bool, error) {
|
|||||||
cm := newConnectMsgFromOptions(&c.options, broker)
|
cm := newConnectMsgFromOptions(&c.options, broker)
|
||||||
DEBUG.Println(CLI, "about to write new connect msg")
|
DEBUG.Println(CLI, "about to write new connect msg")
|
||||||
CONN:
|
CONN:
|
||||||
|
tlsCfg := c.options.TLSConfig
|
||||||
|
if c.options.OnConnectAttempt != nil {
|
||||||
|
DEBUG.Println(CLI, "using custom onConnectAttempt handler...")
|
||||||
|
tlsCfg = c.options.OnConnectAttempt(broker, c.options.TLSConfig)
|
||||||
|
}
|
||||||
|
if c.options.OnConnectionNotification != nil {
|
||||||
|
c.options.OnConnectionNotification(c, ConnectionNotificationBroker{broker})
|
||||||
|
}
|
||||||
|
connDeadline := time.Now().Add(c.options.ConnectTimeout) // Time by which connection must be established
|
||||||
|
dialer := c.options.Dialer
|
||||||
|
if dialer == nil { //
|
||||||
|
WARN.Println(CLI, "dialer was nil, using default")
|
||||||
|
dialer = &net.Dialer{Timeout: 30 * time.Second}
|
||||||
|
}
|
||||||
// Start by opening the network connection (tcp, tls, ws) etc
|
// Start by opening the network connection (tcp, tls, ws) etc
|
||||||
conn, err = openConnection(broker, c.options.TLSConfig, c.options.ConnectTimeout, c.options.HTTPHeaders, c.options.WebsocketOptions)
|
if c.options.CustomOpenConnectionFn != nil {
|
||||||
|
conn, err = c.options.CustomOpenConnectionFn(broker, c.options)
|
||||||
|
} else {
|
||||||
|
conn, err = openConnection(broker, tlsCfg, c.options.ConnectTimeout, c.options.HTTPHeaders, c.options.WebsocketOptions, dialer)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ERROR.Println(CLI, err.Error())
|
ERROR.Println(CLI, err.Error())
|
||||||
WARN.Println(CLI, "failed to connect to broker, trying next")
|
WARN.Println(CLI, "failed to connect to broker, trying next")
|
||||||
rc = packets.ErrNetworkError
|
rc = packets.ErrNetworkError
|
||||||
|
if c.options.OnConnectionNotification != nil {
|
||||||
|
c.options.OnConnectionNotification(c, ConnectionNotificationBrokerFailed{broker, err})
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
DEBUG.Println(CLI, "socket connected to broker")
|
DEBUG.Println(CLI, "socket connected to broker")
|
||||||
|
|
||||||
// Now we send the perform the MQTT connection handshake
|
// Now we perform the MQTT connection handshake ensuring that it does not exceed the timeout
|
||||||
|
if err := conn.SetDeadline(connDeadline); err != nil {
|
||||||
|
ERROR.Println(CLI, "set deadline for handshake ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we perform the MQTT connection handshake
|
||||||
rc, sessionPresent, err = connectMQTT(conn, cm, protocolVersion)
|
rc, sessionPresent, err = connectMQTT(conn, cm, protocolVersion)
|
||||||
if rc == packets.Accepted {
|
if rc == packets.Accepted {
|
||||||
|
if err := conn.SetDeadline(time.Time{}); err != nil {
|
||||||
|
ERROR.Println(CLI, "reset deadline following handshake ", err)
|
||||||
|
}
|
||||||
break // successfully connected
|
break // successfully connected
|
||||||
}
|
}
|
||||||
|
|
||||||
// We may be have to attempt the connection with MQTT 3.1
|
// We may have to attempt the connection with MQTT 3.1
|
||||||
if conn != nil {
|
_ = conn.Close()
|
||||||
conn.Close()
|
|
||||||
}
|
|
||||||
if !c.options.protocolVersionExplicit && protocolVersion == 4 { // try falling back to 3.1?
|
if !c.options.protocolVersionExplicit && protocolVersion == 4 { // try falling back to 3.1?
|
||||||
DEBUG.Println(CLI, "Trying reconnect using MQTT 3.1 protocol")
|
DEBUG.Println(CLI, "Trying reconnect using MQTT 3.1 protocol")
|
||||||
protocolVersion = 3
|
protocolVersion = 3
|
||||||
@@ -417,46 +442,75 @@ func (c *client) attemptConnection() (net.Conn, byte, bool, error) {
|
|||||||
if rc != packets.ErrNetworkError { // mqtt error
|
if rc != packets.ErrNetworkError { // mqtt error
|
||||||
err = packets.ConnErrors[rc]
|
err = packets.ConnErrors[rc]
|
||||||
} else { // network error (if this occurred in ConnectMQTT then err will be nil)
|
} else { // network error (if this occurred in ConnectMQTT then err will be nil)
|
||||||
err = fmt.Errorf("%s : %s", packets.ConnErrors[rc], err)
|
err = fmt.Errorf("%w : %w", packets.ConnErrors[rc], err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err != nil && c.options.OnConnectionNotification != nil {
|
||||||
|
c.options.OnConnectionNotification(c, ConnectionNotificationFailed{err})
|
||||||
|
}
|
||||||
return conn, rc, sessionPresent, err
|
return conn, rc, sessionPresent, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disconnect will end the connection with the server, but not before waiting
|
// Disconnect will end the connection with the server, but not before waiting
|
||||||
// the specified number of milliseconds to wait for existing work to be
|
// the specified number of milliseconds to wait for existing work to be
|
||||||
// completed.
|
// completed.
|
||||||
|
// WARNING: `Disconnect` may return before all activities (goroutines) have completed. This means that
|
||||||
|
// reusing the `client` may lead to panics. If you want to reconnect when the connection drops then use
|
||||||
|
// `SetAutoReconnect` and/or `SetConnectRetry`options instead of implementing this yourself.
|
||||||
func (c *client) Disconnect(quiesce uint) {
|
func (c *client) Disconnect(quiesce uint) {
|
||||||
status := atomic.LoadUint32(&c.status)
|
done := make(chan struct{}) // Simplest way to ensure quiesce is always honoured
|
||||||
if status == connected {
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
disDone, err := c.status.Disconnecting()
|
||||||
|
if err != nil {
|
||||||
|
// Status has been set to disconnecting, but we had to wait for something else to complete
|
||||||
|
WARN.Println(CLI, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
c.disconnect() // Force disconnection
|
||||||
|
disDone() // Update status
|
||||||
|
}()
|
||||||
DEBUG.Println(CLI, "disconnecting")
|
DEBUG.Println(CLI, "disconnecting")
|
||||||
c.setConnected(disconnected)
|
|
||||||
|
|
||||||
dm := packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
|
dm := packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
|
||||||
dt := newToken(packets.Disconnect)
|
dt := newToken(packets.Disconnect)
|
||||||
c.oboundP <- &PacketAndToken{p: dm, t: dt}
|
select {
|
||||||
|
case c.oboundP <- &PacketAndToken{p: dm, t: dt}:
|
||||||
// wait for work to finish, or quiesce time consumed
|
// wait for work to finish, or quiesce time consumed
|
||||||
DEBUG.Println(CLI, "calling WaitTimeout")
|
DEBUG.Println(CLI, "calling WaitTimeout")
|
||||||
dt.WaitTimeout(time.Duration(quiesce) * time.Millisecond)
|
dt.WaitTimeout(time.Duration(quiesce) * time.Millisecond)
|
||||||
DEBUG.Println(CLI, "WaitTimeout done")
|
DEBUG.Println(CLI, "WaitTimeout done")
|
||||||
} else {
|
// Below code causes a potential data race. Following status refactor it should no longer be required
|
||||||
WARN.Println(CLI, "Disconnect() called but not connected (disconnected/reconnecting)")
|
// but leaving in as need to check code further.
|
||||||
c.setConnected(disconnected)
|
// case <-c.commsStopped:
|
||||||
|
// WARN.Println("Disconnect packet could not be sent because comms stopped")
|
||||||
|
case <-time.After(time.Duration(quiesce) * time.Millisecond):
|
||||||
|
WARN.Println("Disconnect packet not sent due to timeout")
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
c.disconnect()
|
// Return when done or after timeout expires (would like to change but this maintains compatibility)
|
||||||
|
delay := time.NewTimer(time.Duration(quiesce) * time.Millisecond)
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
if !delay.Stop() {
|
||||||
|
<-delay.C
|
||||||
|
}
|
||||||
|
case <-delay.C:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// forceDisconnect will end the connection with the mqtt broker immediately (used for tests only)
|
// forceDisconnect will end the connection with the mqtt broker immediately (used for tests only)
|
||||||
func (c *client) forceDisconnect() {
|
func (c *client) forceDisconnect() {
|
||||||
if !c.IsConnected() {
|
disDone, err := c.status.Disconnecting()
|
||||||
WARN.Println(CLI, "already disconnected")
|
if err != nil {
|
||||||
|
// Possible that we are not actually connected
|
||||||
|
WARN.Println(CLI, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.setConnected(disconnected)
|
|
||||||
DEBUG.Println(CLI, "forcefully disconnecting")
|
DEBUG.Println(CLI, "forcefully disconnecting")
|
||||||
c.disconnect()
|
c.disconnect()
|
||||||
|
disDone()
|
||||||
}
|
}
|
||||||
|
|
||||||
// disconnect cleans up after a final disconnection (user requested so no auto reconnection)
|
// disconnect cleans up after a final disconnection (user requested so no auto reconnection)
|
||||||
@@ -473,47 +527,82 @@ func (c *client) disconnect() {
|
|||||||
|
|
||||||
// internalConnLost cleanup when connection is lost or an error occurs
|
// internalConnLost cleanup when connection is lost or an error occurs
|
||||||
// Note: This function will not block
|
// Note: This function will not block
|
||||||
func (c *client) internalConnLost(err error) {
|
func (c *client) internalConnLost(whyConnLost error) {
|
||||||
// It is possible that internalConnLost will be called multiple times simultaneously
|
// It is possible that internalConnLost will be called multiple times simultaneously
|
||||||
// (including after sending a DisconnectPacket) as such we only do cleanup etc if the
|
// (including after sending a DisconnectPacket) as such we only do cleanup etc if the
|
||||||
// routines were actually running and are not being disconnected at users request
|
// routines were actually running and are not being disconnected at users request
|
||||||
DEBUG.Println(CLI, "internalConnLost called")
|
DEBUG.Println(CLI, "internalConnLost called")
|
||||||
|
disDone, err := c.status.ConnectionLost(c.options.AutoReconnect && c.status.ConnectionStatus() > connecting)
|
||||||
|
if err != nil {
|
||||||
|
if err == errConnLossWhileDisconnecting || err == errAlreadyHandlingConnectionLoss {
|
||||||
|
return // Loss of connection is expected or already being handled
|
||||||
|
}
|
||||||
|
ERROR.Println(CLI, fmt.Sprintf("internalConnLost unexpected status: %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// c.stopCommsWorker returns a channel that is closed when the operation completes. This was required prior
|
||||||
|
// to the implementation of proper status management but has been left in place, for now, to minimise change
|
||||||
stopDone := c.stopCommsWorkers()
|
stopDone := c.stopCommsWorkers()
|
||||||
if stopDone != nil { // stopDone will be nil if workers already in the process of stopping or stopped
|
// stopDone was required in previous versions because there was no connectionLost status (and there were
|
||||||
|
// issues with status handling). This code has been left in place for the time being just in case the new
|
||||||
|
// status handling contains bugs (refactoring required at some point).
|
||||||
|
if stopDone == nil { // stopDone will be nil if workers already in the process of stopping or stopped
|
||||||
|
ERROR.Println(CLI, "internalConnLost stopDone unexpectedly nil - BUG BUG")
|
||||||
|
// Cannot really do anything other than leave things disconnected
|
||||||
|
if _, err = disDone(false); err != nil { // Safest option - cannot leave status as connectionLost
|
||||||
|
ERROR.Println(CLI, fmt.Sprintf("internalConnLost failed to set status to disconnected (stopDone): %s", err.Error()))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// It may take a while for the disconnection to complete whatever called us needs to exit cleanly so finnish in goRoutine
|
||||||
go func() {
|
go func() {
|
||||||
DEBUG.Println(CLI, "internalConnLost waiting on workers")
|
DEBUG.Println(CLI, "internalConnLost waiting on workers")
|
||||||
<-stopDone
|
<-stopDone
|
||||||
DEBUG.Println(CLI, "internalConnLost workers stopped")
|
DEBUG.Println(CLI, "internalConnLost workers stopped")
|
||||||
// It is possible that Disconnect was called which led to this error so reconnection depends upon status
|
|
||||||
reconnect := c.options.AutoReconnect && c.connectionStatus() > connecting
|
reConnDone, err := disDone(true)
|
||||||
|
if err != nil {
|
||||||
|
ERROR.Println(CLI, "failure whilst reporting completion of disconnect", err)
|
||||||
|
} else if reConnDone == nil { // Should never happen
|
||||||
|
ERROR.Println(CLI, "BUG BUG BUG reconnection function is nil", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
reconnect := err == nil && reConnDone != nil
|
||||||
|
|
||||||
if c.options.CleanSession && !reconnect {
|
if c.options.CleanSession && !reconnect {
|
||||||
c.messageIds.cleanUp()
|
c.messageIds.cleanUp() // completes PUB/SUB/UNSUB tokens
|
||||||
|
} else if !c.options.ResumeSubs {
|
||||||
|
c.messageIds.cleanUpSubscribe() // completes SUB/UNSUB tokens
|
||||||
}
|
}
|
||||||
if reconnect {
|
if reconnect {
|
||||||
c.setConnected(reconnecting)
|
go c.reconnect(reConnDone) // Will set connection status to reconnecting
|
||||||
go c.reconnect()
|
|
||||||
} else {
|
|
||||||
c.setConnected(disconnected)
|
|
||||||
}
|
}
|
||||||
if c.options.OnConnectionLost != nil {
|
if c.options.OnConnectionLost != nil {
|
||||||
go c.options.OnConnectionLost(c, err)
|
go c.options.OnConnectionLost(c, whyConnLost)
|
||||||
|
}
|
||||||
|
if c.options.OnConnectionNotification != nil {
|
||||||
|
go c.options.OnConnectionNotification(c, ConnectionNotificationLost{whyConnLost})
|
||||||
}
|
}
|
||||||
DEBUG.Println(CLI, "internalConnLost complete")
|
DEBUG.Println(CLI, "internalConnLost complete")
|
||||||
}()
|
}()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// startCommsWorkers is called when the connection is up. It starts off all of the routines needed to process incoming and
|
// startCommsWorkers is called when the connection is up.
|
||||||
// outgoing messages.
|
// It starts off the routines needed to process incoming and outgoing messages.
|
||||||
// Returns true if the comms workers were started (i.e. they were not already running)
|
// Returns true if the comms workers were started (i.e. successful connection)
|
||||||
func (c *client) startCommsWorkers(conn net.Conn, inboundFromStore <-chan packets.ControlPacket) bool {
|
// connectionUp(true) will be called once everything is up; connectionUp(false) will be called on failure
|
||||||
|
func (c *client) startCommsWorkers(conn net.Conn, connectionUp connCompletedFn, inboundFromStore <-chan packets.ControlPacket) bool {
|
||||||
DEBUG.Println(CLI, "startCommsWorkers called")
|
DEBUG.Println(CLI, "startCommsWorkers called")
|
||||||
c.connMu.Lock()
|
c.connMu.Lock()
|
||||||
defer c.connMu.Unlock()
|
defer c.connMu.Unlock()
|
||||||
if c.conn != nil {
|
if c.conn != nil { // Should never happen due to new status handling; leaving in for safety for the time being
|
||||||
WARN.Println(CLI, "startCommsWorkers called when commsworkers already running")
|
WARN.Println(CLI, "startCommsWorkers called when commsworkers already running BUG BUG")
|
||||||
conn.Close() // No use for the new network connection
|
_ = conn.Close() // No use for the new network connection
|
||||||
|
if err := connectionUp(false); err != nil {
|
||||||
|
ERROR.Println(CLI, err.Error())
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
c.conn = conn // Store the connection
|
c.conn = conn // Store the connection
|
||||||
@@ -533,11 +622,21 @@ func (c *client) startCommsWorkers(conn net.Conn, inboundFromStore <-chan packet
|
|||||||
c.workers.Add(1) // Done will be called when ackOut is closed
|
c.workers.Add(1) // Done will be called when ackOut is closed
|
||||||
ackOut := c.msgRouter.matchAndDispatch(incomingPubChan, c.options.Order, c)
|
ackOut := c.msgRouter.matchAndDispatch(incomingPubChan, c.options.Order, c)
|
||||||
|
|
||||||
c.setConnected(connected)
|
// The connection is now ready for use (we spin up a few go routines below).
|
||||||
|
// It is possible that Disconnect has been called in the interim...
|
||||||
|
// issue 675:we will allow the connection to complete before the Disconnect is allowed to proceed
|
||||||
|
// as if a Disconnect event occurred immediately after connectionUp(true) completed.
|
||||||
|
if err := connectionUp(true); err != nil {
|
||||||
|
ERROR.Println(CLI, err)
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG.Println(CLI, "client is connected/reconnected")
|
DEBUG.Println(CLI, "client is connected/reconnected")
|
||||||
if c.options.OnConnect != nil {
|
if c.options.OnConnect != nil {
|
||||||
go c.options.OnConnect(c)
|
go c.options.OnConnect(c)
|
||||||
}
|
}
|
||||||
|
if c.options.OnConnectionNotification != nil {
|
||||||
|
go c.options.OnConnectionNotification(c, ConnectionNotificationConnected{})
|
||||||
|
}
|
||||||
|
|
||||||
// c.oboundP and c.obound need to stay active for the life of the client because, depending upon the options,
|
// c.oboundP and c.obound need to stay active for the life of the client because, depending upon the options,
|
||||||
// messages may be published while the client is disconnected (they will block unless in a goroutine). However
|
// messages may be published while the client is disconnected (they will block unless in a goroutine). However
|
||||||
@@ -592,7 +691,22 @@ func (c *client) startCommsWorkers(conn net.Conn, inboundFromStore <-chan packet
|
|||||||
commsIncomingPub = nil
|
commsIncomingPub = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
incomingPubChan <- pub
|
// Care is needed here because an error elsewhere could trigger a deadlock
|
||||||
|
sendPubLoop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case incomingPubChan <- pub:
|
||||||
|
break sendPubLoop
|
||||||
|
case err, ok := <-commsErrors:
|
||||||
|
if !ok { // commsErrors has been closed so we can ignore it
|
||||||
|
commsErrors = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ERROR.Println(CLI, "Connect comms goroutine - error triggered during send Pub", err)
|
||||||
|
c.internalConnLost(err) // no harm in calling this if the connection is already down (or shutdown is in progress)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
case err, ok := <-commsErrors:
|
case err, ok := <-commsErrors:
|
||||||
if !ok {
|
if !ok {
|
||||||
commsErrors = nil
|
commsErrors = nil
|
||||||
@@ -611,8 +725,9 @@ func (c *client) startCommsWorkers(conn net.Conn, inboundFromStore <-chan packet
|
|||||||
}
|
}
|
||||||
|
|
||||||
// stopWorkersAndComms - Cleanly shuts down worker go routines (including the comms routines) and waits until everything has stopped
|
// stopWorkersAndComms - Cleanly shuts down worker go routines (including the comms routines) and waits until everything has stopped
|
||||||
// Returns nil it workers did not need to be stopped; otherwise returns a channel which will be closed when the stop is complete
|
// Returns nil if workers did not need to be stopped; otherwise returns a channel which will be closed when the stop is complete
|
||||||
// Note: This may block so run as a go routine if calling from any of the comms routines
|
// Note: This may block so run as a go routine if calling from any of the comms routines
|
||||||
|
// Note2: It should be possible to simplify this now that the new status management code is in place.
|
||||||
func (c *client) stopCommsWorkers() chan struct{} {
|
func (c *client) stopCommsWorkers() chan struct{} {
|
||||||
DEBUG.Println(CLI, "stopCommsWorkers called")
|
DEBUG.Println(CLI, "stopCommsWorkers called")
|
||||||
// It is possible that this function will be called multiple times simultaneously due to the way things get shutdown
|
// It is possible that this function will be called multiple times simultaneously due to the way things get shutdown
|
||||||
@@ -661,7 +776,8 @@ func (c *client) Publish(topic string, qos byte, retained bool, payload interfac
|
|||||||
case !c.IsConnected():
|
case !c.IsConnected():
|
||||||
token.setError(ErrNotConnected)
|
token.setError(ErrNotConnected)
|
||||||
return token
|
return token
|
||||||
case c.connectionStatus() == reconnecting && qos == 0:
|
case c.status.ConnectionStatus() == reconnecting && qos == 0:
|
||||||
|
// message written to store and will be sent when connection comes up
|
||||||
token.flowComplete()
|
token.flowComplete()
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
@@ -691,20 +807,26 @@ func (c *client) Publish(topic string, qos byte, retained bool, payload interfac
|
|||||||
token.messageID = mID
|
token.messageID = mID
|
||||||
}
|
}
|
||||||
persistOutbound(c.persist, pub)
|
persistOutbound(c.persist, pub)
|
||||||
switch c.connectionStatus() {
|
switch c.status.ConnectionStatus() {
|
||||||
case connecting:
|
case connecting:
|
||||||
DEBUG.Println(CLI, "storing publish message (connecting), topic:", topic)
|
DEBUG.Println(CLI, "storing publish message (connecting), topic:", topic)
|
||||||
case reconnecting:
|
case reconnecting:
|
||||||
DEBUG.Println(CLI, "storing publish message (reconnecting), topic:", topic)
|
DEBUG.Println(CLI, "storing publish message (reconnecting), topic:", topic)
|
||||||
|
case disconnecting:
|
||||||
|
DEBUG.Println(CLI, "storing publish message (disconnecting), topic:", topic)
|
||||||
default:
|
default:
|
||||||
DEBUG.Println(CLI, "sending publish message, topic:", topic)
|
DEBUG.Println(CLI, "sending publish message, topic:", topic)
|
||||||
publishWaitTimeout := c.options.WriteTimeout
|
publishWaitTimeout := c.options.WriteTimeout
|
||||||
if publishWaitTimeout == 0 {
|
if publishWaitTimeout == 0 {
|
||||||
publishWaitTimeout = time.Second * 30
|
publishWaitTimeout = time.Second * 30
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t := time.NewTimer(publishWaitTimeout)
|
||||||
|
defer t.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case c.obound <- &PacketAndToken{p: pub, t: token}:
|
case c.obound <- &PacketAndToken{p: pub, t: token}:
|
||||||
case <-time.After(publishWaitTimeout):
|
case <-t.C:
|
||||||
token.setError(errors.New("publish was broken by timeout"))
|
token.setError(errors.New("publish was broken by timeout"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -728,11 +850,11 @@ func (c *client) Subscribe(topic string, qos byte, callback MessageHandler) Toke
|
|||||||
if !c.IsConnectionOpen() {
|
if !c.IsConnectionOpen() {
|
||||||
switch {
|
switch {
|
||||||
case !c.options.ResumeSubs:
|
case !c.options.ResumeSubs:
|
||||||
// if not connected and resumesubs not set this sub will be thrown away
|
// if not connected and resumeSubs not set this sub will be thrown away
|
||||||
token.setError(fmt.Errorf("not currently connected and ResumeSubs not set"))
|
token.setError(fmt.Errorf("not currently connected and ResumeSubs not set"))
|
||||||
return token
|
return token
|
||||||
case c.options.CleanSession && c.connectionStatus() == reconnecting:
|
case c.options.CleanSession && c.status.ConnectionStatus() == reconnecting:
|
||||||
// if reconnecting and cleansession is true this sub will be thrown away
|
// if reconnecting and cleanSession is true this sub will be thrown away
|
||||||
token.setError(fmt.Errorf("reconnecting state and cleansession is true"))
|
token.setError(fmt.Errorf("reconnecting state and cleansession is true"))
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
@@ -770,12 +892,16 @@ func (c *client) Subscribe(topic string, qos byte, callback MessageHandler) Toke
|
|||||||
}
|
}
|
||||||
DEBUG.Println(CLI, sub.String())
|
DEBUG.Println(CLI, sub.String())
|
||||||
|
|
||||||
|
if c.options.ResumeSubs { // Only persist if we need this to resume subs after a disconnection
|
||||||
persistOutbound(c.persist, sub)
|
persistOutbound(c.persist, sub)
|
||||||
switch c.connectionStatus() {
|
}
|
||||||
|
switch c.status.ConnectionStatus() {
|
||||||
case connecting:
|
case connecting:
|
||||||
DEBUG.Println(CLI, "storing subscribe message (connecting), topic:", topic)
|
DEBUG.Println(CLI, "storing subscribe message (connecting), topic:", topic)
|
||||||
case reconnecting:
|
case reconnecting:
|
||||||
DEBUG.Println(CLI, "storing subscribe message (reconnecting), topic:", topic)
|
DEBUG.Println(CLI, "storing subscribe message (reconnecting), topic:", topic)
|
||||||
|
case disconnecting:
|
||||||
|
DEBUG.Println(CLI, "storing subscribe message (disconnecting), topic:", topic)
|
||||||
default:
|
default:
|
||||||
DEBUG.Println(CLI, "sending subscribe message, topic:", topic)
|
DEBUG.Println(CLI, "sending subscribe message, topic:", topic)
|
||||||
subscribeWaitTimeout := c.options.WriteTimeout
|
subscribeWaitTimeout := c.options.WriteTimeout
|
||||||
@@ -813,8 +939,8 @@ func (c *client) SubscribeMultiple(filters map[string]byte, callback MessageHand
|
|||||||
// if not connected and resumesubs not set this sub will be thrown away
|
// if not connected and resumesubs not set this sub will be thrown away
|
||||||
token.setError(fmt.Errorf("not currently connected and ResumeSubs not set"))
|
token.setError(fmt.Errorf("not currently connected and ResumeSubs not set"))
|
||||||
return token
|
return token
|
||||||
case c.options.CleanSession && c.connectionStatus() == reconnecting:
|
case c.options.CleanSession && c.status.ConnectionStatus() == reconnecting:
|
||||||
// if reconnecting and cleansession is true this sub will be thrown away
|
// if reconnecting and cleanSession is true this sub will be thrown away
|
||||||
token.setError(fmt.Errorf("reconnecting state and cleansession is true"))
|
token.setError(fmt.Errorf("reconnecting state and cleansession is true"))
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
@@ -842,12 +968,16 @@ func (c *client) SubscribeMultiple(filters map[string]byte, callback MessageHand
|
|||||||
sub.MessageID = mID
|
sub.MessageID = mID
|
||||||
token.messageID = mID
|
token.messageID = mID
|
||||||
}
|
}
|
||||||
|
if c.options.ResumeSubs { // Only persist if we need this to resume subs after a disconnection
|
||||||
persistOutbound(c.persist, sub)
|
persistOutbound(c.persist, sub)
|
||||||
switch c.connectionStatus() {
|
}
|
||||||
|
switch c.status.ConnectionStatus() {
|
||||||
case connecting:
|
case connecting:
|
||||||
DEBUG.Println(CLI, "storing subscribe message (connecting), topics:", sub.Topics)
|
DEBUG.Println(CLI, "storing subscribe message (connecting), topics:", sub.Topics)
|
||||||
case reconnecting:
|
case reconnecting:
|
||||||
DEBUG.Println(CLI, "storing subscribe message (reconnecting), topics:", sub.Topics)
|
DEBUG.Println(CLI, "storing subscribe message (reconnecting), topics:", sub.Topics)
|
||||||
|
case disconnecting:
|
||||||
|
DEBUG.Println(CLI, "storing subscribe message (disconnecting), topics:", sub.Topics)
|
||||||
default:
|
default:
|
||||||
DEBUG.Println(CLI, "sending subscribe message, topics:", sub.Topics)
|
DEBUG.Println(CLI, "sending subscribe message, topics:", sub.Topics)
|
||||||
subscribeWaitTimeout := c.options.WriteTimeout
|
subscribeWaitTimeout := c.options.WriteTimeout
|
||||||
@@ -889,10 +1019,42 @@ func (c *client) reserveStoredPublishIDs() {
|
|||||||
// Load all stored messages and resend them
|
// Load all stored messages and resend them
|
||||||
// Call this to ensure QOS > 1,2 even after an application crash
|
// Call this to ensure QOS > 1,2 even after an application crash
|
||||||
// Note: This function will exit if c.stop is closed (this allows the shutdown to proceed avoiding a potential deadlock)
|
// Note: This function will exit if c.stop is closed (this allows the shutdown to proceed avoiding a potential deadlock)
|
||||||
//
|
// other than that it does not return until all messages in the store have been sent (connect() does not complete its
|
||||||
|
// token before this completes)
|
||||||
func (c *client) resume(subscription bool, ibound chan packets.ControlPacket) {
|
func (c *client) resume(subscription bool, ibound chan packets.ControlPacket) {
|
||||||
DEBUG.Println(STR, "enter Resume")
|
DEBUG.Println(STR, "enter Resume")
|
||||||
|
|
||||||
|
// Prior to sending a message getSemaphore will be called and once sent releaseSemaphore will be called
|
||||||
|
// with the token (so semaphore can be released when ACK received if applicable).
|
||||||
|
// Using a weighted semaphore rather than channels because this retains ordering
|
||||||
|
getSemaphore := func() {} // Default = do nothing
|
||||||
|
releaseSemaphore := func(_ *PublishToken) {} // Default = do nothing
|
||||||
|
var sem *semaphore.Weighted
|
||||||
|
if c.options.MaxResumePubInFlight > 0 {
|
||||||
|
sem = semaphore.NewWeighted(int64(c.options.MaxResumePubInFlight))
|
||||||
|
ctx, cancel := context.WithCancel(context.Background()) // Context needed for semaphore
|
||||||
|
defer cancel() // ensure context gets cancelled
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-c.stop: // Request to stop (due to comm error etc)
|
||||||
|
cancel()
|
||||||
|
case <-ctx.Done(): // resume completed normally
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
getSemaphore = func() { sem.Acquire(ctx, 1) }
|
||||||
|
releaseSemaphore = func(token *PublishToken) { // Note: If token never completes then resume() may stall (will still exit on ctx.Done())
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-token.Done():
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
sem.Release(1)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
storedKeys := c.persist.All()
|
storedKeys := c.persist.All()
|
||||||
for _, key := range storedKeys {
|
for _, key := range storedKeys {
|
||||||
packet := c.persist.Get(key)
|
packet := c.persist.Get(key)
|
||||||
@@ -956,14 +1118,16 @@ func (c *client) resume(subscription bool, ibound chan packets.ControlPacket) {
|
|||||||
c.claimID(token, details.MessageID)
|
c.claimID(token, details.MessageID)
|
||||||
DEBUG.Println(STR, fmt.Sprintf("loaded pending publish (%d)", details.MessageID))
|
DEBUG.Println(STR, fmt.Sprintf("loaded pending publish (%d)", details.MessageID))
|
||||||
DEBUG.Println(STR, details)
|
DEBUG.Println(STR, details)
|
||||||
|
getSemaphore()
|
||||||
select {
|
select {
|
||||||
case c.obound <- &PacketAndToken{p: p, t: token}:
|
case c.obound <- &PacketAndToken{p: p, t: token}:
|
||||||
case <-c.stop:
|
case <-c.stop:
|
||||||
DEBUG.Println(STR, "resume exiting due to stop")
|
DEBUG.Println(STR, "resume exiting due to stop")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
releaseSemaphore(token) // If limiting simultaneous messages then we need to know when message is acknowledged
|
||||||
default:
|
default:
|
||||||
ERROR.Println(STR, "invalid message type in store (discarded)")
|
ERROR.Println(STR, fmt.Sprintf("invalid message type (inbound - %T) in store (discarded)", packet))
|
||||||
c.persist.Del(key)
|
c.persist.Del(key)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -977,7 +1141,7 @@ func (c *client) resume(subscription bool, ibound chan packets.ControlPacket) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ERROR.Println(STR, "invalid message type in store (discarded)")
|
ERROR.Println(STR, fmt.Sprintf("invalid message type (%T) in store (discarded)", packet))
|
||||||
c.persist.Del(key)
|
c.persist.Del(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -998,11 +1162,11 @@ func (c *client) Unsubscribe(topics ...string) Token {
|
|||||||
if !c.IsConnectionOpen() {
|
if !c.IsConnectionOpen() {
|
||||||
switch {
|
switch {
|
||||||
case !c.options.ResumeSubs:
|
case !c.options.ResumeSubs:
|
||||||
// if not connected and resumesubs not set this unsub will be thrown away
|
// if not connected and resumeSubs not set this unsub will be thrown away
|
||||||
token.setError(fmt.Errorf("not currently connected and ResumeSubs not set"))
|
token.setError(fmt.Errorf("not currently connected and ResumeSubs not set"))
|
||||||
return token
|
return token
|
||||||
case c.options.CleanSession && c.connectionStatus() == reconnecting:
|
case c.options.CleanSession && c.status.ConnectionStatus() == reconnecting:
|
||||||
// if reconnecting and cleansession is true this unsub will be thrown away
|
// if reconnecting and cleanSession is true this unsub will be thrown away
|
||||||
token.setError(fmt.Errorf("reconnecting state and cleansession is true"))
|
token.setError(fmt.Errorf("reconnecting state and cleansession is true"))
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
@@ -1021,13 +1185,17 @@ func (c *client) Unsubscribe(topics ...string) Token {
|
|||||||
token.messageID = mID
|
token.messageID = mID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.options.ResumeSubs { // Only persist if we need this to resume subs after a disconnection
|
||||||
persistOutbound(c.persist, unsub)
|
persistOutbound(c.persist, unsub)
|
||||||
|
}
|
||||||
|
|
||||||
switch c.connectionStatus() {
|
switch c.status.ConnectionStatus() {
|
||||||
case connecting:
|
case connecting:
|
||||||
DEBUG.Println(CLI, "storing unsubscribe message (connecting), topics:", topics)
|
DEBUG.Println(CLI, "storing unsubscribe message (connecting), topics:", topics)
|
||||||
case reconnecting:
|
case reconnecting:
|
||||||
DEBUG.Println(CLI, "storing unsubscribe message (reconnecting), topics:", topics)
|
DEBUG.Println(CLI, "storing unsubscribe message (reconnecting), topics:", topics)
|
||||||
|
case disconnecting:
|
||||||
|
DEBUG.Println(CLI, "storing unsubscribe message (reconnecting), topics:", topics)
|
||||||
default:
|
default:
|
||||||
DEBUG.Println(CLI, "sending unsubscribe message, topics:", topics)
|
DEBUG.Println(CLI, "sending unsubscribe message, topics:", topics)
|
||||||
subscribeWaitTimeout := c.options.WriteTimeout
|
subscribeWaitTimeout := c.options.WriteTimeout
|
||||||
|
|||||||
12
vendor/github.com/eclipse/paho.mqtt.golang/components.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/components.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
|
|||||||
70
vendor/github.com/eclipse/paho.mqtt.golang/epl-v10
generated
vendored
70
vendor/github.com/eclipse/paho.mqtt.golang/epl-v10
generated
vendored
@@ -1,70 +0,0 @@
|
|||||||
Eclipse Public License - v 1.0
|
|
||||||
|
|
||||||
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
|
||||||
|
|
||||||
1. DEFINITIONS
|
|
||||||
|
|
||||||
"Contribution" means:
|
|
||||||
|
|
||||||
a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
|
|
||||||
b) in the case of each subsequent Contributor:
|
|
||||||
i) changes to the Program, and
|
|
||||||
ii) additions to the Program;
|
|
||||||
where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
|
|
||||||
"Contributor" means any person or entity that distributes the Program.
|
|
||||||
|
|
||||||
"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
|
|
||||||
|
|
||||||
"Program" means the Contributions distributed in accordance with this Agreement.
|
|
||||||
|
|
||||||
"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
|
|
||||||
|
|
||||||
2. GRANT OF RIGHTS
|
|
||||||
|
|
||||||
a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
|
|
||||||
b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
|
|
||||||
c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
|
|
||||||
d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
|
|
||||||
3. REQUIREMENTS
|
|
||||||
|
|
||||||
A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
|
|
||||||
|
|
||||||
a) it complies with the terms and conditions of this Agreement; and
|
|
||||||
b) its license agreement:
|
|
||||||
i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
|
|
||||||
ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
|
|
||||||
iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
|
|
||||||
iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
|
|
||||||
When the Program is made available in source code form:
|
|
||||||
|
|
||||||
a) it must be made available under this Agreement; and
|
|
||||||
b) a copy of this Agreement must be included with each copy of the Program.
|
|
||||||
Contributors may not remove or alter any copyright notices contained within the Program.
|
|
||||||
|
|
||||||
Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
|
|
||||||
|
|
||||||
4. COMMERCIAL DISTRIBUTION
|
|
||||||
|
|
||||||
Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
|
|
||||||
|
|
||||||
For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
|
|
||||||
|
|
||||||
5. NO WARRANTY
|
|
||||||
|
|
||||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
|
|
||||||
|
|
||||||
6. DISCLAIMER OF LIABILITY
|
|
||||||
|
|
||||||
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
7. GENERAL
|
|
||||||
|
|
||||||
If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
|
|
||||||
|
|
||||||
If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
|
|
||||||
|
|
||||||
All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
|
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
|
|
||||||
|
|
||||||
This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
|
|
||||||
277
vendor/github.com/eclipse/paho.mqtt.golang/epl-v20
generated
vendored
Normal file
277
vendor/github.com/eclipse/paho.mqtt.golang/epl-v20
generated
vendored
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
Eclipse Public License - v 2.0
|
||||||
|
|
||||||
|
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
|
||||||
|
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
|
||||||
|
OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
||||||
|
|
||||||
|
1. DEFINITIONS
|
||||||
|
|
||||||
|
"Contribution" means:
|
||||||
|
|
||||||
|
a) in the case of the initial Contributor, the initial content
|
||||||
|
Distributed under this Agreement, and
|
||||||
|
|
||||||
|
b) in the case of each subsequent Contributor:
|
||||||
|
i) changes to the Program, and
|
||||||
|
ii) additions to the Program;
|
||||||
|
where such changes and/or additions to the Program originate from
|
||||||
|
and are Distributed by that particular Contributor. A Contribution
|
||||||
|
"originates" from a Contributor if it was added to the Program by
|
||||||
|
such Contributor itself or anyone acting on such Contributor's behalf.
|
||||||
|
Contributions do not include changes or additions to the Program that
|
||||||
|
are not Modified Works.
|
||||||
|
|
||||||
|
"Contributor" means any person or entity that Distributes the Program.
|
||||||
|
|
||||||
|
"Licensed Patents" mean patent claims licensable by a Contributor which
|
||||||
|
are necessarily infringed by the use or sale of its Contribution alone
|
||||||
|
or when combined with the Program.
|
||||||
|
|
||||||
|
"Program" means the Contributions Distributed in accordance with this
|
||||||
|
Agreement.
|
||||||
|
|
||||||
|
"Recipient" means anyone who receives the Program under this Agreement
|
||||||
|
or any Secondary License (as applicable), including Contributors.
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source Code or other
|
||||||
|
form, that is based on (or derived from) the Program and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship.
|
||||||
|
|
||||||
|
"Modified Works" shall mean any work in Source Code or other form that
|
||||||
|
results from an addition to, deletion from, or modification of the
|
||||||
|
contents of the Program, including, for purposes of clarity any new file
|
||||||
|
in Source Code form that contains any contents of the Program. Modified
|
||||||
|
Works shall not include works that contain only declarations,
|
||||||
|
interfaces, types, classes, structures, or files of the Program solely
|
||||||
|
in each case in order to link to, bind by name, or subclass the Program
|
||||||
|
or Modified Works thereof.
|
||||||
|
|
||||||
|
"Distribute" means the acts of a) distributing or b) making available
|
||||||
|
in any manner that enables the transfer of a copy.
|
||||||
|
|
||||||
|
"Source Code" means the form of a Program preferred for making
|
||||||
|
modifications, including but not limited to software source code,
|
||||||
|
documentation source, and configuration files.
|
||||||
|
|
||||||
|
"Secondary License" means either the GNU General Public License,
|
||||||
|
Version 2.0, or any later versions of that license, including any
|
||||||
|
exceptions or additional permissions as identified by the initial
|
||||||
|
Contributor.
|
||||||
|
|
||||||
|
2. GRANT OF RIGHTS
|
||||||
|
|
||||||
|
a) Subject to the terms of this Agreement, each Contributor hereby
|
||||||
|
grants Recipient a non-exclusive, worldwide, royalty-free copyright
|
||||||
|
license to reproduce, prepare Derivative Works of, publicly display,
|
||||||
|
publicly perform, Distribute and sublicense the Contribution of such
|
||||||
|
Contributor, if any, and such Derivative Works.
|
||||||
|
|
||||||
|
b) Subject to the terms of this Agreement, each Contributor hereby
|
||||||
|
grants Recipient a non-exclusive, worldwide, royalty-free patent
|
||||||
|
license under Licensed Patents to make, use, sell, offer to sell,
|
||||||
|
import and otherwise transfer the Contribution of such Contributor,
|
||||||
|
if any, in Source Code or other form. This patent license shall
|
||||||
|
apply to the combination of the Contribution and the Program if, at
|
||||||
|
the time the Contribution is added by the Contributor, such addition
|
||||||
|
of the Contribution causes such combination to be covered by the
|
||||||
|
Licensed Patents. The patent license shall not apply to any other
|
||||||
|
combinations which include the Contribution. No hardware per se is
|
||||||
|
licensed hereunder.
|
||||||
|
|
||||||
|
c) Recipient understands that although each Contributor grants the
|
||||||
|
licenses to its Contributions set forth herein, no assurances are
|
||||||
|
provided by any Contributor that the Program does not infringe the
|
||||||
|
patent or other intellectual property rights of any other entity.
|
||||||
|
Each Contributor disclaims any liability to Recipient for claims
|
||||||
|
brought by any other entity based on infringement of intellectual
|
||||||
|
property rights or otherwise. As a condition to exercising the
|
||||||
|
rights and licenses granted hereunder, each Recipient hereby
|
||||||
|
assumes sole responsibility to secure any other intellectual
|
||||||
|
property rights needed, if any. For example, if a third party
|
||||||
|
patent license is required to allow Recipient to Distribute the
|
||||||
|
Program, it is Recipient's responsibility to acquire that license
|
||||||
|
before distributing the Program.
|
||||||
|
|
||||||
|
d) Each Contributor represents that to its knowledge it has
|
||||||
|
sufficient copyright rights in its Contribution, if any, to grant
|
||||||
|
the copyright license set forth in this Agreement.
|
||||||
|
|
||||||
|
e) Notwithstanding the terms of any Secondary License, no
|
||||||
|
Contributor makes additional grants to any Recipient (other than
|
||||||
|
those set forth in this Agreement) as a result of such Recipient's
|
||||||
|
receipt of the Program under the terms of a Secondary License
|
||||||
|
(if permitted under the terms of Section 3).
|
||||||
|
|
||||||
|
3. REQUIREMENTS
|
||||||
|
|
||||||
|
3.1 If a Contributor Distributes the Program in any form, then:
|
||||||
|
|
||||||
|
a) the Program must also be made available as Source Code, in
|
||||||
|
accordance with section 3.2, and the Contributor must accompany
|
||||||
|
the Program with a statement that the Source Code for the Program
|
||||||
|
is available under this Agreement, and informs Recipients how to
|
||||||
|
obtain it in a reasonable manner on or through a medium customarily
|
||||||
|
used for software exchange; and
|
||||||
|
|
||||||
|
b) the Contributor may Distribute the Program under a license
|
||||||
|
different than this Agreement, provided that such license:
|
||||||
|
i) effectively disclaims on behalf of all other Contributors all
|
||||||
|
warranties and conditions, express and implied, including
|
||||||
|
warranties or conditions of title and non-infringement, and
|
||||||
|
implied warranties or conditions of merchantability and fitness
|
||||||
|
for a particular purpose;
|
||||||
|
|
||||||
|
ii) effectively excludes on behalf of all other Contributors all
|
||||||
|
liability for damages, including direct, indirect, special,
|
||||||
|
incidental and consequential damages, such as lost profits;
|
||||||
|
|
||||||
|
iii) does not attempt to limit or alter the recipients' rights
|
||||||
|
in the Source Code under section 3.2; and
|
||||||
|
|
||||||
|
iv) requires any subsequent distribution of the Program by any
|
||||||
|
party to be under a license that satisfies the requirements
|
||||||
|
of this section 3.
|
||||||
|
|
||||||
|
3.2 When the Program is Distributed as Source Code:
|
||||||
|
|
||||||
|
a) it must be made available under this Agreement, or if the
|
||||||
|
Program (i) is combined with other material in a separate file or
|
||||||
|
files made available under a Secondary License, and (ii) the initial
|
||||||
|
Contributor attached to the Source Code the notice described in
|
||||||
|
Exhibit A of this Agreement, then the Program may be made available
|
||||||
|
under the terms of such Secondary Licenses, and
|
||||||
|
|
||||||
|
b) a copy of this Agreement must be included with each copy of
|
||||||
|
the Program.
|
||||||
|
|
||||||
|
3.3 Contributors may not remove or alter any copyright, patent,
|
||||||
|
trademark, attribution notices, disclaimers of warranty, or limitations
|
||||||
|
of liability ("notices") contained within the Program from any copy of
|
||||||
|
the Program which they Distribute, provided that Contributors may add
|
||||||
|
their own appropriate notices.
|
||||||
|
|
||||||
|
4. COMMERCIAL DISTRIBUTION
|
||||||
|
|
||||||
|
Commercial distributors of software may accept certain responsibilities
|
||||||
|
with respect to end users, business partners and the like. While this
|
||||||
|
license is intended to facilitate the commercial use of the Program,
|
||||||
|
the Contributor who includes the Program in a commercial product
|
||||||
|
offering should do so in a manner which does not create potential
|
||||||
|
liability for other Contributors. Therefore, if a Contributor includes
|
||||||
|
the Program in a commercial product offering, such Contributor
|
||||||
|
("Commercial Contributor") hereby agrees to defend and indemnify every
|
||||||
|
other Contributor ("Indemnified Contributor") against any losses,
|
||||||
|
damages and costs (collectively "Losses") arising from claims, lawsuits
|
||||||
|
and other legal actions brought by a third party against the Indemnified
|
||||||
|
Contributor to the extent caused by the acts or omissions of such
|
||||||
|
Commercial Contributor in connection with its distribution of the Program
|
||||||
|
in a commercial product offering. The obligations in this section do not
|
||||||
|
apply to any claims or Losses relating to any actual or alleged
|
||||||
|
intellectual property infringement. In order to qualify, an Indemnified
|
||||||
|
Contributor must: a) promptly notify the Commercial Contributor in
|
||||||
|
writing of such claim, and b) allow the Commercial Contributor to control,
|
||||||
|
and cooperate with the Commercial Contributor in, the defense and any
|
||||||
|
related settlement negotiations. The Indemnified Contributor may
|
||||||
|
participate in any such claim at its own expense.
|
||||||
|
|
||||||
|
For example, a Contributor might include the Program in a commercial
|
||||||
|
product offering, Product X. That Contributor is then a Commercial
|
||||||
|
Contributor. If that Commercial Contributor then makes performance
|
||||||
|
claims, or offers warranties related to Product X, those performance
|
||||||
|
claims and warranties are such Commercial Contributor's responsibility
|
||||||
|
alone. Under this section, the Commercial Contributor would have to
|
||||||
|
defend claims against the other Contributors related to those performance
|
||||||
|
claims and warranties, and if a court requires any other Contributor to
|
||||||
|
pay any damages as a result, the Commercial Contributor must pay
|
||||||
|
those damages.
|
||||||
|
|
||||||
|
5. NO WARRANTY
|
||||||
|
|
||||||
|
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
||||||
|
PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS"
|
||||||
|
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF
|
||||||
|
TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. Each Recipient is solely responsible for determining the
|
||||||
|
appropriateness of using and distributing the Program and assumes all
|
||||||
|
risks associated with its exercise of rights under this Agreement,
|
||||||
|
including but not limited to the risks and costs of program errors,
|
||||||
|
compliance with applicable laws, damage to or loss of data, programs
|
||||||
|
or equipment, and unavailability or interruption of operations.
|
||||||
|
|
||||||
|
6. DISCLAIMER OF LIABILITY
|
||||||
|
|
||||||
|
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
||||||
|
PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS
|
||||||
|
SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
|
||||||
|
PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
|
||||||
|
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
7. GENERAL
|
||||||
|
|
||||||
|
If any provision of this Agreement is invalid or unenforceable under
|
||||||
|
applicable law, it shall not affect the validity or enforceability of
|
||||||
|
the remainder of the terms of this Agreement, and without further
|
||||||
|
action by the parties hereto, such provision shall be reformed to the
|
||||||
|
minimum extent necessary to make such provision valid and enforceable.
|
||||||
|
|
||||||
|
If Recipient institutes patent litigation against any entity
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that the
|
||||||
|
Program itself (excluding combinations of the Program with other software
|
||||||
|
or hardware) infringes such Recipient's patent(s), then such Recipient's
|
||||||
|
rights granted under Section 2(b) shall terminate as of the date such
|
||||||
|
litigation is filed.
|
||||||
|
|
||||||
|
All Recipient's rights under this Agreement shall terminate if it
|
||||||
|
fails to comply with any of the material terms or conditions of this
|
||||||
|
Agreement and does not cure such failure in a reasonable period of
|
||||||
|
time after becoming aware of such noncompliance. If all Recipient's
|
||||||
|
rights under this Agreement terminate, Recipient agrees to cease use
|
||||||
|
and distribution of the Program as soon as reasonably practicable.
|
||||||
|
However, Recipient's obligations under this Agreement and any licenses
|
||||||
|
granted by Recipient relating to the Program shall continue and survive.
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute copies of this Agreement,
|
||||||
|
but in order to avoid inconsistency the Agreement is copyrighted and
|
||||||
|
may only be modified in the following manner. The Agreement Steward
|
||||||
|
reserves the right to publish new versions (including revisions) of
|
||||||
|
this Agreement from time to time. No one other than the Agreement
|
||||||
|
Steward has the right to modify this Agreement. The Eclipse Foundation
|
||||||
|
is the initial Agreement Steward. The Eclipse Foundation may assign the
|
||||||
|
responsibility to serve as the Agreement Steward to a suitable separate
|
||||||
|
entity. Each new version of the Agreement will be given a distinguishing
|
||||||
|
version number. The Program (including Contributions) may always be
|
||||||
|
Distributed subject to the version of the Agreement under which it was
|
||||||
|
received. In addition, after a new version of the Agreement is published,
|
||||||
|
Contributor may elect to Distribute the Program (including its
|
||||||
|
Contributions) under the new version.
|
||||||
|
|
||||||
|
Except as expressly stated in Sections 2(a) and 2(b) above, Recipient
|
||||||
|
receives no rights or licenses to the intellectual property of any
|
||||||
|
Contributor under this Agreement, whether expressly, by implication,
|
||||||
|
estoppel or otherwise. All rights in the Program not expressly granted
|
||||||
|
under this Agreement are reserved. Nothing in this Agreement is intended
|
||||||
|
to be enforceable by any entity that is not a Contributor or Recipient.
|
||||||
|
No third-party beneficiary rights are created under this Agreement.
|
||||||
|
|
||||||
|
Exhibit A - Form of Secondary Licenses Notice
|
||||||
|
|
||||||
|
"This Source Code may also be made available under the following
|
||||||
|
Secondary Licenses when the conditions for such availability set forth
|
||||||
|
in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
|
||||||
|
version(s), and exceptions or additional permissions here}."
|
||||||
|
|
||||||
|
Simply including a copy of this Agreement, including this Exhibit A
|
||||||
|
is not sufficient to license the Source Code under Secondary Licenses.
|
||||||
|
|
||||||
|
If it is not possible or desirable to put the notice in a particular
|
||||||
|
file, then You may include the notice in a location (such as a LICENSE
|
||||||
|
file in a relevant directory) where a recipient would be likely to
|
||||||
|
look for such a notice.
|
||||||
|
|
||||||
|
You may add additional accurate notices of copyright ownership.
|
||||||
27
vendor/github.com/eclipse/paho.mqtt.golang/filestore.go
generated
vendored
27
vendor/github.com/eclipse/paho.mqtt.golang/filestore.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
@@ -15,7 +19,7 @@
|
|||||||
package mqtt
|
package mqtt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -155,20 +159,25 @@ func (store *FileStore) Reset() {
|
|||||||
func (store *FileStore) all() []string {
|
func (store *FileStore) all() []string {
|
||||||
var err error
|
var err error
|
||||||
var keys []string
|
var keys []string
|
||||||
var files fileInfos
|
|
||||||
|
|
||||||
if !store.opened {
|
if !store.opened {
|
||||||
ERROR.Println(STR, "trying to use file store, but not open")
|
ERROR.Println(STR, "trying to use file store, but not open")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err = ioutil.ReadDir(store.directory)
|
entries, err := os.ReadDir(store.directory)
|
||||||
chkerr(err)
|
chkerr(err)
|
||||||
|
files := make(fileInfos, 0, len(entries))
|
||||||
|
for _, entry := range entries {
|
||||||
|
info, err := entry.Info()
|
||||||
|
chkerr(err)
|
||||||
|
files = append(files, info)
|
||||||
|
}
|
||||||
sort.Sort(files)
|
sort.Sort(files)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
DEBUG.Println(STR, "file in All():", f.Name())
|
DEBUG.Println(STR, "file in All():", f.Name())
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
if name[len(name)-4:] != msgExt {
|
if len(name) < len(msgExt) || name[len(name)-len(msgExt):] != msgExt {
|
||||||
DEBUG.Println(STR, "skipping file, doesn't have right extension: ", name)
|
DEBUG.Println(STR, "skipping file, doesn't have right extension: ", name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -242,7 +251,7 @@ func exists(file string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
type fileInfos []os.FileInfo
|
type fileInfos []fs.FileInfo
|
||||||
|
|
||||||
func (f fileInfos) Len() int {
|
func (f fileInfos) Len() int {
|
||||||
return len(f)
|
return len(f)
|
||||||
|
|||||||
8
vendor/github.com/eclipse/paho.mqtt.golang/go.mod
generated
vendored
8
vendor/github.com/eclipse/paho.mqtt.golang/go.mod
generated
vendored
@@ -1,8 +0,0 @@
|
|||||||
module github.com/eclipse/paho.mqtt.golang
|
|
||||||
|
|
||||||
go 1.14
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/gorilla/websocket v1.4.2
|
|
||||||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0
|
|
||||||
)
|
|
||||||
8
vendor/github.com/eclipse/paho.mqtt.golang/go.sum
generated
vendored
8
vendor/github.com/eclipse/paho.mqtt.golang/go.sum
generated
vendored
@@ -1,8 +0,0 @@
|
|||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U=
|
|
||||||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
12
vendor/github.com/eclipse/paho.mqtt.golang/memstore.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/memstore.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
|
|||||||
166
vendor/github.com/eclipse/paho.mqtt.golang/memstore_ordered.go
generated
vendored
Normal file
166
vendor/github.com/eclipse/paho.mqtt.golang/memstore_ordered.go
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
* Matt Brittan
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderedMemoryStore uses a map internally so the order in which All() returns packets is
|
||||||
|
// undefined. OrderedMemoryStore resolves this by storing the time the message is added
|
||||||
|
// and sorting based upon this.
|
||||||
|
|
||||||
|
// storedMessage encapsulates a message and the time it was initially stored
|
||||||
|
type storedMessage struct {
|
||||||
|
ts time.Time
|
||||||
|
msg packets.ControlPacket
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderedMemoryStore implements the store interface to provide a "persistence"
|
||||||
|
// mechanism wholly stored in memory. This is only useful for
|
||||||
|
// as long as the client instance exists.
|
||||||
|
type OrderedMemoryStore struct {
|
||||||
|
sync.RWMutex
|
||||||
|
messages map[string]storedMessage
|
||||||
|
opened bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewOrderedMemoryStore returns a pointer to a new instance of
|
||||||
|
// OrderedMemoryStore, the instance is not initialized and ready to
|
||||||
|
// use until Open() has been called on it.
|
||||||
|
func NewOrderedMemoryStore() *OrderedMemoryStore {
|
||||||
|
store := &OrderedMemoryStore{
|
||||||
|
messages: make(map[string]storedMessage),
|
||||||
|
opened: false,
|
||||||
|
}
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open initializes a OrderedMemoryStore instance.
|
||||||
|
func (store *OrderedMemoryStore) Open() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
store.opened = true
|
||||||
|
DEBUG.Println(STR, "OrderedMemoryStore initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put takes a key and a pointer to a Message and stores the
|
||||||
|
// message.
|
||||||
|
func (store *OrderedMemoryStore) Put(key string, message packets.ControlPacket) {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
store.messages[key] = storedMessage{ts: time.Now(), msg: message}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get takes a key and looks in the store for a matching Message
|
||||||
|
// returning either the Message pointer or nil.
|
||||||
|
func (store *OrderedMemoryStore) Get(key string) packets.ControlPacket {
|
||||||
|
store.RLock()
|
||||||
|
defer store.RUnlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
mid := mIDFromKey(key)
|
||||||
|
m, ok := store.messages[key]
|
||||||
|
if !ok || m.msg == nil {
|
||||||
|
CRITICAL.Println(STR, "OrderedMemoryStore get: message", mid, "not found")
|
||||||
|
} else {
|
||||||
|
DEBUG.Println(STR, "OrderedMemoryStore get: message", mid, "found")
|
||||||
|
}
|
||||||
|
return m.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// All returns a slice of strings containing all the keys currently
|
||||||
|
// in the OrderedMemoryStore.
|
||||||
|
func (store *OrderedMemoryStore) All() []string {
|
||||||
|
store.RLock()
|
||||||
|
defer store.RUnlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
type tsAndKey struct {
|
||||||
|
ts time.Time
|
||||||
|
key string
|
||||||
|
}
|
||||||
|
|
||||||
|
tsKeys := make([]tsAndKey, 0, len(store.messages))
|
||||||
|
for k, v := range store.messages {
|
||||||
|
tsKeys = append(tsKeys, tsAndKey{ts: v.ts, key: k})
|
||||||
|
}
|
||||||
|
sort.Slice(tsKeys, func(a int, b int) bool { return tsKeys[a].ts.Before(tsKeys[b].ts) })
|
||||||
|
|
||||||
|
keys := make([]string, len(tsKeys))
|
||||||
|
for i := range tsKeys {
|
||||||
|
keys[i] = tsKeys[i].key
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
// Del takes a key, searches the OrderedMemoryStore and if the key is found
|
||||||
|
// deletes the Message pointer associated with it.
|
||||||
|
func (store *OrderedMemoryStore) Del(key string) {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mid := mIDFromKey(key)
|
||||||
|
_, ok := store.messages[key]
|
||||||
|
if !ok {
|
||||||
|
WARN.Println(STR, "OrderedMemoryStore del: message", mid, "not found")
|
||||||
|
} else {
|
||||||
|
delete(store.messages, key)
|
||||||
|
DEBUG.Println(STR, "OrderedMemoryStore del: message", mid, "was deleted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close will disallow modifications to the state of the store.
|
||||||
|
func (store *OrderedMemoryStore) Close() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to close memory store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
store.opened = false
|
||||||
|
DEBUG.Println(STR, "OrderedMemoryStore closed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset eliminates all persisted message data in the store.
|
||||||
|
func (store *OrderedMemoryStore) Reset() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to reset memory store, but not open")
|
||||||
|
}
|
||||||
|
store.messages = make(map[string]storedMessage)
|
||||||
|
WARN.Println(STR, "OrderedMemoryStore wiped")
|
||||||
|
}
|
||||||
12
vendor/github.com/eclipse/paho.mqtt.golang/message.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/message.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
|
|||||||
56
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
56
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
@@ -1,15 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2013 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
* Allan Stockdill-Mander
|
* Allan Stockdill-Mander
|
||||||
* Mike Robertson
|
* Mike Robertson
|
||||||
|
* Matt Brittan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mqtt
|
package mqtt
|
||||||
@@ -26,7 +31,7 @@ import (
|
|||||||
type MId uint16
|
type MId uint16
|
||||||
|
|
||||||
type messageIds struct {
|
type messageIds struct {
|
||||||
sync.RWMutex
|
mu sync.RWMutex // Named to prevent Mu from being accessible directly via client
|
||||||
index map[uint16]tokenCompletor
|
index map[uint16]tokenCompletor
|
||||||
|
|
||||||
lastIssuedID uint16 // The most recently issued ID. Used so we cycle through ids rather than immediately reusing them (can make debugging easier)
|
lastIssuedID uint16 // The most recently issued ID. Used so we cycle through ids rather than immediately reusing them (can make debugging easier)
|
||||||
@@ -37,8 +42,9 @@ const (
|
|||||||
midMax uint16 = 65535
|
midMax uint16 = 65535
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// cleanup clears the message ID map; completes all token types and sets error on PUB, SUB and UNSUB tokens.
|
||||||
func (mids *messageIds) cleanUp() {
|
func (mids *messageIds) cleanUp() {
|
||||||
mids.Lock()
|
mids.mu.Lock()
|
||||||
for _, token := range mids.index {
|
for _, token := range mids.index {
|
||||||
switch token.(type) {
|
switch token.(type) {
|
||||||
case *PublishToken:
|
case *PublishToken:
|
||||||
@@ -47,25 +53,43 @@ func (mids *messageIds) cleanUp() {
|
|||||||
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
|
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
|
||||||
case *UnsubscribeToken:
|
case *UnsubscribeToken:
|
||||||
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
|
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
|
||||||
case nil:
|
case nil: // should not be any nil entries
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
token.flowComplete()
|
token.flowComplete()
|
||||||
}
|
}
|
||||||
mids.index = make(map[uint16]tokenCompletor)
|
mids.index = make(map[uint16]tokenCompletor)
|
||||||
mids.Unlock()
|
mids.mu.Unlock()
|
||||||
DEBUG.Println(MID, "cleaned up")
|
DEBUG.Println(MID, "cleaned up")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cleanUpSubscribe removes all SUBSCRIBE and UNSUBSCRIBE tokens (setting error)
|
||||||
|
// This may be called when the connection is lost, and we will not be resending SUB/UNSUB packets
|
||||||
|
func (mids *messageIds) cleanUpSubscribe() {
|
||||||
|
mids.mu.Lock()
|
||||||
|
for mid, token := range mids.index {
|
||||||
|
switch token.(type) {
|
||||||
|
case *SubscribeToken:
|
||||||
|
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
|
||||||
|
delete(mids.index, mid)
|
||||||
|
case *UnsubscribeToken:
|
||||||
|
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
|
||||||
|
delete(mids.index, mid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mids.mu.Unlock()
|
||||||
|
DEBUG.Println(MID, "cleaned up subs")
|
||||||
|
}
|
||||||
|
|
||||||
func (mids *messageIds) freeID(id uint16) {
|
func (mids *messageIds) freeID(id uint16) {
|
||||||
mids.Lock()
|
mids.mu.Lock()
|
||||||
delete(mids.index, id)
|
delete(mids.index, id)
|
||||||
mids.Unlock()
|
mids.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mids *messageIds) claimID(token tokenCompletor, id uint16) {
|
func (mids *messageIds) claimID(token tokenCompletor, id uint16) {
|
||||||
mids.Lock()
|
mids.mu.Lock()
|
||||||
defer mids.Unlock()
|
defer mids.mu.Unlock()
|
||||||
if _, ok := mids.index[id]; !ok {
|
if _, ok := mids.index[id]; !ok {
|
||||||
mids.index[id] = token
|
mids.index[id] = token
|
||||||
} else {
|
} else {
|
||||||
@@ -81,8 +105,8 @@ func (mids *messageIds) claimID(token tokenCompletor, id uint16) {
|
|||||||
// getID will return an available id or 0 if none available
|
// getID will return an available id or 0 if none available
|
||||||
// The id will generally be the previous id + 1 (because this makes tracing messages a bit simpler)
|
// The id will generally be the previous id + 1 (because this makes tracing messages a bit simpler)
|
||||||
func (mids *messageIds) getID(t tokenCompletor) uint16 {
|
func (mids *messageIds) getID(t tokenCompletor) uint16 {
|
||||||
mids.Lock()
|
mids.mu.Lock()
|
||||||
defer mids.Unlock()
|
defer mids.mu.Unlock()
|
||||||
i := mids.lastIssuedID // note: the only situation where lastIssuedID is 0 the map will be empty
|
i := mids.lastIssuedID // note: the only situation where lastIssuedID is 0 the map will be empty
|
||||||
looped := false // uint16 will loop from 65535->0
|
looped := false // uint16 will loop from 65535->0
|
||||||
for {
|
for {
|
||||||
@@ -103,8 +127,8 @@ func (mids *messageIds) getID(t tokenCompletor) uint16 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mids *messageIds) getToken(id uint16) tokenCompletor {
|
func (mids *messageIds) getToken(id uint16) tokenCompletor {
|
||||||
mids.RLock()
|
mids.mu.RLock()
|
||||||
defer mids.RUnlock()
|
defer mids.mu.RUnlock()
|
||||||
if token, ok := mids.index[id]; ok {
|
if token, ok := mids.index[id]; ok {
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|||||||
31
vendor/github.com/eclipse/paho.mqtt.golang/net.go
generated
vendored
31
vendor/github.com/eclipse/paho.mqtt.golang/net.go
generated
vendored
@@ -1,15 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
* Allan Stockdill-Mander
|
* Allan Stockdill-Mander
|
||||||
* Mike Robertson
|
* Mike Robertson
|
||||||
|
* Matt Brittan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mqtt
|
package mqtt
|
||||||
@@ -145,7 +150,7 @@ type incomingComms struct {
|
|||||||
|
|
||||||
// startIncomingComms initiates incoming communications; this includes starting a goroutine to process incoming
|
// startIncomingComms initiates incoming communications; this includes starting a goroutine to process incoming
|
||||||
// messages.
|
// messages.
|
||||||
// Accepts a channel of inbound messages from the store (persisted messages); note this must be closed as soon as the
|
// Accepts a channel of inbound messages from the store (persisted messages); note this must be closed as soon as
|
||||||
// everything in the store has been sent.
|
// everything in the store has been sent.
|
||||||
// Returns a channel that will be passed any received packets; this will be closed on a network error (and inboundFromStore closed)
|
// Returns a channel that will be passed any received packets; this will be closed on a network error (and inboundFromStore closed)
|
||||||
func startIncomingComms(conn io.Reader,
|
func startIncomingComms(conn io.Reader,
|
||||||
@@ -327,7 +332,7 @@ func startOutgoingComms(conn net.Conn,
|
|||||||
DEBUG.Println(NET, "outbound wrote disconnect, closing connection")
|
DEBUG.Println(NET, "outbound wrote disconnect, closing connection")
|
||||||
// As per the MQTT spec "After sending a DISCONNECT Packet the Client MUST close the Network Connection"
|
// As per the MQTT spec "After sending a DISCONNECT Packet the Client MUST close the Network Connection"
|
||||||
// Closing the connection will cause the goroutines to end in sequence (starting with incoming comms)
|
// Closing the connection will cause the goroutines to end in sequence (starting with incoming comms)
|
||||||
conn.Close()
|
_ = conn.Close()
|
||||||
}
|
}
|
||||||
case msg, ok := <-oboundFromIncoming: // message triggered by an inbound message (PubrecPacket or PubrelPacket)
|
case msg, ok := <-oboundFromIncoming: // message triggered by an inbound message (PubrecPacket or PubrelPacket)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -365,6 +370,7 @@ type commsFns interface {
|
|||||||
// startComms initiates goroutines that handles communications over the network connection
|
// startComms initiates goroutines that handles communications over the network connection
|
||||||
// Messages will be stored (via commsFns) and deleted from the store as necessary
|
// Messages will be stored (via commsFns) and deleted from the store as necessary
|
||||||
// It returns two channels:
|
// It returns two channels:
|
||||||
|
//
|
||||||
// packets.PublishPacket - Will receive publish packets received over the network.
|
// packets.PublishPacket - Will receive publish packets received over the network.
|
||||||
// Closed when incoming comms routines exit (on shutdown or if network link closed)
|
// Closed when incoming comms routines exit (on shutdown or if network link closed)
|
||||||
// error - Any errors will be sent on this channel. The channel is closed when all comms routines have shut down
|
// error - Any errors will be sent on this channel. The channel is closed when all comms routines have shut down
|
||||||
@@ -438,24 +444,23 @@ func startComms(conn net.Conn, // Network connection (must be active)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ackFunc acknowledges a packet
|
// ackFunc acknowledges a packet
|
||||||
// WARNING the function returned must not be called if the comms routine is shutting down or not running
|
// WARNING sendAck may be called at any time (even after the connection is dead). At the time of writing ACK sent after
|
||||||
// (it needs outgoing comms in order to send the acknowledgement). Currently this is only called from
|
// connection loss will be dropped (this is not ideal)
|
||||||
// matchAndDispatch which will be shutdown before the comms are
|
func ackFunc(sendAck func(*PacketAndToken), persist Store, packet *packets.PublishPacket) func() {
|
||||||
func ackFunc(oboundP chan *PacketAndToken, persist Store, packet *packets.PublishPacket) func() {
|
|
||||||
return func() {
|
return func() {
|
||||||
switch packet.Qos {
|
switch packet.Qos {
|
||||||
case 2:
|
case 2:
|
||||||
pr := packets.NewControlPacket(packets.Pubrec).(*packets.PubrecPacket)
|
pr := packets.NewControlPacket(packets.Pubrec).(*packets.PubrecPacket)
|
||||||
pr.MessageID = packet.MessageID
|
pr.MessageID = packet.MessageID
|
||||||
DEBUG.Println(NET, "putting pubrec msg on obound")
|
DEBUG.Println(NET, "putting pubrec msg on obound")
|
||||||
oboundP <- &PacketAndToken{p: pr, t: nil}
|
sendAck(&PacketAndToken{p: pr, t: nil})
|
||||||
DEBUG.Println(NET, "done putting pubrec msg on obound")
|
DEBUG.Println(NET, "done putting pubrec msg on obound")
|
||||||
case 1:
|
case 1:
|
||||||
pa := packets.NewControlPacket(packets.Puback).(*packets.PubackPacket)
|
pa := packets.NewControlPacket(packets.Puback).(*packets.PubackPacket)
|
||||||
pa.MessageID = packet.MessageID
|
pa.MessageID = packet.MessageID
|
||||||
DEBUG.Println(NET, "putting puback msg on obound")
|
DEBUG.Println(NET, "putting puback msg on obound")
|
||||||
persistOutbound(persist, pa)
|
persistOutbound(persist, pa) // May fail if store has been closed
|
||||||
oboundP <- &PacketAndToken{p: pa, t: nil}
|
sendAck(&PacketAndToken{p: pa, t: nil})
|
||||||
DEBUG.Println(NET, "done putting puback msg on obound")
|
DEBUG.Println(NET, "done putting puback msg on obound")
|
||||||
case 0:
|
case 0:
|
||||||
// do nothing, since there is no need to send an ack packet back
|
// do nothing, since there is no need to send an ack packet back
|
||||||
|
|||||||
54
vendor/github.com/eclipse/paho.mqtt.golang/netconn.go
generated
vendored
54
vendor/github.com/eclipse/paho.mqtt.golang/netconn.go
generated
vendored
@@ -1,15 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
* Allan Stockdill-Mander
|
* Allan Stockdill-Mander
|
||||||
* Mike Robertson
|
* Mike Robertson
|
||||||
|
* MAtt Brittan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mqtt
|
package mqtt
|
||||||
@@ -30,33 +35,39 @@ import (
|
|||||||
// This just establishes the network connection; once established the type of connection should be irrelevant
|
// This just establishes the network connection; once established the type of connection should be irrelevant
|
||||||
//
|
//
|
||||||
|
|
||||||
// openConnection opens a network connection using the protocol indicated in the URL. Does not carry out any MQTT specific handshakes
|
// openConnection opens a network connection using the protocol indicated in the URL.
|
||||||
func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, headers http.Header, websocketOptions *WebsocketOptions) (net.Conn, error) {
|
// Does not carry out any MQTT specific handshakes.
|
||||||
|
func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, headers http.Header, websocketOptions *WebsocketOptions, dialer *net.Dialer) (net.Conn, error) {
|
||||||
switch uri.Scheme {
|
switch uri.Scheme {
|
||||||
case "ws":
|
case "ws":
|
||||||
conn, err := NewWebsocket(uri.String(), nil, timeout, headers, websocketOptions)
|
dialURI := *uri // #623 - Gorilla Websockets does not accept URL's where uri.User != nil
|
||||||
|
dialURI.User = nil
|
||||||
|
conn, err := NewWebsocket(dialURI.String(), nil, timeout, headers, websocketOptions)
|
||||||
return conn, err
|
return conn, err
|
||||||
case "wss":
|
case "wss":
|
||||||
conn, err := NewWebsocket(uri.String(), tlsc, timeout, headers, websocketOptions)
|
dialURI := *uri // #623 - Gorilla Websockets does not accept URL's where uri.User != nil
|
||||||
|
dialURI.User = nil
|
||||||
|
conn, err := NewWebsocket(dialURI.String(), tlsc, timeout, headers, websocketOptions)
|
||||||
return conn, err
|
return conn, err
|
||||||
case "mqtt", "tcp":
|
case "mqtt", "tcp":
|
||||||
allProxy := os.Getenv("all_proxy")
|
proxyDialer := proxy.FromEnvironmentUsing(dialer)
|
||||||
if len(allProxy) == 0 {
|
|
||||||
conn, err := net.DialTimeout("tcp", uri.Host, timeout)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return conn, nil
|
|
||||||
}
|
|
||||||
proxyDialer := proxy.FromEnvironment()
|
|
||||||
|
|
||||||
conn, err := proxyDialer.Dial("tcp", uri.Host)
|
conn, err := proxyDialer.Dial("tcp", uri.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return conn, nil
|
return conn, nil
|
||||||
case "unix":
|
case "unix":
|
||||||
conn, err := net.DialTimeout("unix", uri.Host, timeout)
|
var conn net.Conn
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// this check is preserved for compatibility with older versions
|
||||||
|
// which used uri.Host only (it works for local paths, e.g. unix://socket.sock in current dir)
|
||||||
|
if len(uri.Host) > 0 {
|
||||||
|
conn, err = dialer.Dial("unix", uri.Host)
|
||||||
|
} else {
|
||||||
|
conn, err = dialer.Dial("unix", uri.Path)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -64,14 +75,13 @@ func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, heade
|
|||||||
case "ssl", "tls", "mqtts", "mqtt+ssl", "tcps":
|
case "ssl", "tls", "mqtts", "mqtt+ssl", "tcps":
|
||||||
allProxy := os.Getenv("all_proxy")
|
allProxy := os.Getenv("all_proxy")
|
||||||
if len(allProxy) == 0 {
|
if len(allProxy) == 0 {
|
||||||
conn, err := tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", uri.Host, tlsc)
|
conn, err := tls.DialWithDialer(dialer, "tcp", uri.Host, tlsc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
proxyDialer := proxy.FromEnvironment()
|
proxyDialer := proxy.FromEnvironment()
|
||||||
|
|
||||||
conn, err := proxyDialer.Dial("tcp", uri.Host)
|
conn, err := proxyDialer.Dial("tcp", uri.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -81,7 +91,7 @@ func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, heade
|
|||||||
|
|
||||||
err = tlsConn.Handshake()
|
err = tlsConn.Handshake()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Close()
|
_ = conn.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
108
vendor/github.com/eclipse/paho.mqtt.golang/notice.html
generated
vendored
108
vendor/github.com/eclipse/paho.mqtt.golang/notice.html
generated
vendored
@@ -1,108 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
|
||||||
<title>Eclipse Foundation Software User Agreement</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body lang="EN-US">
|
|
||||||
<h2>Eclipse Foundation Software User Agreement</h2>
|
|
||||||
<p>February 1, 2011</p>
|
|
||||||
|
|
||||||
<h3>Usage Of Content</h3>
|
|
||||||
|
|
||||||
<p>THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS
|
|
||||||
(COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND
|
|
||||||
CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE
|
|
||||||
OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR
|
|
||||||
NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND
|
|
||||||
CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.</p>
|
|
||||||
|
|
||||||
<h3>Applicable Licenses</h3>
|
|
||||||
|
|
||||||
<p>Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0
|
|
||||||
("EPL"). A copy of the EPL is provided with this Content and is also available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
|
|
||||||
For purposes of the EPL, "Program" will mean the Content.</p>
|
|
||||||
|
|
||||||
<p>Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code
|
|
||||||
repository ("Repository") in software modules ("Modules") and made available as downloadable archives ("Downloads").</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"), plug-in fragments ("Fragments"), and features ("Features").</li>
|
|
||||||
<li>Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".</li>
|
|
||||||
<li>A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named "features". Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of the Plug-ins
|
|
||||||
and/or Fragments associated with that Feature.</li>
|
|
||||||
<li>Features may also include other Features ("Included Features"). Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of Included Features.</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>The terms and conditions governing Plug-ins and Fragments should be contained in files named "about.html" ("Abouts"). The terms and conditions governing Features and
|
|
||||||
Included Features should be contained in files named "license.html" ("Feature Licenses"). Abouts and Feature Licenses may be located in any directory of a Download or Module
|
|
||||||
including, but not limited to the following locations:</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>The top-level (root) directory</li>
|
|
||||||
<li>Plug-in and Fragment directories</li>
|
|
||||||
<li>Inside Plug-ins and Fragments packaged as JARs</li>
|
|
||||||
<li>Sub-directories of the directory named "src" of certain Plug-ins</li>
|
|
||||||
<li>Feature directories</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license ("Feature Update License") during the
|
|
||||||
installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or
|
|
||||||
inform you where you can locate them. Feature Update Licenses may be found in the "license" property of files named "feature.properties" found within a Feature.
|
|
||||||
Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in
|
|
||||||
that directory.</p>
|
|
||||||
|
|
||||||
<p>THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE
|
|
||||||
OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>Eclipse Distribution License Version 1.0 (available at <a href="http://www.eclipse.org/licenses/edl-v10.html">http://www.eclipse.org/licenses/edl-v1.0.html</a>)</li>
|
|
||||||
<li>Common Public License Version 1.0 (available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>)</li>
|
|
||||||
<li>Apache Software License 1.1 (available at <a href="http://www.apache.org/licenses/LICENSE">http://www.apache.org/licenses/LICENSE</a>)</li>
|
|
||||||
<li>Apache Software License 2.0 (available at <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)</li>
|
|
||||||
<li>Metro Link Public License 1.00 (available at <a href="http://www.opengroup.org/openmotif/supporters/metrolink/license.html">http://www.opengroup.org/openmotif/supporters/metrolink/license.html</a>)</li>
|
|
||||||
<li>Mozilla Public License Version 1.1 (available at <a href="http://www.mozilla.org/MPL/MPL-1.1.html">http://www.mozilla.org/MPL/MPL-1.1.html</a>)</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please
|
|
||||||
contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.</p>
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Use of Provisioning Technology</h3>
|
|
||||||
|
|
||||||
<p>The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse
|
|
||||||
Update Manager ("Provisioning Technology") for the purpose of allowing users to install software, documentation, information and/or
|
|
||||||
other materials (collectively "Installable Software"). This capability is provided with the intent of allowing such users to
|
|
||||||
install, extend and update Eclipse-based products. Information about packaging Installable Software is available at <a
|
|
||||||
href="http://eclipse.org/equinox/p2/repository_packaging.html">http://eclipse.org/equinox/p2/repository_packaging.html</a>
|
|
||||||
("Specification").</p>
|
|
||||||
|
|
||||||
<p>You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the
|
|
||||||
applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology
|
|
||||||
in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the
|
|
||||||
Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:</p>
|
|
||||||
|
|
||||||
<ol>
|
|
||||||
<li>A series of actions may occur ("Provisioning Process") in which a user may execute the Provisioning Technology
|
|
||||||
on a machine ("Target Machine") with the intent of installing, extending or updating the functionality of an Eclipse-based
|
|
||||||
product.</li>
|
|
||||||
<li>During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be
|
|
||||||
accessed and copied to the Target Machine.</li>
|
|
||||||
<li>Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable
|
|
||||||
Software ("Installable Software Agreement") and such Installable Software Agreement shall be accessed from the Target
|
|
||||||
Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern
|
|
||||||
the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such
|
|
||||||
indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<h3>Cryptography</h3>
|
|
||||||
|
|
||||||
<p>Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to
|
|
||||||
another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import,
|
|
||||||
possession, or use, and re-export of encryption software, to see if this is permitted.</p>
|
|
||||||
|
|
||||||
<p><small>Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.</small></p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
12
vendor/github.com/eclipse/paho.mqtt.golang/oops.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/oops.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
|
|||||||
92
vendor/github.com/eclipse/paho.mqtt.golang/options.go
generated
vendored
92
vendor/github.com/eclipse/paho.mqtt.golang/options.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
@@ -19,6 +23,7 @@ package mqtt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -49,8 +54,22 @@ type OnConnectHandler func(Client)
|
|||||||
// the initial connection is lost
|
// the initial connection is lost
|
||||||
type ReconnectHandler func(Client, *ClientOptions)
|
type ReconnectHandler func(Client, *ClientOptions)
|
||||||
|
|
||||||
|
// ConnectionAttemptHandler is invoked prior to making the initial connection.
|
||||||
|
type ConnectionAttemptHandler func(broker *url.URL, tlsCfg *tls.Config) *tls.Config
|
||||||
|
|
||||||
|
// OpenConnectionFunc is invoked to establish the underlying network connection
|
||||||
|
// Its purpose if for custom network transports.
|
||||||
|
// Does not carry out any MQTT specific handshakes.
|
||||||
|
type OpenConnectionFunc func(uri *url.URL, options ClientOptions) (net.Conn, error)
|
||||||
|
|
||||||
|
// ConnectionNotificationHandler is invoked for any type of connection event.
|
||||||
|
type ConnectionNotificationHandler func(Client, ConnectionNotification)
|
||||||
|
|
||||||
// ClientOptions contains configurable options for an Client. Note that these should be set using the
|
// ClientOptions contains configurable options for an Client. Note that these should be set using the
|
||||||
// relevant methods (e.g. AddBroker) rather than directly. See those functions for information on usage.
|
// relevant methods (e.g. AddBroker) rather than directly. See those functions for information on usage.
|
||||||
|
// WARNING: Create the below using NewClientOptions unless you have a compelling reason not to. It is easy
|
||||||
|
// to create a configuration with difficult to trace issues (e.g. Mosquitto 2.0.12+ will reject connections
|
||||||
|
// with KeepAlive=0 by default).
|
||||||
type ClientOptions struct {
|
type ClientOptions struct {
|
||||||
Servers []*url.URL
|
Servers []*url.URL
|
||||||
ClientID string
|
ClientID string
|
||||||
@@ -67,7 +86,7 @@ type ClientOptions struct {
|
|||||||
ProtocolVersion uint
|
ProtocolVersion uint
|
||||||
protocolVersionExplicit bool
|
protocolVersionExplicit bool
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
KeepAlive int64
|
KeepAlive int64 // Warning: Some brokers may reject connections with Keepalive = 0.
|
||||||
PingTimeout time.Duration
|
PingTimeout time.Duration
|
||||||
ConnectTimeout time.Duration
|
ConnectTimeout time.Duration
|
||||||
MaxReconnectInterval time.Duration
|
MaxReconnectInterval time.Duration
|
||||||
@@ -79,15 +98,22 @@ type ClientOptions struct {
|
|||||||
OnConnect OnConnectHandler
|
OnConnect OnConnectHandler
|
||||||
OnConnectionLost ConnectionLostHandler
|
OnConnectionLost ConnectionLostHandler
|
||||||
OnReconnecting ReconnectHandler
|
OnReconnecting ReconnectHandler
|
||||||
|
OnConnectAttempt ConnectionAttemptHandler
|
||||||
|
OnConnectionNotification ConnectionNotificationHandler
|
||||||
WriteTimeout time.Duration
|
WriteTimeout time.Duration
|
||||||
MessageChannelDepth uint
|
MessageChannelDepth uint
|
||||||
ResumeSubs bool
|
ResumeSubs bool
|
||||||
HTTPHeaders http.Header
|
HTTPHeaders http.Header
|
||||||
WebsocketOptions *WebsocketOptions
|
WebsocketOptions *WebsocketOptions
|
||||||
|
MaxResumePubInFlight int // // 0 = no limit; otherwise this is the maximum simultaneous messages sent while resuming
|
||||||
|
Dialer *net.Dialer
|
||||||
|
CustomOpenConnectionFn OpenConnectionFunc
|
||||||
|
AutoAckDisabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClientOptions will create a new ClientClientOptions type with some
|
// NewClientOptions will create a new ClientClientOptions type with some
|
||||||
// default values.
|
// default values.
|
||||||
|
//
|
||||||
// Port: 1883
|
// Port: 1883
|
||||||
// CleanSession: True
|
// CleanSession: True
|
||||||
// Order: True (note: it is recommended that this be set to FALSE unless order is important)
|
// Order: True (note: it is recommended that this be set to FALSE unless order is important)
|
||||||
@@ -120,10 +146,15 @@ func NewClientOptions() *ClientOptions {
|
|||||||
Store: nil,
|
Store: nil,
|
||||||
OnConnect: nil,
|
OnConnect: nil,
|
||||||
OnConnectionLost: DefaultConnectionLostHandler,
|
OnConnectionLost: DefaultConnectionLostHandler,
|
||||||
|
OnConnectAttempt: nil,
|
||||||
|
OnConnectionNotification: nil,
|
||||||
WriteTimeout: 0, // 0 represents timeout disabled
|
WriteTimeout: 0, // 0 represents timeout disabled
|
||||||
ResumeSubs: false,
|
ResumeSubs: false,
|
||||||
HTTPHeaders: make(map[string][]string),
|
HTTPHeaders: make(map[string][]string),
|
||||||
WebsocketOptions: &WebsocketOptions{},
|
WebsocketOptions: &WebsocketOptions{},
|
||||||
|
Dialer: &net.Dialer{Timeout: 30 * time.Second},
|
||||||
|
CustomOpenConnectionFn: nil,
|
||||||
|
AutoAckDisabled: false,
|
||||||
}
|
}
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
@@ -321,6 +352,22 @@ func (o *ClientOptions) SetReconnectingHandler(cb ReconnectHandler) *ClientOptio
|
|||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetConnectionAttemptHandler sets the ConnectionAttemptHandler callback to be executed prior
|
||||||
|
// to each attempt to connect to an MQTT broker. Returns the *tls.Config that will be used when establishing
|
||||||
|
// the connection (a copy of the tls.Config from ClientOptions will be passed in along with the broker URL).
|
||||||
|
// This allows connection specific changes to be made to the *tls.Config.
|
||||||
|
func (o *ClientOptions) SetConnectionAttemptHandler(onConnectAttempt ConnectionAttemptHandler) *ClientOptions {
|
||||||
|
o.OnConnectAttempt = onConnectAttempt
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConnectionNotificationHandler sets the ConnectionNotificationHandler callback to receive all types of connection
|
||||||
|
// events.
|
||||||
|
func (o *ClientOptions) SetConnectionNotificationHandler(onConnectionNotification ConnectionNotificationHandler) *ClientOptions {
|
||||||
|
o.OnConnectionNotification = onConnectionNotification
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
// SetWriteTimeout puts a limit on how long a mqtt publish should block until it unblocks with a
|
// SetWriteTimeout puts a limit on how long a mqtt publish should block until it unblocks with a
|
||||||
// timeout error. A duration of 0 never times out. Default never times out
|
// timeout error. A duration of 0 never times out. Default never times out
|
||||||
func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions {
|
func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions {
|
||||||
@@ -333,6 +380,7 @@ func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions {
|
|||||||
// Default 30 seconds. Currently only operational on TCP/TLS connections.
|
// Default 30 seconds. Currently only operational on TCP/TLS connections.
|
||||||
func (o *ClientOptions) SetConnectTimeout(t time.Duration) *ClientOptions {
|
func (o *ClientOptions) SetConnectTimeout(t time.Duration) *ClientOptions {
|
||||||
o.ConnectTimeout = t
|
o.ConnectTimeout = t
|
||||||
|
o.Dialer.Timeout = t
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,3 +435,37 @@ func (o *ClientOptions) SetWebsocketOptions(w *WebsocketOptions) *ClientOptions
|
|||||||
o.WebsocketOptions = w
|
o.WebsocketOptions = w
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMaxResumePubInFlight sets the maximum simultaneous publish messages that will be sent while resuming. Note that
|
||||||
|
// this only applies to messages coming from the store (so additional sends may push us over the limit)
|
||||||
|
// Note that the connect token will not be flagged as complete until all messages have been sent from the
|
||||||
|
// store. If broker does not respond to messages then resume may not complete.
|
||||||
|
// This option was put in place because resuming after downtime can saturate low capacity links.
|
||||||
|
func (o *ClientOptions) SetMaxResumePubInFlight(MaxResumePubInFlight int) *ClientOptions {
|
||||||
|
o.MaxResumePubInFlight = MaxResumePubInFlight
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDialer sets the tcp dialer options used in a tcp connection
|
||||||
|
func (o *ClientOptions) SetDialer(dialer *net.Dialer) *ClientOptions {
|
||||||
|
o.Dialer = dialer
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCustomOpenConnectionFn replaces the inbuilt function that establishes a network connection with a custom function.
|
||||||
|
// The passed in function should return an open `net.Conn` or an error (see the existing openConnection function for an example)
|
||||||
|
// It enables custom networking types in addition to the defaults (tcp, tls, websockets...)
|
||||||
|
func (o *ClientOptions) SetCustomOpenConnectionFn(customOpenConnectionFn OpenConnectionFunc) *ClientOptions {
|
||||||
|
if customOpenConnectionFn != nil {
|
||||||
|
o.CustomOpenConnectionFn = customOpenConnectionFn
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAutoAckDisabled enables or disables the Automated Acking of Messages received by the handler.
|
||||||
|
//
|
||||||
|
// By default it is set to false. Setting it to true will disable the auto-ack globally.
|
||||||
|
func (o *ClientOptions) SetAutoAckDisabled(autoAckDisabled bool) *ClientOptions {
|
||||||
|
o.AutoAckDisabled = autoAckDisabled
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|||||||
27
vendor/github.com/eclipse/paho.mqtt.golang/options_reader.go
generated
vendored
27
vendor/github.com/eclipse/paho.mqtt.golang/options_reader.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
@@ -26,6 +30,21 @@ type ClientOptionsReader struct {
|
|||||||
options *ClientOptions
|
options *ClientOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewOptionsReader creates a ClientOptionsReader, this should only be used for mocking purposes.
|
||||||
|
//
|
||||||
|
// An example implementation:
|
||||||
|
//
|
||||||
|
// func (c *mqttClientMock) OptionsReader() mqtt.ClientOptionsReader {
|
||||||
|
// opts := mqtt.NewClientOptions()
|
||||||
|
// opts.UserName = "TestUserName"
|
||||||
|
// return mqtt.NewOptionsReader(opts)
|
||||||
|
// }
|
||||||
|
func NewOptionsReader(o *ClientOptions) ClientOptionsReader {
|
||||||
|
return ClientOptionsReader{
|
||||||
|
options: o,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Servers returns a slice of the servers defined in the clientoptions
|
// Servers returns a slice of the servers defined in the clientoptions
|
||||||
func (r *ClientOptionsReader) Servers() []*url.URL {
|
func (r *ClientOptionsReader) Servers() []*url.URL {
|
||||||
s := make([]*url.URL, len(r.options.Servers))
|
s := make([]*url.URL, len(r.options.Servers))
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/connack.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/connack.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
22
vendor/github.com/eclipse/paho.mqtt.golang/packets/connect.go
generated
vendored
22
vendor/github.com/eclipse/paho.mqtt.golang/packets/connect.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -29,7 +45,11 @@ type ConnectPacket struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnectPacket) String() string {
|
func (c *ConnectPacket) String() string {
|
||||||
return fmt.Sprintf("%s protocolversion: %d protocolname: %s cleansession: %t willflag: %t WillQos: %d WillRetain: %t Usernameflag: %t Passwordflag: %t keepalive: %d clientId: %s willtopic: %s willmessage: %s Username: %s Password: %s", c.FixedHeader, c.ProtocolVersion, c.ProtocolName, c.CleanSession, c.WillFlag, c.WillQos, c.WillRetain, c.UsernameFlag, c.PasswordFlag, c.Keepalive, c.ClientIdentifier, c.WillTopic, c.WillMessage, c.Username, c.Password)
|
var password string
|
||||||
|
if len(c.Password) > 0 {
|
||||||
|
password = "<redacted>"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s protocolversion: %d protocolname: %s cleansession: %t willflag: %t WillQos: %d WillRetain: %t Usernameflag: %t Passwordflag: %t keepalive: %d clientId: %s willtopic: %s willmessage: %s Username: %s Password: %s", c.FixedHeader, c.ProtocolVersion, c.ProtocolName, c.CleanSession, c.WillFlag, c.WillQos, c.WillRetain, c.UsernameFlag, c.PasswordFlag, c.Keepalive, c.ClientIdentifier, c.WillTopic, c.WillMessage, c.Username, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnectPacket) Write(w io.Writer) error {
|
func (c *ConnectPacket) Write(w io.Writer) error {
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/disconnect.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/disconnect.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
21
vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go
generated
vendored
21
vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -314,6 +330,11 @@ func decodeBytes(b io.Reader) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func encodeBytes(field []byte) []byte {
|
func encodeBytes(field []byte) []byte {
|
||||||
|
// Attempting to encode more than 65,535 bytes would lead to an unexpected 16-bit length and extra data written
|
||||||
|
// (which would be parsed as later parts of the message). The safest option is to truncate.
|
||||||
|
if len(field) > 65535 {
|
||||||
|
field = field[0:65535]
|
||||||
|
}
|
||||||
fieldLength := make([]byte, 2)
|
fieldLength := make([]byte, 2)
|
||||||
binary.BigEndian.PutUint16(fieldLength, uint16(len(field)))
|
binary.BigEndian.PutUint16(fieldLength, uint16(len(field)))
|
||||||
return append(fieldLength, field...)
|
return append(fieldLength, field...)
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingreq.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingreq.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingresp.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingresp.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/puback.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/puback.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubcomp.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubcomp.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/publish.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/publish.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrec.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrec.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrel.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrel.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/suback.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/suback.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/subscribe.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/subscribe.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsuback.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsuback.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsubscribe.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsubscribe.go
generated
vendored
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
*/
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
24
vendor/github.com/eclipse/paho.mqtt.golang/ping.go
generated
vendored
24
vendor/github.com/eclipse/paho.mqtt.golang/ping.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
@@ -28,16 +32,16 @@ import (
|
|||||||
func keepalive(c *client, conn io.Writer) {
|
func keepalive(c *client, conn io.Writer) {
|
||||||
defer c.workers.Done()
|
defer c.workers.Done()
|
||||||
DEBUG.Println(PNG, "keepalive starting")
|
DEBUG.Println(PNG, "keepalive starting")
|
||||||
var checkInterval int64
|
var checkInterval time.Duration
|
||||||
var pingSent time.Time
|
var pingSent time.Time
|
||||||
|
|
||||||
if c.options.KeepAlive > 10 {
|
if c.options.KeepAlive > 10 {
|
||||||
checkInterval = 5
|
checkInterval = 5 * time.Second
|
||||||
} else {
|
} else {
|
||||||
checkInterval = c.options.KeepAlive / 2
|
checkInterval = time.Duration(c.options.KeepAlive) * time.Second / 4
|
||||||
}
|
}
|
||||||
|
|
||||||
intervalTicker := time.NewTicker(time.Duration(checkInterval * int64(time.Second)))
|
intervalTicker := time.NewTicker(checkInterval)
|
||||||
defer intervalTicker.Stop()
|
defer intervalTicker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -54,8 +58,8 @@ func keepalive(c *client, conn io.Writer) {
|
|||||||
if atomic.LoadInt32(&c.pingOutstanding) == 0 {
|
if atomic.LoadInt32(&c.pingOutstanding) == 0 {
|
||||||
DEBUG.Println(PNG, "keepalive sending ping")
|
DEBUG.Println(PNG, "keepalive sending ping")
|
||||||
ping := packets.NewControlPacket(packets.Pingreq).(*packets.PingreqPacket)
|
ping := packets.NewControlPacket(packets.Pingreq).(*packets.PingreqPacket)
|
||||||
// We don't want to wait behind large messages being sent, the Write call
|
// We don't want to wait behind large messages being sent, the `Write` call
|
||||||
// will block until it it able to send the packet.
|
// will block until it is able to send the packet.
|
||||||
atomic.StoreInt32(&c.pingOutstanding, 1)
|
atomic.StoreInt32(&c.pingOutstanding, 1)
|
||||||
if err := ping.Write(conn); err != nil {
|
if err := ping.Write(conn); err != nil {
|
||||||
ERROR.Println(PNG, err)
|
ERROR.Println(PNG, err)
|
||||||
|
|||||||
50
vendor/github.com/eclipse/paho.mqtt.golang/router.go
generated
vendored
50
vendor/github.com/eclipse/paho.mqtt.golang/router.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
@@ -132,14 +136,30 @@ func (r *router) setDefaultHandler(handler MessageHandler) {
|
|||||||
// associated callback (or the defaultHandler, if one exists and no other route matched). If
|
// associated callback (or the defaultHandler, if one exists and no other route matched). If
|
||||||
// anything is sent down the stop channel the function will end.
|
// anything is sent down the stop channel the function will end.
|
||||||
func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order bool, client *client) <-chan *PacketAndToken {
|
func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order bool, client *client) <-chan *PacketAndToken {
|
||||||
ackChan := make(chan *PacketAndToken)
|
ackChan := make(chan *PacketAndToken) // Channel returned to caller; closed when goroutine terminates
|
||||||
go func() {
|
|
||||||
|
// In some cases message acknowledgments may come through after shutdown (connection is down etc). Where this is the
|
||||||
|
// case we need to accept any such requests and then ignore them. Note that this is not a perfect solution, if we
|
||||||
|
// have reconnected, and the session is still live, then the Ack really should be sent (see Issus #726)
|
||||||
|
var ackMutex sync.RWMutex
|
||||||
|
sendAckChan := ackChan // This will be set to nil before ackChan is closed
|
||||||
|
sendAck := func(ack *PacketAndToken) {
|
||||||
|
ackMutex.RLock()
|
||||||
|
defer ackMutex.RUnlock()
|
||||||
|
if sendAckChan != nil {
|
||||||
|
sendAckChan <- ack
|
||||||
|
} else {
|
||||||
|
DEBUG.Println(ROU, "matchAndDispatch received acknowledgment after processing stopped (ACK dropped).")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() { // Main go routine handling inbound messages
|
||||||
|
var handlers []MessageHandler
|
||||||
for message := range messages {
|
for message := range messages {
|
||||||
// DEBUG.Println(ROU, "matchAndDispatch received message")
|
// DEBUG.Println(ROU, "matchAndDispatch received message")
|
||||||
sent := false
|
sent := false
|
||||||
r.RLock()
|
r.RLock()
|
||||||
m := messageFromPublish(message, ackFunc(ackChan, client.persist, message))
|
m := messageFromPublish(message, ackFunc(sendAck, client.persist, message))
|
||||||
var handlers []MessageHandler
|
|
||||||
for e := r.routes.Front(); e != nil; e = e.Next() {
|
for e := r.routes.Front(); e != nil; e = e.Next() {
|
||||||
if e.Value.(*route).match(message.TopicName) {
|
if e.Value.(*route).match(message.TopicName) {
|
||||||
if order {
|
if order {
|
||||||
@@ -148,7 +168,9 @@ func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order
|
|||||||
hd := e.Value.(*route).callback
|
hd := e.Value.(*route).callback
|
||||||
go func() {
|
go func() {
|
||||||
hd(client, m)
|
hd(client, m)
|
||||||
|
if !client.options.AutoAckDisabled {
|
||||||
m.Ack()
|
m.Ack()
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
sent = true
|
sent = true
|
||||||
@@ -161,7 +183,9 @@ func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order
|
|||||||
} else {
|
} else {
|
||||||
go func() {
|
go func() {
|
||||||
r.defaultHandler(client, m)
|
r.defaultHandler(client, m)
|
||||||
|
if !client.options.AutoAckDisabled {
|
||||||
m.Ack()
|
m.Ack()
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -169,13 +193,21 @@ func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.RUnlock()
|
r.RUnlock()
|
||||||
|
if order {
|
||||||
for _, handler := range handlers {
|
for _, handler := range handlers {
|
||||||
handler(client, m)
|
handler(client, m)
|
||||||
|
if !client.options.AutoAckDisabled {
|
||||||
m.Ack()
|
m.Ack()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
handlers = handlers[:0]
|
||||||
|
}
|
||||||
// DEBUG.Println(ROU, "matchAndDispatch handled message")
|
// DEBUG.Println(ROU, "matchAndDispatch handled message")
|
||||||
}
|
}
|
||||||
close(ackChan)
|
ackMutex.Lock()
|
||||||
|
sendAckChan = nil
|
||||||
|
ackMutex.Unlock()
|
||||||
|
close(ackChan) // as sendAckChan is now nil nothing further will be sent on this
|
||||||
DEBUG.Println(ROU, "matchAndDispatch exiting")
|
DEBUG.Println(ROU, "matchAndDispatch exiting")
|
||||||
}()
|
}()
|
||||||
return ackChan
|
return ackChan
|
||||||
|
|||||||
296
vendor/github.com/eclipse/paho.mqtt.golang/status.go
generated
vendored
Normal file
296
vendor/github.com/eclipse/paho.mqtt.golang/status.go
generated
vendored
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
* Matt Brittan
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Status - Manage the connection status
|
||||||
|
|
||||||
|
// Multiple go routines will want to access/set this. Previously status was implemented as a `uint32` and updated
|
||||||
|
// with a mixture of atomic functions and a mutex (leading to some deadlock type issues that were very hard to debug).
|
||||||
|
|
||||||
|
// In this new implementation `connectionStatus` takes over managing the state and provides functions that allow the
|
||||||
|
// client to request a move to a particular state (it may reject these requests!). In some cases the 'state' is
|
||||||
|
// transitory, for example `connecting`, in those cases a function will be returned that allows the client to move
|
||||||
|
// to a more static state (`disconnected` or `connected`).
|
||||||
|
|
||||||
|
// This "belts-and-braces" may be a little over the top but issues with the status have caused a number of difficult
|
||||||
|
// to trace bugs in the past and the likelihood that introducing a new system would introduce bugs seemed high!
|
||||||
|
// I have written this in a way that should make it very difficult to misuse it (but it does make things a little
|
||||||
|
// complex with functions returning functions that return functions!).
|
||||||
|
|
||||||
|
type status uint32
|
||||||
|
|
||||||
|
const (
|
||||||
|
disconnected status = iota // default (nil) status is disconnected
|
||||||
|
disconnecting // Transitioning from one of the below states back to disconnected
|
||||||
|
connecting
|
||||||
|
reconnecting
|
||||||
|
connected
|
||||||
|
)
|
||||||
|
|
||||||
|
// String simplify output of statuses
|
||||||
|
func (s status) String() string {
|
||||||
|
switch s {
|
||||||
|
case disconnected:
|
||||||
|
return "disconnected"
|
||||||
|
case disconnecting:
|
||||||
|
return "disconnecting"
|
||||||
|
case connecting:
|
||||||
|
return "connecting"
|
||||||
|
case reconnecting:
|
||||||
|
return "reconnecting"
|
||||||
|
case connected:
|
||||||
|
return "connected"
|
||||||
|
default:
|
||||||
|
return "invalid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type connCompletedFn func(success bool) error
|
||||||
|
type disconnectCompletedFn func()
|
||||||
|
type connectionLostHandledFn func(bool) (connCompletedFn, error)
|
||||||
|
|
||||||
|
/* State transitions
|
||||||
|
|
||||||
|
static states are `disconnected` and `connected`. For all other states a process will hold a function that will move
|
||||||
|
the state to one of those. That function effectively owns the state and any other changes must not proceed until it
|
||||||
|
completes. One exception to that is that the state can always be moved to `disconnecting` which provides a signal that
|
||||||
|
transitions to `connected` will be rejected (this is required because a Disconnect can be requested while in the
|
||||||
|
Connecting state).
|
||||||
|
|
||||||
|
# Basic Operations
|
||||||
|
|
||||||
|
The standard workflows are:
|
||||||
|
|
||||||
|
disconnected -> `Connecting()` -> connecting -> `connCompletedFn(true)` -> connected
|
||||||
|
connected -> `Disconnecting()` -> disconnecting -> `disconnectCompletedFn()` -> disconnected
|
||||||
|
connected -> `ConnectionLost(false)` -> disconnecting -> `connectionLostHandledFn(true/false)` -> disconnected
|
||||||
|
connected -> `ConnectionLost(true)` -> disconnecting -> `connectionLostHandledFn(true)` -> connected
|
||||||
|
|
||||||
|
Unfortunately the above workflows are complicated by the fact that `Disconnecting()` or `ConnectionLost()` may,
|
||||||
|
potentially, be called at any time (i.e. whilst in the middle of transitioning between states). If this happens:
|
||||||
|
|
||||||
|
* The state will be set to disconnecting (which will prevent any request to move the status to connected)
|
||||||
|
* The call to `Disconnecting()`/`ConnectionLost()` will block until the previously active call completes and then
|
||||||
|
handle the disconnection.
|
||||||
|
|
||||||
|
Reading the tests (unit_status_test.go) might help understand these rules.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var (
|
||||||
|
errAbortConnection = errors.New("disconnect called whist connection attempt in progress")
|
||||||
|
errAlreadyConnectedOrReconnecting = errors.New("status is already connected or reconnecting")
|
||||||
|
errStatusMustBeDisconnected = errors.New("status can only transition to connecting from disconnected")
|
||||||
|
errAlreadyDisconnected = errors.New("status is already disconnected")
|
||||||
|
errDisconnectionRequested = errors.New("disconnection was requested whilst the action was in progress")
|
||||||
|
errDisconnectionInProgress = errors.New("disconnection already in progress")
|
||||||
|
errAlreadyHandlingConnectionLoss = errors.New("status is already Connection Lost")
|
||||||
|
errConnLossWhileDisconnecting = errors.New("connection status is disconnecting so loss of connection is expected")
|
||||||
|
)
|
||||||
|
|
||||||
|
// connectionStatus encapsulates, and protects, the connection status.
|
||||||
|
type connectionStatus struct {
|
||||||
|
sync.RWMutex // Protects the variables below
|
||||||
|
status status
|
||||||
|
willReconnect bool // only used when status == disconnecting. Indicates that an attempt will be made to reconnect (allows us to abort that)
|
||||||
|
|
||||||
|
// Some statuses are transitional (e.g. connecting, connectionLost, reconnecting, disconnecting), that is, whatever
|
||||||
|
// process moves us into that status will move us out of it when an action is complete. Sometimes other users
|
||||||
|
// will need to know when the action is complete (e.g. the user calls `Disconnect()` whilst the status is
|
||||||
|
// `connecting`). `actionCompleted` will be set whenever we move into one of the above statues and the channel
|
||||||
|
// returned to anything else requesting a status change. The channel will be closed when the operation is complete.
|
||||||
|
actionCompleted chan struct{} // Only valid whilst status is Connecting or Reconnecting; will be closed when connection completed (success or failure)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConnectionStatus returns the connection status.
|
||||||
|
// WARNING: the status may change at any time so users should not assume they are the only goroutine touching this
|
||||||
|
func (c *connectionStatus) ConnectionStatus() status {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
return c.status
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConnectionStatusRetry returns the connection status and retry flag (indicates that we expect to reconnect).
|
||||||
|
// WARNING: the status may change at any time so users should not assume they are the only goroutine touching this
|
||||||
|
func (c *connectionStatus) ConnectionStatusRetry() (status, bool) {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
return c.status, c.willReconnect
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connecting - Changes the status to connecting if that is a permitted operation
|
||||||
|
// Will do nothing unless the current status is disconnected
|
||||||
|
// Returns a function that MUST be called when the operation is complete (pass in true if successful)
|
||||||
|
func (c *connectionStatus) Connecting() (connCompletedFn, error) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
// Calling Connect when already connecting (or if reconnecting) may not always be considered an error
|
||||||
|
if c.status == connected || c.status == reconnecting {
|
||||||
|
return nil, errAlreadyConnectedOrReconnecting
|
||||||
|
}
|
||||||
|
if c.status != disconnected {
|
||||||
|
return nil, errStatusMustBeDisconnected
|
||||||
|
}
|
||||||
|
c.status = connecting
|
||||||
|
c.actionCompleted = make(chan struct{})
|
||||||
|
return c.connected, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// connected is an internal function (it is returned by functions that set the status to connecting or reconnecting,
|
||||||
|
// calling it completes the operation). `success` is used to indicate whether the operation was successfully completed.
|
||||||
|
func (c *connectionStatus) connected(success bool) error {
|
||||||
|
c.Lock()
|
||||||
|
defer func() {
|
||||||
|
close(c.actionCompleted) // Alert anything waiting on the connection process to complete
|
||||||
|
c.actionCompleted = nil // Be tidy
|
||||||
|
c.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Status may have moved to disconnecting in the interim (i.e. at users request)
|
||||||
|
if c.status == disconnecting {
|
||||||
|
return errAbortConnection
|
||||||
|
}
|
||||||
|
if success {
|
||||||
|
c.status = connected
|
||||||
|
} else {
|
||||||
|
c.status = disconnected
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disconnecting - should be called when beginning the disconnection process (cleanup etc.).
|
||||||
|
// Can be called from ANY status and the end result will always be a status of disconnected
|
||||||
|
// Note that if a connection/reconnection attempt is in progress this function will set the status to `disconnecting`
|
||||||
|
// then block until the connection process completes (or aborts).
|
||||||
|
// Returns a function that MUST be called when the operation is complete (assumed to always be successful!)
|
||||||
|
func (c *connectionStatus) Disconnecting() (disconnectCompletedFn, error) {
|
||||||
|
c.Lock()
|
||||||
|
if c.status == disconnected {
|
||||||
|
c.Unlock()
|
||||||
|
return nil, errAlreadyDisconnected // May not always be treated as an error
|
||||||
|
}
|
||||||
|
if c.status == disconnecting { // Need to wait for existing process to complete
|
||||||
|
c.willReconnect = false // Ensure that the existing disconnect process will not reconnect
|
||||||
|
disConnectDone := c.actionCompleted
|
||||||
|
c.Unlock()
|
||||||
|
<-disConnectDone // Wait for existing operation to complete
|
||||||
|
return nil, errAlreadyDisconnected // Well we are now!
|
||||||
|
}
|
||||||
|
|
||||||
|
prevStatus := c.status
|
||||||
|
c.status = disconnecting
|
||||||
|
|
||||||
|
// We may need to wait for connection/reconnection process to complete (they should regularly check the status)
|
||||||
|
if prevStatus == connecting || prevStatus == reconnecting {
|
||||||
|
connectDone := c.actionCompleted
|
||||||
|
c.Unlock() // Safe because the only way to leave the disconnecting status is via this function
|
||||||
|
<-connectDone
|
||||||
|
|
||||||
|
if prevStatus == reconnecting && !c.willReconnect {
|
||||||
|
return nil, errAlreadyDisconnected // Following connectionLost process we will be disconnected
|
||||||
|
}
|
||||||
|
c.Lock()
|
||||||
|
}
|
||||||
|
c.actionCompleted = make(chan struct{})
|
||||||
|
c.Unlock()
|
||||||
|
return c.disconnectionCompleted, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// disconnectionCompleted is an internal function (it is returned by functions that set the status to disconnecting)
|
||||||
|
func (c *connectionStatus) disconnectionCompleted() {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
c.status = disconnected
|
||||||
|
close(c.actionCompleted) // Alert anything waiting on the connection process to complete
|
||||||
|
c.actionCompleted = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConnectionLost - should be called when the connection is lost.
|
||||||
|
// This really only differs from Disconnecting in that we may transition into a reconnection (but that could be
|
||||||
|
// cancelled something else calls Disconnecting in the meantime).
|
||||||
|
// The returned function should be called when cleanup is completed. It will return a function to be called when
|
||||||
|
// reconnect completes (or nil if no reconnect requested/disconnect called in the interim).
|
||||||
|
// Note: This function may block if a connection is in progress (the move to connected will be rejected)
|
||||||
|
func (c *connectionStatus) ConnectionLost(willReconnect bool) (connectionLostHandledFn, error) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
if c.status == disconnected {
|
||||||
|
return nil, errAlreadyDisconnected
|
||||||
|
}
|
||||||
|
if c.status == disconnecting { // its expected that connection lost will be called during the disconnection process
|
||||||
|
return nil, errDisconnectionInProgress
|
||||||
|
}
|
||||||
|
|
||||||
|
c.willReconnect = willReconnect
|
||||||
|
prevStatus := c.status
|
||||||
|
c.status = disconnecting
|
||||||
|
|
||||||
|
// There is a slight possibility that a connection attempt is in progress (connection up and goroutines started but
|
||||||
|
// status not yet changed). By changing the status we ensure that process will exit cleanly
|
||||||
|
if prevStatus == connecting || prevStatus == reconnecting {
|
||||||
|
connectDone := c.actionCompleted
|
||||||
|
c.Unlock() // Safe because the only way to leave the disconnecting status is via this function
|
||||||
|
<-connectDone
|
||||||
|
c.Lock()
|
||||||
|
if !willReconnect {
|
||||||
|
// In this case the connection will always be aborted so there is nothing more for us to do
|
||||||
|
return nil, errAlreadyDisconnected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.actionCompleted = make(chan struct{})
|
||||||
|
|
||||||
|
return c.getConnectionLostHandler(willReconnect), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getConnectionLostHandler is an internal function. It returns the function to be returned by ConnectionLost
|
||||||
|
func (c *connectionStatus) getConnectionLostHandler(reconnectRequested bool) connectionLostHandledFn {
|
||||||
|
return func(proceed bool) (connCompletedFn, error) {
|
||||||
|
// Note that connCompletedFn will only be provided if both reconnectRequested and proceed are true
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
|
// `Disconnecting()` may have been called while the disconnection was being processed (this makes it permanent!)
|
||||||
|
if !c.willReconnect || !proceed {
|
||||||
|
c.status = disconnected
|
||||||
|
close(c.actionCompleted) // Alert anything waiting on the connection process to complete
|
||||||
|
c.actionCompleted = nil
|
||||||
|
if !reconnectRequested || !proceed {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, errDisconnectionRequested
|
||||||
|
}
|
||||||
|
|
||||||
|
c.status = reconnecting
|
||||||
|
return c.connected, nil // Note that c.actionCompleted is still live and will be closed in connected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// forceConnectionStatus - forces the connection status to the specified value.
|
||||||
|
// This should only be used when there is no alternative (i.e. only in tests and to recover from situations that
|
||||||
|
// are unexpected)
|
||||||
|
func (c *connectionStatus) forceConnectionStatus(s status) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
c.status = s
|
||||||
|
}
|
||||||
14
vendor/github.com/eclipse/paho.mqtt.golang/store.go
generated
vendored
14
vendor/github.com/eclipse/paho.mqtt.golang/store.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
@@ -45,7 +49,7 @@ type Store interface {
|
|||||||
// where X is 'i' or 'o'
|
// where X is 'i' or 'o'
|
||||||
func mIDFromKey(key string) uint16 {
|
func mIDFromKey(key string) uint16 {
|
||||||
s := key[2:]
|
s := key[2:]
|
||||||
i, err := strconv.Atoi(s)
|
i, err := strconv.ParseUint(s, 10, 16)
|
||||||
chkerr(err)
|
chkerr(err)
|
||||||
return uint16(i)
|
return uint16(i)
|
||||||
}
|
}
|
||||||
|
|||||||
30
vendor/github.com/eclipse/paho.mqtt.golang/token.go
generated
vendored
30
vendor/github.com/eclipse/paho.mqtt.golang/token.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Allan Stockdill-Mander
|
* Allan Stockdill-Mander
|
||||||
@@ -13,6 +17,7 @@
|
|||||||
package mqtt
|
package mqtt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -198,3 +203,20 @@ type UnsubscribeToken struct {
|
|||||||
type DisconnectToken struct {
|
type DisconnectToken struct {
|
||||||
baseToken
|
baseToken
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimedOut is the error returned by WaitTimeout when the timeout expires
|
||||||
|
var TimedOut = errors.New("context canceled")
|
||||||
|
|
||||||
|
// WaitTokenTimeout is a utility function used to simplify the use of token.WaitTimeout
|
||||||
|
// token.WaitTimeout may return `false` due to time out but t.Error() still results
|
||||||
|
// in nil.
|
||||||
|
// `if t := client.X(); t.WaitTimeout(time.Second) && t.Error() != nil {` may evaluate
|
||||||
|
// to false even if the operation fails.
|
||||||
|
// It is important to note that if TimedOut is returned, then the operation may still be running
|
||||||
|
// and could eventually complete successfully.
|
||||||
|
func WaitTokenTimeout(t Token, d time.Duration) error {
|
||||||
|
if !t.WaitTimeout(d) {
|
||||||
|
return TimedOut
|
||||||
|
}
|
||||||
|
return t.Error()
|
||||||
|
}
|
||||||
|
|||||||
12
vendor/github.com/eclipse/paho.mqtt.golang/topic.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/topic.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
|
|||||||
12
vendor/github.com/eclipse/paho.mqtt.golang/trace.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/trace.go
generated
vendored
@@ -1,10 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 IBM Corp.
|
* Copyright (c) 2021 IBM Corp and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
* which accompanies this distribution, and is available at
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Seth Hoenig
|
* Seth Hoenig
|
||||||
|
|||||||
13
vendor/github.com/eclipse/paho.mqtt.golang/websocket.go
generated
vendored
13
vendor/github.com/eclipse/paho.mqtt.golang/websocket.go
generated
vendored
@@ -1,3 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v2.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
*/
|
||||||
|
|
||||||
package mqtt
|
package mqtt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
3
vendor/github.com/golang/protobuf/AUTHORS
generated
vendored
3
vendor/github.com/golang/protobuf/AUTHORS
generated
vendored
@@ -1,3 +0,0 @@
|
|||||||
# This source code refers to The Go Authors for copyright purposes.
|
|
||||||
# The master list of authors is in the main Go distribution,
|
|
||||||
# visible at http://tip.golang.org/AUTHORS.
|
|
||||||
3
vendor/github.com/golang/protobuf/CONTRIBUTORS
generated
vendored
3
vendor/github.com/golang/protobuf/CONTRIBUTORS
generated
vendored
@@ -1,3 +0,0 @@
|
|||||||
# This source code was written by the Go contributors.
|
|
||||||
# The master list of contributors is in the main Go distribution,
|
|
||||||
# visible at http://tip.golang.org/CONTRIBUTORS.
|
|
||||||
28
vendor/github.com/golang/protobuf/LICENSE
generated
vendored
28
vendor/github.com/golang/protobuf/LICENSE
generated
vendored
@@ -1,28 +0,0 @@
|
|||||||
Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
324
vendor/github.com/golang/protobuf/proto/buffer.go
generated
vendored
324
vendor/github.com/golang/protobuf/proto/buffer.go
generated
vendored
@@ -1,324 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/encoding/prototext"
|
|
||||||
"google.golang.org/protobuf/encoding/protowire"
|
|
||||||
"google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
WireVarint = 0
|
|
||||||
WireFixed32 = 5
|
|
||||||
WireFixed64 = 1
|
|
||||||
WireBytes = 2
|
|
||||||
WireStartGroup = 3
|
|
||||||
WireEndGroup = 4
|
|
||||||
)
|
|
||||||
|
|
||||||
// EncodeVarint returns the varint encoded bytes of v.
|
|
||||||
func EncodeVarint(v uint64) []byte {
|
|
||||||
return protowire.AppendVarint(nil, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SizeVarint returns the length of the varint encoded bytes of v.
|
|
||||||
// This is equal to len(EncodeVarint(v)).
|
|
||||||
func SizeVarint(v uint64) int {
|
|
||||||
return protowire.SizeVarint(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeVarint parses a varint encoded integer from b,
|
|
||||||
// returning the integer value and the length of the varint.
|
|
||||||
// It returns (0, 0) if there is a parse error.
|
|
||||||
func DecodeVarint(b []byte) (uint64, int) {
|
|
||||||
v, n := protowire.ConsumeVarint(b)
|
|
||||||
if n < 0 {
|
|
||||||
return 0, 0
|
|
||||||
}
|
|
||||||
return v, n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Buffer is a buffer for encoding and decoding the protobuf wire format.
|
|
||||||
// It may be reused between invocations to reduce memory usage.
|
|
||||||
type Buffer struct {
|
|
||||||
buf []byte
|
|
||||||
idx int
|
|
||||||
deterministic bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBuffer allocates a new Buffer initialized with buf,
|
|
||||||
// where the contents of buf are considered the unread portion of the buffer.
|
|
||||||
func NewBuffer(buf []byte) *Buffer {
|
|
||||||
return &Buffer{buf: buf}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDeterministic specifies whether to use deterministic serialization.
|
|
||||||
//
|
|
||||||
// Deterministic serialization guarantees that for a given binary, equal
|
|
||||||
// messages will always be serialized to the same bytes. This implies:
|
|
||||||
//
|
|
||||||
// - Repeated serialization of a message will return the same bytes.
|
|
||||||
// - Different processes of the same binary (which may be executing on
|
|
||||||
// different machines) will serialize equal messages to the same bytes.
|
|
||||||
//
|
|
||||||
// Note that the deterministic serialization is NOT canonical across
|
|
||||||
// languages. It is not guaranteed to remain stable over time. It is unstable
|
|
||||||
// across different builds with schema changes due to unknown fields.
|
|
||||||
// Users who need canonical serialization (e.g., persistent storage in a
|
|
||||||
// canonical form, fingerprinting, etc.) should define their own
|
|
||||||
// canonicalization specification and implement their own serializer rather
|
|
||||||
// than relying on this API.
|
|
||||||
//
|
|
||||||
// If deterministic serialization is requested, map entries will be sorted
|
|
||||||
// by keys in lexographical order. This is an implementation detail and
|
|
||||||
// subject to change.
|
|
||||||
func (b *Buffer) SetDeterministic(deterministic bool) {
|
|
||||||
b.deterministic = deterministic
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBuf sets buf as the internal buffer,
|
|
||||||
// where the contents of buf are considered the unread portion of the buffer.
|
|
||||||
func (b *Buffer) SetBuf(buf []byte) {
|
|
||||||
b.buf = buf
|
|
||||||
b.idx = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset clears the internal buffer of all written and unread data.
|
|
||||||
func (b *Buffer) Reset() {
|
|
||||||
b.buf = b.buf[:0]
|
|
||||||
b.idx = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bytes returns the internal buffer.
|
|
||||||
func (b *Buffer) Bytes() []byte {
|
|
||||||
return b.buf
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unread returns the unread portion of the buffer.
|
|
||||||
func (b *Buffer) Unread() []byte {
|
|
||||||
return b.buf[b.idx:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal appends the wire-format encoding of m to the buffer.
|
|
||||||
func (b *Buffer) Marshal(m Message) error {
|
|
||||||
var err error
|
|
||||||
b.buf, err = marshalAppend(b.buf, m, b.deterministic)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal parses the wire-format message in the buffer and
|
|
||||||
// places the decoded results in m.
|
|
||||||
// It does not reset m before unmarshaling.
|
|
||||||
func (b *Buffer) Unmarshal(m Message) error {
|
|
||||||
err := UnmarshalMerge(b.Unread(), m)
|
|
||||||
b.idx = len(b.buf)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
type unknownFields struct{ XXX_unrecognized protoimpl.UnknownFields }
|
|
||||||
|
|
||||||
func (m *unknownFields) String() string { panic("not implemented") }
|
|
||||||
func (m *unknownFields) Reset() { panic("not implemented") }
|
|
||||||
func (m *unknownFields) ProtoMessage() { panic("not implemented") }
|
|
||||||
|
|
||||||
// DebugPrint dumps the encoded bytes of b with a header and footer including s
|
|
||||||
// to stdout. This is only intended for debugging.
|
|
||||||
func (*Buffer) DebugPrint(s string, b []byte) {
|
|
||||||
m := MessageReflect(new(unknownFields))
|
|
||||||
m.SetUnknown(b)
|
|
||||||
b, _ = prototext.MarshalOptions{AllowPartial: true, Indent: "\t"}.Marshal(m.Interface())
|
|
||||||
fmt.Printf("==== %s ====\n%s==== %s ====\n", s, b, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeVarint appends an unsigned varint encoding to the buffer.
|
|
||||||
func (b *Buffer) EncodeVarint(v uint64) error {
|
|
||||||
b.buf = protowire.AppendVarint(b.buf, v)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeZigzag32 appends a 32-bit zig-zag varint encoding to the buffer.
|
|
||||||
func (b *Buffer) EncodeZigzag32(v uint64) error {
|
|
||||||
return b.EncodeVarint(uint64((uint32(v) << 1) ^ uint32((int32(v) >> 31))))
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeZigzag64 appends a 64-bit zig-zag varint encoding to the buffer.
|
|
||||||
func (b *Buffer) EncodeZigzag64(v uint64) error {
|
|
||||||
return b.EncodeVarint(uint64((uint64(v) << 1) ^ uint64((int64(v) >> 63))))
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeFixed32 appends a 32-bit little-endian integer to the buffer.
|
|
||||||
func (b *Buffer) EncodeFixed32(v uint64) error {
|
|
||||||
b.buf = protowire.AppendFixed32(b.buf, uint32(v))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeFixed64 appends a 64-bit little-endian integer to the buffer.
|
|
||||||
func (b *Buffer) EncodeFixed64(v uint64) error {
|
|
||||||
b.buf = protowire.AppendFixed64(b.buf, uint64(v))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeRawBytes appends a length-prefixed raw bytes to the buffer.
|
|
||||||
func (b *Buffer) EncodeRawBytes(v []byte) error {
|
|
||||||
b.buf = protowire.AppendBytes(b.buf, v)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeStringBytes appends a length-prefixed raw bytes to the buffer.
|
|
||||||
// It does not validate whether v contains valid UTF-8.
|
|
||||||
func (b *Buffer) EncodeStringBytes(v string) error {
|
|
||||||
b.buf = protowire.AppendString(b.buf, v)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeMessage appends a length-prefixed encoded message to the buffer.
|
|
||||||
func (b *Buffer) EncodeMessage(m Message) error {
|
|
||||||
var err error
|
|
||||||
b.buf = protowire.AppendVarint(b.buf, uint64(Size(m)))
|
|
||||||
b.buf, err = marshalAppend(b.buf, m, b.deterministic)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeVarint consumes an encoded unsigned varint from the buffer.
|
|
||||||
func (b *Buffer) DecodeVarint() (uint64, error) {
|
|
||||||
v, n := protowire.ConsumeVarint(b.buf[b.idx:])
|
|
||||||
if n < 0 {
|
|
||||||
return 0, protowire.ParseError(n)
|
|
||||||
}
|
|
||||||
b.idx += n
|
|
||||||
return uint64(v), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeZigzag32 consumes an encoded 32-bit zig-zag varint from the buffer.
|
|
||||||
func (b *Buffer) DecodeZigzag32() (uint64, error) {
|
|
||||||
v, err := b.DecodeVarint()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return uint64((uint32(v) >> 1) ^ uint32((int32(v&1)<<31)>>31)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeZigzag64 consumes an encoded 64-bit zig-zag varint from the buffer.
|
|
||||||
func (b *Buffer) DecodeZigzag64() (uint64, error) {
|
|
||||||
v, err := b.DecodeVarint()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return uint64((uint64(v) >> 1) ^ uint64((int64(v&1)<<63)>>63)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeFixed32 consumes a 32-bit little-endian integer from the buffer.
|
|
||||||
func (b *Buffer) DecodeFixed32() (uint64, error) {
|
|
||||||
v, n := protowire.ConsumeFixed32(b.buf[b.idx:])
|
|
||||||
if n < 0 {
|
|
||||||
return 0, protowire.ParseError(n)
|
|
||||||
}
|
|
||||||
b.idx += n
|
|
||||||
return uint64(v), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeFixed64 consumes a 64-bit little-endian integer from the buffer.
|
|
||||||
func (b *Buffer) DecodeFixed64() (uint64, error) {
|
|
||||||
v, n := protowire.ConsumeFixed64(b.buf[b.idx:])
|
|
||||||
if n < 0 {
|
|
||||||
return 0, protowire.ParseError(n)
|
|
||||||
}
|
|
||||||
b.idx += n
|
|
||||||
return uint64(v), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeRawBytes consumes a length-prefixed raw bytes from the buffer.
|
|
||||||
// If alloc is specified, it returns a copy the raw bytes
|
|
||||||
// rather than a sub-slice of the buffer.
|
|
||||||
func (b *Buffer) DecodeRawBytes(alloc bool) ([]byte, error) {
|
|
||||||
v, n := protowire.ConsumeBytes(b.buf[b.idx:])
|
|
||||||
if n < 0 {
|
|
||||||
return nil, protowire.ParseError(n)
|
|
||||||
}
|
|
||||||
b.idx += n
|
|
||||||
if alloc {
|
|
||||||
v = append([]byte(nil), v...)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeStringBytes consumes a length-prefixed raw bytes from the buffer.
|
|
||||||
// It does not validate whether the raw bytes contain valid UTF-8.
|
|
||||||
func (b *Buffer) DecodeStringBytes() (string, error) {
|
|
||||||
v, n := protowire.ConsumeString(b.buf[b.idx:])
|
|
||||||
if n < 0 {
|
|
||||||
return "", protowire.ParseError(n)
|
|
||||||
}
|
|
||||||
b.idx += n
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeMessage consumes a length-prefixed message from the buffer.
|
|
||||||
// It does not reset m before unmarshaling.
|
|
||||||
func (b *Buffer) DecodeMessage(m Message) error {
|
|
||||||
v, err := b.DecodeRawBytes(false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return UnmarshalMerge(v, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeGroup consumes a message group from the buffer.
|
|
||||||
// It assumes that the start group marker has already been consumed and
|
|
||||||
// consumes all bytes until (and including the end group marker).
|
|
||||||
// It does not reset m before unmarshaling.
|
|
||||||
func (b *Buffer) DecodeGroup(m Message) error {
|
|
||||||
v, n, err := consumeGroup(b.buf[b.idx:])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.idx += n
|
|
||||||
return UnmarshalMerge(v, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// consumeGroup parses b until it finds an end group marker, returning
|
|
||||||
// the raw bytes of the message (excluding the end group marker) and the
|
|
||||||
// the total length of the message (including the end group marker).
|
|
||||||
func consumeGroup(b []byte) ([]byte, int, error) {
|
|
||||||
b0 := b
|
|
||||||
depth := 1 // assume this follows a start group marker
|
|
||||||
for {
|
|
||||||
_, wtyp, tagLen := protowire.ConsumeTag(b)
|
|
||||||
if tagLen < 0 {
|
|
||||||
return nil, 0, protowire.ParseError(tagLen)
|
|
||||||
}
|
|
||||||
b = b[tagLen:]
|
|
||||||
|
|
||||||
var valLen int
|
|
||||||
switch wtyp {
|
|
||||||
case protowire.VarintType:
|
|
||||||
_, valLen = protowire.ConsumeVarint(b)
|
|
||||||
case protowire.Fixed32Type:
|
|
||||||
_, valLen = protowire.ConsumeFixed32(b)
|
|
||||||
case protowire.Fixed64Type:
|
|
||||||
_, valLen = protowire.ConsumeFixed64(b)
|
|
||||||
case protowire.BytesType:
|
|
||||||
_, valLen = protowire.ConsumeBytes(b)
|
|
||||||
case protowire.StartGroupType:
|
|
||||||
depth++
|
|
||||||
case protowire.EndGroupType:
|
|
||||||
depth--
|
|
||||||
default:
|
|
||||||
return nil, 0, errors.New("proto: cannot parse reserved wire type")
|
|
||||||
}
|
|
||||||
if valLen < 0 {
|
|
||||||
return nil, 0, protowire.ParseError(valLen)
|
|
||||||
}
|
|
||||||
b = b[valLen:]
|
|
||||||
|
|
||||||
if depth == 0 {
|
|
||||||
return b0[:len(b0)-len(b)-tagLen], len(b0) - len(b), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
63
vendor/github.com/golang/protobuf/proto/defaults.go
generated
vendored
63
vendor/github.com/golang/protobuf/proto/defaults.go
generated
vendored
@@ -1,63 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SetDefaults sets unpopulated scalar fields to their default values.
|
|
||||||
// Fields within a oneof are not set even if they have a default value.
|
|
||||||
// SetDefaults is recursively called upon any populated message fields.
|
|
||||||
func SetDefaults(m Message) {
|
|
||||||
if m != nil {
|
|
||||||
setDefaults(MessageReflect(m))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setDefaults(m protoreflect.Message) {
|
|
||||||
fds := m.Descriptor().Fields()
|
|
||||||
for i := 0; i < fds.Len(); i++ {
|
|
||||||
fd := fds.Get(i)
|
|
||||||
if !m.Has(fd) {
|
|
||||||
if fd.HasDefault() && fd.ContainingOneof() == nil {
|
|
||||||
v := fd.Default()
|
|
||||||
if fd.Kind() == protoreflect.BytesKind {
|
|
||||||
v = protoreflect.ValueOf(append([]byte(nil), v.Bytes()...)) // copy the default bytes
|
|
||||||
}
|
|
||||||
m.Set(fd, v)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
|
|
||||||
switch {
|
|
||||||
// Handle singular message.
|
|
||||||
case fd.Cardinality() != protoreflect.Repeated:
|
|
||||||
if fd.Message() != nil {
|
|
||||||
setDefaults(m.Get(fd).Message())
|
|
||||||
}
|
|
||||||
// Handle list of messages.
|
|
||||||
case fd.IsList():
|
|
||||||
if fd.Message() != nil {
|
|
||||||
ls := m.Get(fd).List()
|
|
||||||
for i := 0; i < ls.Len(); i++ {
|
|
||||||
setDefaults(ls.Get(i).Message())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Handle map of messages.
|
|
||||||
case fd.IsMap():
|
|
||||||
if fd.MapValue().Message() != nil {
|
|
||||||
ms := m.Get(fd).Map()
|
|
||||||
ms.Range(func(_ protoreflect.MapKey, v protoreflect.Value) bool {
|
|
||||||
setDefaults(v.Message())
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
113
vendor/github.com/golang/protobuf/proto/deprecated.go
generated
vendored
113
vendor/github.com/golang/protobuf/proto/deprecated.go
generated
vendored
@@ -1,113 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
protoV2 "google.golang.org/protobuf/proto"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Deprecated: No longer returned.
|
|
||||||
ErrNil = errors.New("proto: Marshal called with nil")
|
|
||||||
|
|
||||||
// Deprecated: No longer returned.
|
|
||||||
ErrTooLarge = errors.New("proto: message encodes to over 2 GB")
|
|
||||||
|
|
||||||
// Deprecated: No longer returned.
|
|
||||||
ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func GetStats() Stats { return Stats{} }
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func MarshalMessageSet(interface{}) ([]byte, error) {
|
|
||||||
return nil, errors.New("proto: not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func UnmarshalMessageSet([]byte, interface{}) error {
|
|
||||||
return errors.New("proto: not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func MarshalMessageSetJSON(interface{}) ([]byte, error) {
|
|
||||||
return nil, errors.New("proto: not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func UnmarshalMessageSetJSON([]byte, interface{}) error {
|
|
||||||
return errors.New("proto: not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func RegisterMessageSetType(Message, int32, string) {}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func EnumName(m map[int32]string, v int32) string {
|
|
||||||
s, ok := m[v]
|
|
||||||
if ok {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return strconv.Itoa(int(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
|
|
||||||
if data[0] == '"' {
|
|
||||||
// New style: enums are strings.
|
|
||||||
var repr string
|
|
||||||
if err := json.Unmarshal(data, &repr); err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
val, ok := m[repr]
|
|
||||||
if !ok {
|
|
||||||
return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr)
|
|
||||||
}
|
|
||||||
return val, nil
|
|
||||||
}
|
|
||||||
// Old style: enums are ints.
|
|
||||||
var val int32
|
|
||||||
if err := json.Unmarshal(data, &val); err != nil {
|
|
||||||
return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName)
|
|
||||||
}
|
|
||||||
return val, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this type existed for intenal-use only.
|
|
||||||
type InternalMessageInfo struct{}
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this method existed for intenal-use only.
|
|
||||||
func (*InternalMessageInfo) DiscardUnknown(m Message) {
|
|
||||||
DiscardUnknown(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this method existed for intenal-use only.
|
|
||||||
func (*InternalMessageInfo) Marshal(b []byte, m Message, deterministic bool) ([]byte, error) {
|
|
||||||
return protoV2.MarshalOptions{Deterministic: deterministic}.MarshalAppend(b, MessageV2(m))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this method existed for intenal-use only.
|
|
||||||
func (*InternalMessageInfo) Merge(dst, src Message) {
|
|
||||||
protoV2.Merge(MessageV2(dst), MessageV2(src))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this method existed for intenal-use only.
|
|
||||||
func (*InternalMessageInfo) Size(m Message) int {
|
|
||||||
return protoV2.Size(MessageV2(m))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this method existed for intenal-use only.
|
|
||||||
func (*InternalMessageInfo) Unmarshal(m Message, b []byte) error {
|
|
||||||
return protoV2.UnmarshalOptions{Merge: true}.Unmarshal(b, MessageV2(m))
|
|
||||||
}
|
|
||||||
58
vendor/github.com/golang/protobuf/proto/discard.go
generated
vendored
58
vendor/github.com/golang/protobuf/proto/discard.go
generated
vendored
@@ -1,58 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DiscardUnknown recursively discards all unknown fields from this message
|
|
||||||
// and all embedded messages.
|
|
||||||
//
|
|
||||||
// When unmarshaling a message with unrecognized fields, the tags and values
|
|
||||||
// of such fields are preserved in the Message. This allows a later call to
|
|
||||||
// marshal to be able to produce a message that continues to have those
|
|
||||||
// unrecognized fields. To avoid this, DiscardUnknown is used to
|
|
||||||
// explicitly clear the unknown fields after unmarshaling.
|
|
||||||
func DiscardUnknown(m Message) {
|
|
||||||
if m != nil {
|
|
||||||
discardUnknown(MessageReflect(m))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func discardUnknown(m protoreflect.Message) {
|
|
||||||
m.Range(func(fd protoreflect.FieldDescriptor, val protoreflect.Value) bool {
|
|
||||||
switch {
|
|
||||||
// Handle singular message.
|
|
||||||
case fd.Cardinality() != protoreflect.Repeated:
|
|
||||||
if fd.Message() != nil {
|
|
||||||
discardUnknown(m.Get(fd).Message())
|
|
||||||
}
|
|
||||||
// Handle list of messages.
|
|
||||||
case fd.IsList():
|
|
||||||
if fd.Message() != nil {
|
|
||||||
ls := m.Get(fd).List()
|
|
||||||
for i := 0; i < ls.Len(); i++ {
|
|
||||||
discardUnknown(ls.Get(i).Message())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Handle map of messages.
|
|
||||||
case fd.IsMap():
|
|
||||||
if fd.MapValue().Message() != nil {
|
|
||||||
ms := m.Get(fd).Map()
|
|
||||||
ms.Range(func(_ protoreflect.MapKey, v protoreflect.Value) bool {
|
|
||||||
discardUnknown(v.Message())
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
// Discard unknown fields.
|
|
||||||
if len(m.GetUnknown()) > 0 {
|
|
||||||
m.SetUnknown(nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
356
vendor/github.com/golang/protobuf/proto/extensions.go
generated
vendored
356
vendor/github.com/golang/protobuf/proto/extensions.go
generated
vendored
@@ -1,356 +0,0 @@
|
|||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/encoding/protowire"
|
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
|
||||||
"google.golang.org/protobuf/runtime/protoiface"
|
|
||||||
"google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// ExtensionDesc represents an extension descriptor and
|
|
||||||
// is used to interact with an extension field in a message.
|
|
||||||
//
|
|
||||||
// Variables of this type are generated in code by protoc-gen-go.
|
|
||||||
ExtensionDesc = protoimpl.ExtensionInfo
|
|
||||||
|
|
||||||
// ExtensionRange represents a range of message extensions.
|
|
||||||
// Used in code generated by protoc-gen-go.
|
|
||||||
ExtensionRange = protoiface.ExtensionRangeV1
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this is an internal type.
|
|
||||||
Extension = protoimpl.ExtensionFieldV1
|
|
||||||
|
|
||||||
// Deprecated: Do not use; this is an internal type.
|
|
||||||
XXX_InternalExtensions = protoimpl.ExtensionFields
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrMissingExtension reports whether the extension was not present.
|
|
||||||
var ErrMissingExtension = errors.New("proto: missing extension")
|
|
||||||
|
|
||||||
var errNotExtendable = errors.New("proto: not an extendable proto.Message")
|
|
||||||
|
|
||||||
// HasExtension reports whether the extension field is present in m
|
|
||||||
// either as an explicitly populated field or as an unknown field.
|
|
||||||
func HasExtension(m Message, xt *ExtensionDesc) (has bool) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether any populated known field matches the field number.
|
|
||||||
xtd := xt.TypeDescriptor()
|
|
||||||
if isValidExtension(mr.Descriptor(), xtd) {
|
|
||||||
has = mr.Has(xtd)
|
|
||||||
} else {
|
|
||||||
mr.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
|
|
||||||
has = int32(fd.Number()) == xt.Field
|
|
||||||
return !has
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether any unknown field matches the field number.
|
|
||||||
for b := mr.GetUnknown(); !has && len(b) > 0; {
|
|
||||||
num, _, n := protowire.ConsumeField(b)
|
|
||||||
has = int32(num) == xt.Field
|
|
||||||
b = b[n:]
|
|
||||||
}
|
|
||||||
return has
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearExtension removes the extension field from m
|
|
||||||
// either as an explicitly populated field or as an unknown field.
|
|
||||||
func ClearExtension(m Message, xt *ExtensionDesc) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
xtd := xt.TypeDescriptor()
|
|
||||||
if isValidExtension(mr.Descriptor(), xtd) {
|
|
||||||
mr.Clear(xtd)
|
|
||||||
} else {
|
|
||||||
mr.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
|
|
||||||
if int32(fd.Number()) == xt.Field {
|
|
||||||
mr.Clear(fd)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
clearUnknown(mr, fieldNum(xt.Field))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearAllExtensions clears all extensions from m.
|
|
||||||
// This includes populated fields and unknown fields in the extension range.
|
|
||||||
func ClearAllExtensions(m Message) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
mr.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
|
|
||||||
if fd.IsExtension() {
|
|
||||||
mr.Clear(fd)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
clearUnknown(mr, mr.Descriptor().ExtensionRanges())
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetExtension retrieves a proto2 extended field from m.
|
|
||||||
//
|
|
||||||
// If the descriptor is type complete (i.e., ExtensionDesc.ExtensionType is non-nil),
|
|
||||||
// then GetExtension parses the encoded field and returns a Go value of the specified type.
|
|
||||||
// If the field is not present, then the default value is returned (if one is specified),
|
|
||||||
// otherwise ErrMissingExtension is reported.
|
|
||||||
//
|
|
||||||
// If the descriptor is type incomplete (i.e., ExtensionDesc.ExtensionType is nil),
|
|
||||||
// then GetExtension returns the raw encoded bytes for the extension field.
|
|
||||||
func GetExtension(m Message, xt *ExtensionDesc) (interface{}, error) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() || mr.Descriptor().ExtensionRanges().Len() == 0 {
|
|
||||||
return nil, errNotExtendable
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve the unknown fields for this extension field.
|
|
||||||
var bo protoreflect.RawFields
|
|
||||||
for bi := mr.GetUnknown(); len(bi) > 0; {
|
|
||||||
num, _, n := protowire.ConsumeField(bi)
|
|
||||||
if int32(num) == xt.Field {
|
|
||||||
bo = append(bo, bi[:n]...)
|
|
||||||
}
|
|
||||||
bi = bi[n:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// For type incomplete descriptors, only retrieve the unknown fields.
|
|
||||||
if xt.ExtensionType == nil {
|
|
||||||
return []byte(bo), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the extension field only exists as unknown fields, unmarshal it.
|
|
||||||
// This is rarely done since proto.Unmarshal eagerly unmarshals extensions.
|
|
||||||
xtd := xt.TypeDescriptor()
|
|
||||||
if !isValidExtension(mr.Descriptor(), xtd) {
|
|
||||||
return nil, fmt.Errorf("proto: bad extended type; %T does not extend %T", xt.ExtendedType, m)
|
|
||||||
}
|
|
||||||
if !mr.Has(xtd) && len(bo) > 0 {
|
|
||||||
m2 := mr.New()
|
|
||||||
if err := (proto.UnmarshalOptions{
|
|
||||||
Resolver: extensionResolver{xt},
|
|
||||||
}.Unmarshal(bo, m2.Interface())); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if m2.Has(xtd) {
|
|
||||||
mr.Set(xtd, m2.Get(xtd))
|
|
||||||
clearUnknown(mr, fieldNum(xt.Field))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether the message has the extension field set or a default.
|
|
||||||
var pv protoreflect.Value
|
|
||||||
switch {
|
|
||||||
case mr.Has(xtd):
|
|
||||||
pv = mr.Get(xtd)
|
|
||||||
case xtd.HasDefault():
|
|
||||||
pv = xtd.Default()
|
|
||||||
default:
|
|
||||||
return nil, ErrMissingExtension
|
|
||||||
}
|
|
||||||
|
|
||||||
v := xt.InterfaceOf(pv)
|
|
||||||
rv := reflect.ValueOf(v)
|
|
||||||
if isScalarKind(rv.Kind()) {
|
|
||||||
rv2 := reflect.New(rv.Type())
|
|
||||||
rv2.Elem().Set(rv)
|
|
||||||
v = rv2.Interface()
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// extensionResolver is a custom extension resolver that stores a single
|
|
||||||
// extension type that takes precedence over the global registry.
|
|
||||||
type extensionResolver struct{ xt protoreflect.ExtensionType }
|
|
||||||
|
|
||||||
func (r extensionResolver) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) {
|
|
||||||
if xtd := r.xt.TypeDescriptor(); xtd.FullName() == field {
|
|
||||||
return r.xt, nil
|
|
||||||
}
|
|
||||||
return protoregistry.GlobalTypes.FindExtensionByName(field)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r extensionResolver) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) {
|
|
||||||
if xtd := r.xt.TypeDescriptor(); xtd.ContainingMessage().FullName() == message && xtd.Number() == field {
|
|
||||||
return r.xt, nil
|
|
||||||
}
|
|
||||||
return protoregistry.GlobalTypes.FindExtensionByNumber(message, field)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetExtensions returns a list of the extensions values present in m,
|
|
||||||
// corresponding with the provided list of extension descriptors, xts.
|
|
||||||
// If an extension is missing in m, the corresponding value is nil.
|
|
||||||
func GetExtensions(m Message, xts []*ExtensionDesc) ([]interface{}, error) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() {
|
|
||||||
return nil, errNotExtendable
|
|
||||||
}
|
|
||||||
|
|
||||||
vs := make([]interface{}, len(xts))
|
|
||||||
for i, xt := range xts {
|
|
||||||
v, err := GetExtension(m, xt)
|
|
||||||
if err != nil {
|
|
||||||
if err == ErrMissingExtension {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return vs, err
|
|
||||||
}
|
|
||||||
vs[i] = v
|
|
||||||
}
|
|
||||||
return vs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetExtension sets an extension field in m to the provided value.
|
|
||||||
func SetExtension(m Message, xt *ExtensionDesc, v interface{}) error {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() || mr.Descriptor().ExtensionRanges().Len() == 0 {
|
|
||||||
return errNotExtendable
|
|
||||||
}
|
|
||||||
|
|
||||||
rv := reflect.ValueOf(v)
|
|
||||||
if reflect.TypeOf(v) != reflect.TypeOf(xt.ExtensionType) {
|
|
||||||
return fmt.Errorf("proto: bad extension value type. got: %T, want: %T", v, xt.ExtensionType)
|
|
||||||
}
|
|
||||||
if rv.Kind() == reflect.Ptr {
|
|
||||||
if rv.IsNil() {
|
|
||||||
return fmt.Errorf("proto: SetExtension called with nil value of type %T", v)
|
|
||||||
}
|
|
||||||
if isScalarKind(rv.Elem().Kind()) {
|
|
||||||
v = rv.Elem().Interface()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xtd := xt.TypeDescriptor()
|
|
||||||
if !isValidExtension(mr.Descriptor(), xtd) {
|
|
||||||
return fmt.Errorf("proto: bad extended type; %T does not extend %T", xt.ExtendedType, m)
|
|
||||||
}
|
|
||||||
mr.Set(xtd, xt.ValueOf(v))
|
|
||||||
clearUnknown(mr, fieldNum(xt.Field))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetRawExtension inserts b into the unknown fields of m.
|
|
||||||
//
|
|
||||||
// Deprecated: Use Message.ProtoReflect.SetUnknown instead.
|
|
||||||
func SetRawExtension(m Message, fnum int32, b []byte) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify that the raw field is valid.
|
|
||||||
for b0 := b; len(b0) > 0; {
|
|
||||||
num, _, n := protowire.ConsumeField(b0)
|
|
||||||
if int32(num) != fnum {
|
|
||||||
panic(fmt.Sprintf("mismatching field number: got %d, want %d", num, fnum))
|
|
||||||
}
|
|
||||||
b0 = b0[n:]
|
|
||||||
}
|
|
||||||
|
|
||||||
ClearExtension(m, &ExtensionDesc{Field: fnum})
|
|
||||||
mr.SetUnknown(append(mr.GetUnknown(), b...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExtensionDescs returns a list of extension descriptors found in m,
|
|
||||||
// containing descriptors for both populated extension fields in m and
|
|
||||||
// also unknown fields of m that are in the extension range.
|
|
||||||
// For the later case, an type incomplete descriptor is provided where only
|
|
||||||
// the ExtensionDesc.Field field is populated.
|
|
||||||
// The order of the extension descriptors is undefined.
|
|
||||||
func ExtensionDescs(m Message) ([]*ExtensionDesc, error) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() || mr.Descriptor().ExtensionRanges().Len() == 0 {
|
|
||||||
return nil, errNotExtendable
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect a set of known extension descriptors.
|
|
||||||
extDescs := make(map[protoreflect.FieldNumber]*ExtensionDesc)
|
|
||||||
mr.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
|
|
||||||
if fd.IsExtension() {
|
|
||||||
xt := fd.(protoreflect.ExtensionTypeDescriptor)
|
|
||||||
if xd, ok := xt.Type().(*ExtensionDesc); ok {
|
|
||||||
extDescs[fd.Number()] = xd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
// Collect a set of unknown extension descriptors.
|
|
||||||
extRanges := mr.Descriptor().ExtensionRanges()
|
|
||||||
for b := mr.GetUnknown(); len(b) > 0; {
|
|
||||||
num, _, n := protowire.ConsumeField(b)
|
|
||||||
if extRanges.Has(num) && extDescs[num] == nil {
|
|
||||||
extDescs[num] = nil
|
|
||||||
}
|
|
||||||
b = b[n:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transpose the set of descriptors into a list.
|
|
||||||
var xts []*ExtensionDesc
|
|
||||||
for num, xt := range extDescs {
|
|
||||||
if xt == nil {
|
|
||||||
xt = &ExtensionDesc{Field: int32(num)}
|
|
||||||
}
|
|
||||||
xts = append(xts, xt)
|
|
||||||
}
|
|
||||||
return xts, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// isValidExtension reports whether xtd is a valid extension descriptor for md.
|
|
||||||
func isValidExtension(md protoreflect.MessageDescriptor, xtd protoreflect.ExtensionTypeDescriptor) bool {
|
|
||||||
return xtd.ContainingMessage() == md && md.ExtensionRanges().Has(xtd.Number())
|
|
||||||
}
|
|
||||||
|
|
||||||
// isScalarKind reports whether k is a protobuf scalar kind (except bytes).
|
|
||||||
// This function exists for historical reasons since the representation of
|
|
||||||
// scalars differs between v1 and v2, where v1 uses *T and v2 uses T.
|
|
||||||
func isScalarKind(k reflect.Kind) bool {
|
|
||||||
switch k {
|
|
||||||
case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// clearUnknown removes unknown fields from m where remover.Has reports true.
|
|
||||||
func clearUnknown(m protoreflect.Message, remover interface {
|
|
||||||
Has(protoreflect.FieldNumber) bool
|
|
||||||
}) {
|
|
||||||
var bo protoreflect.RawFields
|
|
||||||
for bi := m.GetUnknown(); len(bi) > 0; {
|
|
||||||
num, _, n := protowire.ConsumeField(bi)
|
|
||||||
if !remover.Has(num) {
|
|
||||||
bo = append(bo, bi[:n]...)
|
|
||||||
}
|
|
||||||
bi = bi[n:]
|
|
||||||
}
|
|
||||||
if bi := m.GetUnknown(); len(bi) != len(bo) {
|
|
||||||
m.SetUnknown(bo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type fieldNum protoreflect.FieldNumber
|
|
||||||
|
|
||||||
func (n1 fieldNum) Has(n2 protoreflect.FieldNumber) bool {
|
|
||||||
return protoreflect.FieldNumber(n1) == n2
|
|
||||||
}
|
|
||||||
306
vendor/github.com/golang/protobuf/proto/properties.go
generated
vendored
306
vendor/github.com/golang/protobuf/proto/properties.go
generated
vendored
@@ -1,306 +0,0 @@
|
|||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StructProperties represents protocol buffer type information for a
|
|
||||||
// generated protobuf message in the open-struct API.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
type StructProperties struct {
|
|
||||||
// Prop are the properties for each field.
|
|
||||||
//
|
|
||||||
// Fields belonging to a oneof are stored in OneofTypes instead, with a
|
|
||||||
// single Properties representing the parent oneof held here.
|
|
||||||
//
|
|
||||||
// The order of Prop matches the order of fields in the Go struct.
|
|
||||||
// Struct fields that are not related to protobufs have a "XXX_" prefix
|
|
||||||
// in the Properties.Name and must be ignored by the user.
|
|
||||||
Prop []*Properties
|
|
||||||
|
|
||||||
// OneofTypes contains information about the oneof fields in this message.
|
|
||||||
// It is keyed by the protobuf field name.
|
|
||||||
OneofTypes map[string]*OneofProperties
|
|
||||||
}
|
|
||||||
|
|
||||||
// Properties represents the type information for a protobuf message field.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
type Properties struct {
|
|
||||||
// Name is a placeholder name with little meaningful semantic value.
|
|
||||||
// If the name has an "XXX_" prefix, the entire Properties must be ignored.
|
|
||||||
Name string
|
|
||||||
// OrigName is the protobuf field name or oneof name.
|
|
||||||
OrigName string
|
|
||||||
// JSONName is the JSON name for the protobuf field.
|
|
||||||
JSONName string
|
|
||||||
// Enum is a placeholder name for enums.
|
|
||||||
// For historical reasons, this is neither the Go name for the enum,
|
|
||||||
// nor the protobuf name for the enum.
|
|
||||||
Enum string // Deprecated: Do not use.
|
|
||||||
// Weak contains the full name of the weakly referenced message.
|
|
||||||
Weak string
|
|
||||||
// Wire is a string representation of the wire type.
|
|
||||||
Wire string
|
|
||||||
// WireType is the protobuf wire type for the field.
|
|
||||||
WireType int
|
|
||||||
// Tag is the protobuf field number.
|
|
||||||
Tag int
|
|
||||||
// Required reports whether this is a required field.
|
|
||||||
Required bool
|
|
||||||
// Optional reports whether this is a optional field.
|
|
||||||
Optional bool
|
|
||||||
// Repeated reports whether this is a repeated field.
|
|
||||||
Repeated bool
|
|
||||||
// Packed reports whether this is a packed repeated field of scalars.
|
|
||||||
Packed bool
|
|
||||||
// Proto3 reports whether this field operates under the proto3 syntax.
|
|
||||||
Proto3 bool
|
|
||||||
// Oneof reports whether this field belongs within a oneof.
|
|
||||||
Oneof bool
|
|
||||||
|
|
||||||
// Default is the default value in string form.
|
|
||||||
Default string
|
|
||||||
// HasDefault reports whether the field has a default value.
|
|
||||||
HasDefault bool
|
|
||||||
|
|
||||||
// MapKeyProp is the properties for the key field for a map field.
|
|
||||||
MapKeyProp *Properties
|
|
||||||
// MapValProp is the properties for the value field for a map field.
|
|
||||||
MapValProp *Properties
|
|
||||||
}
|
|
||||||
|
|
||||||
// OneofProperties represents the type information for a protobuf oneof.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
type OneofProperties struct {
|
|
||||||
// Type is a pointer to the generated wrapper type for the field value.
|
|
||||||
// This is nil for messages that are not in the open-struct API.
|
|
||||||
Type reflect.Type
|
|
||||||
// Field is the index into StructProperties.Prop for the containing oneof.
|
|
||||||
Field int
|
|
||||||
// Prop is the properties for the field.
|
|
||||||
Prop *Properties
|
|
||||||
}
|
|
||||||
|
|
||||||
// String formats the properties in the protobuf struct field tag style.
|
|
||||||
func (p *Properties) String() string {
|
|
||||||
s := p.Wire
|
|
||||||
s += "," + strconv.Itoa(p.Tag)
|
|
||||||
if p.Required {
|
|
||||||
s += ",req"
|
|
||||||
}
|
|
||||||
if p.Optional {
|
|
||||||
s += ",opt"
|
|
||||||
}
|
|
||||||
if p.Repeated {
|
|
||||||
s += ",rep"
|
|
||||||
}
|
|
||||||
if p.Packed {
|
|
||||||
s += ",packed"
|
|
||||||
}
|
|
||||||
s += ",name=" + p.OrigName
|
|
||||||
if p.JSONName != "" {
|
|
||||||
s += ",json=" + p.JSONName
|
|
||||||
}
|
|
||||||
if len(p.Enum) > 0 {
|
|
||||||
s += ",enum=" + p.Enum
|
|
||||||
}
|
|
||||||
if len(p.Weak) > 0 {
|
|
||||||
s += ",weak=" + p.Weak
|
|
||||||
}
|
|
||||||
if p.Proto3 {
|
|
||||||
s += ",proto3"
|
|
||||||
}
|
|
||||||
if p.Oneof {
|
|
||||||
s += ",oneof"
|
|
||||||
}
|
|
||||||
if p.HasDefault {
|
|
||||||
s += ",def=" + p.Default
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse populates p by parsing a string in the protobuf struct field tag style.
|
|
||||||
func (p *Properties) Parse(tag string) {
|
|
||||||
// For example: "bytes,49,opt,name=foo,def=hello!"
|
|
||||||
for len(tag) > 0 {
|
|
||||||
i := strings.IndexByte(tag, ',')
|
|
||||||
if i < 0 {
|
|
||||||
i = len(tag)
|
|
||||||
}
|
|
||||||
switch s := tag[:i]; {
|
|
||||||
case strings.HasPrefix(s, "name="):
|
|
||||||
p.OrigName = s[len("name="):]
|
|
||||||
case strings.HasPrefix(s, "json="):
|
|
||||||
p.JSONName = s[len("json="):]
|
|
||||||
case strings.HasPrefix(s, "enum="):
|
|
||||||
p.Enum = s[len("enum="):]
|
|
||||||
case strings.HasPrefix(s, "weak="):
|
|
||||||
p.Weak = s[len("weak="):]
|
|
||||||
case strings.Trim(s, "0123456789") == "":
|
|
||||||
n, _ := strconv.ParseUint(s, 10, 32)
|
|
||||||
p.Tag = int(n)
|
|
||||||
case s == "opt":
|
|
||||||
p.Optional = true
|
|
||||||
case s == "req":
|
|
||||||
p.Required = true
|
|
||||||
case s == "rep":
|
|
||||||
p.Repeated = true
|
|
||||||
case s == "varint" || s == "zigzag32" || s == "zigzag64":
|
|
||||||
p.Wire = s
|
|
||||||
p.WireType = WireVarint
|
|
||||||
case s == "fixed32":
|
|
||||||
p.Wire = s
|
|
||||||
p.WireType = WireFixed32
|
|
||||||
case s == "fixed64":
|
|
||||||
p.Wire = s
|
|
||||||
p.WireType = WireFixed64
|
|
||||||
case s == "bytes":
|
|
||||||
p.Wire = s
|
|
||||||
p.WireType = WireBytes
|
|
||||||
case s == "group":
|
|
||||||
p.Wire = s
|
|
||||||
p.WireType = WireStartGroup
|
|
||||||
case s == "packed":
|
|
||||||
p.Packed = true
|
|
||||||
case s == "proto3":
|
|
||||||
p.Proto3 = true
|
|
||||||
case s == "oneof":
|
|
||||||
p.Oneof = true
|
|
||||||
case strings.HasPrefix(s, "def="):
|
|
||||||
// The default tag is special in that everything afterwards is the
|
|
||||||
// default regardless of the presence of commas.
|
|
||||||
p.HasDefault = true
|
|
||||||
p.Default, i = tag[len("def="):], len(tag)
|
|
||||||
}
|
|
||||||
tag = strings.TrimPrefix(tag[i:], ",")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init populates the properties from a protocol buffer struct tag.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) {
|
|
||||||
p.Name = name
|
|
||||||
p.OrigName = name
|
|
||||||
if tag == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.Parse(tag)
|
|
||||||
|
|
||||||
if typ != nil && typ.Kind() == reflect.Map {
|
|
||||||
p.MapKeyProp = new(Properties)
|
|
||||||
p.MapKeyProp.Init(nil, "Key", f.Tag.Get("protobuf_key"), nil)
|
|
||||||
p.MapValProp = new(Properties)
|
|
||||||
p.MapValProp.Init(nil, "Value", f.Tag.Get("protobuf_val"), nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var propertiesCache sync.Map // map[reflect.Type]*StructProperties
|
|
||||||
|
|
||||||
// GetProperties returns the list of properties for the type represented by t,
|
|
||||||
// which must be a generated protocol buffer message in the open-struct API,
|
|
||||||
// where protobuf message fields are represented by exported Go struct fields.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protobuf reflection instead.
|
|
||||||
func GetProperties(t reflect.Type) *StructProperties {
|
|
||||||
if p, ok := propertiesCache.Load(t); ok {
|
|
||||||
return p.(*StructProperties)
|
|
||||||
}
|
|
||||||
p, _ := propertiesCache.LoadOrStore(t, newProperties(t))
|
|
||||||
return p.(*StructProperties)
|
|
||||||
}
|
|
||||||
|
|
||||||
func newProperties(t reflect.Type) *StructProperties {
|
|
||||||
if t.Kind() != reflect.Struct {
|
|
||||||
panic(fmt.Sprintf("%v is not a generated message in the open-struct API", t))
|
|
||||||
}
|
|
||||||
|
|
||||||
var hasOneof bool
|
|
||||||
prop := new(StructProperties)
|
|
||||||
|
|
||||||
// Construct a list of properties for each field in the struct.
|
|
||||||
for i := 0; i < t.NumField(); i++ {
|
|
||||||
p := new(Properties)
|
|
||||||
f := t.Field(i)
|
|
||||||
tagField := f.Tag.Get("protobuf")
|
|
||||||
p.Init(f.Type, f.Name, tagField, &f)
|
|
||||||
|
|
||||||
tagOneof := f.Tag.Get("protobuf_oneof")
|
|
||||||
if tagOneof != "" {
|
|
||||||
hasOneof = true
|
|
||||||
p.OrigName = tagOneof
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rename unrelated struct fields with the "XXX_" prefix since so much
|
|
||||||
// user code simply checks for this to exclude special fields.
|
|
||||||
if tagField == "" && tagOneof == "" && !strings.HasPrefix(p.Name, "XXX_") {
|
|
||||||
p.Name = "XXX_" + p.Name
|
|
||||||
p.OrigName = "XXX_" + p.OrigName
|
|
||||||
} else if p.Weak != "" {
|
|
||||||
p.Name = p.OrigName // avoid possible "XXX_" prefix on weak field
|
|
||||||
}
|
|
||||||
|
|
||||||
prop.Prop = append(prop.Prop, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a mapping of oneof field names to properties.
|
|
||||||
if hasOneof {
|
|
||||||
var oneofWrappers []interface{}
|
|
||||||
if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofFuncs"); ok {
|
|
||||||
oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[3].Interface().([]interface{})
|
|
||||||
}
|
|
||||||
if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofWrappers"); ok {
|
|
||||||
oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0].Interface().([]interface{})
|
|
||||||
}
|
|
||||||
if m, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(protoreflect.ProtoMessage); ok {
|
|
||||||
if m, ok := m.ProtoReflect().(interface{ ProtoMessageInfo() *protoimpl.MessageInfo }); ok {
|
|
||||||
oneofWrappers = m.ProtoMessageInfo().OneofWrappers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prop.OneofTypes = make(map[string]*OneofProperties)
|
|
||||||
for _, wrapper := range oneofWrappers {
|
|
||||||
p := &OneofProperties{
|
|
||||||
Type: reflect.ValueOf(wrapper).Type(), // *T
|
|
||||||
Prop: new(Properties),
|
|
||||||
}
|
|
||||||
f := p.Type.Elem().Field(0)
|
|
||||||
p.Prop.Name = f.Name
|
|
||||||
p.Prop.Parse(f.Tag.Get("protobuf"))
|
|
||||||
|
|
||||||
// Determine the struct field that contains this oneof.
|
|
||||||
// Each wrapper is assignable to exactly one parent field.
|
|
||||||
var foundOneof bool
|
|
||||||
for i := 0; i < t.NumField() && !foundOneof; i++ {
|
|
||||||
if p.Type.AssignableTo(t.Field(i).Type) {
|
|
||||||
p.Field = i
|
|
||||||
foundOneof = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !foundOneof {
|
|
||||||
panic(fmt.Sprintf("%v is not a generated message in the open-struct API", t))
|
|
||||||
}
|
|
||||||
prop.OneofTypes[p.Prop.OrigName] = p
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return prop
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sp *StructProperties) Len() int { return len(sp.Prop) }
|
|
||||||
func (sp *StructProperties) Less(i, j int) bool { return false }
|
|
||||||
func (sp *StructProperties) Swap(i, j int) { return }
|
|
||||||
167
vendor/github.com/golang/protobuf/proto/proto.go
generated
vendored
167
vendor/github.com/golang/protobuf/proto/proto.go
generated
vendored
@@ -1,167 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package proto provides functionality for handling protocol buffer messages.
|
|
||||||
// In particular, it provides marshaling and unmarshaling between a protobuf
|
|
||||||
// message and the binary wire format.
|
|
||||||
//
|
|
||||||
// See https://developers.google.com/protocol-buffers/docs/gotutorial for
|
|
||||||
// more information.
|
|
||||||
//
|
|
||||||
// Deprecated: Use the "google.golang.org/protobuf/proto" package instead.
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
protoV2 "google.golang.org/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/runtime/protoiface"
|
|
||||||
"google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
ProtoPackageIsVersion1 = true
|
|
||||||
ProtoPackageIsVersion2 = true
|
|
||||||
ProtoPackageIsVersion3 = true
|
|
||||||
ProtoPackageIsVersion4 = true
|
|
||||||
)
|
|
||||||
|
|
||||||
// GeneratedEnum is any enum type generated by protoc-gen-go
|
|
||||||
// which is a named int32 kind.
|
|
||||||
// This type exists for documentation purposes.
|
|
||||||
type GeneratedEnum interface{}
|
|
||||||
|
|
||||||
// GeneratedMessage is any message type generated by protoc-gen-go
|
|
||||||
// which is a pointer to a named struct kind.
|
|
||||||
// This type exists for documentation purposes.
|
|
||||||
type GeneratedMessage interface{}
|
|
||||||
|
|
||||||
// Message is a protocol buffer message.
|
|
||||||
//
|
|
||||||
// This is the v1 version of the message interface and is marginally better
|
|
||||||
// than an empty interface as it lacks any method to programatically interact
|
|
||||||
// with the contents of the message.
|
|
||||||
//
|
|
||||||
// A v2 message is declared in "google.golang.org/protobuf/proto".Message and
|
|
||||||
// exposes protobuf reflection as a first-class feature of the interface.
|
|
||||||
//
|
|
||||||
// To convert a v1 message to a v2 message, use the MessageV2 function.
|
|
||||||
// To convert a v2 message to a v1 message, use the MessageV1 function.
|
|
||||||
type Message = protoiface.MessageV1
|
|
||||||
|
|
||||||
// MessageV1 converts either a v1 or v2 message to a v1 message.
|
|
||||||
// It returns nil if m is nil.
|
|
||||||
func MessageV1(m GeneratedMessage) protoiface.MessageV1 {
|
|
||||||
return protoimpl.X.ProtoMessageV1Of(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageV2 converts either a v1 or v2 message to a v2 message.
|
|
||||||
// It returns nil if m is nil.
|
|
||||||
func MessageV2(m GeneratedMessage) protoV2.Message {
|
|
||||||
return protoimpl.X.ProtoMessageV2Of(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageReflect returns a reflective view for a message.
|
|
||||||
// It returns nil if m is nil.
|
|
||||||
func MessageReflect(m Message) protoreflect.Message {
|
|
||||||
return protoimpl.X.MessageOf(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshaler is implemented by messages that can marshal themselves.
|
|
||||||
// This interface is used by the following functions: Size, Marshal,
|
|
||||||
// Buffer.Marshal, and Buffer.EncodeMessage.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not implement.
|
|
||||||
type Marshaler interface {
|
|
||||||
// Marshal formats the encoded bytes of the message.
|
|
||||||
// It should be deterministic and emit valid protobuf wire data.
|
|
||||||
// The caller takes ownership of the returned buffer.
|
|
||||||
Marshal() ([]byte, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshaler is implemented by messages that can unmarshal themselves.
|
|
||||||
// This interface is used by the following functions: Unmarshal, UnmarshalMerge,
|
|
||||||
// Buffer.Unmarshal, Buffer.DecodeMessage, and Buffer.DecodeGroup.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not implement.
|
|
||||||
type Unmarshaler interface {
|
|
||||||
// Unmarshal parses the encoded bytes of the protobuf wire input.
|
|
||||||
// The provided buffer is only valid for during method call.
|
|
||||||
// It should not reset the receiver message.
|
|
||||||
Unmarshal([]byte) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merger is implemented by messages that can merge themselves.
|
|
||||||
// This interface is used by the following functions: Clone and Merge.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not implement.
|
|
||||||
type Merger interface {
|
|
||||||
// Merge merges the contents of src into the receiver message.
|
|
||||||
// It clones all data structures in src such that it aliases no mutable
|
|
||||||
// memory referenced by src.
|
|
||||||
Merge(src Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RequiredNotSetError is an error type returned when
|
|
||||||
// marshaling or unmarshaling a message with missing required fields.
|
|
||||||
type RequiredNotSetError struct {
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *RequiredNotSetError) Error() string {
|
|
||||||
if e.err != nil {
|
|
||||||
return e.err.Error()
|
|
||||||
}
|
|
||||||
return "proto: required field not set"
|
|
||||||
}
|
|
||||||
func (e *RequiredNotSetError) RequiredNotSet() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkRequiredNotSet(m protoV2.Message) error {
|
|
||||||
if err := protoV2.CheckInitialized(m); err != nil {
|
|
||||||
return &RequiredNotSetError{err: err}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone returns a deep copy of src.
|
|
||||||
func Clone(src Message) Message {
|
|
||||||
return MessageV1(protoV2.Clone(MessageV2(src)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge merges src into dst, which must be messages of the same type.
|
|
||||||
//
|
|
||||||
// Populated scalar fields in src are copied to dst, while populated
|
|
||||||
// singular messages in src are merged into dst by recursively calling Merge.
|
|
||||||
// The elements of every list field in src is appended to the corresponded
|
|
||||||
// list fields in dst. The entries of every map field in src is copied into
|
|
||||||
// the corresponding map field in dst, possibly replacing existing entries.
|
|
||||||
// The unknown fields of src are appended to the unknown fields of dst.
|
|
||||||
func Merge(dst, src Message) {
|
|
||||||
protoV2.Merge(MessageV2(dst), MessageV2(src))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Equal reports whether two messages are equal.
|
|
||||||
// If two messages marshal to the same bytes under deterministic serialization,
|
|
||||||
// then Equal is guaranteed to report true.
|
|
||||||
//
|
|
||||||
// Two messages are equal if they are the same protobuf message type,
|
|
||||||
// have the same set of populated known and extension field values,
|
|
||||||
// and the same set of unknown fields values.
|
|
||||||
//
|
|
||||||
// Scalar values are compared with the equivalent of the == operator in Go,
|
|
||||||
// except bytes values which are compared using bytes.Equal and
|
|
||||||
// floating point values which specially treat NaNs as equal.
|
|
||||||
// Message values are compared by recursively calling Equal.
|
|
||||||
// Lists are equal if each element value is also equal.
|
|
||||||
// Maps are equal if they have the same set of keys, where the pair of values
|
|
||||||
// for each key is also equal.
|
|
||||||
func Equal(x, y Message) bool {
|
|
||||||
return protoV2.Equal(MessageV2(x), MessageV2(y))
|
|
||||||
}
|
|
||||||
|
|
||||||
func isMessageSet(md protoreflect.MessageDescriptor) bool {
|
|
||||||
ms, ok := md.(interface{ IsMessageSet() bool })
|
|
||||||
return ok && ms.IsMessageSet()
|
|
||||||
}
|
|
||||||
323
vendor/github.com/golang/protobuf/proto/registry.go
generated
vendored
323
vendor/github.com/golang/protobuf/proto/registry.go
generated
vendored
@@ -1,323 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"compress/gzip"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
|
||||||
"google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
// filePath is the path to the proto source file.
|
|
||||||
type filePath = string // e.g., "google/protobuf/descriptor.proto"
|
|
||||||
|
|
||||||
// fileDescGZIP is the compressed contents of the encoded FileDescriptorProto.
|
|
||||||
type fileDescGZIP = []byte
|
|
||||||
|
|
||||||
var fileCache sync.Map // map[filePath]fileDescGZIP
|
|
||||||
|
|
||||||
// RegisterFile is called from generated code to register the compressed
|
|
||||||
// FileDescriptorProto with the file path for a proto source file.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalFiles.RegisterFile instead.
|
|
||||||
func RegisterFile(s filePath, d fileDescGZIP) {
|
|
||||||
// Decompress the descriptor.
|
|
||||||
zr, err := gzip.NewReader(bytes.NewReader(d))
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err))
|
|
||||||
}
|
|
||||||
b, err := ioutil.ReadAll(zr)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a protoreflect.FileDescriptor from the raw descriptor.
|
|
||||||
// Note that DescBuilder.Build automatically registers the constructed
|
|
||||||
// file descriptor with the v2 registry.
|
|
||||||
protoimpl.DescBuilder{RawDescriptor: b}.Build()
|
|
||||||
|
|
||||||
// Locally cache the raw descriptor form for the file.
|
|
||||||
fileCache.Store(s, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FileDescriptor returns the compressed FileDescriptorProto given the file path
|
|
||||||
// for a proto source file. It returns nil if not found.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalFiles.FindFileByPath instead.
|
|
||||||
func FileDescriptor(s filePath) fileDescGZIP {
|
|
||||||
if v, ok := fileCache.Load(s); ok {
|
|
||||||
return v.(fileDescGZIP)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the descriptor in the v2 registry.
|
|
||||||
var b []byte
|
|
||||||
if fd, _ := protoregistry.GlobalFiles.FindFileByPath(s); fd != nil {
|
|
||||||
if fd, ok := fd.(interface{ ProtoLegacyRawDesc() []byte }); ok {
|
|
||||||
b = fd.ProtoLegacyRawDesc()
|
|
||||||
} else {
|
|
||||||
// TODO: Use protodesc.ToFileDescriptorProto to construct
|
|
||||||
// a descriptorpb.FileDescriptorProto and marshal it.
|
|
||||||
// However, doing so causes the proto package to have a dependency
|
|
||||||
// on descriptorpb, leading to cyclic dependency issues.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Locally cache the raw descriptor form for the file.
|
|
||||||
if len(b) > 0 {
|
|
||||||
v, _ := fileCache.LoadOrStore(s, protoimpl.X.CompressGZIP(b))
|
|
||||||
return v.(fileDescGZIP)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// enumName is the name of an enum. For historical reasons, the enum name is
|
|
||||||
// neither the full Go name nor the full protobuf name of the enum.
|
|
||||||
// The name is the dot-separated combination of just the proto package that the
|
|
||||||
// enum is declared within followed by the Go type name of the generated enum.
|
|
||||||
type enumName = string // e.g., "my.proto.package.GoMessage_GoEnum"
|
|
||||||
|
|
||||||
// enumsByName maps enum values by name to their numeric counterpart.
|
|
||||||
type enumsByName = map[string]int32
|
|
||||||
|
|
||||||
// enumsByNumber maps enum values by number to their name counterpart.
|
|
||||||
type enumsByNumber = map[int32]string
|
|
||||||
|
|
||||||
var enumCache sync.Map // map[enumName]enumsByName
|
|
||||||
var numFilesCache sync.Map // map[protoreflect.FullName]int
|
|
||||||
|
|
||||||
// RegisterEnum is called from the generated code to register the mapping of
|
|
||||||
// enum value names to enum numbers for the enum identified by s.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalTypes.RegisterEnum instead.
|
|
||||||
func RegisterEnum(s enumName, _ enumsByNumber, m enumsByName) {
|
|
||||||
if _, ok := enumCache.Load(s); ok {
|
|
||||||
panic("proto: duplicate enum registered: " + s)
|
|
||||||
}
|
|
||||||
enumCache.Store(s, m)
|
|
||||||
|
|
||||||
// This does not forward registration to the v2 registry since this API
|
|
||||||
// lacks sufficient information to construct a complete v2 enum descriptor.
|
|
||||||
}
|
|
||||||
|
|
||||||
// EnumValueMap returns the mapping from enum value names to enum numbers for
|
|
||||||
// the enum of the given name. It returns nil if not found.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalTypes.FindEnumByName instead.
|
|
||||||
func EnumValueMap(s enumName) enumsByName {
|
|
||||||
if v, ok := enumCache.Load(s); ok {
|
|
||||||
return v.(enumsByName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether the cache is stale. If the number of files in the current
|
|
||||||
// package differs, then it means that some enums may have been recently
|
|
||||||
// registered upstream that we do not know about.
|
|
||||||
var protoPkg protoreflect.FullName
|
|
||||||
if i := strings.LastIndexByte(s, '.'); i >= 0 {
|
|
||||||
protoPkg = protoreflect.FullName(s[:i])
|
|
||||||
}
|
|
||||||
v, _ := numFilesCache.Load(protoPkg)
|
|
||||||
numFiles, _ := v.(int)
|
|
||||||
if protoregistry.GlobalFiles.NumFilesByPackage(protoPkg) == numFiles {
|
|
||||||
return nil // cache is up-to-date; was not found earlier
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the enum cache for all enums declared in the given proto package.
|
|
||||||
numFiles = 0
|
|
||||||
protoregistry.GlobalFiles.RangeFilesByPackage(protoPkg, func(fd protoreflect.FileDescriptor) bool {
|
|
||||||
walkEnums(fd, func(ed protoreflect.EnumDescriptor) {
|
|
||||||
name := protoimpl.X.LegacyEnumName(ed)
|
|
||||||
if _, ok := enumCache.Load(name); !ok {
|
|
||||||
m := make(enumsByName)
|
|
||||||
evs := ed.Values()
|
|
||||||
for i := evs.Len() - 1; i >= 0; i-- {
|
|
||||||
ev := evs.Get(i)
|
|
||||||
m[string(ev.Name())] = int32(ev.Number())
|
|
||||||
}
|
|
||||||
enumCache.LoadOrStore(name, m)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
numFiles++
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
numFilesCache.Store(protoPkg, numFiles)
|
|
||||||
|
|
||||||
// Check cache again for enum map.
|
|
||||||
if v, ok := enumCache.Load(s); ok {
|
|
||||||
return v.(enumsByName)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// walkEnums recursively walks all enums declared in d.
|
|
||||||
func walkEnums(d interface {
|
|
||||||
Enums() protoreflect.EnumDescriptors
|
|
||||||
Messages() protoreflect.MessageDescriptors
|
|
||||||
}, f func(protoreflect.EnumDescriptor)) {
|
|
||||||
eds := d.Enums()
|
|
||||||
for i := eds.Len() - 1; i >= 0; i-- {
|
|
||||||
f(eds.Get(i))
|
|
||||||
}
|
|
||||||
mds := d.Messages()
|
|
||||||
for i := mds.Len() - 1; i >= 0; i-- {
|
|
||||||
walkEnums(mds.Get(i), f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// messageName is the full name of protobuf message.
|
|
||||||
type messageName = string
|
|
||||||
|
|
||||||
var messageTypeCache sync.Map // map[messageName]reflect.Type
|
|
||||||
|
|
||||||
// RegisterType is called from generated code to register the message Go type
|
|
||||||
// for a message of the given name.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalTypes.RegisterMessage instead.
|
|
||||||
func RegisterType(m Message, s messageName) {
|
|
||||||
mt := protoimpl.X.LegacyMessageTypeOf(m, protoreflect.FullName(s))
|
|
||||||
if err := protoregistry.GlobalTypes.RegisterMessage(mt); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
messageTypeCache.Store(s, reflect.TypeOf(m))
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterMapType is called from generated code to register the Go map type
|
|
||||||
// for a protobuf message representing a map entry.
|
|
||||||
//
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
func RegisterMapType(m interface{}, s messageName) {
|
|
||||||
t := reflect.TypeOf(m)
|
|
||||||
if t.Kind() != reflect.Map {
|
|
||||||
panic(fmt.Sprintf("invalid map kind: %v", t))
|
|
||||||
}
|
|
||||||
if _, ok := messageTypeCache.Load(s); ok {
|
|
||||||
panic(fmt.Errorf("proto: duplicate proto message registered: %s", s))
|
|
||||||
}
|
|
||||||
messageTypeCache.Store(s, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageType returns the message type for a named message.
|
|
||||||
// It returns nil if not found.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalTypes.FindMessageByName instead.
|
|
||||||
func MessageType(s messageName) reflect.Type {
|
|
||||||
if v, ok := messageTypeCache.Load(s); ok {
|
|
||||||
return v.(reflect.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Derive the message type from the v2 registry.
|
|
||||||
var t reflect.Type
|
|
||||||
if mt, _ := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(s)); mt != nil {
|
|
||||||
t = messageGoType(mt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we could not get a concrete type, it is possible that it is a
|
|
||||||
// pseudo-message for a map entry.
|
|
||||||
if t == nil {
|
|
||||||
d, _ := protoregistry.GlobalFiles.FindDescriptorByName(protoreflect.FullName(s))
|
|
||||||
if md, _ := d.(protoreflect.MessageDescriptor); md != nil && md.IsMapEntry() {
|
|
||||||
kt := goTypeForField(md.Fields().ByNumber(1))
|
|
||||||
vt := goTypeForField(md.Fields().ByNumber(2))
|
|
||||||
t = reflect.MapOf(kt, vt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Locally cache the message type for the given name.
|
|
||||||
if t != nil {
|
|
||||||
v, _ := messageTypeCache.LoadOrStore(s, t)
|
|
||||||
return v.(reflect.Type)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func goTypeForField(fd protoreflect.FieldDescriptor) reflect.Type {
|
|
||||||
switch k := fd.Kind(); k {
|
|
||||||
case protoreflect.EnumKind:
|
|
||||||
if et, _ := protoregistry.GlobalTypes.FindEnumByName(fd.Enum().FullName()); et != nil {
|
|
||||||
return enumGoType(et)
|
|
||||||
}
|
|
||||||
return reflect.TypeOf(protoreflect.EnumNumber(0))
|
|
||||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
|
||||||
if mt, _ := protoregistry.GlobalTypes.FindMessageByName(fd.Message().FullName()); mt != nil {
|
|
||||||
return messageGoType(mt)
|
|
||||||
}
|
|
||||||
return reflect.TypeOf((*protoreflect.Message)(nil)).Elem()
|
|
||||||
default:
|
|
||||||
return reflect.TypeOf(fd.Default().Interface())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func enumGoType(et protoreflect.EnumType) reflect.Type {
|
|
||||||
return reflect.TypeOf(et.New(0))
|
|
||||||
}
|
|
||||||
|
|
||||||
func messageGoType(mt protoreflect.MessageType) reflect.Type {
|
|
||||||
return reflect.TypeOf(MessageV1(mt.Zero().Interface()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageName returns the full protobuf name for the given message type.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoreflect.MessageDescriptor.FullName instead.
|
|
||||||
func MessageName(m Message) messageName {
|
|
||||||
if m == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if m, ok := m.(interface{ XXX_MessageName() messageName }); ok {
|
|
||||||
return m.XXX_MessageName()
|
|
||||||
}
|
|
||||||
return messageName(protoimpl.X.MessageDescriptorOf(m).FullName())
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterExtension is called from the generated code to register
|
|
||||||
// the extension descriptor.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalTypes.RegisterExtension instead.
|
|
||||||
func RegisterExtension(d *ExtensionDesc) {
|
|
||||||
if err := protoregistry.GlobalTypes.RegisterExtension(d); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type extensionsByNumber = map[int32]*ExtensionDesc
|
|
||||||
|
|
||||||
var extensionCache sync.Map // map[messageName]extensionsByNumber
|
|
||||||
|
|
||||||
// RegisteredExtensions returns a map of the registered extensions for the
|
|
||||||
// provided protobuf message, indexed by the extension field number.
|
|
||||||
//
|
|
||||||
// Deprecated: Use protoregistry.GlobalTypes.RangeExtensionsByMessage instead.
|
|
||||||
func RegisteredExtensions(m Message) extensionsByNumber {
|
|
||||||
// Check whether the cache is stale. If the number of extensions for
|
|
||||||
// the given message differs, then it means that some extensions were
|
|
||||||
// recently registered upstream that we do not know about.
|
|
||||||
s := MessageName(m)
|
|
||||||
v, _ := extensionCache.Load(s)
|
|
||||||
xs, _ := v.(extensionsByNumber)
|
|
||||||
if protoregistry.GlobalTypes.NumExtensionsByMessage(protoreflect.FullName(s)) == len(xs) {
|
|
||||||
return xs // cache is up-to-date
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cache is stale, re-compute the extensions map.
|
|
||||||
xs = make(extensionsByNumber)
|
|
||||||
protoregistry.GlobalTypes.RangeExtensionsByMessage(protoreflect.FullName(s), func(xt protoreflect.ExtensionType) bool {
|
|
||||||
if xd, ok := xt.(*ExtensionDesc); ok {
|
|
||||||
xs[int32(xt.TypeDescriptor().Number())] = xd
|
|
||||||
} else {
|
|
||||||
// TODO: This implies that the protoreflect.ExtensionType is a
|
|
||||||
// custom type not generated by protoc-gen-go. We could try and
|
|
||||||
// convert the type to an ExtensionDesc.
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
extensionCache.Store(s, xs)
|
|
||||||
return xs
|
|
||||||
}
|
|
||||||
801
vendor/github.com/golang/protobuf/proto/text_decode.go
generated
vendored
801
vendor/github.com/golang/protobuf/proto/text_decode.go
generated
vendored
@@ -1,801 +0,0 @@
|
|||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/encoding/prototext"
|
|
||||||
protoV2 "google.golang.org/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
|
||||||
)
|
|
||||||
|
|
||||||
const wrapTextUnmarshalV2 = false
|
|
||||||
|
|
||||||
// ParseError is returned by UnmarshalText.
|
|
||||||
type ParseError struct {
|
|
||||||
Message string
|
|
||||||
|
|
||||||
// Deprecated: Do not use.
|
|
||||||
Line, Offset int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *ParseError) Error() string {
|
|
||||||
if wrapTextUnmarshalV2 {
|
|
||||||
return e.Message
|
|
||||||
}
|
|
||||||
if e.Line == 1 {
|
|
||||||
return fmt.Sprintf("line 1.%d: %v", e.Offset, e.Message)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("line %d: %v", e.Line, e.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalText parses a proto text formatted string into m.
|
|
||||||
func UnmarshalText(s string, m Message) error {
|
|
||||||
if u, ok := m.(encoding.TextUnmarshaler); ok {
|
|
||||||
return u.UnmarshalText([]byte(s))
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Reset()
|
|
||||||
mi := MessageV2(m)
|
|
||||||
|
|
||||||
if wrapTextUnmarshalV2 {
|
|
||||||
err := prototext.UnmarshalOptions{
|
|
||||||
AllowPartial: true,
|
|
||||||
}.Unmarshal([]byte(s), mi)
|
|
||||||
if err != nil {
|
|
||||||
return &ParseError{Message: err.Error()}
|
|
||||||
}
|
|
||||||
return checkRequiredNotSet(mi)
|
|
||||||
} else {
|
|
||||||
if err := newTextParser(s).unmarshalMessage(mi.ProtoReflect(), ""); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return checkRequiredNotSet(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type textParser struct {
|
|
||||||
s string // remaining input
|
|
||||||
done bool // whether the parsing is finished (success or error)
|
|
||||||
backed bool // whether back() was called
|
|
||||||
offset, line int
|
|
||||||
cur token
|
|
||||||
}
|
|
||||||
|
|
||||||
type token struct {
|
|
||||||
value string
|
|
||||||
err *ParseError
|
|
||||||
line int // line number
|
|
||||||
offset int // byte number from start of input, not start of line
|
|
||||||
unquoted string // the unquoted version of value, if it was a quoted string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTextParser(s string) *textParser {
|
|
||||||
p := new(textParser)
|
|
||||||
p.s = s
|
|
||||||
p.line = 1
|
|
||||||
p.cur.line = 1
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) unmarshalMessage(m protoreflect.Message, terminator string) (err error) {
|
|
||||||
md := m.Descriptor()
|
|
||||||
fds := md.Fields()
|
|
||||||
|
|
||||||
// A struct is a sequence of "name: value", terminated by one of
|
|
||||||
// '>' or '}', or the end of the input. A name may also be
|
|
||||||
// "[extension]" or "[type/url]".
|
|
||||||
//
|
|
||||||
// The whole struct can also be an expanded Any message, like:
|
|
||||||
// [type/url] < ... struct contents ... >
|
|
||||||
seen := make(map[protoreflect.FieldNumber]bool)
|
|
||||||
for {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return tok.err
|
|
||||||
}
|
|
||||||
if tok.value == terminator {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if tok.value == "[" {
|
|
||||||
if err := p.unmarshalExtensionOrAny(m, seen); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a normal, non-extension field.
|
|
||||||
name := protoreflect.Name(tok.value)
|
|
||||||
fd := fds.ByName(name)
|
|
||||||
switch {
|
|
||||||
case fd == nil:
|
|
||||||
gd := fds.ByName(protoreflect.Name(strings.ToLower(string(name))))
|
|
||||||
if gd != nil && gd.Kind() == protoreflect.GroupKind && gd.Message().Name() == name {
|
|
||||||
fd = gd
|
|
||||||
}
|
|
||||||
case fd.Kind() == protoreflect.GroupKind && fd.Message().Name() != name:
|
|
||||||
fd = nil
|
|
||||||
case fd.IsWeak() && fd.Message().IsPlaceholder():
|
|
||||||
fd = nil
|
|
||||||
}
|
|
||||||
if fd == nil {
|
|
||||||
typeName := string(md.FullName())
|
|
||||||
if m, ok := m.Interface().(Message); ok {
|
|
||||||
t := reflect.TypeOf(m)
|
|
||||||
if t.Kind() == reflect.Ptr {
|
|
||||||
typeName = t.Elem().String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return p.errorf("unknown field name %q in %v", name, typeName)
|
|
||||||
}
|
|
||||||
if od := fd.ContainingOneof(); od != nil && m.WhichOneof(od) != nil {
|
|
||||||
return p.errorf("field '%s' would overwrite already parsed oneof '%s'", name, od.Name())
|
|
||||||
}
|
|
||||||
if fd.Cardinality() != protoreflect.Repeated && seen[fd.Number()] {
|
|
||||||
return p.errorf("non-repeated field %q was repeated", fd.Name())
|
|
||||||
}
|
|
||||||
seen[fd.Number()] = true
|
|
||||||
|
|
||||||
// Consume any colon.
|
|
||||||
if err := p.checkForColon(fd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse into the field.
|
|
||||||
v := m.Get(fd)
|
|
||||||
if !m.Has(fd) && (fd.IsList() || fd.IsMap() || fd.Message() != nil) {
|
|
||||||
v = m.Mutable(fd)
|
|
||||||
}
|
|
||||||
if v, err = p.unmarshalValue(v, fd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.Set(fd, v)
|
|
||||||
|
|
||||||
if err := p.consumeOptionalSeparator(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) unmarshalExtensionOrAny(m protoreflect.Message, seen map[protoreflect.FieldNumber]bool) error {
|
|
||||||
name, err := p.consumeExtensionOrAnyName()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it contains a slash, it's an Any type URL.
|
|
||||||
if slashIdx := strings.LastIndex(name, "/"); slashIdx >= 0 {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return tok.err
|
|
||||||
}
|
|
||||||
// consume an optional colon
|
|
||||||
if tok.value == ":" {
|
|
||||||
tok = p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return tok.err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var terminator string
|
|
||||||
switch tok.value {
|
|
||||||
case "<":
|
|
||||||
terminator = ">"
|
|
||||||
case "{":
|
|
||||||
terminator = "}"
|
|
||||||
default:
|
|
||||||
return p.errorf("expected '{' or '<', found %q", tok.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
mt, err := protoregistry.GlobalTypes.FindMessageByURL(name)
|
|
||||||
if err != nil {
|
|
||||||
return p.errorf("unrecognized message %q in google.protobuf.Any", name[slashIdx+len("/"):])
|
|
||||||
}
|
|
||||||
m2 := mt.New()
|
|
||||||
if err := p.unmarshalMessage(m2, terminator); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b, err := protoV2.Marshal(m2.Interface())
|
|
||||||
if err != nil {
|
|
||||||
return p.errorf("failed to marshal message of type %q: %v", name[slashIdx+len("/"):], err)
|
|
||||||
}
|
|
||||||
|
|
||||||
urlFD := m.Descriptor().Fields().ByName("type_url")
|
|
||||||
valFD := m.Descriptor().Fields().ByName("value")
|
|
||||||
if seen[urlFD.Number()] {
|
|
||||||
return p.errorf("Any message unpacked multiple times, or %q already set", urlFD.Name())
|
|
||||||
}
|
|
||||||
if seen[valFD.Number()] {
|
|
||||||
return p.errorf("Any message unpacked multiple times, or %q already set", valFD.Name())
|
|
||||||
}
|
|
||||||
m.Set(urlFD, protoreflect.ValueOfString(name))
|
|
||||||
m.Set(valFD, protoreflect.ValueOfBytes(b))
|
|
||||||
seen[urlFD.Number()] = true
|
|
||||||
seen[valFD.Number()] = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
xname := protoreflect.FullName(name)
|
|
||||||
xt, _ := protoregistry.GlobalTypes.FindExtensionByName(xname)
|
|
||||||
if xt == nil && isMessageSet(m.Descriptor()) {
|
|
||||||
xt, _ = protoregistry.GlobalTypes.FindExtensionByName(xname.Append("message_set_extension"))
|
|
||||||
}
|
|
||||||
if xt == nil {
|
|
||||||
return p.errorf("unrecognized extension %q", name)
|
|
||||||
}
|
|
||||||
fd := xt.TypeDescriptor()
|
|
||||||
if fd.ContainingMessage().FullName() != m.Descriptor().FullName() {
|
|
||||||
return p.errorf("extension field %q does not extend message %q", name, m.Descriptor().FullName())
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := p.checkForColon(fd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v := m.Get(fd)
|
|
||||||
if !m.Has(fd) && (fd.IsList() || fd.IsMap() || fd.Message() != nil) {
|
|
||||||
v = m.Mutable(fd)
|
|
||||||
}
|
|
||||||
v, err = p.unmarshalValue(v, fd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
m.Set(fd, v)
|
|
||||||
return p.consumeOptionalSeparator()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) unmarshalValue(v protoreflect.Value, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return v, tok.err
|
|
||||||
}
|
|
||||||
if tok.value == "" {
|
|
||||||
return v, p.errorf("unexpected EOF")
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case fd.IsList():
|
|
||||||
lv := v.List()
|
|
||||||
var err error
|
|
||||||
if tok.value == "[" {
|
|
||||||
// Repeated field with list notation, like [1,2,3].
|
|
||||||
for {
|
|
||||||
vv := lv.NewElement()
|
|
||||||
vv, err = p.unmarshalSingularValue(vv, fd)
|
|
||||||
if err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
lv.Append(vv)
|
|
||||||
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return v, tok.err
|
|
||||||
}
|
|
||||||
if tok.value == "]" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if tok.value != "," {
|
|
||||||
return v, p.errorf("Expected ']' or ',' found %q", tok.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// One value of the repeated field.
|
|
||||||
p.back()
|
|
||||||
vv := lv.NewElement()
|
|
||||||
vv, err = p.unmarshalSingularValue(vv, fd)
|
|
||||||
if err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
lv.Append(vv)
|
|
||||||
return v, nil
|
|
||||||
case fd.IsMap():
|
|
||||||
// The map entry should be this sequence of tokens:
|
|
||||||
// < key : KEY value : VALUE >
|
|
||||||
// However, implementations may omit key or value, and technically
|
|
||||||
// we should support them in any order.
|
|
||||||
var terminator string
|
|
||||||
switch tok.value {
|
|
||||||
case "<":
|
|
||||||
terminator = ">"
|
|
||||||
case "{":
|
|
||||||
terminator = "}"
|
|
||||||
default:
|
|
||||||
return v, p.errorf("expected '{' or '<', found %q", tok.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
keyFD := fd.MapKey()
|
|
||||||
valFD := fd.MapValue()
|
|
||||||
|
|
||||||
mv := v.Map()
|
|
||||||
kv := keyFD.Default()
|
|
||||||
vv := mv.NewValue()
|
|
||||||
for {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return v, tok.err
|
|
||||||
}
|
|
||||||
if tok.value == terminator {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
var err error
|
|
||||||
switch tok.value {
|
|
||||||
case "key":
|
|
||||||
if err := p.consumeToken(":"); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
if kv, err = p.unmarshalSingularValue(kv, keyFD); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
if err := p.consumeOptionalSeparator(); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
case "value":
|
|
||||||
if err := p.checkForColon(valFD); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
if vv, err = p.unmarshalSingularValue(vv, valFD); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
if err := p.consumeOptionalSeparator(); err != nil {
|
|
||||||
return v, err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
p.back()
|
|
||||||
return v, p.errorf(`expected "key", "value", or %q, found %q`, terminator, tok.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mv.Set(kv.MapKey(), vv)
|
|
||||||
return v, nil
|
|
||||||
default:
|
|
||||||
p.back()
|
|
||||||
return p.unmarshalSingularValue(v, fd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) unmarshalSingularValue(v protoreflect.Value, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return v, tok.err
|
|
||||||
}
|
|
||||||
if tok.value == "" {
|
|
||||||
return v, p.errorf("unexpected EOF")
|
|
||||||
}
|
|
||||||
|
|
||||||
switch fd.Kind() {
|
|
||||||
case protoreflect.BoolKind:
|
|
||||||
switch tok.value {
|
|
||||||
case "true", "1", "t", "True":
|
|
||||||
return protoreflect.ValueOfBool(true), nil
|
|
||||||
case "false", "0", "f", "False":
|
|
||||||
return protoreflect.ValueOfBool(false), nil
|
|
||||||
}
|
|
||||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
|
||||||
if x, err := strconv.ParseInt(tok.value, 0, 32); err == nil {
|
|
||||||
return protoreflect.ValueOfInt32(int32(x)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// The C++ parser accepts large positive hex numbers that uses
|
|
||||||
// two's complement arithmetic to represent negative numbers.
|
|
||||||
// This feature is here for backwards compatibility with C++.
|
|
||||||
if strings.HasPrefix(tok.value, "0x") {
|
|
||||||
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
|
|
||||||
return protoreflect.ValueOfInt32(int32(-(int64(^x) + 1))), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
|
||||||
if x, err := strconv.ParseInt(tok.value, 0, 64); err == nil {
|
|
||||||
return protoreflect.ValueOfInt64(int64(x)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// The C++ parser accepts large positive hex numbers that uses
|
|
||||||
// two's complement arithmetic to represent negative numbers.
|
|
||||||
// This feature is here for backwards compatibility with C++.
|
|
||||||
if strings.HasPrefix(tok.value, "0x") {
|
|
||||||
if x, err := strconv.ParseUint(tok.value, 0, 64); err == nil {
|
|
||||||
return protoreflect.ValueOfInt64(int64(-(int64(^x) + 1))), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
|
||||||
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
|
|
||||||
return protoreflect.ValueOfUint32(uint32(x)), nil
|
|
||||||
}
|
|
||||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
|
||||||
if x, err := strconv.ParseUint(tok.value, 0, 64); err == nil {
|
|
||||||
return protoreflect.ValueOfUint64(uint64(x)), nil
|
|
||||||
}
|
|
||||||
case protoreflect.FloatKind:
|
|
||||||
// Ignore 'f' for compatibility with output generated by C++,
|
|
||||||
// but don't remove 'f' when the value is "-inf" or "inf".
|
|
||||||
v := tok.value
|
|
||||||
if strings.HasSuffix(v, "f") && v != "-inf" && v != "inf" {
|
|
||||||
v = v[:len(v)-len("f")]
|
|
||||||
}
|
|
||||||
if x, err := strconv.ParseFloat(v, 32); err == nil {
|
|
||||||
return protoreflect.ValueOfFloat32(float32(x)), nil
|
|
||||||
}
|
|
||||||
case protoreflect.DoubleKind:
|
|
||||||
// Ignore 'f' for compatibility with output generated by C++,
|
|
||||||
// but don't remove 'f' when the value is "-inf" or "inf".
|
|
||||||
v := tok.value
|
|
||||||
if strings.HasSuffix(v, "f") && v != "-inf" && v != "inf" {
|
|
||||||
v = v[:len(v)-len("f")]
|
|
||||||
}
|
|
||||||
if x, err := strconv.ParseFloat(v, 64); err == nil {
|
|
||||||
return protoreflect.ValueOfFloat64(float64(x)), nil
|
|
||||||
}
|
|
||||||
case protoreflect.StringKind:
|
|
||||||
if isQuote(tok.value[0]) {
|
|
||||||
return protoreflect.ValueOfString(tok.unquoted), nil
|
|
||||||
}
|
|
||||||
case protoreflect.BytesKind:
|
|
||||||
if isQuote(tok.value[0]) {
|
|
||||||
return protoreflect.ValueOfBytes([]byte(tok.unquoted)), nil
|
|
||||||
}
|
|
||||||
case protoreflect.EnumKind:
|
|
||||||
if x, err := strconv.ParseInt(tok.value, 0, 32); err == nil {
|
|
||||||
return protoreflect.ValueOfEnum(protoreflect.EnumNumber(x)), nil
|
|
||||||
}
|
|
||||||
vd := fd.Enum().Values().ByName(protoreflect.Name(tok.value))
|
|
||||||
if vd != nil {
|
|
||||||
return protoreflect.ValueOfEnum(vd.Number()), nil
|
|
||||||
}
|
|
||||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
|
||||||
var terminator string
|
|
||||||
switch tok.value {
|
|
||||||
case "{":
|
|
||||||
terminator = "}"
|
|
||||||
case "<":
|
|
||||||
terminator = ">"
|
|
||||||
default:
|
|
||||||
return v, p.errorf("expected '{' or '<', found %q", tok.value)
|
|
||||||
}
|
|
||||||
err := p.unmarshalMessage(v.Message(), terminator)
|
|
||||||
return v, err
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("invalid kind %v", fd.Kind()))
|
|
||||||
}
|
|
||||||
return v, p.errorf("invalid %v: %v", fd.Kind(), tok.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consume a ':' from the input stream (if the next token is a colon),
|
|
||||||
// returning an error if a colon is needed but not present.
|
|
||||||
func (p *textParser) checkForColon(fd protoreflect.FieldDescriptor) *ParseError {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return tok.err
|
|
||||||
}
|
|
||||||
if tok.value != ":" {
|
|
||||||
if fd.Message() == nil {
|
|
||||||
return p.errorf("expected ':', found %q", tok.value)
|
|
||||||
}
|
|
||||||
p.back()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// consumeExtensionOrAnyName consumes an extension name or an Any type URL and
|
|
||||||
// the following ']'. It returns the name or URL consumed.
|
|
||||||
func (p *textParser) consumeExtensionOrAnyName() (string, error) {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return "", tok.err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If extension name or type url is quoted, it's a single token.
|
|
||||||
if len(tok.value) > 2 && isQuote(tok.value[0]) && tok.value[len(tok.value)-1] == tok.value[0] {
|
|
||||||
name, err := unquoteC(tok.value[1:len(tok.value)-1], rune(tok.value[0]))
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return name, p.consumeToken("]")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consume everything up to "]"
|
|
||||||
var parts []string
|
|
||||||
for tok.value != "]" {
|
|
||||||
parts = append(parts, tok.value)
|
|
||||||
tok = p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return "", p.errorf("unrecognized type_url or extension name: %s", tok.err)
|
|
||||||
}
|
|
||||||
if p.done && tok.value != "]" {
|
|
||||||
return "", p.errorf("unclosed type_url or extension name")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings.Join(parts, ""), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// consumeOptionalSeparator consumes an optional semicolon or comma.
|
|
||||||
// It is used in unmarshalMessage to provide backward compatibility.
|
|
||||||
func (p *textParser) consumeOptionalSeparator() error {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return tok.err
|
|
||||||
}
|
|
||||||
if tok.value != ";" && tok.value != "," {
|
|
||||||
p.back()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) errorf(format string, a ...interface{}) *ParseError {
|
|
||||||
pe := &ParseError{fmt.Sprintf(format, a...), p.cur.line, p.cur.offset}
|
|
||||||
p.cur.err = pe
|
|
||||||
p.done = true
|
|
||||||
return pe
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) skipWhitespace() {
|
|
||||||
i := 0
|
|
||||||
for i < len(p.s) && (isWhitespace(p.s[i]) || p.s[i] == '#') {
|
|
||||||
if p.s[i] == '#' {
|
|
||||||
// comment; skip to end of line or input
|
|
||||||
for i < len(p.s) && p.s[i] != '\n' {
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
if i == len(p.s) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if p.s[i] == '\n' {
|
|
||||||
p.line++
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
p.offset += i
|
|
||||||
p.s = p.s[i:len(p.s)]
|
|
||||||
if len(p.s) == 0 {
|
|
||||||
p.done = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) advance() {
|
|
||||||
// Skip whitespace
|
|
||||||
p.skipWhitespace()
|
|
||||||
if p.done {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start of non-whitespace
|
|
||||||
p.cur.err = nil
|
|
||||||
p.cur.offset, p.cur.line = p.offset, p.line
|
|
||||||
p.cur.unquoted = ""
|
|
||||||
switch p.s[0] {
|
|
||||||
case '<', '>', '{', '}', ':', '[', ']', ';', ',', '/':
|
|
||||||
// Single symbol
|
|
||||||
p.cur.value, p.s = p.s[0:1], p.s[1:len(p.s)]
|
|
||||||
case '"', '\'':
|
|
||||||
// Quoted string
|
|
||||||
i := 1
|
|
||||||
for i < len(p.s) && p.s[i] != p.s[0] && p.s[i] != '\n' {
|
|
||||||
if p.s[i] == '\\' && i+1 < len(p.s) {
|
|
||||||
// skip escaped char
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
if i >= len(p.s) || p.s[i] != p.s[0] {
|
|
||||||
p.errorf("unmatched quote")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
unq, err := unquoteC(p.s[1:i], rune(p.s[0]))
|
|
||||||
if err != nil {
|
|
||||||
p.errorf("invalid quoted string %s: %v", p.s[0:i+1], err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.cur.value, p.s = p.s[0:i+1], p.s[i+1:len(p.s)]
|
|
||||||
p.cur.unquoted = unq
|
|
||||||
default:
|
|
||||||
i := 0
|
|
||||||
for i < len(p.s) && isIdentOrNumberChar(p.s[i]) {
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
if i == 0 {
|
|
||||||
p.errorf("unexpected byte %#x", p.s[0])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.cur.value, p.s = p.s[0:i], p.s[i:len(p.s)]
|
|
||||||
}
|
|
||||||
p.offset += len(p.cur.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Back off the parser by one token. Can only be done between calls to next().
|
|
||||||
// It makes the next advance() a no-op.
|
|
||||||
func (p *textParser) back() { p.backed = true }
|
|
||||||
|
|
||||||
// Advances the parser and returns the new current token.
|
|
||||||
func (p *textParser) next() *token {
|
|
||||||
if p.backed || p.done {
|
|
||||||
p.backed = false
|
|
||||||
return &p.cur
|
|
||||||
}
|
|
||||||
p.advance()
|
|
||||||
if p.done {
|
|
||||||
p.cur.value = ""
|
|
||||||
} else if len(p.cur.value) > 0 && isQuote(p.cur.value[0]) {
|
|
||||||
// Look for multiple quoted strings separated by whitespace,
|
|
||||||
// and concatenate them.
|
|
||||||
cat := p.cur
|
|
||||||
for {
|
|
||||||
p.skipWhitespace()
|
|
||||||
if p.done || !isQuote(p.s[0]) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
p.advance()
|
|
||||||
if p.cur.err != nil {
|
|
||||||
return &p.cur
|
|
||||||
}
|
|
||||||
cat.value += " " + p.cur.value
|
|
||||||
cat.unquoted += p.cur.unquoted
|
|
||||||
}
|
|
||||||
p.done = false // parser may have seen EOF, but we want to return cat
|
|
||||||
p.cur = cat
|
|
||||||
}
|
|
||||||
return &p.cur
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *textParser) consumeToken(s string) error {
|
|
||||||
tok := p.next()
|
|
||||||
if tok.err != nil {
|
|
||||||
return tok.err
|
|
||||||
}
|
|
||||||
if tok.value != s {
|
|
||||||
p.back()
|
|
||||||
return p.errorf("expected %q, found %q", s, tok.value)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var errBadUTF8 = errors.New("proto: bad UTF-8")
|
|
||||||
|
|
||||||
func unquoteC(s string, quote rune) (string, error) {
|
|
||||||
// This is based on C++'s tokenizer.cc.
|
|
||||||
// Despite its name, this is *not* parsing C syntax.
|
|
||||||
// For instance, "\0" is an invalid quoted string.
|
|
||||||
|
|
||||||
// Avoid allocation in trivial cases.
|
|
||||||
simple := true
|
|
||||||
for _, r := range s {
|
|
||||||
if r == '\\' || r == quote {
|
|
||||||
simple = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if simple {
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := make([]byte, 0, 3*len(s)/2)
|
|
||||||
for len(s) > 0 {
|
|
||||||
r, n := utf8.DecodeRuneInString(s)
|
|
||||||
if r == utf8.RuneError && n == 1 {
|
|
||||||
return "", errBadUTF8
|
|
||||||
}
|
|
||||||
s = s[n:]
|
|
||||||
if r != '\\' {
|
|
||||||
if r < utf8.RuneSelf {
|
|
||||||
buf = append(buf, byte(r))
|
|
||||||
} else {
|
|
||||||
buf = append(buf, string(r)...)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
ch, tail, err := unescape(s)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
buf = append(buf, ch...)
|
|
||||||
s = tail
|
|
||||||
}
|
|
||||||
return string(buf), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func unescape(s string) (ch string, tail string, err error) {
|
|
||||||
r, n := utf8.DecodeRuneInString(s)
|
|
||||||
if r == utf8.RuneError && n == 1 {
|
|
||||||
return "", "", errBadUTF8
|
|
||||||
}
|
|
||||||
s = s[n:]
|
|
||||||
switch r {
|
|
||||||
case 'a':
|
|
||||||
return "\a", s, nil
|
|
||||||
case 'b':
|
|
||||||
return "\b", s, nil
|
|
||||||
case 'f':
|
|
||||||
return "\f", s, nil
|
|
||||||
case 'n':
|
|
||||||
return "\n", s, nil
|
|
||||||
case 'r':
|
|
||||||
return "\r", s, nil
|
|
||||||
case 't':
|
|
||||||
return "\t", s, nil
|
|
||||||
case 'v':
|
|
||||||
return "\v", s, nil
|
|
||||||
case '?':
|
|
||||||
return "?", s, nil // trigraph workaround
|
|
||||||
case '\'', '"', '\\':
|
|
||||||
return string(r), s, nil
|
|
||||||
case '0', '1', '2', '3', '4', '5', '6', '7':
|
|
||||||
if len(s) < 2 {
|
|
||||||
return "", "", fmt.Errorf(`\%c requires 2 following digits`, r)
|
|
||||||
}
|
|
||||||
ss := string(r) + s[:2]
|
|
||||||
s = s[2:]
|
|
||||||
i, err := strconv.ParseUint(ss, 8, 8)
|
|
||||||
if err != nil {
|
|
||||||
return "", "", fmt.Errorf(`\%s contains non-octal digits`, ss)
|
|
||||||
}
|
|
||||||
return string([]byte{byte(i)}), s, nil
|
|
||||||
case 'x', 'X', 'u', 'U':
|
|
||||||
var n int
|
|
||||||
switch r {
|
|
||||||
case 'x', 'X':
|
|
||||||
n = 2
|
|
||||||
case 'u':
|
|
||||||
n = 4
|
|
||||||
case 'U':
|
|
||||||
n = 8
|
|
||||||
}
|
|
||||||
if len(s) < n {
|
|
||||||
return "", "", fmt.Errorf(`\%c requires %d following digits`, r, n)
|
|
||||||
}
|
|
||||||
ss := s[:n]
|
|
||||||
s = s[n:]
|
|
||||||
i, err := strconv.ParseUint(ss, 16, 64)
|
|
||||||
if err != nil {
|
|
||||||
return "", "", fmt.Errorf(`\%c%s contains non-hexadecimal digits`, r, ss)
|
|
||||||
}
|
|
||||||
if r == 'x' || r == 'X' {
|
|
||||||
return string([]byte{byte(i)}), s, nil
|
|
||||||
}
|
|
||||||
if i > utf8.MaxRune {
|
|
||||||
return "", "", fmt.Errorf(`\%c%s is not a valid Unicode code point`, r, ss)
|
|
||||||
}
|
|
||||||
return string(rune(i)), s, nil
|
|
||||||
}
|
|
||||||
return "", "", fmt.Errorf(`unknown escape \%c`, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isIdentOrNumberChar(c byte) bool {
|
|
||||||
switch {
|
|
||||||
case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z':
|
|
||||||
return true
|
|
||||||
case '0' <= c && c <= '9':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
switch c {
|
|
||||||
case '-', '+', '.', '_':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isWhitespace(c byte) bool {
|
|
||||||
switch c {
|
|
||||||
case ' ', '\t', '\n', '\r':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isQuote(c byte) bool {
|
|
||||||
switch c {
|
|
||||||
case '"', '\'':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
560
vendor/github.com/golang/protobuf/proto/text_encode.go
generated
vendored
560
vendor/github.com/golang/protobuf/proto/text_encode.go
generated
vendored
@@ -1,560 +0,0 @@
|
|||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/encoding/prototext"
|
|
||||||
"google.golang.org/protobuf/encoding/protowire"
|
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
|
||||||
)
|
|
||||||
|
|
||||||
const wrapTextMarshalV2 = false
|
|
||||||
|
|
||||||
// TextMarshaler is a configurable text format marshaler.
|
|
||||||
type TextMarshaler struct {
|
|
||||||
Compact bool // use compact text format (one line)
|
|
||||||
ExpandAny bool // expand google.protobuf.Any messages of known types
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal writes the proto text format of m to w.
|
|
||||||
func (tm *TextMarshaler) Marshal(w io.Writer, m Message) error {
|
|
||||||
b, err := tm.marshal(m)
|
|
||||||
if len(b) > 0 {
|
|
||||||
if _, err := w.Write(b); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Text returns a proto text formatted string of m.
|
|
||||||
func (tm *TextMarshaler) Text(m Message) string {
|
|
||||||
b, _ := tm.marshal(m)
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tm *TextMarshaler) marshal(m Message) ([]byte, error) {
|
|
||||||
mr := MessageReflect(m)
|
|
||||||
if mr == nil || !mr.IsValid() {
|
|
||||||
return []byte("<nil>"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if wrapTextMarshalV2 {
|
|
||||||
if m, ok := m.(encoding.TextMarshaler); ok {
|
|
||||||
return m.MarshalText()
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := prototext.MarshalOptions{
|
|
||||||
AllowPartial: true,
|
|
||||||
EmitUnknown: true,
|
|
||||||
}
|
|
||||||
if !tm.Compact {
|
|
||||||
opts.Indent = " "
|
|
||||||
}
|
|
||||||
if !tm.ExpandAny {
|
|
||||||
opts.Resolver = (*protoregistry.Types)(nil)
|
|
||||||
}
|
|
||||||
return opts.Marshal(mr.Interface())
|
|
||||||
} else {
|
|
||||||
w := &textWriter{
|
|
||||||
compact: tm.Compact,
|
|
||||||
expandAny: tm.ExpandAny,
|
|
||||||
complete: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if m, ok := m.(encoding.TextMarshaler); ok {
|
|
||||||
b, err := m.MarshalText()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
w.Write(b)
|
|
||||||
return w.buf, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err := w.writeMessage(mr)
|
|
||||||
return w.buf, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
defaultTextMarshaler = TextMarshaler{}
|
|
||||||
compactTextMarshaler = TextMarshaler{Compact: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
// MarshalText writes the proto text format of m to w.
|
|
||||||
func MarshalText(w io.Writer, m Message) error { return defaultTextMarshaler.Marshal(w, m) }
|
|
||||||
|
|
||||||
// MarshalTextString returns a proto text formatted string of m.
|
|
||||||
func MarshalTextString(m Message) string { return defaultTextMarshaler.Text(m) }
|
|
||||||
|
|
||||||
// CompactText writes the compact proto text format of m to w.
|
|
||||||
func CompactText(w io.Writer, m Message) error { return compactTextMarshaler.Marshal(w, m) }
|
|
||||||
|
|
||||||
// CompactTextString returns a compact proto text formatted string of m.
|
|
||||||
func CompactTextString(m Message) string { return compactTextMarshaler.Text(m) }
|
|
||||||
|
|
||||||
var (
|
|
||||||
newline = []byte("\n")
|
|
||||||
endBraceNewline = []byte("}\n")
|
|
||||||
posInf = []byte("inf")
|
|
||||||
negInf = []byte("-inf")
|
|
||||||
nan = []byte("nan")
|
|
||||||
)
|
|
||||||
|
|
||||||
// textWriter is an io.Writer that tracks its indentation level.
|
|
||||||
type textWriter struct {
|
|
||||||
compact bool // same as TextMarshaler.Compact
|
|
||||||
expandAny bool // same as TextMarshaler.ExpandAny
|
|
||||||
complete bool // whether the current position is a complete line
|
|
||||||
indent int // indentation level; never negative
|
|
||||||
buf []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) Write(p []byte) (n int, _ error) {
|
|
||||||
newlines := bytes.Count(p, newline)
|
|
||||||
if newlines == 0 {
|
|
||||||
if !w.compact && w.complete {
|
|
||||||
w.writeIndent()
|
|
||||||
}
|
|
||||||
w.buf = append(w.buf, p...)
|
|
||||||
w.complete = false
|
|
||||||
return len(p), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
frags := bytes.SplitN(p, newline, newlines+1)
|
|
||||||
if w.compact {
|
|
||||||
for i, frag := range frags {
|
|
||||||
if i > 0 {
|
|
||||||
w.buf = append(w.buf, ' ')
|
|
||||||
n++
|
|
||||||
}
|
|
||||||
w.buf = append(w.buf, frag...)
|
|
||||||
n += len(frag)
|
|
||||||
}
|
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, frag := range frags {
|
|
||||||
if w.complete {
|
|
||||||
w.writeIndent()
|
|
||||||
}
|
|
||||||
w.buf = append(w.buf, frag...)
|
|
||||||
n += len(frag)
|
|
||||||
if i+1 < len(frags) {
|
|
||||||
w.buf = append(w.buf, '\n')
|
|
||||||
n++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.complete = len(frags[len(frags)-1]) == 0
|
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) WriteByte(c byte) error {
|
|
||||||
if w.compact && c == '\n' {
|
|
||||||
c = ' '
|
|
||||||
}
|
|
||||||
if !w.compact && w.complete {
|
|
||||||
w.writeIndent()
|
|
||||||
}
|
|
||||||
w.buf = append(w.buf, c)
|
|
||||||
w.complete = c == '\n'
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) writeName(fd protoreflect.FieldDescriptor) {
|
|
||||||
if !w.compact && w.complete {
|
|
||||||
w.writeIndent()
|
|
||||||
}
|
|
||||||
w.complete = false
|
|
||||||
|
|
||||||
if fd.Kind() != protoreflect.GroupKind {
|
|
||||||
w.buf = append(w.buf, fd.Name()...)
|
|
||||||
w.WriteByte(':')
|
|
||||||
} else {
|
|
||||||
// Use message type name for group field name.
|
|
||||||
w.buf = append(w.buf, fd.Message().Name()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !w.compact {
|
|
||||||
w.WriteByte(' ')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func requiresQuotes(u string) bool {
|
|
||||||
// When type URL contains any characters except [0-9A-Za-z./\-]*, it must be quoted.
|
|
||||||
for _, ch := range u {
|
|
||||||
switch {
|
|
||||||
case ch == '.' || ch == '/' || ch == '_':
|
|
||||||
continue
|
|
||||||
case '0' <= ch && ch <= '9':
|
|
||||||
continue
|
|
||||||
case 'A' <= ch && ch <= 'Z':
|
|
||||||
continue
|
|
||||||
case 'a' <= ch && ch <= 'z':
|
|
||||||
continue
|
|
||||||
default:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeProto3Any writes an expanded google.protobuf.Any message.
|
|
||||||
//
|
|
||||||
// It returns (false, nil) if sv value can't be unmarshaled (e.g. because
|
|
||||||
// required messages are not linked in).
|
|
||||||
//
|
|
||||||
// It returns (true, error) when sv was written in expanded format or an error
|
|
||||||
// was encountered.
|
|
||||||
func (w *textWriter) writeProto3Any(m protoreflect.Message) (bool, error) {
|
|
||||||
md := m.Descriptor()
|
|
||||||
fdURL := md.Fields().ByName("type_url")
|
|
||||||
fdVal := md.Fields().ByName("value")
|
|
||||||
|
|
||||||
url := m.Get(fdURL).String()
|
|
||||||
mt, err := protoregistry.GlobalTypes.FindMessageByURL(url)
|
|
||||||
if err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
b := m.Get(fdVal).Bytes()
|
|
||||||
m2 := mt.New()
|
|
||||||
if err := proto.Unmarshal(b, m2.Interface()); err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
w.Write([]byte("["))
|
|
||||||
if requiresQuotes(url) {
|
|
||||||
w.writeQuotedString(url)
|
|
||||||
} else {
|
|
||||||
w.Write([]byte(url))
|
|
||||||
}
|
|
||||||
if w.compact {
|
|
||||||
w.Write([]byte("]:<"))
|
|
||||||
} else {
|
|
||||||
w.Write([]byte("]: <\n"))
|
|
||||||
w.indent++
|
|
||||||
}
|
|
||||||
if err := w.writeMessage(m2); err != nil {
|
|
||||||
return true, err
|
|
||||||
}
|
|
||||||
if w.compact {
|
|
||||||
w.Write([]byte("> "))
|
|
||||||
} else {
|
|
||||||
w.indent--
|
|
||||||
w.Write([]byte(">\n"))
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) writeMessage(m protoreflect.Message) error {
|
|
||||||
md := m.Descriptor()
|
|
||||||
if w.expandAny && md.FullName() == "google.protobuf.Any" {
|
|
||||||
if canExpand, err := w.writeProto3Any(m); canExpand {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fds := md.Fields()
|
|
||||||
for i := 0; i < fds.Len(); {
|
|
||||||
fd := fds.Get(i)
|
|
||||||
if od := fd.ContainingOneof(); od != nil {
|
|
||||||
fd = m.WhichOneof(od)
|
|
||||||
i += od.Fields().Len()
|
|
||||||
} else {
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
if fd == nil || !m.Has(fd) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case fd.IsList():
|
|
||||||
lv := m.Get(fd).List()
|
|
||||||
for j := 0; j < lv.Len(); j++ {
|
|
||||||
w.writeName(fd)
|
|
||||||
v := lv.Get(j)
|
|
||||||
if err := w.writeSingularValue(v, fd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.WriteByte('\n')
|
|
||||||
}
|
|
||||||
case fd.IsMap():
|
|
||||||
kfd := fd.MapKey()
|
|
||||||
vfd := fd.MapValue()
|
|
||||||
mv := m.Get(fd).Map()
|
|
||||||
|
|
||||||
type entry struct{ key, val protoreflect.Value }
|
|
||||||
var entries []entry
|
|
||||||
mv.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
|
|
||||||
entries = append(entries, entry{k.Value(), v})
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
sort.Slice(entries, func(i, j int) bool {
|
|
||||||
switch kfd.Kind() {
|
|
||||||
case protoreflect.BoolKind:
|
|
||||||
return !entries[i].key.Bool() && entries[j].key.Bool()
|
|
||||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
|
||||||
return entries[i].key.Int() < entries[j].key.Int()
|
|
||||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
|
||||||
return entries[i].key.Uint() < entries[j].key.Uint()
|
|
||||||
case protoreflect.StringKind:
|
|
||||||
return entries[i].key.String() < entries[j].key.String()
|
|
||||||
default:
|
|
||||||
panic("invalid kind")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
for _, entry := range entries {
|
|
||||||
w.writeName(fd)
|
|
||||||
w.WriteByte('<')
|
|
||||||
if !w.compact {
|
|
||||||
w.WriteByte('\n')
|
|
||||||
}
|
|
||||||
w.indent++
|
|
||||||
w.writeName(kfd)
|
|
||||||
if err := w.writeSingularValue(entry.key, kfd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.WriteByte('\n')
|
|
||||||
w.writeName(vfd)
|
|
||||||
if err := w.writeSingularValue(entry.val, vfd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.WriteByte('\n')
|
|
||||||
w.indent--
|
|
||||||
w.WriteByte('>')
|
|
||||||
w.WriteByte('\n')
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
w.writeName(fd)
|
|
||||||
if err := w.writeSingularValue(m.Get(fd), fd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.WriteByte('\n')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if b := m.GetUnknown(); len(b) > 0 {
|
|
||||||
w.writeUnknownFields(b)
|
|
||||||
}
|
|
||||||
return w.writeExtensions(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) writeSingularValue(v protoreflect.Value, fd protoreflect.FieldDescriptor) error {
|
|
||||||
switch fd.Kind() {
|
|
||||||
case protoreflect.FloatKind, protoreflect.DoubleKind:
|
|
||||||
switch vf := v.Float(); {
|
|
||||||
case math.IsInf(vf, +1):
|
|
||||||
w.Write(posInf)
|
|
||||||
case math.IsInf(vf, -1):
|
|
||||||
w.Write(negInf)
|
|
||||||
case math.IsNaN(vf):
|
|
||||||
w.Write(nan)
|
|
||||||
default:
|
|
||||||
fmt.Fprint(w, v.Interface())
|
|
||||||
}
|
|
||||||
case protoreflect.StringKind:
|
|
||||||
// NOTE: This does not validate UTF-8 for historical reasons.
|
|
||||||
w.writeQuotedString(string(v.String()))
|
|
||||||
case protoreflect.BytesKind:
|
|
||||||
w.writeQuotedString(string(v.Bytes()))
|
|
||||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
|
||||||
var bra, ket byte = '<', '>'
|
|
||||||
if fd.Kind() == protoreflect.GroupKind {
|
|
||||||
bra, ket = '{', '}'
|
|
||||||
}
|
|
||||||
w.WriteByte(bra)
|
|
||||||
if !w.compact {
|
|
||||||
w.WriteByte('\n')
|
|
||||||
}
|
|
||||||
w.indent++
|
|
||||||
m := v.Message()
|
|
||||||
if m2, ok := m.Interface().(encoding.TextMarshaler); ok {
|
|
||||||
b, err := m2.MarshalText()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.Write(b)
|
|
||||||
} else {
|
|
||||||
w.writeMessage(m)
|
|
||||||
}
|
|
||||||
w.indent--
|
|
||||||
w.WriteByte(ket)
|
|
||||||
case protoreflect.EnumKind:
|
|
||||||
if ev := fd.Enum().Values().ByNumber(v.Enum()); ev != nil {
|
|
||||||
fmt.Fprint(w, ev.Name())
|
|
||||||
} else {
|
|
||||||
fmt.Fprint(w, v.Enum())
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fmt.Fprint(w, v.Interface())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeQuotedString writes a quoted string in the protocol buffer text format.
|
|
||||||
func (w *textWriter) writeQuotedString(s string) {
|
|
||||||
w.WriteByte('"')
|
|
||||||
for i := 0; i < len(s); i++ {
|
|
||||||
switch c := s[i]; c {
|
|
||||||
case '\n':
|
|
||||||
w.buf = append(w.buf, `\n`...)
|
|
||||||
case '\r':
|
|
||||||
w.buf = append(w.buf, `\r`...)
|
|
||||||
case '\t':
|
|
||||||
w.buf = append(w.buf, `\t`...)
|
|
||||||
case '"':
|
|
||||||
w.buf = append(w.buf, `\"`...)
|
|
||||||
case '\\':
|
|
||||||
w.buf = append(w.buf, `\\`...)
|
|
||||||
default:
|
|
||||||
if isPrint := c >= 0x20 && c < 0x7f; isPrint {
|
|
||||||
w.buf = append(w.buf, c)
|
|
||||||
} else {
|
|
||||||
w.buf = append(w.buf, fmt.Sprintf(`\%03o`, c)...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.WriteByte('"')
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) writeUnknownFields(b []byte) {
|
|
||||||
if !w.compact {
|
|
||||||
fmt.Fprintf(w, "/* %d unknown bytes */\n", len(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
for len(b) > 0 {
|
|
||||||
num, wtyp, n := protowire.ConsumeTag(b)
|
|
||||||
if n < 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
b = b[n:]
|
|
||||||
|
|
||||||
if wtyp == protowire.EndGroupType {
|
|
||||||
w.indent--
|
|
||||||
w.Write(endBraceNewline)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fmt.Fprint(w, num)
|
|
||||||
if wtyp != protowire.StartGroupType {
|
|
||||||
w.WriteByte(':')
|
|
||||||
}
|
|
||||||
if !w.compact || wtyp == protowire.StartGroupType {
|
|
||||||
w.WriteByte(' ')
|
|
||||||
}
|
|
||||||
switch wtyp {
|
|
||||||
case protowire.VarintType:
|
|
||||||
v, n := protowire.ConsumeVarint(b)
|
|
||||||
if n < 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
b = b[n:]
|
|
||||||
fmt.Fprint(w, v)
|
|
||||||
case protowire.Fixed32Type:
|
|
||||||
v, n := protowire.ConsumeFixed32(b)
|
|
||||||
if n < 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
b = b[n:]
|
|
||||||
fmt.Fprint(w, v)
|
|
||||||
case protowire.Fixed64Type:
|
|
||||||
v, n := protowire.ConsumeFixed64(b)
|
|
||||||
if n < 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
b = b[n:]
|
|
||||||
fmt.Fprint(w, v)
|
|
||||||
case protowire.BytesType:
|
|
||||||
v, n := protowire.ConsumeBytes(b)
|
|
||||||
if n < 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
b = b[n:]
|
|
||||||
fmt.Fprintf(w, "%q", v)
|
|
||||||
case protowire.StartGroupType:
|
|
||||||
w.WriteByte('{')
|
|
||||||
w.indent++
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(w, "/* unknown wire type %d */", wtyp)
|
|
||||||
}
|
|
||||||
w.WriteByte('\n')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeExtensions writes all the extensions in m.
|
|
||||||
func (w *textWriter) writeExtensions(m protoreflect.Message) error {
|
|
||||||
md := m.Descriptor()
|
|
||||||
if md.ExtensionRanges().Len() == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ext struct {
|
|
||||||
desc protoreflect.FieldDescriptor
|
|
||||||
val protoreflect.Value
|
|
||||||
}
|
|
||||||
var exts []ext
|
|
||||||
m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
|
|
||||||
if fd.IsExtension() {
|
|
||||||
exts = append(exts, ext{fd, v})
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
sort.Slice(exts, func(i, j int) bool {
|
|
||||||
return exts[i].desc.Number() < exts[j].desc.Number()
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, ext := range exts {
|
|
||||||
// For message set, use the name of the message as the extension name.
|
|
||||||
name := string(ext.desc.FullName())
|
|
||||||
if isMessageSet(ext.desc.ContainingMessage()) {
|
|
||||||
name = strings.TrimSuffix(name, ".message_set_extension")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ext.desc.IsList() {
|
|
||||||
if err := w.writeSingularExtension(name, ext.val, ext.desc); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lv := ext.val.List()
|
|
||||||
for i := 0; i < lv.Len(); i++ {
|
|
||||||
if err := w.writeSingularExtension(name, lv.Get(i), ext.desc); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) writeSingularExtension(name string, v protoreflect.Value, fd protoreflect.FieldDescriptor) error {
|
|
||||||
fmt.Fprintf(w, "[%s]:", name)
|
|
||||||
if !w.compact {
|
|
||||||
w.WriteByte(' ')
|
|
||||||
}
|
|
||||||
if err := w.writeSingularValue(v, fd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.WriteByte('\n')
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *textWriter) writeIndent() {
|
|
||||||
if !w.complete {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for i := 0; i < w.indent*2; i++ {
|
|
||||||
w.buf = append(w.buf, ' ')
|
|
||||||
}
|
|
||||||
w.complete = false
|
|
||||||
}
|
|
||||||
78
vendor/github.com/golang/protobuf/proto/wire.go
generated
vendored
78
vendor/github.com/golang/protobuf/proto/wire.go
generated
vendored
@@ -1,78 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
import (
|
|
||||||
protoV2 "google.golang.org/protobuf/proto"
|
|
||||||
"google.golang.org/protobuf/runtime/protoiface"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Size returns the size in bytes of the wire-format encoding of m.
|
|
||||||
func Size(m Message) int {
|
|
||||||
if m == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
mi := MessageV2(m)
|
|
||||||
return protoV2.Size(mi)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal returns the wire-format encoding of m.
|
|
||||||
func Marshal(m Message) ([]byte, error) {
|
|
||||||
b, err := marshalAppend(nil, m, false)
|
|
||||||
if b == nil {
|
|
||||||
b = zeroBytes
|
|
||||||
}
|
|
||||||
return b, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var zeroBytes = make([]byte, 0, 0)
|
|
||||||
|
|
||||||
func marshalAppend(buf []byte, m Message, deterministic bool) ([]byte, error) {
|
|
||||||
if m == nil {
|
|
||||||
return nil, ErrNil
|
|
||||||
}
|
|
||||||
mi := MessageV2(m)
|
|
||||||
nbuf, err := protoV2.MarshalOptions{
|
|
||||||
Deterministic: deterministic,
|
|
||||||
AllowPartial: true,
|
|
||||||
}.MarshalAppend(buf, mi)
|
|
||||||
if err != nil {
|
|
||||||
return buf, err
|
|
||||||
}
|
|
||||||
if len(buf) == len(nbuf) {
|
|
||||||
if !mi.ProtoReflect().IsValid() {
|
|
||||||
return buf, ErrNil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nbuf, checkRequiredNotSet(mi)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal parses a wire-format message in b and places the decoded results in m.
|
|
||||||
//
|
|
||||||
// Unmarshal resets m before starting to unmarshal, so any existing data in m is always
|
|
||||||
// removed. Use UnmarshalMerge to preserve and append to existing data.
|
|
||||||
func Unmarshal(b []byte, m Message) error {
|
|
||||||
m.Reset()
|
|
||||||
return UnmarshalMerge(b, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalMerge parses a wire-format message in b and places the decoded results in m.
|
|
||||||
func UnmarshalMerge(b []byte, m Message) error {
|
|
||||||
mi := MessageV2(m)
|
|
||||||
out, err := protoV2.UnmarshalOptions{
|
|
||||||
AllowPartial: true,
|
|
||||||
Merge: true,
|
|
||||||
}.UnmarshalState(protoiface.UnmarshalInput{
|
|
||||||
Buf: b,
|
|
||||||
Message: mi.ProtoReflect(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if out.Flags&protoiface.UnmarshalInitialized > 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return checkRequiredNotSet(mi)
|
|
||||||
}
|
|
||||||
34
vendor/github.com/golang/protobuf/proto/wrappers.go
generated
vendored
34
vendor/github.com/golang/protobuf/proto/wrappers.go
generated
vendored
@@ -1,34 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package proto
|
|
||||||
|
|
||||||
// Bool stores v in a new bool value and returns a pointer to it.
|
|
||||||
func Bool(v bool) *bool { return &v }
|
|
||||||
|
|
||||||
// Int stores v in a new int32 value and returns a pointer to it.
|
|
||||||
//
|
|
||||||
// Deprecated: Use Int32 instead.
|
|
||||||
func Int(v int) *int32 { return Int32(int32(v)) }
|
|
||||||
|
|
||||||
// Int32 stores v in a new int32 value and returns a pointer to it.
|
|
||||||
func Int32(v int32) *int32 { return &v }
|
|
||||||
|
|
||||||
// Int64 stores v in a new int64 value and returns a pointer to it.
|
|
||||||
func Int64(v int64) *int64 { return &v }
|
|
||||||
|
|
||||||
// Uint32 stores v in a new uint32 value and returns a pointer to it.
|
|
||||||
func Uint32(v uint32) *uint32 { return &v }
|
|
||||||
|
|
||||||
// Uint64 stores v in a new uint64 value and returns a pointer to it.
|
|
||||||
func Uint64(v uint64) *uint64 { return &v }
|
|
||||||
|
|
||||||
// Float32 stores v in a new float32 value and returns a pointer to it.
|
|
||||||
func Float32(v float32) *float32 { return &v }
|
|
||||||
|
|
||||||
// Float64 stores v in a new float64 value and returns a pointer to it.
|
|
||||||
func Float64(v float64) *float64 { return &v }
|
|
||||||
|
|
||||||
// String stores v in a new string value and returns a pointer to it.
|
|
||||||
func String(v string) *string { return &v }
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user