mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 14:33:52 +00:00
fix:fix lint
Signed-off-by: Chen Kai <281165273grape@gmail.com>
This commit is contained in:
parent
96a89db758
commit
a4e9a7034d
3 changed files with 27 additions and 27 deletions
|
|
@ -7,13 +7,14 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go.uber.org/zap"
|
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/fastcache"
|
"github.com/VictoriaMetrics/fastcache"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover/portalwire"
|
"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 {
|
if contentKeyBitsets.Count() == 0 {
|
||||||
idBuffer := make([]byte, 2)
|
idBuffer := make([]byte, 2)
|
||||||
binary.BigEndian.PutUint16(idBuffer, uint16(0))
|
binary.BigEndian.PutUint16(idBuffer, uint16(0))
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/optimism-java/utp-go"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/optimism-java/utp-go"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/internal/testlog"
|
"github.com/ethereum/go-ethereum/internal/testlog"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
|
@ -57,19 +58,19 @@ func setupLocalPortalNode(addr string, bootNodes []*enode.Node) (*PortalProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPortalWireProtocolUdp(t *testing.T) {
|
func TestPortalWireProtocolUdp(t *testing.T) {
|
||||||
node1, err := setupLocalPortalNode(":7777", nil)
|
node1, err := setupLocalPortalNode(":8777", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
node1.log = testlog.Logger(t, log.LvlTrace)
|
node1.log = testlog.Logger(t, log.LvlTrace)
|
||||||
err = node1.Start()
|
err = node1.Start()
|
||||||
assert.NoError(t, err)
|
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)
|
assert.NoError(t, err)
|
||||||
node2.log = testlog.Logger(t, log.LvlTrace)
|
node2.log = testlog.Logger(t, log.LvlTrace)
|
||||||
err = node2.Start()
|
err = node2.Start()
|
||||||
assert.NoError(t, err)
|
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)
|
assert.NoError(t, err)
|
||||||
node3.log = testlog.Logger(t, log.LvlTrace)
|
node3.log = testlog.Logger(t, log.LvlTrace)
|
||||||
err = node3.Start()
|
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(node2.table.Nodes()))
|
||||||
assert.Equal(t, 2, len(node3.table.Nodes()))
|
assert.Equal(t, 2, len(node3.table.Nodes()))
|
||||||
|
|
||||||
rAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:7777")
|
rAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8777")
|
||||||
lAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:7778")
|
lAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8778")
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(4)
|
wg.Add(4)
|
||||||
|
|
@ -95,6 +96,7 @@ func TestPortalWireProtocolUdp(t *testing.T) {
|
||||||
|
|
||||||
largeTestContent := make([]byte, 1199)
|
largeTestContent := make([]byte, 1199)
|
||||||
_, err = rand.Read(largeTestContent)
|
_, err = rand.Read(largeTestContent)
|
||||||
|
assert.NoError(t, err)
|
||||||
go func() {
|
go func() {
|
||||||
var acceptConn *utp.Conn
|
var acceptConn *utp.Conn
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -250,7 +252,7 @@ func TestPortalWireProtocol(t *testing.T) {
|
||||||
|
|
||||||
// create a byte slice of length 1199 and fill it with random data
|
// create a byte slice of length 1199 and fill it with random data
|
||||||
// this will be used as a test content
|
// this will be used as a test content
|
||||||
largeTestContent := make([]byte, 1199)
|
largeTestContent := make([]byte, 2000)
|
||||||
_, err = rand.Read(largeTestContent)
|
_, err = rand.Read(largeTestContent)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
package portalwire
|
package portalwire
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Protocol IDs for the portal protocol.
|
// Protocol IDs for the portal protocol.
|
||||||
const (
|
const (
|
||||||
StateNetwork = "0x500a"
|
StateNetwork = "0x500a"
|
||||||
|
|
@ -100,18 +96,18 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTalkReqOverheadByLen(protocolIdLen int) int {
|
//func getTalkReqOverheadByLen(protocolIdLen int) int {
|
||||||
return 16 + // IV size
|
// return 16 + // IV size
|
||||||
55 + // header size
|
// 55 + // header size
|
||||||
1 + // talkReq msg id
|
// 1 + // talkReq msg id
|
||||||
3 + // rlp encoding outer list, max length will be encoded in 2 bytes
|
// 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
|
// 9 + // request id (max = 8) + 1 byte from rlp encoding byte string
|
||||||
protocolIdLen + 1 + // + 1 is necessary due to rlp encoding of 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
|
// 3 + // rlp encoding response byte string, max length in 2 bytes
|
||||||
16 // HMAC
|
// 16 // HMAC
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func getTalkReqOverhead(protocolId string) int {
|
//func getTalkReqOverhead(protocolId string) int {
|
||||||
protocolIdBytes, _ := hexutil.Decode(protocolId)
|
// protocolIdBytes, _ := hexutil.Decode(protocolId)
|
||||||
return getTalkReqOverheadByLen(len(protocolIdBytes))
|
// return getTalkReqOverheadByLen(len(protocolIdBytes))
|
||||||
}
|
//}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue