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

Update testcase for packet loss when multiple client transfer data #58

Merged
merged 2 commits into from
Mar 21, 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
22 changes: 22 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Go

on:
[ push, pull_request ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.2

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./tests/session_test.go
24 changes: 11 additions & 13 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/nknorg/tuna/types"
"io"
"log"
"net"
Expand Down Expand Up @@ -60,6 +61,8 @@ type TunaSessionClient struct {
connCount map[string]int
closedSessionKey *gocache.Cache
isClosed bool

tunaNode *types.Node
}

func NewTunaSessionClient(clientAccount *nkn.Account, m *nkn.MultiClient, wallet *nkn.Wallet, config *Config) (*TunaSessionClient, error) {
Expand Down Expand Up @@ -827,6 +830,10 @@ func (c *TunaSessionClient) startExits() error {
return err
}

if c.tunaNode != nil {
exits[i].SetRemoteNode(c.tunaNode)
}

go func(te *tuna.TunaExit) {
select {
case <-te.OnConnect.C:
Expand Down Expand Up @@ -958,19 +965,6 @@ func (c *TunaSessionClient) DialUDPWithConfig(remoteAddr string, config *nkn.Dia
return udpConn, nil
}

func (c *TunaSessionClient) ServicePort() (int, error) {
for _, te := range c.tunaExits {
ip := te.GetReverseIP().String()
ports := te.GetReverseTCPPorts()
if len(ip) > 0 && len(ports) > 0 {
if len(te.ReverseMetadata.ServiceUdp) > 0 {
return int(te.ReverseMetadata.ServiceUdp[0]), nil
}
}
}
return 0, errors.New("no tuna exit available")
}

func (c *TunaSessionClient) dialAConn(ctx context.Context, remoteAddr string, sessionID []byte, i int, addr *PubAddr, config *nkn.DialConfig) (conn *Conn, err error) {
if addr == nil || len(addr.IP) == 0 || addr.Port == 0 {
return nil, fmt.Errorf("dialAConn wrong params addr")
Expand Down Expand Up @@ -1083,3 +1077,7 @@ func (c *TunaSessionClient) IsNcpSessClosed(sessKey string) bool {
}
return false
}

func (c *TunaSessionClient) SetTunaNode(node *types.Node) {
c.tunaNode = node
}
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ go 1.20
require (
github.com/imdario/mergo v0.3.13
github.com/nknorg/ncp-go v1.0.6-0.20230228002512-f4cd1740bebd
github.com/nknorg/nkn-sdk-go v1.4.3
github.com/nknorg/nkn/v2 v2.1.8
github.com/nknorg/nkn-sdk-go v1.4.4
github.com/nknorg/nkn/v2 v2.2.0
github.com/nknorg/nkngomobile v0.0.0-20220615081414-671ad1afdfa9
github.com/nknorg/tuna v0.0.0-20230307074911-ced36707f273
github.com/nknorg/tuna v0.0.0-20230321055416-b949e26142b7
github.com/patrickmn/go-cache v2.1.0+incompatible
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
google.golang.org/protobuf v1.28.1
golang.org/x/crypto v0.7.0
google.golang.org/protobuf v1.29.1
)

require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/itchyny/base58-go v0.0.5 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/itchyny/base58-go v0.2.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/nknorg/encrypted-stream v1.0.1 // indirect
github.com/nknorg/encrypted-stream v1.0.2-0.20230320101720-9891f770de86 // indirect
github.com/oschwald/geoip2-golang v1.4.0 // indirect
github.com/oschwald/maxminddb-golang v1.6.0 // indirect
github.com/pbnjay/memory v0.0.0-20190104145345-974d429e7ae4 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rdegges/go-ipify v0.0.0-20150526035502-2d94a6a86c40 // indirect
github.com/xtaci/smux v2.0.1+incompatible // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c // indirect
golang.org/x/sys v0.6.0 // indirect
)
Loading