Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grpc Gun Transport #757

Merged
merged 15 commits into from
Mar 11, 2021
Prev Previous commit
Next Next commit
various bug fix for gun:grpc transport
  • Loading branch information
xiaokangwang committed Mar 2, 2021
commit d179e48eaa8133350faf629ba9061bf296b6b654
2 changes: 2 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ func (p TransportProtocol) Build() (string, error) {
return "domainsocket", nil
case "quic":
return "quic", nil
case "gun":
return "gun", nil
default:
return "", newError("Config: unknown transport protocol: ", p)
}
Expand Down
1 change: 1 addition & 0 deletions main/distro/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

// Transports
_ "github.com/v2fly/v2ray-core/v4/transport/internet/domainsocket"
_ "github.com/v2fly/v2ray-core/v4/transport/internet/grpc"
_ "github.com/v2fly/v2ray-core/v4/transport/internet/http"
_ "github.com/v2fly/v2ray-core/v4/transport/internet/kcp"
_ "github.com/v2fly/v2ray-core/v4/transport/internet/quic"
Expand Down
11 changes: 11 additions & 0 deletions transport/internet/grpc/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
package grpc

import (
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/transport/internet"
)

const protocolName = "gun"

func init() {
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
return new(Config)
}))
}
5 changes: 3 additions & 2 deletions transport/internet/grpc/encoding/clientConn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func (s *ClientConn) Read(b []byte) (n int, err error) {
}
n, err = s.reader.Read(b)
if err == io.EOF {
return 0, nil
s.reader = nil
return n, nil
}
return 0, err
return n, err
}

func (s *ClientConn) Write(b []byte) (n int, err error) {
Expand Down
17 changes: 11 additions & 6 deletions transport/internet/grpc/encoding/serverconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func (s *ServerConn) Read(b []byte) (n int, err error) {
}
n, err = s.reader.Read(b)
if err == io.EOF {
return 0, nil
s.reader = nil
return n, nil
}
return 0, err
return n, err
}

func (s *ServerConn) Write(b []byte) (n int, err error) {
Expand All @@ -49,19 +50,23 @@ func (s ServerConn) LocalAddr() net.Addr {
}

func (s ServerConn) RemoteAddr() net.Addr {
panic("implement me")
newError("gun transport do not support get remote address").AtWarning().WriteToLog()
return &net.UnixAddr{
Name: "@placeholder",
Net: "unix",
}
}

func (s ServerConn) SetDeadline(t time.Time) error {
panic("implement me")
return nil
}

func (s ServerConn) SetReadDeadline(t time.Time) error {
panic("implement me")
return nil
}

func (s ServerConn) SetWriteDeadline(t time.Time) error {
panic("implement me")
return nil
}

func NewServerConn(server GunService_TunServer, over context.CancelFunc) *ServerConn {
Expand Down