mirror of
https://github.com/ICKelin/opennotr.git
synced 2025-09-26 20:01:13 +08:00
refactor: change project layout
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import "github.com/ICKelin/opennotr/opennotrd/core"
|
||||
import "github.com/ICKelin/opennotr/opennotrd"
|
||||
|
||||
func main() {
|
||||
core.Run()
|
||||
opennotrd.Run()
|
||||
}
|
||||
|
@@ -1,10 +1,23 @@
|
||||
serverAddr: "demo.notr.tech:10100"
|
||||
key: "client server exchange key"
|
||||
domain: "cloud.dahuizong.com"
|
||||
http: 8080
|
||||
https: 8080
|
||||
grpc: 50052
|
||||
tcp:
|
||||
2222: 22
|
||||
udp:
|
||||
53: 53
|
||||
forwards:
|
||||
- protocol: tcp
|
||||
ports:
|
||||
2222: 22
|
||||
|
||||
- protocol: udp
|
||||
ports:
|
||||
53: 53
|
||||
|
||||
- protocol: http
|
||||
ports:
|
||||
0: 8080
|
||||
|
||||
- protocol: https
|
||||
ports:
|
||||
0: 8081
|
||||
|
||||
- protocol: h2c
|
||||
ports:
|
||||
0: 50052
|
0
example/README.md
Normal file
0
example/README.md
Normal file
@@ -16,26 +16,18 @@ type writeReq struct {
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
srv string
|
||||
key string
|
||||
domain string
|
||||
http int
|
||||
https int
|
||||
grpc int
|
||||
tcps map[int]int
|
||||
udps map[int]int
|
||||
srv string
|
||||
key string
|
||||
domain string
|
||||
forwards []proto.ForwardItem
|
||||
}
|
||||
|
||||
func NewClient(cfg *Config) *Client {
|
||||
return &Client{
|
||||
srv: cfg.ServerAddr,
|
||||
key: cfg.Key,
|
||||
domain: cfg.Domain,
|
||||
http: cfg.HTTP,
|
||||
https: cfg.HTTPS,
|
||||
grpc: cfg.Grpc,
|
||||
tcps: cfg.TCPs,
|
||||
udps: cfg.UDPs,
|
||||
srv: cfg.ServerAddr,
|
||||
key: cfg.Key,
|
||||
domain: cfg.Domain,
|
||||
forwards: cfg.Forwards,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,13 +41,9 @@ func (c *Client) Run() {
|
||||
}
|
||||
|
||||
c2sauth := &proto.C2SAuth{
|
||||
Key: c.key,
|
||||
Domain: c.domain,
|
||||
HTTP: c.http,
|
||||
HTTPS: c.https,
|
||||
Grpc: c.grpc,
|
||||
TCPs: c.tcps,
|
||||
UDPs: c.udps,
|
||||
Key: c.key,
|
||||
Domain: c.domain,
|
||||
Forward: c.forwards,
|
||||
}
|
||||
|
||||
err = proto.WriteJSON(conn, proto.CmdAuth, c2sauth)
|
||||
|
@@ -4,18 +4,15 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/ICKelin/opennotr/pkg/proto"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ServerAddr string `yaml:"serverAddr"`
|
||||
Key string `yaml:"key"`
|
||||
Domain string `yaml:"domain"`
|
||||
HTTP int `yaml:"http"`
|
||||
HTTPS int `yaml:"https"`
|
||||
Grpc int `yaml:"grpc"`
|
||||
TCPs map[int]int `yaml:"tcp"`
|
||||
UDPs map[int]int `yaml:"udp"`
|
||||
ServerAddr string `yaml:"serverAddr"`
|
||||
Key string `yaml:"key"`
|
||||
Domain string `yaml:"domain"`
|
||||
Forwards []proto.ForwardItem `yaml:"forwards"`
|
||||
}
|
||||
|
||||
func ParseConfig(path string) (*Config, error) {
|
||||
|
8
opennotrd/plugins.go
Normal file
8
opennotrd/plugins.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package opennotrd
|
||||
|
||||
import (
|
||||
// plugin import
|
||||
_ "github.com/ICKelin/opennotr/opennotrd/plugin/restyproxy"
|
||||
_ "github.com/ICKelin/opennotr/opennotrd/plugin/tcpproxy"
|
||||
_ "github.com/ICKelin/opennotr/opennotrd/plugin/udpproxy"
|
||||
)
|
@@ -1,25 +1,21 @@
|
||||
package core
|
||||
package opennotrd
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/ICKelin/opennotr/opennotrd/core"
|
||||
"github.com/ICKelin/opennotr/opennotrd/plugin"
|
||||
"github.com/ICKelin/opennotr/pkg/device"
|
||||
"github.com/ICKelin/opennotr/pkg/logs"
|
||||
|
||||
// plugin import
|
||||
_ "github.com/ICKelin/opennotr/opennotrd/plugin/restyproxy"
|
||||
_ "github.com/ICKelin/opennotr/opennotrd/plugin/tcpproxy"
|
||||
_ "github.com/ICKelin/opennotr/opennotrd/plugin/udpproxy"
|
||||
)
|
||||
|
||||
func Run() {
|
||||
confpath := flag.String("conf", "", "config file path")
|
||||
flag.Parse()
|
||||
|
||||
cfg, err := ParseConfig(*confpath)
|
||||
cfg, err := core.ParseConfig(*confpath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
@@ -29,6 +25,7 @@ func Run() {
|
||||
logs.Info("config: %v", cfg)
|
||||
|
||||
// initial tun device
|
||||
// tun device create vpn tunnel between opennotrd and opennotr clients.
|
||||
dev, err := device.New()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -50,20 +47,25 @@ func Run() {
|
||||
|
||||
// create dhcp manager
|
||||
// dhcp Select/Release ip for opennotr client
|
||||
dhcp, err := NewDHCP(cfg.DHCPConfig.Cidr)
|
||||
dhcp, err := core.NewDHCP(cfg.DHCPConfig.Cidr)
|
||||
if err != nil {
|
||||
logs.Error("new dhcp module fail: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
plugin.Setup(cfg.Plugins)
|
||||
// setup all plugin base on plugin json configuration
|
||||
err = plugin.Setup(cfg.Plugins)
|
||||
if err != nil {
|
||||
logs.Error("setup plugin fail: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// initial resolver
|
||||
// currently resolver use coredns and etcd
|
||||
// our resolver just write DOMAIN => VIP record to etcd
|
||||
var resolver *Resolver
|
||||
var resolver *core.Resolver
|
||||
if len(cfg.ResolverConfig.EtcdEndpoints) > 0 {
|
||||
resolver, err = NewResolve(cfg.ResolverConfig.EtcdEndpoints)
|
||||
resolver, err = core.NewResolve(cfg.ResolverConfig.EtcdEndpoints)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
@@ -72,6 +74,6 @@ func Run() {
|
||||
|
||||
// run tunnel tcp server, it will cause tcp over tcp problems
|
||||
// it may changed to udp later.
|
||||
s := NewServer(cfg.ServerConfig, dhcp, dev, resolver)
|
||||
s := core.NewServer(cfg.ServerConfig, dhcp, dev, resolver)
|
||||
fmt.Println(s.ListenAndServe())
|
||||
}
|
Reference in New Issue
Block a user