1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-28 10:15:23 +00:00

InboundHandler.Proxy()

This commit is contained in:
Darien Raymond 2017-01-15 00:57:06 +01:00
parent 34a2ae0ab7
commit f2b1d5b60c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 42 additions and 6 deletions

View File

@ -40,6 +40,9 @@ func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
if meta == nil { if meta == nil {
return nil, errors.New("Dokodemo: No outbound meta in context.") return nil, errors.New("Dokodemo: No outbound meta in context.")
} }
if config.NetworkList == nil || config.NetworkList.Size() == 0 {
return nil, errors.New("DokodemoDoor: No network specified.")
}
d := &DokodemoDoor{ d := &DokodemoDoor{
config: config, config: config,
address: config.GetPredefinedAddress(), address: config.GetPredefinedAddress(),
@ -76,16 +79,16 @@ func (v *DokodemoDoor) Close() {
} }
} }
func (v *DokodemoDoor) Network() net.NetworkList {
return *(v.config.NetworkList)
}
func (v *DokodemoDoor) Start() error { func (v *DokodemoDoor) Start() error {
if v.accepting { if v.accepting {
return nil return nil
} }
v.accepting = true v.accepting = true
if v.config.NetworkList == nil || v.config.NetworkList.Size() == 0 {
return errors.New("DokodemoDoor: No network specified.")
}
if v.config.NetworkList.HasNetwork(net.Network_TCP) { if v.config.NetworkList.HasNetwork(net.Network_TCP) {
err := v.ListenTCP() err := v.ListenTCP()
if err != nil { if err != nil {

View File

@ -1,6 +1,7 @@
package http package http
import ( import (
"context"
"io" "io"
"net" "net"
"net/http" "net/http"
@ -8,8 +9,6 @@ import (
"strings" "strings"
"sync" "sync"
"context"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dispatcher" "v2ray.com/core/app/dispatcher"
"v2ray.com/core/common" "v2ray.com/core/common"
@ -62,6 +61,12 @@ func (v *Server) Port() v2net.Port {
return v.meta.Port return v.meta.Port
} }
func (v *Server) Network() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_TCP},
}
}
// Close implements InboundHandler.Close(). // Close implements InboundHandler.Close().
func (v *Server) Close() { func (v *Server) Close() {
v.accepting = false v.accepting = false

View File

@ -54,6 +54,8 @@ type InboundHandler interface {
Close() Close()
// Port returns the port that the handler is listening on. // Port returns the port that the handler is listening on.
Port() net.Port Port() net.Port
Network() net.NetworkList
} }
// An OutboundHandler handles outbound network connection for V2Ray. // An OutboundHandler handles outbound network connection for V2Ray.

View File

@ -67,6 +67,16 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
return s, nil return s, nil
} }
func (v *Server) Network() net.NetworkList {
list := net.NetworkList{
Network: []net.Network{net.Network_TCP},
}
if v.config.UdpEnabled {
list.Network = append(list.Network, net.Network_UDP)
}
return list
}
func (v *Server) Port() net.Port { func (v *Server) Port() net.Port {
return v.meta.Port return v.meta.Port
} }

View File

@ -59,6 +59,16 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
return s, nil return s, nil
} }
func (v *Server) Network() net.NetworkList {
list := net.NetworkList{
Network: []net.Network{net.Network_TCP},
}
if v.config.UdpEnabled {
list.Network = append(list.Network, net.Network_UDP)
}
return list
}
// Port implements InboundHandler.Port(). // Port implements InboundHandler.Port().
func (v *Server) Port() net.Port { func (v *Server) Port() net.Port {
return v.meta.Port return v.meta.Port

View File

@ -120,6 +120,12 @@ func New(ctx context.Context, config *Config) (*VMessInboundHandler, error) {
return handler, nil return handler, nil
} }
func (v *VMessInboundHandler) Network() net.NetworkList {
return net.NetworkList{
Network: []net.Network{net.Network_TCP},
}
}
func (v *VMessInboundHandler) Port() net.Port { func (v *VMessInboundHandler) Port() net.Port {
return v.meta.Port return v.meta.Port
} }