Compare commits

..

11 commits

Author SHA1 Message Date
Ben van Hartingsveldt
3f075c62b9
Fix more naked returns
Some checks are pending
Build and Test / Go CI (push) Waiting to run
golangci-lint / lint (push) Waiting to run
2025-08-29 19:44:22 +02:00
Ben van Hartingsveldt
84f05db599
Fix naked returns 2025-08-29 19:36:26 +02:00
Ben van Hartingsveldt
b2855ad7a7
Allow crypto dependencies 2025-08-29 19:01:22 +02:00
Ben van Hartingsveldt
013170eecc
Allow all GitHub dependencies 2025-08-29 18:55:19 +02:00
Ben van Hartingsveldt
4d4d85799e
Allow all standard dependencies 2025-08-29 18:52:33 +02:00
Ben van Hartingsveldt
8927acc30c
Remove deprecated linters
Some checks are pending
Build and Test / Go CI (push) Waiting to run
golangci-lint / lint (push) Waiting to run
2025-08-29 17:11:28 +02:00
Ben van Hartingsveldt
dc6c24a11d
Move GoLang CI formatters 2025-08-29 17:08:53 +02:00
Ben van Hartingsveldt
ead4e4d6e8
Fix GoLang CI 2025-08-29 17:04:16 +02:00
Ben van Hartingsveldt
33ff9fb583
Update linter workflow 2025-08-29 16:01:54 +02:00
Ben van Hartingsveldt
6054833af4
Update workflow 2025-08-29 15:54:55 +02:00
Lucas Cullen
c198b6d78a fix: correct typo in README and add building instructions 2025-08-26 20:36:03 +10:00
5 changed files with 133 additions and 144 deletions

View file

@ -22,36 +22,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: setup go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: '${{ env.GO_VERSION }}'
- name: checkout source
uses: actions/checkout@v2
uses: actions/checkout@v5
- name: compile code
run: go install -v ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v8
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
# 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
version: latest

View file

@ -49,7 +49,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: lbcd-${{ github.sha }}
path: |

View file

@ -1,71 +1,17 @@
linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
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
formatters:
enable:
- gofmt
- goimports
settings:
gci:
sections:
- prefix(github.com/golangci/golangci-lint)
goimports:
local-prefixes:
- github.com/golangci/golangci-lint
linters:
disable-all: true
default: none
enable:
- asciicheck
- bodyclose
@ -75,7 +21,6 @@ linters:
# - dupl
# - errcheck
# - exhaustive
- exportloopref
# - funlen
# - gochecknoglobals
# - gochecknoinits
@ -86,8 +31,6 @@ linters:
# - godot
# - godox
# - goerr113
- gofmt
- goimports
# - gomnd
- goprintffuncname
# - gosec
@ -117,36 +60,91 @@ linters:
# - varcheck
# - whitespace
# - 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:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
# 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
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
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
version: "2"

View file

@ -9,7 +9,7 @@
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).
@ -37,6 +37,16 @@ $ go install github.com/lbryio/lbcd@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
Default application folder `${LBCDDIR}`:

40
upnp.go
View file

@ -69,18 +69,18 @@ type upnpNAT struct {
func Discover() (nat NAT, err error) {
ssdp, err := net.ResolveUDPAddr("udp4", "239.255.255.250:1900")
if err != nil {
return
return nil, err
}
conn, err := net.ListenPacket("udp4", ":0")
if err != nil {
return
return nil, err
}
socket := conn.(*net.UDPConn)
defer socket.Close()
err = socket.SetDeadline(time.Now().Add(3 * time.Second))
if err != nil {
return
return nil, err
}
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++ {
_, err = socket.WriteToUDP(message, ssdp)
if err != nil {
return
return nil, err
}
var n int
n, _, err = socket.ReadFromUDP(answerBytes)
@ -124,16 +124,16 @@ func Discover() (nat NAT, err error) {
var serviceURL string
serviceURL, err = getServiceURL(locURL)
if err != nil {
return
return nil, err
}
var serviceIP string = getServiceIP(serviceURL)
var ourIP string
ourIP, err = getOurIP(serviceIP)
if err != nil {
return
return nil, err
}
nat = &upnpNAT{serviceURL: serviceURL, ourIP: ourIP}
return
return nat, nil
}
err = errors.New("UPnP port discovery failed")
return nat, err
@ -228,7 +228,7 @@ func getOurIP(serviceIP string) (ip string, err error) {
return ip.String(), nil
}
}
return
return "", err
}
// 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) {
r, err := http.Get(rootURL)
if err != nil {
return
return "", err
}
defer r.Body.Close()
if r.StatusCode >= 400 {
err = errors.New(fmt.Sprint(r.StatusCode))
return
return "", err
}
var root root
err = xml.NewDecoder(r.Body).Decode(&root)
if err != nil {
return
return "", err
}
a := &root.Device
if a.DeviceType != "urn:schemas-upnp-org:device:InternetGatewayDevice:1" {
err = errors.New("no InternetGatewayDevice")
return
return "", err
}
b := getChildDevice(a, "urn:schemas-upnp-org:device:WANDevice:1")
if b == nil {
err = errors.New("no WANDevice")
return
return "", err
}
c := getChildDevice(b, "urn:schemas-upnp-org:device:WANConnectionDevice:1")
if c == nil {
err = errors.New("no WANConnectionDevice")
return
return "", err
}
d := getChildService(c, "urn:schemas-upnp-org:service:WANIPConnection:1")
if d == nil {
err = errors.New("no WANIPConnection")
return
return "", err
}
url = combineURL(rootURL, d.ControlURL)
return url, err
@ -325,7 +325,7 @@ func soapRequest(url, function, message string) (replyXML []byte, err error) {
if r.StatusCode >= 400 {
err = errors.New("Error " + strconv.Itoa(r.StatusCode) + " for " + function)
r = nil
return
return nil, err
}
var reply soapEnvelope
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)
if err != nil {
return
return 0, err
}
// 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.
mappedExternalPort = externalPort
_ = response
return
return mappedExternalPort, nil
}
// 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)
if err != nil {
return
return err
}
// TODO: check response to see if the port was deleted
// log.Println(message, response)
_ = response
return
return nil
}