Skip to content

Commit e508312

Browse files
committed
feature: code opt
1 parent c1722ac commit e508312

11 files changed

Lines changed: 336 additions & 22 deletions

File tree

build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ BIN=$WORKSPACE/bin/
55
cd $WORKSPACE/notr
66
GOOS=darwin go build -o $BIN/opennotr-client_darwin_amd64
77
GOOS=linux go build -o $BIN/opennotr-client_linux_amd64
8-
GOOS=windows go build -o $BIN/opennotr-client_windows.exe
98
GOARCH=arm GOOS=linux go build -o $BIN/opennotr-client_arm.exe
109
GOARCH=arm64 GOOS=linux go build -o $BIN/opennotr-client_arm64.exe
1110

go.mod

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module github.com/ICKelin/opennotr
2+
3+
go 1.13
4+
5+
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
6+
7+
require (
8+
github.com/coreos/bbolt v1.3.2 // indirect
9+
github.com/coreos/etcd v3.3.22+incompatible
10+
github.com/coreos/go-semver v0.3.0 // indirect
11+
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
12+
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
13+
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
14+
github.com/dustin/go-humanize v1.0.0 // indirect
15+
github.com/gogo/protobuf v1.3.1 // indirect
16+
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
17+
github.com/golang/protobuf v1.4.2 // indirect
18+
github.com/google/btree v1.0.0 // indirect
19+
github.com/google/uuid v1.1.1 // indirect
20+
github.com/gorilla/websocket v1.4.0 // indirect
21+
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect
22+
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
23+
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
24+
github.com/jonboulle/clockwork v0.1.0 // indirect
25+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
26+
github.com/kr/pretty v0.2.0 // indirect
27+
github.com/pelletier/go-toml v1.8.0
28+
github.com/pkg/errors v0.9.1 // indirect
29+
github.com/prometheus/client_golang v1.6.0 // indirect
30+
github.com/prometheus/common v0.10.0 // indirect
31+
github.com/soheilhy/cmux v0.1.4 // indirect
32+
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
33+
github.com/stretchr/testify v1.5.1 // indirect
34+
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
35+
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
36+
go.etcd.io/bbolt v1.3.3 // indirect
37+
go.uber.org/zap v1.15.0 // indirect
38+
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 // indirect
39+
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
40+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
41+
golang.org/x/text v0.3.2 // indirect
42+
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
43+
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4 // indirect
44+
google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect
45+
google.golang.org/grpc v1.29.1 // indirect
46+
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
47+
sigs.k8s.io/yaml v1.2.0 // indirect
48+
)

go.sum

Lines changed: 266 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package client
1+
package main
22

33
import (
44
"context"
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/ICKelin/opennotr/device"
10-
"github.com/ICKelin/opennotr/notr/config"
1110
"github.com/ICKelin/opennotr/proto"
1211
)
1312

@@ -25,7 +24,7 @@ type Client struct {
2524
grpc int
2625
}
2726

28-
func New(cfg *config.Config) *Client {
27+
func NewClient(cfg *Config) *Client {
2928
return &Client{
3029
srv: cfg.ServerAddr,
3130
key: cfg.Key,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package config
1+
package main
22

33
import (
44
"encoding/json"
@@ -16,7 +16,7 @@ type Config struct {
1616
Grpc int `toml:"grpc"`
1717
}
1818

19-
func Parse(path string) (*Config, error) {
19+
func ParseConfig(path string) (*Config, error) {
2020
cnt, err := ioutil.ReadFile(path)
2121
if err != nil {
2222
return nil, err

notr/config.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
serverAddr="holenat.net:9092"
1+
serverAddr="demo.notr.tech:10100"
22
key="client server exchange key"
33
http=8080
44
https=4443
55
grpc=8800
6+
domain="47.115.82.137"

notr/gtun_linux_amd64

7.96 MB
Binary file not shown.

notr/main.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@ package main
33
import (
44
"flag"
55
"log"
6-
7-
"github.com/ICKelin/opennotr/notr/client"
8-
"github.com/ICKelin/opennotr/notr/config"
96
)
107

118
func main() {
129
confpath := flag.String("conf", "", "config file path")
1310
flag.Parse()
1411

15-
cfg, err := config.Parse(*confpath)
12+
cfg, err := ParseConfig(*confpath)
1613
if err != nil {
1714
log.Println(err)
1815
return
1916
}
2017

21-
cli := client.New(cfg)
18+
cli := NewClient(cfg)
2219
cli.Run()
2320
}

notrd/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ func main() {
4949
p := proxy.New(cfg.ProxyConfig.ConfigDir, cfg.ProxyConfig.CertFile, cfg.ProxyConfig.KeyFile)
5050

5151
// 初始化域名解析配置
52-
resolver, err := server.NewResolve(cfg.ResolverConfig.EtcdEndpoints)
53-
if err != nil {
54-
log.Println(err)
55-
return
52+
var resolver *server.Resolver
53+
if len(cfg.ResolverConfig.EtcdEndpoints) > 0 {
54+
resolver, err = server.NewResolve(cfg.ResolverConfig.EtcdEndpoints)
55+
if err != nil {
56+
log.Println(err)
57+
return
58+
}
5659
}
57-
5860
// 启动tcp server
5961
s := server.New(cfg.ServerConfig, gw, p, dev, resolver)
6062
fmt.Println(s.ListenAndServe())

notrd/server/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
"time"
99

10-
"go.etcd.io/etcd/clientv3"
10+
"github.com/coreos/etcd/clientv3"
1111
)
1212

1313
type record struct {

0 commit comments

Comments
 (0)