mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
fix: update utp-go version and modify test case
This commit is contained in:
parent
b724ba2b79
commit
da7196970f
4 changed files with 29 additions and 25 deletions
4
go.mod
4
go.mod
|
|
@ -53,7 +53,7 @@ require (
|
|||
github.com/mattn/go-isatty v0.0.17
|
||||
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/optimism-java/utp-go v0.0.0-20231114114639-92925ba7e35e
|
||||
github.com/optimism-java/utp-go v0.0.0-20231203033001-5a531e1e11a0
|
||||
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
|
||||
github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7
|
||||
|
|
@ -71,7 +71,7 @@ require (
|
|||
golang.org/x/crypto v0.15.0
|
||||
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
|
||||
golang.org/x/sync v0.5.0
|
||||
golang.org/x/sys v0.14.0
|
||||
golang.org/x/sys v0.15.0
|
||||
golang.org/x/text v0.14.0
|
||||
golang.org/x/time v0.3.0
|
||||
golang.org/x/tools v0.15.0
|
||||
|
|
|
|||
8
go.sum
8
go.sum
|
|
@ -490,8 +490,8 @@ github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
|||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/optimism-java/utp-go v0.0.0-20231114114639-92925ba7e35e h1:61Mw2nE4trMg/Ze/0oFD5o5yKog2UuLUlbUnBS0lCh8=
|
||||
github.com/optimism-java/utp-go v0.0.0-20231114114639-92925ba7e35e/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
|
||||
github.com/optimism-java/utp-go v0.0.0-20231203033001-5a531e1e11a0 h1:fSjUuzS7gI3IXz5mo8opUlK+9UktElRy1MH5EweLg2k=
|
||||
github.com/optimism-java/utp-go v0.0.0-20231203033001-5a531e1e11a0/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM=
|
||||
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
|
||||
|
|
@ -793,8 +793,8 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ func (p *PortalProtocol) setupUDPListening() (*net.UDPConn, error) {
|
|||
// }
|
||||
//}
|
||||
|
||||
p.packetRouter = utp.NewSocketRouter(
|
||||
p.packetRouter = utp.NewPacketRouter(
|
||||
func(buf []byte, addr *net.UDPAddr) (int, error) {
|
||||
nodes := p.table.Nodes()
|
||||
var target *enode.Node
|
||||
|
|
@ -233,7 +233,7 @@ func (p *PortalProtocol) setupUDPListening() (*net.UDPConn, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.utpSm, err = utp.NewSocketManager("utp", laddr, utp.WithLogger(logger.Named(listenAddr)), utp.WithPacketRouter(p.packetRouter), utp.WithBlockPacketCount(50), utp.WithMaxPacketSize(1145))
|
||||
p.utpSm, err = utp.NewSocketManagerWithOptions("utp", laddr, utp.WithLogger(logger.Named(listenAddr)), utp.WithPacketRouter(p.packetRouter), utp.WithMaxPacketSize(1145))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,39 +84,40 @@ 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:8777")
|
||||
lAddr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8778")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(4)
|
||||
node1Addr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8777")
|
||||
node2Addr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8778")
|
||||
node3Addr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8779")
|
||||
|
||||
cid := uint32(12)
|
||||
cliSendMsgWithCid := "there are connection id : 12!"
|
||||
cliSendMsgWithRandomCid := "there are connection id: random!"
|
||||
|
||||
//
|
||||
serverEchoWithCid := "accept connection sends back msg: echo"
|
||||
//serverEchoWithRandomCid := "ccept connection with random cid sends msg: echo"
|
||||
|
||||
largeTestContent := make([]byte, 1199)
|
||||
_, err = rand.Read(largeTestContent)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(4)
|
||||
go func() {
|
||||
var acceptConn *utp.Conn
|
||||
defer func() {
|
||||
wg.Done()
|
||||
_ = acceptConn.Close()
|
||||
}()
|
||||
acceptConn, err := node1.utp.AcceptUTPWithConnId(cid)
|
||||
acceptConn, err := node3.utp.AcceptUTPWithConnId(cid)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
buf := make([]byte, 100)
|
||||
n, err := acceptConn.Read(buf)
|
||||
if err != nil {
|
||||
if err != nil && err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
assert.Equal(t, cliSendMsgWithCid, string(buf[:n]))
|
||||
acceptConn.Write([]byte(serverEchoWithCid))
|
||||
_, _ = acceptConn.Write([]byte(serverEchoWithCid))
|
||||
}()
|
||||
go func() {
|
||||
var randomConnIdConn net.Conn
|
||||
|
|
@ -130,31 +131,33 @@ func TestPortalWireProtocolUdp(t *testing.T) {
|
|||
}
|
||||
buf := make([]byte, 100)
|
||||
n, err := randomConnIdConn.Read(buf)
|
||||
if err != nil {
|
||||
if err != nil && err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
assert.Equal(t, cliSendMsgWithRandomCid, string(buf[:n]))
|
||||
|
||||
randomConnIdConn.Write(largeTestContent)
|
||||
_, _ = randomConnIdConn.Write(largeTestContent)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
var connWithConnId net.Conn
|
||||
defer func() {
|
||||
wg.Done()
|
||||
//_ = connWithConnId.Close()
|
||||
if connWithConnId != nil {
|
||||
_ = connWithConnId.Close()
|
||||
}
|
||||
}()
|
||||
connWithConnId, err := utp.DialUTPOptions("utp", lAddr, rAddr, utp.WithConnId(cid), utp.WithSocketManager(node2.utpSm))
|
||||
connWithConnId, err := utp.DialUTPOptions("utp", node2Addr, node3Addr, utp.WithConnId(cid), utp.WithSocketManager(node2.utpSm))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = connWithConnId.Write([]byte("there are connection id : 12!"))
|
||||
if err != nil {
|
||||
if err != nil && err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
buf := make([]byte, 100)
|
||||
n, err := connWithConnId.Read(buf)
|
||||
if err != nil {
|
||||
if err != nil && err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
assert.Equal(t, serverEchoWithCid, string(buf[:n]))
|
||||
|
|
@ -165,8 +168,8 @@ func TestPortalWireProtocolUdp(t *testing.T) {
|
|||
wg.Done()
|
||||
//_ = randomConnIdConn.Close()
|
||||
}()
|
||||
randomConnIdConn, err := utp.DialUTPOptions("utp", lAddr, rAddr, utp.WithSocketManager(node2.utpSm))
|
||||
if err != nil {
|
||||
randomConnIdConn, err := utp.DialUTPOptions("utp", node2Addr, node1Addr, utp.WithSocketManager(node2.utpSm))
|
||||
if err != nil && err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
_, err = randomConnIdConn.Write([]byte(cliSendMsgWithRandomCid))
|
||||
|
|
@ -189,6 +192,7 @@ func TestPortalWireProtocolUdp(t *testing.T) {
|
|||
assert.Equal(t, largeTestContent, data)
|
||||
}()
|
||||
wg.Wait()
|
||||
fmt.Println("done")
|
||||
}
|
||||
|
||||
func TestPortalWireProtocol(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue