@@ -13,6 +13,7 @@ import (
1313
1414 "github.com/ethereum/go-ethereum/portalnetwork/storage"
1515 "github.com/optimism-java/utp-go"
16+ "github.com/optimism-java/utp-go/libutp"
1617 "github.com/prysmaticlabs/go-bitfield"
1718 "golang.org/x/exp/slices"
1819
@@ -126,19 +127,10 @@ func TestPortalWireProtocolUdp(t *testing.T) {
126127 assert .NoError (t , err )
127128 time .Sleep (12 * time .Second )
128129
129- udpAddrStr1 := fmt .Sprintf ("%s:%d" , node1 .localNode .Node ().IP (), node1 .localNode .Node ().UDP ())
130- udpAddrStr2 := fmt .Sprintf ("%s:%d" , node2 .localNode .Node ().IP (), node2 .localNode .Node ().UDP ())
131-
132- node1Addr , _ := utp .ResolveUTPAddr ("utp" , udpAddrStr1 )
133- node2Addr , _ := utp .ResolveUTPAddr ("utp" , udpAddrStr2 )
134- fmt .Println (udpAddrStr1 )
135- fmt .Println (udpAddrStr2 )
136- fmt .Println (node1Addr )
137- fmt .Println (node2Addr )
138-
139- cid := uint16 (12 )
140- cliSendMsgWithCid := "there are connection id : 12!"
141- cliSendMsgWithRandomCid := "there are connection id: random!"
130+ cid1 := libutp .ReceConnId (12 )
131+ cid2 := libutp .ReceConnId (116 )
132+ cliSendMsgWithCid1 := "there are connection id : 12!"
133+ cliSendMsgWithCid2 := "there are connection id: 116!"
142134
143135 serverEchoWithCid := "accept connection sends back msg: echo"
144136
@@ -156,7 +148,7 @@ func TestPortalWireProtocolUdp(t *testing.T) {
156148 workGroup .Done ()
157149 _ = acceptConn .Close ()
158150 }()
159- acceptConn , err := node1 .Utp .AcceptWithCid (context .Background (), node2 .localNode .ID (), cid )
151+ acceptConn , err := node1 .Utp .AcceptWithCid (context .Background (), node2 .localNode .ID (), cid1 )
160152 if err != nil {
161153 panic (err )
162154 }
@@ -166,30 +158,30 @@ func TestPortalWireProtocolUdp(t *testing.T) {
166158 if err != nil && err != io .EOF {
167159 panic (err )
168160 }
169- assert .Equal (t , cliSendMsgWithCid , string (buf [:n ]))
161+ assert .Equal (t , cliSendMsgWithCid1 , string (buf [:n ]))
170162 _ , err = acceptConn .Write ([]byte (serverEchoWithCid ))
171163 if err != nil {
172164 panic (err )
173165 }
174166 }()
175167 go func () {
176- var randomConnIdConn net.Conn
168+ var connId2Conn net.Conn
177169 defer func () {
178170 workGroup .Done ()
179- _ = randomConnIdConn .Close ()
171+ _ = connId2Conn .Close ()
180172 }()
181- randomConnIdConn , err := node1 .Utp .Accept (context .Background ())
173+ connId2Conn , err := node1 .Utp .AcceptWithCid (context .Background (), node2 . localNode . ID (), cid2 )
182174 if err != nil {
183175 panic (err )
184176 }
185177 buf := make ([]byte , 100 )
186- n , err := randomConnIdConn .Read (buf )
178+ n , err := connId2Conn .Read (buf )
187179 if err != nil && err != io .EOF {
188180 panic (err )
189181 }
190- assert .Equal (t , cliSendMsgWithRandomCid , string (buf [:n ]))
182+ assert .Equal (t , cliSendMsgWithCid2 , string (buf [:n ]))
191183
192- _ , err = randomConnIdConn .Write (largeTestContent )
184+ _ , err = connId2Conn .Write (largeTestContent )
193185 if err != nil {
194186 panic (err )
195187 }
@@ -203,11 +195,11 @@ func TestPortalWireProtocolUdp(t *testing.T) {
203195 _ = connWithConnId .Close ()
204196 }
205197 }()
206- connWithConnId , err = node2 .Utp .DialWithCid (context .Background (), node1 .localNode .Node (), cid )
198+ connWithConnId , err = node2 .Utp .DialWithCid (context .Background (), node1 .localNode .Node (), uint16 ( cid1 . SendId ()) )
207199 if err != nil {
208200 panic (err )
209201 }
210- _ , err = connWithConnId .Write ([]byte ("there are connection id : 12!" ))
202+ _ , err = connWithConnId .Write ([]byte (cliSendMsgWithCid1 ))
211203 if err != nil && err != io .EOF {
212204 panic (err )
213205 }
@@ -219,18 +211,18 @@ func TestPortalWireProtocolUdp(t *testing.T) {
219211 assert .Equal (t , serverEchoWithCid , string (buf [:n ]))
220212 }()
221213 go func () {
222- var randomConnIdConn net.Conn
214+ var ConnId2Conn net.Conn
223215 defer func () {
224216 workGroup .Done ()
225- if randomConnIdConn != nil {
226- _ = randomConnIdConn .Close ()
217+ if ConnId2Conn != nil {
218+ _ = ConnId2Conn .Close ()
227219 }
228220 }()
229- randomConnIdConn , err = node2 .Utp .Dial (context .Background (), node1 .localNode .Node ())
221+ ConnId2Conn , err = node2 .Utp .DialWithCid (context .Background (), node1 .localNode .Node (), uint16 ( cid2 . SendId () ))
230222 if err != nil && err != io .EOF {
231223 panic (err )
232224 }
233- _ , err = randomConnIdConn .Write ([]byte (cliSendMsgWithRandomCid ))
225+ _ , err = ConnId2Conn .Write ([]byte (cliSendMsgWithCid2 ))
234226 if err != nil {
235227 panic (err )
236228 }
@@ -239,7 +231,7 @@ func TestPortalWireProtocolUdp(t *testing.T) {
239231 buf := make ([]byte , 1024 )
240232 for {
241233 var n int
242- n , err = randomConnIdConn .Read (buf )
234+ n , err = ConnId2Conn .Read (buf )
243235 if err != nil {
244236 if errors .Is (err , io .EOF ) {
245237 break
0 commit comments