Skip to content

Commit

Permalink
Merge pull request #92 from lightninglabs/updateLinterRUles
Browse files Browse the repository at this point in the history
.golangci: update linter rules
  • Loading branch information
ellemouton authored Nov 21, 2023
2 parents a6dd981 + 97d93d2 commit 9cf86bc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
30 changes: 30 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,42 @@ linters-settings:
govet:
# Don't report about shadowed variables
check-shadowing: false

gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true

funlen:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
lines: 200
# Checks the number of statements in a function.
statements: 80

gosec:
excludes:
- G402 # Look for bad TLS connection settings.
- G306 # Poor file permissions used when writing to a new file.

whitespace:
multi-func: true
multi-if: true

linters:
enable-all: true
disable:
# Allow dynamic errors.
- goerr113

# We want to allow short variable names.
- varnamelen

# Allow tests to be put in the same package.
- testpackage

# We want to allow TODOs.
- godox

# Init functions are used by loggers throughout the codebase.
- gochecknoinits

Expand All @@ -46,6 +65,17 @@ linters:
# instances are created.
- exhaustruct

# Disable gofumpt as it has weird behavior regarding formatting multiple
# lines for a function which is in conflict with our contribution
# guidelines. See https://github.com/mvdan/gofumpt/issues/235.
- gofumpt

# Disable whitespace linter as it has conflict rules against our
# contribution guidelines. See https://github.com/bombsimon/wsl/issues/109.
#
# TODO: bring it back when the above issue is fixed.
- wsl

# Deprecated linters. See https://golangci-lint.run/usage/linters/.
- interfacer
- golint
Expand Down
24 changes: 15 additions & 9 deletions gbn/gbn_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc,

// clientHandshake initiates the client side GBN handshake.
// The handshake sequence from the client side is as follows:
// 1. The client sends SYN to the server along with the N value that the
// client wishes to use for the connection.
// 2. The client then waits for the server to respond with SYN.
// 3a. If the client receives SYN from the server then the client sends back
// SYNACK.
// 1. The client sends SYN to the server along with the N value that the
// client wishes to use for the connection.
// 2. The client then waits for the server to respond with SYN.
// 3a. If the client receives SYN from the server, then the client sends back
// SYNACK.
// 3b. If the client does not receive SYN from the server within a given
// timeout, then the client restarts the handshake from step 1.
// timeout, then the client restarts the handshake from step 1.
func (g *GoBackNConn) clientHandshake() error {
// Spin off the recv function in a goroutine so that we can use
// a select to choose to timeout waiting for data from the receive
Expand Down Expand Up @@ -94,7 +94,10 @@ func (g *GoBackNConn) clientHandshake() error {
}
}()

var resp Message
var (
resp Message
respSYN *PacketSYN
)
handshake:
for {
// start Handshake
Expand Down Expand Up @@ -142,8 +145,10 @@ handshake:
}

log.Debugf("Client got %T", resp)
switch resp.(type) {
switch r := resp.(type) {
case *PacketSYN:
respSYN = r

break handshake
default:
}
Expand All @@ -155,7 +160,8 @@ handshake:
}

log.Debugf("Client got SYN")
if resp.(*PacketSYN).N != g.n {

if respSYN.N != g.n {
return io.EOF
}

Expand Down
2 changes: 1 addition & 1 deletion gbn/gbn_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type GoBackNConn struct {
pongTicker *IntervalAwareForceTicker
pongWait chan struct{}

ctx context.Context
ctx context.Context //nolint:containedctx
cancel func()

// remoteClosed is closed if the remote party initiated the FIN sequence.
Expand Down
2 changes: 1 addition & 1 deletion mailbox/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Server struct {

sid [64]byte

ctx context.Context
ctx context.Context //nolint:containedctx

quit chan struct{}
cancel func()
Expand Down

0 comments on commit 9cf86bc

Please sign in to comment.