mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 19:04:02 +03:00
Updates for go 1.18
This commit is contained in:
@@ -50,7 +50,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
|
||||
buf.Reset()
|
||||
sum.Reset()
|
||||
|
||||
if _, err := io.CopyN(writer, w.parent, 4); err != nil {
|
||||
if _, err := io.CopyN(writer, w.parent, 4); err != nil { // nolint: gomnd
|
||||
return nil, fmt.Errorf("cannot read frame padding: %w", err)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
|
||||
|
||||
buf.Reset()
|
||||
|
||||
if _, err := io.CopyN(writer, w.parent, int64(messageLength)-4-4); err != nil {
|
||||
if _, err := io.CopyN(writer, w.parent, int64(messageLength)-4-4); err != nil { // nolint: gomnd
|
||||
return nil, fmt.Errorf("cannot read the message frame: %w", err)
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
|
||||
buf.Reset()
|
||||
// write to buf, not to writer. This is because we are going to fetch
|
||||
// crc32 checksum.
|
||||
if _, err := io.CopyN(buf, w.parent, 4); err != nil {
|
||||
if _, err := io.CopyN(buf, w.parent, 4); err != nil { // nolint: gomnd
|
||||
return nil, fmt.Errorf("cannot read checksum: %w", err)
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
|
||||
}
|
||||
|
||||
func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
|
||||
messageLength := 4 + 4 + len(p) + 4
|
||||
messageLength := 4 + 4 + len(p) + 4 // nolint: gomnd
|
||||
paddingLength := (aes.BlockSize - messageLength%aes.BlockSize) % aes.BlockSize
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
@@ -119,8 +119,8 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
|
||||
buf.Write(p)
|
||||
|
||||
checksum := crc32.ChecksumIEEE(buf.Bytes())
|
||||
binary.Write(buf, binary.LittleEndian, checksum) // nolint: errcheck
|
||||
buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4))
|
||||
binary.Write(buf, binary.LittleEndian, checksum) // nolint: errcheck
|
||||
buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4)) // nolint: gomnd
|
||||
|
||||
w.logger.Debugw("Write MTProto frame",
|
||||
"length", len(p),
|
||||
|
||||
@@ -39,9 +39,9 @@ func (w *wrapperClientAbridged) Read(acks *conntypes.ConnectionAcks) (conntypes.
|
||||
}
|
||||
|
||||
if msgLength == clientAbridgedSmallPacketLength {
|
||||
buf.Grow(3)
|
||||
buf.Grow(3) // nolint: gomnd
|
||||
|
||||
if _, err := io.CopyN(&buf, w.parent, 3); err != nil {
|
||||
if _, err := io.CopyN(&buf, w.parent, 3); err != nil { // nolint: gomnd
|
||||
return nil, fmt.Errorf("cannot read correct message length: %w", err)
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C
|
||||
return nil
|
||||
}
|
||||
|
||||
packetLength := len(packet) / 4
|
||||
packetLength := len(packet) / 4 // nolint: gomnd
|
||||
|
||||
switch {
|
||||
case packetLength < clientAbridgedSmallPacketLength:
|
||||
|
||||
@@ -20,9 +20,9 @@ type wrapperClientIntermediate struct {
|
||||
func (w *wrapperClientIntermediate) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) {
|
||||
buf := bytes.Buffer{}
|
||||
|
||||
buf.Grow(4)
|
||||
buf.Grow(4) // nolint: gomnd
|
||||
|
||||
if _, err := io.CopyN(&buf, w.parent, 4); err != nil {
|
||||
if _, err := io.CopyN(&buf, w.parent, 4); err != nil { // nolint: gomnd
|
||||
return nil, fmt.Errorf("cannot read message length: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ func (w *wrapperClientIntermediateSecure) Read(acks *conntypes.ConnectionAcks) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
length := len(data) - (len(data) % 4)
|
||||
length := len(data) - (len(data) % 4) // nolint: gomnd
|
||||
|
||||
return data[:length], nil
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func (w *wrapperClientIntermediateSecure) Write(packet conntypes.Packet, acks *c
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
paddingLength := rand.Intn(4) // nolint: gosec
|
||||
paddingLength := rand.Intn(4) // nolint: gosec, gomnd
|
||||
|
||||
buf.Grow(4 + len(packet) + paddingLength)
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.Connection
|
||||
buf.Write(rpc.ProxyRequestProxyTag)
|
||||
buf.WriteByte(byte(len(config.C.AdTag)))
|
||||
buf.Write(config.C.AdTag)
|
||||
buf.Write(make([]byte, (4-buf.Len()%4)%4))
|
||||
buf.Write(make([]byte, (4-buf.Len()%4)%4)) // nolint: gomnd
|
||||
buf.Grow(len(packet))
|
||||
buf.Write(packet)
|
||||
|
||||
|
||||
@@ -93,9 +93,9 @@ func newConn(parent net.Conn,
|
||||
connID conntypes.ConnID,
|
||||
purpose connPurpose,
|
||||
) conntypes.StreamReadWriteCloser {
|
||||
localAddr := *parent.LocalAddr().(*net.TCPAddr)
|
||||
localAddr := *parent.LocalAddr().(*net.TCPAddr) // nolint: forcetypeassert
|
||||
|
||||
if parent.RemoteAddr().(*net.TCPAddr).IP.To4() != nil {
|
||||
if parent.RemoteAddr().(*net.TCPAddr).IP.To4() != nil { // nolint: forcetypeassert
|
||||
if config.C.PublicIPv4.IP != nil {
|
||||
localAddr.IP = config.C.PublicIPv4.IP
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func newConn(parent net.Conn,
|
||||
parent: parent,
|
||||
connID: connID,
|
||||
logger: logger,
|
||||
remoteAddr: parent.RemoteAddr().(*net.TCPAddr),
|
||||
remoteAddr: parent.RemoteAddr().(*net.TCPAddr), // nolint: forcetypeassert
|
||||
localAddr: &localAddr,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user