mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 21:24:01 +03:00
Update golangci-lint
This commit is contained in:
@@ -7,10 +7,9 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"github.com/9seconds/mtg/utils"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type wrapperBlockCipher struct {
|
||||
|
||||
@@ -5,10 +5,9 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/config"
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type connPurpose uint8
|
||||
@@ -29,6 +28,7 @@ type wrapperConn struct {
|
||||
func (w *wrapperConn) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
|
||||
if err := w.parent.SetWriteDeadline(time.Now().Add(timeout)); err != nil {
|
||||
w.Close()
|
||||
|
||||
return 0, fmt.Errorf("cannot set write deadline to the socket: %w", err)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (w *wrapperConn) Write(p []byte) (int, error) {
|
||||
w.logger.Debugw("write to stream", "bytes", n, "error", err)
|
||||
|
||||
if err != nil {
|
||||
w.Close() // nolint: gosec
|
||||
w.Close()
|
||||
}
|
||||
|
||||
return n, err
|
||||
@@ -49,6 +49,7 @@ func (w *wrapperConn) Write(p []byte) (int, error) {
|
||||
func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
|
||||
if err := w.parent.SetReadDeadline(time.Now().Add(timeout)); err != nil {
|
||||
w.Close()
|
||||
|
||||
return 0, fmt.Errorf("cannot set read deadline to the socket: %w", err)
|
||||
}
|
||||
|
||||
@@ -68,6 +69,7 @@ func (w *wrapperConn) Read(p []byte) (int, error) {
|
||||
|
||||
func (w *wrapperConn) Close() error {
|
||||
w.logger.Debugw("Close connection")
|
||||
|
||||
return w.parent.Close()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,8 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type wrapperCtx struct {
|
||||
@@ -21,6 +20,7 @@ func (w *wrapperCtx) WriteTimeout(p []byte, timeout time.Duration) (int, error)
|
||||
select {
|
||||
case <-w.ctx.Done():
|
||||
w.Close()
|
||||
|
||||
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
|
||||
default:
|
||||
return w.parent.WriteTimeout(p, timeout)
|
||||
@@ -31,6 +31,7 @@ func (w *wrapperCtx) Write(p []byte) (int, error) {
|
||||
select {
|
||||
case <-w.ctx.Done():
|
||||
w.Close()
|
||||
|
||||
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
|
||||
default:
|
||||
return w.parent.Write(p)
|
||||
@@ -41,6 +42,7 @@ func (w *wrapperCtx) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
|
||||
select {
|
||||
case <-w.ctx.Done():
|
||||
w.Close()
|
||||
|
||||
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
|
||||
default:
|
||||
return w.parent.ReadTimeout(p, timeout)
|
||||
@@ -51,6 +53,7 @@ func (w *wrapperCtx) Read(p []byte) (int, error) {
|
||||
select {
|
||||
case <-w.ctx.Done():
|
||||
w.Close()
|
||||
|
||||
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
|
||||
default:
|
||||
return w.parent.Read(p)
|
||||
@@ -59,6 +62,7 @@ func (w *wrapperCtx) Read(p []byte) (int, error) {
|
||||
|
||||
func (w *wrapperCtx) Close() error {
|
||||
w.cancel()
|
||||
|
||||
return w.parent.Close()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,9 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"github.com/9seconds/mtg/tlstypes"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type wrapperFakeTLS struct {
|
||||
@@ -33,6 +32,7 @@ func (w *wrapperFakeTLS) WriteTimeout(p []byte, timeout time.Duration) (int, err
|
||||
if elapsed > timeout {
|
||||
return w.parent.WriteTimeout(b, timeout-elapsed)
|
||||
}
|
||||
|
||||
return 0, errors.New("timeout")
|
||||
})
|
||||
}
|
||||
@@ -95,6 +95,8 @@ func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWrit
|
||||
rec.Data.WriteBytes(buf)
|
||||
|
||||
return buf.Bytes(), nil
|
||||
case tlstypes.RecordTypeHandshake:
|
||||
return nil, errors.New("unsupported record type handshake")
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported record type %v", rec.Type)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/md5" // nolint: gosec
|
||||
"crypto/sha1" // nolint: gosec
|
||||
"crypto/md5"
|
||||
"crypto/sha1"
|
||||
"encoding/binary"
|
||||
"net"
|
||||
|
||||
@@ -54,12 +54,11 @@ func mtprotoDeriveKeys(purpose mtprotoCipherPurpose,
|
||||
resp *rpc.NonceResponse,
|
||||
client, remote *net.TCPAddr,
|
||||
secret []byte) ([]byte, []byte) {
|
||||
|
||||
message := bytes.Buffer{}
|
||||
|
||||
message.Write(resp.Nonce) // nolint: gosec
|
||||
message.Write(req.Nonce) // nolint: gosec
|
||||
message.Write(req.CryptoTS) // nolint: gosec
|
||||
message.Write(resp.Nonce)
|
||||
message.Write(req.Nonce)
|
||||
message.Write(req.CryptoTS)
|
||||
|
||||
clientIPv4 := mtprotoEmptyIP[:]
|
||||
serverIPv4 := mtprotoEmptyIP[:]
|
||||
@@ -69,34 +68,34 @@ func mtprotoDeriveKeys(purpose mtprotoCipherPurpose,
|
||||
serverIPv4 = utils.ReverseBytes(remote.IP.To4())
|
||||
}
|
||||
|
||||
message.Write(serverIPv4) // nolint: gosec
|
||||
message.Write(serverIPv4)
|
||||
|
||||
var port [2]byte
|
||||
|
||||
binary.LittleEndian.PutUint16(port[:], uint16(client.Port))
|
||||
message.Write(port[:]) // nolint: gosec
|
||||
message.Write(port[:])
|
||||
|
||||
switch purpose {
|
||||
case mtprotoCipherPurposeClient:
|
||||
message.WriteString("CLIENT") // nolint: gosec
|
||||
message.WriteString("CLIENT")
|
||||
case mtprotoCipherPurposeServer:
|
||||
message.WriteString("SERVER") // nolint: gosec
|
||||
message.WriteString("SERVER")
|
||||
default:
|
||||
panic("Unexpected cipher purpose")
|
||||
}
|
||||
|
||||
message.Write(clientIPv4) // nolint: gosec
|
||||
message.Write(clientIPv4)
|
||||
binary.LittleEndian.PutUint16(port[:], uint16(remote.Port))
|
||||
message.Write(port[:]) // nolint: gosec
|
||||
message.Write(secret) // nolint: gosec
|
||||
message.Write(resp.Nonce) // nolint: gosec
|
||||
message.Write(port[:])
|
||||
message.Write(secret)
|
||||
message.Write(resp.Nonce)
|
||||
|
||||
if client.IP.To4() == nil {
|
||||
message.Write(client.IP.To16()) // nolint: gosec
|
||||
message.Write(remote.IP.To16()) // nolint: gosec
|
||||
message.Write(client.IP.To16())
|
||||
message.Write(remote.IP.To16())
|
||||
}
|
||||
|
||||
message.Write(req.Nonce) // nolint: gosec
|
||||
message.Write(req.Nonce)
|
||||
|
||||
data := message.Bytes()
|
||||
md5sum := md5.Sum(data[1:]) // nolint: gas
|
||||
|
||||
@@ -7,9 +7,8 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type wrapperObfuscated2 struct {
|
||||
|
||||
@@ -7,9 +7,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ReadWriteCloseRewinder interface {
|
||||
@@ -88,6 +87,7 @@ func (w *wrapperRewind) RemoteAddr() *net.TCPAddr {
|
||||
|
||||
func (w *wrapperRewind) Close() error {
|
||||
w.buf.Reset()
|
||||
|
||||
return w.parent.Close()
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"github.com/9seconds/mtg/stats"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type wrapperTelegramStats struct {
|
||||
|
||||
@@ -4,10 +4,9 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"github.com/9seconds/mtg/stats"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type wrapperTrafficStats struct {
|
||||
|
||||
@@ -4,9 +4,8 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/9seconds/mtg/conntypes"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user