fix:fix lint

Signed-off-by: Chen Kai <281165273grape@gmail.com>
This commit is contained in:
Chen Kai 2023-11-15 13:51:07 +08:00
parent 96a89db758
commit a4e9a7034d
3 changed files with 27 additions and 27 deletions

View file

@ -7,13 +7,14 @@ import (
"encoding/binary"
"errors"
"fmt"
"go.uber.org/zap"
"io"
"math/big"
"net"
"sort"
"time"
"go.uber.org/zap"
"github.com/VictoriaMetrics/fastcache"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover/portalwire"
@ -782,6 +783,7 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
}
}
fmt.Println(contentKeys)
if contentKeyBitsets.Count() == 0 {
idBuffer := make([]byte, 2)
binary.BigEndian.PutUint16(idBuffer, uint16(0))

View file

@ -4,13 +4,14 @@ import (
"crypto/rand"
"errors"
"fmt"
"github.com/optimism-java/utp-go"
"io"
"net"
"sync"
"testing"
"time"
"github.com/optimism-java/utp-go"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/testlog"
"github.com/ethereum/go-ethereum/log"
@ -57,19 +58,19 @@ func setupLocalPortalNode(addr string, bootNodes []*enode.Node) (*PortalProtocol
}
func TestPortalWireProtocolUdp(t *testing.T) {
node1, err := setupLocalPortalNode(":7777", nil)
node1, err := setupLocalPortalNode(":8777", nil)
assert.NoError(t, err)
node1.log = testlog.Logger(t, log.LvlTrace)
err = node1.Start()
assert.NoError(t, err)
node2, err := setupLocalPortalNode(":7778", []*enode.Node{node1.localNode.Node()})
node2, err := setupLocalPortalNode(":8778", []*enode.Node{node1.localNode.Node()})
assert.NoError(t, err)
node2.log = testlog.Logger(t, log.LvlTrace)
err = node2.Start()
assert.NoError(t, err)
node3, err := setupLocalPortalNode(":7779", []*enode.Node{node1.localNode.Node()})
node3, err := setupLocalPortalNode(":8779", []*enode.Node{node1.localNode.Node()})
assert.NoError(t, err)
node3.log = testlog.Logger(t, log.LvlTrace)
err = node3.Start()
@ -80,8 +81,8 @@ func TestPortalWireProtocolUdp(t *testing.T) {
assert.Equal(t, 2, len(node2.table.Nodes()))
assert.Equal(t, 2, len(node3.table.Nodes()))
rAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:7777")
lAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:7778")
rAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8777")
lAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8778")
var wg sync.WaitGroup
wg.Add(4)
@ -95,6 +96,7 @@ func TestPortalWireProtocolUdp(t *testing.T) {
largeTestContent := make([]byte, 1199)
_, err = rand.Read(largeTestContent)
assert.NoError(t, err)
go func() {
var acceptConn *utp.Conn
defer func() {
@ -250,7 +252,7 @@ func TestPortalWireProtocol(t *testing.T) {
// create a byte slice of length 1199 and fill it with random data
// this will be used as a test content
largeTestContent := make([]byte, 1199)
largeTestContent := make([]byte, 2000)
_, err = rand.Read(largeTestContent)
assert.NoError(t, err)

View file

@ -1,9 +1,5 @@
package portalwire
import (
"github.com/ethereum/go-ethereum/common/hexutil"
)
// Protocol IDs for the portal protocol.
const (
StateNetwork = "0x500a"
@ -100,18 +96,18 @@ type (
}
)
func getTalkReqOverheadByLen(protocolIdLen int) int {
return 16 + // IV size
55 + // header size
1 + // talkReq msg id
3 + // rlp encoding outer list, max length will be encoded in 2 bytes
9 + // request id (max = 8) + 1 byte from rlp encoding byte string
protocolIdLen + 1 + // + 1 is necessary due to rlp encoding of byte string
3 + // rlp encoding response byte string, max length in 2 bytes
16 // HMAC
}
func getTalkReqOverhead(protocolId string) int {
protocolIdBytes, _ := hexutil.Decode(protocolId)
return getTalkReqOverheadByLen(len(protocolIdBytes))
}
//func getTalkReqOverheadByLen(protocolIdLen int) int {
// return 16 + // IV size
// 55 + // header size
// 1 + // talkReq msg id
// 3 + // rlp encoding outer list, max length will be encoded in 2 bytes
// 9 + // request id (max = 8) + 1 byte from rlp encoding byte string
// protocolIdLen + 1 + // + 1 is necessary due to rlp encoding of byte string
// 3 + // rlp encoding response byte string, max length in 2 bytes
// 16 // HMAC
//}
//
//func getTalkReqOverhead(protocolId string) int {
// protocolIdBytes, _ := hexutil.Decode(protocolId)
// return getTalkReqOverheadByLen(len(protocolIdBytes))
//}