Skip to content

Commit

Permalink
Upgrade nkn tunnel to support udp
Browse files Browse the repository at this point in the history
Signed-off-by: bill fort <fxbao@hotmail.com>
  • Loading branch information
billfort authored and yilunzhang committed Apr 21, 2023
1 parent 98f4836 commit cd32e8b
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 630 deletions.
7 changes: 4 additions & 3 deletions bin/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"log"
"os"

"github.com/jessevdk/go-flags"
"github.com/nknorg/nconnect"
"github.com/nknorg/nconnect/config"
"log"
"os"
)

func main() {
Expand All @@ -15,7 +16,7 @@ func main() {
}
}()

var opts config.NConfig
var opts config.Opts
_, err := flags.Parse(&opts)
if err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
Expand Down
10 changes: 8 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/nknorg/nconnect/util"
"github.com/nknorg/nkn/v2/common"
"github.com/nknorg/tuna/types"
)

const (
Expand All @@ -34,7 +35,7 @@ func init() {
rand.Seed(time.Now().UnixNano())
}

type NConfig struct {
type Opts struct {
Client bool `short:"c" long:"client" description:"Client mode"`
Server bool `short:"s" long:"server" description:"Server mode"`

Expand All @@ -44,6 +45,8 @@ type NConfig struct {
Address bool `long:"address" description:"Print client address (client mode) or admin address (server mode)"`
WalletAddress bool `long:"wallet-address" description:"Print wallet address (server only)"`
Version bool `long:"version" description:"Print version"`

TunaNode *types.Node
}

type Config struct {
Expand All @@ -60,7 +63,6 @@ type Config struct {
// Cipher config
Cipher string `json:"cipher,omitempty" long:"cipher" description:"Socks proxy cipher. Dummy (no cipher) will not reduce security because NKN tunnel already has end to end encryption." choice:"dummy" choice:"chacha20-ietf-poly1305" choice:"aes-128-gcm" choice:"aes-256-gcm" default:"chacha20-ietf-poly1305"`
Password string `json:"password,omitempty" long:"password" description:"Socks proxy password"`
UDP bool `json:"udp,omitempty" long:"udp" description:"Support udp proxy"`

// Session config
DialTimeout int32 `json:"dialTimeout,omitempty" long:"dial-timeout" description:"dial timeout in milliseconds"`
Expand Down Expand Up @@ -108,6 +110,10 @@ type Config struct {
TunaDisableMeasureBandwidth bool `json:"tunaDisableMeasureBandwidth,omitempty" long:"tuna-disable-measure-bandwidth" description:"(server only) Disable Tuna measure bandwidth when selecting service nodes"`
TunaMeasureStoragePath string `json:"tunaMeasureStoragePath,omitempty" long:"tuna-measure-storage-path" description:"(server only) Path to store Tuna measurement results" default:"."`

// UDP config
UDP bool `json:"udp,omitempty" long:"udp" description:"Support udp proxy"`
UDPIdleTime int32 `json:"udpIdleTime,omitempty" long:"udp-idle-time" description:"UDP connections will be purged after idle time (in seconds). 0 is for no purge" default:"0"`

// Admin config
AdminIdentifier string `json:"adminIdentifier,omitempty" long:"admin-identifier" description:"(server only) Admin NKN client identifier prefix" default:"nConnect"`
AdminHTTPAddr string `json:"adminHttpAddr,omitempty" long:"admin-http" description:"(server only) Admin web GUI listen address (e.g. 127.0.0.1:8000)"`
Expand Down
16 changes: 6 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ require (
github.com/eycorsican/go-tun2socks v1.16.11
github.com/gin-contrib/gzip v0.0.3
github.com/gin-gonic/gin v1.7.7
github.com/imdario/mergo v0.3.13
github.com/imdario/mergo v0.3.15
github.com/jessevdk/go-flags v1.5.0
github.com/nknorg/ncp-go v1.0.6-0.20230228002512-f4cd1740bebd
github.com/nknorg/nkn-sdk-go v1.4.5
github.com/nknorg/nkn-tuna-session v0.2.6-0.20230328055742-9a596c57b4bb
github.com/nknorg/nkn-tunnel v0.3.5-0.20230328060135-8eb315c90047
github.com/nknorg/nkn-sdk-go v1.4.6-0.20230404044330-ad192f36d07e
github.com/nknorg/nkn-tuna-session v0.2.6-0.20230415032955-7a3fc7be9634
github.com/nknorg/nkn-tunnel v0.3.5-0.20230418225220-c505086e1505
github.com/nknorg/nkn/v2 v2.2.0
github.com/nknorg/nkngomobile v0.0.0-20220615081414-671ad1afdfa9
github.com/nknorg/tuna v0.0.0-20230328054959-0bc6eb5bf369
Expand All @@ -21,6 +21,7 @@ require (
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/gaukas/godicttls v0.0.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand Down Expand Up @@ -60,6 +61,7 @@ require (
github.com/rdegges/go-ipify v0.0.0-20150526035502-2d94a6a86c40 // indirect
github.com/refraction-networking/utls v1.3.2 // indirect
github.com/riobard/go-bloom v0.0.0-20200213042214-218e1707c495 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/songgao/water v0.0.0-20190725173103-fd331bda3f4b // indirect
github.com/tdewolff/minify v2.3.6+incompatible // indirect
github.com/tdewolff/parse v2.3.4+incompatible // indirect
Expand All @@ -81,9 +83,3 @@ require (
google.golang.org/protobuf v1.29.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

//replace github.com/nknorg/tuna v0.0.0-20230128070346-2e1102d13fcb => github.com/nknorg/tuna v0.0.0-20230128070346-2e1102d13fcb
//
//replace github.com/nknorg/nkn-tuna-session v0.2.5 => github.com/nknorg/nkn-tuna-session v0.2.6-0.20230129080815-6bcf65132ef1
//
//replace github.com/nknorg/nkn-tunnel v0.3.4 => github.com/nknorg/nkn-tunnel v0.3.5-0.20230129081143-f866961b9676
Loading

0 comments on commit cd32e8b

Please sign in to comment.