-
Notifications
You must be signed in to change notification settings - Fork 1
/
conn_udp_test.go
64 lines (48 loc) · 1002 Bytes
/
conn_udp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: 2023 Steffen Vogel <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package rosenpass
import (
"net"
"testing"
"github.com/stretchr/testify/require"
)
func TestUDPConn(t *testing.T) {
require := require.New(t)
spk, _, err := generateStaticKeyPair()
require.NoError(err)
ep := net.UDPAddr{
IP: net.IPv6loopback,
Port: 1234,
}
p := &peer{
spkt: spk,
endpoint: (*UDPEndpoint)(&ep),
}
c, err := NewUDPConn([]*net.UDPAddr{
{
Port: 1234,
},
})
require.NoError(err)
sid, err := generateSessionID()
require.NoError(err)
recvFncs, err := c.Open()
require.NoError(err)
pls := make(chan payload)
for _, recvFnc := range recvFncs {
go func(recvFnc ReceiveFunc) {
pl, _, err := recvFnc(spk)
require.NoError(err)
pls <- pl
}(recvFnc)
}
pl := &emptyData{
sid: sid,
}
err = c.Send(pl, spk, p.endpoint)
require.NoError(err)
edr := <-pls
require.Equal(edr, pl)
err = c.Close()
require.NoError(err)
}