mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-30 17:01:29 +00:00
Compare commits
11 commits
Author | SHA1 | Date | |
---|---|---|---|
|
3f075c62b9 | ||
|
84f05db599 | ||
|
b2855ad7a7 | ||
|
013170eecc | ||
|
4d4d85799e | ||
|
8927acc30c | ||
|
dc6c24a11d | ||
|
ead4e4d6e8 | ||
|
33ff9fb583 | ||
|
6054833af4 | ||
|
c198b6d78a |
5 changed files with 133 additions and 144 deletions
25
.github/workflows/golangci-lint.yml
vendored
25
.github/workflows/golangci-lint.yml
vendored
|
@ -22,36 +22,17 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: setup go ${{ env.GO_VERSION }}
|
- name: setup go ${{ env.GO_VERSION }}
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '${{ env.GO_VERSION }}'
|
go-version: '${{ env.GO_VERSION }}'
|
||||||
|
|
||||||
- name: checkout source
|
- name: checkout source
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: compile code
|
- name: compile code
|
||||||
run: go install -v ./...
|
run: go install -v ./...
|
||||||
|
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
|
||||||
version: latest
|
version: latest
|
||||||
|
|
||||||
# Optional: working directory, useful for monorepos
|
|
||||||
# working-directory: somedir
|
|
||||||
|
|
||||||
# Optional: golangci-lint command line arguments.
|
|
||||||
# args: --issues-exit-code=0
|
|
||||||
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
|
||||||
# only-new-issues: true
|
|
||||||
|
|
||||||
# Optional: if set to true then the action will use pre-installed Go.
|
|
||||||
skip-go-installation: true
|
|
||||||
|
|
||||||
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
|
|
||||||
# skip-pkg-cache: true
|
|
||||||
|
|
||||||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
|
||||||
# skip-build-cache: true
|
|
||||||
|
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
@ -49,7 +49,7 @@ jobs:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Upload artifacts
|
name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: lbcd-${{ github.sha }}
|
name: lbcd-${{ github.sha }}
|
||||||
path: |
|
path: |
|
||||||
|
|
196
.golangci.yml
196
.golangci.yml
|
@ -1,71 +1,17 @@
|
||||||
linters-settings:
|
formatters:
|
||||||
depguard:
|
enable:
|
||||||
list-type: blacklist
|
- gofmt
|
||||||
packages:
|
- goimports
|
||||||
# logging is allowed only by logutils.Log, logrus
|
settings:
|
||||||
# is allowed to use only in logutils package
|
gci:
|
||||||
- github.com/sirupsen/logrus
|
sections:
|
||||||
packages-with-error-message:
|
- prefix(github.com/golangci/golangci-lint)
|
||||||
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
|
goimports:
|
||||||
dupl:
|
local-prefixes:
|
||||||
threshold: 100
|
- github.com/golangci/golangci-lint
|
||||||
funlen:
|
|
||||||
lines: 100
|
|
||||||
statements: 50
|
|
||||||
gci:
|
|
||||||
local-prefixes: github.com/golangci/golangci-lint
|
|
||||||
goconst:
|
|
||||||
min-len: 2
|
|
||||||
min-occurrences: 2
|
|
||||||
gocritic:
|
|
||||||
enabled-tags:
|
|
||||||
- diagnostic
|
|
||||||
- experimental
|
|
||||||
- opinionated
|
|
||||||
- performance
|
|
||||||
- style
|
|
||||||
disabled-checks:
|
|
||||||
- dupImport # https://github.com/go-critic/go-critic/issues/845
|
|
||||||
- ifElseChain
|
|
||||||
- octalLiteral
|
|
||||||
- whyNoLint
|
|
||||||
- wrapperFunc
|
|
||||||
gocyclo:
|
|
||||||
min-complexity: 15
|
|
||||||
goimports:
|
|
||||||
local-prefixes: github.com/golangci/golangci-lint
|
|
||||||
gomnd:
|
|
||||||
settings:
|
|
||||||
mnd:
|
|
||||||
# don't include the "operation" and "assign"
|
|
||||||
checks:
|
|
||||||
- argument
|
|
||||||
- case
|
|
||||||
- condition
|
|
||||||
- return
|
|
||||||
govet:
|
|
||||||
check-shadowing: true
|
|
||||||
settings:
|
|
||||||
printf:
|
|
||||||
funcs:
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
|
||||||
lll:
|
|
||||||
line-length: 140
|
|
||||||
maligned:
|
|
||||||
suggest-new: true
|
|
||||||
misspell:
|
|
||||||
locale: US
|
|
||||||
nolintlint:
|
|
||||||
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
|
|
||||||
allow-unused: false # report any unused nolint directives
|
|
||||||
require-explanation: false # don't require an explanation for nolint directives
|
|
||||||
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
default: none
|
||||||
enable:
|
enable:
|
||||||
- asciicheck
|
- asciicheck
|
||||||
- bodyclose
|
- bodyclose
|
||||||
|
@ -75,7 +21,6 @@ linters:
|
||||||
# - dupl
|
# - dupl
|
||||||
# - errcheck
|
# - errcheck
|
||||||
# - exhaustive
|
# - exhaustive
|
||||||
- exportloopref
|
|
||||||
# - funlen
|
# - funlen
|
||||||
# - gochecknoglobals
|
# - gochecknoglobals
|
||||||
# - gochecknoinits
|
# - gochecknoinits
|
||||||
|
@ -86,8 +31,6 @@ linters:
|
||||||
# - godot
|
# - godot
|
||||||
# - godox
|
# - godox
|
||||||
# - goerr113
|
# - goerr113
|
||||||
- gofmt
|
|
||||||
- goimports
|
|
||||||
# - gomnd
|
# - gomnd
|
||||||
- goprintffuncname
|
- goprintffuncname
|
||||||
# - gosec
|
# - gosec
|
||||||
|
@ -117,36 +60,91 @@ linters:
|
||||||
# - varcheck
|
# - varcheck
|
||||||
# - whitespace
|
# - whitespace
|
||||||
# - wsl
|
# - wsl
|
||||||
|
exclusions:
|
||||||
|
paths:
|
||||||
|
- test/testdata_etc
|
||||||
|
- internal/cache
|
||||||
|
- internal/renameio
|
||||||
|
- internal/robustio
|
||||||
|
rules:
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- gomnd
|
||||||
|
- path: pkg/golinters/errcheck.go
|
||||||
|
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
|
||||||
|
- path: pkg/commands/run.go
|
||||||
|
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
|
||||||
|
|
||||||
issues:
|
# TODO must be removed after the release of the next version (v1.41.0)
|
||||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
- path: pkg/commands/run.go
|
||||||
exclude-rules:
|
linters:
|
||||||
- path: _test\.go
|
|
||||||
linters:
|
|
||||||
- gomnd
|
- gomnd
|
||||||
|
# TODO must be removed after the release of the next version (v1.41.0)
|
||||||
|
- path: pkg/golinters/nolintlint/nolintlint.go
|
||||||
|
linters:
|
||||||
|
- gomnd
|
||||||
|
# TODO must be removed after the release of the next version (v1.41.0)
|
||||||
|
- path: pkg/printers/tab.go
|
||||||
|
linters:
|
||||||
|
- gomnd
|
||||||
|
settings:
|
||||||
|
govet:
|
||||||
|
enable:
|
||||||
|
- shadow
|
||||||
|
settings:
|
||||||
|
printf:
|
||||||
|
funcs:
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
||||||
|
lll:
|
||||||
|
line-length: 140
|
||||||
|
depguard:
|
||||||
|
rules:
|
||||||
|
main:
|
||||||
|
list-mode: strict
|
||||||
|
allow:
|
||||||
|
- $gostd
|
||||||
|
- github.com/
|
||||||
|
- golang.org/x/crypto/ripemd160
|
||||||
|
deny:
|
||||||
|
- pkg: github.com/sirupsen/logrus
|
||||||
|
desc: "logging is allowed only by logutils.Log"
|
||||||
|
dupl:
|
||||||
|
threshold: 100
|
||||||
|
funlen:
|
||||||
|
lines: 100
|
||||||
|
statements: 50
|
||||||
|
goconst:
|
||||||
|
min-len: 2
|
||||||
|
min-occurrences: 2
|
||||||
|
gocritic:
|
||||||
|
enabled-tags:
|
||||||
|
- diagnostic
|
||||||
|
- experimental
|
||||||
|
- opinionated
|
||||||
|
- performance
|
||||||
|
- style
|
||||||
|
disabled-checks:
|
||||||
|
- dupImport # https://github.com/go-critic/go-critic/issues/845
|
||||||
|
- ifElseChain
|
||||||
|
- octalLiteral
|
||||||
|
- whyNoLint
|
||||||
|
- wrapperFunc
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 15
|
||||||
|
misspell:
|
||||||
|
locale: US
|
||||||
|
mnd:
|
||||||
|
checks:
|
||||||
|
- argument
|
||||||
|
- case
|
||||||
|
- condition
|
||||||
|
- return
|
||||||
|
nolintlint:
|
||||||
|
allow-unused: false # report any unused nolint directives
|
||||||
|
require-explanation: false # don't require an explanation for nolint directives
|
||||||
|
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
||||||
|
|
||||||
- path: pkg/golinters/errcheck.go
|
version: "2"
|
||||||
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
|
|
||||||
- path: pkg/commands/run.go
|
|
||||||
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
|
|
||||||
|
|
||||||
# TODO must be removed after the release of the next version (v1.41.0)
|
|
||||||
- path: pkg/commands/run.go
|
|
||||||
linters:
|
|
||||||
- gomnd
|
|
||||||
# TODO must be removed after the release of the next version (v1.41.0)
|
|
||||||
- path: pkg/golinters/nolintlint/nolintlint.go
|
|
||||||
linters:
|
|
||||||
- gomnd
|
|
||||||
# TODO must be removed after the release of the next version (v1.41.0)
|
|
||||||
- path: pkg/printers/tab.go
|
|
||||||
linters:
|
|
||||||
- gomnd
|
|
||||||
|
|
||||||
|
|
||||||
run:
|
|
||||||
skip-dirs:
|
|
||||||
- test/testdata_etc
|
|
||||||
- internal/cache
|
|
||||||
- internal/renameio
|
|
||||||
- internal/robustio
|
|
12
README.md
12
README.md
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
Software stack developed by LBRY teams has been all migrated to **lbcd**.
|
Software stack developed by LBRY teams has been all migrated to **lbcd**.
|
||||||
|
|
||||||
We're working with exchanges and pool oerators to migrate from **lbrycrd** to **lbcd**.
|
We're working with exchanges and pool operators to migrate from **lbrycrd** to **lbcd**.
|
||||||
|
|
||||||
If you're integrating with **lbcd+lbcwallet**, please check the Wiki for current [supported RPCs](wiki/RPC-availability).
|
If you're integrating with **lbcd+lbcwallet**, please check the Wiki for current [supported RPCs](wiki/RPC-availability).
|
||||||
|
|
||||||
|
@ -37,6 +37,16 @@ $ go install github.com/lbryio/lbcd@latest
|
||||||
$ go install github.com/lbryio/lbcd/cmd/lbcctl@latest
|
$ go install github.com/lbryio/lbcd/cmd/lbcctl@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Building from Source
|
||||||
|
|
||||||
|
To build **lbcd** from source, clone the repository and use the `go build` command:
|
||||||
|
|
||||||
|
``` sh
|
||||||
|
$ git clone https://github.com/LBRYFoundation/lbcd.git
|
||||||
|
$ cd lbcd
|
||||||
|
$ go build .
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Default application folder `${LBCDDIR}`:
|
Default application folder `${LBCDDIR}`:
|
||||||
|
|
40
upnp.go
40
upnp.go
|
@ -69,18 +69,18 @@ type upnpNAT struct {
|
||||||
func Discover() (nat NAT, err error) {
|
func Discover() (nat NAT, err error) {
|
||||||
ssdp, err := net.ResolveUDPAddr("udp4", "239.255.255.250:1900")
|
ssdp, err := net.ResolveUDPAddr("udp4", "239.255.255.250:1900")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
conn, err := net.ListenPacket("udp4", ":0")
|
conn, err := net.ListenPacket("udp4", ":0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
socket := conn.(*net.UDPConn)
|
socket := conn.(*net.UDPConn)
|
||||||
defer socket.Close()
|
defer socket.Close()
|
||||||
|
|
||||||
err = socket.SetDeadline(time.Now().Add(3 * time.Second))
|
err = socket.SetDeadline(time.Now().Add(3 * time.Second))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
st := "ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n"
|
st := "ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n"
|
||||||
|
@ -95,7 +95,7 @@ func Discover() (nat NAT, err error) {
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
_, err = socket.WriteToUDP(message, ssdp)
|
_, err = socket.WriteToUDP(message, ssdp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
var n int
|
var n int
|
||||||
n, _, err = socket.ReadFromUDP(answerBytes)
|
n, _, err = socket.ReadFromUDP(answerBytes)
|
||||||
|
@ -124,16 +124,16 @@ func Discover() (nat NAT, err error) {
|
||||||
var serviceURL string
|
var serviceURL string
|
||||||
serviceURL, err = getServiceURL(locURL)
|
serviceURL, err = getServiceURL(locURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
var serviceIP string = getServiceIP(serviceURL)
|
var serviceIP string = getServiceIP(serviceURL)
|
||||||
var ourIP string
|
var ourIP string
|
||||||
ourIP, err = getOurIP(serviceIP)
|
ourIP, err = getOurIP(serviceIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
nat = &upnpNAT{serviceURL: serviceURL, ourIP: ourIP}
|
nat = &upnpNAT{serviceURL: serviceURL, ourIP: ourIP}
|
||||||
return
|
return nat, nil
|
||||||
}
|
}
|
||||||
err = errors.New("UPnP port discovery failed")
|
err = errors.New("UPnP port discovery failed")
|
||||||
return nat, err
|
return nat, err
|
||||||
|
@ -228,7 +228,7 @@ func getOurIP(serviceIP string) (ip string, err error) {
|
||||||
return ip.String(), nil
|
return ip.String(), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// getServiceURL parses the xml description at the given root url to find the
|
// getServiceURL parses the xml description at the given root url to find the
|
||||||
|
@ -236,37 +236,37 @@ func getOurIP(serviceIP string) (ip string, err error) {
|
||||||
func getServiceURL(rootURL string) (url string, err error) {
|
func getServiceURL(rootURL string) (url string, err error) {
|
||||||
r, err := http.Get(rootURL)
|
r, err := http.Get(rootURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
if r.StatusCode >= 400 {
|
if r.StatusCode >= 400 {
|
||||||
err = errors.New(fmt.Sprint(r.StatusCode))
|
err = errors.New(fmt.Sprint(r.StatusCode))
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
var root root
|
var root root
|
||||||
err = xml.NewDecoder(r.Body).Decode(&root)
|
err = xml.NewDecoder(r.Body).Decode(&root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
a := &root.Device
|
a := &root.Device
|
||||||
if a.DeviceType != "urn:schemas-upnp-org:device:InternetGatewayDevice:1" {
|
if a.DeviceType != "urn:schemas-upnp-org:device:InternetGatewayDevice:1" {
|
||||||
err = errors.New("no InternetGatewayDevice")
|
err = errors.New("no InternetGatewayDevice")
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
b := getChildDevice(a, "urn:schemas-upnp-org:device:WANDevice:1")
|
b := getChildDevice(a, "urn:schemas-upnp-org:device:WANDevice:1")
|
||||||
if b == nil {
|
if b == nil {
|
||||||
err = errors.New("no WANDevice")
|
err = errors.New("no WANDevice")
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
c := getChildDevice(b, "urn:schemas-upnp-org:device:WANConnectionDevice:1")
|
c := getChildDevice(b, "urn:schemas-upnp-org:device:WANConnectionDevice:1")
|
||||||
if c == nil {
|
if c == nil {
|
||||||
err = errors.New("no WANConnectionDevice")
|
err = errors.New("no WANConnectionDevice")
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
d := getChildService(c, "urn:schemas-upnp-org:service:WANIPConnection:1")
|
d := getChildService(c, "urn:schemas-upnp-org:service:WANIPConnection:1")
|
||||||
if d == nil {
|
if d == nil {
|
||||||
err = errors.New("no WANIPConnection")
|
err = errors.New("no WANIPConnection")
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
url = combineURL(rootURL, d.ControlURL)
|
url = combineURL(rootURL, d.ControlURL)
|
||||||
return url, err
|
return url, err
|
||||||
|
@ -325,7 +325,7 @@ func soapRequest(url, function, message string) (replyXML []byte, err error) {
|
||||||
if r.StatusCode >= 400 {
|
if r.StatusCode >= 400 {
|
||||||
err = errors.New("Error " + strconv.Itoa(r.StatusCode) + " for " + function)
|
err = errors.New("Error " + strconv.Itoa(r.StatusCode) + " for " + function)
|
||||||
r = nil
|
r = nil
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
var reply soapEnvelope
|
var reply soapEnvelope
|
||||||
err = xml.NewDecoder(r.Body).Decode(&reply)
|
err = xml.NewDecoder(r.Body).Decode(&reply)
|
||||||
|
@ -380,7 +380,7 @@ func (n *upnpNAT) AddPortMapping(protocol string, externalPort, internalPort int
|
||||||
|
|
||||||
response, err := soapRequest(n.serviceURL, "AddPortMapping", message)
|
response, err := soapRequest(n.serviceURL, "AddPortMapping", message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check response to see if the port was forwarded
|
// TODO: check response to see if the port was forwarded
|
||||||
|
@ -389,7 +389,7 @@ func (n *upnpNAT) AddPortMapping(protocol string, externalPort, internalPort int
|
||||||
// codes here.
|
// codes here.
|
||||||
mappedExternalPort = externalPort
|
mappedExternalPort = externalPort
|
||||||
_ = response
|
_ = response
|
||||||
return
|
return mappedExternalPort, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePortMapping implements the NAT interface by removing up a port forwarding
|
// DeletePortMapping implements the NAT interface by removing up a port forwarding
|
||||||
|
@ -403,11 +403,11 @@ func (n *upnpNAT) DeletePortMapping(protocol string, externalPort, internalPort
|
||||||
|
|
||||||
response, err := soapRequest(n.serviceURL, "DeletePortMapping", message)
|
response, err := soapRequest(n.serviceURL, "DeletePortMapping", message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check response to see if the port was deleted
|
// TODO: check response to see if the port was deleted
|
||||||
// log.Println(message, response)
|
// log.Println(message, response)
|
||||||
_ = response
|
_ = response
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue