forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8f01e0
commit 34a2ae0
Showing
7 changed files
with
262 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package outbound | ||
|
||
import ( | ||
"context" | ||
|
||
"v2ray.com/core/app/proxyman" | ||
"v2ray.com/core/common/errors" | ||
"v2ray.com/core/common/net" | ||
"v2ray.com/core/proxy" | ||
"v2ray.com/core/transport/internet" | ||
) | ||
|
||
type Handler struct { | ||
config *proxyman.OutboundHandlerConfig | ||
streamSettings *proxyman.StreamSenderConfig | ||
datagramSettings *proxyman.DatagramSenderConfig | ||
proxy proxy.OutboundHandler | ||
} | ||
|
||
func NewHandler(ctx context.Context, config *proxyman.OutboundHandlerConfig) (*Handler, error) { | ||
h := &Handler{ | ||
config: config, | ||
} | ||
for _, rawSettings := range config.SenderSettings { | ||
settings, err := rawSettings.GetInstance() | ||
if err != nil { | ||
return nil, err | ||
} | ||
switch ts := settings.(type) { | ||
case *proxyman.StreamSenderConfig: | ||
h.streamSettings = ts | ||
case *proxyman.DatagramSenderConfig: | ||
h.datagramSettings = ts | ||
default: | ||
return nil, errors.New("Proxyman|DefaultOutboundHandler: Unknown sender settings: ", rawSettings.Type) | ||
} | ||
} | ||
proxyHandler, err := config.GetProxyHandler(proxy.ContextWithDialer(ctx, h)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
h.proxy = proxyHandler | ||
return h, nil | ||
} | ||
|
||
func (h *Handler) Dial(ctx context.Context, destination net.Destination) (internet.Connection, error) { | ||
switch destination.Network { | ||
case net.Network_TCP: | ||
return h.dialStream(ctx, destination) | ||
case net.Network_UDP: | ||
return h.dialDatagram(ctx, destination) | ||
default: | ||
panic("Proxyman|DefaultOutboundHandler: unexpected network.") | ||
} | ||
} | ||
|
||
func (h *Handler) dialStream(ctx context.Context, destination net.Destination) (internet.Connection, error) { | ||
var src net.Address | ||
if h.streamSettings != nil { | ||
src = h.streamSettings.Via.AsAddress() | ||
} | ||
var options internet.DialerOptions | ||
if h.streamSettings != nil { | ||
options.Proxy = h.streamSettings.ProxySettings | ||
options.Stream = h.streamSettings.StreamSettings | ||
} | ||
return internet.Dial(src, destination, options) | ||
} | ||
|
||
func (h *Handler) dialDatagram(ctx context.Context, destination net.Destination) (internet.Connection, error) { | ||
var src net.Address | ||
if h.datagramSettings != nil { | ||
src = h.datagramSettings.Via.AsAddress() | ||
} | ||
var options internet.DialerOptions | ||
if h.datagramSettings != nil { | ||
options.Proxy = h.datagramSettings.ProxySettings | ||
} | ||
return internet.Dial(src, destination, options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
package outbound | ||
|
||
import ( | ||
"sync" | ||
|
||
"context" | ||
"sync" | ||
|
||
"v2ray.com/core/app/proxyman" | ||
"v2ray.com/core/common" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters