Skip to content

Commit

Permalink
feature: code opt
Browse files Browse the repository at this point in the history
  • Loading branch information
ICKelin committed Feb 26, 2021
1 parent c1722ac commit e508312
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 22 deletions.
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ BIN=$WORKSPACE/bin/
cd $WORKSPACE/notr
GOOS=darwin go build -o $BIN/opennotr-client_darwin_amd64
GOOS=linux go build -o $BIN/opennotr-client_linux_amd64
GOOS=windows go build -o $BIN/opennotr-client_windows.exe
GOARCH=arm GOOS=linux go build -o $BIN/opennotr-client_arm.exe
GOARCH=arm64 GOOS=linux go build -o $BIN/opennotr-client_arm64.exe

Expand Down
48 changes: 48 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module github.com/ICKelin/opennotr

go 1.13

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0

require (
github.com/coreos/bbolt v1.3.2 // indirect
github.com/coreos/etcd v3.3.22+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/gorilla/websocket v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/pelletier/go-toml v1.8.0
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.6.0 // indirect
github.com/prometheus/common v0.10.0 // indirect
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/stretchr/testify v1.5.1 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.3 // indirect
go.uber.org/zap v1.15.0 // indirect
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4 // indirect
google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect
google.golang.org/grpc v1.29.1 // indirect
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
266 changes: 266 additions & 0 deletions go.sum

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions notr/client/client.go → notr/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package main

import (
"context"
Expand All @@ -7,7 +7,6 @@ import (
"time"

"github.com/ICKelin/opennotr/device"
"github.com/ICKelin/opennotr/notr/config"
"github.com/ICKelin/opennotr/proto"
)

Expand All @@ -25,7 +24,7 @@ type Client struct {
grpc int
}

func New(cfg *config.Config) *Client {
func NewClient(cfg *Config) *Client {
return &Client{
srv: cfg.ServerAddr,
key: cfg.Key,
Expand Down
4 changes: 2 additions & 2 deletions notr/config/config.go → notr/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package main

import (
"encoding/json"
Expand All @@ -16,7 +16,7 @@ type Config struct {
Grpc int `toml:"grpc"`
}

func Parse(path string) (*Config, error) {
func ParseConfig(path string) (*Config, error) {
cnt, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion notr/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
serverAddr="holenat.net:9092"
serverAddr="demo.notr.tech:10100"
key="client server exchange key"
http=8080
https=4443
grpc=8800
domain="47.115.82.137"
Binary file added notr/gtun_linux_amd64
Binary file not shown.
7 changes: 2 additions & 5 deletions notr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ package main
import (
"flag"
"log"

"github.com/ICKelin/opennotr/notr/client"
"github.com/ICKelin/opennotr/notr/config"
)

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

cfg, err := config.Parse(*confpath)
cfg, err := ParseConfig(*confpath)
if err != nil {
log.Println(err)
return
}

cli := client.New(cfg)
cli := NewClient(cfg)
cli.Run()
}
12 changes: 7 additions & 5 deletions notrd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ func main() {
p := proxy.New(cfg.ProxyConfig.ConfigDir, cfg.ProxyConfig.CertFile, cfg.ProxyConfig.KeyFile)

// 初始化域名解析配置
resolver, err := server.NewResolve(cfg.ResolverConfig.EtcdEndpoints)
if err != nil {
log.Println(err)
return
var resolver *server.Resolver
if len(cfg.ResolverConfig.EtcdEndpoints) > 0 {
resolver, err = server.NewResolve(cfg.ResolverConfig.EtcdEndpoints)
if err != nil {
log.Println(err)
return
}
}

// 启动tcp server
s := server.New(cfg.ServerConfig, gw, p, dev, resolver)
fmt.Println(s.ListenAndServe())
Expand Down
2 changes: 1 addition & 1 deletion notrd/server/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"go.etcd.io/etcd/clientv3"
"github.com/coreos/etcd/clientv3"
)

type record struct {
Expand Down
10 changes: 6 additions & 4 deletions notrd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ func (s *Server) onConn(conn net.Conn) {
// 如果使用内网模式,域名解析为vip,需要启动客户端才能访问,安全性较好
// 如果使用公网模式,域名解析为public_ip公网地址,通过公网服务器即可访问,安全性较差
// 目前只支持公网模式
err = s.resolver.ApplyDomain(auth.Domain, publicIP())
if err != nil {
log.Printf("resolve domain fail: %v\n", err)
return
if s.resolver != nil {
err = s.resolver.ApplyDomain(auth.Domain, publicIP())
if err != nil {
log.Printf("resolve domain fail: %v\n", err)
return
}
}

s.p.Add(auth.HTTP, auth.HTTPS, auth.Grpc, auth.Domain, vip)
Expand Down

0 comments on commit e508312

Please sign in to comment.