Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setting acceptAddrs in ListenUDP #72

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/throughput/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func main() {
}

if *u {
uConn, err := c.ListenUDP(nil)
uConn, err := c.ListenUDP()
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestTunaSession(t *testing.T) {
t.Fatal(err)
}

uConn, err := c.ListenUDP(nil)
uConn, err := c.ListenUDP()
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func StartUDPListner(numListener int, ch chan string) (tunaSess *ts.TunaSessionC
}()
}()

udpSess, err := tunaSess.ListenUDP(nil)
udpSess, err := tunaSess.ListenUDP()
if err != nil {
log.Println("ListenUDP err ", err)
}
Expand Down
23 changes: 8 additions & 15 deletions udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,24 @@ import (
"time"

"github.com/nknorg/nkn-sdk-go"
"github.com/nknorg/nkngomobile"
"github.com/nknorg/tuna"
)

const (
sendUdpMetaDataRetries = 2 // retries to send udp meta data
)

func (c *TunaSessionClient) ListenUDP(addrsRe *nkngomobile.StringArray) (*UdpSession, error) {
acceptAddrs, err := getAcceptAddrs(addrsRe)
if err != nil {
return nil, err
}
if c.wallet == nil {
return nil, errors.New("ListenUDP wallet is empty")
// Start UDP server listening.
// Because UDP is connectionless, we use TCP to track the connection status.
// So we need to start a TCP server first, and then start a UDP server.
// Meanwhile, Tuna session server hase two modes: TCP only, or TCP + UDP.
func (c *TunaSessionClient) ListenUDP() (*UdpSession, error) {
yilunzhang marked this conversation as resolved.
Show resolved Hide resolved
if len(c.listeners) == 0 {
return nil, errors.New("please call Listen() to start TCP first")
}

c.acceptAddrs = acceptAddrs

if c.listenerUdpSess != nil {
return c.listenerUdpSess, nil
}
c.listenerUdpSess = newUdpSession(c, true)

err = c.startExits()
err := c.startExits()
if err != nil {
return nil, err
}
Expand Down