mirror of
https://github.com/ICKelin/opennotr.git
synced 2026-04-22 15:17:10 +08:00
feature: use smux instead of yamux
This commit is contained in:
@@ -23,15 +23,14 @@ require (
|
||||
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/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864
|
||||
github.com/jonboulle/clockwork v0.1.0 // indirect
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
|
||||
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0
|
||||
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
|
||||
github.com/xtaci/smux v2.0.1+incompatible
|
||||
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
|
||||
|
||||
@@ -102,8 +102,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864 h1:Y4V+SFe7d3iH+9pJCoeWIOS5/xBJIFsltS7E+KJSsJY=
|
||||
github.com/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
@@ -177,8 +175,6 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8=
|
||||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E=
|
||||
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
@@ -195,6 +191,8 @@ github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnD
|
||||
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/xtaci/smux v2.0.1+incompatible h1:4NrCD5VzuFktMCxK08IShR0C5vKyNICJRShUzvk0U34=
|
||||
github.com/xtaci/smux v2.0.1+incompatible/go.mod h1:f+nYm6SpuHMy/SH0zpbvAFHT1QoMcgLOsWcFip5KfPw=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
|
||||
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
|
||||
|
||||
+5
-5
@@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ICKelin/opennotr/internal/proto"
|
||||
"github.com/hashicorp/yamux"
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -76,7 +76,7 @@ func (c *Client) Run() {
|
||||
log.Println("vhost:", auth.Vip)
|
||||
log.Println("domain:", auth.Domain)
|
||||
|
||||
mux, err := yamux.Client(conn, nil)
|
||||
mux, err := smux.Client(conn, nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
time.Sleep(time.Second * 3)
|
||||
@@ -98,7 +98,7 @@ func (c *Client) Run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) handleStream(stream *yamux.Stream) {
|
||||
func (c *Client) handleStream(stream *smux.Stream) {
|
||||
lenbuf := make([]byte, 2)
|
||||
_, err := stream.Read(lenbuf)
|
||||
if err != nil {
|
||||
@@ -130,7 +130,7 @@ func (c *Client) handleStream(stream *yamux.Stream) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) tcpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
|
||||
func (c *Client) tcpProxy(stream *smux.Stream, p *proto.ProxyProtocol) {
|
||||
addr := fmt.Sprintf("%s:%s", p.DstIP, p.DstPort)
|
||||
remoteConn, err := net.DialTimeout("tcp", addr, time.Second*10)
|
||||
if err != nil {
|
||||
@@ -157,7 +157,7 @@ func (c *Client) tcpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
|
||||
io.CopyBuffer(stream, remoteConn, buf)
|
||||
}
|
||||
|
||||
func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
|
||||
func (c *Client) udpProxy(stream *smux.Stream, p *proto.ProxyProtocol) {
|
||||
addr := fmt.Sprintf("%s:%s", p.DstIP, p.DstPort)
|
||||
raddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/ICKelin/opennotr/internal/logs"
|
||||
"github.com/ICKelin/opennotr/internal/proto"
|
||||
"github.com/ICKelin/opennotr/opennotrd/plugin"
|
||||
"github.com/hashicorp/yamux"
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -148,9 +148,9 @@ func (s *Server) onConn(conn net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
mux, err := yamux.Server(conn, nil)
|
||||
mux, err := smux.Server(conn, nil)
|
||||
if err != nil {
|
||||
logs.Error("yamux server fail:%v", err)
|
||||
logs.Error("smux server fail:%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package core
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/yamux"
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
var sessionMgr = &SessionManager{}
|
||||
@@ -20,12 +20,12 @@ func GetSessionManager() *SessionManager {
|
||||
|
||||
// Session defines each opennotr_client to opennotr_server connection
|
||||
type Session struct {
|
||||
conn *yamux.Session
|
||||
conn *smux.Session
|
||||
rxbytes uint64
|
||||
txbytes uint64
|
||||
}
|
||||
|
||||
func newSession(conn *yamux.Session, vip string) *Session {
|
||||
func newSession(conn *smux.Session, vip string) *Session {
|
||||
return &Session{
|
||||
conn: conn,
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/yamux"
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -50,7 +50,7 @@ func runBackend() {
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
sess, err := yamux.Client(conn, nil)
|
||||
sess, err := smux.Client(conn, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func runserver(listener net.Listener) {
|
||||
}
|
||||
|
||||
go func() {
|
||||
sess, err := yamux.Server(conn, nil)
|
||||
sess, err := smux.Server(conn, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/ICKelin/opennotr/internal/logs"
|
||||
"github.com/hashicorp/yamux"
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -24,7 +24,7 @@ var (
|
||||
)
|
||||
|
||||
type udpSession struct {
|
||||
stream *yamux.Stream
|
||||
stream *smux.Stream
|
||||
lastActive time.Time
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ func (f *UDPForward) Serve(lconn *net.UDPConn) error {
|
||||
}
|
||||
|
||||
// forwardUDP reads from stream and write to tofd via rawsocket
|
||||
func (f *UDPForward) forwardUDP(stream *yamux.Stream, sessionKey string, fromaddr, toaddr *net.UDPAddr) {
|
||||
func (f *UDPForward) forwardUDP(stream *smux.Stream, sessionKey string, fromaddr, toaddr *net.UDPAddr) {
|
||||
defer stream.Close()
|
||||
defer func() {
|
||||
f.udpsessLock.Lock()
|
||||
|
||||
Reference in New Issue
Block a user